Core: Get system events to be internal not global

This commit is contained in:
zilmar 2023-10-26 19:59:11 +10:30
parent 0dc1fa7f45
commit 4770d29ec0
21 changed files with 121 additions and 97 deletions

View File

@ -82,7 +82,8 @@ void R4300iOp::ExecuteCPU()
uint32_t & JumpToLocation = m_System.m_JumpToLocation; uint32_t & JumpToLocation = m_System.m_JumpToLocation;
uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation; uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation;
bool & TestTimer = m_System.m_TestTimer; bool & TestTimer = m_System.m_TestTimer;
const int32_t & bDoSomething = g_SystemEvents->DoSomething(); CSystemEvents & SystemEvents = m_System.m_SystemEvents;
const bool & DoSomething = SystemEvents.DoSomething();
uint32_t CountPerOp = m_System.CountPerOp(); uint32_t CountPerOp = m_System.CountPerOp();
int32_t & NextTimer = *g_NextTimer; int32_t & NextTimer = *g_NextTimer;
bool CheckTimer = false; bool CheckTimer = false;
@ -168,9 +169,9 @@ void R4300iOp::ExecuteCPU()
{ {
g_SystemTimer->TimerDone(); g_SystemTimer->TimerDone();
} }
if (bDoSomething) if (DoSomething)
{ {
g_SystemEvents->ExecuteEvents(); SystemEvents.ExecuteEvents();
} }
} }
break; break;
@ -184,9 +185,9 @@ void R4300iOp::ExecuteCPU()
PipelineStage = PIPELINE_STAGE_NORMAL; PipelineStage = PIPELINE_STAGE_NORMAL;
InPermLoop(); InPermLoop();
g_SystemTimer->TimerDone(); g_SystemTimer->TimerDone();
if (bDoSomething) if (DoSomething)
{ {
g_SystemEvents->ExecuteEvents(); SystemEvents.ExecuteEvents();
} }
break; break;
default: default:
@ -208,7 +209,8 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation; uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation;
uint32_t & JumpToLocation = m_System.m_JumpToLocation; uint32_t & JumpToLocation = m_System.m_JumpToLocation;
bool & TestTimer = m_System.m_TestTimer; bool & TestTimer = m_System.m_TestTimer;
const int32_t & DoSomething = g_SystemEvents->DoSomething(); CSystemEvents & SystemEvents = m_System.m_SystemEvents;
const bool & DoSomething = SystemEvents.DoSomething();
uint32_t CountPerOp = m_System.CountPerOp(); uint32_t CountPerOp = m_System.CountPerOp();
bool CheckTimer = false; bool CheckTimer = false;
@ -278,7 +280,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
} }
if (DoSomething) if (DoSomething)
{ {
g_SystemEvents->ExecuteEvents(); SystemEvents.ExecuteEvents();
} }
} }
break; break;
@ -294,7 +296,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
g_SystemTimer->TimerDone(); g_SystemTimer->TimerDone();
if (DoSomething) if (DoSomething)
{ {
g_SystemEvents->ExecuteEvents(); SystemEvents.ExecuteEvents();
} }
break; break;
default: default:

View File

@ -55,10 +55,11 @@ const char * SystemEventName(SystemEvent event)
return unknown; return unknown;
} }
CSystemEvents::CSystemEvents(CN64System * System, CPlugins * Plugins) : CSystemEvents::CSystemEvents(CN64System & System, CPlugins * Plugins) :
m_System(System), m_System(System),
m_Reg(System.m_Reg),
m_Plugins(Plugins), m_Plugins(Plugins),
m_bDoSomething(false) m_DoSomething(false)
{ {
} }
@ -77,7 +78,7 @@ void CSystemEvents::QueueEvent(SystemEvent action)
} }
} }
m_Events.push_back(action); m_Events.push_back(action);
m_bDoSomething = true; m_DoSomething = true;
} }
void CSystemEvents::ExecuteEvents() void CSystemEvents::ExecuteEvents()
@ -86,7 +87,7 @@ void CSystemEvents::ExecuteEvents()
{ {
CGuard Guard(m_CS); CGuard Guard(m_CS);
m_bDoSomething = false; m_DoSomething = false;
if (m_Events.size() == 0) if (m_Events.size() == 0)
{ {
return; return;
@ -102,58 +103,58 @@ void CSystemEvents::ExecuteEvents()
switch (*iter) switch (*iter)
{ {
case SysEvent_CloseCPU: case SysEvent_CloseCPU:
m_System->m_EndEmulation = true; m_System.m_EndEmulation = true;
break; break;
case SysEvent_ResetCPU_Soft: case SysEvent_ResetCPU_Soft:
m_System->GameReset(); m_System.GameReset();
break; break;
case SysEvent_ResetCPU_SoftDone: case SysEvent_ResetCPU_SoftDone:
m_System->Reset(true, false); m_System.Reset(true, false);
break; break;
case SysEvent_ResetCPU_Hard: case SysEvent_ResetCPU_Hard:
m_System->Reset(true, true); m_System.Reset(true, true);
break; break;
case SysEvent_ExecuteInterrupt: case SysEvent_ExecuteInterrupt:
if (g_Reg->DoIntrException()) if (m_Reg.DoIntrException())
{ {
g_Reg->m_PROGRAM_COUNTER = m_System->JumpToLocation(); m_Reg.m_PROGRAM_COUNTER = m_System.JumpToLocation();
m_System->m_PipelineStage = PIPELINE_STAGE_NORMAL; m_System.m_PipelineStage = PIPELINE_STAGE_NORMAL;
} }
break; break;
case SysEvent_Interrupt_SP: case SysEvent_Interrupt_SP:
g_Reg->MI_INTR_REG |= MI_INTR_SP; m_Reg.MI_INTR_REG |= MI_INTR_SP;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_Interrupt_SI: case SysEvent_Interrupt_SI:
g_Reg->MI_INTR_REG |= MI_INTR_SI; m_Reg.MI_INTR_REG |= MI_INTR_SI;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_Interrupt_AI: case SysEvent_Interrupt_AI:
g_Reg->MI_INTR_REG |= MI_INTR_AI; m_Reg.MI_INTR_REG |= MI_INTR_AI;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_Interrupt_VI: case SysEvent_Interrupt_VI:
g_Reg->MI_INTR_REG |= MI_INTR_VI; m_Reg.MI_INTR_REG |= MI_INTR_VI;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_Interrupt_PI: case SysEvent_Interrupt_PI:
g_Reg->PI_STATUS_REG |= PI_STATUS_INTERRUPT; m_Reg.PI_STATUS_REG |= PI_STATUS_INTERRUPT;
g_Reg->MI_INTR_REG |= MI_INTR_PI; m_Reg.MI_INTR_REG |= MI_INTR_PI;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_Interrupt_DP: case SysEvent_Interrupt_DP:
g_Reg->MI_INTR_REG |= MI_INTR_DP; m_Reg.MI_INTR_REG |= MI_INTR_DP;
g_Reg->DoIntrException(); m_Reg.DoIntrException();
break; break;
case SysEvent_SaveMachineState: case SysEvent_SaveMachineState:
if (!m_System->SaveState()) if (!m_System.SaveState())
{ {
m_Events.push_back(SysEvent_SaveMachineState); m_Events.push_back(SysEvent_SaveMachineState);
m_bDoSomething = true; m_DoSomething = true;
} }
break; break;
case SysEvent_LoadMachineState: case SysEvent_LoadMachineState:
if (m_System->LoadState()) if (m_System.LoadState())
{ {
bLoadedSave = true; bLoadedSave = true;
} }
@ -177,7 +178,7 @@ void CSystemEvents::ExecuteEvents()
g_Notify->ChangeFullScreen(); g_Notify->ChangeFullScreen();
break; break;
case SysEvent_GSButtonPressed: case SysEvent_GSButtonPressed:
m_System->ApplyGSButton(); m_System.ApplyGSButton();
break; break;
case SysEvent_PauseCPU_FromMenu: case SysEvent_PauseCPU_FromMenu:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
@ -270,12 +271,12 @@ void CSystemEvents::ExecuteEvents()
if (bPause) if (bPause)
{ {
m_System->Pause(); m_System.Pause();
} }
} }
void CSystemEvents::ChangePluginFunc() void CSystemEvents::ChangePluginFunc()
{ {
g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT); g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT);
m_System->PluginReset(); m_System.PluginReset();
} }

View File

@ -51,23 +51,24 @@ enum SystemEvent
const char * SystemEventName(SystemEvent event); const char * SystemEventName(SystemEvent event);
class CN64System; class CN64System;
class CRegisters;
class CPlugins; class CPlugins;
class CSystemEvents class CSystemEvents
{ {
typedef std::vector<SystemEvent> EventList; typedef std::vector<SystemEvent> EventList;
protected: public:
CSystemEvents(CN64System * System, CPlugins * Plugins); CSystemEvents(CN64System & System, CPlugins * Plugins);
virtual ~CSystemEvents(); ~CSystemEvents();
public: public:
void ExecuteEvents(); void ExecuteEvents();
void QueueEvent(SystemEvent action); void QueueEvent(SystemEvent action);
const int32_t & DoSomething() const const bool & DoSomething() const
{ {
return m_bDoSomething; return m_DoSomething;
} }
private: private:
@ -77,9 +78,10 @@ private:
void ChangePluginFunc(); void ChangePluginFunc();
CN64System * m_System; CN64System & m_System;
CRegisters & m_Reg;
CPlugins * m_Plugins; CPlugins * m_Plugins;
EventList m_Events; EventList m_Events;
int32_t m_bDoSomething; bool m_DoSomething;
CriticalSection m_CS; CriticalSection m_CS;
}; };

View File

@ -23,15 +23,15 @@
#pragma warning(disable : 4355) // Disable 'this' : used in base member initializer list #pragma warning(disable : 4355) // Disable 'this' : used in base member initializer list
CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) : CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) :
CSystemEvents(this, Plugins),
m_EndEmulation(false), m_EndEmulation(false),
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)), m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
m_Plugins(Plugins), m_Plugins(Plugins),
m_SyncCPU(nullptr), m_SyncCPU(nullptr),
m_SyncPlugins(nullptr), m_SyncPlugins(nullptr),
m_SystemEvents(*this, Plugins),
m_MMU_VM(*this, SavesReadOnly), m_MMU_VM(*this, SavesReadOnly),
//m_Cheats(m_MMU_VM), //m_Cheats(m_MMU_VM),
m_Reg(*this, *this), m_Reg(*this, m_SystemEvents),
m_TLB(m_MMU_VM, m_Reg, m_Recomp), m_TLB(m_MMU_VM, m_Reg, m_Recomp),
m_OpCodes(*this), m_OpCodes(*this),
m_Recomp(nullptr), m_Recomp(nullptr),
@ -106,7 +106,7 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR
if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores) if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores)
{ {
m_Recomp = new CRecompiler(m_MMU_VM, m_Reg, m_EndEmulation); m_Recomp = new CRecompiler(*this, m_EndEmulation);
} }
if (g_Settings->LoadBool(Game_LoadSaveAtStart)) if (g_Settings->LoadBool(Game_LoadSaveAtStart))
@ -242,7 +242,7 @@ void CN64System::ExternalEvent(SystemEvent action)
case SysEvent_ResetFunctionTimes: case SysEvent_ResetFunctionTimes:
case SysEvent_DumpFunctionTimes: case SysEvent_DumpFunctionTimes:
case SysEvent_ResetRecompilerCode: case SysEvent_ResetRecompilerCode:
QueueEvent(action); m_SystemEvents.QueueEvent(action);
break; break;
case SysEvent_PauseCPU_AppLostFocus: case SysEvent_PauseCPU_AppLostFocus:
case SysEvent_PauseCPU_AppLostActive: case SysEvent_PauseCPU_AppLostActive:
@ -255,13 +255,13 @@ void CN64System::ExternalEvent(SystemEvent action)
case SysEvent_PauseCPU_Enhancement: case SysEvent_PauseCPU_Enhancement:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
QueueEvent(action); m_SystemEvents.QueueEvent(action);
} }
break; break;
case SysEvent_PauseCPU_ChangingBPs: case SysEvent_PauseCPU_ChangingBPs:
if (!WaitingForStep() && !g_Settings->LoadBool(GameRunning_CPU_Paused)) if (!WaitingForStep() && !g_Settings->LoadBool(GameRunning_CPU_Paused))
{ {
QueueEvent(action); m_SystemEvents.QueueEvent(action);
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
bool paused = g_Settings->LoadBool(GameRunning_CPU_Paused); bool paused = g_Settings->LoadBool(GameRunning_CPU_Paused);
@ -974,7 +974,6 @@ bool CN64System::SetActiveSystem(bool bActive)
g_Reg = &m_Reg; g_Reg = &m_Reg;
g_Mempak = &m_Mempak; g_Mempak = &m_Mempak;
g_SystemTimer = &m_SystemTimer; g_SystemTimer = &m_SystemTimer;
g_SystemEvents = this;
g_NextTimer = &m_NextTimer; g_NextTimer = &m_NextTimer;
g_Plugins = m_Plugins; g_Plugins = m_Plugins;
g_TLBLoadAddress = &m_TLBLoadAddress; g_TLBLoadAddress = &m_TLBLoadAddress;
@ -993,7 +992,6 @@ bool CN64System::SetActiveSystem(bool bActive)
g_TLB = nullptr; g_TLB = nullptr;
g_Reg = nullptr; g_Reg = nullptr;
g_SystemTimer = nullptr; g_SystemTimer = nullptr;
g_SystemEvents = nullptr;
g_NextTimer = nullptr; g_NextTimer = nullptr;
g_Plugins = m_Plugins; g_Plugins = m_Plugins;
g_TLBLoadAddress = nullptr; g_TLBLoadAddress = nullptr;

View File

@ -37,7 +37,6 @@ enum CN64SystemCB
class CN64System : class CN64System :
public CLogging, public CLogging,
private CSystemEvents,
protected CN64SystemSettings, protected CN64SystemSettings,
public CGameSettings, public CGameSettings,
protected CDebugSettings protected CDebugSettings
@ -139,15 +138,15 @@ private:
friend class CRSP_Plugin; friend class CRSP_Plugin;
friend class CControl_Plugin; friend class CControl_Plugin;
// Recompiler has access to manipulate and call functions
friend class CSystemTimer; friend class CSystemTimer;
friend class CRecompiler; friend class CRecompiler;
friend class CRecompilerOpsBase;
friend class CX86RecompilerOps; friend class CX86RecompilerOps;
friend class CArmRecompilerOps; friend class CArmRecompilerOps;
friend class CCodeBlock;
friend class CMipsMemoryVM; friend class CMipsMemoryVM;
friend class R4300iOp; friend class R4300iOp;
friend class CSystemEvents; friend class CSystemEvents;
friend class VideoInterfaceHandler; friend class VideoInterfaceHandler;
friend class PifRamHandler; friend class PifRamHandler;
friend class CRegisters; friend class CRegisters;
@ -181,6 +180,7 @@ private:
CPlugins * const m_Plugins; // The plugin container CPlugins * const m_Plugins; // The plugin container
CPlugins * m_SyncPlugins; CPlugins * m_SyncPlugins;
CN64System * m_SyncCPU; CN64System * m_SyncCPU;
CSystemEvents m_SystemEvents;
CMipsMemoryVM m_MMU_VM; CMipsMemoryVM m_MMU_VM;
CRegisters m_Reg; CRegisters m_Reg;
CTLB m_TLB; CTLB m_TLB;

View File

@ -5,7 +5,7 @@
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h> #include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/Notification.h> #include <Project64-core/Notification.h>
CArmRecompilerOps::CArmRecompilerOps(CMipsMemoryVM & /*MMU*/, CCodeBlock & CodeBlock) : CArmRecompilerOps::CArmRecompilerOps(CN64System & System, CCodeBlock & CodeBlock) :
m_Assembler(CodeBlock), m_Assembler(CodeBlock),
m_RegWorkingSet(CodeBlock, m_Assembler) m_RegWorkingSet(CodeBlock, m_Assembler)
{ {

View File

@ -15,7 +15,7 @@ struct CJumpInfo;
class CArmRecompilerOps class CArmRecompilerOps
{ {
public: public:
CArmRecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock); CArmRecompilerOps(CN64System & System, CCodeBlock & CodeBlock);
~CArmRecompilerOps(); ~CArmRecompilerOps();
// Trap functions // Trap functions

View File

@ -13,9 +13,9 @@
extern "C" void __clear_cache_android(uint8_t * begin, uint8_t * end); extern "C" void __clear_cache_android(uint8_t * begin, uint8_t * end);
#endif #endif
CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, CRegisters & Reg, uint32_t VAddrEnter) : CCodeBlock::CCodeBlock(CN64System & System, uint32_t VAddrEnter) :
m_MMU(MMU), m_MMU(System.m_MMU_VM),
m_Reg(Reg), m_Reg(System.m_Reg),
m_VAddrEnter(VAddrEnter), m_VAddrEnter(VAddrEnter),
m_VAddrFirst(VAddrEnter), m_VAddrFirst(VAddrEnter),
m_VAddrLast(VAddrEnter), m_VAddrLast(VAddrEnter),
@ -35,11 +35,11 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, CRegisters & Reg, uint32_t VAddrEnte
} }
#endif #endif
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
m_RecompilerOps = new CX86RecompilerOps(MMU, Reg, *this); m_RecompilerOps = new CX86RecompilerOps(System, *this);
#elif defined(__amd64__) || defined(_M_X64) #elif defined(__amd64__) || defined(_M_X64)
m_RecompilerOps = new CX64RecompilerOps(MMU, Reg, *this); m_RecompilerOps = new CX64RecompilerOps(System, *this);
#elif defined(__arm__) || defined(_M_ARM) #elif defined(__arm__) || defined(_M_ARM)
m_RecompilerOps = new CArmRecompilerOps(MMU, *this); m_RecompilerOps = new CArmRecompilerOps(System, *this);
#else #else
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
#endif #endif
@ -74,7 +74,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, CRegisters & Reg, uint32_t VAddrEnte
memset(m_MemLocation, 0, sizeof(m_MemLocation)); memset(m_MemLocation, 0, sizeof(m_MemLocation));
memset(m_MemContents, 0, sizeof(m_MemContents)); memset(m_MemContents, 0, sizeof(m_MemContents));
m_MemLocation[0] = (uint64_t *)MMU.MemoryPtr(VAddrEnter, 16, true); m_MemLocation[0] = (uint64_t *)m_MMU.MemoryPtr(VAddrEnter, 16, true);
if (m_MemLocation[0] != 0) if (m_MemLocation[0] != 0)
{ {
m_MemLocation[1] = m_MemLocation[0] + 1; m_MemLocation[1] = m_MemLocation[0] + 1;

View File

@ -13,7 +13,7 @@ class CCodeBlock :
public asmjit::ErrorHandler public asmjit::ErrorHandler
{ {
public: public:
CCodeBlock(CMipsMemoryVM & MMU, CRegisters & Reg, uint32_t VAddrEnter); CCodeBlock(CN64System & System, uint32_t VAddrEnter);
~CCodeBlock(); ~CCodeBlock();
bool Compile(); bool Compile();

View File

@ -5,12 +5,13 @@
#include <Project64-core/N64System/Recompiler/Recompiler.h> #include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
CRecompiler::CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & EndEmulation) : CRecompiler::CRecompiler(CN64System & System, bool & EndEmulation) :
m_MMU(MMU), m_System(System),
m_Registers(Registers), m_MMU(System.m_MMU_VM),
m_Reg(System.m_Reg),
m_EndEmulation(EndEmulation), m_EndEmulation(EndEmulation),
m_MemoryStack(0), m_MemoryStack(0),
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER), PROGRAM_COUNTER(System.m_Reg.m_PROGRAM_COUNTER),
m_LogFile(nullptr) m_LogFile(nullptr)
{ {
CFunctionMap::AllocateMemory(); CFunctionMap::AllocateMemory();
@ -86,7 +87,7 @@ void CRecompiler::RecompilerMain_VirtualTable()
{ {
if (!m_MMU.ValidVaddr(PC)) if (!m_MMU.ValidVaddr(PC))
{ {
m_Registers.TriggerAddressException(PC, EXC_RMISS); m_Reg.TriggerAddressException(PC, EXC_RMISS);
PC = g_System->m_JumpToLocation; PC = g_System->m_JumpToLocation;
g_System->m_PipelineStage = PIPELINE_STAGE_NORMAL; g_System->m_PipelineStage = PIPELINE_STAGE_NORMAL;
if (!m_MMU.ValidVaddr(PC)) if (!m_MMU.ValidVaddr(PC))
@ -148,7 +149,7 @@ void CRecompiler::RecompilerMain_Lookup()
{ {
if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr)) if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr))
{ {
m_Registers.TriggerAddressException(PROGRAM_COUNTER, EXC_RMISS); m_Reg.TriggerAddressException(PROGRAM_COUNTER, EXC_RMISS);
if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr)) if (!m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr))
{ {
g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).c_str()); g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).c_str());
@ -207,7 +208,7 @@ void CRecompiler::RecompilerMain_Lookup_validate()
{ {
if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr)) if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr))
{ {
m_Registers.TriggerAddressException(PC, EXC_RMISS); m_Reg.TriggerAddressException(PC, EXC_RMISS);
if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr)) if (!m_MMU.VAddrToPAddr(PC, PhysicalAddr))
{ {
g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).c_str()); g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).c_str());
@ -378,7 +379,7 @@ CCompiledFunc * CRecompiler::CompileCode()
CheckRecompMem(); CheckRecompMem();
WriteTrace(TraceRecompiler, TraceDebug, "Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr); WriteTrace(TraceRecompiler, TraceDebug, "Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr);
CCodeBlock CodeBlock(m_MMU, m_Registers, PROGRAM_COUNTER); CCodeBlock CodeBlock(m_System, PROGRAM_COUNTER);
if (!CodeBlock.Compile()) if (!CodeBlock.Compile())
{ {
return nullptr; return nullptr;
@ -530,14 +531,14 @@ void CRecompiler::ResetLog()
void CRecompiler::ResetMemoryStackPos() void CRecompiler::ResetMemoryStackPos()
{ {
if (m_Registers.m_GPR[29].UW[0] == 0) if (m_Reg.m_GPR[29].UW[0] == 0)
{ {
m_MemoryStack = 0; m_MemoryStack = 0;
return; return;
} }
uint32_t pAddr = 0; uint32_t pAddr = 0;
if (m_MMU.VAddrToPAddr(m_Registers.m_GPR[29].UW[0], pAddr)) if (m_MMU.VAddrToPAddr(m_Reg.m_GPR[29].UW[0], pAddr))
{ {
if (pAddr <= m_MMU.RdramSize()) if (pAddr <= m_MMU.RdramSize())
{ {
@ -558,7 +559,7 @@ void CRecompiler::ResetMemoryStackPos()
} }
else else
{ {
WriteTrace(TraceRecompiler, TraceError, "Failed to translate SP address (%s)", m_Registers.m_GPR[29].UW[0]); WriteTrace(TraceRecompiler, TraceError, "Failed to translate SP address (%s)", m_Reg.m_GPR[29].UW[0]);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
} }

View File

@ -33,7 +33,7 @@ public:
typedef void (*DelayFunc)(); typedef void (*DelayFunc)();
public: public:
CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & EndEmulation); CRecompiler(CN64System & System, bool & EndEmulation);
~CRecompiler(); ~CRecompiler();
void Run(); void Run();
@ -80,8 +80,9 @@ private:
void LogCodeBlock(const CCodeBlock & CodeBlock); void LogCodeBlock(const CCodeBlock & CodeBlock);
CCompiledFuncList m_Functions; CCompiledFuncList m_Functions;
CN64System & m_System;
CMipsMemoryVM & m_MMU; CMipsMemoryVM & m_MMU;
CRegisters & m_Registers; CRegisters & m_Reg;
bool & m_EndEmulation; bool & m_EndEmulation;
uint8_t * m_MemoryStack; uint8_t * m_MemoryStack;
FUNCTION_PROFILE m_BlockProfile; FUNCTION_PROFILE m_BlockProfile;

View File

@ -1,10 +1,13 @@
#include "stdafx.h" #include "stdafx.h"
#include "RecompilerOps.h" #include "RecompilerOps.h"
#include <Project64-core/N64System/N64System.h>
CRecompilerOpsBase::CRecompilerOpsBase(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock) : CRecompilerOpsBase::CRecompilerOpsBase(CN64System & System, CCodeBlock & CodeBlock) :
m_Reg(Reg), m_System(System),
m_MMU(MMU), m_SystemEvents(System.m_SystemEvents),
m_Reg(System.m_Reg),
m_MMU(System.m_MMU_VM),
m_CodeBlock(CodeBlock), m_CodeBlock(CodeBlock),
m_Section(nullptr) m_Section(nullptr)
{ {

View File

@ -39,6 +39,8 @@ enum RecompilerTrapCompare
class CCodeBlock; class CCodeBlock;
class CCodeSection; class CCodeSection;
class CN64System;
class CSystemEvents;
class CMipsMemoryVM; class CMipsMemoryVM;
class CRegisters; class CRegisters;
@ -46,9 +48,11 @@ class CRecompilerOpsBase :
protected CDebugSettings protected CDebugSettings
{ {
protected: protected:
CRecompilerOpsBase(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock); CRecompilerOpsBase(CN64System & System, CCodeBlock & CodeBlock);
~CRecompilerOpsBase(); ~CRecompilerOpsBase();
CN64System & m_System;
CSystemEvents & m_SystemEvents;
CMipsMemoryVM & m_MMU; CMipsMemoryVM & m_MMU;
CRegisters & m_Reg; CRegisters & m_Reg;
CCodeBlock & m_CodeBlock; CCodeBlock & m_CodeBlock;

View File

@ -5,8 +5,8 @@
#include <Project64-core\N64System\Recompiler\CodeSection.h> #include <Project64-core\N64System\Recompiler\CodeSection.h>
#include <Project64-core\N64System\Recompiler\x64-86\x64RecompilerOps.h> #include <Project64-core\N64System\Recompiler\x64-86\x64RecompilerOps.h>
CX64RecompilerOps::CX64RecompilerOps(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock) : CX64RecompilerOps::CX64RecompilerOps(CN64System & System, CCodeBlock & CodeBlock) :
CRecompilerOpsBase(MMU, Reg, CodeBlock), CRecompilerOpsBase(System, CodeBlock),
m_Assembler(CodeBlock), m_Assembler(CodeBlock),
m_RegWorkingSet(CodeBlock, m_Assembler) m_RegWorkingSet(CodeBlock, m_Assembler)
{ {

View File

@ -13,7 +13,7 @@ class CX64RecompilerOps :
public CRecompilerOpsBase public CRecompilerOpsBase
{ {
public: public:
CX64RecompilerOps(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock); CX64RecompilerOps(CN64System & System, CCodeBlock & CodeBlock);
~CX64RecompilerOps(); ~CX64RecompilerOps();
// Trap functions // Trap functions

View File

@ -179,8 +179,8 @@ void CX86RecompilerOps::x86TestWriteBreakPoint64()
} }
} }
CX86RecompilerOps::CX86RecompilerOps(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock) : CX86RecompilerOps::CX86RecompilerOps(CN64System & m_System, CCodeBlock & CodeBlock) :
CRecompilerOpsBase(MMU, Reg, CodeBlock), CRecompilerOpsBase(m_System, CodeBlock),
m_Assembler(CodeBlock), m_Assembler(CodeBlock),
m_RegWorkingSet(CodeBlock, m_Assembler), m_RegWorkingSet(CodeBlock, m_Assembler),
m_CompilePC(0), m_CompilePC(0),
@ -9493,7 +9493,7 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool
void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet) void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet)
{ {
m_Assembler.CompConstToVariable((void *)&g_SystemEvents->DoSomething(), "g_SystemEvents->DoSomething()", 0); m_Assembler.CompConstByteToVariable((void *)&m_SystemEvents.DoSomething(), "m_SystemEvents.DoSomething()", 0);
asmjit::Label Jump = m_Assembler.newLabel(); asmjit::Label Jump = m_Assembler.newLabel();
m_Assembler.JeLabel("Continue_From_Interrupt_Test", Jump); m_Assembler.JeLabel("Continue_From_Interrupt_Test", Jump);
if (TargetPC != (uint32_t)-1) if (TargetPC != (uint32_t)-1)
@ -9503,7 +9503,7 @@ void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & R
CRegInfo RegSetCopy(RegSet); CRegInfo RegSetCopy(RegSet);
RegSetCopy.WriteBackRegisters(); RegSetCopy.WriteBackRegisters();
m_Assembler.CallThis((uint32_t)g_SystemEvents, AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents", 4); m_Assembler.CallThis((uint32_t)&m_SystemEvents, AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents", 4);
ExitCodeBlock(); ExitCodeBlock();
m_CodeBlock.Log(""); m_CodeBlock.Log("");
m_Assembler.bind(Jump); m_Assembler.bind(Jump);
@ -9657,7 +9657,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_DoCPUAction: case ExitReason_DoCPUAction:
m_Assembler.CallThis((uint32_t)g_SystemEvents, AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents", 4); m_Assembler.CallThis((uint32_t)&g_System->m_SystemEvents, AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents", 4);
ExitCodeBlock(); ExitCodeBlock();
break; break;
case ExitReason_DoSysCall: case ExitReason_DoSysCall:

View File

@ -26,7 +26,7 @@ class CX86RecompilerOps :
friend CX86RegInfo; friend CX86RegInfo;
public: public:
CX86RecompilerOps(CMipsMemoryVM & MMU, CRegisters & Reg, CCodeBlock & CodeBlock); CX86RecompilerOps(CN64System & m_System, CCodeBlock & CodeBlock);
~CX86RecompilerOps(); ~CX86RecompilerOps();
// Trap functions // Trap functions

View File

@ -176,6 +176,21 @@ void CX86Ops::CallThis(uint32_t ThisPtr, uint32_t FunctPtr, const char * FunctNa
} }
#endif #endif
void CX86Ops::CompConstByteToVariable(void * Variable, const char * VariableName, uint8_t Const)
{
if (CDebugSettings::bRecordRecompilerAsm())
{
std::string SymbolKey = VariableSymbol(Variable);
AddSymbol(SymbolKey.c_str(), VariableName);
cmp(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
RemoveSymbol(SymbolKey.c_str());
}
else
{
cmp(asmjit::x86::byte_ptr((uint64_t)Variable), Const);
}
}
void CX86Ops::CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const) void CX86Ops::CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
if (CDebugSettings::bRecordRecompilerAsm()) if (CDebugSettings::bRecordRecompilerAsm())

View File

@ -40,6 +40,7 @@ public:
void X86BreakPoint(const char * FileName, int32_t LineNumber); void X86BreakPoint(const char * FileName, int32_t LineNumber);
void CallFunc(uint32_t FunctPtr, const char * FunctName); void CallFunc(uint32_t FunctPtr, const char * FunctName);
void CallThis(uint32_t ThisPtr, uint32_t FunctPtr, const char * FunctName, uint32_t StackSize); void CallThis(uint32_t ThisPtr, uint32_t FunctPtr, const char * FunctName, uint32_t StackSize);
void CompConstByteToVariable(void * Variable, const char * VariableName, uint8_t Const);
void CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const); void CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const);
void CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const); void CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const);
void CompX86regToVariable(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void CompX86regToVariable(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName);

View File

@ -15,7 +15,6 @@ CN64Rom * g_Rom = nullptr; // The current ROM that this system is executing, i
CN64Rom * g_DDRom = nullptr; // 64DD IPL ROM CN64Rom * g_DDRom = nullptr; // 64DD IPL ROM
CN64Disk * g_Disk = nullptr; // 64DD disk CN64Disk * g_Disk = nullptr; // 64DD disk
CSystemTimer * g_SystemTimer = nullptr; CSystemTimer * g_SystemTimer = nullptr;
CSystemEvents * g_SystemEvents = nullptr;
uint32_t * g_TLBLoadAddress = nullptr; uint32_t * g_TLBLoadAddress = nullptr;
uint32_t * g_TLBStoreAddress = nullptr; uint32_t * g_TLBStoreAddress = nullptr;
CDebugger * g_Debugger = nullptr; CDebugger * g_Debugger = nullptr;

View File

@ -33,9 +33,6 @@ extern CN64Disk * g_Disk; // 64DD disk
class CSystemTimer; class CSystemTimer;
extern CSystemTimer * g_SystemTimer; extern CSystemTimer * g_SystemTimer;
class CSystemEvents;
extern CSystemEvents * g_SystemEvents;
extern int32_t * g_NextTimer; extern int32_t * g_NextTimer;
extern uint32_t * g_TLBLoadAddress; extern uint32_t * g_TLBLoadAddress;
extern uint32_t * g_TLBStoreAddress; extern uint32_t * g_TLBStoreAddress;