c64-livecoding/wip-hugo/routines/line/line_down.s

103 lines
3 KiB
ArmAsm

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;drawing line from 2 cordinates
;;# (X_pos, Y_pos) #
;;# * #
;;# * #
;;# * #
;;# (X_end, Y_end) #
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Max 45deg!
.proc line_down
.include "line.inc"; Defines memory positions, ex X_pos
;;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_end - Y_start, dx = OO - X_start
LDA Y_end
SEC
SBC Y_pos
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
;; In loop we have that D = D -V
;; So D needs to be at least >=V.
;; V_max = 00000001 11111111
;; For us to work with unsigned numbers we add 00000001 11111111
;; to V and the branch logic to V!
;;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
LDY #$00
jsr pixel_draw ;;only used first pixel. after this relative position is abused
;;From line_test_time this is at program_start + list_file_offset = $080D + $0116 = $0923
for_x:
;; Lets increment btp_mem_pos with +8
;; Read more in pixel_draw to understand this!
LDX #$00
LDA byte_to_paint
ORA (>btp_mem_pos, X)
STA (>btp_mem_pos, X)
increment_pixel_x:
CLC
ROR byte_to_paint
BCS move_8px_left
JMP increment_pixel_x_end
move_8px_left:
;; add +8 to btp_mem_pos. Find more of why in pixel_draw
Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00
;; reset byte_to_paint
LDA #%10000000
STA byte_to_paint
increment_pixel_x_end:
INC X_pos;; legacy
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:; C =1 so we can use !
Sub_16 >D, <D, >V, <V, ! ; D = D - V
increment_y_pos:
Add_16 >btp_mem_pos, <btp_mem_pos, #$01, #$00
INY
CPY #$08 ;
BEQ move_8px_down
jmp for_x
move_8px_down: ; Z=1 --> C=1
;; +320-8 bytes
LDY #$00
Add_16 >btp_mem_pos, <btp_mem_pos,#$38 , #$01
jmp for_x
increment_y_pos_end:
case_2: ;; C =0 because LAG_16 so we can use !
Add_16 >D, <D, >dy_2, <dy_2, ! ;D = D + 2*dy
JMP for_x
end:
RTS
.endproc