.include "ps2_keyboard_simple_handler.h65" Export skb, init, scancode .bss previous_scancode: .res 1 ; all 1 if previous_scancode is break scancode: .res 1 .code ;;******************************************************************************** ;; @function Initialize the keyboard handler ;; @returns Z: Z = 1 => success, Z = 0 => failure ;; @details ;; Initializes the PS/2 keyboard driver and the handler. ;; If any PS/2 command fails, init returns with Z = 0. The failed command (and parameter) can be loaded from `ps2kb::send_cmd` and `ps2kb::send_data` ;; After init, the keyboard will be able to send scancodes. ;;******************************************************************************** .proc init stz scancode stz previous_scancode jsr ps2kb::init ; init & reset ps2kb_CmdSelfTest ps2kb_WaitFinishCmd lda ps2kb::cmd_response+1 cmp #$aa bne fail ; set set 3 ps2kb_CmdSetScancodeSet 3 ps2kb_WaitFinishCmd lda ps2kb::cmd_response+1 cmp #ps2kb::ACK bne fail ps2kb_CmdEnable ps2kb_WaitFinishCmd lda ps2kb::cmd_response cmp #ps2kb::ACK bne fail StoreDByte process_scancode, ps2kb::scancode_handler jsr ps2kb::begin_receive lda #0 ; set Z = success fail: rts .endproc ;;******************************************************************************** ;; @function Process a scancode ;; @details ;; If it is a 'make' scancode, store it in skb::scancode ;; If the key is not a mod key, the keycode is stored in kb::keycode ;; If the key is an ascii character, the corresponding ascii character is stored in kb::char ;; @param X: The scancode ;; @modifies A, X, Y ;;******************************************************************************** .proc process_scancode ; check how this scancode needs to be interpreted bit previous_scancode jmi break_key ; bit 7 set = BREAK lda ps2kb::scancode cmp #skb::K_BREAK beq @break_scancode sta scancode rts @break_scancode: lda #$ff sta previous_scancode rts break_key: stz previous_scancode rts .endproc