Personally, for games, I read from the appropriate input port(s) as required.
The keyboard is split into 8 sections - 4 'half rows' on each side, and each with a unique port number.
Below are those 8 rows, each beginning with the port number:
$FE - SHIFT, Z, X, C, & V
$FD - A, S, D, F, & G
$FB - Q, W, E, R, & T
$F7 - 1, 2, 3, 4, & 5
$EF - 0, 9, 8, 7, & 6
$DF - P, O, I, U, & Y
$BF - ENTER, L, K, J, & H
$7F - SPACE, FULL-STOP, M, N, & B
To read from a port is simple:
Code: Select all
LD A, <port number as above>
IN A, ($FE)
The value returned in the accumulator has a bit set for each key which ISN'T held, starting from bit 0 for the first of the five keys, up to bit 4 for the last.
For example, to check if K is held:
Code: Select all
LD A, $BF
IN A, ($FE)
BIT 2, A
JP Z, <address of routine to call if K is held>
Also, port #0 can be used to tell if
any keys are held.