/*
** Fade Demo
** ---------
** There are three examples of fading in this program:  Fade_To_White,
** Fade_To_Palette, and Fade_To_Black.
**
** Fade_To_Palette is called as soon as you run the executable, then you
** have to press the Left Mouse Button to see the rest of the fade sequence.
**
** Compiles under SAS/C and DICE.
*/

#include <exec/memory.h>
#include <proto/games.h>
#include <proto/exec.h>

struct GMSBase *GMSBase;
extern struct ExecBase *SysBase;

#define AMT_PLANES 5

UWORD  Palette[] = {
       0x000,0x130,0xFCB,0xFA9,0xD88,0x965,0x644,0x211,
       0x400,0x444,0xFF0,0x432,0xCC0,0x150,0x501,0x880,
       0x261,0x271,0x382,0x492,0x5A3,0x5B4,0x677,0x6C4,
       0x788,0x9AA,0xBCC,0x801,0x901,0xA02,0x701,0x601
       };

struct GameScreen GameScreen = {
       GSV1,                /* Structure version */
       0,0,0,               /* Screen_Mem1,2,3 */
       0,                   /* ScreenLink */
       0,                   /* Adress of palette */
       0,                   /* Address of rasterlist */
       0,                   /* Amount of colours */
       320,256,             /* Screen Width and Height */
       320/8,256,           /* Picture Width/8 and Height */
       AMT_PLANES,          /* Amount of bitplanes */
       0,0,                 /* X/Y screen offset */
       0,0,                 /* X/Y picture offset */
       0,                   /* Special attributes */
       LORES|COL12BIT,      /* Screen mode */
       INTERLEAVED,         /* Screen type */
       0                    /* Reserved */
       };

struct Picture Picture = {
       PCV1,                /* Version header */
       0,                   /* Destination */
       320/8,256,           /* Width, Height */
       AMT_PLANES,          /* Amount of Planes */
       32,                  /* Amount of colours */
       &Palette,            /* Palette (remap) */
       LORES|COL12BIT,      /* Screen mode */
       INTERLEAVED,         /* Destination */
       0,                   /* Parameters */
       "GAMESLIB:data/IFF.Pic320"
       };

struct GameScreen *OurScreen = &GameScreen;
struct Picture *LoadingPic = &Picture;

/*=========================================================================*/

void main(void)
{
   UWORD FState = 0;

   GMSBase = (struct GMSBase *) OpenLibrary("games.library", 0);

   SetUserPrefs(0);

   if (Add_Screen(OurScreen) == NULL) {

      LoadingPic->Data = OurScreen->MemPtr1;
      if (LoadPic(LoadingPic) == NULL) {
         Show_Screen(OurScreen);

         do { Wait_VBL();
              Wait_OSVBL();            
              FState = ColourToPalette(OurScreen,FState,1,0,32,&Palette,0x000);
            }
         while (FState != NULL);

         Wait_LMB();

         do { Wait_OSVBL();
              Wait_VBL();
              FState = PaletteToColour(OurScreen,FState,1,0,32,&Palette,0xFFF);
            }
         while (FState != NULL);

         Wait_Time(30);

         do { Wait_OSVBL();
              Wait_VBL();
              FState = ColourMorph(OurScreen,FState,1,0,32,0xFFF,0x000);
            }
         while (FState != NULL);

         Wait_Time(30);
      }
      Delete_Screen(OurScreen);
   }
   CloseLibrary((struct Library *)GMSBase);
}

