diff --git a/doc/Development.md b/doc/Development.md index b50e1213..775a21ce 100644 --- a/doc/Development.md +++ b/doc/Development.md @@ -53,9 +53,9 @@ There is no official PETSCII code for `TAB` - we can't utilize the ones from C12 `SHFLAG` (`$028D`) variable is extended to support additional bucky keys on C128 and C65 keyboards: -| bits 7-5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | -| :------: | :---------: | :------: | :------: | :------: | :------: | -| reserved | `CAPS LOCK` | `ALT` | `CTRL` | `VENDOR` | `SHIFT` | +| bits 7-6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | +| :------: | :-------: | :---------: | :------: | :------: | :------: | :------: | +| reserved | `NO SCRL` | `CAPS LOCK` | `ALT` | `CTRL` | `VENDOR` | `SHIFT` | Bits 3 and 4 are extension to the original variable, compatible with the C128 ROMs API. There is no official way to retrieve `NO_SCRL` status as of yet. The `40/80` key status cannot be retrieved in C64 mode at all (C128 hardware limitation). diff --git a/src/,,config_mega65.s b/src/,,config_mega65.s index 500ac99e..c86a9e1b 100644 --- a/src/,,config_mega65.s +++ b/src/,,config_mega65.s @@ -46,15 +46,15 @@ ; --- Keyboard settings ;; #CONFIG# LEGACY_SCNKEY NO -;; #CONFIG# KEYBOARD_C65 NO ; untested -;; #CONFIG# KEYBOARD_C65_CAPS_LOCK NO ; untested +;; #CONFIG# KEYBOARD_C65 NO ; does not work +;; #CONFIG# KEYBOARD_C65_CAPS_LOCK NO ; does not work ;; #CONFIG# KEY_REPEAT_DEFAULT NO ;; #CONFIG# KEY_REPEAT_ALWAYS NO ;; #CONFIG# KEY_FAST_SCAN YES ;; #CONFIG# JOY1_CURSOR NO ;; #CONFIG# JOY2_CURSOR NO -;; #CONFIG# CONFIG_M65_KB_DEV NO ; for development, keep disabled +;; #CONFIG# M65_KB_DEV NO ; for development, keep disabled ;; #CONFIG# PROGRAMMABLE_KEYS YES diff --git a/src/aliases/,aliases_hardware_m65.s b/src/aliases/,aliases_hardware_m65.s index 8a03c46e..9ca89e57 100644 --- a/src/aliases/,aliases_hardware_m65.s +++ b/src/aliases/,aliases_hardware_m65.s @@ -32,6 +32,10 @@ !addr C65_EXTKEYS_PR = $D607 !addr C65_EXTKEYS_DDR = $D608 + !addr KBSCN_BUCKY = $D611 + !addr KBSCN_PEEK = $D613 + !addr KBSCN_SELECT = $D614 + ; SD card !addr SD_CTL = $D680 diff --git a/src/aliases/,aliases_petscii_codes.s b/src/aliases/,aliases_petscii_codes.s index 5beb2c43..474573cf 100644 --- a/src/aliases/,aliases_petscii_codes.s +++ b/src/aliases/,aliases_petscii_codes.s @@ -16,6 +16,7 @@ !ifdef CONFIG_KEYBOARD_C128_CAPS_LOCK { !set _NEED_CAPS_LOCK = 1 } !ifdef CONFIG_KEYBOARD_C65 { !set _NEED_EXTENDED = 1 } !ifdef CONFIG_KEYBOARD_C65_CAPS_LOCK { !set _NEED_CAPS_LOCK = 1 } +!ifdef CONFIG_MB_M65 { !set _NEED_CAPS_LOCK = 1 } !ifdef CONFIG_MB_M65 { !set _NEED_EXTENDED = 1 } !ifdef CONFIG_KEYBOARD_C65 { !set _NEED_C65KB = 1 } !ifdef CONFIG_MB_M65 { !set _NEED_C65KB = 1 } @@ -34,7 +35,7 @@ !set KEY_FLAG_NO_SCRL = %00100000 } !ifdef _NEED_CAPS_LOCK { - !set KEY_CAPS_LOCK = %00010000 + !set KEY_FLAG_CAPSL = %00010000 } diff --git a/src/aliases/,aliases_ram_lowmem_m65.s b/src/aliases/,aliases_ram_lowmem_m65.s index 1db7a619..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 6c81c0ca..01c8ad26 100644 --- a/src/kernal/keyboard/scnkey.s +++ b/src/kernal/keyboard/scnkey.s @@ -78,7 +78,7 @@ SCNKEY: and #$40 bne @1 ; branch if no CAPS LOCK - lda #KEY_CAPS_LOCK + lda #KEY_FLAG_CAPSL sta SHFLAG @1: @@ -92,7 +92,7 @@ SCNKEY: and #$01 bne @2 ; branch if no CAPS LOCK - lda #KEY_CAPS_LOCK + lda #KEY_FLAG_CAPSL sta SHFLAG @2: @@ -374,8 +374,8 @@ scnkey_handle_caps_lock: } tax lda SHFLAG - and #(%00000111 + KEY_CAPS_LOCK) - cmp #KEY_CAPS_LOCK + and #(%00000111 + KEY_FLAG_CAPSL) + cmp #KEY_FLAG_CAPSL bne @7 ; branch if no special CAPS LOCK handling needed cpx #$41 ; 'A' diff --git a/src/kernal/keyboard_m65/mega65_scnkey.s b/src/kernal/keyboard_m65/mega65_scnkey.s index b8f32e75..4d15f97c 100644 --- a/src/kernal/keyboard_m65/mega65_scnkey.s +++ b/src/kernal/keyboard_m65/mega65_scnkey.s @@ -4,4 +4,109 @@ m65_scnkey: + ; First scan the whole keyboard + + lda KBSCN_BUCKY + sta M65_KB_BUCKY + + 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_detect_SHIFT: + + 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 + + ; 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 + + rts