-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
  TI-ROM.TXT      A Programmer's Guide to TI-85 ROM Calls      Version 0.5
                        Copyright (c) 1994 Dan Eble
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------

This is a list of routines in the TI-85 ROM 3.0A code.
You may distribute this document, in unmodified form, to anyone you choose.
Direct corrections and inquiries to: Dan.Eble@CommLink.org

  If you find that one of the untested functions in this document actually
works (they should), or find that another doesn't, please contact me.  Be 
sure to include your ROM version, the address you're calling, and what it's 
supposed to do.

For other ROM versions:
4.0: add 3 bytes to all calls between 33E8 and 33F3 (result: 33EB to 33F6)
6.0: add 3 bytes 
8.0: add 7 bytes (result: 33EF to 33FA)

---- Format ---- Explanation of the format of this document -----------------
  The instruction to call the routine is in a header bar like the one above.
Under each header bar, the expected input, result, and description of the
routine is given.

  Between 33E8 and 3FF3 is a table of 6-byte structures for calling functions
memory pages other than 0.  All you have to do is call the proper address
in this range, and it will automatically switch pages, call the procedure, 
and return you to the proper page. In this document, wherever there is a call
address in this table, the actual address of the function will be given in
parenthesis as a 5-digit hexadecimal number.  The first digit represents the
page number the routine is on, and the last four are the address.
  Some of these calls do not return to the original address.  When this is 
the case, the address in parenthesis will be preceeded by "JP".

(nnnn)    denotes a memory address, nnnn, in page 0 of the ROM.
(xnnnn)   denotes a memory address, nnnn, in page x of the ROM.
->        denotes a pointer rather than a normal value.
set n,rr  in an input field, indicates that bit n of register (or memory
          location) rr is to be set before the call.
          in a result field, indicates that bit n of rr is set as a result
          of the call.
res n,rr  in an input field, indicates that bit n of register (or memory
          location) rr is to be clear before the call.
          in a result field, indicates that bit n of rr is clear as a result
          of the call.
All numbers are in hexadecimal except where noted with (d).

---- RST 08 (CALL 208E) ---- Move 11(d) bytes from 8082 to 808D -------------
Probably used by system for copying name to secondary buffer.

Note: This function has not been tested.

---- RST 10 (CALL 2715) ---- Search for variable by name --------------------
Input:  (8083) = Length of variable name (1-8)
        (8084) = Actual name of variable (8 bytes long, padded with anything)

Result: Success: CF clear
                 A = (8082) = Type of the variable found
                 C = 0
                 DE = Address of variable
                 HL = Address of VAT entry for variable

        Failure: CF set

---- RST 20 (CALL 2151) ---- Move 10(d) bytes from (HL) to (8082) -----------
Used to move string name into search buffer.

---- CALL 0033 ---- LD HL,(HL) ----------------------------------------------
Input:  HL -> data word

Result: HL = data word
        A = L

---- RST 38 ---- General Interrupt Handler ----------------------------------
Handles interrupts created by system peripherals.

---- CALL 008E ---- CP HL,DE ------------------------------------------------
Input:  Nothing

Result: Flags are modified

---- CALL 01A2 ---- Read information from keypad port -----------------------
Input:  A = key group mask

Result: A = B = key press data

---- CALL 01B1 ---- Store keystroke in buffer -------------------------------
Input:  A = scancode (see CALL 01BE for scancode list)

Result: (8000) = scancode
        (8006) = scancode if scancode is not 0
        set 3,(IY+00)

---- CALL 01BE ---- Read current keystroke from buffer ----------------------
Input:  Nothing

Result: A = scancode of key that is currently pressed
        HL = 8000
        res 3,(IY+00)

Note: The scancode of the last key pressed is stored at (8006), regardless
      of whether it has been released or not.

Scancode Table:
00 no key       16 TAN          28 x-VAR
01 down         17 CUSTOM       29 ON (The ON handler gets to this first)
02 left         19 .            2A STO
03 right        1A 2            2B ,
04 up           1B 5            2C x
09 Enter        1C 8            2D LN
0A +            1D (            2E LOG
0B -            1E COS          2F GRAPH
0C *            1F PRGM         30 ALPHA
0D /            20 DEL          31 F5
0E ^            21 0            32 F4
0F CLEAR        22 1            33 F3
11 (-)          23 4            34 F2
12 3            24 7            35 F1
13 6            25 EE           36 2nd
14 9            26 SIN          37 EXIT
15 )            27 STAT         38 MORE

---- CALL 0CAD ---- Checksum memory between 8BF7 and FA6F -------------------
Input:  Nothing

Result: HL = checksum
        IX = FA70
        BC = 0
        DE = -HL

Note: This function has not been tested.

---- CALL 0CD4 ---- Copy length-indexed string to 8083 ----------------------
Input:  IX -> string

Result: string is copied
        B = 0
        IX = end of original string + 1
        HL = end of string at 8083 + 1

Note: This function has not been tested.

---- CALL 2FB8 ---- Copy 10(d) bytes from 8082 to [(8BE1)-10(d)] ------------
Input: Nothing

Result: Bytes are copied
        HL = 808C
        DE equals what it should

Note: This function has not been tested.

---- CALL 300C ---- Negate BC -----------------------------------------------
Input: BC

Result: HL = BC = -BC
        A = 0

---- CALL 3014 ---- ?????????? ----------------------------------------------
Input:  Nothing

Result: HL = (8BE1) - 10(d) -> REAL number (Don't know the significance)
        DE = FFF6 = -10(d)

---- CALL 301C ---- Self test -----------------------------------------------
Input:  ?	I haven't investigated this function enough.
Result: ?
-----------------------------------------------------------------------------

---- CALL 307C ---- Measure ASCIIZ string length ----------------------------
Input:  HL -> string

Result: BC = string length

Note: This function has not been tested.

---- CALL 308F ---- Copy ASCIIZ string --------------------------------------
Input:  HL -> source string
        DE -> destination string

Result: HL and DE -> to the null bytes at the ends of their strings
        A = 0

Note: This function has not been tested.

---- CALL 3097 ---- Concatenate ASCIIZ strings ------------------------------
Input: HL -> source string
       DE -> destination string

Result: Increments DE until (DE) = 0, then CALLs 308F to copy the string.

Note: This function has not been tested.

---- CALL 309E ---- Compare length-indexed string ---------------------------
Input:  HL -> first string
        DE -> second string 

Result: Equal: ZF set

        Different: ZF clear
                   CF clear: first string is greater
                   CF set:   second string is greater 

---- CALL 30C4 ---- Test bit in bitstream -----------------------------------
Input:  A = Bits 7-3: byte offset from HL (00-1F)
            Bits 2-0: bit to test (0-7)
        HL -> first byte in bitstream

Result: A = 2^(bit tested)
        HL -> byte tested
        DE = bit tested

Note: This function has not been tested.

---- CALL 3BDA (16FF1) ---- Print menu character ----------------------------
Input:  A = character to print
        (8333) = x coordinate
        (8334) = y coordinate
        res 1,(IY+05): print only 6 rows of the character
        set 1,(IY+05): print entire 7 rows of the character
        res 3,(IY+05): print character over current screen
        set 3,(IY+05): XOR character with current screen

Result: The character is printed on the screen and the x coordinate is
        updated.
        DE is destroyed.

---- CALL 3BE0 (170A7) ---- Print ASCIIZ menu string ------------------------
Input:  HL -> null-terminated string
        (8333) = x coordinate
        (8334) = y coordinate
        res 1,(IY+05): print only 6 rows of the character
        set 1,(IY+05): print entire 7 rows of the character
        res 3,(IY+05): print character over current screen
        set 3,(IY+05): XOR character with current screen

Result: The string is printed on the screen and the x coordinate is updated.

---- CALL 3BE6 (JP 1710F) ---- Save text mode parameters in secondary area --
Input:  Nothing

Result: (8187) = (800C)	        ; cursor row
        (8188) = (800D)         ; cursor column
        (8189) = (8B2F)
        (818A) = (8358)
        (818B) = (834B) AND 10h

Note: This function has not been tested.

---- CALL 3BFE (171A1) ---- Move top right corner of LCD to bitmap at (8078)
Input:  set 1,(IY+12h): don't move bytes
        res 1,(IY+12h): move bytes

Result: 8 bytes are moved from the top right corner of the LCD to (8078).
        set 1,(IY+12h)

---- CALL 3C04 (171C8) ---- Move bitmap at (8078) to top right corner of LCD
Input:  set 1,(IY+12h): move bytes
        res 1,(IY+12h): don't move bytes

Result: 8 bytes are moved from (8078) to the top right corner of the LCD.
        res 1,(IY+12h)

---- CALL 3C22 (170BA) ---- Print length-indexed menu string ----------------
Input:  HL -> string
        B = string length
        (8333) = x coordinate
        (8334) = y coordinate
        res 1,(IY+05): print only 6 rows of the character
        set 1,(IY+05): print entire 7 rows of the character
        res 3,(IY+05): print character over current screen
        set 3,(IY+05): XOR character with current screen

Result: The string is printed on the screen and the x coordinate is updated.

---- CALL 3CA0 (16FDB) ---- Point HL to absolute address of text cursor -----
Input:  Nothing

Result: HL = absolute address of text cursor (in primary text memory [80DF])

---- CALL (3D8A) ---- Store text mode parameters and screen in secondary area
Input:  Nothing

Result: 168 bytes are moved from 80DF to 806B.  ; text buffer
        (8187) = (800C)	        ; cursor row
        (8188) = (800D)         ; cursor column
        (8189) = (8B2F)
        (818A) = (8358)
        (818B) = (834B) AND 16

Note: This function has not been tested.

---- CALL (3D90) ---- Scroll screen up --------------------------------------
Input:  (8B2F) = row to start (0-7)
        (8B30) = number of rows to scroll (1-8)
        set 1,(IY+0D): scroll the text memory
        res 1,(IY+0D): don't scroll the text memory

Result: Text is scrolled and a blank line is inserted at the end.

Note: This function has not been tested.

---- CALL 3DF6 (16A57) ---- Print character ---------------------------------
Input:  A = character to print
        (800C) = row
        (800D) = column
        set 3,(IY+05): display white on black
        res 3,(IY+05): display black on white
        set 1,(IY+0D): alter text memory
        res 1,(IY+0D): don't alter text memory

Result: The character is printed on the screen. 

---- CALL 3DFC (16F03) ---- Clear LCD ---------------------------------------
Input:  Nothing

Result: The LCD is cleared (FC00-FFFF is zeroed).
        Nothing happens to the text memory at 80DF.
        Nothing happens to the graphics memory at 8641.
        HL = 8358
        DE = BC = 0000

---- CALL 3E0E (37D69) ---- *** FAIL ----------------------------------------
Input:  HL = string to print in front of "FAIL"

Result: The string at HL is printed on the screen followed by "FAIL"
        The memory is cleared and the defaults are set.

Note: This function has not been tested.

---- CALL 3E5C (16F27) ---- Clear text screen -------------------------------
Input:  set 1,(IY+0D): fill text memory (80DF) with spaces
        res 1,(IY+0D): clear the LCD without altering the text memory

Result: The screen is cleared.

---- CALL 3E68 (16BDE) ---- Print ASCIIZ string -----------------------------
Input:  HL -> null-terminated string
        (800C) = row
        (800D) = column
        set 3,(IY+05): display white on black
        res 3,(IY+05): display black on white
        set 1,(IY+0D): alter text memory
        res 1,(IY+0D): don't alter text memory

Result: The string is printed on the screen.

---- CALL 3E6E (16FD0) ---- Set cursor row to position stored in (8B2F) -----
Input:  Nothing

Result: (800C) = (8B2F)
        (800D) = 00

Note: This function has not been tested.

---- CALL 3EA4 (170E2) ---- Turn off "busy" indicator -----------------------
Input:  Nothing

Result: The "busy" indicator is turned off.
        res 0,(IY+12h)

---- CALL 3EBC (170CA) ---- Turn on "busy" indicator ------------------------
Input:  Nothing

Result: The "busy" indicator is turned on.
        set 0,(IY+12h)
