2023-08-16 23:29:22 +00:00
|
|
|
#include "RspLog.h"
|
|
|
|
#include "RSPRegisters.h"
|
2021-04-14 05:34:15 +00:00
|
|
|
#include <Common/File.h>
|
|
|
|
#include <Common/Log.h>
|
2023-06-01 11:46:23 +00:00
|
|
|
#include <Common/StdString.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
#include <Common/path.h>
|
2023-08-10 04:46:57 +00:00
|
|
|
#include <Project64-rsp-core/RSPInfo.h>
|
2023-11-09 01:23:06 +00:00
|
|
|
#include <Project64-rsp-core/Settings/RspSettings.h>
|
|
|
|
#include <Settings/Settings.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2024-07-06 09:21:55 +00:00
|
|
|
CLog * RDPLog = nullptr;
|
|
|
|
CLog * CPULog = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void StartCPULog(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2024-07-06 09:21:55 +00:00
|
|
|
if (CPULog != nullptr)
|
2023-06-01 11:46:23 +00:00
|
|
|
{
|
2024-07-06 09:21:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
char LogDir[260];
|
|
|
|
CPath LogFilePath(GetSystemSettingSz(Set_DirectoryLog, LogDir, sizeof(LogDir)), "RSP_x86Log.txt");
|
|
|
|
CPULog = new CLog;
|
|
|
|
if (CPULog != nullptr)
|
|
|
|
{
|
|
|
|
if (CPULog->Open(LogFilePath))
|
|
|
|
{
|
|
|
|
CPULog->SetMaxFileSize(300 * CLog::MB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StopCPULog();
|
|
|
|
}
|
2023-06-01 11:46:23 +00:00
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void StopCPULog(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (CPULog != NULL)
|
|
|
|
{
|
|
|
|
delete CPULog;
|
|
|
|
CPULog = NULL;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void CPU_Message(const char * Message, ...)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (CPULog == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
stdstr Msg;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, Message);
|
|
|
|
Msg.ArgFormat(Message, args);
|
|
|
|
va_end(args);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
Msg += "\r\n";
|
|
|
|
|
|
|
|
CPULog->Log(Msg.c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void StartRDPLog(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-11-09 01:23:06 +00:00
|
|
|
if (RDPLog == nullptr && Set_DirectoryLog != 0)
|
2023-06-01 11:46:23 +00:00
|
|
|
{
|
2023-11-09 01:23:06 +00:00
|
|
|
char LogDir[260];
|
|
|
|
CPath LogFilePath(GetSystemSettingSz(Set_DirectoryLog, LogDir, sizeof(LogDir)), "RDP_Log.txt");
|
2023-06-01 11:46:23 +00:00
|
|
|
RDPLog = new CLog;
|
2023-11-09 01:23:06 +00:00
|
|
|
RDPLog->Open(LogFilePath);
|
2023-06-01 11:46:23 +00:00
|
|
|
RDPLog->SetMaxFileSize(400 * 1024 * 1024);
|
|
|
|
// RDPLog->SetFlush(true);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void StopRDPLog(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (RDPLog != NULL)
|
|
|
|
{
|
|
|
|
delete RDPLog;
|
|
|
|
RDPLog = NULL;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void RDP_Message(const char * Message, ...)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (RDPLog == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
stdstr Msg;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, Message);
|
|
|
|
Msg.ArgFormat(Message, args);
|
|
|
|
va_end(args);
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
Msg += "\r\n";
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
RDPLog->Log(Msg.c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 23:29:22 +00:00
|
|
|
void RDP_LogMT0(uint32_t PC, int Reg, uint32_t Value)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (RDPLog == NULL)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 23:29:22 +00:00
|
|
|
void RDP_LogMF0(uint32_t PC, int Reg)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:23 +00:00
|
|
|
void RDP_LogDlist(void)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-06-01 11:46:23 +00:00
|
|
|
if (RDPLog == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-08-16 23:29:22 +00:00
|
|
|
uint32_t Length = *RSPInfo.DPC_END_REG - *RSPInfo.DPC_CURRENT_REG;
|
2023-06-01 11:46:23 +00:00
|
|
|
RDP_Message(" Dlist length = %d bytes", Length);
|
|
|
|
|
2023-08-16 23:29:22 +00:00
|
|
|
uint32_t Pos = *RSPInfo.DPC_CURRENT_REG;
|
2023-06-01 11:46:23 +00:00
|
|
|
while (Pos < *RSPInfo.DPC_END_REG)
|
|
|
|
{
|
|
|
|
char Hex[100], Ascii[30];
|
2023-08-16 23:29:22 +00:00
|
|
|
uint32_t count;
|
2023-06-01 11:46:23 +00:00
|
|
|
|
|
|
|
memset(&Hex, 0, sizeof(Hex));
|
|
|
|
memset(&Ascii, 0, sizeof(Ascii));
|
|
|
|
|
2023-08-16 23:29:22 +00:00
|
|
|
uint8_t * Mem = RSPInfo.DMEM;
|
2023-06-01 11:46:23 +00:00
|
|
|
if ((*RSPInfo.DPC_STATUS_REG & DPC_STATUS_XBUS_DMEM_DMA) == 0)
|
|
|
|
{
|
|
|
|
Mem = RSPInfo.RDRAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0; count < 0x10; count++, Pos++)
|
|
|
|
{
|
|
|
|
char tmp[3];
|
|
|
|
if ((count % 4) != 0 || count == 0)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "%02X", Mem[Pos]);
|
|
|
|
strcat(Hex, " ");
|
|
|
|
strcat(Hex, tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(tmp, "%02X", Mem[Pos]);
|
|
|
|
strcat(Hex, " - ");
|
|
|
|
strcat(Hex, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Mem[Pos] < 30 || Mem[Pos] > 127)
|
|
|
|
{
|
|
|
|
strcat(Ascii, ".");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(tmp, "%c", Mem[Pos]);
|
|
|
|
strcat(Ascii, tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RDP_Message(" %s %s", Hex, Ascii);
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 23:29:22 +00:00
|
|
|
void RDP_LogLoc(uint32_t /*PC*/)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2023-08-16 23:29:22 +00:00
|
|
|
// 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],
|
2023-06-01 11:46:23 +00:00
|
|
|
// 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]);
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|