plasma: optimize

This commit is contained in:
Vince Weaver 2021-01-09 15:00:32 -05:00
parent bb18191fd7
commit 2010c7b715
4 changed files with 237 additions and 19 deletions

View File

@ -6,10 +6,11 @@ LINKERSCRIPTS = ../../../linker_scripts
all: plasma.dsk
plasma.dsk: HELLO PLASMA
plasma.dsk: HELLO PLASMA PLASMA_TINY
cp empty.dsk plasma.dsk
$(DOS33) -y plasma.dsk SAVE A HELLO
$(DOS33) -y plasma.dsk BSAVE -a 0xC00 PLASMA
$(DOS33) -y plasma.dsk BSAVE -a 0xC00 PLASMA_TINY
###
@ -26,5 +27,14 @@ plasma.o: plasma.s
###
PLASMA_TINY: plasma_tiny.o
ld65 -o PLASMA_TINY plasma_tiny.o -C $(LINKERSCRIPTS)/apple2_c00.inc
plasma_tiny.o: plasma_tiny.s
ca65 -o plasma_tiny.o plasma_tiny.s -l plasma_tiny.lst
###
clean:
rm -f *~ *.o *.lst PLASMA

View File

@ -40,10 +40,12 @@ NORMAL = $F273
;; MONITOR ROUTINES
PLOT = $F800 ;; PLOT AT Y,A
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y
CLRSCR = $F832 ;; Clear low-res screen
CLRTOP = $F836 ;; clear only top of low-res screen
GBASCALC= $F847 ;; take Y coord in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A
ROM_TEXT2COPY = $F962 ;; iigs
SETTXT = $FB36

View File

@ -10,6 +10,10 @@
; 129 -- run loop backwards
; 128 -- set color ourselves
; 127 -- overlap color lookup with sine table
; 119 -- forgot to comment out unused
; 149 -- add page flipping
; 144 -- optimize a bit
.include "zp.inc"
.include "hardware.inc"
@ -24,11 +28,10 @@ SAVEY = $FF
;================================
jsr SETGR
bit FULLGR
lda #0
sta DISP_PAGE
lda #4
sta DRAW_PAGE
; lda #4
; sta DRAW_PAGE
;col = ( 8.0 + (sintable[xx&0xf])
; + 8.0 + (sintable[yy&0xf])
@ -56,6 +59,7 @@ lookup_smc:
dey
bpl create_yloop
; X and Y both $FF
create_lookup_done:
@ -64,7 +68,10 @@ forever_loop:
cycle_colors:
; cycle colors
ldx #0
; X if $FF when arriving here
; ldx #0
inx ; make X 0
cycle_loop:
inc lookup,X
inx
@ -73,19 +80,46 @@ cycle_loop:
plot_frame:
; set which page
; flip page
; ldx #0 ; x already 0
lda DRAW_PAGE
beq done_page
inx
done_page:
ldy PAGE0,X
eor #$4
sta DRAW_PAGE
; plot frame
ldx #39 ; YY=0
ldx #47 ; YY=0
plot_yloop:
ldy #39 ; XX = 0
txa ; get (y&0xf)<<4
asl
asl
asl
asl
sta CTEMP
txa
lsr
php
jsr GBASCALC ; point GBASL/H to address in A
; after, A trashed, C is clear
; after, A is GBASL, C is clear
lda GBASH
adc DRAW_PAGE
sta GBASH
plp
lda #$0f ; setup mask
@ -95,21 +129,17 @@ plot_yloop:
plot_mask:
sta MASK
;==========
ldy #39 ; XX = 39 (countdown)
plot_xloop:
stx SAVEX ; SAVE YY
tya ; get x&0xf
and #$f
sta CTEMP
txa ; get (y&0xf)<<4
asl
asl
asl
asl
ora CTEMP ; get (y*15)+x
ora CTEMP ; get ((y&0xf)*16)+x
tax
@ -140,7 +170,7 @@ plot_lookup_smc:
; iny
; cpy #40
; bne plot_xloop
; bne plot_xlooph
; inx
; cpx #40

View File

@ -0,0 +1,176 @@
; do a (hopefully fast) plasma
; 151 -- original
; 137 -- optimize generation
; 136 -- align lookup table so we can index it easier
; 130 -- optimize indexing of lookup
; 126 -- run loops backaward
; 124 -- notice X already 0 before plot
; 131 -- use GBASCALC. much faster, but 7 bytes larger
; 129 -- run loop backwards
; 128 -- set color ourselves
; 127 -- overlap color lookup with sine table
; 119 -- forgot to comment out unused
; 121 -- make full screen
.include "zp.inc"
.include "hardware.inc"
CTEMP = $FC
SAVEOFF = $FD
SAVEX = $FE
SAVEY = $FF
;================================
; Clear screen and setup graphics
;================================
jsr SETGR
bit FULLGR ; full screen
; lda #0
; sta DISP_PAGE
; lda #4
; sta DRAW_PAGE
;col = ( 8.0 + (sintable[xx&0xf])
; + 8.0 + (sintable[yy&0xf])
; ) / 2;
create_lookup:
ldy #15
create_yloop:
ldx #15
create_xloop:
clc
lda #15
adc sinetable,X
adc sinetable,Y
lsr
lookup_smc:
sta lookup ; always starts at $d00
inc lookup_smc+1
dex
bpl create_xloop
dey
bpl create_yloop
create_lookup_done:
forever_loop:
cycle_colors:
; cycle colors
; X is $FF when arrive here
inx
; ldx #0
cycle_loop:
inc lookup,X
inx
bne cycle_loop
plot_frame:
; plot frame
ldx #47 ; YY=0
plot_yloop:
txa ; get (y&0xf)<<4
asl
asl
asl
asl
sta CTEMP
txa
lsr
php
jsr GBASCALC ; point GBASL/H to address in A
; after, A trashed, C is clear
plp
lda #$0f ; setup mask
bcc plot_mask
adc #$e0
plot_mask:
sta MASK
;==========
ldy #39 ; XX = 39 (countdown)
plot_xloop:
stx SAVEX ; SAVE YY
tya ; get x&0xf
and #$f
ora CTEMP ; get ((y&0xf)*16)+x
tax
plot_lookup:
; sta plot_lookup_smc+1
plot_lookup_smc:
lda lookup,X ; load lookup, (y*16)+x
; lda lookup ; load lookup, (y*16)+x
and #$f
lsr
tax
lda colorlookup,X
sta COLOR
jsr PLOT1 ; plot at GBASL,Y (x co-ord in Y)
ldx SAVEX ; restore YY
dey
bpl plot_xloop
dex
bpl plot_yloop
bmi forever_loop
; iny
; cpy #40
; bne plot_xloop
; inx
; cpx #40
; bne plot_yloop
; beq forever_loop
colorlookup:
bw_color_lookup:
.byte $55,$22,$66,$77,$ff,$77,$55 ; ,$00 shared w sin table
sinetable:
.byte $00,$03,$05,$07,$08,$07,$05,$03
.byte $00,$FD,$FB,$F9,$F8,$F9,$FB,$FD
;colorlookup:
;.byte $00,$00,$05,$05,$07,$07,$0f,$0f
;.byte $07,$07,$06,$06,$02,$02,$05,$05
;.byte $00,$55,$77,$ff,$77,$66,$22,$55
.org $d00
;.align $100
lookup: