/*
** AGA WhiteFade Demo
** ------------------
** There are three examples of fading in this program:  FadeToWhite,
** FadeToPalette, and FadeToBlack.
**
** FadeToWhite is called as soon as you run the executable, then it fades
** to the palette and then to black.
**
** Compiles under SAS/C
*/

#include <stdio.h>
#include <stdlib.h>

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

struct GMSBase *GMSBase;

#define AMT_PLANES 5

ULONG Palette[] = {
      0x000000,0x080808,0x101010,0x191919,0x212121,0x292929,0x313131,
      0x3A3A3A,0x424242,0x4A4A4A,0x525252,0x5A5A5A,0x636363,0x6B6B6B,
      0x737373,0x7B7B7B,0x848484,0x8C8C8C,0x949494,0x9C9C9C,0xA5A5A5,
      0xADADAD,0xB5B5B5,0xBDBDBD,0xC5C5C5,0xCECECE,0xD6D6D6,0x7F7F7F,
      0x9B9B9B,0x707070,0x444444,0x1E1E1E
      };

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,320,256,     /* Screen & Pic Height/Width */
       AMT_PLANES,          /* Amount of bitplanes */
       0,0,                 /* Top Of Screen Offset, X/Y */
       0,0,                 /* X/Y counters (for scrolling) */
       0,                   /* Special attributes */
       LORES|COL24BIT,      /* Screen mode */
       INTERLEAVED,         /* Screen type */
       0                    /* Reserved */
       };

struct Picture Picture = {
       PCV1,                /* Version header */
       0,                   /* Destination */
       320,256,             /* Width, Height */
       AMT_PLANES,          /* Amount of Planes */
       32,                  /* Amount of colours */
       &Palette,            /* Palette (remap) */
       LORES|COL24BIT,      /* Screen mode */
       INTERLEAVED,         /* Destination */
       0                    /* Parameters */
       };

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

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

void main(void)
{
   UWORD FadeState = 0;

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

   SetUserPri();

   if (Add_Screen(OurScreen) == NULL) {

      LoadingPic->Data = OurScreen->MemPtr1;
      if (LoadPic("GAMESLIB:data/IFF.Loading",LoadingPic) == NULL) {
         Show_Screen(OurScreen);

         do { Wait_OSVBL();            
              FadeState = B24_FadeToWhite(OurScreen,FadeState,10);
         } while (FadeState != NULL);

         do { Wait_OSVBL();
              FadeState = B24_FadeToPalette(OurScreen,FadeState,&Palette,2);
         } while (FadeState != NULL);

         Wait_Time(80);

         do { Wait_OSVBL();
	      FadeState = B24_FadeToBlack(OurScreen,FadeState,2);
	 } while (FadeState != NULL);

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

