Make your own free website on Tripod.com

Plasma.

Prev || Home

bar.gif (11170 bytes)

/*
** This code is a pure DJGPP C ( not difficult to port ), with no Assembly based
** implementation of plasma special effect.
**
** Routine by KR Ranjith ( krranjith@crosswinds.net )
*/

#include <dos.h>
#include <pc.h>
#include <math.h>
#include <sys/nearptr.h>

/* Set RGB values for a color */

void setrgb( unsigned char col,
    unsigned char R,
    unsigned char G,
    unsigned char B )
{
outportb(0x3C8,col);
outportb(0x3C9,R);
outportb(0x3C9,G);
outportb(0x3C9,B);
}

int main()
{
unsigned char *scr;
unsigned char *vscr, *tscr; /* Video buffer for speed */
union REGS s;
int costbl[256];
int t,y,x;
unsigned char a1,a2,a3,a4,
b1,b2,b3,b4;

__djgpp_nearptr_enable();

scr = __djgpp_conventional_base + (unsigned char*) 0xA0000; /* Screen */

vscr = (unsigned char*)malloc(320*200);

if( !vscr )
{
printf("Not enough memory");
return(0);
}

/* Start with a clean screen */

memset(vscr,0,320*200);

/* Initialize cos table */

for(t=0;t<256;t++)
costbl[t] = (int)( 27 * cos(t * (3.14159/128) ) );

/* Start 320*200 graphics mode */

s.w.ax = 0x13;
int386(0x10,&s,&s);


/* Set up a gradient like palette */

for (x=1; x<=32; x++) {
setrgb(x, 0, 0, x*2-1); /* Blue part */
setrgb(x+32, x*2-1, 0, 63);
setrgb(x+64, 63, x*2-1, 63);
setrgb(x+96, 63, 63, 63);

setrgb(x+128, 63, 63, 63);
setrgb(x+160, 63, 63, 63-(x*2-1));
setrgb(x+192, 63, 63-(x*2-1), 0);
setrgb(x+224, 63-(x*2-1), 0, 0); /* Red part */

}


/* Loop until key is pressed */

while( !kbhit() ){

a1 = b1;
a2 = b2;

    /* tscr for *tscr++, rather than *(vscr+(y*320)+x) */

    tscr = vscr;

for(y=0;y<200;y++)
{

a3 = b3;
a4 = b4;

for(x=0;x<320;x++)
{
*tscr++ = costbl[a1] +
costbl[a2] +
costbl[a3] +
costbl[a4] ;

/* Higher values result in many slower plasmas */

a3 += 1;
a4 += 2;
}

/* Same as the previous comment*/

a1 += 1;
a2 += 2;

}

/* The higher these vars are incremented, the faster is
** the plasma. Need'nt be similar. */

b1 += 3;
b2 -= 5;
b3 -= 3;
b4 += 2;

    /* retrace sync */
while( inportb(0x3Da) & 0x8 );
while( ! (inportb(0x3Da) & 0x8) );
       
/* Blit plasmas unto screen */
memcpy(scr,vscr,320*200);

}

getch();

/* Get back to text mode */

s.w.ax = 0x3;
int386(0x10,&s,&s);

    __djgpp_nearptr_disable();

return(0);
}

bar.gif (11170 bytes)