ElEctric_EyE wrote:
8BIT wrote:
...I can post a stand alone assembly version if you want it... might take a day to put it together though.
Daryl
I would be in your debt!
Here ya go!
Code:
;*************************************************************************
; Draw a circle using Bresenham's circle algorithm
;
; 65C02 code written by Daryl Rictor
;*************************************************************************
; ZP variables
; ZP base address of data area
ZPBase = $00
XC = $00 + ZPBase ; Center Point
YC = $02 + ZPBase ;
R = $04 + ZPBase ; radius (1 byte)
XP = $06 + ZPBase ; plot point
YP = $08 + ZPBase ;
X1 = $0a + ZPBase ; x,y intermediate
Y1 = $0c + ZPBase ;
FF = $0e + ZPBase ; difference
FX = $10 + ZPBase ; diff x
FY = $12 + ZPBase ; diff y
; ------------------------------------------------------------------------
; SETPIXELCLIP: Test pixel @ XP,YP and plot if on screen
SETPIXELCLIP
; insert user code here
rts
; ------------------------------------------------------------------------
; CIRCLE: Draw a circle around the center XC/YC with radius in R.
;
; Must set an error code: NO
;
CIRCLE
lda R ; get Radius
bne _C1
lda XC ; if R=0, plot center point and exit
sta XP ; move center point to plot point var
lda XC+1
sta XP+1
lda YC
sta YP
lda YC+1
sta YP+1
jmp SETPIXELCLIP ; Plot as a point and exit
; int y = radius;
_C1 lda R ; 8 bit radius - can be expanded to 16 bit
sta Y1
stz Y1+1
; int x = 0;
stz X1
stz X1+1
; int f = 1 - radius; ; if using 16 bit radius, this code section
sec ; will need modifications
lda #$01
sbc R
sta FF
stz FF+1
bcs _C2
dec FF+1
; int ddF_x = 1;
_C2 lda #$01
sta FX
stz FX+1
; int ddF_y = -2 * radius; ; if using 16 bit radius, this code section
stz FY+1 ; will need modifications also
lda R
asl ; *2
sta FY
rol FY+1
lda FY
EOR #$FF
sta FY
lda FY+1
EOR #$FF
sta FY+1
inc FY
bne _C3
inc FY+1
; tgi_setpixel(xC, yC + y);
_C3 lda XC
sta XP
lda XC+1
sta XP+1
clc
lda YC
adc Y1
sta YP
lda YC+1
adc Y1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC, yC - y);
sec
lda YC
sbc Y1
sta YP
lda YC+1
sbc Y1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC + y, yC);
clc
lda XC
adc Y1
sta XP
lda XC+1
adc Y1+1
sta XP+1
lda YC
sta YP
lda YC+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC - y, yC);
sec
lda XC
sbc Y1
sta XP
lda XC+1
sbc Y1+1
sta XP+1
jsr SETPIXELCLIP
_CLOOP
; while (x < y) { ; calculate next plot step
sec
lda X1
sbc Y1
lda X1+1
sbc Y1+1
bcc _C4 ; x<y
rts
_C4 lda FF+1
bmi _C6
lda Y1
bne _C5
dec Y1+1
_C5 dec Y1
clc
lda FY
adc #$02
sta FY
tax
lda FY+1
adc #$00
sta FY+1
tay
clc
txa
adc FF
sta FF
tya
ADC FF+1
sta FF+1
_C6 inc X1
bne _C7
inc X1+1
_C7 clc
lda FX
adc #$02
sta FX
tax
lda FX+1
adc #$00
sta FX+1
tay
clc
txa
adc FF
sta FF
tya
ADC FF+1
sta FF+1 ; computations done - now plot 8 Octants
; tgi_setpixel(xC + x, yC + y);
clc
lda XC
adc X1
sta XP
pha
lda XC+1
adc X1+1
sta XP+1
pha
clc
lda YC
adc Y1
sta YP
lda YC+1
adc Y1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC - x, yC + y);
sec
lda XC
sbc X1
sta XP
lda XC+1
sbc X1+1
sta XP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC - x, yC - y);
sec
lda YC
sbc Y1
sta YP
lda YC+1
sbc Y1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC + x, yC - y);
pla
sta XP+1
pla
sta XP
jsr SETPIXELCLIP
; tgi_setpixel(xC + y, yC + x);
clc
lda XC
adc Y1
sta XP
pha
lda XC+1
adc Y1+1
sta XP+1
pha
clc
lda YC
adc X1
sta YP
lda YC+1
adc X1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC - y, yC + x);
sec
lda XC
sbc Y1
sta XP
lda XC+1
sbc Y1+1
sta XP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC - y, yC - x);
sec
lda YC
sbc X1
sta YP
lda YC+1
sbc X1+1
sta YP+1
jsr SETPIXELCLIP
; tgi_setpixel(xC + x, yC - y);
pla
sta XP+1
pla
sta XP
jsr SETPIXELCLIP
jmp _CLOOP
_________________
Please visit my website ->
https://sbc.rictor.org/