diff --git a/src/kernal/board_m65/mega65_imports.s b/src/kernal/board_m65/mega65_imports.s index bb9c3d10..530b11e4 100644 --- a/src/kernal/board_m65/mega65_imports.s +++ b/src/kernal/board_m65/mega65_imports.s @@ -36,6 +36,9 @@ .label m65_scrtab_txtwidth = KERNAL_0.m65_scrtab_txtwidth .label m65_scrtab_txtheight = KERNAL_0.m65_scrtab_txtheight +.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 #if CONFIG_IEC diff --git a/src/kernal/screen/cursor.s b/src/kernal/screen/cursor.s index f01eccf6..4058778b 100644 --- a/src/kernal/screen/cursor.s +++ b/src/kernal/screen/cursor.s @@ -48,7 +48,7 @@ cursor_draw: lda #1 sta BLNON - bne cursor_blink_timer_reset // branches always + bne cursor_timer_reset // branches always // XXX code below is probably not 100% safe @@ -66,9 +66,9 @@ cursor_hide_if_visible: lda #$FF sta BLNCT - // If cursor is not visible, nothing to do + // If cursor is not visible, not much to do lda BLNON - beq cursor_blink_timer_reset + beq cursor_timer_reset // FALLTROUGH @@ -80,12 +80,17 @@ cursor_undraw: lda GDCOL sta (USER),y + // FALLTROUGH + +cursor_undraw_cont: // entry point used by MEGA65 screen editor + + // Mark cursor as not drawn lda #0 sta BLNON // FALLTROUGH -cursor_blink_timer_reset: +cursor_timer_reset: // Rest blink counter (Mapping the 64, p39-40) lda #20 diff --git a/src/kernal/screen/cursor_show.s b/src/kernal/screen/cursor_show.s index 5a9ad31e..585ce97e 100644 --- a/src/kernal/screen/cursor_show.s +++ b/src/kernal/screen/cursor_show.s @@ -14,28 +14,21 @@ cursor_show_if_enabled: lda BLNSW - bne cursor_show_end + bne !+ lda BLNON - bne cursor_show_end + bne !+ // FALLTROUGH cursor_show: - // Set cursor as though it had just finished the off phase, - // so that the call to cursor_blink paints it - lda #$00 - sta BLNCT - sta BLNON - jsr cursor_blink + // Set the cursor so that it is going to be repainted by the next IRQ - // Then set the timeout to 1 frame, so that the cursor - // blinks under key repeat conditions, like on the original KERNAL lda #$01 sta BLNCT - // FALLTROUGH - -cursor_show_end: + lda #$00 + sta BLNON +!: rts diff --git a/src/kernal/screen_m65/mega65_chrout_screen.s b/src/kernal/screen_m65/mega65_chrout_screen.s index b315630f..8e6564c9 100644 --- a/src/kernal/screen_m65/mega65_chrout_screen.s +++ b/src/kernal/screen_m65/mega65_chrout_screen.s @@ -34,32 +34,13 @@ m65_chrout_screen_literal: // entry point for m65_chrout_screen_quote tax // store screen code, we need .A for calculations - // Preserve .Z on stack, use it toi store screen columnt + // Preserve .Z on stack phz - ldz M65__TXTCOL - // Start from setting M65_LPNT_SCR to point colour memory (starts from $FF80000) + // Prepare .Z and M65_LPNT_SCR for colour memory manipulation - lda #$0F - sta M65_LPNT_SCR+3 - lda #$F8 - sta M65_LPNT_SCR+2 - - lda M65_COLVIEW+1 - sta M65_LPNT_SCR+1 - lda M65_COLVIEW+0 - sta M65_LPNT_SCR+0 - - // Add screen row to the address - - clc - lda M65_TXTROW_OFF+0 - adc M65_LPNT_SCR+0 - sta M65_LPNT_SCR+0 - lda M65_TXTROW_OFF+1 - adc M65_LPNT_SCR+1 - sta M65_LPNT_SCR+1 + jsr m65_helper_scrlpnt_color // Store the new color in screen memory @@ -68,19 +49,7 @@ m65_chrout_screen_literal: // entry point for m65_chrout_screen_quote // Now change M65_LPNT_SCR to point to screen memory - // XXX deduplicate this part - lda M65_SCRSEG+1 - sta M65_LPNT_SCR+3 - lda M65_SCRSEG+0 - sta M65_LPNT_SCR+2 - - clc - lda M65_SCRBASE+0 - adc M65_LPNT_SCR+0 - sta M65_LPNT_SCR+0 - lda M65_SCRBASE+1 - adc M65_LPNT_SCR+1 - sta M65_LPNT_SCR+1 + jsr m65_helper_scrlpnt_to_screen // Store the new character in screen memory, restore .Z @@ -91,6 +60,9 @@ m65_chrout_screen_literal: // entry point for m65_chrout_screen_quote ora #$80 // reverse the character XXX consider doing this within chrout_to_screen_code !: sta_lp (M65_LPNT_SCR),z + + // Restore .Z + plz // Increment screen column by 1 @@ -134,7 +106,7 @@ m65_chrout_fix_txtrow_off: m65_chrout_screen_done: - jsr m65_cursor_show_if_enabled + jsr cursor_show_if_enabled - // XXX change this to return success + // XXX make sure it return success rts diff --git a/src/kernal/screen_m65/mega65_clrscr.s b/src/kernal/screen_m65/mega65_clrscr.s index 1168571c..f410ca46 100644 --- a/src/kernal/screen_m65/mega65_clrscr.s +++ b/src/kernal/screen_m65/mega65_clrscr.s @@ -2,6 +2,8 @@ // #LAYOUT# * * #IGNORE +// XXX deduplicate pointer manipulation + M65_CLRSCR: // Clear additional attributes from the color code diff --git a/src/kernal/screen_m65/mega65_clrwin.s b/src/kernal/screen_m65/mega65_clrwin.s index 34d88a3c..e7a73af1 100644 --- a/src/kernal/screen_m65/mega65_clrwin.s +++ b/src/kernal/screen_m65/mega65_clrwin.s @@ -2,6 +2,8 @@ // #LAYOUT# * * #IGNORE +// XXX deduplicate pointer manipulation + M65_CLRWIN: // Clear additional attributes from the color code diff --git a/src/kernal/screen_m65/mega65_cursor.s b/src/kernal/screen_m65/mega65_cursor.s index b30eae5c..54d0ec36 100644 --- a/src/kernal/screen_m65/mega65_cursor.s +++ b/src/kernal/screen_m65/mega65_cursor.s @@ -13,10 +13,6 @@ m65_cursor_disable: // XXX utilize this! - // Make sure IRQ won't interfere by increasing the counter XXX reuse in legacy mode - lda #$FF - sta BLNCT - // Disable cursor blinking lda #$80 sta BLNSW @@ -29,40 +25,29 @@ m65_cursor_hide_if_visible: lda #$FF sta BLNCT - // If cursor is not visible, nothing to do + // If cursor is not visible, not much to do lda BLNON - beq m65_cursor_blink_timer_reset + beq_16 cursor_timer_reset // FALLTROUGH m65_cursor_undraw: - // XXX provide implementation + // Preserve .Z + phz + // Cursor undraw - color - // Mark cursor as not drawn - lda #0 - sta BLNON + jsr m65_helper_scrlpnt_color + lda GDCOL + sta_lp (M65_LPNT_SCR),z - rts + // Cursor undraw - character -m65_cursor_show_if_enabled: + jsr m65_helper_scrlpnt_to_screen + lda GDBLN + sta_lp (M65_LPNT_SCR),z - // XXX provide implementation - - lda #$00 - sta BLNSW - - // FALLTROUGH - -m65_cursor_blink_timer_reset: // XXX reuse code from main KERNAL - - // Rest blink counter (Mapping the 64, p39-40) - lda #20 - sta BLNCT - - // FALLTROUGH - -m65_cursor_blink_end: - - rts \ No newline at end of file + // Restore .Z and continue as with normal editor + plz + jmp cursor_undraw_cont diff --git a/src/kernal/screen_m65/mega65_cursor_blink.s b/src/kernal/screen_m65/mega65_cursor_blink.s index 6fb5e549..80fd31c8 100644 --- a/src/kernal/screen_m65/mega65_cursor_blink.s +++ b/src/kernal/screen_m65/mega65_cursor_blink.s @@ -62,13 +62,11 @@ m65_cursor_blink_draw: lda_lp (M65_LPNT_IRQ),z sta GDCOL lda COLOR - and #$0F + and #$0F // take current colour, but not extended attributes sta_lp (M65_LPNT_IRQ),z - // Rework pointer to point to screnn memory - jsr m65_cursor_blink_rework_ptr - // Cursor draw - character + jsr m65_cursor_blink_irqpnt_to_screen lda_lp (M65_LPNT_IRQ),z sta GDBLN eor #$80 @@ -89,18 +87,17 @@ m65_cursor_blink_end: m65_cursor_blink_undraw: - lda #0 - sta BLNON - // Cursor undraw - color lda GDCOL sta_lp (M65_LPNT_IRQ),z - // Rework pointer to point to screnn memory - jsr m65_cursor_blink_rework_ptr - // Cursor undraw - character + jsr m65_cursor_blink_irqpnt_to_screen lda GDBLN sta_lp (M65_LPNT_IRQ),z + // Mark cursor as not drawn + lda #0 + sta BLNON + jmp_8 m65_cursor_blink_timer_reset diff --git a/src/kernal/screen_m65/mega65_cursor_blink_rework_ptr.s b/src/kernal/screen_m65/mega65_cursor_blink_irqpnt_to_screen.s similarity index 90% rename from src/kernal/screen_m65/mega65_cursor_blink_rework_ptr.s rename to src/kernal/screen_m65/mega65_cursor_blink_irqpnt_to_screen.s index 7aaffcc0..a5e851a2 100644 --- a/src/kernal/screen_m65/mega65_cursor_blink_rework_ptr.s +++ b/src/kernal/screen_m65/mega65_cursor_blink_irqpnt_to_screen.s @@ -2,7 +2,7 @@ // #LAYOUT# * * #IGNORE -m65_cursor_blink_rework_ptr: +m65_cursor_blink_irqpnt_to_screen: // Adapt pointer to point to screen memory diff --git a/src/kernal/screen_m65/mega65_screen_helpers.s b/src/kernal/screen_m65/mega65_screen_helpers.s new file mode 100644 index 00000000..d5c61caa --- /dev/null +++ b/src/kernal/screen_m65/mega65_screen_helpers.s @@ -0,0 +1,54 @@ +// #LAYOUT# M65 KERNAL_1 #TAKE +// #LAYOUT# * * #IGNORE + + + +m65_helper_scrlpnt_color: + + // Set .Z to the current column + + ldz M65__TXTCOL + + // Setting M65_LPNT_SCR to point to colour memory (starts from $FF80000) + + lda #$0F + sta M65_LPNT_SCR+3 + lda #$F8 + sta M65_LPNT_SCR+2 + + lda M65_COLVIEW+1 + sta M65_LPNT_SCR+1 + lda M65_COLVIEW+0 + sta M65_LPNT_SCR+0 + + // Add screen row to the address + + clc + lda M65_TXTROW_OFF+0 + adc M65_LPNT_SCR+0 + sta M65_LPNT_SCR+0 + lda M65_TXTROW_OFF+1 + adc M65_LPNT_SCR+1 + sta M65_LPNT_SCR+1 + + rts + + +m65_helper_scrlpnt_to_screen: + + // Change M65_LPNT_SCR to point to screen memory (when it points to scren memory) + + lda M65_SCRSEG+1 + sta M65_LPNT_SCR+3 + lda M65_SCRSEG+0 + sta M65_LPNT_SCR+2 + + clc + lda M65_SCRBASE+0 + adc M65_LPNT_SCR+0 + sta M65_LPNT_SCR+0 + lda M65_SCRBASE+1 + adc M65_LPNT_SCR+1 + sta M65_LPNT_SCR+1 + + rts