RSP: Start to have a RSP Settings class

This commit is contained in:
zilmar 2024-08-29 11:26:53 +09:30
parent 96080bfdd2
commit 5eac210197
11 changed files with 104 additions and 48 deletions

View File

@ -89,11 +89,6 @@ void DetectCpuSpecs(void)
void RspPluginLoaded(void) void RspPluginLoaded(void)
{ {
BreakOnStart = false; BreakOnStart = false;
#if defined(_M_IX86) && defined(_MSC_VER)
g_CPUCore = RecompilerCPU;
#else
g_CPUCore = InterpreterCPU;
#endif
LogRDP = false; LogRDP = false;
LogX86Code = false; LogX86Code = false;
Profiling = false; Profiling = false;
@ -111,8 +106,7 @@ void RspPluginLoaded(void)
Compiler.bGPRConstants = true; Compiler.bGPRConstants = true;
DetectCpuSpecs(); DetectCpuSpecs();
InitializeRspSetting(); CRSPSettings::InitializeRspSetting();
SetCPU(g_CPUCore);
} }
void InitilizeRSP(RSP_INFO & Rsp_Info) void InitilizeRSP(RSP_INFO & Rsp_Info)
@ -138,7 +132,9 @@ void InitilizeRSP(RSP_INFO & Rsp_Info)
void RspRomOpened(void) void RspRomOpened(void)
{ {
CRSPSettings::SetRomOpen(true);
ClearAllx86Code(); ClearAllx86Code();
JumpTableSize = GetSetting(Set_JumpTableSize); JumpTableSize = GetSetting(Set_JumpTableSize);
Mfc0Count = GetSetting(Set_Mfc0Count); Mfc0Count = GetSetting(Set_Mfc0Count);
SemaphoreExit = GetSetting(Set_SemaphoreExit); SemaphoreExit = GetSetting(Set_SemaphoreExit);
@ -151,6 +147,7 @@ void RspRomOpened(void)
void RspRomClosed(void) void RspRomClosed(void)
{ {
CRSPSettings::SetRomOpen(false);
if (Profiling) if (Profiling)
{ {
StopTimer(); StopTimer();

View File

@ -4,11 +4,26 @@
#include <Project64-rsp-core/cpu/RSPCpu.h> #include <Project64-rsp-core/cpu/RSPCpu.h>
#include <Settings/Settings.h> #include <Settings/Settings.h>
bool CRSPSettings::m_DebuggingEnabled = false;
bool CRSPSettings::m_RomOpen = false;
#if defined(_M_IX86) && defined(_MSC_VER)
RSPCpuMethod CRSPSettings::m_CPUMethod = RSPCpuMethod::Recompiler;
#else
RSPCpuMethod CRSPSettings::m_CPUMethod = RSPCpuMethod::Interpreter;
#endif
uint16_t Set_AudioHle = 0, Set_GraphicsHle = 0, Set_MultiThreaded = 0, Set_AllocatedRdramSize = 0, Set_DirectoryLog = 0; uint16_t Set_AudioHle = 0, Set_GraphicsHle = 0, Set_MultiThreaded = 0, Set_AllocatedRdramSize = 0, Set_DirectoryLog = 0;
bool GraphicsHle = true, AudioHle, ConditionalMove, HleAlistTask = false, RspMultiThreaded = false; bool GraphicsHle = true, AudioHle, ConditionalMove, HleAlistTask = false, RspMultiThreaded = false;
bool DebuggingEnabled = false, Profiling, IndvidualBlock, ShowErrors, BreakOnStart = false, LogRDP = false, LogX86Code = false; bool DebuggingEnabled = false, Profiling, IndvidualBlock, ShowErrors, BreakOnStart = false, LogRDP = false, LogX86Code = false;
void InitializeRspSetting(void) void CRSPSettings::EnableDebugging(bool Enabled)
{
m_DebuggingEnabled = Enabled;
RefreshSettings();
}
void CRSPSettings::InitializeRspSetting(void)
{ {
SetModuleName("RSP"); SetModuleName("RSP");
Set_GraphicsHle = FindSystemSettingId("HLE GFX"); Set_GraphicsHle = FindSystemSettingId("HLE GFX");
@ -18,7 +33,7 @@ void InitializeRspSetting(void)
Set_DirectoryLog = FindSystemSettingId("Dir:Log"); Set_DirectoryLog = FindSystemSettingId("Dir:Log");
RegisterSetting(Set_BreakOnStart, Data_DWORD_General, "Break on Start", NULL, BreakOnStart, NULL); RegisterSetting(Set_BreakOnStart, Data_DWORD_General, "Break on Start", NULL, BreakOnStart, NULL);
RegisterSetting(Set_CPUCore, Data_DWORD_General, "CPU Method", NULL, g_CPUCore, NULL); RegisterSetting(Set_CPUCore, Data_DWORD_General, "CPU Method", NULL, (int)m_CPUMethod, NULL);
RegisterSetting(Set_LogRDP, Data_DWORD_General, "Log RDP", NULL, LogRDP, NULL); RegisterSetting(Set_LogRDP, Data_DWORD_General, "Log RDP", NULL, LogRDP, NULL);
RegisterSetting(Set_LogX86Code, Data_DWORD_General, "Log X86 Code", NULL, LogX86Code, NULL); RegisterSetting(Set_LogX86Code, Data_DWORD_General, "Log X86 Code", NULL, LogX86Code, NULL);
RegisterSetting(Set_Profiling, Data_DWORD_General, "Profiling", NULL, Profiling, NULL); RegisterSetting(Set_Profiling, Data_DWORD_General, "Profiling", NULL, Profiling, NULL);
@ -45,4 +60,29 @@ void InitializeRspSetting(void)
AudioHle = Set_AudioHle != 0 ? GetSystemSetting(Set_AudioHle) != 0 : false; AudioHle = Set_AudioHle != 0 ? GetSystemSetting(Set_AudioHle) != 0 : false;
GraphicsHle = Set_GraphicsHle != 0 ? GetSystemSetting(Set_GraphicsHle) != 0 : true; GraphicsHle = Set_GraphicsHle != 0 ? GetSystemSetting(Set_GraphicsHle) != 0 : true;
RspMultiThreaded = Set_MultiThreaded != 0 ? GetSystemSetting(Set_MultiThreaded) != 0 : false; RspMultiThreaded = Set_MultiThreaded != 0 ? GetSystemSetting(Set_MultiThreaded) != 0 : false;
RefreshSettings();
}
CRSPSettings::CRSPSettings()
{
}
CRSPSettings::~CRSPSettings()
{
}
void CRSPSettings::RefreshSettings(void)
{
#if defined(_M_IX86) && defined(_MSC_VER)
m_CPUMethod = m_DebuggingEnabled ? (RSPCpuMethod)GetSetting(Set_CPUCore) : RSPCpuMethod::Recompiler;
#else
m_CPUMethod = m_DebuggingEnabled ? (RSPCpuMethod)GetSetting(Set_CPUCore) : RSPCpuMethod::Interpreter;
#endif
}
void CRSPSettings::SetRomOpen(bool Opened)
{
m_RomOpen = Opened;
RefreshSettings();
} }

View File

@ -1,8 +1,42 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
void InitializeRspSetting(void);
extern uint16_t Set_AudioHle, Set_GraphicsHle, Set_AllocatedRdramSize, Set_DirectoryLog; extern uint16_t Set_AudioHle, Set_GraphicsHle, Set_AllocatedRdramSize, Set_DirectoryLog;
extern bool GraphicsHle, AudioHle, ConditionalMove, HleAlistTask, RspMultiThreaded; extern bool GraphicsHle, AudioHle, ConditionalMove, HleAlistTask, RspMultiThreaded;
extern bool DebuggingEnabled, Profiling, IndvidualBlock, ShowErrors, BreakOnStart, LogRDP, LogX86Code; extern bool DebuggingEnabled, Profiling, IndvidualBlock, ShowErrors, BreakOnStart, LogRDP, LogX86Code;
enum class RSPCpuMethod
{
Interpreter = 0,
Recompiler = 1,
};
class CRSPSettings
{
public:
CRSPSettings();
virtual ~CRSPSettings();
inline static RSPCpuMethod CPUMethod(void)
{
return m_CPUMethod;
}
inline static bool RomOpen(void)
{
return m_RomOpen;
}
static void EnableDebugging(bool Enabled);
static void InitializeRspSetting(void);
static void RefreshSettings(void);
static void SetRomOpen(bool Opened);
private:
CRSPSettings(const CRSPSettings &);
CRSPSettings & operator=(const CRSPSettings &);
static bool m_DebuggingEnabled;
static bool m_RomOpen;
static RSPCpuMethod m_CPUMethod;
};

View File

@ -16,13 +16,6 @@ uint32_t RSP_Running;
CriticalSection g_CPUCriticalSection; CriticalSection g_CPUCriticalSection;
uint32_t Mfc0Count, SemaphoreExit = 0; uint32_t Mfc0Count, SemaphoreExit = 0;
RSPCpuType g_CPUCore = InterpreterCPU;
void SetCPU(RSPCpuType core)
{
CGuard Guard(g_CPUCriticalSection);
g_CPUCore = core;
}
void Build_RSP(void) void Build_RSP(void)
{ {
@ -33,7 +26,6 @@ void Build_RSP(void)
SQroot.UW = 0; SQroot.UW = 0;
SQrootResult.UW = 0; SQrootResult.UW = 0;
SetCPU(g_CPUCore);
if (g_RSPDebugger != nullptr) if (g_RSPDebugger != nullptr)
{ {
g_RSPDebugger->ResetTimerList(); g_RSPDebugger->ResetTimerList();
@ -165,12 +157,12 @@ uint32_t DoRspCycles(uint32_t Cycles)
} }
CGuard Guard(g_CPUCriticalSection); CGuard Guard(g_CPUCriticalSection);
switch (g_CPUCore) switch (CRSPSettings::CPUMethod())
{ {
case RecompilerCPU: case RSPCpuMethod::Recompiler:
RSPSystem.RunRecompiler(); RSPSystem.RunRecompiler();
break; break;
case InterpreterCPU: case RSPCpuMethod::Interpreter:
RSPSystem.RunInterpreterCPU(Cycles); RSPSystem.RunInterpreterCPU(Cycles);
break; break;
} }

View File

@ -5,18 +5,10 @@
#include "RspTypes.h" #include "RspTypes.h"
#include <memory> #include <memory>
enum RSPCpuType
{
InterpreterCPU = 0,
RecompilerCPU = 1,
};
extern UDWORD EleSpec[16], Indx[16]; extern UDWORD EleSpec[16], Indx[16];
extern uint32_t RSP_Running; extern uint32_t RSP_Running;
void SetCPU(RSPCpuType core);
void Build_RSP(void); void Build_RSP(void);
extern uint32_t Mfc0Count, SemaphoreExit; extern uint32_t Mfc0Count, SemaphoreExit;
extern RSPCpuType g_CPUCore;

View File

@ -849,7 +849,7 @@ void RSPOp::Cop0_MF(void)
void RSPOp::Cop0_MT(void) void RSPOp::Cop0_MT(void)
{ {
if (LogRDP && g_CPUCore == InterpreterCPU) if (LogRDP && CPUMethod() == RSPCpuMethod::Interpreter)
{ {
RDPLog.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);
} }

View File

@ -7,7 +7,8 @@ class CRSPSystem;
class CRSPRegisters; class CRSPRegisters;
class RSPRegisterHandlerPlugin; class RSPRegisterHandlerPlugin;
class RSPOp class RSPOp :
private CRSPSettings
{ {
friend class CRSPSystem; friend class CRSPSystem;
friend class CRSPRecompilerOps; friend class CRSPRecompilerOps;

View File

@ -41,7 +41,7 @@ void RSPRegisterHandlerPlugin::SetHalt(void)
void RSPRegisterHandlerPlugin::DmaReadDone(uint32_t End) void RSPRegisterHandlerPlugin::DmaReadDone(uint32_t End)
{ {
if (g_CPUCore == RecompilerCPU && (*RSPInfo.SP_MEM_ADDR_REG & 0x1000) != 0 && g_CPUCore == RecompilerCPU) if (CPUMethod() == RSPCpuMethod::Recompiler && (*RSPInfo.SP_MEM_ADDR_REG & 0x1000) != 0)
{ {
m_System.m_Recompiler.SetJumpTable(End); m_System.m_Recompiler.SetJumpTable(End);
} }

View File

@ -1,10 +1,12 @@
#pragma once #pragma once
#include "RSPRegisterHandler.h" #include "RSPRegisterHandler.h"
#include <Project64-rsp-core/Settings/RspSettings.h>
class CRSPSystem; class CRSPSystem;
class RSPRegisterHandlerPlugin : class RSPRegisterHandlerPlugin :
public RSPRegisterHandler public RSPRegisterHandler,
private CRSPSettings
{ {
public: public:
RSPRegisterHandlerPlugin(CRSPSystem & System); RSPRegisterHandlerPlugin(CRSPSystem & System);

View File

@ -119,7 +119,7 @@ void RSPDebuggerUI::UnknownOpcode(void)
void RSPDebuggerUI::RDP_LogMF0(uint32_t PC, uint32_t Reg) void RSPDebuggerUI::RDP_LogMF0(uint32_t PC, uint32_t Reg)
{ {
if (LogRDP && g_CPUCore == InterpreterCPU) if (LogRDP && CRSPSettings::CPUMethod() == RSPCpuMethod::Interpreter)
{ {
RDPLog.LogMF0(PC, Reg); RDPLog.LogMF0(PC, Reg);
} }

View File

@ -173,9 +173,11 @@ void FixMenuState(void)
EnableMenuItem(hRSPMenu, ID_PROFILING_GENERATELOG, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED))); EnableMenuItem(hRSPMenu, ID_PROFILING_GENERATELOG, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
EnableMenuItem(hRSPMenu, ID_DUMP_RSPCODE, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED))); EnableMenuItem(hRSPMenu, ID_DUMP_RSPCODE, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
EnableMenuItem(hRSPMenu, ID_DUMP_DMEM, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED))); EnableMenuItem(hRSPMenu, ID_DUMP_DMEM, MF_BYCOMMAND | (DebuggingEnabled ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
EnableMenuItem(hRSPMenu, ID_CPUMETHOD_RECOMPILER, MF_BYCOMMAND | (!CRSPSettings::RomOpen() ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
EnableMenuItem(hRSPMenu, ID_CPUMETHOD_INTERPT, MF_BYCOMMAND | (!CRSPSettings::RomOpen() ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
CheckMenuItem(hRSPMenu, ID_CPUMETHOD_RECOMPILER, MF_BYCOMMAND | (g_CPUCore == RecompilerCPU ? MFS_CHECKED : MF_UNCHECKED)); CheckMenuItem(hRSPMenu, ID_CPUMETHOD_RECOMPILER, MF_BYCOMMAND | ((RSPCpuMethod)GetSetting(Set_CPUCore) == RSPCpuMethod::Recompiler ? MFS_CHECKED : MF_UNCHECKED));
CheckMenuItem(hRSPMenu, ID_CPUMETHOD_INTERPT, MF_BYCOMMAND | (g_CPUCore == InterpreterCPU ? MFS_CHECKED : MF_UNCHECKED)); CheckMenuItem(hRSPMenu, ID_CPUMETHOD_INTERPT, MF_BYCOMMAND | ((RSPCpuMethod)GetSetting(Set_CPUCore) == RSPCpuMethod::Interpreter ? MFS_CHECKED : MF_UNCHECKED));
CheckMenuItem(hRSPMenu, ID_BREAKONSTARTOFTASK, MF_BYCOMMAND | (BreakOnStart ? MFS_CHECKED : MF_UNCHECKED)); CheckMenuItem(hRSPMenu, ID_BREAKONSTARTOFTASK, MF_BYCOMMAND | (BreakOnStart ? MFS_CHECKED : MF_UNCHECKED));
CheckMenuItem(hRSPMenu, ID_LOGRDPCOMMANDS, MF_BYCOMMAND | (LogRDP ? MFS_CHECKED : MF_UNCHECKED)); CheckMenuItem(hRSPMenu, ID_LOGRDPCOMMANDS, MF_BYCOMMAND | (LogRDP ? MFS_CHECKED : MF_UNCHECKED));
CheckMenuItem(hRSPMenu, ID_SETTINGS_HLEALISTTASK, MF_BYCOMMAND | (HleAlistTask ? MFS_CHECKED : MF_UNCHECKED)); CheckMenuItem(hRSPMenu, ID_SETTINGS_HLEALISTTASK, MF_BYCOMMAND | (HleAlistTask ? MFS_CHECKED : MF_UNCHECKED));
@ -226,6 +228,7 @@ EXPORT void GetRspDebugInfo(RSPDEBUG_INFO * _DebugInfo)
if (hRSPMenu == NULL) if (hRSPMenu == NULL)
{ {
hRSPMenu = LoadMenu((HINSTANCE)hinstDLL, MAKEINTRESOURCE(RspMenu)); hRSPMenu = LoadMenu((HINSTANCE)hinstDLL, MAKEINTRESOURCE(RspMenu));
CRSPSettings::InitializeRspSetting();
FixMenuState(); FixMenuState();
} }
_DebugInfo->hRSPMenu = hRSPMenu; _DebugInfo->hRSPMenu = hRSPMenu;
@ -398,16 +401,12 @@ void ProcessMenuItem(int32_t ID)
break; break;
} }
case ID_CPUMETHOD_RECOMPILER: case ID_CPUMETHOD_RECOMPILER:
SetSetting(Set_CPUCore, RecompilerCPU); SetSetting(Set_CPUCore, (int)RSPCpuMethod::Recompiler);
g_CPUCore = RecompilerCPU;
FixMenuState(); FixMenuState();
SetCPU(RecompilerCPU);
break; break;
case ID_CPUMETHOD_INTERPT: case ID_CPUMETHOD_INTERPT:
SetSetting(Set_CPUCore, InterpreterCPU); SetSetting(Set_CPUCore, (int)RSPCpuMethod::Interpreter);
g_CPUCore = InterpreterCPU;
FixMenuState(); FixMenuState();
SetCPU(InterpreterCPU);
break; break;
} }
} }
@ -439,6 +438,7 @@ Output: None
EXPORT void RomClosed(void) EXPORT void RomClosed(void)
{ {
RspRomClosed(); RspRomClosed();
FixMenuState();
} }
#ifdef _WIN32 #ifdef _WIN32
@ -545,7 +545,7 @@ BOOL CALLBACK ConfigDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM /*lParam
hWndItem = GetDlgItem(hDlg, IDC_COMPILER_SELECT); hWndItem = GetDlgItem(hDlg, IDC_COMPILER_SELECT);
ComboBox_AddString(hWndItem, "Interpreter"); ComboBox_AddString(hWndItem, "Interpreter");
ComboBox_AddString(hWndItem, "Recompiler"); ComboBox_AddString(hWndItem, "Recompiler");
ComboBox_SetCurSel(hWndItem, g_CPUCore); //ComboBox_SetCurSel(hWndItem, g_CPUCore);
break; break;
case WM_COMMAND: case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam)) switch (GET_WM_COMMAND_ID(wParam, lParam))
@ -553,7 +553,6 @@ BOOL CALLBACK ConfigDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM /*lParam
case IDOK: case IDOK:
hWndItem = GetDlgItem(hDlg, IDC_COMPILER_SELECT); hWndItem = GetDlgItem(hDlg, IDC_COMPILER_SELECT);
value = ComboBox_GetCurSel(hWndItem); value = ComboBox_GetCurSel(hWndItem);
SetCPU((RSPCpuType)value);
AudioHle = GetBooleanCheck(hDlg, IDC_AUDIOHLE); AudioHle = GetBooleanCheck(hDlg, IDC_AUDIOHLE);
GraphicsHle = GetBooleanCheck(hDlg, IDC_GRAPHICSHLE); GraphicsHle = GetBooleanCheck(hDlg, IDC_GRAPHICSHLE);
@ -580,11 +579,11 @@ BOOL CALLBACK ConfigDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM /*lParam
EXPORT void EnableDebugging(int Enabled) EXPORT void EnableDebugging(int Enabled)
{ {
CRSPSettings::EnableDebugging(Enabled != 0);
DebuggingEnabled = Enabled != 0; DebuggingEnabled = Enabled != 0;
if (DebuggingEnabled) if (DebuggingEnabled)
{ {
BreakOnStart = GetSetting(Set_BreakOnStart) != 0; BreakOnStart = GetSetting(Set_BreakOnStart) != 0;
g_CPUCore = (RSPCpuType)GetSetting(Set_CPUCore);
LogRDP = GetSetting(Set_LogRDP) != 0; LogRDP = GetSetting(Set_LogRDP) != 0;
LogX86Code = GetSetting(Set_LogX86Code) != 0; LogX86Code = GetSetting(Set_LogX86Code) != 0;
Profiling = GetSetting(Set_Profiling) != 0; Profiling = GetSetting(Set_Profiling) != 0;
@ -602,7 +601,6 @@ EXPORT void EnableDebugging(int Enabled)
Compiler.bGPRConstants = GetSetting(Set_GPRConstants) != 0; Compiler.bGPRConstants = GetSetting(Set_GPRConstants) != 0;
Compiler.bFlags = GetSetting(Set_Flags) != 0; Compiler.bFlags = GetSetting(Set_Flags) != 0;
Compiler.bAlignVector = GetSetting(Set_AlignVector) != 0; Compiler.bAlignVector = GetSetting(Set_AlignVector) != 0;
SetCPU(g_CPUCore);
} }
#ifdef _WIN32 #ifdef _WIN32
FixMenuState(); FixMenuState();