/******************************************************************************
**********							     **********
**********	Oops! - Changes WB's background color to ???	     **********
**********							     **********
*******************************************************************************
**********							     **********
**********	      Designed by Magic Ceee 07-AUG-87		     **********
**********							     **********
**********	This stuff is in the public domain - enjoy!          **********
**********							     **********
******************************************************************************/

#include "exec/types.h"
#include "exec/memory.h"
#include "graphics/gfxbase.h"
#include "graphics/copper.h"
#include "hardware/custom.h"
#include "intuition/intuition.h"

#define NO_INTUI	"Intuition won't open!\n"
#define NO_GFX		"Graphix won't open!\n"

struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;
struct ViewPort		*MagicView;
struct UCopList 	*MagicList;
struct UBYTE		*AllocMem();
extern struct Custom 	custom;


/******************************************************************************
*** y[]   = Vertical beam position 					    ***
*** col[] = Colortable. Starts at $000 (Black), ends at $FFF (Blue)	    ***
******************************************************************************/

static int pos[] = { 0,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102,108,
		     114,120,126,132,138,144,150,156,162,168,174,180,188,194 };

static int col[] = { 0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,0x008,
		       0x009,0x00a,0x00b,0x00c,0x00d,0x00e,0x00f,0x00f,0x00e,
		       0x00d,0x00c,0x00b,0x00a,0x009,0x008,0x007,0x006,0x005,
		       0x004,0x003,0x002,0x001,0x000 };


/******************************************************************************
***			Let the colorful times roll...			    ***
******************************************************************************/

main()
{
 int i;

 if(!(IntuitionBase=(struct IntuitionBase *)
   OpenLibrary("intuition.library",0)))
     {
      Write(Output(),NO_INTUI,strlen(NO_INTUI));
      exit(0); 
     }

 if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
   {
    Write(Output(),NO_GFX,strlen(NO_GFX));
    CloseLibrary(IntuitionBase);
    exit(0);
   }
 
 MagicView=GfxBase->ActiView->ViewPort;		/* Current ViewPort */

 MagicList=AllocMem(sizeof(struct UCopList),MEMF_PUBLIC|MEMF_CLEAR);


 /* for(i=0;i<31;i++) pos[i]+=30;  <-- PAL offset (256 video lines) */


 for(i=0;i<31;i++)
    {
     CWAIT(MagicList,pos[i],0);			/* Wait til pos[i] */
     CMOVE(MagicList,custom.color[0],col[i]); 	/* Use new color */
    }

 CEND(MagicList);	/* New UCopList installed */

 MagicView->UCopIns=MagicList;	/* Tell Copper bout new list */
 RethinkDisplay();		/* At this point, it's going to be funny
				   as hell... */

 CloseLibrary(IntuitionBase);
 CloseLibrary(GfxBase);		/* Ceee you! */
}
