diff --git a/CONFIG.md b/CONFIG.md index 0f0a1f3f..12699fbf 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -197,12 +197,6 @@ Each of them needs a couple of bytes in KERNAL segment - but they can share some Original keyboard support routine is just horrible. It does nothing to prevent ghosting - press A+S+D at the same time - it prints F. Try to use joystick connected to control port 1 - it outputs phantom characters. The Open ROMs provides much more sophisticated routines to prevent such problems. -### `LEGACY_SCNKEY` - -Uses old Open ROMs keyboard scanning routine, which is basically the example routine by TWW/CTR, hacked to work within Kernal. It's greatest advantage is multi-key rollover, it's disadvantages - it's much less compatible (uses several bytes of memory which are normally free for user software - thus, it is considered legacy for now), does not support all the system variables (`RPTFLG` and `KEYLOG` are unsupported), and ignores the configuration options - this can be changed, but it requires some effort. - -Needs 30-250 more space in KERNAL segment (depending on the features enabled for current default routine). If unsure - disable. - ### `KEYBOARD_C128` Allows to use additional keys found on the C128 keyboard. @@ -235,7 +229,7 @@ Needs 13 bytes more space in KERNAL segment. Only disable if you are running out ### `JOY1_CURSOR` and `JOY2_CURSOR` -Joystick movement also moves the cursor. +Use joystick to move the cursor. On MEGA65 applies to legacy mode only (on native mode there is BASIC command available to set this option in runtime). Needs about 65 bytes of ROM space in KERNAL segment to handle both joysticks. diff --git a/STATUS.md b/STATUS.md index 28b0ab74..b68d16e2 100644 --- a/STATUS.md +++ b/STATUS.md @@ -4,7 +4,7 @@ Here are the features of the Open ROMs not found in the original ROMs from the 80s (many of them are [configurable](CONFIG.md) during compilation): -* improved keyboard scanning, resistant to ghosting and joystick interference (one variant even supports multi-key rollover), supports additional C128 keys +* improved keyboard scanning, resistant to ghosting and joystick interference, supports additional C128 keys * joystick can be used to move text cursor * pre-defined function keys diff --git a/src/,,config_custom.s b/src/,,config_custom.s index aa03a16c..b692a05f 100644 --- a/src/,,config_custom.s +++ b/src/,,config_custom.s @@ -76,7 +76,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/,,config_generic.s b/src/,,config_generic.s index a2140f24..7eba194e 100644 --- a/src/,,config_generic.s +++ b/src/,,config_generic.s @@ -65,7 +65,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/,,config_generic_crt.s b/src/,,config_generic_crt.s index a3e60896..37dc7deb 100644 --- a/src/,,config_generic_crt.s +++ b/src/,,config_generic_crt.s @@ -67,7 +67,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/,,config_mega65.s b/src/,,config_mega65.s index ca8e5649..a14d3c59 100644 --- a/src/,,config_mega65.s +++ b/src/,,config_mega65.s @@ -45,7 +45,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO ;; #CONFIG# KEY_REPEAT_ALWAYS NO ;; #CONFIG# KEY_FAST_SCAN YES diff --git a/src/,,config_testing.s b/src/,,config_testing.s index dbeff3fc..17f271b4 100644 --- a/src/,,config_testing.s +++ b/src/,,config_testing.s @@ -65,7 +65,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY YES ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/,,config_ultimate64.s b/src/,,config_ultimate64.s index f729a50b..8a0b075d 100644 --- a/src/,,config_ultimate64.s +++ b/src/,,config_ultimate64.s @@ -55,7 +55,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/,,config_ultimate64_crt.s b/src/,,config_ultimate64_crt.s index 48cb09e2..710d5077 100644 --- a/src/,,config_ultimate64_crt.s +++ b/src/,,config_ultimate64_crt.s @@ -57,7 +57,6 @@ ; --- Keyboard settings -;; #CONFIG# LEGACY_SCNKEY NO ;; #CONFIG# KEYBOARD_C128 NO ;; #CONFIG# KEYBOARD_C128_CAPS_LOCK NO ;; #CONFIG# KEY_REPEAT_DEFAULT NO diff --git a/src/aliases/,aliases_config.s b/src/aliases/,aliases_config.s index 598244ad..d334a0d8 100644 --- a/src/aliases/,aliases_config.s +++ b/src/aliases/,aliases_config.s @@ -227,17 +227,9 @@ ; Check that keyboard settings are correct -!ifdef CONFIG_LEGACY_SCNKEY { - !ifdef CONFIG_RS232_UP2400 { !error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_RS232_UP2400" } - !ifdef CONFIG_RS232_UP9600 { !error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_RS232_UP9600" } - !ifdef CONFIG_TAPE_NORMAL { !error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_TAPE_NORMAL" } - !ifdef CONFIG_KEYBOARD_C128 { !error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_KEYBOARD_C128" } - !ifdef CONFIG_KEYBOARD_C128_CAPS_LOCK { !error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_KEYBOARD_C128_CAPS_LOCK" } -} !ifdef CONFIG_MB_M65 { !ifdef CONFIG_KEYBOARD_C128 { !error "MEGA65 motherboard is not compatible with CONFIG_KEYBOARD_C128" } !ifdef CONFIG_KEYBOARD_C128_CAPS_LOCK { !error "MEGA65 motherboard is not compatible with CONFIG_KEYBOARD_C128_CAPS_LOCK" } - !ifdef CONFIG_LEGACY_SCNKEY { !error "MEGA65 motherboard is not compatible with CONFIG_LEGACY_SCNKEY" } } !ifdef CONFIG_MB_U64 { !ifdef CONFIG_KEYBOARD_C128 { !error "Ultimate 64 motherboard is not compatible with CONFIG_KEYBOARD_C128" } diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index e9491bc4..cc4d80ff 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -108,23 +108,17 @@ !addr CNTDN = $A5 ; -- NOT IMPLEMENTED -- !addr BUFPNT = $A6 ; -- NOT IMPLEMENTED -- !addr INBIT = $A7 ; temporary storage for tape / RS-232 received bits -!ifndef CONFIG_LEGACY_SCNKEY { !addr BITCI = $A8 ; -- NOT IMPLEMENTED -- !addr RINONE = $A9 ; -- WIP -- (UP9600 only) RS-232 check for start bit flag !addr RIDDATA = $AA ; -- NOT IMPLEMENTED -- !addr RIPRTY = $AB ; -- WIP -- checksum while reading tape -} !addr SAL = $AC ; $AC-$AD -- XXX: describe -- (implemented screen part) !addr EAL = $AE ; $AE-$AF -- XXX: describe -- [!] used also by screen editor, for temporary color storage when scrolling !addr CMP0 = $B0 ; $B0-$B1 temporary tape storage, [!] here used for BRK instruction address !addr TAPE1 = $B2 ; $B2-$B3 tape buffer pointer -!ifndef CONFIG_LEGACY_SCNKEY { !addr BITTS = $B4 ; -- NOT IMPLEMENTED -- -} !addr NXTBIT = $B5 ; -- NOT IMPLEMENTED -- [!] also used by tape routine to store CPU turbo settings -!ifndef CONFIG_LEGACY_SCNKEY { !addr RODATA = $B6 ; -- NOT IMPLEMENTED -- -} !addr FNLEN = $B7 ; current file name length !addr LA = $B8 ; current logical_file number !addr SA = $B9 ; current secondary address @@ -175,7 +169,6 @@ !addr BUF = $200 ; $200-$250, BASIC line editor input buffer (81 bytes) ; $250-$258 is the 81st - 88th characters in BASIC input, a carry over from VIC-20 - ; and not used on C64 - they are used if CONFIG_LEGACY_SCNKEY is enabled. ; [!] XXX document $251-$258 usage !addr LAT = $259 ; $259-$262, logical file numbers (table, 10 bytes) @@ -197,14 +190,12 @@ !addr KEYLOG = $28F ; $28F-$290 routine to setup keyboard decoding !addr MODE = $291 ; flag, is case switch allowed !addr AUTODN = $292 ; -- NOT IMPLEMENTED -- screen scroll disable -!ifndef CONFIG_LEGACY_SCNKEY { !addr M51CRT = $293 ; -- NOT IMPLEMENTED -- mock 6551 !addr M51CDR = $294 ; -- NOT IMPLEMENTED -- mock 6551 !addr M51AJB = $295 ; $295-$296 -- NOT IMPLEMENTED -- mock 6551 !addr RSSTAT = $297 ; -- WIP -- (UP9600 only) mock 6551, RS-232 status !addr BITNUM = $298 ; -- NOT IMPLEMENTED -- !addr BAUDOF = $299 ; $299-$29A -- NOT IMPLEMENTED -- -} !addr RIDBE = $29B ; -- WIP -- write pointer into RS-232 receive buffer !addr RIDBS = $29C ; -- WIP -- read pointer into RS-232 receive buffer !addr RODBS = $29D ; -- WIP -- read pointer into RS-232 send buffer diff --git a/src/kernal/,kernal_aliases.s b/src/kernal/,kernal_aliases.s deleted file mode 100644 index 4140a5f5..00000000 --- a/src/kernal/,kernal_aliases.s +++ /dev/null @@ -1,23 +0,0 @@ - -; -; Aliases for legacy keyboard scan routine -; - -!ifdef CONFIG_LEGACY_SCNKEY { - - ; Low memory variables - - ; Reuse RS232 variables, since they should not be used by other things. - ; Carefully avoid $A7 which is used by 64NET - !addr KeyQuantity = $A8 ; 1 byte - !addr BufferNew = $A9 ; 3 bytes - !addr TempZP = $B6 ; 1 byte - ; These should be initialized in CINT to $FF - !addr BufferQuantity = $B4 ; 1 byte - !addr BufferOld = $293 ; 3 bytes - !addr Buffer = $297 ; 4 bytes - - ; $250-$258 is the 81st - 88th characters in BASIC input, a carry over from VIC-20 - ; and not used on C64, so safe for us to use, probably. - !addr ScanResult = $250 ; 8 bytes -} diff --git a/src/kernal/assets/programmable_keys.s b/src/kernal/assets/programmable_keys.s index e5373114..e655f6fe 100644 --- a/src/kernal/assets/programmable_keys.s +++ b/src/kernal/assets/programmable_keys.s @@ -23,8 +23,6 @@ programmable_keys_codes: !ifdef CONFIG_KEYCMD_F7 { !byte KEY_F7 } !ifdef CONFIG_KEYCMD_F8 { !byte KEY_F8 } -!ifndef CONFIG_LEGACY_SCNKEY { - !ifdef CONFIG_KEYBOARD_C128 { !ifdef CONFIG_KEYCMD_HELP { !byte KEY_HELP } @@ -39,9 +37,7 @@ programmable_keys_codes: !ifdef CONFIG_KEYCMD_F12 { !byte KEY_F12 } !ifdef CONFIG_KEYCMD_F13 { !byte KEY_F13 } !ifdef CONFIG_KEYCMD_F14 { !byte KEY_F14 } - - -} } +} __programmable_keys_codes_end: @@ -69,8 +65,6 @@ __str_offset_F7: !ifdef CONFIG_KEYCMD_F7 { +CONFIG_KEYCMD_F7 __str_offset_F8: !ifdef CONFIG_KEYCMD_F8 { +CONFIG_KEYCMD_F8 !byte $00 } -!ifndef CONFIG_LEGACY_SCNKEY { - !ifdef CONFIG_KEYBOARD_C128 { __str_offset_HELP: !ifdef CONFIG_KEYCMD_HELP { +CONFIG_KEYCMD_HELP @@ -94,7 +88,7 @@ __str_offset_F13: !ifdef CONFIG_KEYCMD_F13 { +CONFIG_KEYCMD_F13 __str_offset_F14: !ifdef CONFIG_KEYCMD_F14 { +CONFIG_KEYCMD_F14 !byte $00 } -} } +} __programmable_keys_strings_end: @@ -117,8 +111,6 @@ programmable_keys_offsets: !ifdef CONFIG_KEYCMD_F7 { !byte __str_offset_F7 - programmable_keys_strings } !ifdef CONFIG_KEYCMD_F8 { !byte __str_offset_F8 - programmable_keys_strings } -!ifndef CONFIG_LEGACY_SCNKEY { - !ifdef CONFIG_KEYBOARD_C128 { !ifdef CONFIG_KEYCMD_HELP { !byte __str_offset_HELP - programmable_keys_strings } @@ -135,5 +127,3 @@ programmable_keys_offsets: !ifdef CONFIG_KEYCMD_F14 { !byte __str_offset_F14 - programmable_keys_strings } } } - -} diff --git a/src/kernal/init/cint_screen_keyboard.s b/src/kernal/init/cint_screen_keyboard.s index a03fa9a7..b85557ae 100644 --- a/src/kernal/init/cint_screen_keyboard.s +++ b/src/kernal/init/cint_screen_keyboard.s @@ -34,30 +34,6 @@ cint_screen_keyboard: sta RPTFLG } } - ; Set keyboard decode vector (Computes Mapping the 64 p215) - -!ifdef CONFIG_LEGACY_SCNKEY { - - ; Set initial variables for our improved keyboard scan routine - lda #$FF - ldx #6 -@1: - sta BufferOld,x - dex - bpl @1 - sta BufferQuantity - - ; Set key repeat delay (Computes Mapping the 64 p215) - ; Making some numbers up here: Repeat every ~1/10th sec - ; But require key to be held for ~1/3sec before - ; repeating (Computes Mapping the 64 p58) - - ; Not needed for default keyboard scanning code - - ldx #22-2 ; Fudge factor to match speed - stx DELAY -} - ; Set current colour for text (Computes Mapping the 64 p215) ldx #CONFIG_COLOR_TXT stx COLOR diff --git a/src/kernal/keyboard/eb48.scnkey_set_keytab.s b/src/kernal/keyboard/eb48.scnkey_set_keytab.s index 1bef2873..f81723d1 100644 --- a/src/kernal/keyboard/eb48.scnkey_set_keytab.s +++ b/src/kernal/keyboard/eb48.scnkey_set_keytab.s @@ -13,13 +13,6 @@ scnkey_set_keytab: -!ifdef CONFIG_LEGACY_SCNKEY { ; routine not compatible with legacy SCNKEY - - rts - -} else { - - ; Set initial KEYTAB value lda #__kb_matrix_shift ; left !byte >__kb_matrix_normal ; right -} } +} diff --git a/src/kernal/keyboard/kb_matrix_lookup.s b/src/kernal/keyboard/kb_matrix_lookup.s index 22a281ef..0840f6fa 100644 --- a/src/kernal/keyboard/kb_matrix_lookup.s +++ b/src/kernal/keyboard/kb_matrix_lookup.s @@ -12,8 +12,6 @@ ; -!ifndef CONFIG_LEGACY_SCNKEY { - kb_matrix_lookup: !ifndef SEGMENT_KERNAL_C { @@ -51,5 +49,3 @@ kb_matrix_lookup: !word $0000 ; %1.110 VENDOR+CTRL !word $0000 ; %1.111 SHIFT+VENDOR+CTRL } - -} diff --git a/src/kernal/keyboard/kb_matrix_lookup_legacy.s b/src/kernal/keyboard/kb_matrix_lookup_legacy.s deleted file mode 100644 index 1d1ddaa2..00000000 --- a/src/kernal/keyboard/kb_matrix_lookup_legacy.s +++ /dev/null @@ -1,31 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# X16 * #IGNORE -;; #LAYOUT# * KERNAL_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Work out if normal, shifted, control or Vendor modified keyboard. -; Table contains the offsets into keyboard_matrixes that should be used -; for different values of the bottom 3 bits of key_bucky_state XXX -; Interaction is simple to work out when playing with a C64: -; CTRL trumps SHIFT or VENDOR -; VENDOR + SHIFT = DOES NOTHING -; All 3 does CONTROL -; - -; This lookup table is used by TWW/CTR keyboard routine only! - - -!ifdef CONFIG_LEGACY_SCNKEY { - -kb_matrix_lookup: - - !byte $00 ; Normal - !byte $40 ; Shifted - !byte $80 ; Control - !byte $80 ; Control + SHIFT - !byte $C0 ; Vendor - !byte $C0 ; Vendor + SHIFT - !byte $80 ; Vendor + CTRL - !byte $80 ; Vendor + CTRL + SHIFT -} diff --git a/src/kernal/keyboard/kb_matrix_row_keys.s b/src/kernal/keyboard/kb_matrix_row_keys.s index e74f02db..a550b83a 100644 --- a/src/kernal/keyboard/kb_matrix_row_keys.s +++ b/src/kernal/keyboard/kb_matrix_row_keys.s @@ -11,9 +11,6 @@ ; -!ifndef CONFIG_LEGACY_SCNKEY { - - kb_matrix_row_keys: ; - values for CIA1_PRA to connect only the given row @@ -28,5 +25,3 @@ kb_matrix_row_keys: !byte %11011111 !byte %10111111 !byte %01111111 - -} ; no CONFIG_LEGACY_SCNKEY diff --git a/src/kernal/keyboard/kb_matrix_row_offsets.s b/src/kernal/keyboard/kb_matrix_row_offsets.s index 6a59df0d..39192b58 100644 --- a/src/kernal/keyboard/kb_matrix_row_offsets.s +++ b/src/kernal/keyboard/kb_matrix_row_offsets.s @@ -8,9 +8,6 @@ ; -!ifndef CONFIG_LEGACY_SCNKEY { - - kb_matrix_row_offsets: ; - offsets (in bytes) to the first bytes of keyboard matrix rows @@ -23,4 +20,3 @@ kb_matrix_row_offsets: !byte 5*8 !byte 6*8 !byte 7*8 -} diff --git a/src/kernal/keyboard/keyboard_disconnect.s b/src/kernal/keyboard/keyboard_disconnect.s index 416ed33a..b3b140ef 100644 --- a/src/kernal/keyboard/keyboard_disconnect.s +++ b/src/kernal/keyboard/keyboard_disconnect.s @@ -9,9 +9,6 @@ ; -!ifndef CONFIG_LEGACY_SCNKEY { - - keyboard_disconnect: ldx #$FF @@ -21,4 +18,3 @@ keyboard_disconnect: } rts -} diff --git a/src/kernal/keyboard/scnkey.s b/src/kernal/keyboard/scnkey.s index 68357223..677c4726 100644 --- a/src/kernal/keyboard/scnkey.s +++ b/src/kernal/keyboard/scnkey.s @@ -25,9 +25,6 @@ ; - RPTFLG - whether key repeat is allowed - -!ifndef CONFIG_LEGACY_SCNKEY { - ; Routine takes some ideas from TWW/CTR proposal, see here: ; - http://codebase64.org/doku.php?id=base:scanning_the_keyboard_the_correct_and_non_kernal_way @@ -434,5 +431,3 @@ scnkey_buffer_full: sta KOUNT rts - -} ; no CONFIG_LEGACY_SCNKEY diff --git a/src/kernal/keyboard/scnkey_128.s b/src/kernal/keyboard/scnkey_128.s index 07b11b21..f2bcf90b 100644 --- a/src/kernal/keyboard/scnkey_128.s +++ b/src/kernal/keyboard/scnkey_128.s @@ -10,7 +10,7 @@ ; -!ifdef CONFIG_KEYBOARD_C128 { !ifndef CONFIG_LEGACY_SCNKEY { +!ifdef CONFIG_KEYBOARD_C128 { ; Inlining this within SCNKEY would both overcomplicate the implementation @@ -66,6 +66,4 @@ scnkey_128_no_keys: pla jmp scnkey_no_keys ; pass controll to original routine - - -} } ; CONFIG_KEYBOARD_C128 and no CONFIG_LEGACY_SCNKEY +} diff --git a/src/kernal/keyboard/scnkey_legacy.s b/src/kernal/keyboard/scnkey_legacy.s deleted file mode 100644 index b1bb9d41..00000000 --- a/src/kernal/keyboard/scnkey_legacy.s +++ /dev/null @@ -1,519 +0,0 @@ -;; #LAYOUT# STD * #TAKE -;; #LAYOUT# X16 * #IGNORE -;; #LAYOUT# * KERNAL_0 #TAKE -;; #LAYOUT# * * #IGNORE - -; -; Official Kernal routine, described in: -; -; - [RG64] C64 Programmers Reference Guide - page 295 -; - [CM64] Computes Mapping the Commodore 64 - page 220 -; -; CPU registers that has to be preserved (see [RG64]): none -; - - -; NOTE: The code here is described as legacy, because the algorithm (although working very well) -; requires much more RAM than the original Kernal routine uses; without any form of extended -; RAM available to Open ROMs it will always be a serious compatibility risk. - - -!ifdef CONFIG_LEGACY_SCNKEY { - - -; Scan the keyboard.. -; Here we don't use the horrible buggy original routine, -; not just because of copyright. Instead, we use the -; nice one with joystick interference removal and -; key roll-over support from -; http://codebase64.org/doku.php?id=base:scanning_the_keyboard_the_correct_and_non_kernal_way - -; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -; Keyboard IO Routine -; ~~~~~~~~~~~~~~~~~~~ -; By: TWW/CTR - - -; Information -; ~~~~~~~~~~~ -; The routine uses "2 Key rollower" or up to 3 if the key-combination doesen't induce shadowing. -; If 2 or 3 keys are pressed simultaneously (within 1 scan) a "No Activity" state has to occur before new valid keys are returned. -; RESTORE is not detectable and must be handled by NMI IRQ. -; SHIFT LOCK is not detected due to unreliability. - - -; History: -; ~~~~~~~~ -; V3.0 - Hacked to pieces by PGS to work as KERNAL keyboard scan routine -; V2.5 - New test tool. -; Added return of error codes. -; Fixed a bug causing Buffer Overflow. -; Fixed a bug in Non Alphanumerical Flags from 2.0. -; V2.1 - Shortened the source by adding .for loops & Updated the header and some comments. -; Added "simultaneous keypress" check. -; V2.0 - Added return of non-Alphanumeric keys into X & Y-Registers. -; Small optimizations here and there. -; V1.1 - Unrolled code to make it faster and optimized other parts of it. -; Removed SHIFT LOCK scanning. -; V1.0 - First Working Version along with test tool. - -; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - - - - ; Operational Variables - !set MaxKeyRollover = 3 - -SCNKEY: - - lda #$00 - sta BufferQuantity - - ; Decrement key repeat timeout if non-zero - ldx KOUNT - beq sk_start - dec KOUNT - -sk_start: - ; Call main keyboard scanning routine - jsr Main - - lda BufferQuantity - beq no_keys_waiting - - ; Stuff each key pressed into the keyboard buffer - - ldy #$00 -@1: - lda Buffer,y - jsr accept_key - iny - cpy BufferQuantity - bne @1 -no_keys_waiting: - - rts - -accept_key: - ; Work out what is new and needs to be added - ; to the input buffer. - ; Also update the bucky key status flags etc - cmp #$ff - beq sk_nokey - ; Got a key, turn it from matrix position to key value, - ; and stuff it in the keyboard buffer - - ; Convert matrix position to key code - ; XXX - Add offset of $40, $80 or $C0 if shift, CONTROL or C= are held down - pha - lda SHFLAG - and #$7 - tax - pla - and #$3f - ora kb_matrix_lookup,x - tax - lda kb_matrix,x - ; But don't insert $00 characters - beq sk_nokey - - ; Stash key into keyboard buffer - ldx NDX - cpx XMAX - beq sk_nokey - sta KEYD,x - inc NDX - -sk_nokey: - - rts - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Routine for Scanning a Matrix Row - -KeyInRow: - ldy #7 -NextKeyInRow: - ror - bcs nokey - jsr KeyFound -nokey: - inx - dey - bpl NextKeyInRow - - rts - - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Routine for handling: Key Found - -KeyFound: - stx TempZP - dec KeyQuantity - bmi OverFlow - - ; Originally, we resolved the keys. - ; Now we just return the matrix position, so that - ; we can do C64-style bucky modifications as normal - ; was: ldy KeyTable,x - pha - txa - - ldx KeyQuantity - sta BufferNew,x - pla - ldx TempZP - rts - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Routine for handling: Overflow - -OverFlow: - pla ; Dirty hack to handle 2 layers of JSR - pla - pla - pla - ; Don't manipulate last legal buffer as the routine will fix itself once it gets valid input again. - -ReturnNoKeys: - sec - lda #$00 - sta BufferQuantity - lda #$FF - sta LSTX - ldx #MaxKeyRollover-1 -@2: - sta Buffer,x - sta BufferOld,x - dex - bpl @2 - - rts - - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Exit Routine for: No Activity - -NoActivityDetected: - - ; So cancel all bucky keys - lda SHFLAG - sta LSTSHF - lda #$00 - sta SHFLAG - - jmp ReturnNoKeys - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Configure Data Direction Registers -Main: - ; Begin with no key events - lda #$ff - sta BufferNew+0 - sta BufferNew+1 - sta BufferNew+2 - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Check for Port Activity - - ldx #$FF - ldy #$00 - - sty CIA1_PRA ; Connect all Keyboard Rows - cpx CIA1_PRB - bne skip0 - - jmp NoActivityDetected - -JoystickActivity: - - ; Clear bucky key status - lda #$00 - sta SHFLAG - - lda CIA1_PRB - and #$03 - cmp #$01 - bne @3 - ; down - ldx #$07 ; UP/DOWN - jsr KeyFound -@3: - cmp #$02 - bne @4 - ; Up - ; Mark shift as pressed - ldx #$01 - stx SHFLAG - ldx #$07 ; UP/DOWN - jsr KeyFound -@4: - ; Only allow up/down OR left/right, since - ; else we have confusing situation with SHIFT required - ; for one, but not the other. - ; XXX - We could fix this by making the joystick activity - ; feed the key input at a higher level, rather than - ; simulating directly pressing the cursor keys. - cmp #$03 - beq @5 - jmp skdone -@5: - lda CIA1_PRB - and #$0c - cmp #$04 - bne @6 - ldx #$02 - jsr KeyFound ; LEFT/RIGHT -@6: - cmp #$08 - bne @7 - ldx #$01 - stx SHFLAG - ldx #$02 - jsr KeyFound ; LEFT/RIGHT -@7: - jmp skdone - - -skip0: - - ; ; Set max keys allowed before ignoring result - lda #MaxKeyRollover - sta KeyQuantity - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Check for Control Port #1 Activity - - stx CIA1_PRA ; Disconnect all Keyboard Rows - cpx CIA1_PRB ; Only Control Port activity will be detected - bne JoystickActivity - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Scan Keyboard Matrix - - ldx #7 - lda #%11111110 -next_row: - sta CIA1_PRA - pha - lda CIA1_PRB - sta ScanResult,x - pla - sec - rol - dex - bpl next_row - - ; X gets back to $FF here, which is assumed below - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Check for Control Port #1 Activity (again) - - stx CIA1_PRA ; Disconnect all Keyboard Rows - cpx CIA1_PRB ; Only Control Port activity will be detected - beq @8 - jmp ReturnNoKeys -@8: - ; Make X = $00, assumed below - inx - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Check and flag Non Alphanumeric Keys - - ; Store de-bounce data for bucky keys - ; (Compute's Mapping the 64, p58-59) - lda SHFLAG - sta LSTSHF - - ; Build bucky state - lda #$00 - sta SHFLAG - lda ScanResult+6 - eor #%10000000 - and #%10000000 ; Left shift - rol - rol - and #$01 - ora SHFLAG - sta SHFLAG - - ; Right shift - lda ScanResult+1 - eor #$10 - lsr - lsr - lsr - lsr - and #$01 - ora SHFLAG - sta SHFLAG - - ; Control - lda ScanResult+0 - eor #$04 - and #$04 - ora SHFLAG - sta SHFLAG - - ; Vendor key - lda ScanResult+0 - eor #$ff - lsr - lsr - lsr - lsr - and #$02 - ora SHFLAG - sta SHFLAG - - ; Handle SHIFT + VENDOR - jsr scnkey_toggle_if_needed - -no_case_toggle: - - ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; ; Check for pressed key(s) - - lda ScanResult+7 - cmp #$ff - beq sk6 - jsr KeyInRow -sk6: - ldx #8 - lda ScanResult+6 - beq sk5 - jsr KeyInRow -sk5: - ldx #16 - lda ScanResult+5 - beq sk4 - jsr KeyInRow -sk4: - ldx #24 - lda ScanResult+4 - beq sk3 - jsr KeyInRow -sk3: - ldx #32 - lda ScanResult+3 - beq sk2 - jsr KeyInRow -sk2: - ldx #40 - lda ScanResult+2 - beq sk1 - jsr KeyInRow -sk1: - ldx #48 - lda ScanResult+1 - beq sk0 - jsr KeyInRow -sk0: - ldx #56 - lda ScanResult+0 - beq skdone - jsr KeyInRow -skdone: - - - - ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ; Key Scan Completed - - ; Put any new key (not in old scan) into buffer - ldx #MaxKeyRollover-1 - -ProcessPressedKeys: - - ; Check if the currently pressed key is continuing to be held down - lda BufferNew,x - cmp #$ff - beq ConsiderNextKey - cmp BufferOld - beq KeyHeld - cmp BufferOld+1 - beq KeyHeld - cmp BufferOld+2 - beq KeyHeld - -RecordKeypress: - - ; New Key Detected - ldy BufferQuantity - cpy #MaxKeyRollover - bcc @9 - jmp ReturnNoKeys ; too many new keys -@9: -AcceptKeyEvent: - sta Buffer,y - iny - sty BufferQuantity - -ConsiderNextKey: - dex - bpl ProcessPressedKeys - - ; Copy new presses to old list - ldx #MaxKeyRollover-1 -@10: - lda BufferNew,x - sta BufferOld,x - dex - bpl @10 - - ; Return success and set of pressed keys - clc - rts - -KeyHeld: - ; The key in A is still held down. - ; compare with key in LSTX - ; (Compute's Mapping the 64 p36-37) - ; if different, reset repeat count down. - - ; Ignore bucky keys, so that repeat can work when a - ; bucky is held down. - cmp #15 - beq BuckyHeld - cmp #52 - beq BuckyHeld - cmp #58 - beq BuckyHeld - cmp #61 - beq BuckyHeld - - cmp LSTX - beq SameKeyHeld - - ; Different key held - sta LSTX - pha - lda DELAY - sta KOUNT - pla -BuckyHeld: - jmp ConsiderNextKey - -SameKeyHeld: - pha - lda KOUNT - bmi KeyCanRepeat - bne KeyRepeatWait - ; Count down ended, so repeat key now -KeyCanRepeat: - - ; (Compute's Mapping the 64 p58) - pha - lda #6-2 ; Fudge factor to match speed - sta KOUNT - pla - pla - - jmp RecordKeypress -KeyRepeatWait: - pla - jmp ConsiderNextKey - - -} ; CONFIG_LEGACY_SCNKEY diff --git a/src/kernal/keyboard_m65/mega65_scnkey.s b/src/kernal/keyboard_m65/mega65_scnkey.s index 2666e5cf..e4eeaaf5 100644 --- a/src/kernal/keyboard_m65/mega65_scnkey.s +++ b/src/kernal/keyboard_m65/mega65_scnkey.s @@ -2,6 +2,10 @@ ;; #LAYOUT# * * #IGNORE +; Routine takes many ideas from TWW/CTR proposal, see here: +; - http://codebase64.org/doku.php?id=base:scanning_the_keyboard_the_correct_and_non_kernal_way + + m65_scnkey: ; Initialize work variables for scanning the keyboard