Skip to content

Commit

Permalink
Core: Get system events to be internal not global
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Oct 26, 2023
1 parent 0dc1fa7 commit 4770d29
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 97 deletions.
18 changes: 10 additions & 8 deletions Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp
Expand Up @@ -82,7 +82,8 @@ void R4300iOp::ExecuteCPU()
uint32_t & JumpToLocation = m_System.m_JumpToLocation;
uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation;
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();
int32_t & NextTimer = *g_NextTimer;
bool CheckTimer = false;
Expand Down Expand Up @@ -168,9 +169,9 @@ void R4300iOp::ExecuteCPU()
{
g_SystemTimer->TimerDone();
}
if (bDoSomething)
if (DoSomething)
{
g_SystemEvents->ExecuteEvents();
SystemEvents.ExecuteEvents();
}
}
break;
Expand All @@ -184,9 +185,9 @@ void R4300iOp::ExecuteCPU()
PipelineStage = PIPELINE_STAGE_NORMAL;
InPermLoop();
g_SystemTimer->TimerDone();
if (bDoSomething)
if (DoSomething)
{
g_SystemEvents->ExecuteEvents();
SystemEvents.ExecuteEvents();
}
break;
default:
Expand All @@ -208,7 +209,8 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
uint32_t & JumpDelayLocation = m_System.m_JumpDelayLocation;
uint32_t & JumpToLocation = m_System.m_JumpToLocation;
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();
bool CheckTimer = false;

Expand Down Expand Up @@ -278,7 +280,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
}
if (DoSomething)
{
g_SystemEvents->ExecuteEvents();
SystemEvents.ExecuteEvents();
}
}
break;
Expand All @@ -294,7 +296,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
g_SystemTimer->TimerDone();
if (DoSomething)
{
g_SystemEvents->ExecuteEvents();
SystemEvents.ExecuteEvents();
}
break;
default:
Expand Down
61 changes: 31 additions & 30 deletions Source/Project64-core/N64System/Mips/SystemEvents.cpp
Expand Up @@ -55,10 +55,11 @@ const char * SystemEventName(SystemEvent event)
return unknown;
}

CSystemEvents::CSystemEvents(CN64System * System, CPlugins * Plugins) :
CSystemEvents::CSystemEvents(CN64System & System, CPlugins * Plugins) :
m_System(System),
m_Reg(System.m_Reg),
m_Plugins(Plugins),
m_bDoSomething(false)
m_DoSomething(false)
{
}

Expand All @@ -77,7 +78,7 @@ void CSystemEvents::QueueEvent(SystemEvent action)
}
}
m_Events.push_back(action);
m_bDoSomething = true;
m_DoSomething = true;
}

void CSystemEvents::ExecuteEvents()
Expand All @@ -86,7 +87,7 @@ void CSystemEvents::ExecuteEvents()
{
CGuard Guard(m_CS);

m_bDoSomething = false;
m_DoSomething = false;
if (m_Events.size() == 0)
{
return;
Expand All @@ -102,58 +103,58 @@ void CSystemEvents::ExecuteEvents()
switch (*iter)
{
case SysEvent_CloseCPU:
m_System->m_EndEmulation = true;
m_System.m_EndEmulation = true;
break;
case SysEvent_ResetCPU_Soft:
m_System->GameReset();
m_System.GameReset();
break;
case SysEvent_ResetCPU_SoftDone:
m_System->Reset(true, false);
m_System.Reset(true, false);
break;
case SysEvent_ResetCPU_Hard:
m_System->Reset(true, true);
m_System.Reset(true, true);
break;
case SysEvent_ExecuteInterrupt:
if (g_Reg->DoIntrException())
if (m_Reg.DoIntrException())
{
g_Reg->m_PROGRAM_COUNTER = m_System->JumpToLocation();
m_System->m_PipelineStage = PIPELINE_STAGE_NORMAL;
m_Reg.m_PROGRAM_COUNTER = m_System.JumpToLocation();
m_System.m_PipelineStage = PIPELINE_STAGE_NORMAL;
}
break;
case SysEvent_Interrupt_SP:
g_Reg->MI_INTR_REG |= MI_INTR_SP;
g_Reg->DoIntrException();
m_Reg.MI_INTR_REG |= MI_INTR_SP;
m_Reg.DoIntrException();
break;
case SysEvent_Interrupt_SI:
g_Reg->MI_INTR_REG |= MI_INTR_SI;
g_Reg->DoIntrException();
m_Reg.MI_INTR_REG |= MI_INTR_SI;
m_Reg.DoIntrException();
break;
case SysEvent_Interrupt_AI:
g_Reg->MI_INTR_REG |= MI_INTR_AI;
g_Reg->DoIntrException();
m_Reg.MI_INTR_REG |= MI_INTR_AI;
m_Reg.DoIntrException();
break;
case SysEvent_Interrupt_VI:
g_Reg->MI_INTR_REG |= MI_INTR_VI;
g_Reg->DoIntrException();
m_Reg.MI_INTR_REG |= MI_INTR_VI;
m_Reg.DoIntrException();
break;
case SysEvent_Interrupt_PI:
g_Reg->PI_STATUS_REG |= PI_STATUS_INTERRUPT;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
g_Reg->DoIntrException();
m_Reg.PI_STATUS_REG |= PI_STATUS_INTERRUPT;
m_Reg.MI_INTR_REG |= MI_INTR_PI;
m_Reg.DoIntrException();
break;
case SysEvent_Interrupt_DP:
g_Reg->MI_INTR_REG |= MI_INTR_DP;
g_Reg->DoIntrException();
m_Reg.MI_INTR_REG |= MI_INTR_DP;
m_Reg.DoIntrException();
break;
case SysEvent_SaveMachineState:
if (!m_System->SaveState())
if (!m_System.SaveState())
{
m_Events.push_back(SysEvent_SaveMachineState);
m_bDoSomething = true;
m_DoSomething = true;
}
break;
case SysEvent_LoadMachineState:
if (m_System->LoadState())
if (m_System.LoadState())
{
bLoadedSave = true;
}
Expand All @@ -177,7 +178,7 @@ void CSystemEvents::ExecuteEvents()
g_Notify->ChangeFullScreen();
break;
case SysEvent_GSButtonPressed:
m_System->ApplyGSButton();
m_System.ApplyGSButton();
break;
case SysEvent_PauseCPU_FromMenu:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
Expand Down Expand Up @@ -270,12 +271,12 @@ void CSystemEvents::ExecuteEvents()

if (bPause)
{
m_System->Pause();
m_System.Pause();
}
}

void CSystemEvents::ChangePluginFunc()
{
g_Notify->DisplayMessage(0, MSG_PLUGIN_INIT);
m_System->PluginReset();
m_System.PluginReset();
}
16 changes: 9 additions & 7 deletions Source/Project64-core/N64System/Mips/SystemEvents.h
Expand Up @@ -51,23 +51,24 @@ enum SystemEvent
const char * SystemEventName(SystemEvent event);

class CN64System;
class CRegisters;
class CPlugins;

class CSystemEvents
{
typedef std::vector<SystemEvent> EventList;

protected:
CSystemEvents(CN64System * System, CPlugins * Plugins);
virtual ~CSystemEvents();
public:
CSystemEvents(CN64System & System, CPlugins * Plugins);
~CSystemEvents();

public:
void ExecuteEvents();
void QueueEvent(SystemEvent action);

const int32_t & DoSomething() const
const bool & DoSomething() const
{
return m_bDoSomething;
return m_DoSomething;
}

private:
Expand All @@ -77,9 +78,10 @@ class CSystemEvents

void ChangePluginFunc();

CN64System * m_System;
CN64System & m_System;
CRegisters & m_Reg;
CPlugins * m_Plugins;
EventList m_Events;
int32_t m_bDoSomething;
bool m_DoSomething;
CriticalSection m_CS;
};
14 changes: 6 additions & 8 deletions Source/Project64-core/N64System/N64System.cpp
Expand Up @@ -23,15 +23,15 @@
#pragma warning(disable : 4355) // Disable 'this' : used in base member initializer list

CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) :
CSystemEvents(this, Plugins),
m_EndEmulation(false),
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
m_Plugins(Plugins),
m_SyncCPU(nullptr),
m_SyncPlugins(nullptr),
m_SystemEvents(*this, Plugins),
m_MMU_VM(*this, SavesReadOnly),
//m_Cheats(m_MMU_VM),
m_Reg(*this, *this),
m_Reg(*this, m_SystemEvents),
m_TLB(m_MMU_VM, m_Reg, m_Recomp),
m_OpCodes(*this),
m_Recomp(nullptr),
Expand Down Expand Up @@ -106,7 +106,7 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR

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))
Expand Down Expand Up @@ -242,7 +242,7 @@ void CN64System::ExternalEvent(SystemEvent action)
case SysEvent_ResetFunctionTimes:
case SysEvent_DumpFunctionTimes:
case SysEvent_ResetRecompilerCode:
QueueEvent(action);
m_SystemEvents.QueueEvent(action);
break;
case SysEvent_PauseCPU_AppLostFocus:
case SysEvent_PauseCPU_AppLostActive:
Expand All @@ -255,13 +255,13 @@ void CN64System::ExternalEvent(SystemEvent action)
case SysEvent_PauseCPU_Enhancement:
if (!g_Settings->LoadBool(GameRunning_CPU_Paused))
{
QueueEvent(action);
m_SystemEvents.QueueEvent(action);
}
break;
case SysEvent_PauseCPU_ChangingBPs:
if (!WaitingForStep() && !g_Settings->LoadBool(GameRunning_CPU_Paused))
{
QueueEvent(action);
m_SystemEvents.QueueEvent(action);
for (int i = 0; i < 100; i++)
{
bool paused = g_Settings->LoadBool(GameRunning_CPU_Paused);
Expand Down Expand Up @@ -974,7 +974,6 @@ bool CN64System::SetActiveSystem(bool bActive)
g_Reg = &m_Reg;
g_Mempak = &m_Mempak;
g_SystemTimer = &m_SystemTimer;
g_SystemEvents = this;
g_NextTimer = &m_NextTimer;
g_Plugins = m_Plugins;
g_TLBLoadAddress = &m_TLBLoadAddress;
Expand All @@ -993,7 +992,6 @@ bool CN64System::SetActiveSystem(bool bActive)
g_TLB = nullptr;
g_Reg = nullptr;
g_SystemTimer = nullptr;
g_SystemEvents = nullptr;
g_NextTimer = nullptr;
g_Plugins = m_Plugins;
g_TLBLoadAddress = nullptr;
Expand Down
8 changes: 4 additions & 4 deletions Source/Project64-core/N64System/N64System.h
Expand Up @@ -37,7 +37,6 @@ enum CN64SystemCB

class CN64System :
public CLogging,
private CSystemEvents,
protected CN64SystemSettings,
public CGameSettings,
protected CDebugSettings
Expand Down Expand Up @@ -139,15 +138,15 @@ class CN64System :
friend class CRSP_Plugin;
friend class CControl_Plugin;

// Recompiler has access to manipulate and call functions
friend class CSystemTimer;
friend class CRecompiler;
friend class CRecompilerOpsBase;
friend class CX86RecompilerOps;
friend class CArmRecompilerOps;
friend class CCodeBlock;
friend class CMipsMemoryVM;
friend class R4300iOp;
friend class R4300iOp;
friend class CSystemEvents;

friend class VideoInterfaceHandler;
friend class PifRamHandler;
friend class CRegisters;
Expand Down Expand Up @@ -181,6 +180,7 @@ class CN64System :
CPlugins * const m_Plugins; // The plugin container
CPlugins * m_SyncPlugins;
CN64System * m_SyncCPU;
CSystemEvents m_SystemEvents;
CMipsMemoryVM m_MMU_VM;
CRegisters m_Reg;
CTLB m_TLB;
Expand Down
Expand Up @@ -5,7 +5,7 @@
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/Notification.h>

CArmRecompilerOps::CArmRecompilerOps(CMipsMemoryVM & /*MMU*/, CCodeBlock & CodeBlock) :
CArmRecompilerOps::CArmRecompilerOps(CN64System & System, CCodeBlock & CodeBlock) :
m_Assembler(CodeBlock),
m_RegWorkingSet(CodeBlock, m_Assembler)
{
Expand Down
Expand Up @@ -15,7 +15,7 @@ struct CJumpInfo;
class CArmRecompilerOps
{
public:
CArmRecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock);
CArmRecompilerOps(CN64System & System, CCodeBlock & CodeBlock);
~CArmRecompilerOps();

// Trap functions
Expand Down

0 comments on commit 4770d29

Please sign in to comment.