/******************/ /*** GFx System ***/ /******************/ #include "system/global.h" #include "system\vid.h" #include "gfx\prim.h" #include "fileio\fileio.h" #include "utils\lznp.h" /*****************************************************************************/ #define MaxVBFuncs 4 /*****************************************************************************/ static void (*VbFunc)(void); static VbFuncType VbFuncList[MaxVBFuncs]; static u32 FrameCounter=0,TickCount=0,TickBuffer[2]; static u32 s_lastFrameCounter=0,s_vblsThisFrame=0; static sVidScreen Screen[2]; static int ScreenXOfs=0,ScreenYOfs=0; static int ScreenW, ScreenH; static RECT ScreenRect; /*static*/ int FrameFlipFlag=0; static int ClearScreen=0; static u8 *ScreenImage=0; static const CVECTOR s_defClearCol = {0, 0, 0}; /*****************************************************************************/ /*** Loading Icon Cack *******************************************************/ /*****************************************************************************/ POLY_FT4 LoadPoly; static int LoadX=430; static int LoadY=192; static int LoadBackY; static int LoadHalfWidth; static int LoadIconSide; static int DrawLoadIcon=0; static RECT LoadBackRect; static int LoadTime=0; static const int LoadBackInc=8; /*****************************************************************************/ // Altered to keep aspect ratio s8 LoadTab[]= { 21,21,21,21,20,20,20,20,19,19,19,18,18,17,17,16,15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,17,18,18,19,19,19,20,20,20,20,20,21 }; const int LoadTabSize=sizeof(LoadTab)/sizeof(s8); /*****************************************************************************/ void LoadingIcon() { int Dst; int rgb; POLY_FT4 *PolyPtr=&LoadPoly; Dst=LoadTab[LoadTime]; PolyPtr->x0=PolyPtr->x2=LoadX-Dst+LoadHalfWidth+2; PolyPtr->x1=PolyPtr->x3=LoadX+Dst+LoadHalfWidth+2; rgb=128-(LoadTab[(LoadTime+LoadTabSize/2)%LoadTabSize]*3); setRGB0(PolyPtr,rgb,rgb,rgb); MoveImage(&LoadBackRect,LoadX-LoadBackInc,LoadBackY); PutDrawEnv(&Screen[FrameFlipFlag^1].Draw); DrawPrim(PolyPtr); LoadTime++; if (LoadTime>=LoadTabSize) LoadTime=0; } /*****************************************************************************/ void SetUpLoadIcon(void *_fh) { sFrameHdr *fh=(sFrameHdr*)_fh; setPolyFT4(&LoadPoly); setXYWH(&LoadPoly,LoadX,LoadY,fh->W,fh->H); setUVWH(&LoadPoly,fh->U,fh->V,fh->W,fh->H); LoadPoly.tpage=fh->TPage; LoadPoly.clut=fh->Clut; LoadHalfWidth=fh->W/2; LoadBackRect.w=fh->W+(LoadBackInc*2); LoadBackRect.h=fh->H; } /*****************************************************************************/ void StartLoad(int _loadX,int _loadY) { SYSTEM_DBGMSG("Start Load"); if (_loadX!=-1) LoadX=_loadX; if (_loadY!=-1) LoadY=_loadY; Screen[0].Draw.isbg=Screen[1].Draw.isbg=0; PutDrawEnv(&Screen[FrameFlipFlag^1].Draw); PutDispEnv(&Screen[FrameFlipFlag].Disp); LoadBackRect.x=LoadX-LoadBackInc; LoadBackRect.y=LoadY+((FrameFlipFlag)*256);; LoadBackY=LoadY+((FrameFlipFlag^1)*256); LoadTime=0; DrawLoadIcon=1; LoadIconSide=0; } /*****************************************************************************/ void StopLoad() { #if defined(__USER_CDBUILD__) while(LoadTime) { VSync(0); } #endif Screen[0].Draw.isbg=Screen[1].Draw.isbg=1; DrawLoadIcon=0; SYSTEM_DBGMSG("Stop Load"); } /*****************************************************************************/ /*** VSync *******************************************************************/ /*****************************************************************************/ extern "C" { static void VidVSyncCallback() { int i; FrameCounter++; TickCount++; if (DrawLoadIcon) LoadingIcon(); if (VbFunc) { VbFunc(); VbFunc = NULL; } for (i=0; i< MaxVBFuncs; i++) if (VbFuncList[i]) VbFuncList[i](); } } /*****************************************************************************/ void VidAddVSyncFunc(VbFuncType v) { int i; for (i=0; idisp.x=0; Disp->disp.y=ScrH; Disp->disp.w=ScreenW; Disp->disp.h=ScreenH; Disp->screen.x=ScreenXOfs; Disp->screen.y=ScreenYOfs; Disp->screen.w=256; Disp->screen.h=256; PutDispEnv(Disp); PutDrawEnv(Draw); // If set, load background screen if (ScreenImage) { LoadImage(&Screen[LastFrame].Disp.disp ,(u_long*)ScreenImage); DrawSync(0); } if(ScreenClipBox==1) { DrawLine(15,25,ScreenW-15,25,255,0,0,0); DrawLine(15,ScreenH-25,ScreenW-15,ScreenH-25,255,0,0,0); DrawLine(15,25,15,ScreenH-25,255,0,0,0); DrawLine(ScreenW-15,25,ScreenW-15,ScreenH-25,255,0,0,0); DrawLine(0,0,511,0,0,255,0,0); DrawLine(0,255,511,255,0,255,0,0); DrawLine(0,0,0,255,0,255,0,0); DrawLine(511,0,511,255,0,255,0,0); } if(ScreenClipBox==2) { POLY_F4 *f4; f4=GetPrimF4(); setXYWH(f4,0,0,ScreenW,20); setRGB0(f4,50,50,50); AddPrimToList(f4,0); f4=GetPrimF4(); setXYWH(f4,0,ScreenH-20,ScreenW,20); setRGB0(f4,50,50,50); AddPrimToList(f4,0); f4=GetPrimF4(); setXYWH(f4,ScreenW-10,20,10,ScreenH-40); setRGB0(f4,50,50,50); AddPrimToList(f4,0); f4=GetPrimF4(); setXYWH(f4,0,20,10,ScreenH-40); setRGB0(f4,50,50,50); AddPrimToList(f4,0); } // How many frames since we last flipped the display? int fc=FrameCounter; s_vblsThisFrame=fc-s_lastFrameCounter; s_lastFrameCounter=fc; // Can get 0 vbls during start up, and it breaks things if(s_vblsThisFrame==0) { s_vblsThisFrame=1; } } /*****************************************************************************/ u8 *LoadPakScreen(int Filename) { u8 *PakData=CFileIO::loadFile((FileEquate)Filename,"PakScreen"); u8 *Screen=(u8*)MemAlloc(512*256*2,"Screen"); LZNP_Decode(PakData,Screen); MemFree(PakData); return(Screen); } /*****************************************************************************/ /*** VRAM VIEWER *************************************************************/ /*****************************************************************************/ #define UseVRamViewer #ifdef UseVRamViewer #include "pad\pads.H" void VRamViewer() { bool Done=0; sVidScreen *Scr=VidGetScreen(); u16 Pad; int OldX=Scr->Disp.disp.x,OldY=Scr->Disp.disp.y; while(!Done) { PadUpdate(); DbgPollHost(); Pad=PadGetHeld(0); #ifdef __USER_paul__ // my finger was hurting.. if((PadGetDown(0) & PAD_SELECT)) Done=1; #else if(!(Pad & PAD_SELECT)) Done=1; #endif if(Pad&PAD_LEFT) if(Scr->Disp.disp.x) Scr->Disp.disp.x--; if(Pad&PAD_RIGHT) if(Scr->Disp.disp.x<1024-ScreenW) Scr->Disp.disp.x++; if(Pad&PAD_UP) if(Scr->Disp.disp.y) Scr->Disp.disp.y--; if(Pad&PAD_DOWN) if(Scr->Disp.disp.y<512-ScreenH) Scr->Disp.disp.y++; PutDispEnv(&Scr->Disp); PutDrawEnv(&Scr->Draw); } Scr->Disp.disp.x=OldX; Scr->Disp.disp.y=OldY; } #endif