c64-livecoding/wip-hugo/routines/memory/line/line_down_inv.s
hugova 4d12f20a6e A Fix for D that gets the wrong initial value and the branch logic in line_* checked for the wrong value.
A new proc, line.s that can chose whitch line_* to use
A small test program in source.s
Wrote a smal test program in source.s  (all looks good exept line_up_inv)
2025-03-03 22:08:00 +01:00

84 lines
1.8 KiB
ArmAsm

;;drawing line from 2 cordinates
.proc line_down_inv
;;# (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, #$ff, #$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 < %00000010 00000000: case_2
;;else case 1.
Lag_16 >D, <D, #$00, #$02, 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:
RTS
.endproc