As an example of using ." and . (dot) let's assume that to display a character we simply write to the serial port.
\ Declare the important emit function. code emit ; ( c --) periphbank BANK0 ; poll TRMT to see if we can send __POLL_TRMT btfss TXSTA, TRMT goto __POLL_TRMT ; Bit not set, so loop. ; Send the byte. movfp TLOW, TXREG ; Copy to the transmit register. call _poptop ; Pop the top cell off the stack. return endcode fload disp.f \ This loads the TYPE word. : .intro ." PicForth is #" 1 . ;After invoking .intro, the output of the serial port will be :
PicForth is #1
Setting this up is a bit more complicated than simply programming the
strings into program memory, but if you run out of program memory, there
may be no alternative. First the main program is compiled with the -r option.
The compiler generates some special files to enable assembly and compilation
of the setup program:
stringsp.f: | routine to program the strings |
strindex.inc: | a string index that is also programmed into the rom |
strbase.inc: | defines the base of the string index |
Example of The Setup Program
\ Fload all the necessary libraries. \ ..... \ This file loads routines to type the strings in the rom. fload romtype.f \ This file loads routines to program the strings into the rom. fload romsetup.f \ This compiler generated file defines the routine program_strings. fload stringsp.f \ Declare the main program. : main program_strings \ Programs the strings into the rom. \ Test that the strings are properly programmed. page ." Testing" CR ." 20 strings" CR 1000 MS 20 0 do CR I . space I rtype 1000 MS loop begin again \ Infinite loop. ;
: someword RStrings \ Set default to strings in rom. P." This string goes in program memory" CR R." This string in external rom" CR ." This goes into rom as well" ;