From 183ac3ab870bc365ebd58131815f843c75c0ba37 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 13 Oct 2019 22:50:25 +0200 Subject: [PATCH] new SCNKEY is useable (but is still buggy and incomplete) --- c64/kernal/cint_real.s | 6 ++++++ c64/kernal/keyboard/kb_matrix.s | 5 +---- c64/kernal/keyboard/kb_matrix_bucky_filter.s | 10 ++++----- c64/kernal/keyboard/kb_matrix_row_keys.s | 14 ++++++------- c64/kernal/keyboard/scnkey.s | 22 +++++++++++++------- c64/kernal/keyboard/scnkey_set_keytab.s | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/c64/kernal/cint_real.s b/c64/kernal/cint_real.s index d680f2df..8a214d1f 100644 --- a/c64/kernal/cint_real.s +++ b/c64/kernal/cint_real.s @@ -68,10 +68,16 @@ cint_brk: // entry for BRK and STOP+RESTORE - XXX, where should it start? jsr setup_vicii // Initialise cursor blink flags (Compute's Mapping the 64 p215) + lda #$01 sta BLNCT sta BLNSW + // Enable cursor repeat - XXX make it configurable + + lda #$80 + sta RPTFLG + // Set keyboard decode vector (Compute's Mapping the 64 p215) #if CONFIG_SCNKEY_TWW_CTR diff --git a/c64/kernal/keyboard/kb_matrix.s b/c64/kernal/keyboard/kb_matrix.s index c1eeff70..e0e84114 100644 --- a/c64/kernal/keyboard/kb_matrix.s +++ b/c64/kernal/keyboard/kb_matrix.s @@ -13,10 +13,6 @@ // and converting the values -// XXX to be extra compatible (someone could change the KEYLOG), we should make sure -// we are using the same matrix format as the original ROM does - - kb_matrix: __kb_matrix_normal: @@ -61,6 +57,7 @@ __kb_matrix_ctrl: +// XXX extended matrices for C128/C65 // kb_matrix_ext128: $D02F diff --git a/c64/kernal/keyboard/kb_matrix_bucky_filter.s b/c64/kernal/keyboard/kb_matrix_bucky_filter.s index 1443df5e..21ebe02f 100644 --- a/c64/kernal/keyboard/kb_matrix_bucky_filter.s +++ b/c64/kernal/keyboard/kb_matrix_bucky_filter.s @@ -14,14 +14,14 @@ kb_matrix_bucky_filter: // values for OR with CIA1_PRB content to filter out bucky keys - .byte %00100100 // VENDOR + CONTROL - .byte %00010000 // SHIFT (right) - .byte %00000000 - .byte %00000000 - .byte %00000000 .byte %00000000 .byte %10000000 // SHIFT (left) .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00010000 // SHIFT (right) + .byte %00100100 // VENDOR + CONTROL #endif // no CONFIG_SCNKEY_TWW_CTR diff --git a/c64/kernal/keyboard/kb_matrix_row_keys.s b/c64/kernal/keyboard/kb_matrix_row_keys.s index df3a64f8..f4284108 100644 --- a/c64/kernal/keyboard/kb_matrix_row_keys.s +++ b/c64/kernal/keyboard/kb_matrix_row_keys.s @@ -15,14 +15,14 @@ kb_matrix_row_keys: // - values for CIA1_PRA to connect only the given row // - also used to scan a single row - .byte %01111111 - .byte %10111111 - .byte %11011111 - .byte %11101111 - .byte %11110111 - .byte %11111011 - .byte %11111101 .byte %11111110 + .byte %11111101 + .byte %11111011 + .byte %11110111 + .byte %11101111 + .byte %11011111 + .byte %10111111 + .byte %01111111 #endif // no CONFIG_SCNKEY_TWW_CTR diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index 89e7dea9..4c8689a5 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -24,7 +24,7 @@ // XXX add Commodore 128 keyboard support // XXX add Commodore 65 keybopard support // XXX add support for using joystick to move sursor keys -// XXX prevent joystick port 1 interference +// XXX explicitly prevent joystick port 1 interference #if !CONFIG_SCNKEY_TWW_CTR @@ -98,7 +98,7 @@ scnkey_matrix_loop_inner: cmp kb_matrix_row_keys, y bne !+ // not this particular key tya // now .A contains key offset within a row - sec + clc adc kb_matrix_row_offsets, x // now .A contains key offset from the matrix start tay jmp scnkey_matrix_loop_next @@ -111,7 +111,6 @@ scnkey_matrix_loop_next: bpl scnkey_matrix_loop // Scanning complete - cpy #$FF bne scnkey_got_key @@ -134,20 +133,27 @@ scnkey_got_key: // .Y should now contain the key offset in matrix pointed by KEY // Reset key repeat counters - see [CM64] page 58 - lda #$10 + // Note: according to [CM64] it should be $10 for initializing DELAY, $06 for + // initializing KOUNT for the first time and $04 for subsequent ones - but replicating + // this would make our implementation longer, probably without improving the compatibility. + // + // Besides - since I am the one who writes the code, I will make the values exactly how I like them :D + + // XXX consider making it configurable, also make configurable RPTFLG + + lda #$16 sta DELAY // FALLTROUGH scnkey_output_key: - // Reinitialize secondary couter + // Reinitialize secondary counter - lda #$06 + lda #$03 sta KOUNT // Output PETSCII code to the keyboard buffer - lda (KEYTAB), y beq scnkey_no_keys // branch if we have no PETSCII code for this key ldy NDX @@ -164,6 +170,8 @@ scnkey_handle_repeat: // Check whether we should repeat keys + // XXX some keys should be repeat always! + lda RPTFLG bpl scnkey_done // branch if we should do no repeat diff --git a/c64/kernal/keyboard/scnkey_set_keytab.s b/c64/kernal/keyboard/scnkey_set_keytab.s index eb26ff5d..27fcfef1 100644 --- a/c64/kernal/keyboard/scnkey_set_keytab.s +++ b/c64/kernal/keyboard/scnkey_set_keytab.s @@ -24,7 +24,7 @@ scnkey_set_keytab: lda kb_matrix_lookup, x // Add offset to the vector - sec + clc adc KEYTAB+0 sta KEYTAB+0 lda #$00