c64-livecoding/wip-hugo/routines/memory/line_down_inv.s
hugova f3712eca9f Move logic outside loop for performance reasons.
Same as earlier commit but for line_down_inv.s, line_up.s
Comment: Should do the same for line_up_inv.s
2025-03-02 18:29:58 +01:00

85 lines
1.8 KiB
ArmAsm

;;drawing line from 2 cordinates
.proc line
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg!
;;Not values but register position in memory
X_end = $04
Y_end = $05
X_pos = $FC
Y_pos = $FB
dy = $0c
dx_2 = $0607
V = $0809
D = $0a0b
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$00
STA X_pos
STA Y_pos
LDA #$40
STA X_end
LDA #$a0
STA Y_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_end - Y_start, dx = X_end - X_start
LDA X_end
SEC
SBC X_pos
STA >V
STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V)
LDA Y_end
SEC
SBC Y_pos
STA dy
SEC
SBC >V
STA >V; <V = dy - dx
mult_16 >V, <V; V = 2*(dy -dx)
;dx_2 = dx*2
mult_16 >dx_2, <dx_2
;;D = 2*dy - dx + 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
for_y:
jsr pixel_draw
;;Increment Y until Y_pos = Y_end and X_pos = X_end
INC Y_pos
LDY Y_pos
CPY Y_end
BEQ end
;;If D < %00000001 11111111 <==> >D ==0, then: case_2
LDA <D; if <D > 0 then: case_1
CMP #$00
BEQ case_2
case_1:
INC X_pos
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*dx
JMP for_y
end:
.endproc