View Full Version : maxForth equivalent to S"?
les@windstream
01-17-05, 04:10 PM
Is there an equivalent to the standard FORTH word S", or even older LIT", in maxFORTH. S" places a string in a temporary buffer returning the address and byte count. I need something like that to send a known character sequence out a serial port that is not the "boot" port. I could do something like simply code the character sequence into a word in memory, for example, ": myword 4 C, 61 C, 62 C, 63 C, ;" and then write it out one character at a time, but that isn't very general or elegant. However, if there isn't an alternative, it will work. Any other suggestions? Thanks.
RMDumse
01-17-05, 05:42 PM
Have you tried the downloads page? I don't remember which processor you are using, but I know we have a STRINGS example for both MaxFORTH(TM) and IsoMax(TM).
Here are two words I find useful to define when I have to manipulate ASCII characters and strings. Both words are "state" smart so they work interactively as well as in a definition. The first word "back-tick" parses the next letter and leaves its value on the stack. The second word "quote" is used to encapsulate a string of characters leaving the address on the stack. If used inside of a definition, the string is compiled inline. If used outside of a definition, then dictionary space is allocated.
: ` ( "a" -- n ) BL WORD 1+ C@ [COMPILE] LITERAL ; IMMEDIATE
: " ( "string" -- a ) STATE @ IF COMPILE BRANCH >MARK THEN
` " WORD DUP >R C@ CELL+ CELL / CELL * ALLOT
STATE @ IF >RESOLVE THEN R> [COMPILE] LITERAL ; IMMEDIATE
As for some examples:
" $0%00(00" CONSTANT LI \ vertical line string with parameters
: CLS ` ! LCDEMIT ;
: LIGHTON ` " LCDEMIT ;
: LIGHTOFF ` # LCDEMIT ;
: BAN ( bg \ fg -- )
SETCOLOR 13 13 SETXY 172 52 BOX 15 15 SETXY 170 50 BOXFILL
SETCOLOR 22 20 SETXY 4 SELECTFONT " SensorPod V.1" PRINTSTRING ;
Rob
les@windstream
01-17-05, 05:59 PM
Guess I don't know about the "downloads" page. If you'd be so kind as to point me to it, I'll go have a look. (I haven't noticed a pointed to it on the site.) Thanks.
P.S. I'm using the ARM processors at this point.
RMDumse
01-17-05, 07:02 PM
Hopefully Rob's examples will suffice.
The Downloads page is the buton on our home page along the top marked Downloads. Then there are specific downloads for different processors. There's no example for strings in ARM yet, but there is on the Pod's download examples.
I'm probably missing it, but what are the CELL commands? (CELL CELL+). Thanks for letting me horn in on your project.
RMDumse
02-06-05, 12:39 AM
CELL is the size of a Forth stack item. In an 8-bitter, usually the CELL size will be two bytes. In the DSP they would be 1 16-bit location.
Thanks for that. How would I add CELL and CELL+ to a ServoPod?
RMDumse
02-06-05, 09:28 AM
Probably CELL+ CELL / CELL * can be removed and 1+ can be used instead. The purpose of the CELL / CELL * part is to get on an address word boundary. Since there isn't byte addressing in the DSP, every address is a word boundary. I haven't descended very deeply into the code, but first blush early in the morning, that's how it looks to me.
Here's a quick portable set of definitions:
SP@ SP@ - ABS CONSTANT CELL
: CELL+ CELL + ;
: CELLS CELL * ;
: CELL/ CELL / ;
Rob
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.