c64-livecoding/wip-hugo/routines/memory/line/line_up.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_up
;;# * (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
X_end = $04
Y_end = $05
X_pos = $FC
Y_pos = $FB
dy_2 = $0607
dx = $0c
V = $0809
D = $0a0b
;;example values ~~~~~ SHOULD BE PRECOMPILED
;LDA #$90
;STA X_pos
;STA Y_pos
;LDA #$aa
;STA X_end
;LDA #$80
;STA Y_end
;;~~~~~~~~~~
;;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_pos - Y_end, dx = X_end - X_start
LDA Y_pos
SEC
SBC Y_end
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 + 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:
DEC Y_pos
Sub_16 >D, <D, >V, <V; D = D - V
JMP for_x
case_2:
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
JMP for_x
end:
RTS
.endproc