simplify branch logic for circle draw

This commit is contained in:
hugova 2025-07-10 17:03:33 +02:00
parent a1089ccd1c
commit 385ae9c9e6
3 changed files with 31 additions and 43 deletions

View file

@ -8,27 +8,25 @@
t2 = $E1
X_math = radius
Y_math = $E2
jmp_location_pointer_two = $E3 ;16-bit value (uses E4)
jmp_location_pointer = $E5 ;16-bit value (uses E6)
;; E8 - EA is used by pixel.inc
byte_to_paint_qaa = byte_to_paint
byte_to_paint_qcb = $EB
byte_to_paint_qca = $EC
byte_to_paint_qdb = $ED
byte_to_paint_qcb = $E3
byte_to_paint_qca = $E4
byte_to_paint_qdb = $E5
btp_mem_pos_qaa = btp_mem_pos
btp_mem_pos_qcb = $D0 ; 16bit value (uses D1)
btp_mem_pos_qdb = $D2 ; 16bit value (uses D3)
btp_mem_pos_qda = $D4 ; 16bit value (uses D5)
btp_mem_pos_qab = $D6 ; 16bit value (uses D7)
btp_mem_pos_qca = $D8 ; 16bit value (uses D9)
btp_mem_pos_qba = $DA ; 16bit value (uses DB)
btp_mem_pos_qbb = $DC ; 16bit value (uses DD)
btp_mem_pos_qcb = $E6 ; 16bit value (uses E7)
btp_mem_pos_qdb = $EB ; 16bit value (uses EC)
btp_mem_pos_qda = $ED ; 16bit value (uses EE)
btp_mem_pos_qab = $D0 ; 16bit value (uses D1)
btp_mem_pos_qca = $D2 ; 16bit value (uses D3)
btp_mem_pos_qba = $D4 ; 16bit value (uses D5)
btp_mem_pos_qbb = $D6 ; 16bit value (uses D7)
Y_qda = $DE
Y_qdb = $DF
Y_qbb = $E7 ;; <-- we use E7 here!
Y_qaa = $C0
Y_qda = $EF
Y_qdb = $D8
Y_qbb = $D9
Y_qaa = $DA
;;Reuse addresses, be carful here!
temp__ = Y_qaa
temp_ = Y_qda

View file

@ -24,16 +24,6 @@
.proc circle; user-procedure :clobbers (A X Y) :clobbers-arguments 3
.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
STA jmp_location_pointer + 1
LDA #<endif
STA jmp_location_pointer_two
LDA #>endif
STA jmp_location_pointer_two + 1
;; X_math = radius (share the same address)
;;Y_math =0
@ -140,7 +130,7 @@ while_x_bigger_then_y: ; C=1 here because above and branching logic
draw_pixels:
draw_qaa:
LDY Y_qaa
LDA byte_to_paint ;A byte containing a single 1. Coresponds to 2^rest(X_pos/8)
LDA byte_to_paint_qaa ;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:
@ -149,7 +139,7 @@ draw_qba:
STA (btp_mem_pos_qba), Y
draw_qda:
LDY Y_qda
LDA byte_to_paint
LDA byte_to_paint_qaa
ORA (btp_mem_pos_qda), Y
STA (btp_mem_pos_qda), Y
draw_qca:
@ -188,10 +178,10 @@ qaa_y:
BPL qaa_y_end
qaa_y_underflow:
;; Switch to chunk bellow
; So we subtract #$0140
;; So we subtract #$0140
;; Note that C =1, read from while_x_bigger_then_y label.
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,!
Sub_16 btp_mem_pos_qaa, btp_mem_pos_qaa + 1, #$40, #$01, ! ;-320
Sub_16 btp_mem_pos_qba, btp_mem_pos_qba + 1, #$40, #$01, ! ;-320
STY Y_qaa ; Y_qaa =$07
qaa_y_end:
qda_y:
@ -218,8 +208,8 @@ qcb_x:
BCC qcb_x_end
qcb_x_overflow:
INC 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,!
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, !
CLC
qcb_x_end:
@ -235,7 +225,7 @@ qcb_x_end:
;; if t2 < 0 then skip to endif
;; we can skipp CMP #$00 because SBC above do the same
BPL if
JMP (jmp_location_pointer_two) ; jump to endif
JMP endif
if:
change_x:
DEC X_math
@ -244,8 +234,8 @@ qaa_x:
ASL byte_to_paint
BCC qaa_x_end
qaa_x_overflow:
Sub_16 btp_mem_pos_qaa, btp_mem_pos_qaa + 1, #$08, #$00, ! ;+8
Sub_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$08, #$00, ! ;+8
Sub_16 btp_mem_pos_qaa, btp_mem_pos_qaa + 1, #$08, #$00, ! ;-8
Sub_16 btp_mem_pos_qda, btp_mem_pos_qda + 1, #$08, #$00, ! ;-8
;; Restores byte to paint
INC byte_to_paint
qaa_x_end:
@ -255,16 +245,16 @@ qca_x:
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, !
Add_16 btp_mem_pos_qca, btp_mem_pos_qca + 1, #$08, #$00, ! ;+8
Add_16 btp_mem_pos_qba, btp_mem_pos_qba + 1, #$08, #$00, ! ;+8
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
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
STY Y_qdb
qdb_y_end:
@ -285,7 +275,7 @@ endif:
LDA X_math
CMP Y_math
BCC end
JMP (jmp_location_pointer)
jmp while_x_bigger_then_y
end:
RTS
.endproc

View file

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