Karma Universe - demuynck.org Lesson 7
TI-82 ASM Corner :: Programming Guide :: Lesson 7 Back | Home | Search
Lesson 7 : Displaying Text

In this lesson, you will learn various ways to display text on the TI-82's LCD.

2 types of text | Normal font | Menu Font | String types

2 types of text

Fonts on the TI-82 What is text? Well actually it are just pixels that have been turned on or off. Luckily the TI-82 ROM contains some routines that does all those things for us. We only need to tell where we want the text and what text we want.

On the TI-82, there are two types of text. There is the normal font, which is normally used: all characters of 6 pixels width and 8 pixels high. This is the kind of text you can see when you are doing calculations on your calculator.

Next to that, there is a variable width menu font which is normally only used on the graph screen. But since we are not in TI-OS when doing assembly, we can use both fonts on the same screen if we want to.

Normal font

Normal Font Coordinates Before you write text in the normal font, you need to store the location in the CURSOR_ROW and CURSOR_COL locations. After you have written text, these memory addresses are updated.

The top left coordinate is (0,0) and the bottom right coordinate is (15,7), which means that you can put 8 lines of 16 characters each on the screen: 128 characters. (what was the size of TEXT_MEM again?)

ROM_CALL(D_ZT_STR)

This is the method that is used most of the time. It displays a zero terminated string using normal font. When you call the function, the HL register needs to contain the address of the string and CURSOR_ROW and CURSOR_COL contain the location.

An example:

#Include "ti82.h"
.org START_ADDR
.db "D_ZT_STR test",0

 ROM_CALL(CLEARLCD)     ; clear the LCD
 LD	A,5
 LD	(CURSOR_ROW),A  ; select row 5
 LD 	A,2
 LD	(CURSOR_COL),A  ; select column 2
 LD	HL,Msg_Hello    ; let HL point to string
 ROM_CALL(D_ZT_STR)     ; show the string
 ROM_CALL(KEY_HAND)     ; wait for a key
 RET                    ; return to Ash
Msg_Hello:
 .db "Hello All",0

.END
 

You may have noticed the semi-colons in the source above. Well, they tell the assembler that everything from the semi-colon to the end of the line is comments.
I strongly advise everyone to write comments in your sourcecode, this way you will still understand it after some months.

ROM_CALL(D_LT_STR)

This method is almost identical to the one above, but this time the string is given with a length indexed string. A length indexed string is a string that is preceded by the number of characters in the string. A zero at the end in not necessary here.

The same example from above:

#Include "ti82.h"
.org START_ADDR
.db "D_ZT_STR test",0

 ROM_CALL(CLEARLCD)     ; clear the LCD
 LD	HL,$0205
 LD	(CURSOR_POS),HL
 LD	HL,Msg_Hello    ; let HL point to string
 ROM_CALL(D_LT_STR)     ; show the string
 ROM_CALL(KEY_HAND)     ; wait for a key
 RET                    ; return to Ash
Msg_Hello:
 .db 9,"Hello All"      ; length indexed string

.END
 

This time I changed the cursor position in a slightly different way. The result is the same, but this method takes less bytes and is a little bit faster. CURSOR_POS is actually the same as CURSOR_ROW. CURSOR_COL is the byte that comes immediately after the CURSOR_ROW byte. So, if you write a word to CURSOR_POS, it will fill both CURSOR_ROW and CURSOR_COL.

Now you may wonder why it says LD HL,$0205 and not $0502. This is because words will always be written and read with the low byte first. If you write $0205 to CURSOR_POS, $05 (lower byte) will be written to CURSOR_ROW and $02 (high byte) will be written to CURSOR_ROW+1 or CURSOR_COL.

Please remember this way of storing words backwards. You will often need (or want) to do alike operations.

ROM_CALL(TX_CHARPUT)

This call only places 1 character at a time. The code for the character needs to be stored in the A register. The most important characters have the same code as the ASCII set, but some are different. Experiment to find out which characters are where. You can also download a TI-82 character map.

An example

#Include "ti82.h"
.org START_ADDR
.db "D_ZT_STR test",0

 ROM_CALL(CLEARLCD)     ; clear the LCD
 LD	HL,$0000
 LD	(CURSOR_POS),HL ; cursor position to (0,0)
 LD	A,$05		; A contains 5, code for an arrow
 ROM_CALL(TX_CHARPUT)   ; show the character
 ROM_CALL(KEY_HAND)     ; wait for a key
 RET                    ; return to Ash

.END
 

ROM_CALL(D_HL_DECI)

This call shows the contents of the HL register as a decimal value. HL is displayed with 5 digits and justified to the right. If there are less than 5 digits, the remaining places on the left are filled with spaces.

An example:

#Include "ti82.h"
.org START_ADDR
.db "D_ZT_STR test",0

 ROM_CALL(CLEARLCD)     ; clear the LCD
 LD	HL,0     
 LD	(CURSOR_POS),HL ; cursor position to (0,0)
 LD	HL,1234         ; decimal number 1234
 ROM_CALL(D_HL_DECI)    ; show the character
 ROM_CALL(KEY_HAND)     ; wait for a key
 RET                    ; return to Ash

.END
 

Menu Font

Menu Font Coordinates Before you write text in the menu font, you need to store the location in the CURSOR_X and CURSOR_Y locations. And after you have written text, these memory addresses are updated with the new coordinates.

The top left coordinate is (0,0) and the bottom right coordinate is (63,95).

ROM_CALL(D_ZM_STR)

This call is almost identical to the D_ZT_STR call, but this time, the text is displayed in menu font.

ROM_CALL(D_LM_STR)

This call is almost identical to the D_LM_STR call, but this time, the text is displayed in menu font.

ROM_CALL(M_CHARPUT)

This call is almost identical to the TX_CHARPUT call, but this time, the text is displayed in menu font.

String types

There are 2 common ways to store strings in the memory. Zero-terminated strings and length indexed strings. Zero-terminated strings are used most of the time, but length-indexed strings also have their advantages.

Zero-Terminated

A zero terminated string is a string followed by a zero byte. This zero-byte can be seen as a guardian. When the text-display routine enncounters the $00 byte, it knows that it can stop reading now.

Some examples:

 ; "This is a zero terminated string"
 .db "This is a zero-terminated string",0

 ; "This is also a zero terminated string"
 .db "This is also"
 .db "a zero terminated string",0
 

Length Indexed

A length indexed string is a string that is preceded by a byte indicating the length in characters of the string. When the text-display routine starts reading the string, it first reads this byte and goes in a loop afterwards until all the characters are printed on the screen.

Some examples:

 ; "This is a length indexed string"
 .db 31,"This is a length indexed string"

 ; "This is also a length indexed string"
 .db 36,"This is also"
 .db "a length indexed string"
 

Previous lesson | Contents | Next lesson