Skip to content

Commit

Permalink
Core: Have R4300iInstruction in CRecompilerOpsBase
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Dec 21, 2023
1 parent 8e3fb3e commit 6610ae3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Source/Project64-core/N64System/Mips/R4300iInstruction.cpp
Expand Up @@ -11,6 +11,25 @@ R4300iInstruction::R4300iInstruction(uint32_t Address, uint32_t Instruction) :
m_Instruction.Value = Instruction;
}

R4300iInstruction & R4300iInstruction::operator=(const R4300iInstruction & Instr)
{
m_Address = Instr.m_Address;
m_Instruction.Value = Instr.m_Instruction.Value;
m_Name[0] = '\0';
m_Param[0] = '\0';
return *this;
}

const uint32_t & R4300iInstruction::Address() const
{
return m_Address;
}

const R4300iOpcode & R4300iInstruction::Opcode() const
{
return m_Instruction;
}

const char * R4300iInstruction::Name()
{
if (m_Name[0] == '\0')
Expand Down
4 changes: 3 additions & 1 deletion Source/Project64-core/N64System/Mips/R4300iInstruction.h
Expand Up @@ -6,7 +6,10 @@ class R4300iInstruction
{
public:
R4300iInstruction(uint32_t Address, uint32_t Instruction);
R4300iInstruction & operator=(const R4300iInstruction &);

const uint32_t & Address() const;
const R4300iOpcode & Opcode() const;
const char * Name();
const char * Param();
std::string NameAndParam();
Expand All @@ -23,7 +26,6 @@ class R4300iInstruction
private:
R4300iInstruction(void);
R4300iInstruction(const R4300iInstruction &);
R4300iInstruction & operator=(const R4300iInstruction &);

static const char * FPR_Type(uint32_t COP1OpCode);

Expand Down
2 changes: 2 additions & 0 deletions Source/Project64-core/N64System/Recompiler/RecompilerOps.cpp
Expand Up @@ -10,6 +10,8 @@ CRecompilerOpsBase::CRecompilerOpsBase(CN64System & System, CCodeBlock & CodeBlo
m_TLB(System.m_TLB),
m_MMU(System.m_MMU_VM),
m_CodeBlock(CodeBlock),
m_Instruction(0, 0),
m_Opcode(m_Instruction.Opcode()),
m_Section(nullptr)
{
}
Expand Down
7 changes: 4 additions & 3 deletions Source/Project64-core/N64System/Recompiler/RecompilerOps.h
@@ -1,6 +1,6 @@
#pragma once
#include <Project64-core\N64System\Mips\R4300iOpcode.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/Settings/DebugSettings.h>

enum RecompilerBranchType
{
Expand Down Expand Up @@ -58,7 +58,8 @@ class CRecompilerOpsBase :
CRegisters & m_Reg;
CTLB & m_TLB;
CCodeBlock & m_CodeBlock;
R4300iOpcode m_Opcode;
R4300iInstruction m_Instruction;
const R4300iOpcode & m_Opcode;
CCodeSection * m_Section;

private:
Expand Down
Expand Up @@ -184,7 +184,7 @@ CX86RecompilerOps::CX86RecompilerOps(CN64System & m_System, CCodeBlock & CodeBlo
CRecompilerOpsBase(m_System, CodeBlock),
m_Assembler(CodeBlock),
m_RegWorkingSet(CodeBlock, m_Assembler),
m_CompilePC(0),
m_CompilePC(m_Instruction.Address()),
m_RegBeforeDelay(CodeBlock, m_Assembler),
m_EffectDelaySlot(false)
{
Expand All @@ -198,7 +198,7 @@ void CX86RecompilerOps::PreCompileOpcode(void)
{
if (m_PipelineStage != PIPELINE_STAGE_DELAY_SLOT_DONE)
{
m_CodeBlock.Log(" %X %s", m_CompilePC, R4300iInstruction(m_CompilePC, m_Opcode.Value).NameAndParam().c_str());
m_CodeBlock.Log(" %X %s", m_CompilePC, m_Instruction.NameAndParam().c_str());
}
/*if (m_CompilePC == 0x803275F4 && m_PipelineStage == PIPELINE_STAGE_NORMAL)
{
Expand Down Expand Up @@ -9477,11 +9477,12 @@ void CX86RecompilerOps::JumpToUnknown(CJumpInfo * JumpInfo)

void CX86RecompilerOps::SetCurrentPC(uint32_t ProgramCounter)
{
m_CompilePC = ProgramCounter;
if (!g_MMU->MemoryValue32(m_CompilePC, m_Opcode.Value))
uint32_t Value;
if (!g_MMU->MemoryValue32(ProgramCounter, Value))
{
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
}
m_Instruction = R4300iInstruction(ProgramCounter, Value);
}

uint32_t CX86RecompilerOps::GetCurrentPC(void)
Expand Down Expand Up @@ -9509,6 +9510,11 @@ const R4300iOpcode & CX86RecompilerOps::GetOpcode(void) const
return m_Opcode;
}

const R4300iInstruction & CX86RecompilerOps::GetInstruction(void) const
{
return m_Instruction;
}

void CX86RecompilerOps::UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles)
{
if (!g_SyncSystem)
Expand Down Expand Up @@ -9590,7 +9596,7 @@ void CX86RecompilerOps::CompileExecuteBP(void)
m_RegWorkingSet.WriteBackRegisters();

UpdateCounters(m_RegWorkingSet, true, true);
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", CompilePC());
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_CompilePC);
if (g_SyncSystem)
{
m_Assembler.CallThis((uint32_t)g_BaseSystem, AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem", 4);
Expand All @@ -9610,7 +9616,7 @@ void CX86RecompilerOps::CompileExecuteDelaySlotBP(void)
m_RegWorkingSet.WriteBackRegisters();

UpdateCounters(m_RegWorkingSet, true, true);
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", CompilePC());
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_CompilePC);
if (g_SyncSystem)
{
m_Assembler.CallThis((uint32_t)g_BaseSystem, AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem", 4);
Expand All @@ -9634,7 +9640,7 @@ void CX86RecompilerOps::OverflowDelaySlot(bool TestTimer)
}
else
{
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", CompilePC() + 4);
m_Assembler.MoveConstToVariable(&m_Reg.m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_CompilePC + 4);
}
m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "System->m_PipelineStage", PIPELINE_STAGE_JUMP);
if (g_SyncSystem)
Expand Down
Expand Up @@ -241,6 +241,7 @@ class CX86RecompilerOps :
void SetNextStepType(PIPELINE_STAGE StepType);
PIPELINE_STAGE GetNextStepType(void);
const R4300iOpcode & GetOpcode(void) const;
const R4300iInstruction & GetInstruction(void) const;
void PreCompileOpcode(void);
void PostCompileOpcode(void);
void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason Reason);
Expand All @@ -261,12 +262,6 @@ class CX86RecompilerOps :
return m_Assembler;
}

public:
uint32_t CompilePC()
{
return m_CompilePC;
}

private:
CX86RecompilerOps(const CX86RecompilerOps &);
CX86RecompilerOps & operator=(const CX86RecompilerOps &);
Expand Down Expand Up @@ -304,7 +299,7 @@ class CX86RecompilerOps :
EXIT_LIST m_ExitInfo;
CX86Ops m_Assembler;
PIPELINE_STAGE m_PipelineStage;
uint32_t m_CompilePC;
const uint32_t & m_CompilePC;
CX86RegInfo m_RegWorkingSet;
CRegInfo m_RegBeforeDelay;
bool m_EffectDelaySlot;
Expand Down

0 comments on commit 6610ae3

Please sign in to comment.