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

117 lines
3.5 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 +1
STA dy_2 +1
STA $FD ; for pixel_draw
;; V = 2*(dx -dy)
SEC
LDA dx
SBC dy
Mult_16 A, V +1
STA V
;dy_2 = dy*2
Mult_16 dy_2, dy_2 +1 ;dy_2 = dy (same address)
;; D = dy_2 - x. (signed 16-bit)
SEC
LDA dy_2
SBC dx
STA D
LDA dy_2 + 1
SBC #$00
STA D + 1
;; because C flag is wrong value we let dy_2 be 1 to small
Sub_16 dy_2, dy_2 +1, #$01,#$00
selfmod:
;; Self modifying code. Makes LDA and SBC instructions each take 1 cycle less.
;; You can remove this if you run the loop without # at dy_2 and V.
;;Note: The offsets like +2 etc is because there are instructions betwean the label and the
;; address that needs to be modified.
;; dy_2
;; Modifies LDA >dy_2
LDA dy_2
STA case_2 + 1
;; Modifies LDA <dy_2
LDA dy_2 + 1
STA case_2 + 7
;; V
;;Modidies SBC >V
LDA V
STA case_1 + 3
;; Modifies SBC <V
LDA V + 1
STA case_1 + 9
end_selfmod:
LDA X_end
STA X_pos
LDA Y_end
STA Y_pos
JSR pixel_calc ;;only used first pixel. after this relative position is abused
STA byte_to_paint
;; X = X_end - X_pos
LDX dx
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00,! ;; Y has always a offset of at least 1 = C + $0000
INY
for_x:
;; Paints A to address in |btp_mem_pos* + Y|
;; Y is pixel position in the chunk. Therefor it may be that Y = 0, 1, 2, 3, 4, ,5 ,6 ,7.
LDA byte_to_paint ;A byte containing a single 1. Coresponds to X position in the chunk.
ORA (btp_mem_pos), Y
STA (btp_mem_pos), Y
decrement_pixel_x:
ASL byte_to_paint ; Rotates the pixel one bit to the left ON THE SCREEN.
BCC decrement_pixel_x_end; We need to move to the next chunk
move_8px_right:
;; Restores byte to paint to #%00000001
ROL byte_to_paint
;; Next chunk is 8 addresses away. Look in pixel_draw for more detail.
;; -8.
;; C = 0
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$07, #$00, !
decrement_pixel_x_end:
DEX
BEQ end ;We keep track on when to stop line draw with the X registry.
;;If D < 0 goto case_2
LDA D + 1
BMI case_2
case_1:
;; D = D - V
;; Because Sub_16 C = 1 so we can use !
Sub_16 D, D + 1, #V, #V + 1, !
decrement_y_pos:
DEY ; Increment Y pos inside the buffer
BNE for_x
move_8px_up:
LDY #$08
;; Switch to chunk bellow
; C = 1 or 0
; So we subtract #$40, #$01
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01;
JMP for_x
decrement_y_pos_end:
case_2:
; dy_2 is one off but C= 1 witch is off as well
Add_16 D, D + 1, #dy_2, #dy_2 + 1, ! ;D = D + 2*dy
JMP for_x
end:
RTS
.endproc