Experimental 8x8 Encoded Matrix Keyboard ======================================== Layout modified making the cursor keys easier to process D0 D1 D2 D3 D4 D5 D6 D7 | | | | | | | | +-+---+---+---+---+---+---+---+-+ IORQ--+---\ | | RD---+ OR >-+-----+EN 74LS245 | PORT--+---/ | | | | +-+---+---+---+---+---+---+---+-+ | | | | | | | | | +--+--+ | | | | | | | | Part-processed keypress A8 -->---+ EN +-- SHF CTL LCK CPY 00 01 05 06 07 A9 -->---+ 7 +-- LFT RGT DWN UP TAB RET ESC SPC 08 09 0A 0B 0C 0D 0E 0F A10 -->---+ 4 +-- 0 1 2 3 4 5 6 7 30 31 32 33 34 35 36 37 A11 -->---+ L +-- 8 9 : ; . - , / 38 39 3A 3B 3C 3D 3E 3F A12 -->---+ S +-- @ A B C D E F G 40 41 42 43 44 45 46 47 A13 -->---+ 2 +-- H I J K L M N O 48 49 4A 4B 4C 4D 4E 4F A14 -->---+ 4 +-- P Q R S T U V W 50 51 52 53 54 55 56 57 A15 -->---+ 5 +-- X Y Z [ \ ] ^ DEL 58 59 5A 5B 5C 5D 5E 5F +-----+ This gives raw keypress: C7-C0 D7-D0 +--+--+--+--+--+--+--+--+ | | | : : | : : | -> add &20 ASCII code &20-&5F requiring +--+--+--+--+--+--+--+--+ some processing, eg: ; Typical keyscan code, positive logic ; ------------------------------------ LD BC,&80FD ; keyboard port &FD, row 7 selected .scanLoop1 IN A,(BC):AND A:JR NZ,scanPressed ; a key is pressed ROR B:JR NC,scanLoop1 ; select next row, loop until '1' falls out RET ; Carry set, no key pressed ; Typical keyscan code, negative logic ; ------------------------------------ LD BC,&7FFD ; keyboard port &FD, row 7 selected .scanLoop1 IN A,(BC):CPL:JR NZ,scanPressed ; a key is pressed ROR B:JR C,scanLoop1 ; select next row, loop until '0' falls out RET ; Carry clear, no key pressed ; Key pressed, convert to key number ; ---------------------------------- .scanPressed LD C,A:LD A,&F7 ; start at -9 .scanLoop2 INC A:LSR C:JR NC,scanLoop2 ; loop until a bit falls out of column byte ; ; A is now &F8...&FF .scanLoop3 ADD A,8:LSR B:JR NC,scanLoop3 ; loop until a bit falls out row select ; ; A is now &00-&3F LD BC,&01FD:IN B,(BC) ; read modifier keys if positive logic LD BC,&FEFD:IN B,(BC) ; read modifier keys if negative logic ; ; A =raw keycode &00-&3F ; B =modifiers, b0=SHIFT, b1=CONTROL ; Experimental Spectrum keyboard as built ======================================= Addressed with 16-port multiplexor: D0 D1 D2 D3 D4 D5 D6 D7 Raw keypress | | | | | | | | C0 - SHF CTL TAB LFT RGT DWN UP 00 01 03 04 05 06 07 C1 - LCK CPY RET ESC SPC 0B 0C 0D 0E 0F C6 - 0 1 2 3 4 5 6 7 30 31 32 33 34 35 36 37 C7 - 8 9 : ; . - , / 38 39 3A 3B 3C 3D 3E 3F C8 - @ A B C D E F G 40 41 42 43 44 45 46 47 C9 - H I J K L M N O 48 49 4A 4B 4C 4D 4E 4F C10 - P Q R S T U V W 50 51 52 53 54 55 56 57 C11 - X Y Z [ \ ] ^ DEL 58 59 4A 5B 5C 5D 5E 5F Raw keypress: C15-C0 D7-D0 +--+--+--+--+--+--+--+--+ | | : : : | : : | -> gives ASCII code &00-&0F and &30-&5F +--+--+--+--+--+--+--+--+ for minor processing, eg: