dos33fsprogs/demos/lovebyte2022/orb_256/orb.s

167 lines
2.4 KiB
ArmAsm
Raw Normal View History

; orb
; this was found accidentally when trying to draw circles
; it's doing Bresenham circle algo I think, which does weird
; things when radius=0
orb:
2022-02-02 18:17:59 +00:00
; a=0, y=0 here (it's after HGR2)
2022-02-02 18:17:59 +00:00
tax ; x=0 (set R=0)
dey ; set init color to white
sty HGR_COLOR ; set init color to white
draw_next:
2022-02-02 18:17:59 +00:00
; X is always R here
stx R
;===============================
; draw circle
;===============================
; draw circle at (CX,CY) of radius R
; signed 8-bit math so problems if R > 64?
lda #0
2022-02-02 17:30:14 +00:00
sta XX ; XX = 0
2022-02-02 17:30:14 +00:00
stx YY ; YY =R (X is R here)
2022-02-02 17:30:14 +00:00
lda #3 ; D=3-2*R
sec
sbc R
sbc R
2022-02-02 20:12:54 +00:00
; D is now in A
; always odd, never zero
2022-02-02 17:30:14 +00:00
bne do_plots ; bra skip ahead first time through
circle_loop:
2022-02-02 17:30:14 +00:00
inc XX ; XX=XX+1
2022-02-02 17:30:14 +00:00
lda XX ; XX is common both paths
ldy #6 ; default path add 6
; IF D>0 THEN Y=Y-1:D=D+4*(X-Y)+10
2022-02-02 17:30:14 +00:00
bit D ; check if negative w/o changing A
bmi d_negative
2022-02-02 17:30:14 +00:00
dec YY ; YY=YY-1
2022-02-02 17:30:14 +00:00
d_positive:
; D=D+4*(XX-YY)+10
; XX is already in A
2022-02-02 20:12:54 +00:00
; sec ; saves a byte, seems to be OK?
2022-02-02 17:30:14 +00:00
sbc YY
ldy #10
d_negative:
; ELSE D=D+4*(XX)+6
common_D:
sty DADD
asl
asl
clc
adc DADD
adc D
do_plots:
2022-02-02 18:17:59 +00:00
; D is always in A here
sta D
2022-02-02 20:12:54 +00:00
; setup plus/minus XX/YY
2022-02-02 20:12:54 +00:00
ldx #2
plus_minus_loop:
lda XX,X
eor #$FF
2022-02-02 20:12:54 +00:00
sta MINUSXX,X
inc MINUSXX,X
dex
dex
bpl plus_minus_loop
; HPLOT CX+X,CY+Y
; HPLOT CX-X,CY+Y
; HPLOT CX+X,CY-Y
; HPLOT CX-X,CY-Y
; HPLOT CX+Y,CY+X
; HPLOT CX-Y,CY+X
; HPLOT CX+Y,CY-X
; HPLOT CX-Y,CY-X
2022-02-02 18:17:59 +00:00
ldx #3
2022-02-02 18:17:59 +00:00
pos_loop:
; calc left side
2022-02-02 18:17:59 +00:00
; COUNT already in X here
2022-02-02 18:17:59 +00:00
stx COUNT
2022-02-02 17:30:14 +00:00
2022-02-02 18:17:59 +00:00
; calc y co-ord
2022-02-02 17:30:14 +00:00
2022-02-02 18:17:59 +00:00
lda #96 ; center around y=96
clc
2022-02-02 18:17:59 +00:00
adc XX,X ; index with COUNT
2022-02-02 20:12:54 +00:00
tay ; save for later
2022-02-02 18:17:59 +00:00
; calc x co-ord
txa ; get count
ora #$1 ; generate pattern
eor #$2 ; ???
tax ; offset in array
2022-02-02 18:17:59 +00:00
lda #128 ; center around x=128
clc
2022-02-02 18:17:59 +00:00
adc XX,X
2022-02-02 18:17:59 +00:00
tax
2022-02-02 20:12:54 +00:00
tya ; restore Y co-ordinate
2022-02-02 18:17:59 +00:00
ldy #0 ; always 0
jsr HPLOT0 ; plot at (Y,X), (A)
; calc right side
lda COUNT
and #$2
eor #$2
2022-02-02 18:17:59 +00:00
tax
lda XX,X
asl
2022-02-02 18:17:59 +00:00
jsr combo_hlinrl ; plot relative (X,A), (Y)
; so in our case (0,XX*2),0
2022-02-02 18:17:59 +00:00
; X/A/Y saved to zero page
; X/Y were zero
ldx COUNT
dex ; decrement count
bpl pos_loop
2022-02-02 18:17:59 +00:00
; IF YY>=XX THEN 4
2022-02-02 19:02:02 +00:00
; should be equivelant to IF XX<YY
2022-02-02 20:12:54 +00:00
; but sadly appears we need IF XX<=YY for our initial effect
lda YY
cmp XX
bcs circle_loop
done:
ldx R
inx ; increment radius
jsr HCOLOR1 ; use as color
2022-02-02 17:30:14 +00:00
cpx #48 ; run until R=48
bne draw_next ; loop (GOTO 1)
rdone: