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

101 lines
2.5 KiB
ArmAsm

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;drawing line from 2 cordinates
;;# * (X_end, Y_end) #
;;# #
;;# * #
;;# * #
;;# (X_pos, Y_pos) #
;;
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
.proc line_up
.include "line.inc"; Defines memory positions, ex X_pos
;LDA #$20
;STA X_pos
;STA Y_pos
;LDA #$10
;STA Y_end
;LDA #$40
;STA X_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_end - Y_start, dx = OO - 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
;; 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
jsr pixel_draw
;INY ; Dont want underflow
;LDY #$09
;Sub_16 >btp_mem_pos, <btp_mem_pos, #$40, #$01 ;-320
LDX X_pos
for_x:
LDA byte_to_paint
ORA (>btp_mem_pos), Y
STA (>btp_mem_pos), Y
increment_pixel_x:
LSR byte_to_paint
BCC increment_pixel_x_end
move_8px_left:
Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00
LDA #%10000000
STA byte_to_paint
increment_pixel_x_end:
INX
CPX X_end
BEQ end
Lag_16 >D, <D, #$00, #$02, case_2
case_1:
Sub_16 >D, <D, >V, <V
decrement_y_pos:
DEY
CPY #$ff
BNE for_x
move_8px_up:
LDY #$07
Sub_16 >btp_mem_pos, <btp_mem_pos, #$40, #$01 ;-320
jmp for_x
decrement_y_pos_end:
case_2:
Add_16 >D, <D, >dy_2, <dy_2 ;D = D + 2*dy
JMP for_x
end:
RTS
.endproc