Skip to content

Commit

Permalink
Core: Make R4300iOp::ExecuteCPU() and R4300iOp::ExecuteOps(int32_t Cy…
Browse files Browse the repository at this point in the history
…cles) non static
  • Loading branch information
project64 committed Oct 18, 2023
1 parent d3edbf6 commit 7f42f70
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 57 deletions.
41 changes: 12 additions & 29 deletions Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp
Expand Up @@ -15,7 +15,6 @@
#include <math.h>

bool R4300iOp::m_TestTimer = false;
R4300iOp::Func * R4300iOp::m_R4300i_Opcode = nullptr;
R4300iOpcode R4300iOp::m_Opcode;

R4300iOp::Func R4300iOp::Jump_Opcode[64];
Expand All @@ -41,10 +40,14 @@ const int32_t R4300iOp::SWR_SHIFT[4] = {24, 16, 8, 0};
const int32_t R4300iOp::LWL_SHIFT[4] = {0, 8, 16, 24};
const int32_t R4300iOp::LWR_SHIFT[4] = {24, 16, 8, 0};

void R4300iOp::BuildCPU()
R4300iOp::R4300iOp()
{
m_TestTimer = false;
BuildInterpreter();
}

R4300iOp::~R4300iOp()
{
R4300iOp::m_TestTimer = false;
m_R4300i_Opcode = R4300iOp::BuildInterpreter();
}

void R4300iOp::InPermLoop()
Expand Down Expand Up @@ -77,10 +80,9 @@ void R4300iOp::ExecuteCPU()
bool & Done = g_System->m_EndEmulation;
PIPELINE_STAGE & PipelineStage = g_System->m_PipelineStage;
uint32_t & PROGRAM_COUNTER = *_PROGRAM_COUNTER;
R4300iOpcode & Opcode = R4300iOp::m_Opcode;
uint32_t & JumpToLocation = g_System->m_JumpToLocation;
uint32_t & JumpDelayLocation = g_System->m_JumpDelayLocation;
bool & TestTimer = R4300iOp::m_TestTimer;
bool & TestTimer = m_TestTimer;
const int32_t & bDoSomething = g_SystemEvents->DoSomething();
uint32_t CountPerOp = g_System->CountPerOp();
int32_t & NextTimer = *g_NextTimer;
Expand All @@ -90,7 +92,7 @@ void R4300iOp::ExecuteCPU()
{
while (!Done)
{
if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Value))
if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, m_Opcode.Value))
{
g_Reg->TriggerAddressException(PROGRAM_COUNTER, EXC_RMISS);
PROGRAM_COUNTER = JumpToLocation;
Expand Down Expand Up @@ -130,7 +132,7 @@ void R4300iOp::ExecuteCPU()
// WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType());
} */

m_R4300i_Opcode[Opcode.op]();
Jump_Opcode[m_Opcode.op]();
_GPR[0].DW = 0; // MIPS $zero hard-wired to 0
NextTimer -= CountPerOp;

Expand Down Expand Up @@ -237,7 +239,7 @@ void R4300iOp::ExecuteOps(int32_t Cycles)
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",*_PROGRAM_COUNTER,R4300iInstruction(*_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),_GPR[0x19].UW[0],_GPR[0x03].UW[0]);
//WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",*_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType());
}*/
m_R4300i_Opcode[Opcode.op]();
Jump_Opcode[Opcode.op]();
_GPR[0].DW = 0; /* MIPS $zero hard-wired to 0 */

Cycles -= CountPerOp;
Expand Down Expand Up @@ -376,7 +378,7 @@ void R4300iOp::COP1_L()
Jump_CoP1_L[m_Opcode.funct]();
}

R4300iOp::Func * R4300iOp::BuildInterpreter()
void R4300iOp::BuildInterpreter()
{
Jump_Opcode[0] = SPECIAL;
Jump_Opcode[1] = REGIMM;
Expand Down Expand Up @@ -996,8 +998,6 @@ R4300iOp::Func * R4300iOp::BuildInterpreter()
Jump_CoP2[29] = CPO2_INVALID_OP;
Jump_CoP2[30] = CPO2_INVALID_OP;
Jump_CoP2[31] = CPO2_INVALID_OP;

return Jump_Opcode;
}

// Opcode functions
Expand Down Expand Up @@ -3323,23 +3323,6 @@ void R4300iOp::UnknownOpcode()
}
}

bool R4300iOp::MemoryBreakpoint()
{
if (g_Settings->LoadBool(Debugger_SteppingOps))
{
return false;
}
g_Settings->SaveBool(Debugger_SteppingOps, true);
g_Debugger->WaitForStep();
if (SkipOp())
{
// Skip command if instructed by the debugger
g_Settings->SaveBool(Debugger_SkipOp, false);
return true;
}
return false;
}

bool R4300iOp::TestCop1UsableException(void)
{
if (g_Reg->STATUS_REGISTER.CU1 == 0)
Expand Down
22 changes: 12 additions & 10 deletions Source/Project64-core/N64System/Interpreter/InterpreterOps.h
Expand Up @@ -8,15 +8,17 @@ class CX86RecompilerOps;

class R4300iOp :
public CLogging,
protected CDebugSettings,
protected CSystemRegisters
private CDebugSettings,
private CSystemRegisters
{
friend CX86RecompilerOps;

public:
static void BuildCPU();
static void ExecuteCPU();
static void ExecuteOps(int32_t Cycles);
R4300iOp();
~R4300iOp(void);

void ExecuteCPU();
void ExecuteOps(int32_t Cycles);
static void InPermLoop();

typedef void (*Func)();
Expand Down Expand Up @@ -232,14 +234,15 @@ class R4300iOp :
static void ReservedInstruction();
static void UnknownOpcode();

static Func * BuildInterpreter();

static bool m_TestTimer;
static R4300iOpcode m_Opcode;

static bool MemoryBreakpoint();
private:
R4300iOp(const R4300iOp &);
R4300iOp & operator=(const R4300iOp &);

void BuildInterpreter(void);

protected:
static void SPECIAL();
static void REGIMM();
static void COP0();
Expand Down Expand Up @@ -279,5 +282,4 @@ class R4300iOp :

static const uint32_t SWL_MASK[4], SWR_MASK[4], LWL_MASK[4], LWR_MASK[4];
static const int32_t SWL_SHIFT[4], SWR_SHIFT[4], LWL_SHIFT[4], LWR_SHIFT[4];
static R4300iOp::Func * m_R4300i_Opcode;
};
17 changes: 17 additions & 0 deletions Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp
Expand Up @@ -625,6 +625,23 @@ bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t & PAddr) const
return true;
}

bool CMipsMemoryVM::MemoryBreakpoint()
{
if (g_Settings->LoadBool(Debugger_SteppingOps))
{
return false;
}
g_Settings->SaveBool(Debugger_SteppingOps, true);
g_Debugger->WaitForStep();
if (SkipOp())
{
// Skip command if instructed by the debugger
g_Settings->SaveBool(Debugger_SkipOp, false);
return true;
}
return false;
}

bool CMipsMemoryVM::LB_VAddr32(uint32_t VAddr, uint8_t & Value)
{
uint32_t BaseAddress = m_TLB_ReadMap[VAddr >> 12];
Expand Down
6 changes: 4 additions & 2 deletions Source/Project64-core/N64System/Mips/MemoryVirtualMem.h
Expand Up @@ -48,8 +48,8 @@ class CArmRecompilerOps;
#endif

class CMipsMemoryVM :
private R4300iOp,
private CGameSettings
private CGameSettings,
private CDebugSettings
{
public:
CMipsMemoryVM(CN64System & System, bool SavesReadOnly);
Expand Down Expand Up @@ -163,6 +163,8 @@ class CMipsMemoryVM :
static void RdramChanged(CMipsMemoryVM * _this);
static void ChangeMiIntrMask();

bool MemoryBreakpoint();

bool LB_VAddr32(uint32_t VAddr, uint8_t & Value);
bool LH_VAddr32(uint32_t VAddr, uint16_t & Value);
bool LW_VAddr32(uint32_t VAddr, uint32_t & Value);
Expand Down
7 changes: 2 additions & 5 deletions Source/Project64-core/N64System/N64System.cpp
Expand Up @@ -61,9 +61,6 @@ CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesR
}
m_Limiter.SetHertz(gameHertz);
g_Settings->SaveDword(GameRunning_ScreenHertz, gameHertz);
WriteTrace(TraceN64System, TraceDebug, "Setting up system");
R4300iOp::BuildCPU();

if (!m_MMU_VM.Initialize(SyncSystem))
{
WriteTrace(TraceN64System, TraceWarning, "MMU failed to initialize");
Expand Down Expand Up @@ -1077,7 +1074,7 @@ void CN64System::ExecuteCPU()
void CN64System::ExecuteInterpret()
{
SetActiveSystem();
R4300iOp::ExecuteCPU();
m_OpCodes.ExecuteCPU();
}

void CN64System::ExecuteRecompiler()
Expand Down Expand Up @@ -1123,7 +1120,7 @@ void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycl
}

SecondCPU->SetActiveSystem(true);
R4300iOp::ExecuteOps(Cycles);
m_OpCodes.ExecuteOps(Cycles);
SetActiveSystem(true);
}

Expand Down
1 change: 1 addition & 0 deletions Source/Project64-core/N64System/N64System.h
Expand Up @@ -180,6 +180,7 @@ class CN64System :
CMipsMemoryVM m_MMU_VM;
CRegisters m_Reg;
CTLB m_TLB;
R4300iOp m_OpCodes;
CMempak m_Mempak;
CFramePerSecond m_FPS;
CProfiling m_CPU_Usage; // Used to track the CPU usage
Expand Down
4 changes: 2 additions & 2 deletions Source/Project64-core/N64System/Recompiler/Recompiler.cpp
Expand Up @@ -183,7 +183,7 @@ void CRecompiler::RecompilerMain_Lookup()

while (m_MMU.VAddrToPAddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
{
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
opsExecuted += g_System->CountPerOp();
}

Expand Down Expand Up @@ -296,7 +296,7 @@ void CRecompiler::RecompilerMain_Lookup_validate()

while (m_MMU.VAddrToPAddr(PC, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
{
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
opsExecuted += g_System->CountPerOp();
}

Expand Down
Expand Up @@ -56,7 +56,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint()
}
continue;
}
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
if (g_SyncSystem)
{
g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp());
Expand All @@ -67,7 +67,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint()

if (g_System->PipelineStage() != PIPELINE_STAGE_NORMAL)
{
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
if (g_SyncSystem)
{
g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp());
Expand All @@ -78,7 +78,7 @@ void CX86RecompilerOps::x86CompilerBreakPoint()

void CX86RecompilerOps::x86BreakPointDelaySlot()
{
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_SyncSystem->m_OpCodes.ExecuteOps(g_System->CountPerOp());
if (g_SyncSystem)
{
g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp());
Expand All @@ -90,7 +90,7 @@ void CX86RecompilerOps::x86BreakPointDelaySlot()
}
if (g_System->PipelineStage() != PIPELINE_STAGE_NORMAL)
{
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
if (g_SyncSystem)
{
g_System->UpdateSyncCPU(g_SyncSystem, g_System->CountPerOp());
Expand All @@ -110,7 +110,7 @@ void CX86RecompilerOps::x86MemoryBreakPoint()
{
g_Reg->m_PROGRAM_COUNTER -= 4;
*g_NextTimer += g_System->CountPerOp();
R4300iOp::ExecuteOps(g_System->CountPerOp());
g_System->m_OpCodes.ExecuteOps(g_System->CountPerOp());
}
x86CompilerBreakPoint();
}
Expand Down Expand Up @@ -9576,9 +9576,7 @@ void CX86RecompilerOps::OverflowDelaySlot(bool TestTimer)
}

m_Assembler.PushImm32("g_System->CountPerOp()", g_System->CountPerOp());
m_Assembler.CallFunc((uint32_t)R4300iOp::ExecuteOps, "R4300iOp::ExecuteOps");
m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4);

m_Assembler.CallThis((uint32_t)&g_System->m_OpCodes, AddressOf(&R4300iOp::ExecuteOps), "R4300iOp::ExecuteOps", 8);
if (g_System->bFastSP() && g_Recompiler)
{
m_Assembler.CallThis((uint32_t)g_Recompiler, AddressOf(&CRecompiler::ResetMemoryStackPos), "CRecompiler::ResetMemoryStackPos", 4);
Expand Down
2 changes: 1 addition & 1 deletion Source/Project64-core/N64System/SystemGlobals.cpp
Expand Up @@ -24,4 +24,4 @@ CMempak * g_Mempak = nullptr;
CRandom * g_Random = nullptr;
CEnhancements * g_Enhancements = nullptr;

int * g_NextTimer;
int32_t * g_NextTimer;

0 comments on commit 7f42f70

Please sign in to comment.