legacy keyboard code removed

This commit is contained in:
FeralChild64 committed 2020-12-04 21:55:50 +01:00
1 parent 295bed09c7
commit 64c2def140
29 files changed
+16 -694

No files matched your search

+1 -7
View File
@@ -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.
+1 -1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-8
View File
@@ -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" }
-9
View File
@@ -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
-23
View File
@@ -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
}
+2 -12
View File
@@ -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 }
} }
}
-24
View File
@@ -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
@@ -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
sta KEYTAB+0
@@ -59,8 +52,6 @@ scnkey_valid_offset_cont:
; FALLTROUGH
} ; no CONFIG_LEGACY_SCNKEY
scnkey_toggle_if_needed: ; entry for SCNKEY (TWW/CTR version)
; Check if we should toggle the character set
+2 -4
View File
@@ -11,7 +11,7 @@
;
!ifdef CONFIG_KEYBOARD_C128 { !ifndef CONFIG_LEGACY_SCNKEY {
!ifdef CONFIG_KEYBOARD_C128 {
kb_matrix_128:
@@ -28,6 +28,4 @@ kb_matrix_128_bucky_filter:
!byte %00000000
!byte %00000000
!byte %10000001 ; ALT, NO_SCRL
} } ; CONFIG_KEYBOARD_C128 and no CONFIG_LEGACY_SCNKEY
}
+2 -2
View File
@@ -11,7 +11,7 @@
;
!ifndef CONFIG_LEGACY_SCNKEY { !ifndef CONFIG_KEY_REPEAT_ALWAYS {
!ifndef CONFIG_KEY_REPEAT_ALWAYS {
kb_matrix_alwaysrepeat:
@@ -24,4 +24,4 @@ kb_matrix_alwaysrepeat:
__kb_matrix_alwaysrepeat_end:
} } ; no CONFIG_LEGACY_SCNKEY and no CONFIG_KEY_REPEAT_ALWAYS
}
-6
View File
@@ -12,8 +12,6 @@
; - https://github.com/MEGA65/c65-specifications/blob/master/c65manualupdated.txt
;
!ifndef CONFIG_LEGACY_SCNKEY {
kb_matrix_bucky_confmask: ; values to be written to CIA1_PRA
@@ -65,7 +63,3 @@ kb_matrix_bucky_shflag: ; mask to be ORed to SHFLAG to mark key status
!byte KEY_FLAG_ALT
!byte KEY_FLAG_NO_SCRL
}
} ; no CONFIG_LEGACY_SCNKEY
@@ -11,9 +11,6 @@
;
!ifndef CONFIG_LEGACY_SCNKEY {
kb_matrix_bucky_filter:
; values for OR with CIA1_PRB content to filter out bucky keys
@@ -26,4 +23,3 @@ kb_matrix_bucky_filter:
!byte %00000000
!byte %00010000 ; SHIFT (right)
!byte %00100100 ; VENDOR + CONTROL
}
+2 -2
View File
@@ -8,7 +8,7 @@
;
!ifndef CONFIG_LEGACY_SCNKEY { !ifdef CONFIG_JOY1_OR_JOY2_CURSOR {
!ifdef CONFIG_JOY1_OR_JOY2_CURSOR {
kb_matrix_joy_status:
@@ -39,4 +39,4 @@ kb_matrix_joy_keytab_hi:
!byte >__kb_matrix_shift ; left
!byte >__kb_matrix_normal ; right
} }
}
-4
View File
@@ -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
}
}
@@ -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
}
-5
View File
@@ -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
@@ -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
}
@@ -9,9 +9,6 @@
;
!ifndef CONFIG_LEGACY_SCNKEY {
keyboard_disconnect:
ldx #$FF
@@ -21,4 +18,3 @@ keyboard_disconnect:
}
rts
}
-5
View File
@@ -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
+2 -4
View File
@@ -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
}
-519
View File
@@ -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
+4
View File
@@ -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