diff --git a/src/aliases/,aliases_hardware_m65.s b/src/aliases/,aliases_hardware_m65.s index c85b88f1..9ca89e57 100644 --- a/src/aliases/,aliases_hardware_m65.s +++ b/src/aliases/,aliases_hardware_m65.s @@ -32,7 +32,6 @@ !addr C65_EXTKEYS_PR = $D607 !addr C65_EXTKEYS_DDR = $D608 - !addr KBSCN_KEYCODE = $D610 !addr KBSCN_BUCKY = $D611 !addr KBSCN_PEEK = $D613 !addr KBSCN_SELECT = $D614 diff --git a/src/aliases/,aliases_ram_lowmem_m65.s b/src/aliases/,aliases_ram_lowmem_m65.s index e7bc2ce1..8d208c7e 100644 --- a/src/aliases/,aliases_ram_lowmem_m65.s +++ b/src/aliases/,aliases_ram_lowmem_m65.s @@ -53,7 +53,10 @@ !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_SCRCOLMAX = $594 ; maximum allowed column - ; $595-$5EB -- UNUSED -- + !addr M65_KB_BUCKY = $595 ; result of bucky keys scan + !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_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/scnkey.s b/src/kernal/keyboard/scnkey.s index 74196ef0..01c8ad26 100644 --- a/src/kernal/keyboard/scnkey.s +++ b/src/kernal/keyboard/scnkey.s @@ -317,7 +317,7 @@ scnkey_output_key: lda NDX cmp XMAX - bcs scnkey_early_repeat ; branch if no free space in buffer + bcs scnkey_early_repeat ; no space in buffer ; Reinitialize secondary counter diff --git a/src/kernal/keyboard_m65/mega65_kb_matrix_bucky.s b/src/kernal/keyboard_m65/mega65_kb_matrix_bucky.s deleted file mode 100644 index b7ea685e..00000000 --- a/src/kernal/keyboard_m65/mega65_kb_matrix_bucky.s +++ /dev/null @@ -1,15 +0,0 @@ -;; #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 diff --git a/src/kernal/keyboard_m65/mega65_scnkey.s b/src/kernal/keyboard_m65/mega65_scnkey.s index 6e2d495c..4d15f97c 100644 --- a/src/kernal/keyboard_m65/mega65_scnkey.s +++ b/src/kernal/keyboard_m65/mega65_scnkey.s @@ -4,120 +4,109 @@ m65_scnkey: - ; Read the key from automatic scanner + ; First scan the whole keyboard lda KBSCN_BUCKY - ldy KBSCN_KEYCODE - sty KBSCN_KEYCODE + sta M65_KB_BUCKY - ; Update the SHFLAG in a way that preserves .Y - - and #%01111111 - - ldx SHFLAG - stx LSTSHF ; needed for SHIFT+VENDOR support - - ldx #$00 - stx SHFLAG + ldx #$08 +@1: + stx KBSCN_SELECT + lda KBSCN_PEEK + eor #$FF ; let bit 1 mean 'pressed', not the otherwise + sta M65_KB_COLSCAN, x 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 -m65_scnkey_SHFLAG_loop: +m65_scnkey_detect_SHIFT: - inx - asr - 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 + txa + and #%00000011 + beq m65_scnkey_detect_VENDOR tya - beq m65_scnkey_done ; branch if no key was pressed - ldy NDX - sta KEYD, y - inc NDX + ora #KEY_FLAG_SHIFT + tay ; FALLTROUGH -m65_scnkey_done: +m65_scnkey_detect_VENDOR: + + txa + and #%00001000 + beq m65_scnkey_detect_CTRL - rts + tya + ora #KEY_FLAG_VENDOR + tay -m65_scnkey_try_repeat: + ; FALLTROUGH -!ifndef CONFIG_KEY_REPEAT_ALWAYS { +m65_scnkey_detect_CTRL: + + txa + and #%00000100 + beq m65_scnkey_detect_ALT - ; Check whether we should repeat keys - first the flag, afterwards hardcoded list + tya + ora #KEY_FLAG_CTRL + tay - lda RPTFLG - bmi m65_scnkey_handle_repeat ; branch if we should repeat always + ; FALLTROUGH - ; XXX if key to be repeated - go to m65_scnkey_handle_repeat, otherwise to m65_scnkey_done +m65_scnkey_detect_ALT: + + txa + and #%00010000 + beq m65_scnkey_detect_CAPS_LOCK -m65_scnkey_handle_repeat: + tya + ora #KEY_FLAG_ALT + tay -} ; no CONFIG_KEY_REPEAT_ALWAYS + ; FALLTROUGH - ; Countdown before first repeat +m65_scnkey_detect_CAPS_LOCK: + + txa + and #%01000000 + beq m65_scnkey_detect_NO_SCRL - lda DELAY - beq @10 - dec DELAY + tya + ora #KEY_FLAG_NO_SCRL + tay - rts -@10: - ; Countdown before subsequent repeats + ; 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 - lda KOUNT - beq m65_scnkey_output_key ; if second counter is also 0, we can repeat the key - dec KOUNT rts