| Routines

031E: THE 'K-TEST' SUBROUTINE

Used by the routines at KEYBOARD and S_INKEY. The key value is tested and a return made if 'no-key' or 'shift-only'; otherwise the 'main code' for that key is found.
Input
D | Shift key pressed (+18 or +27), or +FF if no shift key pressed
E | Other key pressed (+00 to +27), or +FF if no other key pressed
Output
A | Main code (from the main key table)
F | Carry flag reset if an invalid combination of keys is pressed
K_TEST | 031E | LD B,D | Copy the shift byte.
| 031F | LD D,$00 | Clear the D register for later.
| 0321 | LD A,E | Move the key number.
| 0322 | CP $27 | Return now if the key was 'CAPS SHIFT' only or 'no-key'.
| 0324 | RET NC
| 0325 | CP $18 | Jump forward unless the E key was SYMBOL SHIFT.
| 0327 | JR NZ,K_MAIN
| 0329 | BIT 7,B | However accept SYMBOL SHIFT and another key; return with SYMBOL SHIFT only.
| 032B | RET NZ
The 'main code' is found by indexing into the main key table.
K_MAIN | 032C | LD HL,$0205 | The base address of the main key table.
| 032F | ADD HL,DE | Index into the table and fetch the 'main code'.
| 0330 | LD A,(HL)
| 0331 | SCF | Signal 'valid keystroke' before returning.
| 0332 | RET