c64-livecoding/wip-hugo/routines/line/line_down.s

71 lines
1.8 KiB
ArmAsm

;;drawing line from 2 cordinates
.proc line_down
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg!
.include "line.inc"; Defines memory positions, ex X_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 = OO - X_start
LDA Y_end
SEC
SBC Y_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)
;dy_2 = dy*2
mult_16 >dy_2, <dy_2, !
;; D = 2*dy - dx
;; In loop we have that D = D -V
;; So D needs to be at least >=V.
;; V_max = 00000001 11111111
;; For us to work with unsigned numbers we add 00000001 11111111
;; to V and the branch logic to V!
;;D = 2*dy - dx + 2*255
;;Our D is bigger then wikipedia because D is unsigned.
LDA >dy_2
STA >D
LDA <dy_2
STA <D
Add_16 >D, <D, #$ff, #$01, !
Sub_16 >D, <D, dx, #$00
for_x:
jsr pixel_draw
;;Increment X until X_pos = X_end and Y_pos = Y_end
INC X_pos
LDX X_pos
CPX X_end
BEQ end
;;If D < %00000010 00000000: case_2
;;else case 1.
Lag_16 >D, <D, #$00, #$02, case_2
case_1:; C =1 so we can use !
INC Y_pos
Sub_16 >D, <D, >V, <V, !; D = D - V
JMP for_x
case_2: ;; C =0 because LAG_16 so we can use !
Add_16 >D, <D, >dy_2, <dy_2, !;D = D + 2*dy
JMP for_x
end:
RTS
.endproc