diff --git a/pcsx2/GS.h b/pcsx2/GS.h index 727a56d5f3..849d2b5233 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -134,8 +134,7 @@ enum GS_RINGTYPE , GS_RINGTYPE_MEMWRITE16 , GS_RINGTYPE_MEMWRITE32 , GS_RINGTYPE_MEMWRITE64 -, GS_RINGTYPE_SAVE -, GS_RINGTYPE_LOAD +, GS_RINGTYPE_FREEZE , GS_RINGTYPE_RECORD , GS_RINGTYPE_RESET // issues a GSreset() command. , GS_RINGTYPE_SOFTRESET // issues a soft reset for the GIF diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 6f5c2408dd..f55af22b7f 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -526,11 +526,12 @@ int mtgsThreadObject::Callback() *(u64*)(m_gsMem+*(u32*)(m_RingPos+4)) = *(u64*)(m_RingPos+8); break; - case GS_RINGTYPE_SAVE: - case GS_RINGTYPE_LOAD: + case GS_RINGTYPE_FREEZE: { - SaveState* f = (SaveState*)(*(uptr*)(m_RingPos+8)); - f->FreezePlugin( "GS", GSfreeze ); + //SaveState* f = (SaveState*)(*(uptr*)(m_RingPos+8)); + freezeData* data = (freezeData*)(*(uptr*)(m_RingPos+8)); + int mode = *(s32*)(m_RingPos+4); + GSfreeze( mode, data ); break; } diff --git a/pcsx2/Misc.cpp b/pcsx2/Misc.cpp index 7f9c2a6eb1..508be96c84 100644 --- a/pcsx2/Misc.cpp +++ b/pcsx2/Misc.cpp @@ -434,7 +434,7 @@ void LoadGSState(const string& file) f->Freeze(g_nLeftGSFrames); f->gsFreeze(); - f->FreezePlugin( "GS", GSfreeze ); + f->FreezePlugin( "GS", gsSafeFreeze ); RunGSState( *f ); diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index c0f0193851..7c2778f119 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -86,6 +86,25 @@ SaveState::SaveState( const char* msg, const string& destination ) : m_version( Console::WriteLn( "%s %S", params msg, &destination ); } +s32 CALLBACK gsSafeFreeze( int mode, freezeData *data ) +{ + if( mtgsThread != NULL ) + { + if( mode == 2 ) + return GSfreeze( 2, data ); + + // have to call in thread, otherwise weird stuff will start happening + mtgsThread->SendPointerPacket( GS_RINGTYPE_FREEZE, mode, data ); + mtgsWaitGS(); + return 0; + } + else + { + // Single threaded... + return GSfreeze( mode, data ); + } +} + void SaveState::FreezeAll() { if( IsLoading() ) @@ -136,14 +155,7 @@ void SaveState::FreezeAll() psxRcntFreeze(); sio2Freeze(); - if( mtgsThread != NULL ) { - // have to call in thread, otherwise weird stuff will start happening - mtgsThread->SendPointerPacket( GS_RINGTYPE_SAVE, 0, this ); - mtgsWaitGS(); - } - else { - FreezePlugin( "GS", GSfreeze ); - } + FreezePlugin( "GS", gsSafeFreeze ); FreezePlugin( "SPU2", SPU2freeze ); FreezePlugin( "DEV9", DEV9freeze ); FreezePlugin( "USB", USBfreeze ); @@ -298,6 +310,8 @@ memBaseStateInfo::memBaseStateInfo( MemoryAlloc& memblock, const char* msg ) , m_memory( memblock ) , m_idx( 0 ) { + // Always clear the MTGS thread state. + mtgsWaitGS(); } memSavingState::memSavingState( MemoryAlloc& save_to ) : memBaseStateInfo( save_to, _("Saving state to: ") ) diff --git a/pcsx2/SaveState.h b/pcsx2/SaveState.h index ee8315b346..eae4479bd8 100644 --- a/pcsx2/SaveState.h +++ b/pcsx2/SaveState.h @@ -35,6 +35,10 @@ static const u32 g_SaveVersion = 0x7a300011; static const u32 g_SaveVersion = 0x8b400001; #endif +// this function is meant to be sued in the place of GSfreeze, and provides a safe layer +// between the GS saving function and the MTGS's needs. :) +extern s32 CALLBACK gsSafeFreeze( int mode, freezeData *data ); + // This class provides the base API for both loading and saving savestates. // Normally you'll want to use one of the four "functional" derrived classes rather // than this class directly: gzLoadingState, gzSavingState (gzipped disk-saved diff --git a/pcsx2/windows/WinMain.cpp b/pcsx2/windows/WinMain.cpp index 942049d2ac..8e83caf394 100644 --- a/pcsx2/windows/WinMain.cpp +++ b/pcsx2/windows/WinMain.cpp @@ -50,6 +50,9 @@ #include "implement.h" // pthreads-win32 defines for startup/shutdown +// Disabled warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc +#pragma warning(disable:4530) + bool AccBreak = false; unsigned int langsMax; diff --git a/pcsx2/windows/WinSysExec.cpp b/pcsx2/windows/WinSysExec.cpp index e47d33d21e..b8bfdd1564 100644 --- a/pcsx2/windows/WinSysExec.cpp +++ b/pcsx2/windows/WinSysExec.cpp @@ -298,7 +298,7 @@ void RunGuiAndReturn() { if( g_gsRecoveryState != NULL ) { memLoadingState eddie( *g_gsRecoveryState ); - eddie.FreezePlugin( "GS", GSfreeze ); + eddie.FreezePlugin( "GS", gsSafeFreeze ); eddie.gsFreeze(); safe_delete( g_gsRecoveryState ); @@ -338,7 +338,7 @@ public: void FreezePlugin( const char* name, s32 (CALLBACK* freezer)(int mode, freezeData *data) ) { - if( (freezer == GSfreeze) && (g_gsRecoveryState != NULL) ) + if( (freezer == gsSafeFreeze) && (g_gsRecoveryState != NULL) ) { // Gs data is already in memory, so just copy from src to dest: // length of the GS data is stored as the first u32, so use that to run the copy: @@ -379,7 +379,7 @@ public: void FreezePlugin( const char* name, s32 (CALLBACK* freezer)(int mode, freezeData *data) ) { - if( (freezer == GSfreeze) && (g_gsRecoveryState != NULL) ) + if( (freezer == gsSafeFreeze) && (g_gsRecoveryState != NULL) ) { // Gs data is already in memory, so just copy from there into the gzip file. // length of the GS data is stored as the first u32, so use that to run the copy: @@ -672,7 +672,7 @@ void CALLBACK KeyEvent(keyEvent* ev) safe_delete( g_RecoveryState ); g_gsRecoveryState = new MemoryAlloc(); JustGsSavingState eddie; - eddie.FreezePlugin( "GS", GSfreeze ) ; + eddie.FreezePlugin( "GS", gsSafeFreeze ) ; eddie.gsFreeze(); PluginsResetGS(); } @@ -702,7 +702,6 @@ void SysRestorableReset() try { - SetCursor( LoadCursor( gApp.hInstance, IDC_APPSTARTING ) ); g_RecoveryState = new MemoryAlloc( "Memory Savestate Recovery" ); RecoveryMemSavingState().FreezeAll(); safe_delete( g_gsRecoveryState ); diff --git a/pcsx2/x86/iHw.cpp b/pcsx2/x86/iHw.cpp index 8de6679629..5dac1c31e3 100644 --- a/pcsx2/x86/iHw.cpp +++ b/pcsx2/x86/iHw.cpp @@ -287,7 +287,7 @@ int hwConstRead32(u32 x86reg, u32 mem) return 1; case 0x10000010: _eeReadConstMem32(x86reg, (uptr)&counters[0].mode); - EECNT_LOG("Counter 0 mode read = %x\n", counters[0].mode); + EECNT_LOG("Counter 0 mode read = %x\n", counters[0].modeval); return 0; case 0x10000020: _eeReadConstMem32(x86reg, (uptr)&counters[0].target); @@ -306,7 +306,7 @@ int hwConstRead32(u32 x86reg, u32 mem) return 1; case 0x10000810: _eeReadConstMem32(x86reg, (uptr)&counters[1].mode); - EECNT_LOG("Counter 1 mode read = %x\n", counters[1].mode); + EECNT_LOG("Counter 1 mode read = %x\n", counters[1].modeval); return 0; case 0x10000820: _eeReadConstMem32(x86reg, (uptr)&counters[1].target); @@ -325,7 +325,7 @@ int hwConstRead32(u32 x86reg, u32 mem) return 1; case 0x10001010: _eeReadConstMem32(x86reg, (uptr)&counters[2].mode); - EECNT_LOG("Counter 2 mode read = %x\n", counters[2].mode); + EECNT_LOG("Counter 2 mode read = %x\n", counters[2].modeval); return 0; case 0x10001020: _eeReadConstMem32(x86reg, (uptr)&counters[2].target); @@ -346,7 +346,7 @@ int hwConstRead32(u32 x86reg, u32 mem) return 1; case 0x10001810: _eeReadConstMem32(x86reg, (uptr)&counters[3].mode); - EECNT_LOG("Counter 3 mode read = %x\n", counters[3].mode); + EECNT_LOG("Counter 3 mode read = %x\n", counters[3].modeval); return 0; case 0x10001820: _eeReadConstMem32(x86reg, (uptr)&counters[3].target);