plamsa: more work

This commit is contained in:
Vince Weaver 2021-10-16 21:30:06 -04:00
parent c9b19346eb
commit f4879d9121
7 changed files with 840 additions and 46 deletions

View File

@ -9,7 +9,8 @@ all: plasma.dsk
plasma.dsk: HELLO PLASMA PLASMA2 \
DIAMONDS STATIC STATIC_BOT \
PLASMA_128 PLASMA_TINY PLASMA_BOT WIRES WIRES_BOT
PLASMA_128 PLASMA_TINY PLASMA_BOT WIRES WIRES_BOT \
SMALLCIRCS STAR OVAL
cp $(EMPTYDISK) plasma.dsk
$(DOS33) -y plasma.dsk SAVE A HELLO
$(DOS33) -y plasma.dsk BSAVE -a 0x70 PLASMA
@ -22,6 +23,9 @@ plasma.dsk: HELLO PLASMA PLASMA2 \
$(DOS33) -y plasma.dsk BSAVE -a 0xc00 DIAMONDS
$(DOS33) -y plasma.dsk BSAVE -a 0xc00 STATIC
$(DOS33) -y plasma.dsk BSAVE -a 0x384 STATIC_BOT
$(DOS33) -y plasma.dsk BSAVE -a 0xc00 SMALLCIRCS
$(DOS33) -y plasma.dsk BSAVE -a 0xc00 STAR
$(DOS33) -y plasma.dsk BSAVE -a 0xc00 OVAL
###
@ -44,6 +48,33 @@ PLASMA2: plasma2.o
plasma2.o: plasma2.s
ca65 -o plasma2.o plasma2.s -l plasma2.lst
###
SMALLCIRCS: smallcircs.o
ld65 -o SMALLCIRCS smallcircs.o -C $(LINKERSCRIPTS)/apple2_c00.inc
smallcircs.o: smallcircs.s
ca65 -o smallcircs.o smallcircs.s -l smallcircs.lst
###
STAR: star.o
ld65 -o STAR star.o -C $(LINKERSCRIPTS)/apple2_c00.inc
star.o: star.s
ca65 -o star.o star.s -l star.lst
###
OVAL: oval.o
ld65 -o OVAL oval.o -C $(LINKERSCRIPTS)/apple2_c00.inc
oval.o: oval.s
ca65 -o oval.o oval.s -l oval.lst
###
DIAMONDS: diamonds.o

View File

@ -7,7 +7,9 @@ int main(int argc, char **argv) {
double d;
int i,r;
unsigned char c;
#if 0
for(i=0;i<16;i++) {
d=(((double)i)*2.0*PI)/16.0;
@ -17,6 +19,20 @@ int main(int argc, char **argv) {
printf("%i, %02X\n",i,r);
}
#endif
for(i=0;i<64;i++) {
d=(((double)i)*2.0*PI)/64.0;
r=32*sin(d);
c=r;
printf("$%02X,",c);
}
printf("\n");
return 0;
}

169
graphics/gr/plasma/oval.s Normal file
View File

@ -0,0 +1,169 @@
; Ovals
; zero page
GBASL = $26
GBASH = $27
MASK = $2E
COLOR = $30
;CTEMP = $68
YY = $69
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
PLOT = $F800 ;; PLOT AT Y,A
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A*17
SETGR = $FB40
;================================
; Clear screen and setup graphics
;================================
oval:
jsr SETGR ; set lo-res 40x40 mode
bit FULLGR ; make it 40x48
draw_oval:
inc FRAME
ldx #47 ; YY
create_yloop:
ldy #39
txa
jsr PLOT ; (Y,A) sets GBASL/GBASH, Y
create_xloop:
; lda #128
lda FRAME
sta SUM
tya ; XX
jsr calcsine_div2
txa ; YY
jsr calcsine
; X (YY) is in SAVEX
clc
; sty SAVEY ; XX
tya
adc SAVEX ; XX + YY
jsr calcsine_div2
; clc
; adc FRAME
lsr ; double colors
and #$7 ; mask
tax
lda colorlookup,X
jsr SETCOL
jsr PLOT1 ; PLOT (GBASL),Y
ldx SAVEX
dey
bpl create_xloop
dex
bpl create_yloop
; X and Y both $FF
bmi draw_oval
calcsine_div2:
lsr
calcsine:
stx SAVEX
and #$3f
tax
rol
rol
rol
bcc sinadd
sinsub:
lda #0
lda SUM
; sec
sbc sinetable-32,X
jmp sindone
sinadd:
lda SUM
; clc
adc sinetable,X
sindone:
sta SUM
ldx SAVEX
rts
colorlookup:
; blue
;.byte $55,$77,$ff,$77,$66,$22,$55 ; use 00 from sinetable
;.byte $00
; pink
.byte $55,$11,$33,$bb,$ff,$bb,$55
;.byte $00
; green
;.byte $55,$44,$cc,$ff,$cc,$44,$55 ; use 00 from sinetable
;.byte $00
; orange
;.byte $99,$88,$ff,$44,$cc,$ff,$55 ; use 00 from sinetable
;.byte $00
;.byte $00,$00,$55,$55,$77,$77,$ff,$ff
;.byte $77,$77,$66,$66,$22,$22,$55,$55
sinetable:
; this is actually (32*sin(x))
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
.byte $20,$1F,$1F,$1E,$1D,$1C,$1A,$18
.byte $16,$14,$11,$0F,$0C,$09,$06,$03
;.byte $00,$FD,$FA,$F7,$F4,$F1,$EF,$EC
;.byte $EA,$E8,$E6,$E4,$E3,$E2,$E1,$E1
;.byte $E0,$E1,$E1,$E2,$E3,$E4,$E6,$E8
;.byte $EA,$EC,$EF,$F1,$F4,$F7,$FA,$FD
;.byte $00,$06,$0C,$11,$16,$1A,$1D,$1F
;.byte $20,$1F,$1D,$1A,$16,$11,$0C,$06
;.byte $00,$FA,$F4,$EF,$EA,$E6,$E3,$E1
;.byte $E0,$E1,$E3,$E6,$EA,$EF,$F4,$FA
;.byte $00,$0C,$16,$1D
;.byte $20,$1D,$16,$0C
;.byte $00,$F4,$EA,$E3
;.byte $E0,$E3,$EA,$F4

View File

@ -37,50 +37,61 @@ plasma:
jsr SETGR ; set lo-res 40x40 mode
bit FULLGR ; make it 40x48
draw_plasma:
ldx #39
; lda #$0f
; sta MASK
ldx #47 ; YY
create_yloop:
ldy #47
; lda MASK
; eor #$FF
; sta MASK
; txa
; lsr
; jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
ldy #0
txa
jsr PLOT ; (Y,A) sets GBASL/GBASH, Y
ldy #39
create_xloop:
lda #128
sta SUM
txa
adc FRAME
jsr calcsine
tya
; adc FRAME
jsr calcsine_div_2
tya ; XX
jsr calcsine_div2
txa ; YY
jsr calcsine
clc
stx SAVEX
tya
adc SAVEX
jsr calcsine
sty SAVEY ; XX
txa
adc SAVEY ; XX + YY
jsr calcsine_div2
stx SAVEX
sty SAVEY
; clc
clc
adc FRAME
lsr
and #$7
tax
lda colorlookup,X
jsr SETCOL
ldy SAVEY
lda SAVEX
ldy SAVEX
lda SAVEY
jsr PLOT ; PLOT Y,A
jsr PLOT1 ; PLOT (GBASL),Y
ldx SAVEX
ldy SAVEY
dey
bpl create_xloop
@ -208,20 +219,39 @@ frame_smc:
.endif
calcsine_div_8:
lsr
calcsine_div_4:
lsr
calcsine_div_2:
;calcsine_div8:
; lsr
;calcsine_div4:
; lsr
calcsine_div2:
lsr
calcsine:
stx SAVEX
and #$f
and #$3f
tax
lda sinetable,X
clc
adc SUM
rol
rol
rol
bcc sinadd
sinsub:
lda #0
lda SUM
; sec
sbc sinetable-32,X
jmp sindone
sinadd:
lda SUM
; clc
adc sinetable,X
sindone:
sta SUM
ldx SAVEX
rts
@ -229,14 +259,34 @@ calcsine:
colorlookup:
; blue
.byte $55,$22,$66,$77,$ff,$77,$55,$00
;.byte $55,$22,$66,$77,$ff,$77,$55,$00
.byte $00,$55,$77,$ff,$77,$66,$22,$55
;.byte $00,$00,$55,$55,$77,$77,$ff,$ff
;.byte $77,$77,$66,$66,$22,$22,$55,$55
sinetable:
; this is actually (32*sin(x))
.byte $00,$0C,$16,$1D
.byte $20,$1D,$16,$0C
.byte $00,$F4,$EA,$E3
.byte $E0,$E3,$EA,$F4
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
.byte $20,$1F,$1F,$1E,$1D,$1C,$1A,$18
.byte $16,$14,$11,$0F,$0C,$09,$06,$03
;.byte $00,$FD,$FA,$F7,$F4,$F1,$EF,$EC
;.byte $EA,$E8,$E6,$E4,$E3,$E2,$E1,$E1
;.byte $E0,$E1,$E1,$E2,$E3,$E4,$E6,$E8
;.byte $EA,$EC,$EF,$F1,$F4,$F7,$FA,$FD
;.byte $00,$06,$0C,$11,$16,$1A,$1D,$1F
;.byte $20,$1F,$1D,$1A,$16,$11,$0C,$06
;.byte $00,$FA,$F4,$EF,$EA,$E6,$E3,$E1
;.byte $E0,$E1,$E3,$E6,$EA,$EF,$F4,$FA
;.byte $00,$0C,$16,$1D
;.byte $20,$1D,$16,$0C
;.byte $00,$F4,$EA,$E3
;.byte $E0,$E3,$EA,$F4

View File

@ -0,0 +1,254 @@
; more plasma
; by Vince `deater` Weaver (vince@deater.net) / dSr
; with some help from qkumba
; zero page
GBASL = $26
GBASH = $27
MASK = $2E
COLOR = $30
;CTEMP = $68
YY = $69
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
PLOT = $F800 ;; PLOT AT Y,A
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A*17
SETGR = $FB40
;================================
; Clear screen and setup graphics
;================================
plasma:
jsr SETGR ; set lo-res 40x40 mode
bit FULLGR ; make it 40x48
draw_plasma:
lda #$0f
sta MASK
ldx #47 ; YY
create_yloop:
lda MASK
eor #$FF
sta MASK
txa
lsr
jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
ldy #39
create_xloop:
lda #128
sta SUM
tya ; XX
jsr calcsine
txa ; YY
jsr calcsine
clc
sty SAVEY ; XX
txa
adc SAVEY ; XX + YY
jsr calcsine
clc
adc FRAME
and #$7
tax
lda colorlookup,X
jsr SETCOL
ldy SAVEY
lda SAVEX
jsr PLOT1 ; PLOT (GBASL),Y
ldx SAVEX
dey
bpl create_xloop
dex
bpl create_yloop
; X and Y both $FF
create_lookup_done:
forever_loop:
inc FRAME
jmp draw_plasma
; jmp forever_loop
.if 0
cycle_colors:
; cycle colors
; instead of advancing entire frame, do slightly slower route
; instead now and just incrememnting the frame and doing the
; adjustment at plot time.
; increment frame
inc frame_smc+1
; set/flip pages
; we want to flip pages and then draw to the offscreen one
flip_pages:
; ldy #0
; iny ; y is $FF, make it 0
lda draw_page_smc+1 ; DRAW_PAGE
bne done_page
dey
done_page:
; ldx PAGE1,Y ; set display page to PAGE1 or PAGE2
ldx $BF56,Y ; PAGE1 - $FF
eor #$4 ; flip draw page between $400/$800
sta draw_page_smc+1 ; DRAW_PAGE
; plot current frame
; scan whole 40x48 screen and plot each point based on
; lookup table colors
plot_frame:
ldx #47 ; YY=47 (count backwards)
plot_yloop:
txa ; get YY into A
pha ; save X for later
lsr ; call actually wants Ycoord/2
php ; save C flag for mask handling
; ugh can't use PLOT trick as it always will draw something
; to PAGE1 even if we don't want to
jsr GBASCALC ; point GBASL/H to address in (A is ycoord/2)
; after, A is GBASL, C is clear
lda GBASH ; adjust to be PAGE1/PAGE2 ($400 or $800)
draw_page_smc:
adc #0
sta GBASH
; increment YY in top nibble of lookup for (yy<<16)+xx
; clc from above, C always 0
lda plot_lookup_smc+1
adc #$10 ; no need to mask as it will oflo and be ignored
sta plot_lookup_smc+1
;==========
ldy #39 ; XX = 39 (countdown)
; sets MASK by calling into middle of PLOT routine
; by Y being 39 draw in a spot that gets over-written
plp
jsr $f806
plot_xloop:
tya ; get XX & 0x0f
and #$f
tax
plot_lookup_smc:
lda lookup,X ; load lookup, (YY*16)+XX
clc
frame_smc:
adc #$00 ; add in frame
and #$f
lsr ; we actually only have 8 colors
tax
lda colorlookup,X ; lookup color
sta COLOR ; each nibble should be same
jsr PLOT1 ; plot at GBASL,Y (x co-ord goes in Y)
dey
bpl plot_xloop
pla ; restore YY
tax
dex
bpl plot_yloop
bmi forever_loop
.endif
;calcsine_div_8:
; lsr
;calcsine_div_4:
; lsr
;calcsine_div_2:
; lsr
calcsine:
asl
stx SAVEX
and #$f
tax
lda sinetable,X
clc
adc SUM
sta SUM
ldx SAVEX
rts
colorlookup:
; blue
.byte $55,$22,$66,$77,$ff,$77,$55,$00
sinetable:
; this is actually (32*sin(x))
.byte $00,$06,$0C,$11,$16,$1A,$1D,$1F
.byte $20,$1F,$1D,$1A,$16,$11,$0C,$06
;.byte $00,$FA,$F4,$EF,$EA,$E6,$E3,$E1
;.byte $E0,$E1,$E3,$E6,$EA,$EF,$F4,$FA
;.byte $00,$0C,$16,$1D
;.byte $20,$1D,$16,$0C
;.byte $00,$F4,$EA,$E3
;.byte $E0,$E3,$EA,$F4

259
graphics/gr/plasma/star.s Normal file
View File

@ -0,0 +1,259 @@
; more plasma
; by Vince `deater` Weaver (vince@deater.net) / dSr
; with some help from qkumba
; zero page
GBASL = $26
GBASH = $27
MASK = $2E
COLOR = $30
;CTEMP = $68
YY = $69
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
PLOT = $F800 ;; PLOT AT Y,A
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A*17
SETGR = $FB40
;================================
; Clear screen and setup graphics
;================================
plasma:
jsr SETGR ; set lo-res 40x40 mode
bit FULLGR ; make it 40x48
draw_plasma:
lda #$0f
sta MASK
ldx #47 ; YY
create_yloop:
lda MASK
eor #$FF
sta MASK
txa
lsr
jsr GBASCALC ; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
ldy #39
create_xloop:
lda #128
sta SUM
tya ; XX
jsr calcsine
txa ; YY
jsr calcsine
clc
sty SAVEY ; XX
txa
adc SAVEY ; XX + YY
jsr calcsine
clc
adc FRAME
lsr
and #$7
tax
lda colorlookup,X
jsr SETCOL
ldy SAVEY
lda SAVEX
jsr PLOT1 ; PLOT (GBASL),Y
ldx SAVEX
dey
bpl create_xloop
dex
bpl create_yloop
; X and Y both $FF
create_lookup_done:
forever_loop:
inc FRAME
jmp draw_plasma
; jmp forever_loop
.if 0
cycle_colors:
; cycle colors
; instead of advancing entire frame, do slightly slower route
; instead now and just incrememnting the frame and doing the
; adjustment at plot time.
; increment frame
inc frame_smc+1
; set/flip pages
; we want to flip pages and then draw to the offscreen one
flip_pages:
; ldy #0
; iny ; y is $FF, make it 0
lda draw_page_smc+1 ; DRAW_PAGE
bne done_page
dey
done_page:
; ldx PAGE1,Y ; set display page to PAGE1 or PAGE2
ldx $BF56,Y ; PAGE1 - $FF
eor #$4 ; flip draw page between $400/$800
sta draw_page_smc+1 ; DRAW_PAGE
; plot current frame
; scan whole 40x48 screen and plot each point based on
; lookup table colors
plot_frame:
ldx #47 ; YY=47 (count backwards)
plot_yloop:
txa ; get YY into A
pha ; save X for later
lsr ; call actually wants Ycoord/2
php ; save C flag for mask handling
; ugh can't use PLOT trick as it always will draw something
; to PAGE1 even if we don't want to
jsr GBASCALC ; point GBASL/H to address in (A is ycoord/2)
; after, A is GBASL, C is clear
lda GBASH ; adjust to be PAGE1/PAGE2 ($400 or $800)
draw_page_smc:
adc #0
sta GBASH
; increment YY in top nibble of lookup for (yy<<16)+xx
; clc from above, C always 0
lda plot_lookup_smc+1
adc #$10 ; no need to mask as it will oflo and be ignored
sta plot_lookup_smc+1
;==========
ldy #39 ; XX = 39 (countdown)
; sets MASK by calling into middle of PLOT routine
; by Y being 39 draw in a spot that gets over-written
plp
jsr $f806
plot_xloop:
tya ; get XX & 0x0f
and #$f
tax
plot_lookup_smc:
lda lookup,X ; load lookup, (YY*16)+XX
clc
frame_smc:
adc #$00 ; add in frame
and #$f
lsr ; we actually only have 8 colors
tax
lda colorlookup,X ; lookup color
sta COLOR ; each nibble should be same
jsr PLOT1 ; plot at GBASL,Y (x co-ord goes in Y)
dey
bpl plot_xloop
pla ; restore YY
tax
dex
bpl plot_yloop
bmi forever_loop
.endif
;calcsine_div_8:
; lsr
;calcsine_div_4:
; lsr
;calcsine_div_2:
; lsr
calcsine:
; asl
stx SAVEX
and #$1f
tax
lda sinetable,X
clc
adc SUM
sta SUM
ldx SAVEX
rts
colorlookup:
; blue
;.byte $55,$22,$66,$77,$ff,$77,$55,$00
.byte $00,$55,$77,$ff,$77,$66,$22,$55
;.byte $00,$00,$55,$55,$77,$77,$ff,$ff
;.byte $77,$77,$66,$66,$22,$22,$55,$55
sinetable:
; this is actually (32*sin(x))
.byte $00,$06,$0C,$11,$16,$1A,$1D,$1F
.byte $20,$1F,$1D,$1A,$16,$11,$0C,$06
.byte $00,$FA,$F4,$EF,$EA,$E6,$E3,$E1
.byte $E0,$E1,$E3,$E6,$EA,$EF,$F4,$FA
;.byte $00,$0C,$16,$1D
;.byte $20,$1D,$16,$0C
;.byte $00,$F4,$EA,$E3
;.byte $E0,$E3,$EA,$F4

View File

@ -13,6 +13,8 @@
#define PI 3.14159265358979323846264338327950
int sine_lookup[64];
#if 1
static unsigned char color_lookup[]={0x0, 0x0, 0x5, 0x5,
0x7, 0x7, 0xf, 0xf,
@ -27,7 +29,7 @@ static unsigned char color_lookup[]={0x0, 0x5, 0x7, 0xf,
#endif
static int offscreen[40][40];
static int offscreen[40][48];
int main(int argc, char **argv) {
@ -42,7 +44,13 @@ int main(int argc, char **argv) {
ram[DRAW_PAGE]=0x0;
for(yy=0;yy<40;yy++) {
for(xx=0;xx<64;xx++) {
sine_lookup[xx]=32.0*sin( (xx*2*PI)/64);
}
for(yy=0;yy<48;yy++) {
for(xx=0;xx<40;xx++) {
// col = ( 32.0 + (32.0 * sin(xx / 4.0))
@ -75,13 +83,20 @@ int main(int argc, char **argv) {
sin(xx/16.0), sin(yy/8.0), sin((xx+yy)/16.0));
//#endif
#else
// col = (int)
// ( 128.0 + 32*sin(xx / 16.0)
// + 32*sin(yy / 8.0)
// + 32*sin((xx + yy) / 16.0)
// ) ;
col = (int)
(
128.0 + 32*sin(xx / 16.0)
+ 32*sin(yy / 8.0)
+ 32*sin((xx + yy) / 16.0)
( 128.0 + sine_lookup[ (int)(xx/2)&0x3f ]
+ sine_lookup[ (int)(yy/1)&0x3f ]
+ sine_lookup[ (int)((xx + yy)/2)&0x3f ]
) ;
printf("%d %d %d %.2f %.2f %.2f\n",xx,yy,col,
sin(xx/16.0), sin(yy/8.0), sin((xx+yy)/16.0));
#endif
@ -93,7 +108,7 @@ int main(int argc, char **argv) {
}
while(1) {
for(yy=0;yy<40;yy++) {
for(yy=0;yy<48;yy++) {
for(xx=0;xx<40;xx++) {
col=offscreen[xx][yy];
color_equals(color_lookup[col]);