


/*Your Amiga*/
/*amiga.lib rules ok!*/
/*part5-scrolling*/
/*c source code*/

#include <exec/types.h>
#include  <graphics/gfx.h>
#include  <graphics/view.h>
#include  <graphics/rastport.h>
#include  <graphics/gfxbase.h>
#include  <intuition/intuition.h>

long dosbase=0;                        /*library pointer*/
long libraries=0;
long i,k;                              /*loop variables*/
short j;
struct GfxBase *GfxBase;               /*graphics base*/
struct View myview;                    /*view*/
struct View *oldview;                  /*viewports*/
struct ViewPort vpredandgrey;
struct ColorMap *colourmap2;
struct BitMap   BMred;
struct ColorMap *GetColorMap();       /*returned colormap pointer*/
struct RastPort redrastport;
UWORD *colourtable2;
 
static USHORT colours2[] =
{
0x000,0xf00,0xe00,0xc00,0xa00,0x800,0x600,0x400,
0xeee,0xccc,0xaaa,0x999,0x777,0x666,0x444,0xddd,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
 
struct Screen *customscreen;            /*pointer to screen structure*/
struct Window *thiswindow;              /*pointers to window structures*/

struct NewScreen TheNewScreen =         /*the new screen structure*/
{
 0,0,320,200,3,
 1,3,
 NULL,
 CUSTOMSCREEN,
 NULL,
 "custom screen",
 NULL,
 NULL
};

struct NewWindow TheNewWindow =       /*a new window structure*/
{
 20,20,150,50,0,1,CLOSEWINDOW,
 WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SIZEBRIGHT,
 0,0,"this window",
 0,0,
 64,20,300,200,
 CUSTOMSCREEN,
};

struct RasInfo rired =
{
0,&BMred,0,0
};
main()
{
libraries= openlibraries();            /*open the libraries*/
if (libraries == 0) exit(1);
init();                                /*initialise the viewports*/
oldview  =  GfxBase->ActiView;         /*store the old view address*/
remakedisplay();                       /*load the new view*/
stripes();
scroll();
LoadView(oldview);                     /*replace the old view*/
Delay(200);
cleanup();
closelibraries();                      /*close the libraries*/
}
openlibraries()
{
dosbase= OpenLibrary("dos.library",0);
if (dosbase == 0) return(0);
GfxBase= (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase == 0) return(0);
return(1);
}
init()
{
InitView(&myview);                    /*initialise the view*/
myview.ViewPort = &vpredandgrey;            /*connect it to the first viewport*/
InitVPort(&vpredandgrey);             /*initialise the second viewport*/
vpredandgrey.DWidth = 320;
vpredandgrey.DHeight = 200;
vpredandgrey.RasInfo = &rired;        /*connect it to the first RasInfo*/
colourmap2 = GetColorMap(32);
colourtable2 = (UWORD *)colourmap2->ColorTable;
for(i=0;i<32;i++)                    /*the first 8 red colour registers are*/
{                                    /*for the first playfield, the next 8*/
*colourtable2++ = colours2[i];       /*grey colour registers are for the*/
}                                    /*second playfield*/
vpredandgrey.ColorMap = colourmap2;
InitBitMap(&BMred,3,640,400);        /*a separate bitmap for each RasInfo*/
for(i=0;i<3;i++)
{
BMred.Planes[i] = (PLANEPTR)AllocRaster(640,400);
if (BMred.Planes[i] == 0) exit(2);
}
}
scroll()
{
Delay(100);
for(i=0;i<100;i++)   scrollx(i);
Delay(100);
for(i=0;i<100;i++)   scrolly(i);
Delay(100);
for(i=100;i>0;i--)   scrollx(i);
Delay(100);
for(i=100;i>0;i--)   scrolly(i);
}
scrollx(i)
long i;
{
rired.RxOffset=i;
remakedisplay();
}
scrolly(i)
long i;
{
rired.RyOffset=i;
remakedisplay();
}
remakedisplay()
{
MakeVPort(&myview,&vpredandgrey);
MrgCop(&myview);                   /*merge the copper lists*/
WaitTOF();                         /*wait for top of frame*/
LoadView(&myview);                 /*and load the new view*/
}
stripes()
{
InitRastPort(&redrastport);
redrastport.BitMap = &BMred;
for(i=0;i<31;i++)
{
SetAPen(&redrastport,i%8);
RectFill(&redrastport,20*i,0,32+20*i,400);
}
for(i=0;i<20;i++)
{
SetAPen(&redrastport,i%8);
RectFill(&redrastport,0,20*i,639,10+20*i);
}
}
cleanup()
{
FreeVPortCopLists(&vpredandgrey);
FreeColorMap(colourmap2);
for (i=0;i<3;i++)
{
FreeRaster(BMred.Planes[i],640,400);
}
}
closelibraries()
{
CloseLibrary(dosbase);
CloseLibrary(GfxBase);
}
window()
{
customscreen= (struct Screen *) OpenScreen(&TheNewScreen);
if (customscreen == 0) exit(1);                   /*open the screen*/

TheNewWindow.Screen = customscreen;              /*open this window*/
if ((thiswindow = (struct Window *)OpenWindow(&TheNewWindow))  == NULL) exit(FALSE);


Wait(1<<thiswindow->UserPort->mp_SigBit);        /*wait for mousclick on*/
                                                 /*thiswindow close gadget*/
CloseWindow(thiswindow);                         /*close windows*/
CloseScreen(customscreen);                       /*close screen*/
}

