dos33fsprogs/graphics/gr/plasma/plasma.s

207 lines
3.7 KiB
ArmAsm
Raw Normal View History

2021-01-10 04:25:43 +00:00
; do a (hopefully fast) plasma type demo
2021-01-09 06:41:44 +00:00
2021-01-09 16:58:12 +00:00
; 151 -- original
; 137 -- optimize generation
2021-01-09 17:26:57 +00:00
; 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
2021-01-09 18:19:52 +00:00
; 129 -- run loop backwards
; 128 -- set color ourselves
; 127 -- overlap color lookup with sine table
2021-01-09 20:00:32 +00:00
; 119 -- forgot to comment out unused
2021-01-10 04:16:54 +00:00
; 121 -- make it use full screen (40x48)
2021-01-09 20:00:32 +00:00
; 149 -- add page flipping
; 144 -- optimize a bit
2021-01-09 20:48:29 +00:00
; 141 -- smc DRAW_PAGE
2021-01-10 20:11:32 +00:00
; 139 -- from qkumba, remove php/plp
; 138 -- from qkumba, remove SAVEX
2021-01-09 20:48:29 +00:00
; goal=135
2021-01-09 06:41:44 +00:00
.include "zp.inc"
.include "hardware.inc"
CTEMP = $FC
;================================
; Clear screen and setup graphics
;================================
plasma:
2021-01-09 06:41:44 +00:00
2021-01-10 04:25:43 +00:00
jsr SETGR ; set lo-res 40x40 mode
bit FULLGR ; make it 40x48
2021-01-09 06:41:44 +00:00
2021-01-10 04:25:43 +00:00
; color = ( 8.0 + 8*sin(x) + 8.0 + 8*sin(y) )/2
; becomes
; color = ( 16 + (sintable[xx&0xf]) + (sintable[yy&0xf])) / 2;
; we only create a 16x16 texture, which we pattern across 40x48 screen
2021-01-09 16:58:12 +00:00
2021-01-09 17:26:57 +00:00
create_lookup:
ldy #15
2021-01-09 06:41:44 +00:00
create_yloop:
2021-01-09 17:26:57 +00:00
ldx #15
2021-01-09 06:41:44 +00:00
create_xloop:
clc
2021-01-10 04:25:43 +00:00
lda #15 ; 8+8 (but 15 works better)
2021-01-09 06:41:44 +00:00
adc sinetable,X
adc sinetable,Y
lsr
lookup_smc:
2021-01-09 17:26:57 +00:00
sta lookup ; always starts at $d00
2021-01-09 06:41:44 +00:00
2021-01-09 17:26:57 +00:00
inc lookup_smc+1
2021-01-09 06:41:44 +00:00
2021-01-09 17:26:57 +00:00
dex
bpl create_xloop
dey
bpl create_yloop
2021-01-09 20:00:32 +00:00
; X and Y both $FF
2021-01-09 17:26:57 +00:00
create_lookup_done:
2021-01-09 06:41:44 +00:00
forever_loop:
2021-01-09 17:26:57 +00:00
cycle_colors:
2021-01-09 06:41:44 +00:00
; cycle colors
2021-01-10 04:25:43 +00:00
; can't do palette rotate on Apple II so faking it here
; just incrementing every entry in texture by 1
2021-01-09 20:00:32 +00:00
2021-01-10 04:25:43 +00:00
; X if $FF when arriving here
2021-01-09 20:00:32 +00:00
; ldx #0
inx ; make X 0
2021-01-09 06:41:44 +00:00
cycle_loop:
inc lookup,X
inx
bne cycle_loop
2021-01-09 17:26:57 +00:00
2021-01-10 04:25:43 +00:00
; set/flip pages
; we want to flip pages and then draw to the offscreen one
flip_pages:
2021-01-09 20:00:32 +00:00
; ldx #0 ; x already 0
2021-01-09 20:48:29 +00:00
lda draw_page_smc+1 ; DRAW_PAGE
2021-01-09 20:00:32 +00:00
beq done_page
inx
done_page:
2021-01-10 04:16:54 +00:00
ldy PAGE0,X ; set display page to PAGE1 or PAGE2
2021-01-09 20:00:32 +00:00
2021-01-10 04:16:54 +00:00
eor #$4 ; flip draw page between $400/$800
2021-01-09 20:48:29 +00:00
sta draw_page_smc+1 ; DRAW_PAGE
2021-01-09 20:00:32 +00:00
2021-01-10 04:25:43 +00:00
; plot current frame
; scan whole 40x48 screen and plot each point based on
; lookup table colors
plot_frame:
2021-01-09 06:41:44 +00:00
2021-01-10 04:16:54 +00:00
ldx #47 ; YY=47 (count backwards)
2021-01-09 06:41:44 +00:00
plot_yloop:
2021-01-09 20:00:32 +00:00
txa ; get (y&0xf)<<4
2021-01-10 20:11:32 +00:00
pha ; save YY
2021-01-09 20:00:32 +00:00
asl
asl
asl
asl
2021-01-10 04:16:54 +00:00
sta CTEMP ; save for later
2021-01-10 04:25:43 +00:00
txa ; get Y in accumulator
lsr ; call actually wants Ycoord/2
2021-01-10 20:11:32 +00:00
ldy #$0f ; setup mask for odd/even line
bcc plot_mask
ldy #$f0 ; needlessly clever, from monitor rom src
plot_mask:
sty MASK
; ugh can't use PLOT trick as it always will draw something
; to PAGE1 even if we don't want to
2021-01-10 04:25:43 +00:00
jsr GBASCALC ; point GBASL/H to address in (A is ycoord/2)
2021-01-09 20:00:32 +00:00
; after, A is GBASL, C is clear
2021-01-10 04:25:43 +00:00
lda GBASH ; adjust to be PAGE1/PAGE2 ($400 or $800)
2021-01-09 20:48:29 +00:00
draw_page_smc:
adc #0
2021-01-09 20:00:32 +00:00
sta GBASH
2021-01-09 20:00:32 +00:00
;==========
ldy #39 ; XX = 39 (countdown)
2021-01-09 06:41:44 +00:00
plot_xloop:
tya ; get x&0xf
2021-01-09 06:41:44 +00:00
and #$f
2021-01-10 04:27:28 +00:00
ora CTEMP ; combine with val from earlier
; get ((y&0xf)*16)+x
2021-01-09 18:19:52 +00:00
2021-01-09 06:41:44 +00:00
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
2021-01-09 18:19:52 +00:00
2021-01-09 06:41:44 +00:00
and #$f
2021-01-10 04:27:28 +00:00
lsr ; we actually only have 8 colors
2021-01-09 20:48:29 +00:00
2021-01-09 06:41:44 +00:00
tax
2021-01-10 04:27:28 +00:00
lda colorlookup,X ; lookup color
sta COLOR ; each nibble should be same
2021-01-09 06:41:44 +00:00
2021-01-10 04:16:54 +00:00
jsr PLOT1 ; plot at GBASL,Y (x co-ord goes in Y)
2021-01-09 06:41:44 +00:00
2021-01-09 18:19:52 +00:00
dey
bpl plot_xloop
2021-01-09 06:41:44 +00:00
2021-01-10 20:11:32 +00:00
pla ; restore YY
tax
2021-01-09 18:19:52 +00:00
dex
bpl plot_yloop
bmi forever_loop
2021-01-09 06:41:44 +00:00
2021-01-09 18:19:52 +00:00
colorlookup:
bw_color_lookup:
2021-01-10 20:11:32 +00:00
; blue
2021-01-09 18:19:52 +00:00
.byte $55,$22,$66,$77,$ff,$77,$55 ; ,$00 shared w sin table
2021-01-10 20:11:32 +00:00
; pink
;.byte $55,$11,$33,$bb,$ff,$bb,$55 ; ,$00 shared w sin table
2021-01-09 06:41:44 +00:00
2021-01-10 04:16:54 +00:00
; this is actually 8*sin(x)
2021-01-09 06:41:44 +00:00
sinetable:
.byte $00,$03,$05,$07,$08,$07,$05,$03
.byte $00,$FD,$FB,$F9,$F8,$F9,$FB,$FD
2021-01-09 18:19:52 +00:00
;colorlookup:
2021-01-09 16:58:12 +00:00
;.byte $00,$00,$05,$05,$07,$07,$0f,$0f
;.byte $07,$07,$06,$06,$02,$02,$05,$05
2021-01-09 18:19:52 +00:00
;.byte $00,$55,$77,$ff,$77,$66,$22,$55
2021-01-09 20:48:29 +00:00
; make lookup happen at page boundary
2021-01-09 06:41:44 +00:00
2021-01-09 17:26:57 +00:00
.org $d00
2021-01-09 06:41:44 +00:00
lookup: