// File : dbuffer.h // Coded by : Scotte // History : Created 14/03/00 19:58:37 // // Description : Creating and updating a double buffer // Notes : None #include "profile.h" #include "yaroze.h" #include "dbuffer.h" #include "gtypes.h" #include "console.h" // The double buffer static sDBUFFER db[2]; // Current buffer ID static u_word id; // Function : DBUFFER_Set() // Coded by : Scotte // History : Created 12/03/00 16:44:46 // // Description : Set up the double buffer // // Parameters : r - screen area // x,y - display position // // Returns : Double buffer input // // Notes : None void DBUFFER_Set(const RECT *r,const u_hword x,const u_hword y) { // Initialise the graphics GsInitGraph(r->w,r->h,GPU_OFFSET,1,VRAM_MODE_16BIT); GsDefDispBuff(r->x,r->y+r->h,r->x,r->y); // Set display and drawing environments for buffer 0 and 1 SetDefDrawEnv(&db[0].drawenv,r->x,r->y+r->h,r->w,r->h); SetDefDrawEnv(&db[1].drawenv,r->x,r->y,r->w,r->h); SetDefDispEnv(&db[0].dispenv,r->x,r->y,r->w,r->h); SetDefDispEnv(&db[1].dispenv,r->x,r->y+r->h,r->w,r->h); // Automatically clear background db[0].drawenv.isbg=db[1].drawenv.isbg=1; // Enable dithering db[0].drawenv.dtd=db[1].drawenv.dtd=1; // Set screen position and size db[0].dispenv.screen.x=db[1].dispenv.screen.x=x; db[0].dispenv.screen.y=db[1].dispenv.screen.y=y; db[0].dispenv.screen.h=db[1].dispenv.screen.h=r->h; // Set the current buffer ID id=0; // Initialise the profiler mPROFILE_INIT(r->w,r->h,2); // Turn on the display SetDispMask(1); } // Function : DBUFFER_SetOT() // Coded by : Scotte // History : Created 14/03/00 20:15:01 // // Description : Link an ordering table to the double buffer // // Parameters : ot - ordering table // // Returns : None // // Notes : None void DBUFFER_SetOT(GsOT *ot) { db[0].ot=ot; db[1].ot=ot+1; // Clear the OT GsClearOt(0,0,db[0].ot); GsClearOt(0,0,db[1].ot); } // Function : DBUFFER_SetPB() // Coded by : Scotte // History : Created 14/03/00 20:19:57 // // Description : Set the packet buffer // // Parameters : pb - base packet buffer // size - packet buffer size // // Returns : None // // Notes : None void DBUFFER_SetPB(PACKET *pb,const u_word size) { db[0].pb=pb; db[1].pb=(PACKET *)((u_byte *)pb+size); // Point to the current packet buffer (used by GsSort...() functions) GsOUT_PACKET_P=db[0].pb; mMESSAGE("Packet buffer size : %d (bytes)\n",size); } // Function : DBUFFER_SetBG() // Coded by : Scotte // History : Created 14/03/00 20:07:47 // // Description : Set the background colour // // Parameters : r,g,b - new background colour // // Returns : Double buffer pointer // // Notes : None void DBUFFER_SetBG(const u_byte r,const u_byte g,const u_byte b) { setRGB0(&db[0].drawenv,r,g,b); setRGB0(&db[1].drawenv,r,g,b); } // Function : DBUFFER_Swap() // Coded by : Scotte // History : Created 14/03/00 20:50:36 // // Description : Swap display/drawing environments and starts drawing // // Parameters : None // // Returns : Frame time in scanlines (horizontal blanks) // // Notes : None u_word DBUFFER_Swap(void) { u_word vsync; // Time taken during this frame mPROFILE_READ(0x80,0x80,0x80); // Wait for drawing of previous frame to finish while(DrawSync(1)); // Draw the profile bars mPROFILE_DRAW(db[id].ot); // Lock to 50/60 frames per second vsync=VSync(0); // Start of a frame mPROFILE_START(); // Switch ID id^=1; // Switch display and drawing environments PutDrawEnv(&db[id].drawenv); PutDispEnv(&db[id].dispenv); // Start drawing next frame GsDrawOt(db[id^1].ot); // Swap packet buffers GsOUT_PACKET_P=db[id].pb; // Clear OT GsClearOt(0,0,db[id].ot); return(vsync); } // Function : DBUFFER_CurrentOT() // Coded by : Scotte // History : Created 14/03/00 20:53:11 // // Description : Pointer to current ordering table // // Parameters : None // // Returns : Current OT // // Notes : None GsOT *DBUFFER_CurrentOT(void) { return(db[id].ot); }