Optimisation by moving logic out of loop for faster execution.

This should be implemented on the other line_* files
This commit is contained in:
hugova 2025-03-02 18:05:20 +01:00
parent 0940d9f9f9
commit ee69828ec7

View file

@ -12,42 +12,50 @@
Y_end = $05
X_pos = $FC
Y_pos = $FB
dx = $0c
dy_2 = $0607
dx = $08
V = $0809 ;Lets reuse dx register ($08)
D = $0a0b
;;Set values
LDA #$00
STA $FD ; for pixel_draw
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$00
STA X_pos
STA Y_pos
LDA #$f0
LDA #$90
STA X_end
LDA #$80
LDA #$10
STA Y_end
;;~~~~~~~~~~
;;2*dy = 2*(Y_end -Y_pos)
;;We need to clear this memory
LDA #$00
STA <V
STA <dy_2
STA $FD ; for pixel_draw
;; V = 2*(dx -dy)
;; where: dy = Y_end - Y_start, dx = X_end - X_start
LDA Y_end
SEC
SBC Y_pos
STA >dy_2
LDA #$00
STA <dy_2
mult_16 >dy_2, <dy_2
;;dx = (X_end -X_pos)
STA >V
STA >dy_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA X_end
SEC
SBC X_pos
STA dx
SEC
SBC >V
STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy)
;;D = 2*dy - dx + 2*255. 0 <=D <= 4*255
;;Our D is bigger then wikipedia to not use negative numbers
;dy_2 = dy*2
mult_16 >dy_2, <dy_2
;;D = 2*dy - dx + 2*255
;;Our D is bigger then wikipedia because D is unsigned.
LDA >dy_2
STA >D
LDA <dy_2
@ -55,12 +63,6 @@
Add_16 >D, <D, #$00, #$01
Sub_16 >D, <D, dx, #$00
;;We wont use dx, only 2*dx from now on
dx_2 = $0809 ;Lets reuse dx register ($08)
LDA #$00
STA <dx_2
mult_16 >dx_2, <dx_2
for_x:
jsr pixel_draw
;;Increment X until X_pos = X_end and Y_pos = Y_end
@ -75,10 +77,10 @@ for_x:
BEQ case_2
case_1:
INC Y_pos
Sub_16 >D, <D, >dx_2, <dx_2; D = D - 2*dx
Sub_16 >D, <D, >V, <V; D = D - V
JMP for_x
case_2:
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
last:
JMP for_x
end:
.endproc