/*
** AGA WhiteFade Demo
** ------------------
** There are three examples of fading in this program:  ColourMorph,
** ColourToPalette, and PaletteToColour.
**
** FadeToWhite is called as soon as you run the executable, then it fades
** to the palette and then to black.
**
** 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

struct GameScreen GameScreen = {
       GSV1,                /* Structure version */
       0,0,0,               /* Screen_Mem1,2,3 */
       0,                   /* ScreenLink */
       0,                   /* Adress of palette */
       0,                   /* Address of rasterlist */
       32,                  /* 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|COL24BIT,      /* 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 */
       0,                   /* Palette (remap) */
       LORES|COL24BIT,      /* Screen mode */
       INTERLEAVED,         /* Destination */
       GETPALETTE,          /* Parameters */
       "GAMESLIB:data/IFF.Loading"
       };

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

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

void main(void)
{
   UWORD FadeState = 0;

   if (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_OSVBL();
                 FadeState = ColourMorph(OurScreen,FadeState,10,0,32,0x000000,0xFFFFFF);
            } while (FadeState != NULL);

            do { Wait_OSVBL();
                 FadeState = ColourToPalette(OurScreen,FadeState,2,0,32,LoadingPic->Palette,0xFFFFFF);
            } while (FadeState != NULL);

            do { Wait_OSVBL();
                 FadeState = PaletteToColour(OurScreen,FadeState,2,0,32,LoadingPic->Palette,0x000000);
            } while (FadeState != NULL);

            FreePic(LoadingPic);
         }
      Delete_Screen(OurScreen);
      }
   CloseLibrary((struct Library *)GMSBase);
   }
}

