orb: more optimizations. so close...

This commit is contained in:
Vince Weaver 2022-02-02 14:02:02 -05:00
parent b550f014b4
commit 5e015925a7
5 changed files with 199 additions and 44 deletions

View File

@ -18,13 +18,15 @@ outer_boxes:
ldx #5 ; grab 5 bytes
; YRUN, XRUN, Y1, X1, COLOR
data_smc:
lda $f180
lda $f200 ; was $f180
sta YRUN-1,X ; store reverse for some reason
inc data_smc+1 ; move to next
dex
bne data_smc
lda YRUN
; at end, YRUN is in A, X=0
; lda YRUN ; keep size of YRUN<64
and #$3f
sta YRUN
@ -45,23 +47,20 @@ rectangle_loop:
and #$f
tax
jsr HCOLOR1
; lda COLORTBL,X ; index into color table
; sta HGR_COLOR ; and store
jsr HCOLOR1 ; index into color table with X
; Note: we purposefully index off end
ldx X1 ; X1 into X
lda Y1 ; Y1 into A
ldy #0 ; always 0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
jsr HPLOT0 ; (Y,X),(A) (values stored in HGRX,XH,Y)
lda XRUN ; XRUN into A
and #$3f
; ldx #0 ; always 0
; ldy #0 ; relative Y is 0
; jsr HLINRL ; (X,A),(Y)
jsr combo_hlinrl
and #$3f ; keep it <64
; sets X=0,Y=0 first
jsr combo_hlinrl ; draw relative (X,A),Y
blah:
inc Y1
dec YRUN
bne rectangle_loop

View File

@ -1,5 +1,7 @@
; combo -- Apple II Hires
; need 252 bytes to qualify (4 byte Apple II header)
; 280 bytes -- initial combo
; 276 bytes -- shave some bytes
; 275 bytes -- common HLINRL function (thought it would save more)
@ -7,6 +9,8 @@
; 268 bytes -- circle code now <128 so use bne instead of jmp
; 266 bytes -- use X to index in zero page
; 263 bytes -- more circle optimization
; 261 bytes -- optimize boxes
; 257 bytes -- optimize staggered
; zero page
@ -58,9 +62,6 @@ WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
combo:
lda #$20
sta FRAME
jsr HGR2 ; after, A=0, Y=0
@ -71,6 +72,11 @@ combo:
.include "boxes.s"
even_lookup:
.byte $D7,$DD,$F5,$D5, $D5,$D5,$D5,$D5
odd_lookup:
.byte $AA,$AA,$AA,$AB, $AB,$AE,$BA,$EA
; sadly this only saves a byte
combo_hlinrl:
ldy #0
@ -78,8 +84,5 @@ combo_hlinrl:
jmp HLINRL ; plot relative (X,A), (Y)
even_lookup:
.byte $D7,$DD,$F5,$D5, $D5,$D5,$D5,$D5
odd_lookup:
.byte $AA,$AA,$AA,$AB, $AB,$AE,$BA,$EA

154
demos/l/orb_256/horror.s Normal file
View File

@ -0,0 +1,154 @@
; 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:
; a=0, y=0 here
tax ; x=0
dey ; set init color to white
sty HGR_COLOR ; set init color to white
draw_next:
stx R
;===============================
; draw circle
;===============================
; draw circle at (CX,CY) of radius R
; signed 8-bit math so problems if R > 64?
lda #0
sta XX ; XX = 0
stx YY ; YY =R (X is R here)
lda #3 ; D=3-2*R
sec
sbc R
sbc R
sta D
; always odd, never zero
bne do_plots ; bra skip ahead first time through
circle_loop:
inc XX ; XX=XX+1
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
bit D ; check if negative w/o changing A
bmi d_negative
dec YY ; YY=YY-1
d_positive:
; D=D+4*(XX-YY)+10
; XX is already in A
sec
sbc YY
ldy #10
d_negative:
; ELSE D=D+4*(XX)+6
common_D:
sty DADD
asl
asl
clc
adc DADD
adc D
sta D
do_plots:
; setup constants
lda XX
eor #$FF
sta MINUSXX
inc MINUSXX
lda YY
eor #$FF
sta MINUSYY
inc MINUSYY
; 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
lda #3
sta COUNT
pos_loop:
; calc left side
; calc X co-ord
lda COUNT
ora #$1
eor #$2
tax
; lda CX
lda #128
clc
adc XX,X
tax
; calc y co-ord
ldx COUNT
; lda CY
lda #96
clc
adc XX,X
ldy #0
jsr HPLOT0 ; plot at (Y,X), (A)
; calc right side
lda COUNT
and #$2
eor #$2
tax
lda XX,X
asl
jsr combo_hlinrl ; plot relative (X,A), (Y)
; so in our case (0,XX*2),0
dec COUNT
bpl pos_loop
; IF YY>=XX THEN 4
; equivelant to IF XX<YY
; but sadly appears we need IF XX<=YY for same effect
lda YY
cmp XX
bcs circle_loop
done:
ldx R
inx ; increment radius
jsr HCOLOR1 ; use as color
cpx #48 ; run until R=48
bne draw_next ; loop (GOTO 1)
rdone:

View File

@ -147,7 +147,7 @@ pos_loop:
; IF YY>=XX THEN 4
; equivelant to IF XX<YY
; should be equivelant to IF XX<YY
; but sadly appears we need IF XX<=YY for same effect
lda YY
cmp XX

View File

@ -1,47 +1,47 @@
; shimmery blue pattern
; X=48 here, can't count on others
staggered:
stx FRAME ; set FRAME to 48
ldx #$00 ; init X to 0
stx GBASL ; set GBASL to 0
; pulse loop horizontal
lda #$00
tay
tax
sta GBASL
outer_loop:
lda #$40
lda #$40 ; reset GBASH to begin page2
sta GBASH
inner_loop:
lda even_lookup,X
sta (GBASL),Y
lda even_lookup,X ; get even color
sta (GBASL),Y ; store it to memory
iny
lda odd_lookup,X
sta (GBASL),Y
lda odd_lookup,X ; get odd color
sta (GBASL),Y ; store it to memory
iny
bne inner_loop
inc GBASH
bne inner_loop ; repeat for 256
inx
inc GBASH ; point to next page
inx ; wrap lookup at 8
txa
and #$7
tax
lda #$60
lda #$60 ; see if done
cmp GBASH
bne inner_loop
; lda #100
jsr WAIT
; lda #100 ; A is $60 here
jsr WAIT ; pause a bit
inx
; A is 0 here
dec FRAME
inx ; offset next FRAME
dec FRAME ; exit after so many frames
bne outer_loop
@ -50,4 +50,3 @@ inner_loop:
;.byte $D7,$DD,$F5,$D5, $D5,$D5,$D5,$D5
;odd_lookup:
;.byte $AA,$AA,$AA,$AB, $AB,$AE,$BA,$EA