From 25a67211e8aede42e713cc2324d70be8d256d260 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sun, 2 Nov 2008 14:07:27 +0000 Subject: [PATCH] Changed some GS-related #define macros into more type-safe inline'd functions. git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@274 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/FiFo.c | 2 +- pcsx2/GS.cpp | 22 ++++--- pcsx2/GS.h | 144 ++++++++++++++----------------------------- pcsx2/x86/iVUmicro.c | 63 +++++++++++++++++++ 4 files changed, 124 insertions(+), 107 deletions(-) diff --git a/pcsx2/FiFo.c b/pcsx2/FiFo.c index 8771863fc4..4f2d60163a 100644 --- a/pcsx2/FiFo.c +++ b/pcsx2/FiFo.c @@ -138,7 +138,7 @@ void WriteFIFO(u32 mem, u64 *value) { data[0] = value[0]; data[1] = value[1]; GSgifTransferDummy(2, (u32*)data, 1); - GSRINGBUF_DONECOPY(data, 16); + GSRINGBUF_DONECOPY((u8*)data, 16); if( !CHECK_DUALCORE ) { #if defined(_WIN32) && !defined(WIN32_PTHREADS) diff --git a/pcsx2/GS.cpp b/pcsx2/GS.cpp index 4c0c40d6d2..db37d9cd02 100644 --- a/pcsx2/GS.cpp +++ b/pcsx2/GS.cpp @@ -730,13 +730,17 @@ typedef void (*GIFRegHandler)(u32* data); static GIFRegHandler s_GSHandlers[3] = { GSRegHandlerSIGNAL, GSRegHandlerFINISH, GSRegHandlerLABEL }; extern "C" int Path3transfer; -#define TagPathTransfer /*midnight madness cares because the tag is 5 dwords*/ \ - int* psrc = (int*)ptag; \ - int* pdst = (int*)&g_path[path]; \ - pdst[0] = psrc[0]; \ - pdst[1] = psrc[1]; \ - pdst[2] = psrc[2]; \ +/*midnight madness cares because the tag is 5 dwords*/ \ +static __forceinline void TagPathTransfer( GIFTAG* ptag, GIFTAG *path ) +{ + u32* psrc = (u32*)ptag; + u32* pdst = (u32*)path; + pdst[0] = psrc[0]; + pdst[1] = psrc[1]; + pdst[2] = psrc[2]; pdst[3] = psrc[3]; +} + // simulates a GIF tag u32 GSgifTransferDummy(int path, u32 *pMem, u32 size) @@ -827,7 +831,7 @@ u32 GSgifTransferDummy(int path, u32 *pMem, u32 size) if( nloop > 0 ) { assert(size == 0); - TagPathTransfer; + TagPathTransfer( ptag, &g_path[path] ); g_path[path].nloop = nloop; g_path[path].curreg = curreg; return 0; @@ -865,7 +869,7 @@ u32 GSgifTransferDummy(int path, u32 *pMem, u32 size) if( nloop > 0 ) { assert(size == 0); - TagPathTransfer; + TagPathTransfer( ptag, &g_path[path] ); g_path[path].nloop = nloop; g_path[path].curreg = curreg; return 0; @@ -878,7 +882,7 @@ u32 GSgifTransferDummy(int path, u32 *pMem, u32 size) { // simulate if( (int)size < nloop ) { - TagPathTransfer; + TagPathTransfer( ptag, &g_path[path] ); g_path[path].nloop = nloop-size; return 0; } diff --git a/pcsx2/GS.h b/pcsx2/GS.h index 9c2245c5a5..ba694b28cd 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -26,8 +26,8 @@ typedef struct { - u32 SIGID; - u32 LBLID; + u32 SIGID; + u32 LBLID; } GSRegSIGBLID; #define GSPATH3FIX @@ -43,21 +43,21 @@ extern u8 g_RealGSMem[0x2000]; #define GSSIGLBLID ((GSRegSIGBLID*)(g_RealGSMem+0x1080)) #endif -#define GS_RINGBUFFERBASE (u8*)(0x10200000) -#define GS_RINGBUFFERSIZE 0x00300000 // 3Mb -#define GS_RINGBUFFEREND (u8*)(GS_RINGBUFFERBASE+GS_RINGBUFFERSIZE) +#define GS_RINGBUFFERBASE (u8*)(0x10200000) +#define GS_RINGBUFFERSIZE 0x00300000 // 3Mb +#define GS_RINGBUFFEREND (u8*)(GS_RINGBUFFERBASE+GS_RINGBUFFERSIZE) #define GS_RINGTYPE_RESTART 0 -#define GS_RINGTYPE_P1 1 -#define GS_RINGTYPE_P2 2 -#define GS_RINGTYPE_P3 3 -#define GS_RINGTYPE_VSYNC 4 -#define GS_RINGTYPE_VIFFIFO 5 // GSreadFIFO2 -#define GS_RINGTYPE_FRAMESKIP 6 -#define GS_RINGTYPE_MEMWRITE8 7 -#define GS_RINGTYPE_MEMWRITE16 8 -#define GS_RINGTYPE_MEMWRITE32 9 -#define GS_RINGTYPE_MEMWRITE64 10 +#define GS_RINGTYPE_P1 1 +#define GS_RINGTYPE_P2 2 +#define GS_RINGTYPE_P3 3 +#define GS_RINGTYPE_VSYNC 4 +#define GS_RINGTYPE_VIFFIFO 5 // GSreadFIFO2 +#define GS_RINGTYPE_FRAMESKIP 6 +#define GS_RINGTYPE_MEMWRITE8 7 +#define GS_RINGTYPE_MEMWRITE16 8 +#define GS_RINGTYPE_MEMWRITE32 9 +#define GS_RINGTYPE_MEMWRITE64 10 #define GS_RINGTYPE_SAVE 11 #define GS_RINGTYPE_LOAD 12 #define GS_RINGTYPE_RECORD 13 @@ -73,34 +73,23 @@ extern u8* g_pGSWritePos; extern FILE* g_fMTGSWrite, *g_fMTGSRead; extern u32 g_MTGSDebug, g_MTGSId; -#define MTGS_RECWRITE(start, size) { \ - if( g_MTGSDebug & 1 ) { \ - u32* pstart = (u32*)(start); \ - u32 cursize = (u32)(size); \ - fprintf(g_fMTGSWrite, "*%x-%x (%d)\n", (u32)(uptr)(start), (u32)(size), ++g_MTGSId); \ - /*while(cursize > 0) { \ - fprintf(g_fMTGSWrite, "%x %x %x %x\n", pstart[0], pstart[1], pstart[2], pstart[3]); \ - pstart += 4; \ - cursize -= 16; \ - }*/ \ - if( g_MTGSDebug & 2 ) fflush(g_fMTGSWrite); \ - } \ -} \ - -#define MTGS_RECREAD(start, size) { \ - if( g_MTGSDebug & 1 ) { \ - u32* pstart = (u32*)(start); \ - u32 cursize = (u32)(size); \ - fprintf(g_fMTGSRead, "*%x-%x (%d)\n", (u32)(uptr)(start), (u32)(size), ++g_MTGSId); \ - /*while(cursize > 0) { \ - fprintf(g_fMTGSRead, "%x %x %x %x\n", pstart[0], pstart[1], pstart[2], pstart[3]); \ - pstart += 4; \ - cursize -= 16; \ - }*/ \ - if( g_MTGSDebug & 4 ) fflush(g_fMTGSRead); \ - } \ -} \ +static __forceinline void MTGS_RECWRITE(const u8 *start, u32 size) { + if( g_MTGSDebug & 1 ) { + const u32* pstart = (u32*)(start); + u32 cursize = (size); + fprintf(g_fMTGSWrite, "*%x-%x (%d)\n", (u32)(uptr)(start), (u32)(size), ++g_MTGSId); + if( g_MTGSDebug & 2 ) fflush(g_fMTGSWrite); + } +} +static __forceinline void MTGS_RECREAD( const u8* start, u32 size) { + if( g_MTGSDebug & 1 ) { + const u32* pstart = (u32*)(start); + u32 cursize = (size); + fprintf(g_fMTGSRead, "*%x-%x (%d)\n", (u32)(uptr)(start), (u32)(size), ++g_MTGSId); + if( g_MTGSDebug & 4 ) fflush(g_fMTGSRead); + } +} #else #define MTGS_RECWRITE 0&& @@ -109,21 +98,25 @@ extern u32 g_MTGSDebug, g_MTGSId; #endif // mem and size are the ones from GSRingBufCopy -#define GSRINGBUF_DONECOPY(mem, size) { \ - u8* temp = (u8*)(mem) + (size); \ - assert( temp <= GS_RINGBUFFEREND); \ - MTGS_RECWRITE(mem, size); \ - if( temp == GS_RINGBUFFEREND ) temp = GS_RINGBUFFERBASE; \ - InterlockedExchangePointer((void**)&g_pGSWritePos, temp); \ +static __forceinline void GSRINGBUF_DONECOPY(const u8 *mem, u32 size) { + u8* temp = (u8*)(mem) + (size); + assert( temp <= GS_RINGBUFFEREND); + MTGS_RECWRITE(mem, size); + if( temp == GS_RINGBUFFEREND ) temp = GS_RINGBUFFERBASE; + InterlockedExchangePointer((void**)&g_pGSWritePos, temp); } #if defined(_WIN32) && !defined(WIN32_PTHREADS) + #define GS_SETEVENT() SetEvent(g_hGsEvent) + #else + #include #include extern sem_t g_semGsThread; #define GS_SETEVENT() sem_post(&g_semGsThread) + #endif u32 GSgifTransferDummy(int path, u32 *pMem, u32 size); @@ -184,56 +177,13 @@ extern int g_SaveGSStream; extern int g_nLeftGSFrames; extern gzFile g_fGSSave; -#define GSGIFTRANSFER1(pMem, addr) { \ - if( g_SaveGSStream == 2) { \ - int type = GSRUN_TRANS1; \ - int size = (0x4000-(addr))/16; \ - gzwrite(g_fGSSave, &type, sizeof(type)); \ - gzwrite(g_fGSSave, &size, 4); \ - gzwrite(g_fGSSave, ((u8*)pMem)+(addr), size*16); \ - } \ - GSgifTransfer1(pMem, addr); \ -} - -#define GSGIFTRANSFER2(pMem, size) { \ - if( g_SaveGSStream == 2) { \ - int type = GSRUN_TRANS2; \ - int _size = size; \ - gzwrite(g_fGSSave, &type, sizeof(type)); \ - gzwrite(g_fGSSave, &_size, 4); \ - gzwrite(g_fGSSave, pMem, _size*16); \ - } \ - GSgifTransfer2(pMem, size); \ -} - - -#define GSGIFTRANSFER3(pMem, size) { \ - if( g_SaveGSStream == 2 ) { \ - int type = GSRUN_TRANS3; \ - int _size = size; \ - gzwrite(g_fGSSave, &type, sizeof(type)); \ - gzwrite(g_fGSSave, &_size, 4); \ - gzwrite(g_fGSSave, pMem, _size*16); \ - } \ - GSgifTransfer3(pMem, size); \ -} - -#define GSVSYNC() { \ - if( g_SaveGSStream == 2 ) { \ - int type = GSRUN_VSYNC; \ - gzwrite(g_fGSSave, &type, sizeof(type)); \ - } \ -} \ - -#else - -#define GSGIFTRANSFER1(pMem, size) GSgifTransfer1(pMem, size) -#define GSGIFTRANSFER2(pMem, size) GSgifTransfer2(pMem, size) -#define GSGIFTRANSFER3(pMem, size) GSgifTransfer3(pMem, size) -#define GSVSYNC() - #endif void RunGSState(gzFile f); -#endif \ No newline at end of file +extern void GSGIFTRANSFER1(u32 *pMem, u32 addr); +extern void GSGIFTRANSFER2(u32 *pMem, u32 addr); +extern void GSGIFTRANSFER3(u32 *pMem, u32 addr); +extern void GSVSYNC(); + +#endif diff --git a/pcsx2/x86/iVUmicro.c b/pcsx2/x86/iVUmicro.c index 0baa691729..6dc065d818 100644 --- a/pcsx2/x86/iVUmicro.c +++ b/pcsx2/x86/iVUmicro.c @@ -47,6 +47,69 @@ extern _GSgifTransfer1 GSgifTransfer1; +#ifdef PCSX2_DEVBUILD + +// These would amke more sense in GS.cpp, but then the legacy "C" files +// (like this one!) wouldn't be able to access them (C++ name mangling) + +__forceinline void GSGIFTRANSFER1(u32 *pMem, u32 addr) { + if( g_SaveGSStream == 2) { + u32 type = GSRUN_TRANS1; + u32 size = (0x4000-(addr))/16; + gzwrite(g_fGSSave, &type, sizeof(type)); + gzwrite(g_fGSSave, &size, 4); + gzwrite(g_fGSSave, ((u8*)pMem)+(addr), size*16); + } + GSgifTransfer1(pMem, addr); +} + +__forceinline void GSGIFTRANSFER2(u32 *pMem, u32 size) { + if( g_SaveGSStream == 2) { + u32 type = GSRUN_TRANS2; + u32 _size = size; + gzwrite(g_fGSSave, &type, sizeof(type)); + gzwrite(g_fGSSave, &_size, 4); + gzwrite(g_fGSSave, pMem, _size*16); + } + GSgifTransfer2(pMem, size); +} + +__forceinline void GSGIFTRANSFER3(u32 *pMem, u32 size) { + if( g_SaveGSStream == 2 ) { + u32 type = GSRUN_TRANS3; + u32 _size = size; + gzwrite(g_fGSSave, &type, sizeof(type)); + gzwrite(g_fGSSave, &_size, 4); + gzwrite(g_fGSSave, pMem, _size*16); + } + GSgifTransfer3(pMem, size); +} + +__forceinline void GSVSYNC(void) { + if( g_SaveGSStream == 2 ) { + u32 type = GSRUN_VSYNC; + gzwrite(g_fGSSave, &type, sizeof(type)); + } +} + +#else + +__forceinline void GSGIFTRANSFER1(const u32 *pMem, u32 addr) { + GSgifTransfer1(pMem, addr); +} + +__forceinline void GSGIFTRANSFER2(u32 *pMem, u32 size) { + GSgifTransfer2(pMem, size); +} + +__forceinline void GSGIFTRANSFER3(const u32 *pMem, u32 size) { + GSgifTransfer3(pMem, size); +} + +__forceinline void GSVSYNC(void) { +} +#endif + int g_VuNanHandling = 0; // for now enable all the time int vucycle;