diff --git a/bin/basic_generic.rom b/bin/basic_generic.rom index 447fd20d..e3875ba6 100644 Binary files a/bin/basic_generic.rom and b/bin/basic_generic.rom differ diff --git a/bin/basic_ultimate64.rom b/bin/basic_ultimate64.rom index 5ae0f03b..cbddecf5 100644 Binary files a/bin/basic_ultimate64.rom and b/bin/basic_ultimate64.rom differ diff --git a/bin/kernal_generic.rom b/bin/kernal_generic.rom index 9a23705a..8d00b563 100644 Binary files a/bin/kernal_generic.rom and b/bin/kernal_generic.rom differ diff --git a/bin/kernal_ultimate64.rom b/bin/kernal_ultimate64.rom index 76f62af3..03b1839c 100644 Binary files a/bin/kernal_ultimate64.rom and b/bin/kernal_ultimate64.rom differ diff --git a/bin/mega65.rom b/bin/mega65.rom index 643e1484..50a2efdb 100644 Binary files a/bin/mega65.rom and b/bin/mega65.rom differ diff --git a/bin/mega65_pxlfont.rom b/bin/mega65_pxlfont.rom index 92655da7..b725a017 100644 Binary files a/bin/mega65_pxlfont.rom and b/bin/mega65_pxlfont.rom differ diff --git a/src/,,config_mega65.s b/src/,,config_mega65.s index 29bd1ddc..665650c5 100644 --- a/src/,,config_mega65.s +++ b/src/,,config_mega65.s @@ -68,8 +68,8 @@ // #define CONFIG_LEGACY_SCNKEY // #define CONFIG_KEYBOARD_C128 // #define CONFIG_KEYBOARD_C128_CAPS_LOCK -#define CONFIG_KEYBOARD_C65 // untested -#define CONFIG_KEYBOARD_C65_CAPS_LOCK // untested +// #define CONFIG_KEYBOARD_C65 // untested +// #define CONFIG_KEYBOARD_C65_CAPS_LOCK // untested // #define CONFIG_KEY_REPEAT_DEFAULT // #define CONFIG_KEY_REPEAT_ALWAYS #define CONFIG_KEY_FAST_SCAN diff --git a/src/aliases/,aliases_petscii_codes.s b/src/aliases/,aliases_petscii_codes.s index 6cb39b13..cde7575f 100644 --- a/src/aliases/,aliases_petscii_codes.s +++ b/src/aliases/,aliases_petscii_codes.s @@ -17,7 +17,7 @@ .const KEY_FLAG_VENDOR = %00000010 .const KEY_FLAG_CTRL = %00000100 -#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_FLAG_ALT = %00001000 #if CONFIG_KEYBOARD_C128_CAPS_LOCK || CONFIG_KEYBOARD_C65_CAPS_LOCK .const KEY_CAPS_LOCK = %00010000 @@ -40,12 +40,12 @@ // PETSCII codes for certain C128 and C65 functionalities -#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_BELL = $07 // no key, originally CTRL+G // XXX implement, add to C65 keyboard matrix .const KEY_ESC = $1B #endif -#if CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_TAB = $09 // XXX add to C65 keyboard matrix .const KEY_LINE_FEED = $0A // XXX add to C65 keyboard matrix .const KEY_TAB_SET_CLR = $18 // XXX add to C65 keyboard matrix @@ -69,7 +69,7 @@ .const KEY_F7 = $88 .const KEY_F8 = $8C -#if CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_F9 = $10 .const KEY_F10 = $15 .const KEY_F11 = $16 @@ -78,7 +78,7 @@ .const KEY_F14 = $1A #endif -#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_HELP = $84 #endif @@ -119,7 +119,7 @@ .const KEY_C64_SHIFT_ON = $09 // no key .const KEY_C64_SHIFT_OFF = $08 // no key -#if CONFIG_KEYBOARD_C65 +#if CONFIG_KEYBOARD_C65 || ROM_LAYOUT_M65 .const KEY_C65_SHIFT_OFF = $0B // no key .const KEY_C65_SHIFT_ON = $0C // no key #endif diff --git a/src/aliases/,aliases_ram_lowmem_m65.s b/src/aliases/,aliases_ram_lowmem_m65.s index 1f8064db..b4ebafdc 100644 --- a/src/aliases/,aliases_ram_lowmem_m65.s +++ b/src/aliases/,aliases_ram_lowmem_m65.s @@ -40,16 +40,15 @@ .label M65_SCRSEG = $580 // $580-$581 segment address (2 higher bytes) of the screen memory .label M65_SCRBASE = $582 // $582-$583 first byte of screen memory .label M65_SCRGUARD = $584 // $584-$585 last byte of screen memory + 1 - .label M65_SCRVIEW = $586 // $586-$587 first byte of screen memory viewport - .label M65_COLVIEW = $588 // $588-$589 first byte of color memory viewport - .label M65_SCRVIEWMAX = $58A // $58A-$58B largest allowed value of M65_SCRVIEW - .label M65_SCRMODE = $58C // 0 = 40x25, 1 = 80x25, 2 = 80x50 - .label M64_SCRWINMODE = $58D // $00 = normal mode, $FF = window enabled - .label M65_TXTWIN_X0 = $58E // text window - top-left X coordinate, starting from 0 - .label M65_TXTWIN_Y0 = $58F // text window - top-left Y coordinate, starting from 0 - .label M65_TXTWIN_X1 = $590 // text window - bottom-right X coordinate + 1 - .label M65_TXTWIN_Y1 = $591 // text window - bottom-right Y coordinate + 1 - .label M65_TXTROW_OFF = $592 // $592-$594 offset to the current text row - // $594-$5FF -- UNUSED -- + .label M65_COLVIEW = $586 // $586-$587 first byte of color memory viewport + .label M65_COLVIEWMAX = $588 // $588-$589 largest allowed value of M65_SCRVIEW + .label M65_SCRMODE = $58A // 0 = 40x25, 1 = 80x25, 2 = 80x50 + .label M64_SCRWINMODE = $58B // $00 = normal mode, $FF = window enabled + .label M65_TXTWIN_X0 = $58C // text window - top-left X coordinate, starting from 0 + .label M65_TXTWIN_Y0 = $58D // text window - top-left Y coordinate, starting from 0 + .label M65_TXTWIN_X1 = $58E // text window - bottom-right X coordinate + 1 + .label M65_TXTWIN_Y1 = $58F // text window - bottom-right Y coordinate + 1 + .label M65_TXTROW_OFF = $590 // $590-$591 offset to the current text row + // $592-$5FF -- UNUSED -- .label M65_RS232_INBUF = $600 // $600-$6FF -- reserved for RS-232 input buffer -- .label M65_RS232_OUTBUF = $700 // $700-$7FF -- reserved for RS-232 output buffer -- diff --git a/src/basic/board_m65/mega65_proxies.s b/src/basic/board_m65/mega65_proxies.s index 29350754..46391cb9 100644 --- a/src/basic/board_m65/mega65_proxies.s +++ b/src/basic/board_m65/mega65_proxies.s @@ -9,6 +9,7 @@ proxy_B1_peek_via_OLDTXT: jsr map_NORMAL + #if CONFIG_MEMORY_MODEL_60K .error "not implemented" #elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K @@ -17,6 +18,7 @@ proxy_B1_peek_via_OLDTXT: #else // CONFIG_MEMORY_MODEL_38K lda (OLDTXT),y #endif +!: jmp map_BASIC_1 proxy_B1_poke_via_OLDTXT: @@ -27,13 +29,14 @@ proxy_B1_poke_via_OLDTXT: #else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K sta (OLDTXT),y #endif +!: jmp map_BASIC_1 proxy_B1_JCLALL: jsr map_NORMAL jsr JCLALL - jmp map_BASIC_1 + jmp_8 !- #if CONFIG_DOS_WEDGE @@ -41,14 +44,13 @@ proxy_B1_JCLOSE: jsr map_NORMAL jsr JCLOSE - jmp map_BASIC_1 - + jmp_8 !- proxy_B1_JOPEN: jsr map_NORMAL jsr JOPEN - jmp map_BASIC_1 + jmp_8 !- #endif @@ -56,45 +58,43 @@ proxy_B1_JCHROUT: jsr map_NORMAL jsr JCHROUT - jmp map_BASIC_1 + jmp_8 !- proxy_B1_print_hex_byte: jsr map_NORMAL jsr print_hex_byte - jmp map_BASIC_1 + jmp_8 !- proxy_B1_print_integer: jsr map_NORMAL jsr print_integer - jmp map_BASIC_1 - + jmp_8 !- proxy_B1_print_return: jsr map_NORMAL jsr print_return - jmp map_BASIC_1 - + jmp_8 !- proxy_B1_print_space: jsr map_NORMAL jsr print_space - jmp map_BASIC_1 + jmp_8 !- proxy_B1_plot_set: jsr map_NORMAL jsr plot_set - jmp map_BASIC_1 + jmp_8 !- proxy_B1_M65_SETWIN_Y: jsr map_NORMAL jsr M65_SETWIN_Y - jmp map_BASIC_1 + jmp_8 !- #if CONFIG_DOS_WEDGE @@ -102,23 +102,24 @@ proxy_B1_fetch_character: jsr map_NORMAL jsr fetch_character - jmp map_BASIC_1 + jmp_8 !- proxy_B1_fetch_character_skip_spaces: jsr map_NORMAL jsr fetch_character_skip_spaces - jmp map_BASIC_1 + jmp_8 !- proxy_B1_fetch_uint8: jsr map_NORMAL jsr fetch_uint8 +!: jmp map_BASIC_1 proxy_B1_shell_main_loop: jsr map_NORMAL - jmp shell_main_loop + jmp_8 !- #endif diff --git a/src/kernal/board_m65/mega65_imports.s b/src/kernal/board_m65/mega65_imports.s index 530b11e4..7d139fdc 100644 --- a/src/kernal/board_m65/mega65_imports.s +++ b/src/kernal/board_m65/mega65_imports.s @@ -8,6 +8,7 @@ #import "KERNAL_0_combined.sym" +.label CHROUT = KERNAL_0.proxy_K1_CHROUT .label STOP = KERNAL_0.STOP .label M65_SLOW = KERNAL_0.M65_SLOW .label M65_FAST = KERNAL_0.M65_FAST @@ -36,9 +37,12 @@ .label m65_scrtab_txtwidth = KERNAL_0.m65_scrtab_txtwidth .label m65_scrtab_txtheight = KERNAL_0.m65_scrtab_txtheight +.label cursor_enable = KERNAL_0.cursor_enable .label cursor_undraw_cont = KERNAL_0.cursor_undraw_cont .label cursor_timer_reset = KERNAL_0.cursor_timer_reset .label cursor_show_if_enabled = KERNAL_0.cursor_show_if_enabled +.label chrin_programmable_keys = KERNAL_0.proxy_K1_chrin_programmable_keys +.label pop_keyboard_buffer = KERNAL_0.pop_keyboard_buffer #if CONFIG_IEC diff --git a/src/kernal/board_m65/mega65_proxies.s b/src/kernal/board_m65/mega65_proxies.s index cf274435..3120e933 100644 --- a/src/kernal/board_m65/mega65_proxies.s +++ b/src/kernal/board_m65/mega65_proxies.s @@ -6,26 +6,37 @@ // -#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO +proxy_K1_chrin_programmable_keys: + jsr map_NORMAL + jsr CHROUT + jmp_8 !+ + +proxy_K1_CHROUT: + + jsr map_NORMAL + jsr CHROUT +!: + jmp map_KERNAL_1 + +#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO proxy_K1_kernalerror_ROUTINE_TERMINATED: jsr map_NORMAL jmp kernalerror_ROUTINE_TERMINATED - proxy_K1_lvs_display_loading_verifying: jsr map_NORMAL jsr lvs_display_loading_verifying - jmp map_KERNAL_1 + jmp_8 !- proxy_K1_lvs_display_done: jsr map_NORMAL jsr lvs_display_done - jmp map_KERNAL_1 + jmp_8 !- proxy_K1_lvs_return_last_address: @@ -42,28 +53,26 @@ proxy_K1_lvs_load_verify_error: jsr map_NORMAL jmp lvs_load_verify_error - proxy_K1_print_kernal_message: jsr map_NORMAL jsr print_kernal_message - jmp map_KERNAL_1 + jmp_8 !- proxy_K1_print_return: jsr map_NORMAL jsr print_return - jmp map_KERNAL_1 + jmp_8 !- #endif - #if CONFIG_TAPE_HEAD_ALIGN proxy_K1_CLALL: jsr map_NORMAL jsr CLALL - jmp map_KERNAL_1 + jmp_8 !- #endif diff --git a/src/kernal/board_m65/mega65_viciv_unhide.s b/src/kernal/board_m65/mega65_viciv_unhide.s index 7f1de0a0..179950f3 100644 --- a/src/kernal/board_m65/mega65_viciv_unhide.s +++ b/src/kernal/board_m65/mega65_viciv_unhide.s @@ -8,9 +8,7 @@ // -#if ROM_LAYOUT_M65 || CONFIG_KEYBOARD_C65 - - // XXX viciii_unhide for non-Mega65 build? +#if ROM_LAYOUT_M65 viciv_unhide: diff --git a/src/kernal/keyboard/chrin_keyboard.s b/src/kernal/keyboard/chrin_keyboard.s index a7ab5e83..a539f770 100644 --- a/src/kernal/keyboard/chrin_keyboard.s +++ b/src/kernal/keyboard/chrin_keyboard.s @@ -10,53 +10,54 @@ chrin_keyboard: - // Save .X - stx XSAV + // Preserve .X and .Y registers - // Save .Y + stx XSAV phy_trash_a -chrin_repeat: + // FALLTROUGH + +chrin_keyboard_repeat: // Do we have a line of input we are currently returning? // If so, return the next byte, and clear the flag when we reach the end. - // Do we have a line of input waiting? lda CRSW - beq read_from_keyboard + beq chrin_keyboard_read - // Yes, we have input waiting at (LSXP)+CRSW - // When CRSW = INDX, then we return a carriage return - // and clear the flag + // We have input waiting at (LSXP)+CRSW + // When CRSW = INDX, then we return a carriage return and clear the flag cmp INDX - bne not_end_of_input + bne chrin_keyboard_not_end_of_input - // Return carriage return and clear pending input and quote flags + // Clear pending input and quote flags lda #$00 sta CRSW sta QTSW // FALLTROUGH -empty_line: +chrin_keyboard_empty_line: + // For an empty line, just return the carriage return - // (and do not forget to actually print the carriage return, so that - // the cursor advances and screen scrolls as required) ply_trash_a ldx XSAV clc - lda #$0d + lda #$0D rts -not_end_of_input: - // Advance index - inc CRSW +chrin_keyboard_not_end_of_input: - // Return next byte of waiting + // Advance index, return the next byte + + inc CRSW tay + // FALLTROUGH + chrin_keyboard_return_byte: + lda (LSXP),y jsr screen_check_toggle_quote tax @@ -67,28 +68,28 @@ chrin_keyboard_return_byte: clc rts -read_from_keyboard: +chrin_keyboard_read: jsr cursor_enable // Wait for a key lda NDX - beq chrin_repeat + beq chrin_keyboard_repeat lda KEYD cmp #$0D - bne not_enter + bne chrkin_keyboard_not_enter -chrin_enter: + // FALLTROUGH + +chrin_keyboard_enter: jsr cursor_disable jsr pop_keyboard_buffer jsr cursor_hide_if_visible - // It was enter. - // Note that we have a line of input to return, and return the first byte thereof - // after computing and storing its length. - // (Computes Mapping the 64, p96) + // It was enter. Note that we have a line of input to return, and return the first byte + // after computing and storing its length (Computes Mapping the 64, p96) // Set pointer to line of input lda PNT+0 @@ -120,7 +121,7 @@ chrin_enter_loop: // Retrieve bytes dey - bmi empty_line + bmi chrin_keyboard_empty_line lda (LSXP),y cmp #$20 beq chrin_enter_loop @@ -138,47 +139,18 @@ chrin_enter_loop: // Return first char of line beq chrin_keyboard_return_byte // branch always -not_enter: +chrkin_keyboard_not_enter: lda KEYD #if CONFIG_PROGRAMMABLE_KEYS - ldx #(__programmable_keys_codes_end - programmable_keys_codes - 1) - -chrin_programmable_loop: - - cmp programmable_keys_codes, x - beq chrin_programmable_key - dex - bpl chrin_programmable_loop - - // FALLTROUGH + jsr chrin_programmable_keys + bcc chrin_keyboard_enter #endif // CONFIG_PROGRAMMABLE_KEYS -chrin_print_character: - + // Print character, keep looking for input from keyboard until carriage return jsr CHROUT jsr pop_keyboard_buffer - - // Keep looking for input from keyboard until carriage return - jmp chrin_repeat - -#if CONFIG_PROGRAMMABLE_KEYS - -chrin_programmable_key: - - // .X contains index of the key code, we need offset to key string instead - lda programmable_keys_offsets, x - tax - - // Print all the characters assigned to key -!: - lda programmable_keys_strings, x - beq chrin_enter - jsr CHROUT // our implementation preserves .X too - inx - bne !- // jumps always - -#endif // CONFIG_PROGRAMMABLE_KEYS + jmp chrin_keyboard_repeat diff --git a/src/kernal/keyboard/chrin_programmable_keys.s b/src/kernal/keyboard/chrin_programmable_keys.s new file mode 100644 index 00000000..c785543a --- /dev/null +++ b/src/kernal/keyboard/chrin_programmable_keys.s @@ -0,0 +1,46 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# X16 * #IGNORE +// #LAYOUT# * KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Keyboard part of the CHRIN routine - programmable keys support +// Output: if Carry clear, programmable key was handled +// + + +#if CONFIG_PROGRAMMABLE_KEYS + +chrin_programmable_keys: + + // Check if the key is programmable + + ldx #(__programmable_keys_codes_end - programmable_keys_codes - 1) +!: + cmp programmable_keys_codes, x + beq !+ + dex + bpl !- + + // This is not a programmable key + + sec + rts +!: + // .X contains index of the key code, we need offset to key string instead + + lda programmable_keys_offsets, x + tax + + // Print all the characters assigned to key +!: + lda programmable_keys_strings, x + beq !+ + jsr CHROUT // our implementation preserves .X too + inx + bne !- // jumps always +!: + clc + rts + +#endif // CONFIG_PROGRAMMABLE_KEYS diff --git a/src/kernal/keyboard/scnkey.s b/src/kernal/keyboard/scnkey.s index ac43679c..50965ea7 100644 --- a/src/kernal/keyboard/scnkey.s +++ b/src/kernal/keyboard/scnkey.s @@ -34,30 +34,6 @@ SCNKEY: -#if CONFIG_KEYBOARD_C65 && CONFIG_MB_MEGA_65 - - // Idea by Paul Gardner-Stephen - - lda VIC_XPOS // check raster X position - cmp VIC_XPOS // if it changes, we are on a MEGA65 with VIC-IV registers already visible - bne scnkey_viciv_mode - - // We are on machine that is not in VIC-IV IO mode, so try enabling it (harmless on C64/C65) - // If we are on a C65 (or MEGA65 with C65 VIC-III IO mode selected), the above test would - // have failed, but we could already be in C65 IO mode. In that case, this will disable C65 IO - // mode when done. This is not ideal, but as MEGA65s start C65 mode with VIC-IV IO mode - // selected anyway, it should not be a big problem in practice. - - jsr viciv_unhide - jsr scnkey_viciv_mode - - sta VIC_KEY // hide Mega65 registers - rts - -scnkey_viciv_mode: - -#endif - // Prepare for SHFLAG update lda SHFLAG diff --git a/src/kernal/screen/cursor_enable.s b/src/kernal/screen/cursor_enable.s index d5322360..2208768b 100644 --- a/src/kernal/screen/cursor_enable.s +++ b/src/kernal/screen/cursor_enable.s @@ -13,4 +13,5 @@ cursor_enable: lda #$00 sta BLNSW + rts diff --git a/src/kernal/screen_m65/mega65_chrin_keyboard.s b/src/kernal/screen_m65/mega65_chrin_keyboard.s new file mode 100644 index 00000000..268a6eb3 --- /dev/null +++ b/src/kernal/screen_m65/mega65_chrin_keyboard.s @@ -0,0 +1,112 @@ +// #LAYOUT# M65 KERNAL_1 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Keyboard part of the CHRIN routine, version for MEGA65 native mode +// + + +m65_chrin_keyboard: // XXX connnect this function to Kernal + + // Preserve .X and .Y registers + + phx + phy + + // FALLTROUGH + +m65_chrin_keyboard_repeat: + + // Do we have a line of input we are currently returning? + // If so, return the next byte, and clear the flag when we reach the end. + + lda CRSW + beq m65_chrin_keyboard_read + + // XXX implement + + // We have input waiting at (XXX)+CRSW + // When CRSW = INDX, then we return a carriage return and clear the flag + + cmp INDX + bne m65_chrin_keyboard_not_end_of_input + + // Clear pending input and quote flags + + lda #$00 + sta CRSW + sta QTSW + + // FALLTROUGH + +m65_chrin_keyboard_empty_line: + + // For an empty line, just return the carriage return + + ply + plx + clc + lda #$0D + rts + +m65_chrin_keyboard_not_end_of_input: + + // Advance index, return the next byte + + inc CRSW + tay + + // FALLTROUGH + +m65_chrin_keyboard_return_byte: + + // XXX implement + + rts + +m65_chrin_keyboard_read: + + jsr cursor_enable + + // Wait for a key + lda NDX + beq m65_chrin_keyboard_repeat + + lda KEYD + cmp #$0D + bne m65_chrkin_keyboard_not_enter + + // FALLTROUGH + +m65_chrin_keyboard_enter: + + jsr m65_cursor_disable + jsr pop_keyboard_buffer + jsr m65_cursor_hide_if_visible + + // It was enter. Note that we have a line of input to return, and return the first byte + // after computing and storing its length (Computes Mapping the 64, p96) + + // XXX implement + + rts + + + + + +m65_chrkin_keyboard_not_enter: + + lda KEYD + +#if CONFIG_PROGRAMMABLE_KEYS + + jsr chrin_programmable_keys + bcc m65_chrin_keyboard_enter + +#endif // CONFIG_PROGRAMMABLE_KEYS + + // Print character, keep looking for input from keyboard until carriage return + jsr CHROUT + jsr pop_keyboard_buffer + jmp m65_chrin_keyboard_repeat diff --git a/src/kernal/screen_m65/mega65_chrout_screen.s b/src/kernal/screen_m65/mega65_chrout_screen.s index 8e6564c9..61449b39 100644 --- a/src/kernal/screen_m65/mega65_chrout_screen.s +++ b/src/kernal/screen_m65/mega65_chrout_screen.s @@ -80,10 +80,49 @@ m65_chrout_fix_column_row: // Non-windowed mode - // XXX - // XXX provide implementation - // XXX + // Check for column below 0 + lda M65__TXTCOL + bpl !++ + + lda M65_COLVIEW+0 + ora M65_COLVIEW+1 + ora M65__TXTROW + bne !+ + lda #$00 + sta M65__TXTCOL + jmp_8 !++ +!: + dec M65__TXTROW + lda m65_scrtab_txtwidth,y + sta M65__TXTCOL + dec M65__TXTCOL +!: + // Check for column above maximum + + lda M65__TXTCOL + cmp m65_scrtab_txtwidth,y + bcc !+ + + inc M65__TXTROW + lda #$00 + sta M65__TXTCOL +!: + // Check for row below 0 + + lda M65__TXTROW + bpl !+ + + jsr m65_chrout_fix_scroll_up +!: + // Check for row above maximum + + lda M65__TXTROW + cmp m65_scrtab_txtheight,y + bcc !+ + + jsr m65_chrout_fix_scroll_down +!: jmp_8 m65_chrout_fix_txtrow_off m65_chrout_fix_column_row_win: @@ -110,3 +149,89 @@ m65_chrout_screen_done: // XXX make sure it return success rts + + + +// Try to fix coordinates by scrolling the screen up + +m65_chrout_fix_scroll_up: + + inc M65__TXTROW + + // Check if we can simply adapt the viewport + + lda M65_COLVIEW+0 + ora M65_COLVIEW+1 + beq m65_chrout_fix_scroll_up_end + + // Yes, we can simply adapt the viewport + + sec + lda M65_COLVIEW+0 + sbc #$50 + sta M65_COLVIEW+0 + sta VIC_COLPTR+0 + bcs !+ + dec M65_COLVIEW+1 + dec VIC_COLPTR+1 +!: + sec + lda VIC_SCRNPTR+0 + sbc #$50 + sta VIC_SCRNPTR+0 + bcs !+ + dec VIC_SCRNPTR+1 +!: + // FALLTROUGH + +m65_chrout_fix_scroll_up_end: + + jmp_8 m65_chrout_fix_scroll_done + + +// Try to fix coordinates by scrolling the screen up + +m65_chrout_fix_scroll_down: + + dec M65__TXTROW + + // Check if we can simply adapt the viewport + + lda M65_COLVIEW+1 + cmp M65_COLVIEWMAX+1 + bne !+ + + lda M65_COLVIEW+0 + cmp M65_COLVIEWMAX+0 + beq m65_chrout_fix_scroll_down_scroll +!: + // Yes, we can simply adapt the viewport + + clc + lda M65_COLVIEW+0 + adc #$50 + sta M65_COLVIEW+0 + sta VIC_COLPTR+0 + bcc !+ + inc M65_COLVIEW+1 + inc VIC_COLPTR+1 +!: + clc + lda VIC_SCRNPTR+0 + adc #$50 + sta VIC_SCRNPTR+0 + bcc !+ + inc VIC_SCRNPTR+1 +!: + jmp_8 m65_chrout_fix_scroll_done + +m65_chrout_fix_scroll_down_scroll: + + // XXX implement + + // FALLTROUGH + +m65_chrout_fix_scroll_done: + + ldy M65_SCRMODE + rts diff --git a/src/kernal/screen_m65/mega65_clrscr.s b/src/kernal/screen_m65/mega65_clrscr.s index f410ca46..f2dcfb1c 100644 --- a/src/kernal/screen_m65/mega65_clrscr.s +++ b/src/kernal/screen_m65/mega65_clrscr.s @@ -22,7 +22,7 @@ M65_CLRSCR: m65_clrscr_takeover: // Set the viewport to the beginning of screen memory - variables: - // - M65_SCRVIEW, M65_COLVIEW + // - M65_COLVIEW // To clear the screen, two zeropage long pointers will be used, initialize them too // - M65_LPNT_SCR for screen memory // - M65_LPNT_KERN for colour memory (starts from $FF80000) // XXX preserve this on stack, restore afterwards @@ -37,11 +37,6 @@ m65_clrscr_takeover: lda #$0F sta M65_LPNT_KERN+3 - lda M65_SCRSEG+0 - sta M65_SCRVIEW+0 - lda M65_SCRSEG+1 - sta M65_SCRVIEW+1 - lda M65_SCRBASE+0 sta M65_LPNT_SCR+0 lda M65_SCRBASE+1 diff --git a/src/kernal/screen_m65/mega65_clrwin.s b/src/kernal/screen_m65/mega65_clrwin.s index e7a73af1..d57d9d1d 100644 --- a/src/kernal/screen_m65/mega65_clrwin.s +++ b/src/kernal/screen_m65/mega65_clrwin.s @@ -24,9 +24,12 @@ M65_CLRWIN: // First initialize both pointers - lda M65_SCRVIEW+0 + clc + lda M65_COLVIEW+0 + adc M65_SCRBASE+0 sta M65_LPNT_SCR+0 - lda M65_SCRVIEW+1 + lda M65_COLVIEW+1 + adc M65_SCRBASE+1 sta M65_LPNT_SCR+1 lda M65_SCRSEG+0 sta M65_LPNT_SCR+2 diff --git a/src/kernal/screen_m65/mega65_screen_tables_misc.s b/src/kernal/screen_m65/mega65_screen_tables_misc.s index 51d0b7b6..329d5c7a 100644 --- a/src/kernal/screen_m65/mega65_screen_tables_misc.s +++ b/src/kernal/screen_m65/mega65_screen_tables_misc.s @@ -8,17 +8,17 @@ m65_scrtab_vic_ctrlb: // parameters for VIC control register B .byte %10100000 // 80x25 + extended attributes .byte %10100100 // 80x50 + extended attributes -m65_scrtab_viewmax_lo: // maximum allowed viewport start - low byte +m65_scrtab_colviewmax_lo: // maximum allowed color viewport start - low byte - .byte $B0 - .byte $B0 - .byte $E0 + .byte $10 + .byte $10 + .byte $40 -m65_scrtab_viewmax_hi: // maximum allowed viewport start - high byte +m65_scrtab_colviewmax_hi: // maximum allowed color viewport start - high byte - .byte $96 - .byte $96 - .byte $8E + .byte $27 + .byte $27 + .byte $1F m65_scrtab_scrolx: // values for VIC_SCROLX diff --git a/src/kernal/screen_m65/mega65_scrmodeset.s b/src/kernal/screen_m65/mega65_scrmodeset.s index 981e5b8e..00ecf9a4 100644 --- a/src/kernal/screen_m65/mega65_scrmodeset.s +++ b/src/kernal/screen_m65/mega65_scrmodeset.s @@ -71,17 +71,16 @@ m65_scrmodeset_internal: // entry point for M65_MODE65 // Set the following locations: // - M65_SCRBASE - for screen starting from $xxxx6000 - // - M65_SCRVIEW, VIC_SCRNPTR+0/+1 - for screen viewport starting from the same address + // - VIC_SCRNPTR+0/+1 - for screen viewport start // - M65_COLVIEW, VIC_COLPTR - for using color memory from the start ldx #$60 stx M65_SCRBASE+1 - stx M65_SCRVIEW+1 stx VIC_SCRNPTR+1 ldx #$00 stx M65_SCRBASE+0 - stx M65_SCRVIEW+0 + stx VIC_SCRNPTR+0 stx M65_COLVIEW+0 @@ -91,7 +90,7 @@ m65_scrmodeset_internal: // entry point for M65_MODE65 // Set the following locations: // - M65_SCREND - for max 200 lines of virtual screen - // - M65_SCRVIEWMAX - as above, but depending on the mode + // - M65_COLVIEWMAX - as above, but depending on the mode ldx #$80 stx M65_SCRGUARD+0 @@ -99,9 +98,9 @@ m65_scrmodeset_internal: // entry point for M65_MODE65 stx M65_SCRGUARD+1 ldx M65_SCRMODE - lda m65_scrtab_viewmax_lo, x - sta M65_SCRVIEWMAX+0 - lda m65_scrtab_viewmax_hi, x - sta M65_SCRVIEWMAX+1 + lda m65_scrtab_colviewmax_lo, x + sta M65_COLVIEWMAX+0 + lda m65_scrtab_colviewmax_hi, x + sta M65_COLVIEWMAX+1 rts