/*
** 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
*/

#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

UWORD  Palette[] = {
       0x0000,0x0130,0x0FCB,0x0FA9,0x0D88,0x0965,0x0644,0x0211,
       0x0400,0x0444,0x0FF0,0x0432,0x0CC0,0x0150,0x0501,0x0880,
       0x0261,0x0271,0x0382,0x0492,0x05A3,0x05B4,0x0677,0x06C4,
       0x0788,0x09AA,0x0BCC,0x0801,0x0901,0x0A02,0x0701,0x0601
       };

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,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,               /* 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,               /* 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.Pic320",LoadingPic) == NULL) {
         Show_Screen(OurScreen);
         Wait_Time(10);

         do { Wait_VBL();
              Wait_OSVBL();            
              FadeState = B12_FadeToPalette(OurScreen,FadeState,&Palette,00,32);
            }
         while (FadeState != NULL);

         Wait_LMB();

         do { Wait_OSVBL();
              Wait_VBL();
              FadeState = B12_FadeToWhite(OurScreen,FadeState,00,32);
            }
         while (FadeState != NULL);

         Wait_Time(30);

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

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

