Lesson 6: Intoduction to the ROM and built in functions

The rom is a vast fourtine of code, just sitting there waiting to be used. But how are we to know where what we want is? You don't have to worry about that, all you have to do is remember some archaic names. ROM calls are some of the best, because it does all the hard work and only costs you 3 bytes. Lets say we wish to print a number on the screen. Woah!! We haven't learned output yet! Nor do we have to! All we have to do is know which rom call is going to do it for us. If you look in this listing of the standard rom calls, I am sure we can find one suitable to our liking.

Ooh! check out this one:
D_HL_DECI

Call method: ROM_CALL(D_HL_DECI)
Input: HL = value to print
Memory and bits for normal output.
Returns: (800C) and (800D) updated with new cursor positions.

Description: HL is displayed as a 5-number, right justified, blank-padded
decimal number.
Traps: None, I think.
Example:

ld hl,1234 ;This is the value we want to print
ROM_CALL(D_HL_DECI)

I'm sure every ZShell programmer remembers the infamous ROM_CALL. But now, with Usgard, you will never have to use it. See, back in the 'old days' each rom call had a different method of being called. With usgard, all you need is type
call D_HL_DECI
and you will have just made a rom call. You will note that when making a rom call, you do NOT use a & sign. Pretty simple huh? Lets write some code where we display the acc. in the upper right hand corner of the screen.

   ld l,a
   ld h,0
   ld de,$0F00
   ld ($800C),de
   call D_HL_DECI

That should do it! see, first we copied A into hl. then we put the coords of what we wanter to print (0,15 - remember, words are written backwards!) in de, and put de into $800C, where the cursor location is stored. Then we made out rom call.
Make sure you get that file that I talked about above, print it out, because you are going to need it.

But since we are programming for Usgard, guess what? There are more rom calls!! There are some wonderful ones, like a random number generator, which I found that only will generate a, the rest are not very random... But there are some nice ones. So print out this file too.

There is one other rom call I want to teach you about: GET_KEY. This reads the last key pressed on the calc. Except, the number it returns is quite cryptic. It is not as nicely organized as the getky in basic. here is a bit of code that waits until you press enter.

Wait:
   call GET_KEY
   cp 9
   jr nz,Wait

Just one thing to note, the value in HL is destroyed when you call GET_KEY.

Here is a scancode chart, it is really helpful.

TI-85 Assembler Programming - Keycodes

Note that these codes are much different from the ones used in TI-BASIC

 
 Hex codes:              Decimal codes:

 ---------------------- ----------------------
|  35  34  33  32  31  |  53  52  51  50  49  |
|                      |                      |              
|                04    |                04    |
|                      |                      |              
|  36  37  38  02  03  |  54  55  56  02  03  |
|                      |                      |              
|  30  28  20    01    |  48  40  32    01    |
|                      |                      |              
|  2F  27  1F  17  0F  |  47  39  31  23  15  |
|                      |                      |              
|  2E  26  1E  16  0E  |  46  38  30  22  14  |
|                      |                      |              
|  2D  25  1D  15  0D  |  45  37  29  21  13  |
|                      |                      |              
|  2C  24  1C  14  0C  |  44  36  28  20  12  |
|                      |                      |              
|  2B  23  1B  13  0B  |  43  35  27  19  11  |
|                      |                      |              
|  2A  22  1A  12  0A  |  42  34  26  18  10  | 
|                      |                      |              
|  xx  21  19  11  09  |  xx  33  25  17  09  |
 ---------------------- ----------------------

Keys of interest:

up    = $04 = 04
down  = $01 = 01
left  = $02 = 02
right = $03 = 03

enter = $09 = 09
2nd   = $36 = 54
exit  = $37 = 55
more  = $38 = 56

on    = no key code is returned

 

Well, I think we are ready. Next lesson, we are going to write our first program! And probably our second too.