Prev: B74D Up: Map Next: B761
B759: Read a half-row of the keyboard
Knight Lore's routine, byte for byte. The IN does the selecting on its own: IN A,($FE) puts A on the top half of the address bus, so each 0 bit in A selects a half-row, and A = 0 reads all eight at once. The CPL turns the keys' active-low bits the right way up.
The OUT before it is not needed for the read. It writes A to port A*256+$FD, which nothing on a 48K Spectrum answers; a 128K machine's paging port would decode it whenever A has bit 7 clear (see Pentagram's READ_KEYS, where that was tried). Not tried with Alien 8.
Input
A the half-rows to read, as the port's high byte
Output
A the keys pressed, bits 0-4, a set bit for a key down
F Z set if none is
READ_KEYS B759 OUT ($FD),A not what selects the row: see above
B75B IN A,($FE) reads port A*256+$FE
B75D CPL set bits now mean pressed keys; keep the five
B75E AND $1F
B760 RET
Prev: B74D Up: Map Next: B761