From 71f027cdfb93b3ed0d13e53bfa69bb048a95cb03 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 29 Nov 2020 10:52:43 +0100 Subject: [PATCH] restored some parts of the new keyboard scanner --- src/aliases/,aliases_ram_lowmem_m65.s | 3 +- src/kernal/keyboard/kb_matrix_bucky.s | 7 +- src/kernal/keyboard/scnkey_set_keytab.s | 11 +- src/kernal/keyboard_m65/mega65_scnkey.s | 131 ++++++++++-------------- 4 files changed, 69 insertions(+), 83 deletions(-) diff --git a/src/aliases/,aliases_ram_lowmem_m65.s b/src/aliases/,aliases_ram_lowmem_m65.s index 8d208c7e..6bbc5813 100644 --- a/src/aliases/,aliases_ram_lowmem_m65.s +++ b/src/aliases/,aliases_ram_lowmem_m65.s @@ -55,8 +55,9 @@ !addr M65_SCRCOLMAX = $594 ; maximum allowed column !addr M65_KB_BUCKY = $595 ; result of bucky keys scan !addr M65_KB_COLSCAN = $596 ; $596-$59E results of keyboard scan, columns 0-8 + !addr M65_KB_COLSUM = $59F ; sum (OR) of the M65_KB_COLSCAN - ; $59F-$5EB -- UNUSED -- + ; $560-$5EB -- UNUSED -- !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_OUTBUF = $700 ; $700-$7FF -- reserved for RS-232 output buffer -- diff --git a/src/kernal/keyboard/kb_matrix_bucky.s b/src/kernal/keyboard/kb_matrix_bucky.s index eb3d1b8e..16b12add 100644 --- a/src/kernal/keyboard/kb_matrix_bucky.s +++ b/src/kernal/keyboard/kb_matrix_bucky.s @@ -78,10 +78,15 @@ kb_matrix_bucky_shflag: ; mask to be ORed to SHFLAG to mark key status !byte KEY_FLAG_SHIFT !byte KEY_FLAG_VENDOR !byte KEY_FLAG_CTRL -!ifdef CONFIG_KEYBOARD_C128_OR_C65 { +!ifdef CONFIG_MB_M65 { + !byte KEY_FLAG_ALT + !byte KEY_FLAG_NO_SCRL + !byte KEY_FLAG_CAPSL +} else ifdef CONFIG_KEYBOARD_C128_OR_C65 { !byte KEY_FLAG_ALT !byte KEY_FLAG_NO_SCRL } + } ; no CONFIG_LEGACY_SCNKEY diff --git a/src/kernal/keyboard/scnkey_set_keytab.s b/src/kernal/keyboard/scnkey_set_keytab.s index 86aceb29..cef83aac 100644 --- a/src/kernal/keyboard/scnkey_set_keytab.s +++ b/src/kernal/keyboard/scnkey_set_keytab.s @@ -61,10 +61,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 @@ -84,8 +80,10 @@ scnkey_toggle_if_needed: ; entry for SCNKEY (TWW/CTR version) !ifdef CONFIG_MB_M65 { +!ifndef HOTFIX_CHARPTR { jsr M65_MODEGET bcc @2 +} ; Toggling charsets for C64 mode @@ -95,12 +93,15 @@ scnkey_toggle_if_needed: ; entry for SCNKEY (TWW/CTR version) @1: rts +!ifndef HOTFIX_CHARPTR { + ; Toggling charsets for M65 mode @2: lda VIC_CHARPTR+1 eor #%00001000 sta VIC_CHARPTR+1 rts +} } else { @@ -111,3 +112,5 @@ scnkey_toggle_if_needed: ; entry for SCNKEY (TWW/CTR version) rts } + +} ; no CONFIG_LEGACY_SCNKEY diff --git a/src/kernal/keyboard_m65/mega65_scnkey.s b/src/kernal/keyboard_m65/mega65_scnkey.s index 4d15f97c..a9496051 100644 --- a/src/kernal/keyboard_m65/mega65_scnkey.s +++ b/src/kernal/keyboard_m65/mega65_scnkey.s @@ -4,107 +4,84 @@ m65_scnkey: - ; First scan the whole keyboard + ; + ; Scan the whole keyboard, store results in memory + ; - lda KBSCN_BUCKY - sta M65_KB_BUCKY + lda #$00 + sta M65_KB_COLSUM ldx #$08 -@1: + + lda #%01111111 + and KBSCN_BUCKY + sta M65_KB_BUCKY + + ; FALLTROUGH + +m65_scnkey_loop: + stx KBSCN_SELECT lda KBSCN_PEEK eor #$FF ; let bit 1 mean 'pressed', not the otherwise sta M65_KB_COLSCAN, x + ora M65_KB_COLSUM + sta M65_KB_COLSUM dex - bpl @1 + bpl m65_scnkey_loop - ; Update the SHFLAG + ; + ; Retrieve SHIFT / VENDOR / CTRL / ALT / NO SCROLL / CAPS LOCK status + ; 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 + ldx #$00 + stx SHFLAG + + lda M65_KB_BUCKY + dex ; index into kb_matrix_bucky_shflag ; FALLTROUGH -m65_scnkey_detect_SHIFT: +m65_scnkey_shflag_loop: + + inx + asr + bcc m65_scnkey_shflag_next + + ; Bucky key pressed + + pha + lda kb_matrix_bucky_shflag, x + ora SHFLAG + sta SHFLAG + pla + + ; FALLTROUGH + +m65_scnkey_shflag_next: + + bne m65_scnkey_shflag_loop + + ; + ; Scan the keyboard matrix stored in memory to determine which keys were pressed + ; + + lda M65_KB_COLSUM + beq m65_scnkey_no_key + + ; XXX - txa - and #%00000011 - beq m65_scnkey_detect_VENDOR - tya - ora #KEY_FLAG_SHIFT - tay - ; FALLTROUGH -m65_scnkey_detect_VENDOR: - txa - and #%00001000 - beq m65_scnkey_detect_CTRL - tya - ora #KEY_FLAG_VENDOR - tay +m65_scnkey_no_key: - ; FALLTROUGH -m65_scnkey_detect_CTRL: - - txa - and #%00000100 - beq m65_scnkey_detect_ALT - - tya - ora #KEY_FLAG_CTRL - tay - - ; FALLTROUGH - -m65_scnkey_detect_ALT: - - txa - and #%00010000 - beq m65_scnkey_detect_CAPS_LOCK - - tya - ora #KEY_FLAG_ALT - tay - - ; FALLTROUGH - -m65_scnkey_detect_CAPS_LOCK: - - txa - 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