From 3295b71f6b784dd924ff4ce39d219324f6eeca07 Mon Sep 17 00:00:00 2001 From: hugova Date: Mon, 12 May 2025 12:21:18 +0200 Subject: [PATCH] make char_draw faster using lookup-table --- wip-hugo/routines/pixel/pixel_draw.s | 2 - wip-hugo/routines/text/char.inc | 8 --- wip-hugo/routines/text/char_draw.s | 67 +++++++++++-------------- wip-hugo/routines/text/char_draw_test.s | 3 +- 4 files changed, 30 insertions(+), 50 deletions(-) diff --git a/wip-hugo/routines/pixel/pixel_draw.s b/wip-hugo/routines/pixel/pixel_draw.s index fb3c7db..fb91601 100755 --- a/wip-hugo/routines/pixel/pixel_draw.s +++ b/wip-hugo/routines/pixel/pixel_draw.s @@ -57,8 +57,6 @@ calc_byte_to_paint: AND Y_pos ;; offset to add TAY - ;Add_16 btp_mem_pos, btp_mem_pos + 1, #Bitmap, ! - ;;Let draw some stuff LDA byte_to_paint ;; note that both bytes are used! ORA (btp_mem_pos), Y diff --git a/wip-hugo/routines/text/char.inc b/wip-hugo/routines/text/char.inc index ffaae58..5f80983 100644 --- a/wip-hugo/routines/text/char.inc +++ b/wip-hugo/routines/text/char.inc @@ -3,16 +3,8 @@ Y_pos = ARGVEC + 1 code = ARGVEC + 2 - ;; 16-bit value, we reuse bytes from X_pos - X_pos_offset_hi = $ED - X_pos_offset_lo = X_pos - ;; 16-bit value, we reuse bytes from Y_pos - Y_pos_offset_hi = $EC - Y_pos_offset_lo = Y_pos - ;; private variables screen_position = $EE ; 16-bit value (uses EF) - temp_value = $EC ; 16-bit value (uses ED) ;; What you will see bellow is .. interesting. I want to reuse ;; code and I need it for a 16-bit pointer. Because 6502 pointers expect the bytes to be besides each other diff --git a/wip-hugo/routines/text/char_draw.s b/wip-hugo/routines/text/char_draw.s index 81c909c..00a8099 100644 --- a/wip-hugo/routines/text/char_draw.s +++ b/wip-hugo/routines/text/char_draw.s @@ -7,21 +7,11 @@ .proc char_draw; user-procedure :clobbers (A Y) :clobbers-arguments 4 .include "char.inc" - ;#### TEMP INIT DATA #### - LDA #$10 - STA code - LDA #04 - STA X_pos - LDA #02 - STA Y_pos - - ;;Do arithimatic to know where to read and write bytes. -initial: +;;Do arithimatic to know where to read and write bytes. +calculate_petski_position: ;We first need to clear some memory LDA #$00 STA petski_position + 1 - STA Y_pos_offset_hi - STA X_pos_offset_hi ;;We need the relative offset for bytes to read and write. ;; This is code *8 because 8byte is one character @@ -32,34 +22,35 @@ initial: ;; Add starting position Add_16 petski_position, petski_position + 1, #Character_generator_ROM, ! - ;;Calculate screen_position to use - Mov_16 screen_position, screen_position + 1, #VIC_bank +calculate_screen_position: + ;; Therefore we have that: btp_mem_pos = big_x_offset + smal_y_offset + big_y_offset + bitmap_offset - ;; Add the X_pos has a offset multiplier of *8 because 1 chunk = 8 addresses - ;; *8 - Mult_16 X_pos_offset_lo, X_pos_offset_hi - Mult_16 X_pos_offset_lo, X_pos_offset_hi - Mult_16 X_pos_offset_lo, X_pos_offset_hi - ;; Add - Add_16 screen_position, screen_position + 1, X_pos, #$00, ! - - ;; And Y_pos has a offset multiplier of "screen length" = 320 = (2*2 +1)*2^6 - ;;Y_pos*2*2 +1 |Lets reuse X_pos for storage + ;; We use a lookup-table for big_y_offset + bitmap_offset (see END.s) LDA Y_pos - STA X_pos - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Add_16 Y_pos_offset_lo, Y_pos_offset_hi, X_pos, #$00, ! - ;; *2^6 - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - Mult_16 Y_pos_offset_lo, Y_pos_offset_hi - ;; Add - Add_16 screen_position, screen_position + 1, Y_pos_offset_lo, Y_pos_offset_hi, ! - initial_end: + LSR A + LSR A + ;; We need to remove the last digit if its still there + ;; same as LSR ASR + AND #%11111110 + TAX + LDA big_y_offset, X + STA screen_position + INX + LDA big_y_offset, X + STA screen_position + 1 + + ;; Y = big_x_offset + LDA #%11111000 + AND X_pos + STA X_pos + ;; Y += smal_y_offset + LDA #%00000111 ; A = y (mod 8) + AND Y_pos ;; offset to add + CLC + ADC X_pos + Add_16 screen_position, screen_position + 1, A, #$00 + +move_data: ;; One character is 8 byte, move these bytes to screen LDY #$07 diff --git a/wip-hugo/routines/text/char_draw_test.s b/wip-hugo/routines/text/char_draw_test.s index e27607e..2a54446 100644 --- a/wip-hugo/routines/text/char_draw_test.s +++ b/wip-hugo/routines/text/char_draw_test.s @@ -2,9 +2,8 @@ .include "char.inc" LDA #$10 STA code - LDA #04 + LDA #$20 STA X_pos - LDA #02 STA Y_pos JSR char_draw .endscope