/*
** Double Buffer Demo
** ------------------
** This just shows how to double buffer the screen.
**
** Compiles under SAS/C.
*/

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

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

#define AMT_PLANES 5

struct GMSBase *GMSBase;

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 Mem - 1,2,3 */
       0,                         /* ScreenLink */
       &Palette,                  /* Address of palette */
       0,                         /* Address of rasterlist */
       32,                        /* Amt of colours in palette */
       320,256,320,256,           /* Screen & Pic Height/Width */
       AMT_PLANES,                /* Amt_Planes */
       0,0,                       /* Top Of Screen, X/Y */
       0,0,                       /* X/Y counters (for scrolling) */
       DBLBUFFER,                 /* 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|COL24BIT,      /* Screen mode */
       INTERLEAVED,         /* Destination */
       0                    /* Parameters */
       };

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

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

void main(void)
{
   struct GamesLibrary *GMSBase = (struct GamesLibrary *)
       OpenLibrary("games.library", 0);
   if (GMSBase == NULL) exit(FALSE);

   SetUserPri();

   if (Add_Screen(OurScreen) == NULL) {

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

        Show_Screen(OurScreen);

        while (!(Read_Mouse(JPORT1)&MB_LMB)) {
          Wait_OSVBL();
          SwapBuffers(OurScreen);
        }
      }
      Delete_Screen(OurScreen);
   }
   CloseLibrary((struct Library *)GMSBase);
}

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

