hgr: plasma

This commit is contained in:
Vince Weaver 2021-10-25 14:10:44 -04:00
parent cb453394b2
commit ccdae6d1fb
10 changed files with 889 additions and 1 deletions

BIN
graphics/hgr/plasma/HELLO Normal file

Binary file not shown.

View File

@ -0,0 +1,41 @@
include ../../../Makefile.inc
DOS33 = ../../../utils/dos33fs-utils/dos33
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
LINKERSCRIPTS = ../../../linker_scripts
EMPTYDISK = ../../../empty_disk/empty.dsk
all: plasma_hgr.dsk
plasma_hgr.dsk: HELLO OVAL PURPLE_WAVES
cp $(EMPTYDISK) plasma_hgr.dsk
$(DOS33) -y plasma_hgr.dsk SAVE A HELLO
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OVAL
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 PURPLE_WAVES
###
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
###
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
###
PURPLE_WAVES: purple_waves.o
ld65 -o PURPLE_WAVES purple_waves.o -C $(LINKERSCRIPTS)/apple2_c00.inc
purple_waves.o: purple_waves.s
ca65 -o purple_waves.o purple_waves.s -l purple_waves.lst
###
clean:
rm -f *~ *.o *.lst OVAL PURPLE_WAVES

View File

@ -0,0 +1,103 @@
;; HARDWARE LOCATIONS
KEYPRESS = $C000
KEYRESET = $C010
;; SOFT SWITCHES
CLR80COL = $C000 ; PAGE0/PAGE1 normal
SET80COL = $C001 ; PAGE0/PAGE1 switches PAGE0 in Aux instead
EIGHTYCOLOFF = $C00C
EIGHTYCOLON = $C00D
TBCOLOR = $C022 ; IIgs text foreground / background colors
NEWVIDEO = $C029 ; IIgs graphics modes
SPEAKER = $C030
CLOCKCTL = $C034 ; bits 0-3 are IIgs border color
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
TEXTGR = $C053
PAGE0 = $C054
PAGE1 = $C055
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
AN3 = $C05E ; Annunciator 3
PADDLE_BUTTON0 = $C061
PADDLE_BUTTON1 = $C062
PADDL0 = $C064
PTRIG = $C070
;; BASIC ROUTINES
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/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A
ROM_TEXT2COPY = $F962 ;; iigs
SETTXT = $FB36
SETGR = $FB40
TABV = $FB5B ;; VTAB to A
ROM_MACHINEID = $FBB3 ;; iigs
BELL = $FBDD ;; ring the bell
BASCALC = $FBC1 ;;
VTAB = $FC22 ;; VTAB to CV
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
CROUT1 = $FD8B
SETINV = $FE80 ;; INVERSE
SETNORM = $FE84 ;; NORMAL
COUT = $FDED ;; output A to screen
COUT1 = $FDF0 ;; output A to screen
COLOR_BLACK = 0
COLOR_RED = 1
COLOR_DARKBLUE = 2
COLOR_PURPLE = 3
COLOR_DARKGREEN = 4
COLOR_GREY = 5
COLOR_MEDIUMBLUE = 6
COLOR_LIGHTBLUE = 7
COLOR_BROWN = 8
COLOR_ORANGE = 9
COLOR_GREY2 = 10
COLOR_PINK = 11
COLOR_LIGHTGREEN = 12
COLOR_YELLOW = 13
COLOR_AQUA = 14
COLOR_WHITE = 15
COLOR_BOTH_BLACK = $00
COLOR_BOTH_RED = $11
COLOR_BOTH_DARKBLUE = $22
COLOR_BOTH_DARKGREEN = $44
COLOR_BOTH_GREY = $55
COLOR_BOTH_MEDIUMBLUE = $66
COLOR_BOTH_LIGHTBLUE = $77
COLOR_BOTH_BROWN = $88
COLOR_BOTH_ORANGE = $99
COLOR_BOTH_PINK = $BB
COLOR_BOTH_LIGHTGREEN = $CC
COLOR_BOTH_YELLOW = $DD
COLOR_BOTH_AQUA = $EE
COLOR_BOTH_WHITE = $FF

View File

@ -0,0 +1,2 @@
5 HOME
10 PRINT CHR$(4);"CATALOG"

140
graphics/hgr/plasma/oval.s Normal file
View File

@ -0,0 +1,140 @@
; Ovals
; zero page
GBASL = $26
GBASH = $27
YY = $69
ROW_SUM = $70
HGR_X = $E0
HGR_XH = $E1
HGR_Y = $E2
HGR_COLOR = $E4
HGR_PAGE = $E6
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
HGR2 = $F3D8
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
;================================
; Clear screen and setup graphics
;================================
oval:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
draw_oval:
inc FRAME
ldx #191 ; YY
stx HGR_Y
create_yloop:
lda HGR_Y
ldx #39
ldy #0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
; restore values
ldy #39 ; XX
lda FRAME
sta SUM
lda HGR_Y ; YY
jsr calcsine_div2
ldx HGR_Y ; YY
sta ROW_SUM
create_xloop:
lda ROW_SUM
sta SUM
tya ; XX
jsr calcsine
lsr ; double colors
and #$7 ; mask
tax
lda colorlookup,X
sta SAVEY
tya
ror
bcc noshift
ror SAVEY
noshift:
lda SAVEY
; and #$7f
sta (GBASL),Y
dey
bpl create_xloop
dec HGR_Y
bne create_yloop
; X and Y both $FF
beq draw_oval
;==============================
; calcsine
;==============================
; looks up sine of value in A
; accumulates it with SUM
; returns result in A
; Y preserved
calcsine_div2:
lsr ; 2
calcsine:
and #$3f ; wrap sine at 63 entries ; 2
tax ; 2
rol ; 2
rol ; 2
rol ; 2
bcc sinadd ; 2/3
sinsub:
lda SUM ; 3
; sec
sbc sinetable-32,X ; 4+
jmp sindone ; 3
sinadd:
lda SUM ; 3
; clc
adc sinetable,X ; 4+
sindone:
rts ; 6
colorlookup:
.byte $11,$55,$5d,$7f,$5d,$55,$11 ; use 00 from sinetable
;.byte $00
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

View File

@ -0,0 +1,138 @@
; Ovals
; zero page
GBASL = $26
GBASH = $27
MASK = $2E
COLOR = $30
;CTEMP = $68
YY = $69
HGR_X = $E0
HGR_XH = $E1
HGR_Y = $E2
HGR_COLOR = $E4
HGR_PAGE = $E6
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
HGR2 = $F3D8
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
;================================
; Clear screen and setup graphics
;================================
oval:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
draw_oval:
inc FRAME
ldx #191 ; YY
create_yloop:
txa
ldx #39
ldy #0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
; restore values
ldx HGR_Y
ldy HGR_X
create_xloop:
lda FRAME
sta SUM
tya ; XX
jsr calcsine
txa ; YY
jsr calcsine_div2
lsr ; double colors
and #$7 ; mask
tax
lda colorlookup,X
sta SAVEY
tya
ror
bcc noshift
ror SAVEY
noshift:
lda SAVEY
and #$7f
sta (GBASL),Y
ldx SAVEX
dey
bpl create_xloop
dex
bne create_yloop
; X and Y both $FF
beq 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:
.byte $11,$55,$5d,$7f,$5d,$55,$11 ; use 00 from sinetable
;.byte $00
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

161
graphics/hgr/plasma/zp.inc Normal file
View File

@ -0,0 +1,161 @@
;; Zero page monitor routines addresses
;; LZSA addresses
NIBCOUNT = $00
HGRBITS = $1C
WNDLFT = $20
WNDWDTH = $21
WNDTOP = $22
WNDBTM = $23
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
H2 = $2C
V2 = $2D
MASK = $2E
COLOR = $30
INVFLG = $32
HGRPAGE = $E6
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related
;; Flying Routine Only
TURNING = $60
;SCREEN_X = $61 ; not used?
SCREEN_Y = $62
ANGLE = $63
HORIZ_SCALE_I = $64
HORIZ_SCALE_F = $65
SCALE_I = $64
SCALE_F = $65
FACTOR_I = $66
FACTOR_F = $67
DX_I = $68
DX_F = $69
SPACEX_I = $6A
SPACEX_F = $6B
CX_I = $6C
CX_F = $6D
DY_I = $6E
DY_F = $6F
SPACEY_I = $70
SPACEY_F = $71
CY_I = $72
CY_F = $73
TEMP_I = $74
TEMP_F = $75
DISTANCE_I = $76
DISTANCE_F = $77
SPACEZ_I = $78
SPACEZ_F = $79
DRAW_SPLASH = $7A
SPEED = $7B
SPLASH_COUNT = $7C
OVER_LAND = $7D
NUM1L = $7E
NUM1H = $7F
NUM2L = $80
NUM2H = $81
RESULT = $82 ; 83,84,85
NEGATE = $86 ; UNUSED?
LAST_SPACEX_I = $87
LAST_SPACEY_I = $88
LAST_MAP_COLOR = $89
COLOR_MASK = $8A
;; World Map Only
ODD = $7B
DIRECTION = $7C
REFRESH = $7D
ON_BIRD = $7E
MOVED = $7F
STEPS = $80
TFV_X = $81
TFV_Y = $82
NEWX = $83
NEWY = $84
MAP_X = $85
GROUND_COLOR = $86
LEVEL_OVER = $A0
JOYSTICK_ENABLED= $A1
FRAMEL = $A2
FRAMEH = $A3
WHICH_LOAD = $A4
MENU_RESULT = $A5
SOUND_STATUS = $A6
SOUND_DISABLED = $80
SOUND_IN_LC = $01 ; $01 sound effects in language card
SOUND_MOCKINGBOARD = $02 ; mockingboard detected
JS_BUTTON_STATE = $A7
COLOR1 = $E0
COLOR2 = $E1
MATCH = $E2
XX = $E3
YY = $E4
SHIPY = $E4
YADD = $E5
LOOP = $E6
;MEMPTRL = $E7
;MEMPTRH = $E8
NAMEL = $E9
NAMEH = $EA
NAMEX = $EB
CHAR = $EC
DISP_PAGE = $ED
DRAW_PAGE = $EE
FIRST = $F0
LASTKEY = $F1
PADDLE_STATUS = $F2
XPOS = $F3
YPOS = $F4
TEMP = $FA
RUN = $FA
TEMP2 = $FB
TEMPY = $FB
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assemble with ca65 -- vmw
; added code to patch it to run from current disk slot -- vmw
adrlo = $26 ; constant from boot prom
adrhi = $27 ; constant from boot prom
tmpsec = $3c ; constant from boot prom
reqsec = $3d ; constant from boot prom
sizelo = $44
sizehi = $45
secsize = $46
ldsizel = $70
ldsizeh = $71
namlo = $7b
namhi = $7c
step = $7d ; state for stepper motor
tmptrk = $7e ; temporary copy of current track
phase = $7f ; current phase for /seek

View File

@ -6,7 +6,8 @@ SDL_LIBS= `sdl-config --libs`
SDL_INCLUDE= `sdl-config --cflags`
GR_SIM = ../gr-sim.a
all: fireworks fw_purple lines image_load hgr_view seven random16 scroll scroll-asm
all: fireworks fw_purple lines image_load hgr_view seven \
random16 scroll scroll-asm plasma_new
###
@ -42,6 +43,14 @@ fireworks.o: fireworks.c
###
plasma_new: plasma_new.o $(GR_SIM)
$(CC) -o plasma_new plasma_new.o $(GR_SIM) $(LFLAGS) $(SDL_LIBS)
plasma_new.o: plasma_new.c
$(CC) $(CFLAGS) -c plasma_new.c
###
fw_purple: fw_purple.o $(GR_SIM)
$(CC) -o fw_purple fw_purple.o $(GR_SIM) $(LFLAGS) $(SDL_LIBS)

View File

@ -0,0 +1,147 @@
/* for demoscene, you need a plasma effect... */
/* https://rosettacode.org/wiki/Plasma_effect */
/* https://www.bidouille.org/prog/plasma */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "tfv_zp.h"
#include "gr-sim.h"
#define PI 3.14159265358979323846264338327950
int sine_lookup[64];
#if 1
static unsigned char color_lookup[]={0x0, 0x0, 0x1, 0x1,
0x2, 0x2, 0x3, 0x3,
0x4, 0x4, 0x5, 0x5,
0x6, 0x6, 0x7, 0x7};
#else
static unsigned char color_lookup[]={0x0, 0x0, 0x0, 0x1,
0x1, 0x1, 0x2, 0x2,
0x2, 0x3, 0x3, 0x3,
0x2, 0x2, 0x1, 0x1};
#endif
static int offscreen[40][192];
int main(int argc, char **argv) {
int ch,xx,yy,col;
grsim_init();
home();
hgr();
soft_switch(MIXCLR);
clear_screens();
ram[DRAW_PAGE]=0x0;
for(xx=0;xx<64;xx++) {
sine_lookup[xx]=32.0*sin( (xx*2*PI)/64);
}
for(yy=0;yy<192;yy++) {
for(xx=0;xx<40;xx++) {
// col = ( 32.0 + (32.0 * sin(xx / 4.0))
// + 32.0 + (32.0 * sin(yy / 4.0))
// ) / 2;
// col = ( 8.0 + (8.0 * sin(xx *PI/8.0))
// + 8.0 + (8.0 * sin(yy *PI/8.0))
// ) / 2;
#if 0
col = (int)
(
128.0 + (128.0 * sin(xx / 16.0))
+ 128.0 + (128.0 * sin(yy / 8.0))
+ 128.0 + (128.0 * sin((xx + yy) / 16.0))
+ 128.0 + (128.0 * sin(sqrt( (double)(xx * xx + yy * yy)) / 8.0))
) / 4;
//#else
col = (int)
((
4.0 + sin(xx / 16.0)
+ sin(yy / 8.0)
+ sin((xx + yy) / 16.0)
// + sin(sqrt(xx * xx + yy * yy) / 8.0)
)*32) ;
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
#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 + sine_lookup[ (int)(xx/1)&0x1f ]
+ sine_lookup[ (int)(yy/2)&0x3f ]
// + sine_lookup[ (int)((xx + yy)/8)&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
offscreen[xx][yy]=col;
}
}
int offset=0;
while(1) {
for(yy=0;yy<192;yy++) {
for(xx=0;xx<40;xx++) {
col=offscreen[xx][yy];
col+=offset;
// col&=0x7;
// offscreen[xx][yy]=col;
// plot(xx,yy);
// printf("color=%d\n",col);
// hcolor_equals(col);
hcolor_equals(color_lookup[col&0xf]);
hplot(xx*7,yy);
hplot_to((xx*7)+6,yy);
}
}
offset++;
grsim_update();
ch=grsim_input();
if (ch=='q') exit(0);
if (ch==' ') {
while(1) {
ch=grsim_input();
if (ch) break;
}
}
usleep(200000);
}
return 0;
}

View File

@ -0,0 +1,147 @@
/* for demoscene, you need a plasma effect... */
/* https://rosettacode.org/wiki/Plasma_effect */
/* https://www.bidouille.org/prog/plasma */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "tfv_zp.h"
#include "gr-sim.h"
#define PI 3.14159265358979323846264338327950
int sine_lookup[64];
#if 0
static unsigned char color_lookup[]={0x0, 0x0, 0x1, 0x1,
0x2, 0x2, 0x3, 0x3,
0x4, 0x4, 0x5, 0x5,
0x6, 0x6, 0x7, 0x7};
#else
static unsigned char color_lookup[]={0x0, 0x0, 0x0, 0x1,
0x1, 0x1, 0x2, 0x2,
0x2, 0x3, 0x3, 0x3,
0x2, 0x2, 0x1, 0x1};
#endif
static int offscreen[40][192];
int main(int argc, char **argv) {
int ch,xx,yy,col;
grsim_init();
home();
hgr();
soft_switch(MIXCLR);
clear_screens();
ram[DRAW_PAGE]=0x0;
for(xx=0;xx<64;xx++) {
sine_lookup[xx]=32.0*sin( (xx*2*PI)/64);
}
for(yy=0;yy<192;yy++) {
for(xx=0;xx<40;xx++) {
// col = ( 32.0 + (32.0 * sin(xx / 4.0))
// + 32.0 + (32.0 * sin(yy / 4.0))
// ) / 2;
// col = ( 8.0 + (8.0 * sin(xx *PI/8.0))
// + 8.0 + (8.0 * sin(yy *PI/8.0))
// ) / 2;
#if 0
col = (int)
(
128.0 + (128.0 * sin(xx / 16.0))
+ 128.0 + (128.0 * sin(yy / 8.0))
+ 128.0 + (128.0 * sin((xx + yy) / 16.0))
+ 128.0 + (128.0 * sin(sqrt( (double)(xx * xx + yy * yy)) / 8.0))
) / 4;
//#else
col = (int)
((
4.0 + sin(xx / 16.0)
+ sin(yy / 8.0)
+ sin((xx + yy) / 16.0)
// + sin(sqrt(xx * xx + yy * yy) / 8.0)
)*32) ;
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
#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 + sine_lookup[ (int)(xx/1)&0x3f ]
+ sine_lookup[ (int)(yy/2)&0x3f ]
// + sine_lookup[ (int)((xx + yy)/4)&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
offscreen[xx][yy]=col;
}
}
int offset=0;
while(1) {
for(yy=0;yy<192;yy++) {
for(xx=0;xx<40;xx++) {
col=offscreen[xx][yy];
col+=offset;
// col&=0x7;
// offscreen[xx][yy]=col;
// plot(xx,yy);
// printf("color=%d\n",col);
// hcolor_equals(col);
hcolor_equals(color_lookup[col&0xf]);
hplot(xx*7,yy);
hplot_to((xx*7)+6,yy);
}
}
offset++;
grsim_update();
ch=grsim_input();
if (ch=='q') exit(0);
if (ch==' ') {
while(1) {
ch=grsim_input();
if (ch) break;
}
}
usleep(200000);
}
return 0;
}