/* WorkBench4096-ein Programm, das den Hintergrund der Workbench in 4096 Farben
   darstellt. Diese Aufgabe übernimmt der COPPER. Tim Pietzcker 29.12.88 

   Dieses Programm muß mit der +l - Option compiliert und gelinkt werden.
   Ich lege zwar großen Wert auf Vermeiden dieser Option, aber ich habe
   mit allen Versuchen, ohne +l auszukommen, nur Gurus erzeugt.             */

#include <exec/types.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <graphics/copper.h>
#include <hardware/custom.h>
#include <exec/memory.h>

#define LEFT_OFFSET 30l   /* der sichtbare Bereich des Bildschirms beginnt da */
#define RECT_WIDTH  12l   /* so breit (12*8 Pixel) wird ein Rechteck */

struct IntuitionBase *IntuitionBase;
struct GfxBase       *GfxBase;
struct Library       *OpenLibrary();
struct ViewPort      *vp,*ViewPortAddress();
void                 *AllocMem();
struct Window        *MyWindow,*OpenWindow();
struct UCopList      *MyCL;

struct NewWindow TheWindow =
{
   0,0,
   400,10,
   2,1,
   CLOSEWINDOW,
   WINDOWDRAG|WINDOWCLOSE|SMART_REFRESH,
   NULL,NULL,
   (UBYTE *)"WorkBench4096   © 29.12.88 by Tim Pietzcker",
   NULL,NULL,
   0,0,0,0,
   WBENCHSCREEN
};

main()
{
   UWORD red,green,blue;
   
   GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",NULL);
   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",NULL);

   MyWindow=OpenWindow(&TheWindow);
   vp=ViewPortAddress(MyWindow);
   MyCL=(struct UCopList *)
         AllocMem(sizeof(struct UCopList),MEMF_CHIP|MEMF_CLEAR);
   
   for(red=0;red<16;++red)
      for(green=0;green<16;++green)
         for(blue=0;blue<16;++blue)
         {
            CWAIT(MyCL,red*16l+green,LEFT_OFFSET+blue*RECT_WIDTH);
            CMOVE(MyCL,custom.color[0],(UWORD)(red*256+ green*16 + blue));
         }
   CEND(MyCL);
   WaitTOF();
   vp->UCopIns=MyCL;
   RethinkDisplay();
   Wait(1l<<MyWindow->UserPort->mp_SigBit);
   FreeVPortCopLists(vp);
   RemakeDisplay();
   CloseWindow(MyWindow);
   CloseLibrary(IntuitionBase);
   CloseLibrary(GfxBase);
}
