optimise circle using lookup table

This commit is contained in:
hugova 2025-07-01 23:49:15 +02:00
parent 7d55bc9ed8
commit 5bb62aed88
6 changed files with 47 additions and 43 deletions

View file

@ -1,19 +1,33 @@
inverse_factor_value: ;lookup 00000001 --gives--> 10000000 , etc etc. only 1st 1 in binary numbers inverse_factor_value: ;lookup 00000001 --gives--> 10000000 , etc etc. only 1st 1 in binary numbers
NOP NOP
.byte %10000000, %01000000 .byte %10000000, %01000000; (inverse factor value)
NOP NOP
.byte %00100000 .byte %00100000; (inverse factor value)
NOP
NOP;.byte $0; (log)
NOP;.byte $1; (log)
.byte %00010000; (inverse factor value)
log:
NOP
.byte $0; (log)
.byte $1; (log)
NOP
.byte $2
NOP NOP
NOP NOP
NOP .byte %00001000; (inverse factor value)
.byte %00010000 .byte $3
NOP
NOP NOP
NOP NOP
;; i put another lookup table where nops normaly are' ;; i put another lookup table where nops normaly are'
binary_factor: binary_factor:
.byte %10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001 .byte %10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001; (binary factor)
;; ^ this one it is (in inverse_faktor value) ;; ^(log)
NOP
NOP
NOP
NOP
.byte %00000100; (inverse factor value)
NOP NOP
NOP NOP
NOP NOP
@ -22,11 +36,7 @@ NOP
NOP NOP
NOP NOP
NOP NOP
NOP .byte $5
NOP
NOP
NOP
.byte %00000100
NOP NOP
NOP NOP
NOP NOP
@ -49,6 +59,8 @@ NOP
NOP NOP
NOP NOP
NOP NOP
.byte %00000010; (inverse factor value)
NOP NOP
NOP NOP
NOP NOP
@ -57,8 +69,7 @@ NOP
NOP NOP
NOP NOP
NOP NOP
NOP .byte $6
.byte %00000010
;; i put another lookup table where nops normaly are ;; i put another lookup table where nops normaly are
Bitmap = $4000 Bitmap = $4000
;;This is used by pixel_draw! look at it for more detail ;;This is used by pixel_draw! look at it for more detail
@ -117,13 +128,13 @@ NOP
NOP NOP
NOP NOP
NOP NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
.byte %00000001 .byte %00000001
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
.byte $7

View file

@ -9,8 +9,10 @@
Y_rel = $E2 Y_rel = $E2
temp = $E3 temp = $E3
temp_ = $E4 temp_ = $E4
X_swap = $E5 temo__ = $E5
byte_to_paint_swap = $EF byte_to_paint_qaa = byte_to_paint
byte_to_paint_qcb = $EB ;16bit value (uses EC)
; E8 - EA is used by pixel.inc ; E8 - EA is used by pixel.inc
btp_mem_pos_center = $E6 ; 16bit value (uses E7) btp_mem_pos_center = $E6 ; 16bit value (uses E7)
btp_mem_pos_center_two = btp_mem_pos_center btp_mem_pos_center_two = btp_mem_pos_center

View file

@ -104,8 +104,7 @@ move_8px_left:
Sub_16 btp_mem_pos_qdb, btp_mem_pos_qdb +1, #$40, #$01, ! ;+320 Sub_16 btp_mem_pos_qdb, btp_mem_pos_qdb +1, #$40, #$01, ! ;+320
;; Restores byte to paint ;; Restores byte to paint
LDX #%00000001 INC byte_to_paint
STX byte_to_paint
LDA t2 LDA t2
decrement_x_pos_end: decrement_x_pos_end:

View file

@ -63,20 +63,12 @@ draw_qaa:
draw_qcb:; xy swoped draw_qcb:; xy swoped
STY temp STY temp
LDA byte_to_paint
STA temp__
;;modify Y_pos LDX byte_to_paint
LDY #$00 LDA inverse_factor_value, X;; (see END.s)
JMP goto_loop TAX
loop: LDA log, X
INY TAY
goto_loop:
ASL byte_to_paint
BCC loop
revert_byte_to_paint:
LDA temp__
STA byte_to_paint
;;modify X_pos ;;modify X_pos
LDX temp LDX temp

View file

@ -3,7 +3,7 @@
LDA #$50 LDA #$50
STA X_pos STA X_pos
STA Y_pos STA Y_pos
LDA #$55 LDA #$40
STA radius STA radius
JSR circle JSR circle
.endscope .endscope

View file

@ -10,9 +10,9 @@
;.include "routines/arithmatic/mult_test.s" ;.include "routines/arithmatic/mult_test.s"
;.include "routines/arithmatic/div_test.s" ;.include "routines/arithmatic/div_test.s"
;.include "routines/circle/circle_test.s" .include "routines/circle/circle_test.s"
;.include "routines/circle/circle_test_size.s" ;.include "routines/circle/circle_test_size.s"
.include "routines/circle/circle_test_position.s" ;.include "routines/circle/circle_test_position.s"
;.include "routines/line/line_test.s" ;.include "routines/line/line_test.s"
;.include "routines/text/char_draw_test.s" ;.include "routines/text/char_draw_test.s"
;.include "routines/pixel/pixel_test.s" ;.include "routines/pixel/pixel_test.s"