c64-livecoding/wip-hugo/routines/circle/circle.s
2025-06-26 22:05:08 +02:00

60 lines
1.1 KiB
ArmAsm

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
.proc circle
.include "circle.inc"
;; We use the algorithm jerkos method
;; https://schwarzers.com/algorithms/
LDY Y_pos
LDX X_pos
;; X_pos = X_pos + r (hack, should fix later ( xpos == ypos is not always true))
CLC
LDA X_pos
ADC radius
STA X_pos
;; t1 = radius >> 4
LDA radius
LSR
LSR
LSR
LSR
STA t1
while_x_bigger_then_y:
STY Y_pos
STX X_pos
STA temp
jsr pixel_draw
LDY Y_pos
LDX X_pos
LDA temp
INY ; y++
;;t1 += y
CLC
LDA t1
STY temp
ADC temp
STA t1
;; t2 = t1 -x
SEC
STX temp
SBC temp
;; if t2 < 0 then skip to endif
CMP #$00
BMI endif
if:
DEX; x--
STA t1; t1 = t2
endif:
;; repeat if X > Y
STX temp
TYA
CMP temp
JMP while_x_bigger_then_y
BEQ while_x_bigger_then_y
.endproc