I made the following extensions to ColorForth.
s 0 hello , i speak forth
stype 1 + @
type fffffff0 and unpack if emit type ; then drop drop ;
The word "type" takes a packed word and displays it on the screen. Right now it ignores all color tags and just emits charecters using the current foreground color. Note that s is a string variable. Actually it's just a regular variable, but I'm treating it like a string variable. Variables in ColorForth really point directly to block memory. So by adding 1 to the address of s I can get the address of the text for "hello". The word "stype" adds 1 to the address on the stack and then returns data which is treated by "type" as a packed string. So the code:
greet show text s stype ;
Will display "hello" on the screen. Of course that's only part of the phrase. I added a definition to get a word, display it, and add the address for the next word.
nxtw 1 + dup @ type space ;
The word "space" was defined in a previous posting. I then added a word to unpack and display several words of text.
words for nxtw next ;
So the code:
greet show text s 5 words ;
hello , i speak forth
I'm looking for better ways to do this. All comments welcome.