c64-livecoding/wip-hugo/routines/memory/line_up_inv.s

84 lines
1.8 KiB
ArmAsm

;drawing line from 2 cordinates
.proc line
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT Y_pos <= Y_end, X_pos >= X_end. Min 45deg!
;;Not values but register position in memory
X_end = $04
Y_end = $05
X_pos = $FC
Y_pos = $FB
dx_2 = $0607
dy = $0c
V = $0809
D = $0a0b
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$60
STA X_pos
STA Y_pos
LDA #$50
STA X_end
LDA #$90
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_pos - Y_end, dx = X_end - X_start
LDA X_pos
SEC
SBC X_end
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)
;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
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:
DEC 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*dy
JMP for_y
end:
.endproc