/************************************************************************
 *                                                                      *
 *    PlasmDat.C     Generate palette, movement, random data file for   *
 *                         TomsPlas (Plasm3.ASM)                        *
 *                                                                      *
 ************************************************************************/

#define XDIM   320      /*  change if we change plasm3.asm  */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

/*****  Function Prototypes for C:\PLASDAT.C  *****/
void  main(void);


void  main(void)
   {
   signed int i;
   unsigned int rval;
   long unsigned count;
   int   lead,offset;
   FILE  *fp;

   printf("\nTom's Plasma Data Generation, (C) Tom Dibble 1994\n\n");

   if (!(fp=fopen("TOMSPLASM.DAT","wb")))
      {
      printf("\7Cant open output file TOMSPLASM.DAT\n");
      exit(-1);
      }

   /*  Arbitrary movement for two pointers  */
   /*  Size is 10000*4 = 40,000 bytes  */
   /*  These pointers are the offset from (0,0) on the main function
            from which each of the two overlaid screens is taken.
            The first term defines how the screen is moving horizontally,
            the second how it is moving vertically.  Make sure neither of
            these values is ever negative!  */
   /*  The 'offset' value has the 'lead' value subtracted from it.  I don't
            know why...  */
   /*  Finally, the numbers.  In the term '60+59*cos(...)', the cos()
            term varies between -1 and 1.  Therefore, the whole term
            varies between 1 and 119.  This means that the first
            pixel horizontally are never shown, but the other edge is
            never overrun either.  The 'y' term of this varies
            between 1 and 99.  The last five pixels vertically are
            never shown.  I don't know why this is.

            The numbers themselves ...  changing the numbers within
            the sin() and cos() functions will make the picture
            wobble more (with lower numbers) or less (higher
            numbers).

            Putting more of a difference in the two numbers will
            make the screen change more drastically with each
            update.

            */

   printf("\n\tGenerating Movement Pointers \t==========\b\b\b\b\b\b\b\b\b\b");
   for (count=0;count<10000;count++)
      {
      if(count%1000 == 999)
         printf(">");   /*  ten dots  */

      lead=           60+59.0*cos((double)count/32)
           +XDIM*(int)(50+49*sin((double)count/16));
      offset=         60+59.0*sin((double)count/21)
           +XDIM*(int)(50+49*cos((double)count/24))
           -lead;
      fwrite(&lead,2,1,fp);
      fwrite(&offset,2,1,fp);
      }

   /* And a smooth transition colour lookup table */
   /*  Size is (256*39 + 256)*3 =30,720 bytes  */
   /*  The first 256 colors are all black, so that we start with
            a blank screen and the glop oozes in.  The rest of the palette
            is cycled and cycled and cycled until we reach the end, then
            the screen blanks again and we start all over ...  */

   printf("\n\tGenerating Color Palette \t==========\b\b\b\b\b\b\b\b\b\b");
   for (i=0; i<256*4; i++)
      {
      if( (i%(102)) == (102)-1)  printf(">");

      fputc((sin((double)i/20)*sin((double)i/15)*31+31),fp);
      fputc((sin((double)i/35)*sin((double)i/22)*31+31),fp);
      fputc((sin((double)i/13)*sin((double)i/30)*31+31),fp);

      }

   /*  Finally, 64k of random numbers.  */
   randomize();
   printf("\n\tAnd now, Random Values \t\t==========\b\b\b\b\b\b\b\b\b\b");
   for (count=0; count < 0x8000 ; count++)
      {
      if( (count % 3276) == 3275)
         printf(">");   /*  ten dots  */
      rval=rand();
      fwrite(&rval,2,1,fp);
      }



   fclose(fp);
   printf("\nNow, that wasn't so bad ...  was it?\n");
   }

