Input

The main source of user input will be through the keypad, so almost every input routine will require use of a GetKey function.

Note: This page will need to have routines for actual user input aside from GetKey routines.

GetKey

This is essentially like several of the OS routines. If OS interrupts are read, you can also read from address 8445h. But if you really want a custom routine:

;===============================================================
GetKey:
;===============================================================
;Outputs:
;     A is a value from 0 to 56 that is the keypress
;    HL is not modified
;    BC is not modified
;Destroys:
;    D
;    E is destroyed if no keys are pressed, else it is also the keypress
;===============================================================
     ld de,$7FFF
KeyLoop:
     rlc d
     ld a,d
     out (1),a
     sub 7Fh
     ret z
     ld a,e
     add a,8
     ld e,a
     in a,(1)
     inc a
     jr z,KeyLoop
     dec a
       inc e
       rra
       jr c,$-2
     ld a,e
     ret

ScanAllKeys

This routine requires 7 bytes of RAM pointed to by HL. This will return the value of all the key groups, stored in each of the bytes:

ScanAllKeys:
;Inputs:
;     HL points to the 7 bytes to output the result to
;Notes:
;     There is not enough delay for 15MHz
     ld bc,0701h
     ld a,$FE      ;test the keys
KeyUpdateLoop:
     out (1),a
     rlca
     nop
     ini
     jr nz,KeyUpdateLoop
     ret
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.