Re: [colorforth] Question about displaying text
- Subject: Re: [colorforth] Question about displaying text
- From: "Ray St. Marie" <ray.stmarie@xxxxxxxxx>
- Date: Wed, 27 Dec 2006 04:29:12 -0600
Hi John,
Ray here...
Well done, this.
On 12/26/06, John Drake <jmdrake_98@xxxxxxxxx> wrote:
Hello all,
I've made some progess on the Primary ColorForth
tutorial.
...
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
Great job here. Keep it up. I'll be helping soon.
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.
Okay, this was neat. I don't have much time right
now to test, but I suspect you will find that before
unpacking the 'double-bytecoded-word' you will
need to duplicate the first portion and get it's tag.
A tag of 0 will indicate a second portion, and you
may need to recurse thru all of these 0 tagged
portions, feeding each to your type word.
I'll try to knock something off after work today.
Again, keep the flame burning, your not alone :-)
Ray
Regards,
John M. Drake
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com