make char_draw faster using lookup-table

This commit is contained in:
hugova 2025-05-12 12:21:18 +02:00
parent 55e63ff627
commit 3295b71f6b
4 changed files with 30 additions and 50 deletions

View file

@ -57,8 +57,6 @@ calc_byte_to_paint:
AND Y_pos ;; offset to add AND Y_pos ;; offset to add
TAY TAY
;Add_16 btp_mem_pos, btp_mem_pos + 1, #<Bitmap, #>Bitmap, !
;;Let draw some stuff ;;Let draw some stuff
LDA byte_to_paint ;; note that both bytes are used! LDA byte_to_paint ;; note that both bytes are used!
ORA (btp_mem_pos), Y ORA (btp_mem_pos), Y

View file

@ -3,16 +3,8 @@
Y_pos = ARGVEC + 1 Y_pos = ARGVEC + 1
code = ARGVEC + 2 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 ;; private variables
screen_position = $EE ; 16-bit value (uses EF) 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 ;; 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 ;; code and I need it for a 16-bit pointer. Because 6502 pointers expect the bytes to be besides each other

View file

@ -7,21 +7,11 @@
.proc char_draw; user-procedure :clobbers (A Y) :clobbers-arguments 4 .proc char_draw; user-procedure :clobbers (A Y) :clobbers-arguments 4
.include "char.inc" .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. ;;Do arithimatic to know where to read and write bytes.
initial: calculate_petski_position:
;We first need to clear some memory ;We first need to clear some memory
LDA #$00 LDA #$00
STA petski_position + 1 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. ;;We need the relative offset for bytes to read and write.
;; This is code *8 because 8byte is one character ;; This is code *8 because 8byte is one character
@ -32,34 +22,35 @@ initial:
;; Add starting position ;; Add starting position
Add_16 petski_position, petski_position + 1, #<Character_generator_ROM , #>Character_generator_ROM, ! Add_16 petski_position, petski_position + 1, #<Character_generator_ROM , #>Character_generator_ROM, !
;;Calculate screen_position to use calculate_screen_position:
Mov_16 screen_position, screen_position + 1, #<VIC_bank, #>VIC_bank ;; 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 ;; We use a lookup-table for big_y_offset + bitmap_offset (see END.s)
;; *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
LDA Y_pos LDA Y_pos
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 STA X_pos
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi ;; Y += smal_y_offset
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi LDA #%00000111 ; A = y (mod 8)
Add_16 Y_pos_offset_lo, Y_pos_offset_hi, X_pos, #$00, ! AND Y_pos ;; offset to add
;; *2^6 CLC
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi ADC X_pos
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi Add_16 screen_position, screen_position + 1, A, #$00
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi
Mult_16 Y_pos_offset_lo, Y_pos_offset_hi move_data:
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:
;; One character is 8 byte, move these bytes to screen ;; One character is 8 byte, move these bytes to screen
LDY #$07 LDY #$07

View file

@ -2,9 +2,8 @@
.include "char.inc" .include "char.inc"
LDA #$10 LDA #$10
STA code STA code
LDA #04 LDA #$20
STA X_pos STA X_pos
LDA #02
STA Y_pos STA Y_pos
JSR char_draw JSR char_draw
.endscope .endscope