rewrite circle code, such that it works on all X and Y (and not only if rest(X /8)=0 and rest(Y/0)=0. This makes the code alot bigger because the same symetries cant be abused.

This commit is contained in:
hugova 2025-07-10 00:24:20 +02:00
parent 06d6b434de
commit fbb7c395e4
6 changed files with 187 additions and 167 deletions

View file

@ -8,15 +8,16 @@
X_rel = radius X_rel = radius
Y_rel = $E2 Y_rel = $E2
Y_copy = $E3 Y_copy = $E3
temp_ = $E4 temp_ = $ED
temp__ = $E5 jmp_location_pointer_two = $E4 ;16bit value (uses E5)
temp___ = $ED
jmp_location_pointer = $EE ;16 bit value (uses EF) jmp_location_pointer = $EE ;16 bit value (uses EF)
byte_to_paint_qaa = byte_to_paint byte_to_paint_qaa = byte_to_paint
byte_to_paint_qcb = $EB ;16bit value (uses EC) byte_to_paint_qcb = $EB
byte_to_paint_qca = $EC
; E8 - EA is used by pixel.inc ; E8 - EA is used by pixel.inc
btp_mem_pos_center = $E6 ; 16bit value (uses E7) byte_to_paint_qdb = $CF
btp_mem_pos_center = $E6
btp_mem_pos_center_two = btp_mem_pos_center btp_mem_pos_center_two = btp_mem_pos_center
btp_mem_pos_qaa = btp_mem_pos btp_mem_pos_qaa = btp_mem_pos
@ -29,3 +30,8 @@
btp_mem_pos_qca = $D8 btp_mem_pos_qca = $D8
btp_mem_pos_qba = $DA btp_mem_pos_qba = $DA
btp_mem_pos_qbb = $DC btp_mem_pos_qbb = $DC
Y_qda = $DE
Y_qdb = $DF
Y_qbb = $CE
Y_qaa = Y_copy

View file

@ -1,5 +1,19 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;We have named the parts of the circle as such.
;; |
;; qbb (7) | qab (8)
;; |
;; qba (2) | qaa (1)
;;---------------X-----------------> X
;; qca (4) | qda (3)
;; |
;; qcb (5) | qdb (6)
;; |
;; v Y
;; The q stands for quarter, whe have 4 quarter, and each quarter is split into 2
.proc circle .proc circle
.include "circle.inc" .include "circle.inc"
@ -8,6 +22,11 @@
STA jmp_location_pointer STA jmp_location_pointer
LDA #>while_x_bigger_then_y LDA #>while_x_bigger_then_y
STA jmp_location_pointer + 1 STA jmp_location_pointer + 1
LDA #<endif
STA jmp_location_pointer_two
LDA #>endif
STA jmp_location_pointer_two + 1
;; X_rel = radius (share the same address) ;; X_rel = radius (share the same address)
;;Y_rel =0 ;;Y_rel =0
@ -22,19 +41,47 @@
LSR LSR
STA t1 STA t1
draw_upper_px_in_circle:
SEC
LDA Y_pos
STA temp_
SBC radius
STA Y_pos
draw_center_px_in_circle:
JSR pixel_draw JSR pixel_draw
LDA btp_mem_pos LDA btp_mem_pos
STA btp_mem_pos_center STA btp_mem_pos_qbb
STA btp_mem_pos_qab
LDA btp_mem_pos + 1 LDA btp_mem_pos + 1
STA btp_mem_pos_center + 1 STA btp_mem_pos_qbb + 1
STA btp_mem_pos_qab + 1
LDA byte_to_paint
STA byte_to_paint_qca
;; btp_mem_pos_center_two = 2*btp_mem_pos_center | used later for calculating btp_mem_pos_inv STY Y_qbb
Mult_16 btp_mem_pos_center, btp_mem_pos_center + 1
Sub_16 btp_mem_pos_center, btp_mem_pos_center +1, #$08, #$00
Sub_16 btp_mem_pos_center, btp_mem_pos_center +1, #$40, #$01
LDA temp_
STA Y_pos
draw_left_px_in_circle:
SEC
LDA X_pos
STA temp_
SBC radius
STA X_pos
JSR pixel_draw
LDA btp_mem_pos
STA btp_mem_pos_qca
STA btp_mem_pos_qba
LDA btp_mem_pos + 1
STA btp_mem_pos_qca + 1
STA btp_mem_pos_qba + 1
LDA byte_to_paint
STA byte_to_paint_qca
LDA temp_
STA X_pos
draw_lower_px_in_circle: draw_lower_px_in_circle:
CLC CLC
LDA Y_pos LDA Y_pos
@ -45,13 +92,18 @@ draw_lower_px_in_circle:
JSR pixel_draw JSR pixel_draw
LDA btp_mem_pos LDA btp_mem_pos
STA btp_mem_pos_qcb
STA btp_mem_pos_qdb STA btp_mem_pos_qdb
STA btp_mem_pos_qcb
LDA btp_mem_pos + 1 LDA btp_mem_pos + 1
STA btp_mem_pos_qdb + 1 STA btp_mem_pos_qdb + 1
STA btp_mem_pos_qcb + 1 STA btp_mem_pos_qcb + 1
Sub_16 btp_mem_pos_qdb, btp_mem_pos_qdb +1, #$08, #$00 LDA byte_to_paint
STA byte_to_paint_qdb
STA byte_to_paint_qcb
STY Y_qdb
STY Y_qaa
LDA temp_ LDA temp_
STA Y_pos STA Y_pos
@ -69,159 +121,96 @@ draw_right_px_in_circle:
STA btp_mem_pos_qda STA btp_mem_pos_qda
LDA btp_mem_pos + 1 LDA btp_mem_pos + 1
STA btp_mem_pos_qda + 1 STA btp_mem_pos_qda + 1
Sub_16 btp_mem_pos_qda, btp_mem_pos_qda +1, #$40, #$01
STY Y_qda
STY Y_qaa
while_x_bigger_then_y: while_x_bigger_then_y:
SEC
;;Draw pixels and does the ypos incrementation logic
;; WARNING expects C=1 before and C =0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;; WARNING expects C=1 before and C =0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;;We have named the parts of the circle as such.
;; |
;; qbb (7) | qab (8)
;; |
;; qba (2) | qaa (1)
;;---------------X-----------------> X
;; qca (4) | qda (3)
;; |
;; qcb (5) | qdb (6)
;; |
;; v Y
;; The q stands for quarter, whe have 4 quarter, and each quarter is split into 2
;; We first calculate all btp_mem_pos for the inverted half quarters!
calculate:
;; qab = 2*center - qcb
;; qca = 2*center - qaa
;; qba = 2*center - qda
;; qbb = 2*center - qdb
;; a = 2*center - b comes from that a = center -(b-center)
LDA btp_mem_pos_center_two
SBC btp_mem_pos_qcb
STA btp_mem_pos_qab
LDA btp_mem_pos_center_two + 1
SBC btp_mem_pos_qcb + 1
STA btp_mem_pos_qab + 1
LDA btp_mem_pos_center_two
SBC btp_mem_pos
STA btp_mem_pos_qca
LDA btp_mem_pos_center_two + 1
SBC btp_mem_pos + 1
STA btp_mem_pos_qca + 1
LDA btp_mem_pos_center_two
SBC btp_mem_pos_qda
STA btp_mem_pos_qba
LDA btp_mem_pos_center_two + 1
SBC btp_mem_pos_qda + 1
STA btp_mem_pos_qba + 1
LDA btp_mem_pos_center_two
SBC btp_mem_pos_qdb
STA btp_mem_pos_qbb
LDA btp_mem_pos_center_two + 1
SBC btp_mem_pos_qdb + 1
STA btp_mem_pos_qbb + 1
end_calculation:
;; Lets draw all half-quatrons of the circle. This draws only 8 pixels per iteration.
;; Note that I have the draw_qxx in listed pairs. Each pair chair the same Y-register :)
STY Y_copy
draw_qaa: draw_qaa:
LDY Y_qaa
LDA byte_to_paint ;A byte containing a single 1. Coresponds to X position in the chunk. LDA byte_to_paint ;A byte containing a single 1. Coresponds to X position in the chunk.
ORA (btp_mem_pos), Y ORA (btp_mem_pos), Y
STA (btp_mem_pos), Y STA (btp_mem_pos), Y
draw_qba: ;;mirror_technique draw_qba:
LDX byte_to_paint LDA byte_to_paint_qca
LDA inverse_factor_value, X;; (see END.s)
TAX
ORA (btp_mem_pos_qba), Y ORA (btp_mem_pos_qba), Y
STA (btp_mem_pos_qba), Y STA (btp_mem_pos_qba), Y
draw_qda:; y is inverted draw_qda:
LDY Y_qda
;; invert Y, this is shared with qca
LDA #$07
SBC Y_copy
TAY
LDA byte_to_paint LDA byte_to_paint
ORA (btp_mem_pos_qda), Y ORA (btp_mem_pos_qda), Y
STA (btp_mem_pos_qda), Y STA (btp_mem_pos_qda), Y
draw_qca:
draw_qca: ;;mirror technique LDA byte_to_paint_qca
TXA
ORA (btp_mem_pos_qca), Y ORA (btp_mem_pos_qca), Y
STA (btp_mem_pos_qca), Y STA (btp_mem_pos_qca), Y
draw_qcb:
draw_qcb:; xy swoped LDY Y_qdb
LDA log, X LDA byte_to_paint_qcb
TAY
;;modify X_pos
LDX Y_copy
LDA binary_factor, X; (see END.s)
TAX
ORA (btp_mem_pos_qcb), Y ORA (btp_mem_pos_qcb), Y
STA (btp_mem_pos_qcb), Y STA (btp_mem_pos_qcb), Y
draw_qdb:
draw_qdb:; xy swaped and y is inverted. LDA byte_to_paint_qdb
LDA inverse_factor_value, X
STA temp__
;;Uses modifyed Y from above
ORA (btp_mem_pos_qdb), Y ORA (btp_mem_pos_qdb), Y
STA (btp_mem_pos_qdb), Y STA (btp_mem_pos_qdb), Y
draw_qbb: draw_qbb:
LDY Y_qbb
STY temp_ LDA byte_to_paint_qcb
LDA #$07
SBC temp_
TAY
TXA
ORA (btp_mem_pos_qbb), Y ORA (btp_mem_pos_qbb), Y
STA (btp_mem_pos_qbb), Y STA (btp_mem_pos_qbb), Y
draw_qab:
draw_qab:; xy swoped + mirroring LDA byte_to_paint_qdb
LDA temp__
ORA (btp_mem_pos_qab), Y ORA (btp_mem_pos_qab), Y
STA (btp_mem_pos_qab), Y STA (btp_mem_pos_qab), Y
;;Recover the Y value (we changed it because evrything is inverted)
LDY Y_copy
increment_y_pos: change_Y:
INC Y_rel ; y++ INC Y_rel ; y++
DEY qaa_y:
BPL increment_y_pos_end DEC Y_qaa
move_8px_down: BPL qaa_y_end
LDY #$07 qaa_y_underflow:
LDA #$07
STA Y_qaa
;; Switch to chunk bellow ;; Switch to chunk bellow
; So we subtract #$0140 ; So we subtract #$0140
; C = 1 because branching! Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01 ;-320
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$40, #$01, ! ;-320 Sub_16 btp_mem_pos_qba, btp_mem_pos_qba + 1, #$40, #$01,!
;; Y is inverted qaa_y_end:
Add_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$3f, #$01,! ;+320 qda_y:
;; X and Y has swopped INC Y_qda
Sub_16 btp_mem_pos_qcb, btp_mem_pos_qcb + 1, #$07, #$00,! ;-8 LDA Y_qda
;; X and Y has swoped and Y has inverted CMP #$08
Add_16 btp_mem_pos_qdb, btp_mem_pos_qdb +1, #$07, #$00,! ;+8 BCC qda_y_end
increment_y_pos_end: qda_y_overflow:
Add_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$3f, #$01,! ;+319 + C
Add_16 btp_mem_pos_qca, btp_mem_pos_qca + 1, #$40, #$01,! ;+320
LDA #$00
STA Y_qda
qda_y_end:
qdb_x:
LSR byte_to_paint_qdb
BCC qdb_x_end
qdb_x_overflow:
ROR byte_to_paint_qdb
Add_16 btp_mem_pos_qdb, btp_mem_pos_qdb + 1, #$08, #$00, !
Add_16 btp_mem_pos_qab, btp_mem_pos_qab + 1, #$08, #$00, !
qdb_x_end:
qcb_x:
ASL byte_to_paint_qcb
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:
;;t1 += y ;;t1 += y
; C==0 from circle_help CLC
LDA t1 LDA t1
ADC Y_rel ADC Y_rel
STA t1 STA t1
@ -231,36 +220,61 @@ increment_y_pos_end:
STA t2 STA t2
;; if t2 < 0 then skip to endif ;; if t2 < 0 then skip to endif
;; we can skipp CMP #$00 because SBC above do the same ;; we can skipp CMP #$00 because SBC above do the same
BMI endif BPL if
JMP (jmp_location_pointer_two)
if: if:
decrement_x_pos: change_x:
DEC X_rel DEC X_rel
LDA t2
STA t1 ; t1 = t2
qaa_x:
ASL byte_to_paint ASL byte_to_paint
BCC decrement_x_pos_end BCC qaa_x_end
move_8px_left: qaa_x_overflow:
;; Next chunk is 8 addresses away. Look in pixel_draw for more detail.
;; -8.
;; C = 1 because branching
Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00, ! ;+8 Sub_16 btp_mem_pos, btp_mem_pos + 1, #$08, #$00, ! ;+8
;; Y is inverted
Sub_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$08, #$00, ! ;+8 Sub_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$08, #$00, ! ;+8
;; X and Y has swoped
Sub_16 btp_mem_pos_qcb, btp_mem_pos_qcb + 1, #$40, #$01, ! ;-320
;; X and Y has swoped and Y has inverted
Sub_16 btp_mem_pos_qdb, btp_mem_pos_qdb +1, #$40, #$01, ! ;+320
;; Restores byte to paint ;; Restores byte to paint
INC byte_to_paint INC byte_to_paint
qaa_x_end:
qca_x:
LSR byte_to_paint_qca
BCC qca_x_end
qca_x_overflow:
ROR byte_to_paint_qca
Add_16 btp_mem_pos_qca, btp_mem_pos_qca + 1, #$08, #$00, !
Add_16 btp_mem_pos_qba, btp_mem_pos_qba + 1, #$08, #$00, !
qca_x_end:
qdb_y:
DEC Y_qdb
BPL qdb_y_end
qdb_overflow:
Sub_16 btp_mem_pos_qdb, btp_mem_pos_qdb + 1, #$3f, #$01, ! ;+320
Sub_16 btp_mem_pos_qcb, btp_mem_pos_qcb + 1, #$40, #$01, ! ;+320
LDA #$07
STA Y_qdb
qdb_y_end:
qbb_y:
INC Y_qbb
LDA Y_qbb
CMP #$08
BCC qbb_y_end
qbb_y_overflow:
Add_16 btp_mem_pos_qbb, btp_mem_pos_qbb + 1, #$3f, #$01, ! ;+320
Add_16 btp_mem_pos_qab, btp_mem_pos_qab + 1, #$40, #$01, !;+320
LDA #$00
STA Y_qbb
qbb_y_end:
LDA t2
decrement_x_pos_end:
STA t1 ; t1 = t2
endif: endif:
;; repeat if X > Y ;; repeat if X > Y
LDA X_rel LDA X_rel
CMP Y_rel CMP Y_rel
BCC end BCC end
JMP (jmp_location_pointer) JMP (jmp_location_pointer)
end: end:

View file

@ -1,6 +1,6 @@
.scope circle_test .scope circle_test
.include "circle.inc" .include "circle.inc"
LDA #$50 LDA #$58
STA X_pos STA X_pos
STA Y_pos STA Y_pos
LDA #$40 LDA #$40

View file

@ -2,11 +2,11 @@
.include "circle.inc" .include "circle.inc"
LDA #$50 LDA #$50
STA $ED STA $AD
LDA #$50 LDA #$50
STA $EE STA $AE
LDA #$08 LDA #$40
STA $EF STA $AF
@ -20,13 +20,13 @@
DEY DEY
BNE hihi BNE hihi
INC $ED INC $AD
LDA $ED LDA $AD
STA X_pos STA X_pos
LDA $EE LDA $AE
STA Y_pos STA Y_pos
LDA $EF LDA $AF
STA radius STA radius
VIC_bank = $4000 VIC_bank = $4000

View file

@ -5,7 +5,7 @@
STA X_pos STA X_pos
STA Y_pos STA Y_pos
LDA #$01 LDA #$01
STA $EF STA $AD
@ -23,8 +23,8 @@
STA X_pos STA X_pos
STA Y_pos STA Y_pos
INC $EF INC $AD
LDA $EF LDA $AD
STA radius STA radius

View file

@ -10,9 +10,9 @@
;.include "routines/arithmatic/mult_test.s" ;.include "routines/arithmatic/mult_test.s"
;.include "routines/arithmatic/div_test.s" ;.include "routines/arithmatic/div_test.s"
.include "routines/circle/circle_test.s" ;.include "routines/circle/circle_test.s"
;.include "routines/circle/circle_test_size.s" ;.include "routines/circle/circle_test_size.s"
;.include "routines/circle/circle_test_position.s" .include "routines/circle/circle_test_position.s"
;.include "routines/line/line_test.s" ;.include "routines/line/line_test.s"
;.include "routines/text/char_draw_test.s" ;.include "routines/text/char_draw_test.s"
;.include "routines/pixel/pixel_test.s" ;.include "routines/pixel/pixel_test.s"