From 5750d3df800b33f956ce700f13441de5fde81e92 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 24 Oct 2024 09:59:41 +1030 Subject: [PATCH] Core: Have only one function to do what R4300iOp::ExecuteOps and R4300iOp::ExecuteCPU was doing --- .../N64System/Interpreter/InterpreterOps.cpp | 127 +----------------- .../N64System/Interpreter/InterpreterOps.h | 2 +- Source/Project64-core/N64System/N64System.cpp | 2 +- Source/Project64-core/N64System/N64System.h | 2 +- 4 files changed, 10 insertions(+), 123 deletions(-) diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp index 8a4eee5be..1e10a07c2 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp @@ -73,10 +73,8 @@ void R4300iOp::InPermLoop() } } -void R4300iOp::ExecuteCPU() +void R4300iOp::ExecuteOps(uint32_t Cycles) { - WriteTrace(TraceN64System, TraceDebug, "Start"); - bool & Done = m_System.m_EndEmulation; PIPELINE_STAGE & PipelineStage = m_System.m_PipelineStage; uint64_t & JumpToLocation = m_System.m_JumpToLocation; @@ -88,7 +86,7 @@ void R4300iOp::ExecuteCPU() int32_t & NextTimer = *g_NextTimer; bool CheckTimer = false; - while (!Done) + while (!Done && Cycles > 0) { if ((uint64_t)((int32_t)m_PROGRAM_COUNTER) != m_PROGRAM_COUNTER) { @@ -136,16 +134,13 @@ void R4300iOp::ExecuteCPU() g_Debugger->CPUStep(); } - /* if (PROGRAM_COUNTER > 0x80000300 && PROGRAM_COUNTER < 0x80380000) - { - WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str()); - // WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),m_GPR[0x19].UW[0],m_GPR[0x03].UW[0]); - // WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",m_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType()); - } */ - (this->*Jump_Opcode[m_Opcode.op])(); m_GPR[0].DW = 0; // MIPS $zero hard-wired to 0 NextTimer -= CountPerOp; + if (Cycles != (uint32_t)-1) + { + Cycles -= CountPerOp; + } if (CDebugSettings::HaveDebugger()) { @@ -205,115 +200,7 @@ void R4300iOp::ExecuteCPU() g_Notify->BreakPoint(__FILE__, __LINE__); } } - WriteTrace(TraceN64System, TraceDebug, "Done"); -} - -void R4300iOp::ExecuteOps(int32_t Cycles) -{ - bool & Done = m_System.m_EndEmulation; - PIPELINE_STAGE & PipelineStage = m_System.m_PipelineStage; - uint64_t & JumpDelayLocation = m_System.m_JumpDelayLocation; - uint64_t & JumpToLocation = m_System.m_JumpToLocation; - bool & TestTimer = m_System.m_TestTimer; - CSystemEvents & SystemEvents = m_System.m_SystemEvents; - const bool & DoSomething = SystemEvents.DoSomething(); - uint32_t CountPerOp = m_System.CountPerOp(); - bool CheckTimer = false; - - while (!Done) - { - if (Cycles <= 0) - { - g_SystemTimer->UpdateTimers(); - return; - } - - if (m_MMU.MemoryValue32((uint32_t)m_PROGRAM_COUNTER, m_Opcode.Value)) - { - /*if (PROGRAM_COUNTER > 0x80000300 && PROGRAM_COUNTER< 0x80380000) - { - WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str()); - //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),m_GPR[0x19].UW[0],m_GPR[0x03].UW[0]); - //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",m_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType()); - }*/ - /*if (PROGRAM_COUNTER > 0x80323000 && PROGRAM_COUNTER< 0x80380000) - { - WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str()); - //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %s t9: %08X v1: %08X",m_PROGRAM_COUNTER,R4300iInstruction(m_PROGRAM_COUNTER, Opcode.Value).NameAndParam().c_str(),m_GPR[0x19].UW[0],m_GPR[0x03].UW[0]); - //WriteTraceF((TraceType)(TraceError | TraceNoHeader),"%X: %d %d",m_PROGRAM_COUNTER,*g_NextTimer,g_SystemTimer->CurrentType()); - }*/ - (this->*Jump_Opcode[m_Opcode.op])(); - m_GPR[0].DW = 0; /* MIPS $zero hard-wired to 0 */ - - Cycles -= CountPerOp; - *g_NextTimer -= CountPerOp; - - /*static uint32_t TestAddress = 0x80077B0C, TestValue = 0, CurrentValue = 0; - if (m_MMU.MemoryValue32(TestAddress, TestValue)) - { - if (TestValue != CurrentValue) - { - WriteTraceF(TraceError,"%X: %X changed (%s)",PROGRAM_COUNTER,TestAddress,R4300iInstruction(PROGRAM_COUNTER, m_Opcode.Value).NameAndParam().c_str()); - CurrentValue = TestValue; - } - }*/ - - switch (PipelineStage) - { - case PIPELINE_STAGE_NORMAL: - m_PROGRAM_COUNTER += 4; - break; - case PIPELINE_STAGE_DELAY_SLOT: - PipelineStage = PIPELINE_STAGE_JUMP; - m_PROGRAM_COUNTER += 4; - break; - case PIPELINE_STAGE_PERMLOOP_DO_DELAY: - PipelineStage = PIPELINE_STAGE_PERMLOOP_DELAY_DONE; - m_PROGRAM_COUNTER += 4; - break; - case PIPELINE_STAGE_JUMP: - CheckTimer = (JumpToLocation < m_PROGRAM_COUNTER || TestTimer); - m_PROGRAM_COUNTER = JumpToLocation; - PipelineStage = PIPELINE_STAGE_NORMAL; - if (CheckTimer) - { - TestTimer = false; - if (*g_NextTimer < 0) - { - g_SystemTimer->TimerDone(); - } - if (DoSomething) - { - SystemEvents.ExecuteEvents(); - } - } - break; - case PIPELINE_STAGE_JUMP_DELAY_SLOT: - PipelineStage = PIPELINE_STAGE_JUMP; - m_PROGRAM_COUNTER = JumpToLocation; - JumpToLocation = JumpDelayLocation; - break; - case PIPELINE_STAGE_PERMLOOP_DELAY_DONE: - m_PROGRAM_COUNTER = JumpToLocation; - PipelineStage = PIPELINE_STAGE_NORMAL; - InPermLoop(); - g_SystemTimer->TimerDone(); - if (DoSomething) - { - SystemEvents.ExecuteEvents(); - } - break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - } - else - { - m_Reg.TriggerAddressException((int32_t)m_PROGRAM_COUNTER, EXC_RMISS); - m_PROGRAM_COUNTER = JumpToLocation; - PipelineStage = PIPELINE_STAGE_NORMAL; - } - } + g_SystemTimer->UpdateTimers(); } void R4300iOp::SPECIAL() diff --git a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h index 970861390..4deaa0b3c 100644 --- a/Source/Project64-core/N64System/Interpreter/InterpreterOps.h +++ b/Source/Project64-core/N64System/Interpreter/InterpreterOps.h @@ -17,7 +17,7 @@ public: ~R4300iOp(void); void ExecuteCPU(); - void ExecuteOps(int32_t Cycles); + void ExecuteOps(uint32_t Cycles); void InPermLoop(); R4300iOpcode Opcode(void) const diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index 232414971..07b702da6 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -1052,7 +1052,7 @@ void CN64System::ExecuteCPU() void CN64System::ExecuteInterpret() { SetActiveSystem(); - m_OpCodes.ExecuteCPU(); + m_OpCodes.ExecuteOps((uint32_t)-1); } void CN64System::ExecuteRecompiler() diff --git a/Source/Project64-core/N64System/N64System.h b/Source/Project64-core/N64System/N64System.h index a3ade1ced..cf812ddc5 100644 --- a/Source/Project64-core/N64System/N64System.h +++ b/Source/Project64-core/N64System/N64System.h @@ -47,7 +47,6 @@ public: CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem); virtual ~CN64System(void); - bool m_EndEmulation; SAVE_CHIP_TYPE m_SaveUsing; // Methods @@ -189,6 +188,7 @@ private: CProfiling m_CPU_Usage; // Used to track the CPU usage CRecompiler * m_Recomp; CSpeedLimiter m_Limiter; + bool m_EndEmulation; bool m_InReset; int32_t m_NextTimer; CSystemTimer m_SystemTimer;