A optimisation of line_up_inv.s by moving some logic out of loop

This commit is contained in:
hugova 2025-03-02 23:14:51 +01:00
parent f3712eca9f
commit 1524c837ca
4 changed files with 32 additions and 35 deletions

View file

@ -28,7 +28,6 @@
STA Y_end
;;~~~~~~~~~~
;;We need to clear this memory
LDA #$00
STA <V

View file

@ -1,14 +1,14 @@
;;drawing line from 2 cordinates
.proc line
;;# * (X_end, Y_end) #
;;# #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
;;# * (X_end, Y_end) #
;;# #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
;;Not values but register position in memory
;;Not values but register position in memory
X_end = $04
Y_end = $05
X_pos = $FC
@ -62,7 +62,6 @@
STA <D
Add_16 >D, <D, #$00, #$01
Sub_16 >D, <D, dx, #$00
for_x:
jsr pixel_draw
;;Increment X until X_pos = X_end and Y_pos = Y_end

View file

@ -13,13 +13,10 @@
X_pos = $FC
Y_pos = $FB
dx_2 = $0607
dy = $08
dy = $0c
V = $0809
D = $0a0b
;;Set values
LDA #$00
STA $FD ; for pixel_draw
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$60
STA X_pos
@ -31,37 +28,39 @@
STA Y_end
;;~~~~~~~~~~
;;2*dx = 2*(X_pos - X_end)
;We need to clear this memory
LDA #$00
STA <V
STA <dx_2
STA $FD ; for pixel_draw
;; V = 2*(dy -dx)
;; where: dy = Y_pos - Y_end, dx = X_end - X_start
LDA X_pos
SEC
SBC X_end
STA >dx_2
LDA #$00
STA <dx_2
mult_16 >dx_2, <dx_2
;;dy = (Y_end -Y_pos)
STA >V
STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V)
LDA Y_end
SEC
SBC Y_pos
STA dy
SEC
SBC >V
STA >V; <V = dx - dy
mult_16 >V, <V; V = 2*(dx -dy)
;;D = 2*dx - dy + 2*255. 0 <=D <= 4*255
;;Our D is bigger then wikipedia to not use negative numbers
;dy_2 = dy*2
mult_16 >dx_2, <dx_2
;;D = 2*dx - dy + 2*255
;;Our D is bigger then wikipedia because D is unsigned.
LDA >dx_2
STA >D
LDA <dx_2
STA <D
Add_16 >D, <D, #$00, #$01
Sub_16 >D, <D, dy, #$00
;;We wont use dy, only 2*dy from now on
dy_2 = $0809 ;Lets reuse dy register ($08)
LDA #$00
STA <dy_2
mult_16 >dy_2, <dy_2
for_y:
jsr pixel_draw
;;Increment Y until Y_pos = Y_end and X_pos = X_end
@ -76,10 +75,10 @@ for_y:
BEQ case_2
case_1:
DEC X_pos
Sub_16 >D, <D, >dy_2, <dy_2; D = D - 2*dx
Sub_16 >D, <D, >V, <V; D = D - V
JMP for_y
case_2:
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy
last:
JMP for_y
end:
.endproc

View file

@ -1,6 +1,6 @@
.include "STARTUP.s"
.include "macros/16aritmatic.s"
.include "routines/memory/line_up.s"
.include "routines/memory/line_up_inv.s"
loop_:
jmp loop_