c64-livecoding/wip-hugo/routines/memory/line_down.s
hugova 0940d9f9f9 1. A fix for a bug where D gets the wrong initial value (2 bytes where flipped)
2. Implemented line drawing for the other 3 cases
2025-03-02 16:51:55 +01:00

84 lines
1.7 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. 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 = $08
D = $0a0b
;;Set values
LDA #$00
STA $FD ; for pixel_draw
;example values ~~~~~ SHOULD BE PRECOMPILED
LDA #$00
STA X_pos
STA Y_pos
LDA #$f0
STA X_end
LDA #$80
STA Y_end
;;~~~~~~~~~~
;;2*dy = 2*(Y_end -Y_pos)
LDA Y_end
SEC
SBC Y_pos
STA >dy_2
LDA #$00
STA <dy_2
mult_16 >dy_2, <dy_2
;;dx = (X_end -X_pos)
LDA X_end
SEC
SBC X_pos
STA dx
;;D = 2*dy - dx + 2*255. 0 <=D <= 4*255
;;Our D is bigger then wikipedia to not use negative numbers
LDA >dy_2
STA >D
LDA <dy_2
STA <D
Add_16 >D, <D, #$00, #$01
Sub_16 >D, <D, dx, #$00
;;We wont use dx, only 2*dx from now on
dx_2 = $0809 ;Lets reuse dx register ($08)
LDA #$00
STA <dx_2
mult_16 >dx_2, <dx_2
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 < %00000001 11111111 <==> >D ==0, then: case_2
LDA <D; if <D > 0 then: case_1
CMP #$00
BEQ case_2
case_1:
INC Y_pos
Sub_16 >D, <D, >dx_2, <dx_2; D = D - 2*dx
case_2:
Add_16 >D, <D, >dy_2, <dy_2;D = D + 2*dy
last:
JMP for_x
end:
.endproc