#include "exec/types.h"
#include "intuition/intuition.h"
#include "graphics/gfxmacros.h"
#include "exec/libraries.h" /* vanwege textfont van disk */

struct IntuitionBase *IntuitionBase;
struct Window *NoBorder;
struct GfxBase *GfxBase;
struct Screen *Scrn;
struct IntuiMessage *mesg;
struct RastPort *r;
struct Library *DiskfontBase;



#define INTUITION_REV 29
#define GRAPHICS_REV 29

main()
{
 ULONG flags,mclass;
 SHORT x,y,w,h,d,c0,c1,einde,txt0ycrd,txt1ycrd,txt2ycrd,xt;
 USHORT mode;
 int len;
 char *txt0,*txt1,*txt2;
 struct TextFont *FontPtr;
 static struct TextAttr SysFont=
       {"topaz.font",9,0,0}; 


 VOID OpenALL();

 OpenALL();

 /* ======Open een hires custom screen====== */

 y=0;
 w=320;
 h=200;
 d=5; /* max 32 colors ! */
 c0=0x00;
 c1=0x01;
 mode=NULL;

 Scrn=(struct Screen *)
         make_screen(y,w,h,d,c0,c1,mode,NULL);

 /* ======open een borderless window ====== */

 x=y=0;
 w=320;
 h=200;
 flags=ACTIVATE|NOCAREREFRESH|BORDERLESS|BACKDROP;
 NoBorder=(struct Window *)
             make_window(x,y,w,h,NULL,flags,Scrn);

 /* ======geen screentitel====== */

 ShowTitle(Scrn,0);

 /* ======definitie van RPort !====== */

 r=NoBorder->RPort;

  SetRGB4(ViewPortAddress(NoBorder),0,0,0,0);
  for(x=1;x<16;x++)
   { 
   SetRGB4(ViewPortAddress(NoBorder),   x,(15-x)  , 2+y,15);
   SetRGB4(ViewPortAddress(NoBorder),16+x,(x+y)%16,5,          x);
   };


  for(xt=319;xt>=0;xt--)
   {
   SetAPen(r,xt%31+1);
   Move(r,0,199);Draw(r,xt,0);
   Move(r,319,0);Draw(r,319-xt,199);

   Move(r,0,0);Draw(r,xt,199);
   Move(r,319,199);Draw(r,319-xt,0);

   };



  /* zwart vlak om in te schrijven */

  SetAPen(r,0);
  SetBPen(r,0);
  RectFill(r,0,99-50,319,99+50);

  SetAPen(r,10);
  RectFill(r,5,99-55+10,319-5,99+55-10);

  SetAPen(r,0);
  RectFill(r,10,99-55+15,319-10,99+55-15);


  /* text , zie ook OpenAll() */
 

 /*==Font==*/

  FontPtr=(struct TextFont *)OpenFont(&SysFont);
  if (FontPtr== 0)exit(FALSE);

  SetAPen(r,1);
  SetFont(r,FontPtr);
  SetSoftStyle(r,FSF_BOLD,FSF_BOLD);
  PrintAt(r,73,99-20-4,"BAMIGA SECTOR ONE");
  PrintAt(r,118,104-4,"PRESENTS");

  SetAPen(r,1);
  PrintAt(r,58,99+33-6,"THE THREE MUSKETEERS");

  SetSoftStyle(r,FS_NORMAL,FS_NORMAL);

  CloseFont(FontPtr);

 
 


 /* ======einde in stijl !====== */

einde=0; /* init einde op 0 ! */
while (einde != 1)
 {
  Wait(1<<NoBorder->UserPort->mp_SigBit);

  while((mesg=(struct IntuiMessage *)
      GetMsg(NoBorder->UserPort))!=NULL)
  {
   ReplyMsg(mesg);
   mclass=mesg->Class;
  }

  if(mclass==MOUSEBUTTONS)
   {
     einde=1;

    /* scroll */

    for(xt=0;xt<50;xt++)
     {
       ScrollRaster(r,0,2,0,99-50,319,99+50-xt*2);
       WaitTOF();
      };

     Delay(10);
     cleanwindow(r);
     CloseLibrary(IntuitionBase);
     CloseLibrary(GfxBase);
     CloseWindow(NoBorder);
     CloseScreen(Scrn);

   }
 }

} /********************************** einde van main **********************/

VOID OpenALL()
{
 /*==Intuition==*/

 IntuitionBase=(struct IntuitionBase *)
            OpenLibrary("intuition.library",INTUITION_REV);

 if(IntuitionBase==NULL)
    exit(FALSE);

 /*==Graphics Library==*/

 GfxBase=(struct GfxBase *)
          OpenLibrary("graphics.library",GRAPHICS_REV);

 if(GfxBase==NULL)
    exit(FALSE);

}

make_window(x,y,w,h,name,flags,screen)
SHORT x,y,w,h;
UBYTE *name;
ULONG flags;
struct Screen *screen;

{
 struct NewWindow NewWindow;

 NewWindow.LeftEdge = x;
 NewWindow.TopEdge = y;
 NewWindow.Width = w;
 NewWindow.Height = h;
 NewWindow.DetailPen = -1;
 NewWindow.BlockPen = -1;
 NewWindow.Title = name;
 NewWindow.Flags = flags;
 NewWindow.IDCMPFlags = MOUSEBUTTONS;
 NewWindow.Type = CUSTOMSCREEN;
 NewWindow.FirstGadget = NULL;
 NewWindow.CheckMark = NULL;
 NewWindow.Screen = screen;
 NewWindow.BitMap = NULL;
 NewWindow.MinWidth = 0;
 NewWindow.MinHeight = 0;
 NewWindow.MaxWidth = 0;
 NewWindow.MaxHeight = 0;

 return(OpenWindow(&NewWindow));

}


make_screen(y,w,h,d,color0,color1,mode,name)
SHORT y,w,h,d;
UBYTE color0,color1,*name;
USHORT mode;
{
 struct NewScreen NewScreen;

 NewScreen.LeftEdge = 0;
 NewScreen.TopEdge = y;
 NewScreen.Width = w;
 NewScreen.Height = h;
 NewScreen.Depth = d;
 NewScreen.DetailPen = color0;
 NewScreen.BlockPen = color1;
 NewScreen.ViewModes = mode;
 NewScreen.Type = CUSTOMSCREEN;
 NewScreen.Font = NULL;
 NewScreen.DefaultTitle = name;
 NewScreen.Gadgets = NULL;
 NewScreen.CustomBitMap = NULL;

 return(OpenScreen(&NewScreen));
}



cleanwindow(rast)
struct RastPort *rast;
{
 SHORT i,x2,y2;

 SetAPen(rast,0); /* zwart */
 SetBPen(rast,1); /* wit  */


 for(i=0;i<200;i++)
  {
   Move(rast,0,0);Draw(rast,319,i);
   Move(rast,319,0);Draw(rast,0,i);
   Move(rast,0,199);Draw(rast,319,199-i);
   Move(rast,319,199);Draw(rast,0,199-i);
  }
}

PrintAt(rast,x,y,s)
struct RastPort *rast;
int x,y;
char *s;
{
 Move(rast,x,y);
 Text(rast,s,strlen(s));
}







