c64-livecoding/wip-hugo/routines/memory/line_down_inv.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

87 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. 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 = $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 #$40
STA X_end
LDA #$a0
STA Y_end
;;~~~~~~~~~~
;;2*dx = 2*(X_end -X_pos)
LDA X_end
SEC
SBC X_pos
STA >dx_2
LDA #$00
STA <dx_2
mult_16 >dx_2, <dx_2
;;dy = (Y_end -Y_pos)
LDA Y_end
SEC
SBC Y_pos
STA dy
;;D = 2*dx - dy + 2*255. 0 <=D <= 4*255
;;Our D is bigger then wikipedia to not use negative numbers
LDA >dx_2
STA >D
LDA <dx_2
STA <D
Add_16 >D, <D, #$00, #$01
Sub_16 >D, <D, dy, #$00
;;We wont use dy, only 2*dy from now on
dy_2 = $0809 ;Lets reuse dy register ($08)
LDA #$00
STA <dy_2
mult_16 >dy_2, <dy_2
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:
INC X_pos
;; D = D - 2*dx
Sub_16 >D, <D, >dy_2, <dy_2
case_2:
;;D = D + 2*dy
Add_16 >D, <D, >dx_2, <dx_2
last:
JMP for_y
end:
.endproc