Prev: FEA9 Up: Map Next: FF2C
FF0C: Scans the keyboard matrix for a single currently-held key
Walks the classic 8 half-row ports ($FEFE, $FDFE, ..., $7FFE, rotating the row-select byte in B via RLC). D starts at $FF and is incremented once per row found to have any key held, then overwritten with the key's bit-position within its row (via the SRL/JR NC shift-count at $FF1D-$FF21); E counts down the row number. Returns NZ (an early RET NZ at $FF1A/$FF23) if more than one row has a key held (reject as ambiguous); otherwise always returns with Z set (via the unconditional CP A at $FF2A) and the caller (read_new_key_definition) tells "no key" from "one key" by checking whether D is still $FF.
Used by the routine at read_new_key_definition.
scan_keyboard_matrix FF0C LD DE,$FF2F
FF0F LD BC,$FEFE
scan_keyboard_matrix_0 FF12 IN A,(C)
FF14 CPL
FF15 AND $1F
FF17 JR Z,scan_keyboard_matrix_2
FF19 INC D
FF1A RET NZ
FF1B LD H,A
FF1C LD A,E
scan_keyboard_matrix_1 FF1D SUB $08
FF1F SRL H
FF21 JR NC,scan_keyboard_matrix_1
FF23 RET NZ
FF24 LD D,A
scan_keyboard_matrix_2 FF25 DEC E
FF26 RLC B
FF28 JR C,scan_keyboard_matrix_0
FF2A CP A
FF2B RET
Prev: FEA9 Up: Map Next: FF2C