/*Amiga Computing*/
/*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 libraries=0;
long i,k;                              /*loop variables*/
short j;
struct GfxBase *GfxBase;               /*graphics base*/
struct IntuitionBase *IntuitionBase;   /*intuition base*/
struct ViewPort *viewport;             /*viewport pointer*/
struct BitMap   BMred;                 /*bitmap */
struct RastPort *redrastport;          /*rastport pointer*/
struct Screen *customscreen;           /*pointer to screen structure*/
struct Window *thiswindow;             /*pointer to window structure*/
struct RasInfo *rired;                 /*RasInfo pointer*/

static USHORT colours2[] =              /*the colours*/
{
0x000,0xf00,0xe00,0xc00,0xa00,0x800,0x600,0x400,
};

struct NewScreen TheNewScreen =         /*the new screen structure*/
{
 0,0,320,200,3,
 1,3,
 NULL,
 CUSTOMSCREEN|CUSTOMBITMAP,
 NULL,
 NULL,
 NULL,
 &BMred,
};

struct NewWindow TheNewWindow =       /*a new window structure*/
{
 0,0,320,200,0,1,0,
 ACTIVATE|SUPER_BITMAP,
 0,0,0,
 0,0,
 64,20,320,200,
 CUSTOMSCREEN,
};

main()
{
libraries= openlibraries();                     /*open the libraries*/
if (libraries == 0) exit(1);
init();                                         /*open the window*/
stripes();                                      /*put stripes on the screen*/
scroll();                                       /*scroll demo */
cleanup();                                      /*close the window */
closelibraries();                               /*close the libraries*/
}

openlibraries()                                 /*open the libraries*/
{
GfxBase= (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase == 0) return(0);
IntuitionBase= (struct IntuitionBase *)OpenLibrary("intuition.library",0);
if (IntuitionBase == 0) return(0);
return(1);
}

init()
{
InitBitMap(&BMred,3,640,400);                   /*set up a bitmap */
for(i=0;i<3;i++)                                /*allocate screen for it*/
{
BMred.Planes[i] = (PLANEPTR)AllocRaster(640,400);
if (BMred.Planes[i] == 0) exit(2);
BltClear(BMred.Planes[i],80*400,0);             /*clear the screen*/
}
customscreen= (struct Screen *) OpenScreen(&TheNewScreen);
if (customscreen == 0) exit(1);                 /*open the screen*/
TheNewWindow.BitMap=(struct BitMap *) &BMred;
TheNewWindow.Screen = customscreen;             /*open the window*/
thiswindow = (struct Window *)OpenWindow(&TheNewWindow);
if (thiswindow  == NULL) exit(FALSE);
viewport=(struct ViewPort *)ViewPortAddress(thiswindow);
                                              /*save the viewport address*/

rired=(struct RasInfo *)viewport->RasInfo;    /*save the RasInfo address*/
LoadRGB4(viewport,&colours2[0],8);            /*change the colours*/
return(0);
}

scroll()
{
Delay(100);
for(i=0;i<100;i++)   scrollx(i);             /*scroll right*/
Delay(100);
for(i=0;i<100;i++)   scrolly(i);             /*scroll up*/
Delay(100);
for(i=100;i>-1;i--)   scrollx(i);            /*scroll left*/
Delay(100);
for(i=100;i>-1;i--)   scrolly(i);            /*scroll down*/
return(0);
}

scrollx(i)
long i;
{
rired->RxOffset=i;                          /*update the x RasInfo offset*/
RemakeDisplay();                         /*Intuition updates the display*/
return(0);
}

scrolly(i)
long i;
{
rired->RyOffset=i;                         /*update the y RasInfo offset*/
RemakeDisplay();                        /*Intuition updates the display*/
return(0);
}

stripes()
{                                      /*find the RastPort address*/
redrastport=thiswindow->RPort;
for(i=0;i<31;i++)                      /*draw solid vertical stripes*/
{
SetAPen(redrastport,i%8);
RectFill(redrastport,20*i,0,32+20*i,400);
}
for(i=0;i<20;i++)                      /*draw spaced horizontal stripes*/
{
SetAPen(redrastport,i%8);
RectFill(redrastport,0,20*i,639,10+20*i);
}
return(0);
}

cleanup()
{
CloseWindow(thiswindow);               /*close window*/
CloseScreen(customscreen);             /*close screen*/
for (i=0;i<3;i++)                      /*release bitplanes memory*/
{
FreeRaster(BMred.Planes[i],640,400);
}
return(0);
}

closelibraries()                       /*close libraries*/
{
CloseLibrary(GfxBase);
CloseLibrary(IntuitionBase);
return(0);
}


