Tutorial 14
User Input via Keypad

    For those of you who have had experience with TI-83 Asm programming, you will note that the below program looks familiar. That's because it is the exact same program from tutorial 7 in James Matthew's Asmguru! This proves that TI-83 Asm programs will run on a TI-83 Plus with just a few minor changes. Therefore I assume no responsibility for writing this program, just porting it. This program takes user input from the TI's key pad to move a dot about the screen. Sort of like a small sprite! This program uses Getkey (Tutorial 8) call. Only this time we've narrowed the area in which getkey scans the keyboard to the Arrow keys and the clear key.

Here we go...

#define B_CALL(xxxx)           rst 28h \ .dw xxxx
#define B_JUMP(xxxx)           call 50h \ .dw xxxx

_RunIndicOff   = 4570h
_IPoint             = 47E3h
_getkey           = 4972h
_clrlcdfull                     = 4540h
_homeup                     = 4558h

#DEFINE kLeft>       02h
#DEFINE kRight      01h
#DEFINE kUp         03h
#DEFINE kDown       04h                  ;All these guys are hex codes
#DEFINE kEnter      05h                   ;for keys on the Ti-keyboard.
#DEFINE kClear      09h

.org 9D95h
            B_CALL(_clrLCDFull)           ;Clear the screen.
            ld b,47
            ld c,47
            ld d,1                           ;Set D to 1.

B_CALL(_runIndicOff)           ;Turn off run indicatorDésactive l'indicateur d'exécution.
            B_CALL(_getKey)                       ;Asked for a key.
            cp kLeft   ;Compare ky with code for left
            jp z,Left                                   ;If equale 0, go to left.
            cp kRight
            jp z,Right
            cp kUp
            jp z,Up
            cp kDown
            jp z,Down
            cp kClear
            jp z,Quit
            jp GetKey
            ld d,0                           ;Set D to 0.
            dec b                           ;Decrement B
            jp Draw
            ld d,0
            inc b
            jp Draw
            ld d,0
            inc c
            jp Draw
            ld d,0
            dec c
            jp Draw

ld d,1
            jp GetKey                               ;Repeat
            ret                                           ;Return to OS.


Note: You may want to set your calc's graph to ZInteger because ZStandard may interfere with the axis.


New Commands
cp - Compares with accumulator.
    jr - The ASM equivalent to If xx then jump to xxxxxx
    jp - Same as above, except very different
    _ipoint - Turns a point on/off/switch or tests.

    What's the difference between Call and jp/jr? Call is a z80 instruction that jumps to a sub-routine, a label with specified calls and instructions. What about jp/jr? Well I'm going to let James Matthews explain that.

    "What is the difference between jr and jp? There is one massive difference. JR is a relative jump - meaning, when TASM compiles it, the instruction for the Z80 simply tells it how many bytes forward or backward to jump.  Thus, jr has a limited range.  jp on the other hand is an absolute jump - tells the Z80 the address to jump to. The advantage of JR over JP is the file size is smaller and faster once compiled.  (Thank you to Mindless Productions for this information.) Harper told me that jr is a small jump (up to 128 bytes), and jp is a large jump (up to 32K- the whole RAM, basically!)."

- James Matthews

Not yet comfortable with Registers? Take a look at Andy S.' 83 Asm tutorials in Tutorial 4! Or look in tutorial 17 in this help file. Now let's get moving!



Tutorial 15

    Click to return to the site's menu... or here to get back to the tutorial's menu.