![]() |
|
#1
|
|||
|
|||
|
Character handling
Hi,
looking through the list of forth words, I am not sure I can accomplish what I am setting out to do. I am designing an autonavigating wheelchair. Words have been developed for possible paths within the building. For example, ATSDH is used for going between assistive technology and the small dining hall. I would like the wheelchair to remember that it is presently at assistive technology so the user will only have to enter SDH to move to the small dining hall. How do I have the system remember its present location in a character format, wait for two or three characters to be entered, and then join these characters together into a word to be executed? (I realize I will have to deal with two or three characters being entered but I can always use a leading or trailing ) thanks, Mark |
|
#2
|
|||
|
|||
|
There are several ways to do what you're trying to accomplish. Probably the most elegant would be to use wordlists (vocabularies) for each location, but that would require typing two words (one for location, one for destination). Also, I get the impression that you want the command to execute as soon as the three characters are entered, not requiring an "Enter" key.
Since RAM allocation is different on different Forth systems, I'll assume you've defined a word RAMBUFFER to declare a RAM buffer of arbitrary size. (This might be as simple as : RAMBUFFER VARIABLE 2 - ALLOT ; ) Also, the word FIND has changed over the years; I'll assume the Isomax definition ( addr1 -- addr2 n ) that expects a counted string and returns execution address and n<>0 if the word is found, string address and n=0 if the word is not found). Code:
Finally, inside the word ATSDH (and all words like it), you must remember the new position in the PREFIX buffer. That's what the word COMMIT" is for: Code:
This is just off the top of my head; I haven't tested any of it. It should be fairly easy to debug. Handling the problem of two or three keys is left as an exercise for the student. Once you know how to use FIND, you can even write it to accept a variable number of keys until a Forth word is recognized. (In which case you'll need a way to clear the WORDNAME and start over.) |
|
#3
|
|||
|
|||
|
Whoops...an error in my ATSDH. I forgot this is going from AT to SDH. So when you get to the small dining hall, you'll want to COMMIT" SD" instead of COMMIT" AT". You get the idea. You can use a longer prefix, but you'll need to increase the size of the RAMBUFFERs (each must hold N characters plus one count byte).
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|