diff --git a/src/aliases/,aliases_ram_lowmem_m65.s b/src/aliases/,aliases_ram_lowmem_m65.s index 6bbc5813..af7d83bb 100644 --- a/src/aliases/,aliases_ram_lowmem_m65.s +++ b/src/aliases/,aliases_ram_lowmem_m65.s @@ -39,24 +39,25 @@ ; $580-$5FF - reserved for KERNAL - !addr M65_SCRSEG = $580 ; $580-$581 segment address (2 higher bytes) of the screen memory - !addr M65_SCRBASE = $582 ; $582-$583 first byte of screen memory - !addr M65_SCRGUARD = $584 ; $584-$585 last byte of screen memory + 1 XXX is it needed? - !addr M65_COLGUARD = $586 ; $586-$587 last byte of colour memory + 1 - !addr M65_COLVIEW = $588 ; $588-$589 first byte of color memory viewport - !addr M65_COLVIEWMAX = $58A ; $58A-$58B largest allowed value of M65_COLVIEW - !addr M65_SCRMODE = $58C ; 0 = 40x25, 1 = 80x25, 2 = 80x50 - !addr M65_SCRWINMODE = $58D ; $00 = normal mode, $FF = window enabled - !addr M65_TXTWIN_X0 = $58E ; text window - top-left X coordinate, starting from 0 - !addr M65_TXTWIN_Y0 = $58F ; text window - top-left Y coordinate, starting from 0 - !addr M65_TXTWIN_X1 = $590 ; text window - bottom-right X 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_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 - + !addr M65_SCRSEG = $580 ; $580-$581 segment address (2 higher bytes) of the screen memory + !addr M65_SCRBASE = $582 ; $582-$583 first byte of screen memory + !addr M65_SCRGUARD = $584 ; $584-$585 last byte of screen memory + 1 XXX is it needed? + !addr M65_COLGUARD = $586 ; $586-$587 last byte of colour memory + 1 + !addr M65_COLVIEW = $588 ; $588-$589 first byte of color memory viewport + !addr M65_COLVIEWMAX = $58A ; $58A-$58B largest allowed value of M65_COLVIEW + !addr M65_SCRMODE = $58C ; 0 = 40x25, 1 = 80x25, 2 = 80x50 + !addr M65_SCRWINMODE = $58D ; $00 = normal mode, $FF = window enabled + !addr M65_TXTWIN_X0 = $58E ; text window - top-left X coordinate, starting from 0 + !addr M65_TXTWIN_Y0 = $58F ; text window - top-left Y coordinate, starting from 0 + !addr M65_TXTWIN_X1 = $590 ; text window - bottom-right X 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_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 + !addr M65_KB_PRESSED = $560 ; $560-$562 keys pressed, used during scanning keyboard + !addr M65_KB_PRESSED_OLD = $563 ; $563-$565 keys pressed during previous scan ; $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 -- diff --git a/src/kernal/board_m65/mega65_imports.s b/src/kernal/board_m65/mega65_imports.s index 60a496f9..beebb89e 100644 --- a/src/kernal/board_m65/mega65_imports.s +++ b/src/kernal/board_m65/mega65_imports.s @@ -29,6 +29,7 @@ ;; #ALIAS# colour_codes = KERNAL_0.colour_codes ;; #ALIAS# screen_check_toggle_quote = KERNAL_0.screen_check_toggle_quote ;; #ALIAS# screen_code_to_petscii = KERNAL_0.screen_code_to_petscii +;; #ALIAS# m65_scnkey_init_pressed = KERNAL_0.m65_scnkey_init_pressed ;; #ALIAS# setup_irq_timer = KERNAL_0.setup_irq_timer ;; #ALIAS# wait_x_bars = KERNAL_0.wait_x_bars diff --git a/src/kernal/board_m65/mega65_native_meminit.s b/src/kernal/board_m65/mega65_native_meminit.s index 6ff5e8e2..a15775bb 100644 --- a/src/kernal/board_m65/mega65_native_meminit.s +++ b/src/kernal/board_m65/mega65_native_meminit.s @@ -4,11 +4,17 @@ m65_native_meminit: + ; Initialize variables for keyboard scanning + + jsr m65_scnkey_init_pressed + ; Prepare generic DMAgic list jsr m65_dmagic_init + ; ; Copy MEGA65 charset to target location - set size + ; lda #$00 sta M65_DMAJOB_SIZE_0 diff --git a/src/kernal/keyboard/scnkey.s b/src/kernal/keyboard/scnkey.s index 01c8ad26..554d78fd 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 ; no space in buffer + bcs scnkey_buffer_full ; no space in buffer ; Reinitialize secondary counter @@ -466,7 +466,7 @@ scnkey_handle_repeat: rts -scnkey_early_repeat: +scnkey_buffer_full: ; Keyboard buffer was full - at least make sure the key ; will be repeated as soon as possible diff --git a/src/kernal/keyboard/scnkey_set_keytab.s b/src/kernal/keyboard/scnkey_set_keytab.s index e4990d65..98d90a77 100644 --- a/src/kernal/keyboard/scnkey_set_keytab.s +++ b/src/kernal/keyboard/scnkey_set_keytab.s @@ -61,6 +61,8 @@ 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 @@ -105,7 +107,4 @@ scnkey_toggle_if_needed: ; entry for SCNKEY (TWW/CTR version) sta VIC_YMCSB @1: rts - -} - -} ; no CONFIG_LEGACY_SCNKEY +} \ No newline at end of file diff --git a/src/kernal/keyboard_m65/mega65_scnkey.s b/src/kernal/keyboard_m65/mega65_scnkey.s index a9496051..343b8be1 100644 --- a/src/kernal/keyboard_m65/mega65_scnkey.s +++ b/src/kernal/keyboard_m65/mega65_scnkey.s @@ -69,21 +69,116 @@ m65_scnkey_shflag_next: ; Scan the keyboard matrix stored in memory to determine which keys were pressed ; + ldx #$02 +@1: + lda M65_KB_PRESSED, x + sta M65_KB_PRESSED_OLD, x + dex + bpl @1 + + jsr m65_scnkey_init_pressed + lda M65_KB_COLSUM + beq m65_scnkey_no_key ; branch if no key was pressed XXX try joystick + + ldx #$08 + + ; FALLTROUGH + +m65_scnkey_loop_1: + + lda M65_KB_COLSCAN, x + pha + ldy #$FF + + ; FALLTROUGH + +m65_scnkey_loop_2: + + iny + pla + beq m65_scnkey_next_1 + asl + pha + bcc m65_scnkey_loop_2 + + ; Found a pressed key - add it to the list + + lda M65_KB_PRESSED+2 + bpl m65_scnkey_jam ; branch if too many keys pressed + lda M65_KB_PRESSED+1 + sta M65_KB_PRESSED+2 + lda M65_KB_PRESSED+0 + sta M65_KB_PRESSED+1 + + sty M65_KB_PRESSED+0 + txa + asl + asl + asl + clc + adc M65_KB_PRESSED+0 + sta M65_KB_PRESSED+0 + + bra m65_scnkey_loop_2 + +m65_scnkey_next_1: + + dex + bpl m65_scnkey_loop_1 + + ; + ; Analyze currently and previously pressed keys + ; + + ; XXX add proper implementation + ldx M65_KB_PRESSED+0 + + ; + ; Convert the key coordinates to key code + ; + + ; XXX add proper implementation + ldy __kb_matrix_normal, x beq m65_scnkey_no_key +m65_scnkey_output_key: + + ; + ; Output selected key to the keyboard buffer + ; + + ; Check if we have free space in the keyboard buffer + + lda NDX + cmp XMAX + +bcs scnkey_buffer_full + + ; Put the key into the keyboard buffer + + tya + ldy NDX + sta KEYD, y + inc NDX + + rts + + ; XXX - - -m65_scnkey_no_key: +m65_scnkey_jam: ; XXX + jmp m65_scnkey_init_pressed + +m65_scnkey_no_key: + + ; XXX rts diff --git a/src/kernal/keyboard_m65/mega65_scnkey_init_pressed.s b/src/kernal/keyboard_m65/mega65_scnkey_init_pressed.s new file mode 100644 index 00000000..35e2761d --- /dev/null +++ b/src/kernal/keyboard_m65/mega65_scnkey_init_pressed.s @@ -0,0 +1,12 @@ +;; #LAYOUT# M65 KERNAL_0 #TAKE +;; #LAYOUT# * * #IGNORE + + +m65_scnkey_init_pressed: + + lda #$FF + sta M65_KB_PRESSED+0 + sta M65_KB_PRESSED+1 + sta M65_KB_PRESSED+2 + + rts