Two short demonstrations from Ian Logan’s article on reading the ZX81 keyboard from machine code. The Key-Value Demonstrator scrolls up the screen showing the key you are pressing and the value in the system variable LAST K: 65535 for no key, 65015 for 1, 64503 for 2, and so on, the values a SLOW-mode machine-code program can test for.
The second program is Logan’s FAST/SLOW keyboard scanning routine, a copy of Sinclair’s own method that handles multiple keys and debounce. The BASIC POKEs the 36 bytes from a hex string into the line 10 REM, then calls it in a loop, so each key you press is printed down the screen.
[Editor’s note: as printed, the routine ends 46 75 D7 C9, which prints the wrong characters. The file in the download ends 7E 00 D7 C9 (LD A,(HL) instead of LD B,(HL); LD (HL),L), which prints the key pressed as the article describes. Line 30 of the listing below is as printed.]
Published in Syntax July 1982 (Keyboard Scanning from Machine Code).
Source Code
KEY-VALUE DEMONSTRATOR
10 SCROLL
20 PRINT INKEY$;TAB 7;PEEK 16421+256*PEEK 16422
30 GOTO 10
FAST/SLOW KEYBOARD SCANNING
10 REM 123456789012345678901234567890123456
20 REM NOW ENTER THE ROUTINE
30 LET A$="213B40CB7ECC2902CB4628FCED4B2540CBC0FDCB3B863EFF322740CDBD0730E04675D7C9"
40 FOR A=1 TO 36
50 POKE 16513+A,16*(CODE A$(A*2-1)-28)+CODE A$(A*2)-28
60 NEXT A
100 REM NOW CALL THE ROUTINE
110 SCROLL
120 RAND USR 16514
130 GOTO 100Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

