add code comments and compiler flag for circle draw.

This commit is contained in:
hugova 2025-07-10 01:08:37 +02:00
parent 4916678549
commit 7cd03c02ba
2 changed files with 28 additions and 18 deletions

View file

@ -2,6 +2,7 @@
.include "../pixel/pixel.inc"
;; public args
radius = ARGVEC + 2
;; and others from pixel.inc
;; private args
t1 = $E0
t2 = $E1

View file

@ -1,5 +1,6 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;We have named the parts of the circle as such.
;; |
;; qbb (7) | qab (8)
@ -12,12 +13,18 @@
;; |
;; v Y
;; The q stands for quarter, whe have 4 quarter, and each quarter is split into 2
;; The q stands for quarter, whe have 4 quarter, and each quarter is split into 2 (a and b)
;; We use jerko's method https://schwarzers.com/algorithms/
;;
;; There exist 4 uniqe half-quarter-pairs such that they share the same byte_to_paint
; and another 4 uniqe ... such that they shair the same Y value.
;; The Y value is the mod 8 rest of the position of the byte to paint.
;; We paint one pixel in each half quarter area for each loop.
.proc circle
.include "circle.inc"
.proc circle; user-procedure :clobbers (A X Y) :clobbers-arguments 3
;; Because loop is so big, We need to save position in pointer
.include "circle.inc"
;; Because loop is so big, We need to save positions in pointer
LDA #<while_x_bigger_then_y
STA jmp_location_pointer
LDA #>while_x_bigger_then_y
@ -42,6 +49,7 @@
STA t1
draw_upper_px_in_circle:
;; move uppwards
SEC
LDA Y_pos
STA temp_
@ -49,6 +57,8 @@ draw_upper_px_in_circle:
STA Y_pos
JSR pixel_draw
;; initial pixel for 2 half-quarter arias
LDA btp_mem_pos
STA btp_mem_pos_qbb
STA btp_mem_pos_qab
@ -57,11 +67,13 @@ draw_upper_px_in_circle:
STA btp_mem_pos_qab + 1
;; initial Y value for one half-quarter aria
STY Y_qbb
;; reset changes we have made to circle Y_pos
LDA temp_
STA Y_pos
draw_left_px_in_circle:
draw_left_px_in_circle: ;similar as above
SEC
LDA X_pos
STA temp_
@ -82,7 +94,7 @@ draw_left_px_in_circle:
LDA temp_
STA X_pos
draw_lower_px_in_circle:
draw_lower_px_in_circle: ;similar as above
CLC
LDA Y_pos
STA temp_
@ -107,15 +119,12 @@ draw_lower_px_in_circle:
LDA temp_
STA Y_pos
draw_right_px_in_circle:
draw_right_px_in_circle:; similar as above
CLC
LDA X_pos
ADC radius
STA X_pos
;; We only draw the first pixel using absolute position.
;; After that we use relative position.
JSR pixel_draw
;; This sets byte_to_paint, btp_mem_pos and Y
LDA btp_mem_pos
STA btp_mem_pos_qda
@ -124,13 +133,15 @@ draw_right_px_in_circle:
STY Y_qda
STY Y_qaa
LDX #$08
while_x_bigger_then_y: ; X=8 always expected
LDX #$08 ; X=8 always expected inside the loop
while_x_bigger_then_y:
draw_pixels.
draw_qaa:
LDY Y_qaa
LDA byte_to_paint ;A byte containing a single 1. Coresponds to X position in the chunk.
ORA (btp_mem_pos), Y
LDA byte_to_paint ;A byte containing a single 1. Coresponds to 2^rest(X_pos/8)
ORA (btp_mem_pos), Y; Y = rest(Y_pos/8)
STA (btp_mem_pos), Y
draw_qba:
LDA byte_to_paint_qca
@ -165,6 +176,8 @@ draw_qab:
STA (btp_mem_pos_qab), Y
;; Y_rel and X_rel is the X and Y in the eye of the algorithm. Thsese are calculated seperatly from the pixel cordinates,
;; but are modified at the same time. This is becsuse the pixel cordinate system is complex (see pixel draw)
change_Y:
INC Y_rel ; y++
@ -203,8 +216,6 @@ qcb_x:
BCC qcb_x_end
qcb_x_overflow:
INC byte_to_paint_qcb
;LDA #$01
;STA byte_to_paint_qcb
Sub_16 btp_mem_pos_qcb, btp_mem_pos_qcb + 1, #$08, #$00,!
Sub_16 btp_mem_pos_qbb, btp_mem_pos_qbb + 1, #$08, #$00,!
qcb_x_end:
@ -231,8 +242,6 @@ qaa_x:
ASL byte_to_paint
BCC qaa_x_end
qaa_x_overflow:
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00, ! ;+8
Sub_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$08, #$00, ! ;+8
;; Restores byte to paint