Add better code coments
This commit is contained in:
parent
842033a014
commit
7a5585d2c4
4 changed files with 54 additions and 91 deletions
|
@ -17,16 +17,12 @@
|
|||
STA $FD ; for pixel_draw
|
||||
|
||||
;; V = 2*(dx -dy)
|
||||
;; where: dy = Y_end - Y_start, dx = OO - X_start
|
||||
LDA Y_end
|
||||
SEC
|
||||
LDA Y_end
|
||||
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
|
||||
LDA dx
|
||||
SEC
|
||||
SBC >V
|
||||
STA >V; <V = dx - dy
|
||||
|
@ -34,15 +30,18 @@
|
|||
|
||||
;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!
|
||||
|
||||
;; This is an Bresenham's line algorithm, se wikipedia bellow.
|
||||
;;https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||
;; We need to compute the Value D = 2*dy - dx,
|
||||
;; but it may be or get negative.
|
||||
;; IN the loop we may set D = D -V
|
||||
;; Because math D needs to be at least >=V.
|
||||
;; V_max = %00000001 11111111
|
||||
;; We therefor need to add this offset to V 00000001 11111111
|
||||
;; and to its branch logic later in the loop.
|
||||
|
||||
;;D = 2*dy - dx + 2*255
|
||||
;;Our D is bigger then wikipedia because D is unsigned.
|
||||
LDA >dy_2
|
||||
STA >D
|
||||
LDA <dy_2
|
||||
|
@ -53,35 +52,36 @@
|
|||
jsr pixel_draw ;;only used first pixel. after this relative position is abused
|
||||
LDX X_pos
|
||||
for_x:
|
||||
;; Paints A to address i btp_mem_pos* + Y
|
||||
;; Y is our Y-pos-chunk-offset.
|
||||
LDA byte_to_paint
|
||||
;; 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
|
||||
increment_pixel_x:
|
||||
LSR byte_to_paint
|
||||
BCC increment_pixel_x_end
|
||||
LSR byte_to_paint ; Rotates the pixel one bit to the left ON THE SCREEN.
|
||||
BCC increment_pixel_x_end; We need to move to the next chunk
|
||||
move_8px_left:
|
||||
;; add +8 to btp_mem_pos. Find more of why in pixel_draw
|
||||
;; Next chunk is 8 addresses away. Look in pixel_draw for more detail.
|
||||
Add_16 >btp_mem_pos, <btp_mem_pos, #$08, #$00
|
||||
;; reset byte_to_paint
|
||||
;; Restores byte to paint
|
||||
LDA #%10000000
|
||||
STA byte_to_paint
|
||||
increment_pixel_x_end:
|
||||
INX
|
||||
CPX X_end
|
||||
BEQ end
|
||||
BEQ end ;We keep track on when to stop line draw with the X registry.
|
||||
;;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:
|
||||
INY
|
||||
CPY #$08 ;
|
||||
INY ; Increment Y pos inside the buffer
|
||||
CPY #$08
|
||||
BNE for_x
|
||||
move_8px_down: ; Z=1 --> C=1
|
||||
LDY #$00
|
||||
;; Switch to chunk bellow
|
||||
Add_16 >btp_mem_pos, <btp_mem_pos, #$40, #$01; +320
|
||||
JMP for_x
|
||||
increment_y_pos_end:
|
||||
|
|
|
@ -8,35 +8,28 @@
|
|||
;;# (X_end, Y_end) #
|
||||
;;NOTE THAT X_pos <= X_end, Y_pos <= Y_end. Min 45deg!
|
||||
.proc line_down_inv
|
||||
.include "line.inc"; Defines memory positions, ex X_pos
|
||||
|
||||
;;We need to clear this memory
|
||||
;; Look at line_down for referense
|
||||
.include "line.inc"
|
||||
LDA #$00
|
||||
STA <V
|
||||
STA <dx_2
|
||||
STA $FD ; for pixel_draw
|
||||
STA $FD
|
||||
|
||||
;; V = 2*(dy -dx)
|
||||
;; where: dy = Y_end - Y_start, dx = X_end - X_start
|
||||
LDA X_end
|
||||
SEC
|
||||
SBC X_pos
|
||||
LDA dx
|
||||
STA >V
|
||||
STA >dx_2; >dx_2 = dx. Needed for dx_2 (not for V)
|
||||
STA >dx_2
|
||||
LDA Y_end
|
||||
SEC
|
||||
SBC Y_pos
|
||||
STA dy
|
||||
|
||||
SEC
|
||||
SBC >V
|
||||
STA >V; <V = dy - dx
|
||||
mult_16 >V, <V; V = 2*(dy -dx)
|
||||
STA >V
|
||||
mult_16 >V, <V
|
||||
|
||||
;dx_2 = dx*2
|
||||
mult_16 >dx_2, <dx_2
|
||||
|
||||
;;D = 2*dy - dx + 2*255
|
||||
;;Our D is bigger then wikipedia because D is unsigned.
|
||||
LDA >dx_2
|
||||
STA >D
|
||||
LDA <dx_2
|
||||
|
@ -44,7 +37,7 @@
|
|||
Add_16 >D, <D, #$ff, #$01
|
||||
Sub_16 >D, <D, dy, #$00
|
||||
|
||||
jsr pixel_draw ;;only used first pixel. after this relative position is abused
|
||||
jsr pixel_draw
|
||||
LDX Y_pos
|
||||
for_y:
|
||||
LDA byte_to_paint
|
||||
|
@ -56,28 +49,24 @@ increment_y_pos:
|
|||
BNE increment_y_pos_end
|
||||
move_8px_down:
|
||||
LDY #$00
|
||||
Add_16 >btp_mem_pos, <btp_mem_pos,#$40 , #$01; ; +320 bytes
|
||||
Add_16 >btp_mem_pos, <btp_mem_pos,#$40 , #$01;
|
||||
increment_y_pos_end:
|
||||
INX
|
||||
CPX Y_end
|
||||
BEQ end
|
||||
;;If D < %00000010 00000000: case_2
|
||||
;;else case 1.
|
||||
Lag_16 >D, <D, #$00, #$02, case_2
|
||||
case_1:; C = 1 because LAG
|
||||
Sub_16 >D, <D, >V, <V, !; D = D - V
|
||||
case_1:
|
||||
Sub_16 >D, <D, >V, <V, !
|
||||
increment_pixel_x:
|
||||
LDA byte_to_paint
|
||||
LSR byte_to_paint
|
||||
BCC for_y
|
||||
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
|
||||
JMP for_y
|
||||
case_2: ;; C =0 because LAG_16 so we can use !
|
||||
case_2:
|
||||
Add_16 >D, <D, >dx_2, <dx_2, ! ;D = D + 2*dx
|
||||
JMP for_y
|
||||
end:
|
||||
|
|
|
@ -10,41 +10,26 @@
|
|||
;;NOTE THAT X_pos <= X_end, Y_pos >= Y_end. Max 45deg!
|
||||
|
||||
.proc line_up
|
||||
.include "line.inc"; Defines memory positions, ex X_pos
|
||||
|
||||
;;We need to clear this memory
|
||||
;; Look at line_down for referense
|
||||
.include "line.inc"
|
||||
LDA #$00
|
||||
STA <V
|
||||
STA <dy_2
|
||||
STA $FD ; for pixel_draw
|
||||
STA $FD
|
||||
|
||||
;; 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
|
||||
STA >dy_2
|
||||
LDA dx
|
||||
SEC
|
||||
SBC >V
|
||||
STA >V; <V = dx - dy
|
||||
mult_16 >V, <V; V = 2*(dx -dy)
|
||||
STA >V
|
||||
mult_16 >V, <V
|
||||
|
||||
;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
|
||||
|
@ -78,11 +63,11 @@ decrement_y_pos:
|
|||
BNE for_x
|
||||
move_8px_up:
|
||||
LDY #$07
|
||||
Sub_16 >btp_mem_pos, <btp_mem_pos, #$40, #$01 ;-320
|
||||
Sub_16 >btp_mem_pos, <btp_mem_pos, #$40, #$01
|
||||
jmp for_x
|
||||
decrement_y_pos_end:
|
||||
case_2:
|
||||
Add_16 >D, <D, >dy_2, <dy_2 ;D = D + 2*dy
|
||||
Add_16 >D, <D, >dy_2, <dy_2
|
||||
JMP for_x
|
||||
end:
|
||||
RTS
|
||||
|
|
|
@ -9,35 +9,28 @@
|
|||
;;NOTE THAT Y_pos >) Y_end, X_pos <= X_end. Min 45deg!
|
||||
|
||||
.proc line_up_inv
|
||||
;; Look at line_down for referense
|
||||
.include "line.inc"
|
||||
|
||||
;We need to clear this memory
|
||||
LDA #$00
|
||||
STA <V
|
||||
STA <dx_2
|
||||
STA $FD ; for pixel_draw
|
||||
STA $FD
|
||||
|
||||
;; V = 2*(dy -dx)
|
||||
;; where: dy = Y_pos - Y_end, dx = X_end - X_start
|
||||
LDA X_end
|
||||
SEC
|
||||
SBC X_pos
|
||||
LDA dx
|
||||
STA >V
|
||||
STA >dx_2; >dy_2 = dy. Needed for dy_2 (not for V)
|
||||
STA >dx_2
|
||||
LDA Y_pos
|
||||
SEC
|
||||
SBC Y_end
|
||||
STA dy
|
||||
SEC
|
||||
SBC >V
|
||||
STA >V; <V = dx - dy
|
||||
mult_16 >V, <V; V = 2*(dx -dy)
|
||||
STA >V
|
||||
mult_16 >V, <V
|
||||
|
||||
;dy_2 = dy*2
|
||||
mult_16 >dx_2, <dx_2
|
||||
|
||||
;;D = 2*dx - dy + 2*255
|
||||
;;Our D is bigger then wikipedia because D is unsigned.
|
||||
LDA >dx_2
|
||||
STA >D
|
||||
LDA <dx_2
|
||||
|
@ -57,29 +50,25 @@ decrement_y_pos:
|
|||
BNE decrement_y_pos_end
|
||||
move_8px_up:
|
||||
LDY #$07
|
||||
Sub_16>btp_mem_pos, <btp_mem_pos,#$40 , #$01; ; +320 bytes
|
||||
Sub_16>btp_mem_pos, <btp_mem_pos,#$40 , #$01
|
||||
decrement_y_pos_end:
|
||||
DEX
|
||||
CPX Y_end
|
||||
BEQ end
|
||||
;;If D < %00000010 00000000: case_2
|
||||
;;else case 1.
|
||||
Lag_16 >D, <D, #$00, #$02, case_2
|
||||
case_1:
|
||||
Sub_16 >D, <D, >V, <V, !; D = D - V
|
||||
Sub_16 >D, <D, >V, <V, !
|
||||
increment_pixel_x:
|
||||
LDA byte_to_paint
|
||||
LSR byte_to_paint
|
||||
BCC for_y
|
||||
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
|
||||
JMP for_y
|
||||
case_2:
|
||||
Add_16 >D, <D, >dx_2, <dx_2;D = D + 2*dy
|
||||
Add_16 >D, <D, >dx_2, <dx_2
|
||||
JMP for_y
|
||||
end:
|
||||
RTS
|
||||
|
|
Loading…
Add table
Reference in a new issue