diff --git a/c64/,,config_generic.s b/c64/,,config_generic.s index bfe8029d..2659f198 100644 --- a/c64/,,config_generic.s +++ b/c64/,,config_generic.s @@ -6,7 +6,7 @@ // // Idea: -// - sane defaults for the original Commodore 64 machine +// - sane defaults for the original Commodore 64/128 machines // - do not enable features which are a significant compatibility risk @@ -49,6 +49,7 @@ // #define CONFIG_LEGACY_SCNKEY // XXX document this +#define CONFIG_KEYBOARD_C128 // XXX document this // #define CONFIG_KEY_REPEAT_DEFAULT // XXX document this // #define CONFIG_KEY_REPEAT_ALWAYS // XXX document this #define CONFIG_KEY_FAST_SCAN // XXX document this diff --git a/c64/,,config_mega65.s b/c64/,,config_mega65.s index 8f874fb1..3fce219e 100644 --- a/c64/,,config_mega65.s +++ b/c64/,,config_mega65.s @@ -51,6 +51,7 @@ #define CONFIG_LEGACY_SCNKEY // XXX document this +// #define CONFIG_KEYBOARD_C128 // XXX document this // #define CONFIG_KEY_REPEAT_DEFAULT // XXX document this // #define CONFIG_KEY_REPEAT_ALWAYS // XXX document this #define CONFIG_KEY_FAST_SCAN // XXX document this diff --git a/c64/,,config_ultimate64.s b/c64/,,config_ultimate64.s index 9b37ebab..f1f55f9d 100644 --- a/c64/,,config_ultimate64.s +++ b/c64/,,config_ultimate64.s @@ -49,6 +49,7 @@ // #define CONFIG_LEGACY_SCNKEY // XXX document this +// #define CONFIG_KEYBOARD_C128 // XXX document this // #define CONFIG_KEY_REPEAT_DEFAULT // XXX document this // #define CONFIG_KEY_REPEAT_ALWAYS // XXX document this #define CONFIG_KEY_FAST_SCAN // XXX document this diff --git a/c64/kernal/keyboard/kb_matrix_bucky.s b/c64/kernal/keyboard/kb_matrix_bucky.s index 32150a3a..8b658609 100644 --- a/c64/kernal/keyboard/kb_matrix_bucky.s +++ b/c64/kernal/keyboard/kb_matrix_bucky.s @@ -16,6 +16,28 @@ kb_matrix_bucky_confmask: // values to be written to CIA1_PRA .byte %10111111 // SHIFT (right) .byte %01111111 // VENDOR .byte %01111111 // CTRL +#if CONFIG_KEYBOARD_C128 + .byte %11111111 // C128 extra keys + .byte %11111111 +#endif + + +__kb_matrix_bucky_confmask_end: + + +#if CONFIG_KEYBOARD_C128 + +kb_matrix_bucky_confmask_c128: // values to be written to VIC_XSCAN + + .byte %11111111 + .byte %11111111 + .byte %11111111 + .byte %11111111 + + .byte %11111011 // ALT + .byte %11111011 // NO_SCRL + +#endif kb_matrix_bucky_testmask: // for AND with CIA1_PRB value @@ -24,13 +46,22 @@ kb_matrix_bucky_testmask: // for AND with CIA1_PRB value .byte %00010000 // SHIFT (right) .byte %00100000 // VENDOR .byte %00000100 // CTRL +#if CONFIG_KEYBOARD_C128 + .byte %10000000 // ALT + .byte %00000001 // NO_SCRL +#endif kb_matrix_bucky_shflag: // mask to be ORed to SHFLAG to mark key status + .byte KEY_FLAG_SHIFT .byte KEY_FLAG_SHIFT .byte KEY_FLAG_VENDOR .byte KEY_FLAG_CTRL +#if CONFIG_KEYBOARD_C128 + .byte KEY_FLAG_ALT + .byte KEY_FLAG_NO_SCRL +#endif #endif // no CONFIG_LEGACY_SCNKEY diff --git a/c64/kernal/keyboard/keyboard_disconnect.s b/c64/kernal/keyboard/keyboard_disconnect.s index 12708fb6..37f4e973 100644 --- a/c64/kernal/keyboard/keyboard_disconnect.s +++ b/c64/kernal/keyboard/keyboard_disconnect.s @@ -8,5 +8,8 @@ keyboard_disconnect: ldx #$FF stx CIA1_PRA // disconnect all the rows +#if CONFIG_KEYBOARD_C128 + stx VIC_XSCAN +#endif rts diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index c4454dd2..60a72767 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -21,7 +21,7 @@ // - RPTFLG - whether key repeat is allowed -// XXX add Commodore 128 keyboard support +// XXX finish Commodore 128 keyboard support // XXX add Commodore 65 keyboard support @@ -40,14 +40,15 @@ SCNKEY: lda #$00 sta SHFLAG - // XXX retrieve ALT and NO_SCRL status for C128/C65 keyboards - // Check for any activity #if !CONFIG_JOY2_CURSOR && CONFIG_KEY_FAST_SCAN ldx #$00 stx CIA1_PRA // connect all the rows +#if CONFIG_KEYBOARD_C128 + stx VIC_XSCAN +#endif dex // puts $FF cpx CIA1_PRB beq scnkey_no_keys @@ -56,10 +57,15 @@ SCNKEY: // Retrieve SHIFT / VENDOR / CTRL status // Use .X to detect 2 or more keys pressed (should be $FF now) - ldy #$03 + + ldy #(__kb_matrix_bucky_confmask_end - kb_matrix_bucky_confmask - 1) scnkey_bucky_loop: lda kb_matrix_bucky_confmask, y sta CIA1_PRA +#if CONFIG_KEYBOARD_C128 + lda kb_matrix_bucky_confmask_c128, y + sta VIC_XSCAN +#endif lda kb_matrix_bucky_testmask, y and CIA1_PRB bne !+ // not pressed @@ -76,8 +82,6 @@ scnkey_bucky_loop: #if CONFIG_JOY2_CURSOR - // XXX why this does not work ??? - // Check for control port 2 activity ldx #$00 @@ -97,6 +101,9 @@ scnkey_bucky_loop: inx // puts $00 stx CIA1_PRA // connect all the rows +#if CONFIG_KEYBOARD_C128 + stx VIC_XSCAN +#endif dex // puts $FF cpx CIA1_PRB beq scnkey_no_keys @@ -169,9 +176,13 @@ scnkey_no_keys: // Mark no key press - lda #$40 // XXX adapt value for C128 and C65 keyboards - sta LSTX +#if CONFIG_KEYBOARD_C128 + lda #$FF // non-standard, but for C128 keyboard $40 is a valid position +#else + lda #$40 +#endif + sta LSTX rts #if CONFIG_JOY1_CURSOR @@ -231,8 +242,6 @@ scnkey_got_key: // .Y should now contain the key offset in matrix pointed by KEY // // 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 @@ -244,7 +253,7 @@ scnkey_output_key: lda NDX cmp XMAX - bcs scnkey_early_repeat // no space in buffer XXX set timer to trigger repeat the next time + bcs scnkey_early_repeat // no space in buffer // Reinitialize secondary counter