draw 1/2 of circle by circle-help-subroutine
This commit is contained in:
parent
219f8c155d
commit
c4add9a62c
3 changed files with 111 additions and 41 deletions
|
@ -9,5 +9,9 @@
|
|||
Y_rel = $E3
|
||||
temp = $E4
|
||||
temp_ = $E7
|
||||
btp_mem_pos_center = $E5 ;; 16bit <fix>
|
||||
btp_mem_pos_inv = $EE ;; 16bit <fix>
|
||||
; E8 - EA is used by pixel.inc
|
||||
btp_mem_pos_center = $E5 ; 16bit value (uses E6)
|
||||
btp_mem_pos_center_two = btp_mem_pos_center
|
||||
btp_mem_pos_inv_y =$EB ; 16bit value (uses EC)
|
||||
Y_inv_x = $EC
|
||||
btp_mem_pos_inv = $EE ; 16bit value (uses EF)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
.proc circle
|
||||
.include "circle.inc"
|
||||
;; We use the algorithm jerkos method
|
||||
;; https://schwarzers.com/algorithms/
|
||||
;; git
|
||||
|
||||
;; X_rel = radius (share the same address)
|
||||
|
||||
|
@ -27,8 +27,9 @@ draw_center_px_in_circle:
|
|||
LDA btp_mem_pos + 1
|
||||
STA btp_mem_pos_center + 1
|
||||
;; btp_mem_pos_center_two = 2*btp_mem_pos_center | used later for calculating btp_mem_pos_inv
|
||||
btp_mem_pos_center_two = btp_mem_pos_center
|
||||
Mult_16 btp_mem_pos_center, btp_mem_pos_center + 1
|
||||
;; fix offset of 8 bytes, idk why this is needed
|
||||
Sub_16 btp_mem_pos_center, btp_mem_pos_center + 1, #$40, #$01 ;-320
|
||||
|
||||
|
||||
draw_right_px_in_circle:
|
||||
|
@ -41,44 +42,19 @@ draw_right_px_in_circle:
|
|||
JSR pixel_draw
|
||||
;; This sets byte_to_paint, btp_mem_pos and Y
|
||||
|
||||
LDA btp_mem_pos
|
||||
STA btp_mem_pos_inv_y
|
||||
LDA btp_mem_pos + 1
|
||||
STA btp_mem_pos_inv_y + 1
|
||||
|
||||
;; fix offset of 8 bytes, idk why this is needed
|
||||
Sub_16 btp_mem_pos_inv_y, btp_mem_pos_inv_y + 1, #$40, #$01 ;-320
|
||||
|
||||
|
||||
SEC ;; See draw_pixel_inv
|
||||
while_x_bigger_then_y:
|
||||
|
||||
|
||||
draw_pixel:
|
||||
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
|
||||
|
||||
draw_pixel_inv:
|
||||
;;C = 1 beacause the branching to while_x_bigger_then_y and SEC on first ittteration.
|
||||
LDA btp_mem_pos_center_two
|
||||
SBC btp_mem_pos
|
||||
STA btp_mem_pos_inv
|
||||
LDA btp_mem_pos_center_two + 1
|
||||
SBC btp_mem_pos + 1
|
||||
STA btp_mem_pos_inv + 1
|
||||
|
||||
;; calculate the inverted y value Y = 7-Y
|
||||
STY temp
|
||||
LDA #$07
|
||||
;; C = 1 because arithmatic above
|
||||
SBC temp
|
||||
TAY
|
||||
|
||||
;; calculate byte_to_paint_inv 00000001 --> 10000000, 00000010 --> 01000000 ... etc
|
||||
;; uses a table!
|
||||
STX temp_
|
||||
LDX byte_to_paint
|
||||
LDA inverse_factor_value, X;; (see END.s)
|
||||
LDX temp_
|
||||
|
||||
; A = byte_to_paint_inv
|
||||
ORA (btp_mem_pos_inv), Y
|
||||
STA (btp_mem_pos_inv), Y
|
||||
|
||||
;;Recover the Y value (we changed it because evrything is inverted)
|
||||
LDY temp
|
||||
;;Draw pixels
|
||||
JSR circle_help
|
||||
|
||||
increment_y_pos:
|
||||
INC Y_rel ; y++
|
||||
|
@ -87,9 +63,10 @@ increment_y_pos:
|
|||
move_8px_down:
|
||||
LDY #$07
|
||||
;; Switch to chunk bellow
|
||||
; So we subtract #$4001
|
||||
; So we subtract #$0140
|
||||
; C = 1 because branching!
|
||||
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01, ! ;-320
|
||||
Add_16 btp_mem_pos_inv_y, btp_mem_pos_inv_y + 1, #$40, #$01 ;+320
|
||||
increment_y_pos_end:
|
||||
|
||||
;;t1 += y
|
||||
|
@ -115,6 +92,7 @@ move_8px_left:
|
|||
;; -8.
|
||||
;; C = 1 because branching
|
||||
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00, !
|
||||
Sub_16 btp_mem_pos_inv_y, btp_mem_pos_inv_y + 1, #$08, #$00, !
|
||||
;; Restores byte to paint
|
||||
LDA #%00000001
|
||||
STA byte_to_paint
|
||||
|
@ -128,4 +106,5 @@ endif:
|
|||
|
||||
BCS while_x_bigger_then_y
|
||||
RTS
|
||||
.include "routines/circle/circle_help.s"
|
||||
.endproc
|
||||
|
|
87
wip-hugo/routines/circle/circle_help.s
Normal file
87
wip-hugo/routines/circle/circle_help.s
Normal file
|
@ -0,0 +1,87 @@
|
|||
.proc circle_help ;; This is because jmp cant jump that long!
|
||||
.include "circle.inc"
|
||||
|
||||
|
||||
;;We have named the parts of the circle as such.
|
||||
;; |
|
||||
;; q22 | q12
|
||||
;; |
|
||||
;; q21 | q11
|
||||
;;---------------X-----------------> X
|
||||
;; q31 | q41
|
||||
;; |
|
||||
;; q32 | q42
|
||||
;; |
|
||||
;; v Y
|
||||
;; The q stands for quarter, whe have 4 quarter, and each quarter is split into 2
|
||||
|
||||
|
||||
draw_pixel:;;q11
|
||||
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
|
||||
|
||||
draw_pixel_inv_y:;;q41
|
||||
STY temp
|
||||
LDA #$07
|
||||
SEC
|
||||
SBC temp
|
||||
TAY
|
||||
LDA byte_to_paint
|
||||
ORA (btp_mem_pos_inv_y), Y
|
||||
STA (btp_mem_pos_inv_y), Y
|
||||
;hihi:
|
||||
;jmp hihi
|
||||
LDY temp
|
||||
|
||||
draw_pixel_inv_y_mirror:
|
||||
SEC
|
||||
LDA btp_mem_pos_center_two
|
||||
SBC btp_mem_pos_inv_y
|
||||
STA btp_mem_pos_inv
|
||||
LDA btp_mem_pos_center_two + 1
|
||||
SBC btp_mem_pos_inv_y + 1
|
||||
STA btp_mem_pos_inv + 1
|
||||
|
||||
STX temp_
|
||||
LDX byte_to_paint
|
||||
LDA inverse_factor_value, X;; (see END.s)
|
||||
LDX temp_
|
||||
|
||||
; A = byte_to_paint_inv
|
||||
ORA (btp_mem_pos_inv), Y
|
||||
STA (btp_mem_pos_inv), Y
|
||||
|
||||
|
||||
draw_pixel_mirror:;;q31
|
||||
SEC
|
||||
;;C = 1 beacause the branching to while_x_bigger_then_y and SEC on first ittteration.
|
||||
LDA btp_mem_pos_center_two
|
||||
SBC btp_mem_pos
|
||||
STA btp_mem_pos_inv
|
||||
LDA btp_mem_pos_center_two + 1
|
||||
SBC btp_mem_pos + 1
|
||||
STA btp_mem_pos_inv + 1
|
||||
|
||||
;; calculate the inverted y value Y = 7-Y
|
||||
STY temp
|
||||
LDA #$07
|
||||
;; C = 1 because arithmatic above
|
||||
SBC temp
|
||||
TAY
|
||||
|
||||
;; calculate byte_to_paint_inv 00000001 --> 10000000, 00000010 --> 01000000 ... etc
|
||||
;; uses a table!
|
||||
STX temp_
|
||||
LDX byte_to_paint
|
||||
LDA inverse_factor_value, X;; (see END.s)
|
||||
LDX temp_
|
||||
|
||||
; A = byte_to_paint_inv
|
||||
ORA (btp_mem_pos_inv), Y
|
||||
STA (btp_mem_pos_inv), Y
|
||||
|
||||
;;Recover the Y value (we changed it because evrything is inverted)
|
||||
LDY temp
|
||||
RTS
|
||||
.endproc
|
Loading…
Add table
Reference in a new issue