Question about displaying text

John Drake <[email protected]>
Newsgroups gmane.comp.lang.forth.colorforth
Message-ID <[email protected]>
Hello all,

I've made some progess on the Primary ColorForth
tutorial.  For one thing I added the formatting
to the "editor" chapter Jeff did.  Jeff included
the formatting when he wrote it, but I was unsure
how well the Wiki would take HTML so I just 
pasted raw text.  Now I realize that it handles
HTML pretty well.  I pasted Jeff's HTML and all
I had to do was attach all of the images.

http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForthEditor

I also added the examples from chapter 1 of 
Starting Forth that I had documented on my
blog.

http://www.quartus.net/cgi-bin/twiki/view/Main/PrimaryColorForthGettingStarted

Note, the HTML that the blog had inserted
was much more problematic for the Wiki and
I had to do a lot of editing, but I got it
to work.

Now for my question.  I've actually finished
the rest of the example from chapter 1.  But
I'm not 100% satisfied with the results.

This is what I have so far.  I know how to
display a packed word that's on the stack.

: type fffffff0 and unpack if emit type ; then 
drop drop ;

This recursively upacks a charecter and displays.
If the charecter is 0 then we're at the end of
the word and "type" stops.  So if "hello" was
at the top of block 20 then

: ok show text 20 block type keyboard ;

would create a word to display "hello" at the
top of the screen.

I also figured out a way to use "string
variables".  Magenta variables are basically
pointers to areas of memory inside of blocks.
So if you put a magenta variable address on
the stack and add 1 to it you'll have a
pointer to the packed source code that comes
after the variable.  So I create magenta
variables and then put the string I want
directly after the variables in the form
of comments.

var s 0 ( hello )

Then

: ok show text s 1 + @ type keyboard ;

will also display "hello" on the screen.

Factoring out "1 + @ type" I get:

: stype 1 + @
: type fffffff0 and unpack if emit type ; then 
drop drop ;

But the problem is, what happens when you have
longer words?  For example:

var s 0 ( bookends )

If I do:

: ok show text s stype keyboard ;

I get:

booke

Now I can chain words together.  For example
I created a word "dword" to deal with long
words like "bookends".

: dword dup stype 1 + stype ;

Then

: ok show text s dword keyboard ;

displays:

bookends

But there HAS to be a better way.  How can
I get ColorForth to differentiate between
short words like "hello" that get packed
into a single 32 bit word and longer words
like "bookends" that take 2 32 bit words?

Clearly the editor knows how to do this
because it displays "bookends" just fine.

Regards,

John M. Drake

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.