;PC Keyboard -> SAM Interface ;---------------------------- ;(C) 1995 Simon Cooke ;Equates: breakcode: EQU &F0 setleds: EQU &ED ;&ED,,XX, echo: EQU &EE ;&EE,<&EE> setscancode: EQU &F0 ;&F0,,XX, typerate: EQU &F3 ;&F3,,XX, enablekscan: EQU &F4 ;&F4, disablekscan: EQU &F5 ;&F5, setdefault: EQU &F6 ;&F6,ack allmaketype: EQU &F7 ;&f7,ack allmakebreak: EQU &F8 ;&f8,ack allmake: EQU &F9 ;&f9,ack allmtb: EQU &FA ;&fa,ack keymaketype: EQU &FB keymakebreak: EQU &FC keymake: EQU &FD resend: EQU &FE reset: EQU &FF readid: EQU &F2 testokay: EQU &AA keybrderror: EQU &FC ack: EQU &FA capsled: EQU %00000100 numlled: EQU %00000010 scrlled: EQU %00000001 ORG &8000 initialise: DI LD (errsp),SP ;keep stack in case of error JP initkeyboard initkeyboard: LD A,reset CALL send.command okayinitloop: CALL read.byte ;wait for the response CP testokay JR Z,testedgood JR initkeyboard ;Passed keyboard test... testedgood: ;set scan code set 3 LD A,setscancode CALL send.command LD A,&03 ;code set 3 CALL send.command ;(wait for ACK) ;set all keys to be make/break type LD A,allmakebreak CALL send.command ;reset all leds - just in case XOR A LD (makebreakstat),A ;make sure next code is a ;make - we've not received ;ANY data yet, much less a ;&F0 break code LD (leds),A CALL reset.capslock ;clear them all... main.loop: LD A,&7F IN A,(&FE) RRA RRA JP NC,badcrash ;let's ditch this CALL read.byte CP breakcode JR Z,togglebreak LD (newcode),A LD A,(makebreakstat) OR A JP NZ,break_key make_key: LD HL,main.loop PUSH HL ;return address LD A,(newcode) CP &14 JP Z,toggle.clock CP &76 JP Z,toggle.nlock CP &5F JP Z,toggle.slock POP HL break_key: XOR A LD (makebreakstat),A JR main.loop togglebreak: LD (makebreakstat),A JR main.loop ;LEDs... ;======= toggle.clock: LD A,setleds CALL send.command LD A,(leds) XOR capsled LD (leds),A CALL send.command RET set.capslock: LD A,setleds CALL send.command LD A,(leds) OR capsled LD (leds),A CALL send.command RET reset.capslock: LD A,setleds CALL send.command LD A,(leds) AND &FF-capsled LD (leds),A CALL send.command RET toggle.nlock: LD A,setleds CALL send.command LD A,(leds) XOR numlled LD (leds),A CALL send.command RET set.numlock: LD A,setleds CALL send.command LD A,(leds) OR numlled LD (leds),A CALL send.command RET reset.numlock: LD A,setleds CALL send.command LD A,(leds) AND &FF-numlled LD (leds),A CALL send.command RET toggle.slock: LD A,setleds CALL send.command LD A,(leds) XOR scrlled LD (leds),A CALL send.command RET set.scrllock: LD A,setleds CALL send.command LD A,(leds) OR scrlled LD (leds),A CALL send.command RET reset.scrllock: LD A,setleds CALL send.command LD A,(leds) AND &FF-scrlled LD (leds),A CALL send.command RET ;Deadly error handler ;==================== badcrash: LD SP,(errsp) EI RST &08 DEFB 10 ;some error... who knows? ;Other stuff ;=========== errsp: DEFW 0 leds: DEFB 0 makebreakstat: DEFB 0 newcode: DEFB 0 ** Error ** Disk error INC "keycomms.S" ;communication with keyboard