From 643de3a8b7a245e240b9445c76e0596c26527162 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Mon, 14 Oct 2019 19:58:59 +0200 Subject: [PATCH] new SCNKEY can now use joystick port 1 --- c64/,,config_generic.s | 12 ++++-- c64/,,config_mega65.s | 12 ++++-- c64/,,config_ultimate64.s | 12 ++++-- c64/kernal/cint_real.s | 4 ++ c64/kernal/keyboard/kb_matrix_joy.s | 38 +++++++++++++++++++ c64/kernal/keyboard/scnkey.s | 57 +++++++++++++++++++++-------- 6 files changed, 111 insertions(+), 24 deletions(-) create mode 100644 c64/kernal/keyboard/kb_matrix_joy.s diff --git a/c64/,,config_generic.s b/c64/,,config_generic.s index 60c34491..049ac84b 100644 --- a/c64/,,config_generic.s +++ b/c64/,,config_generic.s @@ -45,6 +45,15 @@ // #define CONFIG_SID_D5XX +// Keyboard settings + + +// #define CONFIG_SCNKEY_TWW_CTR // XXX document this +// #define CONFIG_KEY_REPEAT // XXX document this +#define CONFIG_JOY1_CURSOR // XXX document this +#define CONFIG_JOY2_CURSOR // XXX document this + + // Eye candy // #define CONFIG_BANNER_SIMPLE @@ -58,9 +67,6 @@ #define CONFIG_PANIC_SCREEN #define CONFIG_DOS_WEDGE #define CONFIG_BCD_SAFE_INTERRUPTS -// #define CONFIG_SCNKEY_TWW_CTR // XXX document this -#define CONFIG_JOY1_CURSOR // XXX document this -#define CONFIG_JOY2_CURSOR // XXX document this // Debug options diff --git a/c64/,,config_mega65.s b/c64/,,config_mega65.s index 8f94243e..0bc2c86c 100644 --- a/c64/,,config_mega65.s +++ b/c64/,,config_mega65.s @@ -47,6 +47,15 @@ // #define CONFIG_SID_D5XX +// Keyboard settings + + +#define CONFIG_SCNKEY_TWW_CTR // XXX document this +// #define CONFIG_KEY_REPEAT // XXX document this +#define CONFIG_JOY1_CURSOR // XXX document this +#define CONFIG_JOY2_CURSOR // XXX document this + + // Eye candy // #define CONFIG_BANNER_SIMPLE @@ -60,9 +69,6 @@ #define CONFIG_PANIC_SCREEN #define CONFIG_DOS_WEDGE #define CONFIG_BCD_SAFE_INTERRUPTS -#define CONFIG_SCNKEY_TWW_CTR // XXX document this -#define CONFIG_JOY1_CURSOR // XXX document this -#define CONFIG_JOY2_CURSOR // XXX document this // Debug options diff --git a/c64/,,config_ultimate64.s b/c64/,,config_ultimate64.s index 6a1a0e5b..aa0ce73d 100644 --- a/c64/,,config_ultimate64.s +++ b/c64/,,config_ultimate64.s @@ -45,6 +45,15 @@ #define CONFIG_SID_D5XX +// Keyboard settings + + +// #define CONFIG_SCNKEY_TWW_CTR // XXX document this +#define CONFIG_KEY_REPEAT // XXX document this +#define CONFIG_JOY1_CURSOR // XXX document this +#define CONFIG_JOY2_CURSOR // XXX document this + + // Eye candy // #define CONFIG_BANNER_SIMPLE @@ -58,9 +67,6 @@ #define CONFIG_PANIC_SCREEN #define CONFIG_DOS_WEDGE #define CONFIG_BCD_SAFE_INTERRUPTS -// #define CONFIG_SCNKEY_TWW_CTR // XXX document this -#define CONFIG_JOY1_CURSOR // XXX document this -#define CONFIG_JOY2_CURSOR // XXX document this // Debug options diff --git a/c64/kernal/cint_real.s b/c64/kernal/cint_real.s index 8a214d1f..3a096a63 100644 --- a/c64/kernal/cint_real.s +++ b/c64/kernal/cint_real.s @@ -75,9 +75,13 @@ cint_brk: // entry for BRK and STOP+RESTORE - XXX, where should it start? // Enable cursor repeat - XXX make it configurable +#if CONFIG_KEY_REPEAT + lda #$80 sta RPTFLG +#endif + // Set keyboard decode vector (Compute's Mapping the 64 p215) #if CONFIG_SCNKEY_TWW_CTR diff --git a/c64/kernal/keyboard/kb_matrix_joy.s b/c64/kernal/keyboard/kb_matrix_joy.s new file mode 100644 index 00000000..50c9d501 --- /dev/null +++ b/c64/kernal/keyboard/kb_matrix_joy.s @@ -0,0 +1,38 @@ + +// +// Matrix for retrieving C64 joystick status and inject is as keyboard event +// + + +#if !CONFIG_SCNKEY_TWW_CTR && (CONFIG_JOY1_CURSOR || CONFIG_JOY2_CURSOR) + + +kb_matrix_joy_status: + + .byte %00001110 // up + .byte %00001101 // down + .byte %00001011 // left + .byte %00000111 // right + +kb_matrix_joy_keytab_idx: + + .byte $07 // up + .byte $07 // down + .byte $02 // left + .byte $02 // right + +kb_matrix_joy_keytab_lo: + + .byte <__kb_matrix_shift // up + .byte <__kb_matrix_normal // down + .byte <__kb_matrix_shift // left + .byte <__kb_matrix_normal // right + +kb_matrix_joy_keytab_hi: + + .byte >__kb_matrix_shift // up + .byte >__kb_matrix_normal // down + .byte >__kb_matrix_shift // left + .byte >__kb_matrix_normal // right + +#endif diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index d79f183f..05ef1b54 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -23,7 +23,7 @@ // XXX add Commodore 128 keyboard support // XXX add Commodore 65 keybopard support -// XXX add support for using joysticks to move cursor keys +// XXX fix support for joystick port 2 to move cursor keys // XXX add support for keys which are repeated always @@ -72,14 +72,9 @@ scnkey_bucky_loop: jsr via_keylog // XXX for some CPUs we have indirect jsr - // Check if KEYTAB is not 0 (happens if more than one bucky key is pressed) - // High byte equal to 0 = table considered invalid - lda KEYTAB+1 - beq scnkey_no_keys - #if CONFIG_JOY2_CURSOR - // XXX why this does not work??? + // XXX why this does not work // Check for control port 2 activity @@ -92,7 +87,8 @@ scnkey_bucky_loop: // stx CIA1_DDRA // set port back to output // and #%00001111 // filter out anything but joystick movement - // bne scnkey_joystick_a_filtered + // cmp #%00001111 + // bne scnkey_joystick_filtered #endif @@ -101,11 +97,17 @@ scnkey_bucky_loop: jsr keyboard_disconnect // disconnect all the rows, .X will be $FF cpx CIA1_PRB // only control port activity will be reported #if CONFIG_JOY1_CURSOR - bne scnkey_joystick_x // use joystick for cursor keys + bne scnkey_joystick_1 // use joystick for cursor keys #else bne scnkey_no_keys // if activity detected do not scan the keyboard #endif + // Check if KEYTAB is not 0 (happens if more than one bucky key is pressed) + // High byte equal to 0 = table considered invalid + + lda KEYTAB+1 + beq scnkey_no_keys + // Scan the keyboard matrix ldy #$FF // offset in key matrix table, $FF for not found yet @@ -159,22 +161,46 @@ scnkey_no_keys: rts -#if CONFIG_JOY1_CURSOR || CONFIG_JOY2_CURSOR +#if CONFIG_JOY1_CURSOR -scnkey_joystick_x: +scnkey_joystick_1: - // Handle joystick activity (in .X) as cursor keys + // Prepare joystick 1 status - txa + lda CIA1_PRB and #%00001111 // filter out anything but movement // FALLTROUGH -scnkey_joystick_a_filtered: +#endif - // XXX finish the implementation +#if CONFIG_JOY1_CURSOR || CONFIG_JOY2_CURSOR + +scnkey_joystick_filtered: + + // Set appropriate keyboard matrix and key code for joystick event + + ldy #$03 +!: + cmp kb_matrix_joy_status, y + beq !+ + dey + bpl !- + + // Not found rts +!: + // Found + + lda kb_matrix_joy_keytab_lo, y + sta KEYTAB+0 + lda kb_matrix_joy_keytab_hi, y + sta KEYTAB+1 + lda kb_matrix_joy_keytab_idx, y + tay + + // FALLTROUGH #endif @@ -228,6 +254,7 @@ scnkey_done: scnkey_handle_repeat: // Check whether we should repeat keys + // XXX always repeat SPACE, cvursors, ins/del lda RPTFLG bpl scnkey_done // branch if we should do no repeat