PDA

View Full Version : TV_Text format question



Paul_H
09-08-2007, 04:15 AM
Quick question today about the tv_text object.

When the first output to the TV screen is sent without using any locations information, the text appear at the top line of the screen. eg:





tv.str(string("This is at the top of the screen")




However, when I specify a screen location it is one line below this physical spot. eg:



tv.str(string($A,5,$B,1)) 'set screen position indent to the 5th column and 1st row.
tv.str(string("This comes up on the second line"))




Also the compiler complains when I try to enter a "0" for the line top.
If anyone has the answer, I do appreciate it!
Paul

deSilva
09-08-2007, 04:41 AM
As every self-respecting program TV counts things starting with zero. Thus the upper left corner is (0,0)

However a funny convention lent from C requires a text (!) string to be terminated by 0, which has nothing to do with the former convention.

The directive string(...) is aware of the latter convention but not of the former one http://forums.parallax.com/images/smilies/smile.gif

So no wonder you get confused. You have to use TV.OUT when zeroes are concerned..

Post Edited (deSilva) : 9/7/2007 8:48:07 PM GMT

Paul_H
09-08-2007, 05:31 AM
Thanks for the clarity, and my program now respects itself http://forums.parallax.com/images/smilies/wink.gif

This works:



tv.out($0A) ' set position on the Zero line at about center scren
tv.out(19)
tv.out($0B)
tv.out(0)

tv.str(string("On the Top Line!"))




Gracias!
Paul

deSilva
09-08-2007, 05:53 AM
You are welcome!
I should like to use this opportunity to discuss another rarely used technique:
Using a "mask" in the DAT section.


DAT
myString BYTE 10,19,11
theLine BYTE 1
BYTE "Not on the Top Line", 0



The usage is:


theLine:= 1
tv.str(@myString)



Note there still is no cheating with the terminating zero: tv.str will merciless stop at any 0!

But you can make your own tv_str:



PRI tv_str(sAddr) ' stringterminator 255 rather than 0
REPEAT WHILE BYTE[sAddr]<>255
tv.out(BYTE[sAddr++])

Post Edited (deSilva) : 9/7/2007 9:58:58 PM GMT

deSilva
09-08-2007, 06:42 AM
I just had a look into TV.SPIN, it says there:


$0A: col := c // cols
$0B: row := c // rows


So without changing any code at all you could write:

tv.str(STRING(10, tv#cols, 11, tv#rows, "Upper Left Corner"))

Post Edited (deSilva) : 9/7/2007 10:47:24 PM GMT