/*
** Colour List Example
** -------------------
**
** Colourlists are those nice colour gradients used in demos and games,
** usually  sitting in the background of your screen.  Colourlists are mostly
** good for getting more colours on screen than what there really is.
** Although  the games.library allows you to do other screen effects based on
** raster lines, we'll just stick to changing colours in this demo.
** 
** You can move the green colour bar by moving the mouse up and down.
** You will notice that if you move the green bar into the upper red bar,
** your bar will disappear.  This is because:
** 
**   WAITLINE  95        ;Wait for line 95
**   WAITLINE 100        ;Wait for line 100
**   WAITLINE  90        ;Wait for line 90 <--Error! 
** 
** Is not allowed.  The monitor beam travels down the screen, and so the
** Update_RasterList routine will expect all lines to be in sequential order.
** Moving two colourbars into each other breaks this rule, causing the wait
** command to be ignored.  If you want to get around this, you will have to
** have just one large colourlist and sort your colours before each call to
** Update_RasterList.
** 
** Similarly if you move the colour bar too far down the screen the hardware
** won't like it because lines > 311 don't exist.  It's up to you to be
** responsible enough to stop this from happening!
** 
** Press the left mouse button to exit the demo.
*/

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

#define AMT_PLANES 1

struct GMSBase *GMSBase;
extern struct ExecBase *SysBase;

WORD ColourBar1[] =
{
     0x100,0x200,0x300,0x400,0x500,0x600,0x700,0x800,0x900,0xa00,
     0xb00,0xc00,0xd00,0xe00,0xe00,0xe00,0xd00,0xc00,0xb00,0xa00,
     0x900,0x800,0x700,0x600,0x500,0x400,0x300,0x200,0x100,0x000,
     -1
};

WORD ColourBar2[] =
{
     0x010,0x020,0x030,0x040,0x050,0x060,0x070,0x080,0x090,0x0a0,
     0x0b0,0x0c0,0x0d0,0x0e0,0x0f0,0x0e0,0x0d0,0x0c0,0x0b0,0x0a0,
     0x090,0x080,0x070,0x060,0x050,0x040,0x030,0x020,0x010,0x000,
     -1
};

WORD ColourBar3[] =
{
     0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,0x009,0x00a,
     0x00b,0x00c,0x00d,0x00e,0x00f,0x00e,0x00d,0x00c,0x00b,0x00a,
     0x009,0x008,0x007,0x006,0x005,0x004,0x003,0x002,0x001,0x000,
     -1
};


ULONG RasterList[] =
{
     COL12LIST(000,3,00,&ColourBar1),   /* Line, Skip, Colnum, ColourList */
     COL12LIST(160,1,00,&ColourBar2),   /* Line, Skip, Colnum, ColourList */
     COL12LIST(230,1,00,&ColourBar3),   /* Line, Skip, Colnum, ColourList */
     RASTEND
};


struct GameScreen GameScreen =
{
     GSV1,
     0,0,0,              /* Screen Mem 1,2,3 */
     0,                  /* ScreenLink */
     0,                  /* Address of palette */
     &RasterList,        /* Address of rasterlist */
     0,                  /* Amount of colours in palette */
     320,256,            /* Screen Width and Height */
     320/8,256,          /* Picture Width/8 and Height */
     AMT_PLANES,         /* Amt_Planes */
     0,0,                /* X/Y screen offset */
     0,0,                /* X/Y picture offset */
     BLKBDR,             /* Special attributes */
     LORES|COL24BIT,     /* Screen mode */
     PLANAR,             /* Screen type */
     0                   /* Reserved */
};

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

void main(void)
{
   int finished = FALSE;
   short barpos = 160;
   ULONG mousestat;

   if (GMSBase = (struct GMSBase *) OpenLibrary("games.library",0)) {
      SetUserPrefs(0);
      if (Add_Screen(&GameScreen) == NULL) {

         Show_Screen(&GameScreen);

         do
         {
            mousestat = Read_Mouse(JPORT1);
            barpos += (BYTE)mousestat;
            if (barpos < 0) barpos = 0;
            if (barpos > 226) barpos = 226;
            RasterList[4] = (RasterList[4] & 0xffff0000) | barpos;
            Update_RasterLines(&GameScreen);
            Wait_OSVBL();
            if (mousestat & MB_LMB)
               finished = TRUE;
         } while (finished == FALSE);

      Delete_Screen(&GameScreen);
      }
   CloseLibrary((struct Library *)GMSBase);
   }
}

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