diff --git a/kernel/nintendo/keyboard.s b/kernel/nintendo/keyboard.s index 2d5ae1f..5df5a85 100644 --- a/kernel/nintendo/keyboard.s +++ b/kernel/nintendo/keyboard.s @@ -79,6 +79,13 @@ key_delay: .byte $00 ; TODO: check if a keyboard is actually connected. +; burn some cycles to give the keyboard time to settle. +keyb_delay: + ldy #10 + - dey + bne - + rts + ; interrupt routine, that scans for keys keyb_scan: ; our current key table offset encodes where we are in the scanning process. @@ -101,6 +108,7 @@ read_keyboard: ; reset the keyboard to the 0th row, 0th column. lda #$05 sta JOYPAD1 + jsr keyb_delay ; this may not be strictly necessary but it's safer and only wastes a few cycles. ; reset keytab_offset to 0 ldx #0 stx keytab_offset @@ -115,6 +123,7 @@ get_nibble: ; always set the keyboard enable bit. ora #%00000100 sta JOYPAD1 + jsr keyb_delay ; read 4 bits of key data from the keyboard. lda JOYPAD2 diff --git a/kernel/nintendo/keyboard_init.s b/kernel/nintendo/keyboard_init.s index 518c871..7b25dd5 100644 --- a/kernel/nintendo/keyboard_init.s +++ b/kernel/nintendo/keyboard_init.s @@ -16,26 +16,41 @@ ;; initialize and install keyboard scanning routine keyboard_init: ; check that a keyboard is attached. - ; reset the keyboard to the 0th row, 0th column. lda #$05 sta JOYPAD1 - ; toggle the column select bit until we reach the keyless 10th row. + ; give the keyboard some time to reset. + nop + nop + nop + nop + nop + nop + + ; toggle the column select bit until we reach the last column of the 9th row. + ldx #9 + - lda #$04 + sta JOYPAD1 + jsr _delay lda #$06 - ldx #$04 - ldy #18 - - sta JOYPAD1 - stx JOYPAD1 - dey + sta JOYPAD1 + jsr _delay + dex bne - + ; select the keyless 10th row. + lda #$04 + sta JOYPAD1 + jsr _delay + ; check that the keyboard responds correctly to enable/disable signals. lda JOYPAD2 and #$1e eor #$1e bne _printmsg ; branch on error sta JOYPAD1 + jsr _delay lda JOYPAD2 and #$1e bne _printmsg ; branch on error @@ -60,8 +75,15 @@ _printmsg: bne - + rts +; burn some cycles to give the keyboard time to settle. +_delay: + ldy #10 + - dey + bne - + rts + _startmsg: - .text "Family BASIC Keyboard module version 0.3" + .text "Family BASIC Keyboard module version 0.4" .byte $0a _errormsg: .text "No Keyboard" diff --git a/lunix.fds b/lunix.fds index 6ebf1cb..2033b89 100644 Binary files a/lunix.fds and b/lunix.fds differ