diff --git a/Source/Project64-rsp-core/RSPInfo.cpp b/Source/Project64-rsp-core/RSPInfo.cpp index 06f261e33..89268f192 100644 --- a/Source/Project64-rsp-core/RSPInfo.cpp +++ b/Source/Project64-rsp-core/RSPInfo.cpp @@ -159,7 +159,7 @@ void RspRomClosed(void) } g_RSPRegisterHandler.reset(nullptr); ClearAllx86Code(); - StopRDPLog(); + RDPLog.StopLog(); StopCPULog(); #ifdef GenerateLog diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp b/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp index cd162867e..b9484bcca 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerCPU.cpp @@ -874,15 +874,6 @@ void CRSPRecompiler::CompilerRSPBlock(void) #endif RSP_LW_IMEM(CompilePC, &m_OpCode.Value); - if (LogRDP && NextInstruction != RSPPIPELINE_DELAY_SLOT_DONE) - { - char str[40]; - sprintf(str, "%X", CompilePC); - PushImm32(str, CompilePC); - Call_Direct((void *)RDP_LogLoc, "RDP_LogLoc"); - AddConstToX86Reg(x86_ESP, 4); - } - if (m_OpCode.Value == 0xFFFFFFFF) { // I think this pops up an unknown OP dialog diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp index 53406a66a..6144bda49 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerOps.cpp @@ -2172,8 +2172,8 @@ void CRSPRecompilerOps::Cop0_MF(void) PushImm32(str, m_OpCode.rd); sprintf(str, "%X", CompilePC); PushImm32(str, CompilePC); - Call_Direct((void *)RDP_LogMF0, "RDP_LogMF0"); - AddConstToX86Reg(x86_ESP, 8); + MoveConstToX86reg((uint32_t)(&RDPLog), x86_ECX); + Call_Direct(AddressOf(&CRDPLog::LogMF0), "CRDPLog::LogMF0"); } #ifndef Compile_Cop0 @@ -2306,8 +2306,8 @@ void CRSPRecompilerOps::Cop0_MT(void) PushImm32(str, m_OpCode.rd); sprintf(str, "%X", CompilePC); PushImm32(str, CompilePC); - Call_Direct((void *)RDP_LogMT0, "RDP_LogMT0"); - AddConstToX86Reg(x86_ESP, 12); + MoveConstToX86reg((uint32_t)(&RDPLog), x86_ECX); + Call_Direct(AddressOf(&CRDPLog::LogMT0), "CRDPLog::LogMT0"); } #ifndef Compile_Cop0 @@ -2397,7 +2397,8 @@ void CRSPRecompilerOps::Cop0_MT(void) if (LogRDP) { - Call_Direct((void *)RDP_LogDlist, "RDP_LogDlist"); + MoveConstToX86reg((uint32_t)(&RDPLog), x86_ECX); + Call_Direct(AddressOf(&CRDPLog::LogDlist), "CRDPLog::LogDlist"); } if (RSPInfo.ProcessRdpList != NULL) diff --git a/Source/Project64-rsp-core/Recompiler/RspRecompilerSections.cpp b/Source/Project64-rsp-core/Recompiler/RspRecompilerSections.cpp index fd5dba327..e66b25c24 100644 --- a/Source/Project64-rsp-core/Recompiler/RspRecompilerSections.cpp +++ b/Source/Project64-rsp-core/Recompiler/RspRecompilerSections.cpp @@ -612,28 +612,11 @@ void CRSPRecompilerOps::Compile_Section_000(void) CPU_Message("Compiling: %X to ..., RSP optimization $000", CompilePC); CPU_Message(" %X %s", CompilePC + 0x00, RSPInstruction(CompilePC + 0x00, vmudn.Value).NameAndParam().c_str()); - if (LogRDP) - { - char str[40]; - sprintf(str, "%X", CompilePC); - PushImm32(str, CompilePC); - Call_Direct((void *)RDP_LogLoc, "RDP_LogLoc"); - AddConstToX86Reg(x86_ESP, 4); - } for (i = 0; i < Section_000_VMADN; i++) { RSP_LW_IMEM(CompilePC + 0x04 + (i * 4), &vmadn.Value); CPU_Message(" %X %s", CompilePC + 0x04 + (i * 4), RSPInstruction(CompilePC + 0x04 + (i * 4), vmadn.Value).NameAndParam().c_str()); - - if (LogRDP) - { - char str[40]; - sprintf(str, "%X", CompilePC + 0x04 + (i * 4)); - PushImm32(str, CompilePC + 0x04 + (i * 4)); - Call_Direct((void *)RDP_LogLoc, "RDP_LogLoc"); - AddConstToX86Reg(x86_ESP, 4); - } } RSP_Sections_VMUDN(vmudn, Low16BitAccum); @@ -849,14 +832,6 @@ void CRSPRecompilerOps::Compile_Section_002(void) { RSP_LW_IMEM(CompilePC + (Count * 0x04), &op[Count].Value); CPU_Message(" %X %s", CompilePC + (Count * 0x04), RSPInstruction(CompilePC + (Count * 0x04), op[Count].Value).NameAndParam().c_str()); - if (LogRDP) - { - char str[40]; - sprintf(str, "%X", CompilePC + (Count * 0x04)); - PushImm32(str, CompilePC + (Count * 0x04)); - Call_Direct((void *)RDP_LogLoc, "RDP_LogLoc"); - AddConstToX86Reg(x86_ESP, 4); - } } vmudh = op[0]; diff --git a/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp b/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp index 070396fc0..64c55c3f7 100644 --- a/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp +++ b/Source/Project64-rsp-core/cpu/RSPInterpreterOps.cpp @@ -849,7 +849,7 @@ void RSPOp::Cop0_MT(void) { if (LogRDP && g_CPUCore == InterpreterCPU) { - RDP_LogMT0(*m_SP_PC_REG, m_OpCode.rd, m_GPR[m_OpCode.rt].UW); + RDPLog.LogMT0(*m_SP_PC_REG, m_OpCode.rd, m_GPR[m_OpCode.rt].UW); } switch (m_OpCode.rd) { @@ -865,7 +865,7 @@ void RSPOp::Cop0_MT(void) break; case 9: *m_DPC_END_REG = m_GPR[m_OpCode.rt].UW; - RDP_LogDlist(); + RDPLog.LogDlist(); if (ProcessRdpList != nullptr) { ProcessRdpList(); diff --git a/Source/Project64-rsp-core/cpu/RspLog.cpp b/Source/Project64-rsp-core/cpu/RspLog.cpp index 86623971b..666f85c68 100644 --- a/Source/Project64-rsp-core/cpu/RspLog.cpp +++ b/Source/Project64-rsp-core/cpu/RspLog.cpp @@ -6,9 +6,10 @@ #include #include #include +#include #include -CLog * RDPLog = nullptr; +CRDPLog RDPLog(RSPSystem); CLog * CPULog = nullptr; void StartCPULog(void) @@ -61,31 +62,44 @@ void CPU_Message(const char * Message, ...) CPULog->Log(Msg.c_str()); } -void StartRDPLog(void) +CRDPLog::CRDPLog(CRSPSystem & System) : + m_System(System), + m_Log(nullptr), + m_DPC_START_REG(System.m_DPC_START_REG), + m_DPC_END_REG(System.m_DPC_END_REG), + m_DPC_CURRENT_REG(System.m_DPC_CURRENT_REG), + m_DPC_STATUS_REG(System.m_DPC_STATUS_REG), + m_DPC_CLOCK_REG(System.m_DPC_CLOCK_REG), + m_RDRAM(System.m_RDRAM), + m_DMEM(System.m_DMEM) { - if (RDPLog == nullptr && Set_DirectoryLog != 0) +} + +void CRDPLog::StartLog(void) +{ + if (m_Log == nullptr && Set_DirectoryLog != 0) { char LogDir[260]; CPath LogFilePath(GetSystemSettingSz(Set_DirectoryLog, LogDir, sizeof(LogDir)), "RDP_Log.txt"); - RDPLog = new CLog; - RDPLog->Open(LogFilePath); - RDPLog->SetMaxFileSize(400 * 1024 * 1024); + m_Log = new CLog; + m_Log->Open(LogFilePath); + m_Log->SetMaxFileSize(400 * 1024 * 1024); // RDPLog->SetFlush(true); } } -void StopRDPLog(void) +void CRDPLog::StopLog(void) { - if (RDPLog != NULL) + if (m_Log != nullptr) { - delete RDPLog; - RDPLog = NULL; + delete m_Log; + m_Log = nullptr; } } -void RDP_Message(const char * Message, ...) +void CRDPLog::Message(const char * Message, ...) { - if (RDPLog == NULL) + if (m_Log == nullptr) { return; } @@ -99,56 +113,56 @@ void RDP_Message(const char * Message, ...) Msg += "\r\n"; - RDPLog->Log(Msg.c_str()); + m_Log->Log(Msg.c_str()); } -void RDP_LogMT0(uint32_t PC, int Reg, uint32_t Value) +void CRDPLog::LogMT0(uint32_t PC, int Reg, uint32_t Value) { - if (RDPLog == NULL) + if (m_Log == nullptr) { return; } switch (Reg) { - case 0: RDP_Message("%03X: Stored 0x%08X into SP_MEM_ADDR_REG", PC, Value); break; - case 1: RDP_Message("%03X: Stored 0x%08X into SP_DRAM_ADDR_REG", PC, Value); break; - case 2: RDP_Message("%03X: Stored 0x%08X into SP_RD_LEN_REG", PC, Value); break; - case 3: RDP_Message("%03X: Stored 0x%08X into SP_WR_LEN_REG", PC, Value); break; - case 4: RDP_Message("%03X: Stored 0x%08X into SP_STATUS_REG", PC, Value); break; - case 5: RDP_Message("%03X: Stored 0x%08X into Reg 5 ???", PC, Value); break; - case 6: RDP_Message("%03X: Stored 0x%08X into Reg 6 ???", PC, Value); break; - case 7: RDP_Message("%03X: Stored 0x%08X into SP_SEMAPHORE_REG", PC, Value); break; - case 8: RDP_Message("%03X: Stored 0x%08X into DPC_START_REG", PC, Value); break; - case 9: RDP_Message("%03X: Stored 0x%08X into DPC_END_REG", PC, Value); break; - case 10: RDP_Message("%03X: Stored 0x%08X into DPC_CURRENT_REG", PC, Value); break; - case 11: RDP_Message("%03X: Stored 0x%08X into DPC_STATUS_REG", PC, Value); break; - case 12: RDP_Message("%03X: Stored 0x%08X into DPC_CLOCK_REG", PC, Value); break; + case 0: Message("%03X: Stored 0x%08X into SP_MEM_ADDR_REG", PC, Value); break; + case 1: Message("%03X: Stored 0x%08X into SP_DRAM_ADDR_REG", PC, Value); break; + case 2: Message("%03X: Stored 0x%08X into SP_RD_LEN_REG", PC, Value); break; + case 3: Message("%03X: Stored 0x%08X into SP_WR_LEN_REG", PC, Value); break; + case 4: Message("%03X: Stored 0x%08X into SP_STATUS_REG", PC, Value); break; + case 5: Message("%03X: Stored 0x%08X into Reg 5 ???", PC, Value); break; + case 6: Message("%03X: Stored 0x%08X into Reg 6 ???", PC, Value); break; + case 7: Message("%03X: Stored 0x%08X into SP_SEMAPHORE_REG", PC, Value); break; + case 8: Message("%03X: Stored 0x%08X into DPC_START_REG", PC, Value); break; + case 9: Message("%03X: Stored 0x%08X into DPC_END_REG", PC, Value); break; + case 10: Message("%03X: Stored 0x%08X into DPC_CURRENT_REG", PC, Value); break; + case 11: Message("%03X: Stored 0x%08X into DPC_STATUS_REG", PC, Value); break; + case 12: Message("%03X: Stored 0x%08X into DPC_CLOCK_REG", PC, Value); break; } } -void RDP_LogMF0(uint32_t PC, int Reg) +void CRDPLog::LogMF0(uint32_t PC, int Reg) { switch (Reg) { - case 8: RDP_Message("%03X: Read 0x%08X from DPC_START_REG", PC, *RSPInfo.DPC_START_REG); break; - case 9: RDP_Message("%03X: Read 0x%08X from DPC_END_REG", PC, *RSPInfo.DPC_END_REG); break; - case 10: RDP_Message("%03X: Read 0x%08X from DPC_CURRENT_REG", PC, *RSPInfo.DPC_CURRENT_REG); break; - case 11: RDP_Message("%03X: Read 0x%08X from DPC_STATUS_REG", PC, *RSPInfo.DPC_STATUS_REG); break; - case 12: RDP_Message("%03X: Read 0x%08X from DPC_CLOCK_REG", PC, *RSPInfo.DPC_CLOCK_REG); break; + case 8: Message("%03X: Read 0x%08X from DPC_START_REG", PC, *m_DPC_START_REG); break; + case 9: Message("%03X: Read 0x%08X from DPC_END_REG", PC, *m_DPC_END_REG); break; + case 10: Message("%03X: Read 0x%08X from DPC_CURRENT_REG", PC, *m_DPC_CURRENT_REG); break; + case 11: Message("%03X: Read 0x%08X from DPC_STATUS_REG", PC, *m_DPC_STATUS_REG); break; + case 12: Message("%03X: Read 0x%08X from DPC_CLOCK_REG", PC, *m_DPC_CLOCK_REG); break; } } -void RDP_LogDlist(void) +void CRDPLog::LogDlist(void) { - if (RDPLog == NULL) + if (m_Log == nullptr) { return; } - uint32_t Length = *RSPInfo.DPC_END_REG - *RSPInfo.DPC_CURRENT_REG; - RDP_Message(" Dlist length = %d bytes", Length); + uint32_t Length = *m_DPC_END_REG - *m_DPC_CURRENT_REG; + Message(" Dlist length = %d bytes", Length); - uint32_t Pos = *RSPInfo.DPC_CURRENT_REG; - while (Pos < *RSPInfo.DPC_END_REG) + uint32_t Pos = *m_DPC_CURRENT_REG; + while (Pos < *m_DPC_END_REG) { char Hex[100], Ascii[30]; uint32_t count; @@ -156,10 +170,10 @@ void RDP_LogDlist(void) memset(&Hex, 0, sizeof(Hex)); memset(&Ascii, 0, sizeof(Ascii)); - uint8_t * Mem = RSPInfo.DMEM; - if ((*RSPInfo.DPC_STATUS_REG & DPC_STATUS_XBUS_DMEM_DMA) == 0) + uint8_t * Mem = m_DMEM; + if ((*m_DPC_STATUS_REG & DPC_STATUS_XBUS_DMEM_DMA) == 0) { - Mem = RSPInfo.RDRAM; + Mem = m_RDRAM; } for (count = 0; count < 0x10; count++, Pos++) @@ -188,13 +202,6 @@ void RDP_LogDlist(void) strcat(Ascii, tmp); } } - RDP_Message(" %s %s", Hex, Ascii); + Message(" %s %s", Hex, Ascii); } } - -void RDP_LogLoc(uint32_t /*PC*/) -{ - // RDP_Message("%03X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X %08X",PC, RSP_GPR[26].UW, *(uint32_t *)&RSPInfo.IMEM[0xDBC], - // RSP_Flags[0].UW, RSP_Vect[0].UW[0],RSP_Vect[0].UW[1],RSP_Vect[0].UW[2],RSP_Vect[0].UW[3], - // RSP_Vect[28].UW[0],RSP_Vect[28].UW[1],RSP_Vect[28].UW[2],RSP_Vect[28].UW[3],RSP_Vect[31].UW[0]); -} diff --git a/Source/Project64-rsp-core/cpu/RspLog.h b/Source/Project64-rsp-core/cpu/RspLog.h index f7131c0c5..cf721b338 100644 --- a/Source/Project64-rsp-core/cpu/RspLog.h +++ b/Source/Project64-rsp-core/cpu/RspLog.h @@ -5,10 +5,31 @@ void StartCPULog(void); void StopCPULog(void); void CPU_Message(const char * Message, ...); -void StartRDPLog(void); -void StopRDPLog(void); -void RDP_Message(const char * Message, ...); -void RDP_LogDlist(void); -void RDP_LogMT0(uint32_t PC, int Reg, uint32_t Value); -void RDP_LogMF0(uint32_t PC, int Reg); -void RDP_LogLoc(uint32_t PC); \ No newline at end of file +class CRSPSystem; +class CLog; + +class CRDPLog +{ +public: + CRDPLog(CRSPSystem & System); + + void StartLog(void); + void StopLog(void); + void Message(const char * Message, ...); + void LogDlist(void); + void LogMT0(uint32_t PC, int Reg, uint32_t Value); + void LogMF0(uint32_t PC, int Reg); + +private: + CRSPSystem & m_System; + CLog * m_Log; + uint32_t *& m_DPC_START_REG; + uint32_t *& m_DPC_END_REG; + uint32_t *& m_DPC_CURRENT_REG; + uint32_t *& m_DPC_STATUS_REG; + uint32_t *& m_DPC_CLOCK_REG; + uint8_t *& m_RDRAM; + uint8_t *& m_DMEM; +}; + +extern CRDPLog RDPLog; diff --git a/Source/Project64-rsp-core/cpu/RspSystem.cpp b/Source/Project64-rsp-core/cpu/RspSystem.cpp index 6a2886682..431f85300 100644 --- a/Source/Project64-rsp-core/cpu/RspSystem.cpp +++ b/Source/Project64-rsp-core/cpu/RspSystem.cpp @@ -76,36 +76,36 @@ uint32_t CRSPSystem::RunInterpreterCPU(uint32_t Cycles) } CycleCount = 0; uint32_t & GprR0 = m_Reg.m_GPR[0].UW; - uint32_t & PrgCount = *m_SP_PC_REG; + uint32_t & ProgramCounter = *m_SP_PC_REG; while (RSP_Running) { if (g_RSPDebugger != nullptr) { g_RSPDebugger->BeforeExecuteOp(); } - m_OpCode.Value = *(uint32_t *)(RSPInfo.IMEM + (PrgCount & 0xFFC)); + m_OpCode.Value = *(uint32_t *)(m_IMEM + (ProgramCounter & 0xFFC)); (m_Op.*(m_Op.Jump_Opcode[m_OpCode.op]))(); GprR0 = 0x00000000; // MIPS $zero hard-wired to 0 switch (RSP_NextInstruction) { case RSPPIPELINE_NORMAL: - PrgCount = (PrgCount + 4) & 0xFFC; + ProgramCounter = (ProgramCounter + 4) & 0xFFC; break; case RSPPIPELINE_DELAY_SLOT: RSP_NextInstruction = RSPPIPELINE_JUMP; - PrgCount = (PrgCount + 4) & 0xFFC; + ProgramCounter = (ProgramCounter + 4) & 0xFFC; break; case RSPPIPELINE_JUMP: RSP_NextInstruction = RSPPIPELINE_NORMAL; - PrgCount = RSP_JumpTo; + ProgramCounter = RSP_JumpTo; break; case RSPPIPELINE_SINGLE_STEP: - PrgCount = (PrgCount + 4) & 0xFFC; + ProgramCounter = (ProgramCounter + 4) & 0xFFC; RSP_NextInstruction = RSPPIPELINE_SINGLE_STEP_DONE; break; case RSPPIPELINE_SINGLE_STEP_DONE: - PrgCount = (PrgCount + 4) & 0xFFC; + ProgramCounter = (ProgramCounter + 4) & 0xFFC; *m_SP_STATUS_REG |= SP_STATUS_HALT; RSP_Running = false; break; diff --git a/Source/Project64-rsp-core/cpu/RspSystem.h b/Source/Project64-rsp-core/cpu/RspSystem.h index 064218b81..f72357987 100644 --- a/Source/Project64-rsp-core/cpu/RspSystem.h +++ b/Source/Project64-rsp-core/cpu/RspSystem.h @@ -11,6 +11,7 @@ class CRSPSystem friend class CRSPRecompilerOps; friend class CRSPRecompiler; friend class RSPDebuggerUI; + friend class CRDPLog; friend void UpdateRSPRegistersScreen(void); public: diff --git a/Source/Project64-rsp/Debugger/RSPDebuggerUI.cpp b/Source/Project64-rsp/Debugger/RSPDebuggerUI.cpp index 067ee4c7c..3ecca4b78 100644 --- a/Source/Project64-rsp/Debugger/RSPDebuggerUI.cpp +++ b/Source/Project64-rsp/Debugger/RSPDebuggerUI.cpp @@ -11,7 +11,6 @@ #include void UpdateRSPRegistersScreen(void); -void RDP_LogLoc(DWORD /*PC*/); RSPDebuggerUI::RSPDebuggerUI(CRSPSystem & System) : m_System(System), @@ -93,8 +92,6 @@ void RSPDebuggerUI::BeforeExecuteOp(void) } } } - - RDP_LogLoc(*PrgCount); } void RSPDebuggerUI::UnknownOpcode(void) @@ -124,6 +121,6 @@ void RSPDebuggerUI::RDP_LogMF0(uint32_t PC, uint32_t Reg) { if (LogRDP && g_CPUCore == InterpreterCPU) { - ::RDP_LogMF0(PC, Reg); + RDPLog.LogMF0(PC, Reg); } } diff --git a/Source/Project64-rsp/Main.cpp b/Source/Project64-rsp/Main.cpp index 5287a07a0..dbfe8579d 100644 --- a/Source/Project64-rsp/Main.cpp +++ b/Source/Project64-rsp/Main.cpp @@ -351,11 +351,11 @@ void ProcessMenuItem(int32_t ID) LogRDP = !Checked; if (LogRDP) { - StartRDPLog(); + RDPLog.StartLog(); } else { - StopRDPLog(); + RDPLog.StopLog(); } } break; @@ -611,7 +611,7 @@ EXPORT void EnableDebugging(int Enabled) #endif if (LogRDP) { - StartRDPLog(); + RDPLog.StartLog(); } if (LogX86Code) {