// Filename : Dbuff2.c // Coded by : Scott Evans // Created/Modified : 16/9/97 // Description : Demonstrates the use of interlace mode #include void SetDefDispEnv(DISPENV *,int,int,int,int); void SetDefDrawEnv(DRAWENV *,int,int,int,int); // Set r0,g0,b0 members of a structure #define setRGB0(p,r,g,b)\ (p)->r0=(r),(p)->g0=(g),(p)->b0=(b) // Packet buffer and ordering table size #define NPKTS 1 #define PBSIZE NPKTS*sizeof(GsBOXF) #define OT_LENGTH 1 // To run non-interlace mode comment this define #define INTERLACE_ON // Screen size (NTSC) #ifdef INTERLACE_ON #define SCRNW 640 #define SCRNH 480 #else #define SCRNW 320 #define SCRNH 240 #endif // 2 ordering tables and 2 packet buffers GsOT mainOT[2],*ot=mainOT; GsOT_TAG OTTags[2][1<length=(ot+1)->length=OT_LENGTH; ot->org=OTTags[0]; (ot+1)->org=OTTags[1]; // Set drawing area for buffer 0 and 1 SetDefDrawEnv(&dbp->drawenv,0,0,SCRNW,SCRNH); SetDefDrawEnv(&(dbp+1)->drawenv,0,SCRNH,SCRNW,SCRNH); // Set display area for buffer 0 and 1 SetDefDispEnv(&dbp->dispenv,0,SCRNH,SCRNW,SCRNH); SetDefDispEnv(&(dbp+1)->dispenv,0,0,SCRNW,SCRNH); // Set ordering table for buffer 0 and 1 dbp->ot=ot; (dbp+1)->ot=ot+1; // Set packet buffer for buffer 0 and 1 dbp->pb=pb; (dbp+1)->pb=pb+PBSIZE; // Clear background on dbp->drawenv.isbg=(dbp+1)->drawenv.isbg=1; // Background colour=red setRGB0(&dbp->drawenv,0x80,0x0,0x0); setRGB0(&(dbp+1)->drawenv,0x80,0x0,0x0); #ifdef INTERLACE_ON // Set drawing area for buffer 0 and 1 SetDefDrawEnv(&dbp->drawenv,0,0,SCRNW,SCRNH); SetDefDrawEnv(&(dbp+1)->drawenv,0,0,SCRNW,SCRNH); // Set display area for buffer 0 and 1 SetDefDispEnv(&dbp->dispenv,0,0,SCRNW,SCRNH); SetDefDispEnv(&(dbp+1)->dispenv,0,0,SCRNW,SCRNH); // Allow drawing in display area dbp->drawenv.dfe=0; (dbp+1)->drawenv.dfe=0; #endif // Set up a white box box.attribute=0; box.w=box.h=50; box.x=(SCRNW-box.w)>>1; box.y=(SCRNH-box.h)>>1; box.r=box.g=box.b=0xff; // Initialise graphics ResetGraph(0); // Turn on display SetDispMask(1); while(1) { // Swap buffers dbp=(dbp==db ? db+1 : db); // Set packet buffer for current buffer GsSetWorkBase(dbp->pb); // Initialise ordering table GsClearOt(0,0,dbp->ot); // Put primitive in ordering table GsSortBoxFill(&box,dbp->ot,0); // Wait for it all to finish #ifndef INTERLACE_ON DrawSync(0); #endif VSync(0); // Halt drawing after vertical blank has returned // Similar to DrawSync() but does not wait for drawing to // finish, it just stops the drawing ResetGraph(1); // Set new drawing and display areas PutDrawEnv(&dbp->drawenv); PutDispEnv(&dbp->dispenv); // Execute the primitives in the ordering table GsDrawOt(dbp->ot); } exit(0); } #ifdef 0 // Set default drawing environment void SetDefDrawnEnv(DRAWENV *e,int x,int y,int w,int h) { e->clip.x=x; e->clip.y=y; e->clip.w=w; e->clip.h=h; e->tw.x=e->tw.y=tw->w=tw->h=0; e->ofs[0]=x; e->ofs[1]=y; e->tpage-GetTPage(0,0,640,0); e->dtd=1; e->dfe=1; e->isbg=0; e->r0=e->g0=e->b0=0; } // Set default display environment void SetDefDispEnv(DISPENV *e,int x,int y,int w,int h) { e->disp.x=x; e->disp.y=y; e->disp.w=w; e->disp.h=h; e->screen.x=e->screen.y=0; e->screen.w=256; e->screen.h=240; e->isinter=e->isrgb24=0; } #endif