/* This program creates and displays a 400 by 300 by 2 bit plane * playfield on top of a 320 by 200, 2 plane deep playfield, as * a demo of a dual playfield display. This program is largely * the same as the basic display program in the graphics primitives * chapter of the ROM Kernel manual, except that it uses a rastport * to control the writing instead of writing directly into display * memory. */ #include "exec/types.h" #include "intuition/intuition.h" #include "graphics/gfxbase.h" #define DEPTH 2 #define WIDTH 400 #define HEIGHT 300 #define DEPTH2 2 /* for second playfield */ #define WIDTH2 320 #define HEIGHT2 200 #define VPWIDTH 320 #define VPHEIGHT 200 #define MAXSCROLL_X WIDTH-WIDTH2 #define MAXSCROLL_Y HEIGHT-HEIGHT2 #define NOT_ENOUGH_MEMORY -1000 struct View v; struct ViewPort vp; struct ColorMap *cm; /* pointer to colormap structure, dynamic alloc */ struct BitMap b, b2; struct RastPort rp, rp2; struct RasInfo ri, ri2; LONG i; SHORT k,n; struct GfxBase *GfxBase; struct View *oldview; /* save pointer to old view so can restore */ UWORD colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f, 0, 0, 0, 0, 0, 0x4f8, 0xff0, 0xf9c }; /* black, red, green, blue, ignored, ignored, ignored, ignored, (transparent), purple, yellow, mauve */ UWORD *colorpalette; struct cprlist *LOF[2]; struct cprlist *SHF[2]; /* this is a set of pointers which will be used to hold the old values of these pointers .... we reuse an old copper list by saying MakeView with whatever copper list is currently in LOFCprList and SHFCprList. If they are currently = 0, a brand new copper list is created */ short w; main() { GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0); if (GfxBase == NULL) exit(1); oldview = GfxBase->ActiView; /* save current view to restore later */ /* example steals screen from Intuition if started from WBench */ /* init bitmap structures */ InitBitMap(&b,DEPTH,WIDTH,HEIGHT); InitBitMap(&b2,DEPTH2,WIDTH2,HEIGHT2); /* allocate and clear bitplanes */ for(i=0; iColorTable; for(i=0; i<12; i++) *colorpalette++ = colortable[i]; /* copy my colors into this data structure */ vp.ColorMap = cm; /* link it with the viewport */ /* now specify critical characteristics */ vp.DWidth = VPWIDTH; /* this is how much you will SEE */ vp.DHeight = VPHEIGHT; vp.RasInfo = &ri; vp.Modes = DUALPF; MakeVPort( &v, &vp ); /* construct copper instr (prelim) list */ MrgCop( &v ); /* merge prelim lists together into a real * copper list in the view structure. */ InitRastPort(&rp); /* first playfield's rastport */ rp.BitMap = &b; /* link to its bitmap */ InitRastPort(&rp2); /* second playfield's rastport */ rp2.BitMap = &b2; /* link to its bitmap */ SetRast(&rp,0); /* make first one blank */ SetRast(&rp2,0); /* make top one transparent */ LoadView(&v); SetAPen(&rp2,2); /* small rectangle in back playfield */ RectFill(&rp2,140,80,180,100); SetAPen(&rp,1); /* cover except around edges */ RectFill(&rp,20,20,300,180); SetAPen(&rp,0); /* open hole to see back playfield */ RectFill(&rp,120,60,200,120); scrollit(); LoadView(oldview); /* put back the old view */ Delay(200); FreeMemory(); /* exit gracefully */ CloseLibrary(GfxBase); /* since opened library, close it */ } /* end of main() */ /* return allocated memory */ FreeMemory() { /* free drawing area */ for(i=0; i(0); i--) { swapPointers(); ri.RxOffset--; remakeView(); w ^= 1; } for(i=MAXSCROLL_Y; i>(0); i--) { swapPointers(); ri.RyOffset-- ; remakeView(); w ^= 1; } } /* end of scrollit() */ swapPointers() /* provided for double buffering of copper lists */ { LOF[w] = v.LOFCprList; SHF[w] = v.SHFCprList; v.LOFCprList = LOF[(w^1)]; v.SHFCprList = SHF[(w^1)]; /* swap the pointers so that they can reuse existing space */ } remakeView() { MakeVPort(&v, &vp); MrgCop(&v); LoadView(&v); /* and show it */ WaitTOF(); /* slow things down so we can see it move */ }