Merge pull request #1126 from LukeUsher/change-default-rdtsc
Make new RDTSC patch the default
This commit is contained in:
commit
4cc918881d
BIN
resource/Cxbx.rc
BIN
resource/Cxbx.rc
Binary file not shown.
|
@ -134,7 +134,7 @@
|
||||||
#define ID_FPS 40096
|
#define ID_FPS 40096
|
||||||
#define ID_HACKS_UNCAPFRAMERATE 40097
|
#define ID_HACKS_UNCAPFRAMERATE 40097
|
||||||
#define ID_HACKS_RUNXBOXTHREADSONALLCORES 40098
|
#define ID_HACKS_RUNXBOXTHREADSONALLCORES 40098
|
||||||
#define ID_HACKS_PATCHCPUFREQUENCY 40099
|
#define ID_HACKS_SKIPRDTSCPATCHING 40099
|
||||||
#define ID_HACKS_SCALEVIEWPORT 40100
|
#define ID_HACKS_SCALEVIEWPORT 40100
|
||||||
#define IDC_STATIC -1
|
#define IDC_STATIC -1
|
||||||
|
|
||||||
|
|
|
@ -225,9 +225,9 @@ WndMain::WndMain(HINSTANCE x_hInstance) :
|
||||||
}
|
}
|
||||||
|
|
||||||
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
||||||
result = RegQueryValueEx(hKey, "HackPatchCpuFrequency", NULL, &dwType, (PBYTE)&m_PatchCpuFrequency, &dwSize);
|
result = RegQueryValueEx(hKey, "HackSkipRdtscPatching", NULL, &dwType, (PBYTE)&m_SkipRdtscPatching, &dwSize);
|
||||||
if (result != ERROR_SUCCESS) {
|
if (result != ERROR_SUCCESS) {
|
||||||
m_PatchCpuFrequency = 0;
|
m_SkipRdtscPatching = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
||||||
|
@ -396,7 +396,7 @@ WndMain::~WndMain()
|
||||||
RegSetValueEx(hKey, "HackUseAllCores", 0, dwType, (PBYTE)&m_UseAllCores, dwSize);
|
RegSetValueEx(hKey, "HackUseAllCores", 0, dwType, (PBYTE)&m_UseAllCores, dwSize);
|
||||||
|
|
||||||
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
||||||
RegSetValueEx(hKey, "HackPatchCpuFrequency", 0, dwType, (PBYTE)&m_PatchCpuFrequency, dwSize);
|
RegSetValueEx(hKey, "HackSkipRdtscPatching", 0, dwType, (PBYTE)&m_SkipRdtscPatching, dwSize);
|
||||||
|
|
||||||
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
dwType = REG_DWORD; dwSize = sizeof(DWORD);
|
||||||
RegSetValueEx(hKey, "HackScaleViewport", 0, dwType, (PBYTE)&m_ScaleViewport, dwSize);
|
RegSetValueEx(hKey, "HackScaleViewport", 0, dwType, (PBYTE)&m_ScaleViewport, dwSize);
|
||||||
|
@ -1366,8 +1366,8 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
|
||||||
RefreshMenus();
|
RefreshMenus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_HACKS_PATCHCPUFREQUENCY:
|
case ID_HACKS_SKIPRDTSCPATCHING:
|
||||||
m_PatchCpuFrequency = !m_PatchCpuFrequency;
|
m_SkipRdtscPatching = !m_SkipRdtscPatching;
|
||||||
RefreshMenus();
|
RefreshMenus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1804,8 +1804,8 @@ void WndMain::RefreshMenus()
|
||||||
chk_flag = (m_UseAllCores) ? MF_CHECKED : MF_UNCHECKED;
|
chk_flag = (m_UseAllCores) ? MF_CHECKED : MF_UNCHECKED;
|
||||||
CheckMenuItem(settings_menu, ID_HACKS_RUNXBOXTHREADSONALLCORES, chk_flag);
|
CheckMenuItem(settings_menu, ID_HACKS_RUNXBOXTHREADSONALLCORES, chk_flag);
|
||||||
|
|
||||||
chk_flag = (m_PatchCpuFrequency) ? MF_CHECKED : MF_UNCHECKED;
|
chk_flag = (m_SkipRdtscPatching) ? MF_CHECKED : MF_UNCHECKED;
|
||||||
CheckMenuItem(settings_menu, ID_HACKS_PATCHCPUFREQUENCY, chk_flag);
|
CheckMenuItem(settings_menu, ID_HACKS_SKIPRDTSCPATCHING, chk_flag);
|
||||||
|
|
||||||
chk_flag = (m_ScaleViewport) ? MF_CHECKED : MF_UNCHECKED;
|
chk_flag = (m_ScaleViewport) ? MF_CHECKED : MF_UNCHECKED;
|
||||||
CheckMenuItem(settings_menu, ID_HACKS_SCALEVIEWPORT, chk_flag);
|
CheckMenuItem(settings_menu, ID_HACKS_SCALEVIEWPORT, chk_flag);
|
||||||
|
@ -2182,7 +2182,7 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState /
|
||||||
g_EmuShared->SetDisablePixelShaders(&m_DisablePixelShaders);
|
g_EmuShared->SetDisablePixelShaders(&m_DisablePixelShaders);
|
||||||
g_EmuShared->SetUncapFramerate(&m_UncapFramerate);
|
g_EmuShared->SetUncapFramerate(&m_UncapFramerate);
|
||||||
g_EmuShared->SetUseAllCores(&m_UseAllCores);
|
g_EmuShared->SetUseAllCores(&m_UseAllCores);
|
||||||
g_EmuShared->SetPatchCpuFrequency(&m_PatchCpuFrequency);
|
g_EmuShared->SetSkipRdtscPatching(&m_SkipRdtscPatching);
|
||||||
g_EmuShared->SetScaleViewport(&m_ScaleViewport);
|
g_EmuShared->SetScaleViewport(&m_ScaleViewport);
|
||||||
|
|
||||||
if (m_ScaleViewport) {
|
if (m_ScaleViewport) {
|
||||||
|
|
|
@ -221,7 +221,7 @@ class WndMain : public Wnd
|
||||||
int m_DisablePixelShaders;
|
int m_DisablePixelShaders;
|
||||||
int m_UncapFramerate;
|
int m_UncapFramerate;
|
||||||
int m_UseAllCores;
|
int m_UseAllCores;
|
||||||
int m_PatchCpuFrequency;
|
int m_SkipRdtscPatching;
|
||||||
int m_ScaleViewport;
|
int m_ScaleViewport;
|
||||||
|
|
||||||
// ******************************************************************
|
// ******************************************************************
|
||||||
|
|
|
@ -583,7 +583,7 @@ void PrintCurrentConfigurationLog()
|
||||||
printf("Disable Pixel Shaders: %s\n", g_DisablePixelShaders == 1 ? "On" : "Off");
|
printf("Disable Pixel Shaders: %s\n", g_DisablePixelShaders == 1 ? "On" : "Off");
|
||||||
printf("Uncap Framerate: %s\n", g_UncapFramerate == 1 ? "On" : "Off");
|
printf("Uncap Framerate: %s\n", g_UncapFramerate == 1 ? "On" : "Off");
|
||||||
printf("Run Xbox threads on all cores: %s\n", g_UseAllCores == 1 ? "On" : "Off");
|
printf("Run Xbox threads on all cores: %s\n", g_UseAllCores == 1 ? "On" : "Off");
|
||||||
printf("Patch CPU Frequency (rdtsc): %s\n", g_PatchCpuFrequency == 1 ? "On" : "Off");
|
printf("Skip RDTSC Patching: %s\n", g_SkipRdtscPatching == 1 ? "On" : "Off");
|
||||||
printf("Scale Xbox to host viewport (and back): %s\n", g_ScaleViewport == 1 ? "On" : "Off");
|
printf("Scale Xbox to host viewport (and back): %s\n", g_ScaleViewport == 1 ? "On" : "Off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ const uint8_t rdtsc_pattern[] = {
|
||||||
};
|
};
|
||||||
const int sizeof_rdtsc_pattern = sizeof(rdtsc_pattern);
|
const int sizeof_rdtsc_pattern = sizeof(rdtsc_pattern);
|
||||||
|
|
||||||
void PatchRdtscInstruction()
|
void PatchRdtscInstructions()
|
||||||
{
|
{
|
||||||
uint8_t rdtsc[2] = { 0x0F, 0x31 };
|
uint8_t rdtsc[2] = { 0x0F, 0x31 };
|
||||||
DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage;
|
DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage;
|
||||||
|
@ -1200,8 +1200,8 @@ __declspec(noreturn) void CxbxKrnlInit
|
||||||
g_UncapFramerate = !!HackEnabled;
|
g_UncapFramerate = !!HackEnabled;
|
||||||
g_EmuShared->GetUseAllCores(&HackEnabled);
|
g_EmuShared->GetUseAllCores(&HackEnabled);
|
||||||
g_UseAllCores = !!HackEnabled;
|
g_UseAllCores = !!HackEnabled;
|
||||||
g_EmuShared->GetPatchCpuFrequency(&HackEnabled);
|
g_EmuShared->GetSkipRdtscPatching(&HackEnabled);
|
||||||
g_PatchCpuFrequency = !!HackEnabled;
|
g_SkipRdtscPatching = !!HackEnabled;
|
||||||
g_EmuShared->GetScaleViewport(&HackEnabled);
|
g_EmuShared->GetScaleViewport(&HackEnabled);
|
||||||
g_ScaleViewport = !!HackEnabled;
|
g_ScaleViewport = !!HackEnabled;
|
||||||
}
|
}
|
||||||
|
@ -1366,9 +1366,9 @@ __declspec(noreturn) void CxbxKrnlInit
|
||||||
// See: https://multimedia.cx/eggs/xbox-sphinx-protocol/
|
// See: https://multimedia.cx/eggs/xbox-sphinx-protocol/
|
||||||
ApplyMediaPatches();
|
ApplyMediaPatches();
|
||||||
|
|
||||||
if(g_PatchCpuFrequency)
|
if(!g_SkipRdtscPatching)
|
||||||
{
|
{
|
||||||
PatchRdtscInstruction();
|
PatchRdtscInstructions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup per-title encryption keys
|
// Setup per-title encryption keys
|
||||||
|
|
|
@ -67,7 +67,7 @@ bool g_XInputEnabled = false;
|
||||||
bool g_DisablePixelShaders = false;
|
bool g_DisablePixelShaders = false;
|
||||||
bool g_UncapFramerate = false;
|
bool g_UncapFramerate = false;
|
||||||
bool g_UseAllCores = false;
|
bool g_UseAllCores = false;
|
||||||
bool g_PatchCpuFrequency = false;
|
bool g_SkipRdtscPatching = false;
|
||||||
bool g_ScaleViewport = false;
|
bool g_ScaleViewport = false;
|
||||||
|
|
||||||
// Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime
|
// Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime
|
||||||
|
@ -236,7 +236,7 @@ extern int EmuException(LPEXCEPTION_POINTERS e)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if this exception came from rdtsc, but only whe g_PatchCpuFrequency hack is set.
|
// Check if this exception came from rdtsc, but only whe g_PatchCpuFrequency hack is set.
|
||||||
if (e->ExceptionRecord->ExceptionCode == STATUS_PRIVILEGED_INSTRUCTION && g_PatchCpuFrequency )
|
if (e->ExceptionRecord->ExceptionCode == STATUS_PRIVILEGED_INSTRUCTION && !g_SkipRdtscPatching )
|
||||||
{
|
{
|
||||||
if (IsRdtscInstruction(e->ContextRecord->Eip)) {
|
if (IsRdtscInstruction(e->ContextRecord->Eip)) {
|
||||||
LARGE_INTEGER PerformanceCount;
|
LARGE_INTEGER PerformanceCount;
|
||||||
|
|
|
@ -110,6 +110,6 @@ typedef struct DUMMY_KERNEL
|
||||||
extern bool g_DisablePixelShaders;
|
extern bool g_DisablePixelShaders;
|
||||||
extern bool g_UncapFramerate;
|
extern bool g_UncapFramerate;
|
||||||
extern bool g_UseAllCores;
|
extern bool g_UseAllCores;
|
||||||
extern bool g_PatchCpuFrequency;
|
extern bool g_SkipRdtscPatching;
|
||||||
extern bool g_ScaleViewport;
|
extern bool g_ScaleViewport;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1096,10 +1096,6 @@ XBSYSAPI EXPORTNUM(126) xboxkrnl::ULONGLONG NTAPI xboxkrnl::KeQueryPerformanceCo
|
||||||
ULONGLONG ret;
|
ULONGLONG ret;
|
||||||
::LARGE_INTEGER PerformanceCounter;
|
::LARGE_INTEGER PerformanceCounter;
|
||||||
//no matter rdtsc is patched or not, we should always return a scaled performance counter here.
|
//no matter rdtsc is patched or not, we should always return a scaled performance counter here.
|
||||||
/*if (g_PatchCpuFrequency)
|
|
||||||
{
|
|
||||||
RETURN((ULONGLONG)__rdtsc());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Dxbx note : Xbox actually uses the RDTSC machine code instruction for this,
|
// Dxbx note : Xbox actually uses the RDTSC machine code instruction for this,
|
||||||
// and we we're bound to a single core, so we could do that too, but on Windows
|
// and we we're bound to a single core, so we could do that too, but on Windows
|
||||||
|
|
|
@ -126,8 +126,8 @@ class EmuShared : public Mutex
|
||||||
void SetUncapFramerate(int* value) { Lock(); m_UncapFramerate = *value; Unlock(); }
|
void SetUncapFramerate(int* value) { Lock(); m_UncapFramerate = *value; Unlock(); }
|
||||||
void GetUseAllCores(int* value) { Lock(); *value = m_UseAllCores; Unlock(); }
|
void GetUseAllCores(int* value) { Lock(); *value = m_UseAllCores; Unlock(); }
|
||||||
void SetUseAllCores(int* value) { Lock(); m_UseAllCores = *value; Unlock(); }
|
void SetUseAllCores(int* value) { Lock(); m_UseAllCores = *value; Unlock(); }
|
||||||
void GetPatchCpuFrequency(int* value) { Lock(); *value = m_PatchCpuFrequeny; Unlock(); }
|
void GetSkipRdtscPatching(int* value) { Lock(); *value = m_SkipRdtscPatching; Unlock(); }
|
||||||
void SetPatchCpuFrequency(int* value) { Lock(); m_PatchCpuFrequeny = *value; Unlock(); }
|
void SetSkipRdtscPatching(int* value) { Lock(); m_SkipRdtscPatching = *value; Unlock(); }
|
||||||
void GetScaleViewport(int* value) { Lock(); *value = m_ScaleViewport; Unlock(); }
|
void GetScaleViewport(int* value) { Lock(); *value = m_ScaleViewport; Unlock(); }
|
||||||
void SetScaleViewport(int* value) { Lock(); m_ScaleViewport = *value; Unlock(); }
|
void SetScaleViewport(int* value) { Lock(); m_ScaleViewport = *value; Unlock(); }
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ class EmuShared : public Mutex
|
||||||
int m_DisablePixelShaders;
|
int m_DisablePixelShaders;
|
||||||
int m_UncapFramerate;
|
int m_UncapFramerate;
|
||||||
int m_UseAllCores;
|
int m_UseAllCores;
|
||||||
int m_PatchCpuFrequeny;
|
int m_SkipRdtscPatching;
|
||||||
float m_MSpF;
|
float m_MSpF;
|
||||||
float m_FPS;
|
float m_FPS;
|
||||||
bool m_bMultiXbeFlag;
|
bool m_bMultiXbeFlag;
|
||||||
|
|
|
@ -954,15 +954,7 @@ BOOL WINAPI XTL::EMUPATCH(QueryPerformanceCounter)
|
||||||
{
|
{
|
||||||
FUNC_EXPORTS;
|
FUNC_EXPORTS;
|
||||||
|
|
||||||
//if the rdtsc is patched, we shall keep using scaled PerformanceCounter.
|
lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter();
|
||||||
/*if (g_PatchCpuFrequency)
|
|
||||||
{
|
|
||||||
lpPerformanceCount->QuadPart = (LONGLONG)__rdtsc();
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter();
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue