diff --git a/c64/kernal/keyboard/kb_matrix.s b/c64/kernal/keyboard/kb_matrix.s index e0e84114..e681f9f3 100644 --- a/c64/kernal/keyboard/kb_matrix.s +++ b/c64/kernal/keyboard/kb_matrix.s @@ -54,21 +54,3 @@ __kb_matrix_ctrl: .byte $00,$10,$0C,$00,$00,$1B,$00,$00 .byte $1C,$00,$1D,$00,$00,$1F,$1E,$00 .byte $90,$06,$00,$05,$00,$00,$11,$00 - - - -// XXX extended matrices for C128/C65 - -// kb_matrix_ext128: $D02F - - // .byte (HELP),$38,$35,(TAB),$32,$34,$37,$31 // $FE - // .byte $1B, $2B, $2D,$0A,$0D,$36,$39,$33 // $FD - // .byte $00,$30,$2E,$91,$11,$9D,$1D,(NO_SCRL) // $FB - -// kb_matrix_ext65: - - // Last column - normal - // .byte (NO_SCRL),(TAB),$00,(HELP),(F9),(F11),(F13),$1B - - // Last column - shifted - // .byte (NO_SCRL),(TAB),$00,(HELP),(F10),(F12),(F14),$1B diff --git a/c64/kernal/keyboard/kb_matrix_128.s b/c64/kernal/keyboard/kb_matrix_128.s new file mode 100644 index 00000000..8afbef1a --- /dev/null +++ b/c64/kernal/keyboard/kb_matrix_128.s @@ -0,0 +1,30 @@ + +// +// Extended keyboard matrix for Commodore 128 keyboards, based on +// +// - [CM128] Compute's Mapping the Commodore 128 - page 290 +// - http://commodore128.mirkosoft.sk/keyboard.html +// + + +#if CONFIG_KEYBOARD_C128 + + +kb_matrix_128: + + // XXX fill-in the matrix properly!!! + .byte $41,$42,$43,$44,$45,$46,$47,$48 + .byte $51,$52,$53,$54,$55,$56,$57,$58 + .byte $61,$62,$63,$64,$65,$66,$67,$68 + +kb_matrix_128_bucky_filter: + + // values for OR with CIA1_PRB content to filter out bucky keys + + .byte %00000000 + .byte %00000000 + .byte %00000000 // XXX ALT, NO_SCRL - probably here + + + +#endif // CONFIG_KEYBOARD_C128 diff --git a/c64/kernal/keyboard/kb_matrix_bucky.s b/c64/kernal/keyboard/kb_matrix_bucky.s index 8b658609..4b685e0d 100644 --- a/c64/kernal/keyboard/kb_matrix_bucky.s +++ b/c64/kernal/keyboard/kb_matrix_bucky.s @@ -3,10 +3,10 @@ // Matrix for retrieving bucky key status on the C64 keyboard // // Values based on: -// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix) +// - [CM64] Compute's Mapping the Commodore 64 - pages 58 (SHFLAG), 173 (matrix) +// - [CM128] Compute's Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) // - #if !CONFIG_LEGACY_SCNKEY diff --git a/c64/kernal/keyboard/kb_matrix_row_keys.s b/c64/kernal/keyboard/kb_matrix_row_keys.s index cf09dfc7..bb4b9afb 100644 --- a/c64/kernal/keyboard/kb_matrix_row_keys.s +++ b/c64/kernal/keyboard/kb_matrix_row_keys.s @@ -13,6 +13,7 @@ kb_matrix_row_keys: // - values for CIA1_PRA to connect only the given row + // - first 3 values also meant for VIC_XSCAN for C128 keyboards // - also used to scan a single row .byte %11111110 diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index 60a72767..91698ef5 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -21,9 +21,6 @@ // - RPTFLG - whether key repeat is allowed -// XXX finish Commodore 128 keyboard support -// XXX add Commodore 65 keyboard support - #if !CONFIG_LEGACY_SCNKEY @@ -130,8 +127,11 @@ scnkey_bucky_loop: // Scan the keyboard matrix - ldy #$FF // offset in key matrix table, $FF for not found yet - ldx #$07 // XXX adapt for C128 and C65 keyboards + ldy #$FF // offset in key matrix table, $FF for not found yet +#if CONFIG_KEYBOARD_C128 + jsr scnkey_128 +#endif + ldx #$07 scnkey_matrix_loop: lda kb_matrix_row_keys, x sta CIA1_PRA @@ -261,6 +261,11 @@ scnkey_output_key: sta KOUNT // Output PETSCII code to the keyboard buffer +#if CONFIG_KEYBOARD_C128 + + // XXX implement C128 key matrix support here + +#endif lda (KEYTAB), y beq scnkey_no_keys // branch if we have no PETSCII code for this key ldy NDX diff --git a/c64/kernal/keyboard/scnkey_128.s b/c64/kernal/keyboard/scnkey_128.s new file mode 100644 index 00000000..e8f5a000 --- /dev/null +++ b/c64/kernal/keyboard/scnkey_128.s @@ -0,0 +1,77 @@ + +// +// Keyboard scanning routine extension for C128 keyboards +// +// - [CM128] Compute's Mapping the Commodore 128 - pages 212 (SHFLAG), 290 (matrix) +// + + +#if CONFIG_KEYBOARD_C128 + + +// Inlining this within SCNKEY would both overcomplicate the implementation +// and disrupt a lot of branches (they would cross the 127 bytes distance limit) + +// .Y is now $FF - try to put there a key code from extended keyboard + + +scnkey_128: + + sty CIA1_PRA // disconnect all the classic keys first + + ldx #$02 +scnkey_matrix_128_loop: + lda kb_matrix_row_keys, x + sta VIC_XSCAN + lda kb_matrix_128_bucky_filter, x // filter out bucky keys + ora CIA1_PRB + cmp #$FF + beq scnkey_matrix_128_loop_next // skip if no key pressed from this row + cpy #$FF + bne scnkey_128_no_keys // clash, more than one key pressed + // We have at least one key pressed in this row, we need to find which one exactly + ldy #$07 +scnkey_matrix_128_loop_inner: // XXX try to deduplicate this with regular SCNKEY + cmp kb_matrix_row_keys, y + bne !+ // not this particular key + tya // now .A contains key offset within a row + clc + adc kb_matrix_row_offsets, x // now .A contains key offset from the matrix start + tay + jmp scnkey_matrix_128_loop_next +!: + dey + bpl scnkey_matrix_128_loop_inner + bmi scnkey_128_no_keys // branch always, multiple keys must have been pressed +scnkey_matrix_128_loop_next: + dex + bpl scnkey_matrix_128_loop + + // Scanning the C128 keyboard part complete - check if we got a key + + cpy #$FF + beq scnkey_128_done + + // Shift the matrix code +.break + clc + tya + adc #$40 + tay + + // Continue with C64 keyboard scanning + +scnkey_128_done: + + rts + + +scnkey_128_no_keys: + + pla // get rid of return address from the stack + pla + + jmp scnkey_no_keys // pass controll to original routine + + +#endif // CONFIG_KEYBOARD_C128