home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
aga_software
/
plasma
/
plasma_256.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-06
|
19KB
|
745 lines
/*************************************************
/*
/* Plasma Cloud Generator 256 Color Version
/* AGA only (a4000/A1200 et al) uses 320X400 or 640X400
/* for HIRES run from CLI and type Plasma_256 HIRES
/* if run with no args, or from WB it will be lo-res
/* 256 color displays with 24 bit palette.
/* This code © 1992 by W. Roger uzun
/* This code is for SAS/C 6.0x
/* First assemble FastPix.asm by using SAS/C asm
/* use smallcode and smalldata for models
/* To Color Cycle Press C, press space to quit color cycle
/* and restore palette to original, any other key keeps
/* current palette.
/*
/*************************************************/
#define FASTER 1
long __OSlibversion = 39;
#define HEIGHT 400L
#define DEPTH 8
int WIDTH=320L;
#define VIEW_MODES (LACE)
#define NUM_COLORS 256
#define CPU020 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <proto/exec.h>
#ifdef CPU020
#include <exec/execbase.h>
#endif
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <time.h>
#include <proto/dos.h>
int rowoffset=(320L/8);
#define MODULUS (0x20000L)
#define C 13849
#define A 25173
#define randu2(x) (((seed = seed*A+C))%(x))
#ifdef LATTICE
#define PROTOTYPES 1
#endif
#ifndef LATTICE
#define __regargs
#endif
#ifdef DEBUG
int temparray[64];
#endif
#define WINDOWSIGNAL (1L<<(wG->UserPort->mp_SigBit))
#define PaletteColorCount 32
short __aligned nplanes = DEPTH;
UBYTE __aligned *bp[DEPTH];
short __aligned ytable[HEIGHT];
struct TextFont __aligned *myTextFont;
struct RastPort __aligned *rpG;
struct TextAttr TOPAZ80 = {
(STRPTR)"topaz.font",
TOPAZ_EIGHTY,0,0
};
struct NewScreen NewScreenStructure = {
0,0, /* screen XY origin relative to View */
320L,HEIGHT, /* screen width and height */
DEPTH, /* screen depth (number of bitplanes) */
0,1, /* detail and block pens */
VIEW_MODES, /* display modes for this screen */
CUSTOMSCREEN, /* screen type */
&TOPAZ80, /* pointer to default screen font */
"Plasma 256", /* screen title */
NULL, /* first in list of custom screen gadgets */
NULL /* pointer to custom BitMap structure */
};
#define NEWSCREENSTRUCTURE NewScreenStructure
struct PalletteEntry {
ULONG red,green,blue;
};
struct PalletteEntry Red = {0xff,0,0};
struct PalletteEntry Green = {0,0xff,0};
struct PalletteEntry Blue = {0,0,0xff};
#define SCALE8TO32(x) ((x)|((x)<<8)|((x)<<16)|((x)<<24))
ULONG BigColorPalette[256*3+2]={256<<16 /* this says load 256 colors */ +
0, /* start at color register 0 */
0x0, /* red for color 0 */
0x0, /* green for color 0 */
0x0, /* blue for color 0, color 0 is Black */
0xffffffff,
0xffffffff,
0xffffffff /* color 1 is white */
};
USHORT __aligned Palette[] = {
0x000, /* color #0 */
0x0a5, /* color #6 */
0x0b4, /* color #7 */
0x0c3, /* color #8 */
0x0e1, /* color #9 */
0x0f0, /* color #10 */
0x01f0, /* color #11 */
0x03d0, /* color #12 */
0x05b0, /* color #13 */
0x0790, /* color #14 */
0x0970, /* color #15 */
0x0a50, /* color #16 */
0x0B40, /* color #17 */
0x0c30, /* color #18 */
0x0e10, /* color #19 */
0x0f00, /* color #20 */
0x0f01, /* color #21 */
0x0d03, /* color #22 */
0x0b05, /* color #23 */
0x0907, /* color #24 */
0x0709, /* color #25 */
0x050a, /* color #26 */
0x040b, /* color #27 */
0x030c, /* color #28 */
0x020d, /* color #29 */
0x010e, /* color #30 */
0x000f, /* color #31 */
0x01f, /* color #1 */
0x03d, /* color #2 */
0x05b, /* color #3 */
0x079, /* color #4 */
0x097 /* color #5 */
};
#define PALETTE Palette
struct IntuiText IText1 = {
3,1,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&TOPAZ80, /* font pointer or NULL for default */
"Quit", /* pointer to text */
NULL /* next IntuiText structure */
};
struct MenuItem MenuItem2 = {
NULL, /* next MenuItem structure */
0,8, /* XY of Item hitbox relative to TopLeft of parent hitbox */
80,8, /* hit box width and height */
ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP, /* Item flags */
0, /* each bit mutually-excludes a same-level Item */
(APTR)&IText1, /* Item render (IntuiText or Image or NULL) */
NULL, /* Select render */
'Q', /* alternate command-key */
NULL, /* SubItem list */
MENUNULL /* filled in by Intuition for drag selections */
};
struct IntuiText IText2 = {
3,1,JAM1, /* front and back text pens, drawmode and fill byte */
0,0, /* XY origin relative to container TopLeft */
&TOPAZ80, /* font pointer or NULL for default */
"About", /* pointer to text */
NULL /* next IntuiText structure */
};
struct MenuItem MenuItem1 = {
&MenuItem2, /* next MenuItem structure */
0,0, /* XY of Item hitbox relative to TopLeft of parent hitbox */
80,8, /* hit box width and height */
ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP, /* Item flags */
0, /* each bit mutually-excludes a same-level Item */
(APTR)&IText2, /* Item render (IntuiText or Image or NULL) */
NULL, /* Select render */
'A', /* alternate command-key */
NULL, /* SubItem list */
MENUNULL /* filled in by Intuition for drag selections */
};
struct Menu Menu1 = {
NULL, /* next Menu structure */
0,0, /* XY origin of Menu hit box relative to screen TopLeft */
63,0, /* Menu hit box width and height */
MENUENABLED, /* Menu flags */
"Project", /* text of Menu name */
&MenuItem1 /* MenuItem linked list pointer */
};
#define MenuList1 Menu1
struct NewWindow NewWindowStructure1 = {
0,0, /* window XY origin relative to TopLeft of screen */
320L,HEIGHT, /* window width and height */
4,8, /* detail and block pens */
VANILLAKEY|MENUPICK, /* IDCMP flags */
SMART_REFRESH+BACKDROP+BORDERLESS+ACTIVATE, /* other window flags */
NULL, /* first gadget in gadget list */
NULL, /* custom CHECKMARK imagery */
" ", /* window title */
NULL, /* custom screen pointer */
NULL, /* custom bitmap */
5,5, /* minimum width and height */
0xffff,0xffff, /* maximum width and height */
CUSTOMSCREEN /* destination screen type */
};
SHORT BorderVectors1[] = {
0,0,
51,0,
51,41,
0,41,
0,0
};
struct Border Border1 = {
-1,-1, /* XY origin relative to container TopLeft */
3,0,JAM1, /* front pen, back pen and drawmode */
5, /* number of XY vectors */
BorderVectors1, /* pointer to XY vectors */
NULL /* next border in list */
};
struct IntuiText IText3 = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
15,17, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"OK", /* pointer to text */
NULL /* next IntuiText structure */
};
struct Gadget Gadget1 = {
NULL, /* next gadget */
65,217, /* origin XY of hit box relative to window TopLeft */
50,40, /* hit box width and height */
NULL, /* gadget flags */
RELVERIFY, /* activation flags */
BOOLGADGET, /* gadget type flags */
(APTR)&Border1, /* gadget border or image to be rendered */
NULL, /* alternate imagery for selection */
&IText3, /* first IntuiText structure */
NULL, /* gadget mutual-exclude long word */
NULL, /* SpecialInfo structure */
NULL, /* user-definable data */
NULL /* pointer to user-definable data */
};
#define GadgetList2 Gadget1
struct IntuiText IText5 = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
40,114, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"By Roger Uzun", /* pointer to text */
NULL /* next IntuiText structure */
};
struct IntuiText IText4a = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
16,61, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"Press 'C' to Cycle", /* pointer to text */
&IText5 /* next IntuiText structure */
};
#ifndef CPU020
struct IntuiText IText4 = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
6,21, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"Plasma 256 Ver 0.0", /* pointer to text */
&IText4a /* next IntuiText structure */
};
#else
struct IntuiText IText4c = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
35,41, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"68020 Edition", /* pointer to text */
&IText4a /* next IntuiText structure */
};
struct IntuiText IText4 = {
3,0,JAM2, /* front and back text pens, drawmode and fill byte */
6,21, /* XY origin relative to container TopLeft */
NULL, /* font pointer or NULL for default */
"Plasma 256 Ver 0.0", /* pointer to text */
&IText4c /* next IntuiText structure */
};
#endif
struct NewWindow NewWindowStructure3 = {
70,30, /* window XY origin relative to TopLeft of screen */
180,280, /* window width and height */
0,1, /* detail and block pens */
GADGETUP, /* IDCMP flags */
SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH, /* other window flags */
&Gadget1, /* first gadget in gadget list */
NULL, /* custom CHECKMARK imagery */
" ", /* window title */
NULL, /* custom screen pointer */
NULL, /* custom bitmap */
5,5, /* minimum width and height */
0xffff,0xffff, /* maximum width and height */
CUSTOMSCREEN /* destination screen type */
};
struct Screen __aligned *sC;
struct Window __aligned *wG;
UWORD __aligned done=0;
unsigned short __aligned seed = 7;
#ifdef PROTOTYPES
#ifdef FASTER
int __regargs ReadPix(long,long);
void __regargs FastPix(long,long,long);
#endif
void CycleColors(void);
void __regargs HandleEvent(APTR);
void DoAbout(void);
void DoQuit(void);
void __regargs SubDivide(long,long,long,long);
void __regargs adjust(long,long,long,long,long,long);
#endif
ULONG tpal[256*3+2];
void CycleColors()
{
long __aligned code;
ULONG __aligned class;
UWORD __aligned d=0,i;
ULONG temp[3];
struct IntuiMessage __aligned *message;
for(i=0;i<(256*3+2);i++)
{
tpal[i] = BigColorPalette[i];
}
while (!d)
{
temp[0] = tpal[4];
temp[1] = tpal[5];
temp[2] = tpal[6];
for(i=2;i<256;i++)
{
tpal[(i-1)*3+1] = tpal[i*3+1];
tpal[(i-1)*3+2] = tpal[i*3+2];
tpal[(i-1)*3+3] = tpal[i*3+3];
}
tpal[255*3] = temp[0];
tpal[255*3+1] = temp[1];
tpal[255*3+2] = temp[2];
LoadRGB32(&(sC->ViewPort),tpal);
Delay(1L);
if ( (message = (struct IntuiMessage *)
GetMsg(wG->UserPort) ))
{
class = message->Class;
code = message->Code;
ReplyMsg((struct Message *)message);
if (class = VANILLAKEY)
d = 1;
}
}
if (code == ' ')
LoadRGB32(&(sC->ViewPort),BigColorPalette);
}
void __regargs adjust(xa,ya,x,y,xb,yb)
long xa,ya,x,y,xb,yb;
{
long __aligned t1,t2;
int __aligned pa,pb,pc,pd;
register long __aligned globalcolor;
#ifdef FASTER
if (ReadPix(x,y))
return;
#else
if (ReadPixel(rpG,x,y))
return;
#endif
pa = xa;
pb =xb;
pc = ya;
pd = yb;
globalcolor = randu2(3) * (abs(pa-pb)+abs(pc-pd));
#ifdef FASTER
t1 = (ReadPix(xa,ya));
t2 = (ReadPix(xb,yb));
#else
t1 = (ReadPixel(rpG,xa,ya));
t2 = (ReadPixel(rpG,xb,yb));
#endif
if (!randu2(2))
{
globalcolor = -globalcolor;
}
globalcolor = ((t1+t2)>>1)+globalcolor;
globalcolor &= 0xffL;
#ifdef FASTER
FastPix(x,y,globalcolor);
#else
SetAPen(rpG,globalcolor);
WritePixel(rpG,x,y);
#endif
#ifdef DEBUG
temparray[globalcolor]++;
#endif
}
void __regargs SubDivide(x1,y1,x2,y2)
long x1,y1,x2,y2;
{
long __aligned t1,t2,t3,t4;
ULONG __aligned signals,v;
struct IntuiMessage __aligned *message;
long __aligned x,y,class,code;
APTR __aligned object;
UWORD __aligned d;
if (((x2-x1)<2L) && ((y2-y1)<2L))
return;
if ( (message = (struct IntuiMessage *)
GetMsg(wG->UserPort) ))
{
class = message->Class;
code = message->Code;
object = message->IAddress; /* Gadget */
ReplyMsg((struct Message *)message);
if ( class == MENUPICK ) /* MenuItems */
HandleEvent((APTR)ItemAddress(&MenuList1,code));
else if (class = VANILLAKEY)
{
if ((code == 'c')||(code == 'C'))
{
CycleColors();
}
else
{
d = 0;
while(!d)
{
signals = Wait(WINDOWSIGNAL);
if (signals & WINDOWSIGNAL)
while ((message = (struct IntuiMessage *)
GetMsg(wG->UserPort)))
{
class = message->Class;
ReplyMsg((struct Message *)message);
if (class == VANILLAKEY)
d = 1;
}
}
}
}
}
if (done)
return;
x = (x1+x2)>>1;
y = (y1+y2)>>1;
#ifdef FASTER
if (!ReadPix(x,y))
{
t1 = (ReadPix(x1,y1));
t2 = (ReadPix(x2,y1));
t3 = (ReadPix(x2,y2));
t4 = (ReadPix(x1,y2));
#else
if (!ReadPixel(rpG,x,y))
{
t1 = (ReadPixel(rpG,x1,y1));
t2 = (ReadPixel(rpG,x2,y1));
t3 = (ReadPixel(rpG,x2,y2));
t4 = (ReadPixel(rpG,x1,y2));
#endif
v = ((t1+t2+t3+t4)>>2);
#ifdef FASTER
FastPix(x,y,v);
#else
SetAPen(rpG,v);
WritePixel(rpG,x,y);
#endif
}
adjust(x1,y1,x,y1,x2,y1);
adjust(x2,y1,x2,y,x2,y2);
adjust(x1,y2,x,y2,x2,y2);
adjust(x1,y1,x1,y,x1,y2);
SubDivide(x1,y1,x,y);
SubDivide(x,y1,x2,y);
SubDivide(x,y,x2,y2);
SubDivide(x1,y,x,y2);
}
void DoAbout()
{
struct IntuiMessage __aligned *message;
struct Window __aligned *wG3;
if (!(wG3 = OpenWindow(&NewWindowStructure3)))
{
DisplayBeep(0L);
return;
}
PrintIText(wG3->RPort,&IText4,0L,0L);
WaitPort(wG3->UserPort);
while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
ReplyMsg((struct Message *)message);
CloseWindow(wG3);
}
void __regargs HandleEvent(object)
APTR object;
{
if (object == (APTR)&MenuItem1) { DoAbout(); return; }
if (object == (APTR)&MenuItem2) { DoQuit(); return; }
}
#define HANDLEEVENT HandleEvent
/* end of PowerWindows source generation */
void DoQuit()
{
done = TRUE;
}
/* end of PowerWindows source generation */
void main(int,char **);
void main(argc,argv)
int argc;
char *argv[];
{
int __aligned j;
int __aligned i;
#ifdef DEBUG
int __aligned d;
#endif
ULONG __aligned code;
ULONG __aligned class;
APTR __aligned object;
ULONG __aligned signals;
struct IntuiMessage __aligned *message; /* the message the IDCMP sends us */
#ifdef CPU020
struct ExecBase **execbaseptr=(struct ExecBase **)4L;
UWORD cpuid;
struct ExecBase *execbase;
if (argc > 1)
{ /* hires */
NewScreenStructure.Width = 640;
NewScreenStructure.ViewModes = LACE|HIRES;
WIDTH = 640;
NewWindowStructure1.Width = 640;
}
execbase = *execbaseptr;
cpuid = execbase->AttnFlags;
if (!(cpuid & AFF_68020))
{
exit(0);
}
#endif
rowoffset=(WIDTH/8);
nplanes = DEPTH - 1;
/* We want Blues, Greens then reds in our palette */
for(i=1,j=4;i<85;i++,j+=3)
{
BigColorPalette[j] = (i*Green.red + (86-i)*Blue.red)/85;
BigColorPalette[j+1] = (i*Green.green+ (86-i)*Blue.green)/85;
BigColorPalette[j+2] = (i*Green.blue + (86-i)*Blue.blue)/85;
BigColorPalette[j+85*3] = (i*Red.red + (86-i)*Green.red)/85;
BigColorPalette[j+85*3+1] = (i*Red.green+ (86-i)*Green.green)/85;
BigColorPalette[j+85*3+2] = (i*Red.blue + (86-i)*Green.blue)/85;
BigColorPalette[j+170*3] = (i*Blue.red + (86-i)*Red.red)/85;
BigColorPalette[j+170*3+1] = (i*Blue.green+ (86-i)*Red.green)/85;
BigColorPalette[j+170*3+2] = (i*Blue.blue + (86-i)*Red.blue)/85;
}
BigColorPalette[85*3+1] = 0;
BigColorPalette[85*3+2] = 0xff;
BigColorPalette[85*3+3] = 3;
BigColorPalette[170*3+1] = 0xff;
BigColorPalette[170*3+2] = 0x3;
BigColorPalette[170*3+3] = 0;
BigColorPalette[255*3+1] = 3;
BigColorPalette[255*3+2] = 0x0;
BigColorPalette[255*3+3] = 0xff;
BigColorPalette[256*3+1] = 0L;
BigColorPalette[256*3+1] = 0L;
for(j=4;j<256*3+1;j++)
BigColorPalette[j] = SCALE8TO32(BigColorPalette[j]);
#ifdef DEBUG
for(d=0;d<64;d++)temparray[d] = 0;
#endif
#ifdef OLD_COMPILER
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 33L)))
{
exit(0);
}
if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L)))
{
#ifdef OLD_COMPILER
CloseLibrary((struct Library *)IntuitionBase);
#endif
exit(0);
}
#endif
if (!(myTextFont = OpenFont(&TOPAZ80)))
{
#ifdef OLD_COMPILER
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
#endif
exit(0);
}
if (!(sC = OpenScreen(&NewScreenStructure)))
{
CloseFont(myTextFont);
#ifdef OLD_COMPILER
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
#endif
exit(0);
}
LoadRGB32(&(sC->ViewPort),BigColorPalette);
NewWindowStructure3.Screen = NewWindowStructure1.Screen = sC;
wG = OpenWindow(&NewWindowStructure1); /* open the window */
if ( wG == NULL )
{
CloseScreen(sC);
CloseFont(myTextFont);
#ifdef OLD_COMPILER
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
#endif
exit(0);
}
rpG = wG->RPort; /* get a rastport pointer for the window */
SetFont(rpG,myTextFont);
SetMenuStrip(wG,&MenuList1); /* attach any Menu */
SetDrMd(rpG,JAM1);
for(i=0;i<DEPTH;i++)
bp[i] = wG->RPort->BitMap->Planes[i];
ytable[0] = 0;
for(i=1;i<HEIGHT;i++)
ytable[i] = ytable[i-1] + rowoffset;
#ifdef COLOR_DEBUG
for(i=0;i<256;i++)
{
SetAPen(rpG,i);
RectFill(rpG,30L,30L,60L,60L);
Delay(5L);
}
#endif
seed = time(0L);
signals = (randu2((NUM_COLORS-1))) + 1L;
#ifdef FASTER
FastPix(0L,11L,signals);
#else
SetAPen(rpG,signals);
WritePixel(rpG,0L,11L);
#endif
signals = (randu2((NUM_COLORS-1))) + 1L;
#ifdef FASTER
FastPix(WIDTH-1,11L,signals);
#else
SetAPen(rpG,signals);
WritePixel(rpG,WIDTH-1,11L);
#endif
signals = (randu2((NUM_COLORS-1))) + 1L;
#ifdef FASTER
FastPix(WIDTH-1,HEIGHT-1L,signals);
#else
SetAPen(rpG,signals);
WritePixel(rpG,WIDTH-1,HEIGHT-1L);
#endif
signals = (randu2((NUM_COLORS-1))) + 1L;
#ifdef FASTER
FastPix(0L,HEIGHT-1L,signals);
#else
SetAPen(rpG,signals);
WritePixel(rpG,0L,HEIGHT-1L);
#endif
SubDivide(0L,11L,WIDTH-1L,HEIGHT-1L);
DisplayBeep(0L);
while(!done)
{
signals = Wait(WINDOWSIGNAL);
if (signals & WINDOWSIGNAL)
while( (message = (struct IntuiMessage *)
GetMsg(wG->UserPort) ) != NULL)
{
class = message->Class;
code = message->Code;
object = message->IAddress; /* Gadget */
ReplyMsg((struct Message *)message);
if ( class == MENUPICK ) /* MenuItems */
HandleEvent((APTR)ItemAddress(&MenuList1,code));
else if (class = VANILLAKEY)
{
if ((code == 'c')||(code == 'C'))
{
CycleColors();
}
}
}
}
CloseWindow(wG);
CloseFont(myTextFont);
CloseScreen(sC);
#ifdef OLD_COMPILER
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
#endif
#ifdef DEBUG
for(d=0;d<64;d++)printf("temp[%d] = %d\n",d,temparray[d]);
#endif
}