New Micros, Inc  

Go Back   New Micros, Inc > Software Technical Support > FORTH ONLY
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 03-16-12, 01:36 PM
Mark Bresler Mark Bresler is offline
Registered User
 
Posts: 78
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
Reply With Quote
  #2  
Old 03-18-12, 09:15 AM
Brad R Brad R is offline
Registered User
 
Posts: 5
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:
3 RAMBUFFER PREFIX ( will hold the "location" counted string ) 6 RAMBUFFER WORDNAME ( will hold the assembled word name ) ( commit to "memory" the string which follows, " delimited ) HEX : COMMIT" ( a -- ) 22 WORD DUP C@ 1+ PREFIX SWAP CMOVE ; ( recall the memorized string to the WORDNAME buffer ) : RECALL ( -- ) PREFIX DUP C@ 1+ WORDNAME SWAP CMOVE ; ( append a character to WORDNAME ) : APPEND ( c -- ) WORDNAME COUNT + C! ( store char ) WORDNAME C@ 1+ WORDNAME C! ; ( increment length ) ( accept three keys and do that word ) : COMMAND ( -- ) RECALL ( first get the prefix ) 3 0 DO KEY APPEND LOOP ( append three keys ) WORDNAME FIND ( look for the combined wordname ) IF EXECUTE ( found - perform the word ) ELSE COUNT TYPE ( not found - display the wordname ) ." ?" ( followed by a question mark) THEN ;

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:
: ATSDH ( ...whatever is needed to move to the new position... ) COMMIT" AT" ( remember the AT prefix ) ;

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.)
Reply With Quote
  #3  
Old 03-18-12, 09:25 AM
Brad R Brad R is offline
Registered User
 
Posts: 5
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).
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is On
Forum Jump



All times are GMT -5. The time now is 08:32 AM.


Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.