Allow reset to work correctly in sync core

This commit is contained in:
zilmar 2012-12-19 10:55:05 +11:00
parent d3c946891b
commit ab03a0d10e
7 changed files with 74 additions and 45 deletions

View File

@ -200,7 +200,7 @@ Serial_InterfaceReg::Serial_InterfaceReg(DWORD * SerialInterface) :
{ {
} }
CRegisters::CRegisters (void) : CRegisters::CRegisters(CN64System * System, CSystemEvents * SystemEvents) :
CP0registers(m_CP0), CP0registers(m_CP0),
Rdram_InterfaceReg(m_RDRAM_Registers), Rdram_InterfaceReg(m_RDRAM_Registers),
Mips_InterfaceReg(m_Mips_Interface), Mips_InterfaceReg(m_Mips_Interface),
@ -210,7 +210,9 @@ CRegisters::CRegisters (void) :
RDRAMInt_InterfaceReg(m_RDRAM_Interface), RDRAMInt_InterfaceReg(m_RDRAM_Interface),
SigProcessor_InterfaceReg(m_SigProcessor_Interface), SigProcessor_InterfaceReg(m_SigProcessor_Interface),
DisplayControlReg(m_Display_ControlReg), DisplayControlReg(m_Display_ControlReg),
Serial_InterfaceReg(m_SerialInterface) Serial_InterfaceReg(m_SerialInterface),
m_System(System),
m_SystemEvents(SystemEvents)
{ {
Reset(); Reset();
} }
@ -264,7 +266,7 @@ void CRegisters::SetAsCurrentSystem ( void )
void CRegisters::CheckInterrupts ( void ) void CRegisters::CheckInterrupts ( void )
{ {
if (!g_System->bFixedAudio() && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_SyncCores) { if (!m_System->bFixedAudio() && (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_SyncCores) {
MI_INTR_REG &= ~MI_INTR_AI; MI_INTR_REG &= ~MI_INTR_AI;
MI_INTR_REG |= (m_AudioIntrReg & MI_INTR_AI); MI_INTR_REG |= (m_AudioIntrReg & MI_INTR_AI);
} }
@ -289,7 +291,7 @@ void CRegisters::CheckInterrupts ( void )
g_Recompiler->ClearRecompCode_Virt(0x80000000,0x200,CRecompiler::Remove_InitialCode); g_Recompiler->ClearRecompCode_Virt(0x80000000,0x200,CRecompiler::Remove_InitialCode);
} }
} }
g_SystemEvents->QueueEvent(SysEvent_ExecuteInterrupt); m_SystemEvents->QueueEvent(SysEvent_ExecuteInterrupt);
} }
} }

View File

@ -459,6 +459,9 @@ protected:
static ROUNDING_MODE * _RoundingModel; static ROUNDING_MODE * _RoundingModel;
}; };
class CN64System;
class CSystemEvents;
class CRegisters: class CRegisters:
protected CSystemRegisters, protected CSystemRegisters,
public CP0registers, public CP0registers,
@ -473,7 +476,7 @@ class CRegisters:
public Serial_InterfaceReg public Serial_InterfaceReg
{ {
public: public:
CRegisters(); CRegisters(CN64System * System, CSystemEvents * SystemEvents);
//General Registers //General Registers
DWORD m_PROGRAM_COUNTER; DWORD m_PROGRAM_COUNTER;
@ -517,6 +520,11 @@ public:
void SetAsCurrentSystem ( void ); void SetAsCurrentSystem ( void );
private: private:
bool m_FirstInterupt; CRegisters(void); // Disable default constructor
CRegisters(const CRegisters&); // Disable copy constructor
CRegisters& operator=(const CRegisters&); // Disable assignment
bool m_FirstInterupt;
CN64System * m_System;
CSystemEvents * m_SystemEvents;
}; };

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
CSystemEvents::CSystemEvents() : CSystemEvents::CSystemEvents(CN64System * System) :
m_bDoSomething(false) m_bDoSomething(false),
m_System(System)
{ {
} }
@ -26,43 +27,43 @@ void CSystemEvents::QueueEvent(SystemEvent action)
void CSystemEvents::ExecuteEvents ( void ) void CSystemEvents::ExecuteEvents ( void )
{ {
CGuard Guard(m_CS); EventList Events;
m_bDoSomething = false;
if (m_Events.size() == 0)
{ {
return; CGuard Guard(m_CS);
}
m_bDoSomething = false;
if (m_Events.size() == 0)
{
return;
}
EventList Events = m_Events; Events = m_Events;
m_Events.clear(); m_Events.clear();
}
bool bPause = false, bLoadedSave = false; bool bPause = false, bLoadedSave = false;
for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++ ) for (EventList::const_iterator iter = Events.begin(); !bLoadedSave && iter != Events.end(); iter++ )
{ {
switch (*iter) switch (*iter)
{ {
case SysEvent_CloseCPU: case SysEvent_CloseCPU:
g_System->m_EndEmulation = true; m_System->m_EndEmulation = true;
break; break;
case SysEvent_ResetCPU_Soft: case SysEvent_ResetCPU_Soft:
g_SystemTimer->SetTimer(CSystemTimer::SoftResetTimer,0x3000000,false); m_System->GameReset();
g_Plugins->Gfx()->ShowCFB();
g_Reg->FAKE_CAUSE_REGISTER |= CAUSE_IP4;
g_Reg->CheckInterrupts();
g_Plugins->Gfx()->SoftReset();
break; break;
case SysEvent_ResetCPU_SoftDone: case SysEvent_ResetCPU_SoftDone:
g_System->Reset(true,false); m_System->Reset(true,false);
break; break;
case SysEvent_ResetCPU_Hard: case SysEvent_ResetCPU_Hard:
g_System->Reset(true,true); m_System->Reset(true,true);
break; break;
case SysEvent_Profile_GenerateLogs: case SysEvent_Profile_GenerateLogs:
g_BaseSystem->m_Profile.GenerateLog(); m_System->m_Profile.GenerateLog();
break; break;
case SysEvent_Profile_StartStop: case SysEvent_Profile_StartStop:
case SysEvent_Profile_ResetLogs: case SysEvent_Profile_ResetLogs:
g_System->m_Profile.ResetCounters(); m_System->m_Profile.ResetCounters();
break; break;
case SysEvent_ExecuteInterrupt: case SysEvent_ExecuteInterrupt:
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
@ -92,14 +93,14 @@ void CSystemEvents::ExecuteEvents ( void )
g_Reg->DoIntrException(false); g_Reg->DoIntrException(false);
break; break;
case SysEvent_SaveMachineState: case SysEvent_SaveMachineState:
if (!g_System->SaveState()) if (!m_System->SaveState())
{ {
m_Events.push_back(SysEvent_SaveMachineState); m_Events.push_back(SysEvent_SaveMachineState);
m_bDoSomething = true; m_bDoSomething = true;
} }
break; break;
case SysEvent_LoadMachineState: case SysEvent_LoadMachineState:
if (g_System->LoadState()) if (m_System->LoadState())
{ {
bLoadedSave = true; bLoadedSave = true;
} }
@ -111,11 +112,9 @@ void CSystemEvents::ExecuteEvents ( void )
g_Notify->ChangeFullScreen(); g_Notify->ChangeFullScreen();
break; break;
case SysEvent_GSButtonPressed: case SysEvent_GSButtonPressed:
if (g_BaseSystem == NULL) if (m_System->m_Cheats.CheatsSlectionChanged())
return; m_System->m_Cheats.LoadCheats(false);
if (g_BaseSystem->m_Cheats.CheatsSlectionChanged()) m_System->m_Cheats.ApplyGSButton(g_MMU);
g_BaseSystem->m_Cheats.LoadCheats(false);
g_BaseSystem->m_Cheats.ApplyGSButton(g_MMU);
break; break;
case SysEvent_PauseCPU_FromMenu: case SysEvent_PauseCPU_FromMenu:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
@ -181,7 +180,7 @@ void CSystemEvents::ExecuteEvents ( void )
if (bPause) if (bPause)
{ {
g_BaseSystem->Pause(); m_System->Pause();
} }
} }

View File

@ -40,7 +40,7 @@ class CSystemEvents
typedef std::vector<SystemEvent> EventList; typedef std::vector<SystemEvent> EventList;
protected: protected:
CSystemEvents(); CSystemEvents(CN64System * System);
virtual ~CSystemEvents(); virtual ~CSystemEvents();
public: public:
@ -50,9 +50,14 @@ public:
inline const BOOL & DoSomething ( void ) const { return m_bDoSomething; } inline const BOOL & DoSomething ( void ) const { return m_bDoSomething; }
private: private:
CSystemEvents(void); // Disable default constructor
CSystemEvents(const CSystemEvents&); // Disable copy constructor
CSystemEvents& operator=(const CSystemEvents&); // Disable assignment
void ChangePluginFunc( void ); void ChangePluginFunc( void );
EventList m_Events; CN64System * m_System;
BOOL m_bDoSomething; EventList m_Events;
BOOL m_bDoSomething;
CriticalSection m_CS; CriticalSection m_CS;
}; };

View File

@ -5,6 +5,8 @@
#include <windows.h> #include <windows.h>
CN64System::CN64System ( CPlugins * Plugins, bool SavesReadOnly ) : CN64System::CN64System ( CPlugins * Plugins, bool SavesReadOnly ) :
CSystemEvents(this),
m_Reg(this,this),
m_MMU_VM(this,SavesReadOnly), m_MMU_VM(this,SavesReadOnly),
m_TLB(this), m_TLB(this),
m_FPS(g_Notify), m_FPS(g_Notify),
@ -68,16 +70,10 @@ void CN64System::ExternalEvent ( SystemEvent action )
case SysEvent_Interrupt_VI: case SysEvent_Interrupt_VI:
case SysEvent_Interrupt_PI: case SysEvent_Interrupt_PI:
case SysEvent_Interrupt_DP: case SysEvent_Interrupt_DP:
QueueEvent(action);
break;
case SysEvent_ResetCPU_Hard: case SysEvent_ResetCPU_Hard:
case SysEvent_ResetCPU_Soft: case SysEvent_ResetCPU_Soft:
case SysEvent_CloseCPU: case SysEvent_CloseCPU:
QueueEvent(action); QueueEvent(action);
if (m_SyncCPU)
{
m_SyncCPU->QueueEvent(action);
}
break; break;
case SysEvent_PauseCPU_FromMenu: case SysEvent_PauseCPU_FromMenu:
case SysEvent_PauseCPU_AppLostFocus: case SysEvent_PauseCPU_AppLostFocus:
@ -466,9 +462,21 @@ bool CN64System::IsDialogMsg( MSG * msg )
return false; return false;
} }
void CN64System::GameReset (void)
{
m_SystemTimer.SetTimer(CSystemTimer::SoftResetTimer,0x3000000,false);
m_Plugins->Gfx()->ShowCFB();
m_Reg.FAKE_CAUSE_REGISTER |= CAUSE_IP4;
m_Plugins->Gfx()->SoftReset();
if (m_SyncCPU)
{
m_SyncCPU->GameReset();
}
}
void CN64System::Reset (bool bInitReg, bool ClearMenory) void CN64System::Reset (bool bInitReg, bool ClearMenory)
{ {
if (g_Plugins) { g_Plugins->GameReset(); } if (m_Plugins) { m_Plugins->GameReset(); }
m_Audio.Reset(); m_Audio.Reset();
m_MMU_VM.Reset(ClearMenory); m_MMU_VM.Reset(ClearMenory);
Debug_Reset(); Debug_Reset();
@ -504,7 +512,11 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory)
{ {
m_Recomp->Reset(); m_Recomp->Reset();
} }
if (g_Plugins) { g_Plugins->GameReset(); } if (m_Plugins) { m_Plugins->GameReset(); }
if (m_SyncCPU)
{
m_SyncCPU->Reset(bInitReg,ClearMenory);
}
} }
bool CN64System::SetActiveSystem( bool bActive ) bool CN64System::SetActiveSystem( bool bActive )

View File

@ -49,6 +49,7 @@ public:
void IncreaseSpeed ( void ) { m_Limitor.IncreaeSpeed(10); } void IncreaseSpeed ( void ) { m_Limitor.IncreaeSpeed(10); }
void DecreaeSpeed ( void ) { m_Limitor.DecreaeSpeed(10); } void DecreaeSpeed ( void ) { m_Limitor.DecreaeSpeed(10); }
void Reset ( bool bInitReg, bool ClearMenory ); void Reset ( bool bInitReg, bool ClearMenory );
void GameReset ( void );
void Pause ( void ); void Pause ( void );
void RunRSP ( void ); void RunRSP ( void );

View File

@ -343,6 +343,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lps
if (g_Settings) { delete g_Settings; g_Settings = NULL; } if (g_Settings) { delete g_Settings; g_Settings = NULL; }
if (_Lang) { delete _Lang; _Lang = NULL; } if (_Lang) { delete _Lang; _Lang = NULL; }
CMipsMemoryVM::FreeReservedMemory();
CoUninitialize(); CoUninitialize();
WriteTrace(TraceDebug,__FUNCTION__ ": Done"); WriteTrace(TraceDebug,__FUNCTION__ ": Done");
CloseTrace(); CloseTrace();