Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Broseph Radson on January 18, 2011, 05:37:08 pm
-
Hai im back with another probably dumb question. So i have a users input stored to I, then the first letter of I is stored to N. I have "RLDQ" stored to C. Im trying to figure out how to step thru the letters in C and compare them to N. Inside a For( loop, i have this code:
If (N=(C+A)):Goto KK:End
Where A increments from 1 to 4. It seems to always return false and i know it has to do with the If block. Help plz :) EDIT: i just realized that when i copy the first byte of I to N, it doesnt stay as a char. Oops
-
I would also do A from 0-3, not 1-4. Also, {C+A} I believe would be more accurate as you are getting the byte at location C+A.
-
May I suggest a simpler soultion? inData(N,C) will return the 1-based position at which the byte stored in N is found in the string, or 0 if it is not found.
-
Ok i cant seem to get the first byte of I as a character so ill try inData. Will report back in a sec. One sec later, I got this to work:
For(A,0,3):If inData({C+A}, I):Goto KK:End:End
Thatx guise! I didnt know about inData lol
-
inData( would be better. Remember that you'll occasionally have problems with getting the characters to display properly, so set the byte with a known hex value to test it. Don't trust your input routine.
-
Ok another question. How to i get a substring? Like get the last part of a string?
For(A,3,Length([string]))
//something to get the character at A and append it to another string
End
Or is there a command that does this?
-
To get the end of the string you don't even need a command. If your string is Str1, lets say it says: "Hello". Then Str1+1 is "ello", Str1+2 is "llo", Str1+3 is "lo" etc.
-
orly i didnt try that. ill try once i remake the program. Just got a RAM clear messing with interrupts lol. which reminds me i have a question about interrupts but ill make a new thread for that.
-
Another question involving strings (since i cant for the life of me find the thread where this was mentioned), how do i insert a token at the beginning of a string? Like if R is "ABC" and i want to make it say "prgmABC"
-
The easiest Axe way to do it would be to make a new string and copy it over.
If you want a faster way to do it, there's bcall(_InsertMem), which allocates extra memory for a variable.
-
ok that worked but the token is copying as a character. How do i copy a token? It gives me a bad symbol error when i do >Tok in the copy and when i try to store it to its own string
-
Use T. For example, Tprgm→{getCalc("Str0")}.
Another question involving strings (since i cant for the life of me find the thread where this was mentioned), how do i insert a token at the beginning of a string? Like if R is "ABC" and i want to make it say "prgmABC"
How can R be a string?
-
Good question but it works for me. I cant store input to a regular string var so idk. I forgot about that T thing thanks. The most recent version of the commands list i have printed (no computer access) is 0.4.1 so i guess it wasnt listed in that one
-
DJ posted an online version here (http://ourl.ca/8409/154963).
-
well i tried copying the prgm token to the string then copying the progname to the string after the prgm token, but when i display it it spits out garbage. im sorry i know i really suck at this
-
well i tried copying the prgm token to the string then copying the progname to the string after the prgm token, but when i display it it spits out garbage. im sorry i know i really suck at this
Can you post your copying and displaying code together? Someone may be able to see what went wrong.
-
ok i can try. my phone doesnt do hard returns though.
input->I:Tprgm->{R}:I->{R+1}:Disp R
Input wont store to a string pointer and i dont want to use OS variables unless i absolutely have to.
-
Um, what's R again? What does it point to?
If you never set it (like with GetCalc("Str0")→R) R could point to any address in memory. Most likely R is 0, which points to a location in the flash memory. You're not allowed to store anything to flash, so when you do Tprgm→{R}, it doesn't do anything.
-
The completed string which i want to be "prgmWHATEVS". EDIT: tried doing Tprgm->R instead of {R} and it displayed different garbage.
-
The completed string which i want to be "prgmWHATEVS". EDIT: tried doing Tprgm->R instead of {R} and it displayed different garbage.
You're using R as a pointer when you store it as {R}. In other words, the variable R should already be holding an address in memory where you want to store it, or else you're storing to any random spot in memory.
If you just do Tprgm->R, you're setting the address to the value of Tprgm, which is $5F, which is still a random spot in memory. In fact, it still points to flash, and so it's still not doing anything.
The thinng is, R isn't actually a variable. It's just two bytes at a specific spot in memory. When you do {R}, you're taking the value of R and storing to that address. So if R were 32768, {R} would be the byte stored at the 32768th byte in memory. You can't just randomly store to {R} and expect it to be at a safe place.
-
GetCalc("Str0")->A
GetCalc("Str1")->R
[sup]T[/sup]prgm->R
input->A
A->{R+1}
Disp R
Doesnt display properly, but Str1 does have the token in it. The input appears to not store the input as a string...
-
Oh, you do init R, never mind then :)
But when you do input→A, you're only storing the pointer to the inputted string to A. When you do A→{R+1}, you're storing this value to the string (actually only the smaller byte of it). You need to replace the line A→{R+1} with Copy(A,R+1,LENGTH) and it should work. Make sure Str1 is at least LENGTH+1 long, though.
-
Derp moment there. Forgot to give Str1 a size. RAM clear lol. 1 more try
GetCalc("Str0",9)->R
GetCalc("Str1",8)->A
input->A
[sup]T[/sup]prgm->R
Copy(A,R+1,8)
Disp R
Gives the following output:
■■■#F2.43
Also Str1 is a bunch of question marks
-
Tprgm->R
Why that? You're storing the value as an address again, not to the address.
Replace it with Tprgm->{R}.
-
I am so fail at this lol. testing...
-
Is there any reason you're using the OS string variables for this? It might be easier to just use your own data storage. Also, prgm is a token, not a character, and would not display correctly as part of an ASCII string. May I suggest something like the following?
.Prepare a string buffer
"prgm"Zeros(9)→Str1
.Fill the string buffer with input
Copy(input,Str1+1,8)
.Display prgm token
Disp ᵀprgm►Tok
.Display program name
Disp Str1+1
Str1 will also contain the correct data for any GetCalc() operations that you may want to perform after this.
-
Wow thats cool i didnt know input could be used like that. It works thanks!
-
I'm not sure exactly what you're doing, but if you need something very adaptable and want to define the keys, you could always use the more complicated method I used for command line:
1) Record Keypress
2) Determine if Keypress is within valid range
3) Search for keycode in lookup table
4) Use data associated with lookup table to look up the input token in another table
5) Write data to known location
6) Repeat steps 1-6 until user presses Enter
7) Write termination data to the end of the location
8) Step through string until a match is found within parser commands
9) Jump to location of executable code associated with parser command
10) Execute data
11) Return to step 1
-
I am a fan of graphscreen input, but until i can memorize the math to do a lookup, its a bit out of my range. I think i can find out though. I believe someone posted how to do that somewhere
-
Actually, it's surprisingly easy in Axe. I cheat and use the inString command, where the string to be searched contains the hex keycodes of all of the keys used.
-
Oh cool how?? Axe is amazing
-
Er, let me dig up my source.
Okay, here's some example code. I'd post the original code, but it's very complex because I'm dealing with a lot of commands (and I also have a few 1500 byte strings laying around). Str1 is the key lookup table and defines all of the alphabet as well as the space button and the "." button. L2 holds the character set, although only not all of the keys defined in the lookup table have characters defined.
:.Lookup table
:[2F271F2E261E160E2D251D150D2C241C140C2B231B130B2A221A211911]→Str1
:.SET UP character TABLE
:For(A,65,90
:.SET LETTERS
:A→{L2+A-65}
:End
:.SET SPACE
:41→{L2+26}
:1→N→P+40→X→Y
:15→J+2→I
:.RECORD KEYPRESS
:getKey→K
:.REPLACE GRAPHICS ERASED BY MOUSE
:sub(RCL
:If K>0
:.SEARCH LOOKUP TABLE
:!If K-56
:If P-1
:sub(BCK
:End
:Goto 01
:Else
:inString(K,Str1)→A
:End
:.IF KEYPRESS ISVALID
:If A
:If I+48<N
:1→N
:O+6→O
:End
:Text(I+N,J+O,L2+A-1►Tok
:{L2+A-1}→{L5+P}
:.MOVE CURSOR
:N+5→N
:P+1→P
:End
:End
The parser itself is kind of a mess though and over a thousand bytes of code. I'll let you figure it out :P
Hint: You just step through the string starting from L5.
There are also a lot of optimizations I haven't made yet, so...
-
Looks cool ill try it out soooooooooon :)