From a442bf910f8065afd50ea66cfe21d7a12c40099d Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Tue, 8 Oct 2019 16:27:07 +0200 Subject: [PATCH] reordered and size-optimized some screen routines --- Makefile | 2 +- c64/kernal/blink_cursor.s | 96 ------------------- c64/kernal/chrin_real.s | 51 ++-------- c64/kernal/chrout_screen.s | 4 +- c64/kernal/e544.clear_screen.s | 4 +- c64/kernal/f1ca.chrout.s | 6 +- .../interrupts/ea31.default_irq_handler.s | 2 +- c64/kernal/screen/cursor.s | 81 ++++++++++++++++ c64/kernal/screen/cursor_enable.s | 10 ++ .../{home_cursor.s => screen/cursor_home.s} | 8 +- c64/kernal/screen/cursor_show.s | 34 +++++++ c64/kernal/screen/screen_code_to_petscii.s | 36 +++++++ 12 files changed, 183 insertions(+), 151 deletions(-) delete mode 100644 c64/kernal/blink_cursor.s create mode 100644 c64/kernal/screen/cursor.s create mode 100644 c64/kernal/screen/cursor_enable.s rename c64/kernal/{home_cursor.s => screen/cursor_home.s} (58%) create mode 100644 c64/kernal/screen/cursor_show.s create mode 100644 c64/kernal/screen/screen_code_to_petscii.s diff --git a/Makefile b/Makefile index c8f9f776..bd47fec9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SRCDIR_COMMON = c64/aliases SRCDIR_BASIC_COMMON = $(SRCDIR_COMMON) c64/basic -SRCDIR_KERNAL_COMMON = $(SRCDIR_COMMON) c64/kernal c64/kernal/assets c64/kernal/jumptable c64/kernal/iec c64/kernal/interrupts c64/kernal/print +SRCDIR_KERNAL_COMMON = $(SRCDIR_COMMON) c64/kernal c64/kernal/assets c64/kernal/jumptable c64/kernal/iec c64/kernal/interrupts c64/kernal/print c64/kernal/screen SRCDIR_BASIC_generic = $(SRCDIR_BASIC_COMMON) c64/basic/,target_generic SRCDIR_BASIC_mega65 = $(SRCDIR_BASIC_COMMON) c64/basic/,target_mega65 diff --git a/c64/kernal/blink_cursor.s b/c64/kernal/blink_cursor.s deleted file mode 100644 index 5d3c5446..00000000 --- a/c64/kernal/blink_cursor.s +++ /dev/null @@ -1,96 +0,0 @@ -// We have the following variables: -// BLNSW (cursor blink switch) -// BLNCT (cursor blink countdown) -// GDBLN (cursor saved character) -// BLNON (if cursor is visible) -// GDCOL (colour under cursor) -// USER (current screen line colour pointer) -// PNT (current screen line pointer) -// PNTR (current screen x position) - -show_cursor_if_enabled: - lda BLNSW - beq !+ - rts -!: lda BLNON - beq show_cursor - rts - -show_cursor: - // Set cursor as though it had just finished the off phase, - // so that the call to blink_cursor paints it - lda #$00 - sta BLNCT - sta BLNON - jsr blink_cursor - // 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 - rts - -blink_cursor: - // Is the cursor enabled? - lda BLNSW - bne no_blink_cursor - - // Do we need to redraw things? - dec BLNCT - bpl no_blink_cursor - - // Check if cursor was visible or not, and toggle - lda BLNON - bne undraw_cursor -draw_cursor: - jsr calculate_screen_line_pointer - - ldy PNTR - lda (PNT),y - sta GDBLN - eor #$80 - sta (PNT),y - // Also set cursor colour - lda (USER),y - sta GDCOL - lda COLOR - sta (USER),y - - lda #1 - sta BLNON - - jmp reset_blink_timer - -undraw_cursor: - jsr calculate_screen_line_pointer - - lda GDBLN - ldy PNTR - sta (PNT),y - lda GDCOL - sta (USER),y - - lda #0 - sta BLNON - // Fall through -reset_blink_timer: - // Rest blink counter - // (Compute's Mapping the 64, p39-40) - lda #20 - sta BLNCT -no_blink_cursor: - rts - -disable_cursor: - lda #$80 - sta BLNSW - // FALL THROUGH -hide_cursor_if_visible: - lda BLNON - bne undraw_cursor - rts - -enable_cursor: - lda #$00 - sta BLNSW - rts - diff --git a/c64/kernal/chrin_real.s b/c64/kernal/chrin_real.s index cbed585e..4d1a3a87 100644 --- a/c64/kernal/chrin_real.s +++ b/c64/kernal/chrin_real.s @@ -9,6 +9,7 @@ // // XXX keyboard part currently does not preserve register Y, to be fixed! +// XXX try to make chrin_real unnecessary (try to fit this into original location) // Reads a byte of input, unless from keyboard. // If from keyboard, then it gets a whole line of input, and returns the first char. @@ -84,8 +85,8 @@ not_end_of_input: read_from_keyboard: - jsr enable_cursor - + jsr cursor_enable + // Wait for a key lda NDX beq chrin_repeat @@ -94,12 +95,12 @@ read_from_keyboard: cmp #$0d bne not_enter - jsr disable_cursor - + jsr cursor_disable + jsr pop_keyboard_buffer - jsr hide_cursor_if_visible - + 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. @@ -170,41 +171,3 @@ pop_keyboard_buffer: cli rts - -screen_code_to_petscii: - cmp #$1b - bcs not_alpha - - clc - adc #$40 - rts - -not_alpha: - cmp #$40 - bcs not_punctuation - - rts - -not_punctuation: - cmp #$5b - bcs not_shifted - - clc - adc #$80 - - rts - -not_shifted: - - cmp #$80 - bcs not_vendor - - // $60-$7F -> $A0-$BF - - clc - adc #$40 - - // FALLTROUGH -not_vendor: - rts - diff --git a/c64/kernal/chrout_screen.s b/c64/kernal/chrout_screen.s index 8ed05fd7..6e4b0ac5 100644 --- a/c64/kernal/chrout_screen.s +++ b/c64/kernal/chrout_screen.s @@ -9,7 +9,7 @@ chrout_screen: // Crude implementation of character output sei // XXX why do we need to disable interrupts? - jsr hide_cursor_if_visible + jsr cursor_hide_if_visible lda SCHAR tax @@ -620,7 +620,7 @@ line_not_linked_del: screen_advance_to_next_line: - // jsr hide_cursor_if_visible + // jsr cursor_hide_if_visible // Go to start of line lda #0 diff --git a/c64/kernal/e544.clear_screen.s b/c64/kernal/e544.clear_screen.s index 90d1999d..9c790007 100644 --- a/c64/kernal/e544.clear_screen.s +++ b/c64/kernal/e544.clear_screen.s @@ -3,6 +3,8 @@ clear_screen: + // XXX it is probably a good idea to hide cursor first + // Clear line link table // (Compute's Mapping the 64 p215) @@ -57,4 +59,4 @@ clearscreen_l3: bne clearscreen_l3 // (Compute's Mapping the 64 p216) - jmp home_cursor + jmp cursor_home diff --git a/c64/kernal/f1ca.chrout.s b/c64/kernal/f1ca.chrout.s index e13da0f8..6c37056a 100644 --- a/c64/kernal/f1ca.chrout.s +++ b/c64/kernal/f1ca.chrout.s @@ -41,7 +41,7 @@ chrout_iec: // FALLTROUGH chrout_done_fail: - jsr show_cursor_if_enabled + jsr cursor_show_if_enabled plp @@ -54,7 +54,7 @@ chrout_done_fail: rts chrout_done_unknown_device: - jsr show_cursor_if_enabled + jsr cursor_show_if_enabled plp @@ -68,7 +68,7 @@ chrout_done_unknown_device: jmp lvs_device_not_found_error chrout_done: - jsr show_cursor_if_enabled + jsr cursor_show_if_enabled plp diff --git a/c64/kernal/interrupts/ea31.default_irq_handler.s b/c64/kernal/interrupts/ea31.default_irq_handler.s index 5ce46892..304fa343 100644 --- a/c64/kernal/interrupts/ea31.default_irq_handler.s +++ b/c64/kernal/interrupts/ea31.default_irq_handler.s @@ -1,7 +1,7 @@ default_irq_handler: - jsr blink_cursor + jsr cursor_blink jsr JSCNKEY jsr JUDTIM // update jiffy clock diff --git a/c64/kernal/screen/cursor.s b/c64/kernal/screen/cursor.s new file mode 100644 index 00000000..59cae342 --- /dev/null +++ b/c64/kernal/screen/cursor.s @@ -0,0 +1,81 @@ + +// +// Variables used: +// - BLNSW (cursor blink switch) +// - BLNCT (cursor blink countdown) +// - GDBLN (cursor saved character) +// - BLNON (if cursor is visible) +// - GDCOL (colour under cursor) +// - USER (current screen line colour pointer) +// - PNT (current screen line pointer) +// - PNTR (current screen x position) +// + + +cursor_blink: + // Is the cursor enabled? + lda BLNSW + bne cursor_blink_end + + // Do we need to redraw things? + dec BLNCT + bpl cursor_blink_end + + // Check if cursor was visible or not, and toggle + lda BLNON + bne cursor_undraw + + // FALLTROUGH + +cursor_draw: + jsr calculate_screen_line_pointer // XXX make sure this is not needed and remove the call + + ldy PNTR + lda (PNT),y + sta GDBLN + eor #$80 + sta (PNT),y + // Also set cursor colour + lda (USER),y + sta GDCOL + lda COLOR + sta (USER),y + + lda #1 + sta BLNON + + bne cursor_blink_timer_reset // branches always + +cursor_disable: + lda #$80 + sta BLNSW + + // FALLTHROUGH + +cursor_hide_if_visible: + lda BLNON + beq cursor_blink_end + +cursor_undraw: + + lda GDBLN + ldy PNTR + sta (PNT),y + lda GDCOL + sta (USER),y + + lda #0 + sta BLNON + + // FALLTROUGH + +cursor_blink_timer_reset: + + // Rest blink counter (Mapping the 64, p39-40) + lda #20 + sta BLNCT + + // FALLTROUGH + +cursor_blink_end: + rts diff --git a/c64/kernal/screen/cursor_enable.s b/c64/kernal/screen/cursor_enable.s new file mode 100644 index 00000000..72646312 --- /dev/null +++ b/c64/kernal/screen/cursor_enable.s @@ -0,0 +1,10 @@ + +// +// Variables used: +// - BLNSW (cursor blink switch) +// + +cursor_enable: + lda #$00 + sta BLNSW + rts diff --git a/c64/kernal/home_cursor.s b/c64/kernal/screen/cursor_home.s similarity index 58% rename from c64/kernal/home_cursor.s rename to c64/kernal/screen/cursor_home.s index 37965f96..42718ce1 100644 --- a/c64/kernal/home_cursor.s +++ b/c64/kernal/screen/cursor_home.s @@ -1,7 +1,9 @@ -// Home the cursor -// (Compute's Mapping the 64 p216) -home_cursor: +// +// Home the cursor (Compute's Mapping the 64 p216) +// + +cursor_home: lda #$00 sta PNTR // x position diff --git a/c64/kernal/screen/cursor_show.s b/c64/kernal/screen/cursor_show.s new file mode 100644 index 00000000..c21b092c --- /dev/null +++ b/c64/kernal/screen/cursor_show.s @@ -0,0 +1,34 @@ + +// +// Variables used: +// - BLNSW (cursor blink switch) +// - BLNON (if cursor is visible) +// - BLNCT (cursor blink countdown) +// + +cursor_show_if_enabled: + lda BLNSW + bne cursor_show_end + lda BLNON + bne cursor_show_end + + // 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 + + // 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: + rts diff --git a/c64/kernal/screen/screen_code_to_petscii.s b/c64/kernal/screen/screen_code_to_petscii.s new file mode 100644 index 00000000..3485a3b9 --- /dev/null +++ b/c64/kernal/screen/screen_code_to_petscii.s @@ -0,0 +1,36 @@ + +screen_code_to_petscii: + cmp #$1B + bcc s2p_adc_40 + +s2p_not_alpha: + cmp #$40 + bcc s2p_end + + // FALLTROUGH + +s2p_not_punctuation: + cmp #$5B + bcs s2p_not_shifted + + // carry already clear here + adc #$80 + + rts + +s2p_not_shifted: + + cmp #$80 + bcs s2p_end // not vendor + + // $60-$7F -> $A0-$BF + +s2p_adc_40: + + clc + adc #$40 + + // FALLTROUGH + +s2p_end: + rts