more work on MEGA65 keyboard scanner

This commit is contained in:
FeralChild64 committed 2020-11-28 23:33:29 +01:00
1 parent bdbafaa76e
commit 7918ef55b9
5 files changed
+108 -84

No files matched your search

+1
View File
@@ -32,6 +32,7 @@
!addr C65_EXTKEYS_PR = $D607 !addr C65_EXTKEYS_PR = $D607
!addr C65_EXTKEYS_DDR = $D608 !addr C65_EXTKEYS_DDR = $D608
!addr KBSCN_KEYCODE = $D610
!addr KBSCN_BUCKY = $D611 !addr KBSCN_BUCKY = $D611
!addr KBSCN_PEEK = $D613 !addr KBSCN_PEEK = $D613
!addr KBSCN_SELECT = $D614 !addr KBSCN_SELECT = $D614
+1 -4
View File
@@ -53,10 +53,7 @@
!addr M65_TXTWIN_Y1 = $591 ; text window - bottom-right Y coordinate + 1 !addr M65_TXTWIN_Y1 = $591 ; text window - bottom-right Y coordinate + 1
!addr M65_TXTROW_OFF = $592 ; $592-$593 offset to the current text row from the viewport start !addr M65_TXTROW_OFF = $592 ; $592-$593 offset to the current text row from the viewport start
!addr M65_SCRCOLMAX = $594 ; maximum allowed column !addr M65_SCRCOLMAX = $594 ; maximum allowed column
!addr M65_KB_BUCKY = $595 ; result of bucky keys scan ; $595-$5EB -- UNUSED --
!addr M65_KB_COLSCAN = $596 ; $596-$59E results of keyboard scan, columns 0-8
; $59F-$5EB -- UNUSED --
!addr M65_DMAGIC_LIST = $5F1 ; $5EF-$5FF reserved for DMAgic list, 15 bytes (modulo bytes are not needed) !addr M65_DMAGIC_LIST = $5F1 ; $5EF-$5FF reserved for DMAgic list, 15 bytes (modulo bytes are not needed)
!addr M65_RS232_INBUF = $600 ; $600-$6FF -- reserved for RS-232 input buffer -- !addr M65_RS232_INBUF = $600 ; $600-$6FF -- reserved for RS-232 input buffer --
!addr M65_RS232_OUTBUF = $700 ; $700-$7FF -- reserved for RS-232 output buffer -- !addr M65_RS232_OUTBUF = $700 ; $700-$7FF -- reserved for RS-232 output buffer --
+1 -1
View File
@@ -317,7 +317,7 @@ scnkey_output_key:
lda NDX lda NDX
cmp XMAX cmp XMAX
bcs scnkey_early_repeat ; no space in buffer bcs scnkey_early_repeat ; branch if no free space in buffer
; Reinitialize secondary counter ; Reinitialize secondary counter
@@ -0,0 +1,15 @@
;; #LAYOUT# M65 KERNAL_0 #TAKE
;; #LAYOUT# * * #IGNORE
; Keyboard matrix for bucky keys decoding on MEGA65
m65_kb_matrix_bucky:
!byte KEY_FLAG_SHIFT
!byte KEY_FLAG_SHIFT
!byte KEY_FLAG_VENDOR
!byte KEY_FLAG_CTRL
!byte KEY_FLAG_ALT
!byte KEY_FLAG_NO_SCRL
!byte KEY_FLAG_CAPSL
+90 -79
View File
@@ -4,109 +4,120 @@
m65_scnkey: m65_scnkey:
; First scan the whole keyboard ; Read the key from automatic scanner
lda KBSCN_BUCKY lda KBSCN_BUCKY
sta M65_KB_BUCKY ldy KBSCN_KEYCODE
sty KBSCN_KEYCODE
ldx #$08 ; Update the SHFLAG in a way that preserves .Y
@1:
stx KBSCN_SELECT and #%01111111
lda KBSCN_PEEK
eor #$FF ; let bit 1 mean 'pressed', not the otherwise ldx SHFLAG
sta M65_KB_COLSCAN, x stx LSTSHF ; needed for SHIFT+VENDOR support
ldx #$00
stx SHFLAG
dex dex
bpl @1
; Update the SHFLAG
lda SHFLAG
sta LSTSHF ; needed for SHIFT+VENDOR support
ldy #$00 ; the new SHFLAG will be constructed in .Y
ldx M65_KB_BUCKY
beq m65_scnkey_SHFLAG_ready
; FALLTROUGH ; FALLTROUGH
m65_scnkey_detect_SHIFT: m65_scnkey_SHFLAG_loop:
txa inx
and #%00000011 asr
beq m65_scnkey_detect_VENDOR bcc m65_scnkey_SHFLAG_next
; Bucky key pressed
pha
lda m65_kb_matrix_bucky, x
ora SHFLAG
sta SHFLAG
pla
; FALLTROUGH
m65_scnkey_SHFLAG_next:
bne m65_scnkey_SHFLAG_loop
; We have the key code in .Y - check if same as the last one
cpy LSTX
beq m65_scnkey_try_repeat
; Not the same key - store the key code, reset delay counter
sty LSTX
!ifndef CONFIG_RS232_UP9600 {
lda #$16
} else {
lda #$18
}
sta DELAY
; FALLTROUGH
m65_scnkey_output_key:
; Check if we have free space in the keyboard buffer
lda NDX
cmp XMAX
+bcs scnkey_early_repeat ; branch if no free space in buffer
; Reinitialize secondary counter
lda #$03
sta KOUNT
; Output PETSCII code to the keyboard buffer
m65_scnkey_got_petscii:
; XXX if no key pressed, try joysticks
tya tya
ora #KEY_FLAG_SHIFT beq m65_scnkey_done ; branch if no key was pressed
tay ldy NDX
sta KEYD, y
inc NDX
; FALLTROUGH ; FALLTROUGH
m65_scnkey_detect_VENDOR: m65_scnkey_done:
txa rts
and #%00001000
beq m65_scnkey_detect_CTRL
tya m65_scnkey_try_repeat:
ora #KEY_FLAG_VENDOR
tay
; FALLTROUGH !ifndef CONFIG_KEY_REPEAT_ALWAYS {
m65_scnkey_detect_CTRL: ; Check whether we should repeat keys - first the flag, afterwards hardcoded list
txa lda RPTFLG
and #%00000100 bmi m65_scnkey_handle_repeat ; branch if we should repeat always
beq m65_scnkey_detect_ALT
tya ; XXX if key to be repeated - go to m65_scnkey_handle_repeat, otherwise to m65_scnkey_done
ora #KEY_FLAG_CTRL
tay
; FALLTROUGH m65_scnkey_handle_repeat:
m65_scnkey_detect_ALT: } ; no CONFIG_KEY_REPEAT_ALWAYS
txa ; Countdown before first repeat
and #%00010000
beq m65_scnkey_detect_CAPS_LOCK
tya lda DELAY
ora #KEY_FLAG_ALT beq @10
tay dec DELAY
; FALLTROUGH rts
@10:
; Countdown before subsequent repeats
m65_scnkey_detect_CAPS_LOCK: lda KOUNT
beq m65_scnkey_output_key ; if second counter is also 0, we can repeat the key
txa dec KOUNT
and #%01000000
beq m65_scnkey_detect_NO_SCRL
tya
ora #KEY_FLAG_NO_SCRL
tay
; FALLTROUGH
m65_scnkey_detect_NO_SCRL:
txa
and #%00100000
beq m65_scnkey_SHFLAG_ready
tya
ora #KEY_FLAG_CAPSL
tay
; FALLTROUGH
m65_scnkey_SHFLAG_ready:
sty SHFLAG
; XXX
rts rts