diff --git a/resource/Cxbx.rc b/resource/Cxbx.rc index 641f567fa..9e60c89dc 100644 Binary files a/resource/Cxbx.rc and b/resource/Cxbx.rc differ diff --git a/src/Cxbx/ResCxbx.h b/src/Cxbx/ResCxbx.h index 43f491b45..b12bd1de5 100644 --- a/src/Cxbx/ResCxbx.h +++ b/src/Cxbx/ResCxbx.h @@ -134,7 +134,7 @@ #define ID_FPS 40096 #define ID_HACKS_UNCAPFRAMERATE 40097 #define ID_HACKS_RUNXBOXTHREADSONALLCORES 40098 -#define ID_HACKS_PATCHCPUFREQUENCY 40099 +#define ID_HACKS_SKIPRDTSCPATCHING 40099 #define ID_HACKS_SCALEVIEWPORT 40100 #define IDC_STATIC -1 diff --git a/src/Cxbx/WndMain.cpp b/src/Cxbx/WndMain.cpp index 0eff1a8d6..7f85f0a48 100644 --- a/src/Cxbx/WndMain.cpp +++ b/src/Cxbx/WndMain.cpp @@ -225,9 +225,9 @@ WndMain::WndMain(HINSTANCE x_hInstance) : } 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) { - m_PatchCpuFrequency = 0; + m_SkipRdtscPatching = 0; } dwType = REG_DWORD; dwSize = sizeof(DWORD); @@ -396,7 +396,7 @@ WndMain::~WndMain() RegSetValueEx(hKey, "HackUseAllCores", 0, dwType, (PBYTE)&m_UseAllCores, dwSize); 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); 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(); break; - case ID_HACKS_PATCHCPUFREQUENCY: - m_PatchCpuFrequency = !m_PatchCpuFrequency; + case ID_HACKS_SKIPRDTSCPATCHING: + m_SkipRdtscPatching = !m_SkipRdtscPatching; RefreshMenus(); break; @@ -1804,8 +1804,8 @@ void WndMain::RefreshMenus() chk_flag = (m_UseAllCores) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_RUNXBOXTHREADSONALLCORES, chk_flag); - chk_flag = (m_PatchCpuFrequency) ? MF_CHECKED : MF_UNCHECKED; - CheckMenuItem(settings_menu, ID_HACKS_PATCHCPUFREQUENCY, chk_flag); + chk_flag = (m_SkipRdtscPatching) ? MF_CHECKED : MF_UNCHECKED; + CheckMenuItem(settings_menu, ID_HACKS_SKIPRDTSCPATCHING, chk_flag); chk_flag = (m_ScaleViewport) ? MF_CHECKED : MF_UNCHECKED; 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->SetUncapFramerate(&m_UncapFramerate); g_EmuShared->SetUseAllCores(&m_UseAllCores); - g_EmuShared->SetPatchCpuFrequency(&m_PatchCpuFrequency); + g_EmuShared->SetSkipRdtscPatching(&m_SkipRdtscPatching); g_EmuShared->SetScaleViewport(&m_ScaleViewport); if (m_ScaleViewport) { diff --git a/src/Cxbx/WndMain.h b/src/Cxbx/WndMain.h index c479c1058..229d0eb83 100644 --- a/src/Cxbx/WndMain.h +++ b/src/Cxbx/WndMain.h @@ -221,7 +221,7 @@ class WndMain : public Wnd int m_DisablePixelShaders; int m_UncapFramerate; int m_UseAllCores; - int m_PatchCpuFrequency; + int m_SkipRdtscPatching; int m_ScaleViewport; // ****************************************************************** diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index 99994b897..934f9c789 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -583,7 +583,7 @@ void PrintCurrentConfigurationLog() printf("Disable Pixel Shaders: %s\n", g_DisablePixelShaders == 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("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"); } @@ -708,7 +708,7 @@ const uint8_t rdtsc_pattern[] = { }; const int sizeof_rdtsc_pattern = sizeof(rdtsc_pattern); -void PatchRdtscInstruction() +void PatchRdtscInstructions() { uint8_t rdtsc[2] = { 0x0F, 0x31 }; DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage; @@ -1200,8 +1200,8 @@ __declspec(noreturn) void CxbxKrnlInit g_UncapFramerate = !!HackEnabled; g_EmuShared->GetUseAllCores(&HackEnabled); g_UseAllCores = !!HackEnabled; - g_EmuShared->GetPatchCpuFrequency(&HackEnabled); - g_PatchCpuFrequency = !!HackEnabled; + g_EmuShared->GetSkipRdtscPatching(&HackEnabled); + g_SkipRdtscPatching = !!HackEnabled; g_EmuShared->GetScaleViewport(&HackEnabled); g_ScaleViewport = !!HackEnabled; } @@ -1366,9 +1366,9 @@ __declspec(noreturn) void CxbxKrnlInit // See: https://multimedia.cx/eggs/xbox-sphinx-protocol/ ApplyMediaPatches(); - if(g_PatchCpuFrequency) + if(!g_SkipRdtscPatching) { - PatchRdtscInstruction(); + PatchRdtscInstructions(); } // Setup per-title encryption keys diff --git a/src/CxbxKrnl/Emu.cpp b/src/CxbxKrnl/Emu.cpp index 410b7aa73..b26bd15d6 100644 --- a/src/CxbxKrnl/Emu.cpp +++ b/src/CxbxKrnl/Emu.cpp @@ -67,7 +67,7 @@ bool g_XInputEnabled = false; bool g_DisablePixelShaders = false; bool g_UncapFramerate = false; bool g_UseAllCores = false; -bool g_PatchCpuFrequency = false; +bool g_SkipRdtscPatching = false; bool g_ScaleViewport = false; // Delta added to host SystemTime, used in xboxkrnl::KeQuerySystemTime and xboxkrnl::NtSetSystemTime @@ -236,7 +236,7 @@ extern int EmuException(LPEXCEPTION_POINTERS e) else { // 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)) { LARGE_INTEGER PerformanceCount; diff --git a/src/CxbxKrnl/Emu.h b/src/CxbxKrnl/Emu.h index b825da40a..79aad3310 100644 --- a/src/CxbxKrnl/Emu.h +++ b/src/CxbxKrnl/Emu.h @@ -110,6 +110,6 @@ typedef struct DUMMY_KERNEL extern bool g_DisablePixelShaders; extern bool g_UncapFramerate; extern bool g_UseAllCores; -extern bool g_PatchCpuFrequency; +extern bool g_SkipRdtscPatching; extern bool g_ScaleViewport; #endif diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp index 1e75d1ab2..e8e4b4b06 100644 --- a/src/CxbxKrnl/EmuKrnlKe.cpp +++ b/src/CxbxKrnl/EmuKrnlKe.cpp @@ -1096,10 +1096,6 @@ XBSYSAPI EXPORTNUM(126) xboxkrnl::ULONGLONG NTAPI xboxkrnl::KeQueryPerformanceCo ULONGLONG ret; ::LARGE_INTEGER PerformanceCounter; //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, // and we we're bound to a single core, so we could do that too, but on Windows diff --git a/src/CxbxKrnl/EmuShared.h b/src/CxbxKrnl/EmuShared.h index 9ffedb314..0dc6e802d 100644 --- a/src/CxbxKrnl/EmuShared.h +++ b/src/CxbxKrnl/EmuShared.h @@ -126,8 +126,8 @@ class EmuShared : public Mutex void SetUncapFramerate(int* value) { Lock(); m_UncapFramerate = *value; Unlock(); } void GetUseAllCores(int* value) { Lock(); *value = m_UseAllCores; Unlock(); } void SetUseAllCores(int* value) { Lock(); m_UseAllCores = *value; Unlock(); } - void GetPatchCpuFrequency(int* value) { Lock(); *value = m_PatchCpuFrequeny; Unlock(); } - void SetPatchCpuFrequency(int* value) { Lock(); m_PatchCpuFrequeny = *value; Unlock(); } + void GetSkipRdtscPatching(int* value) { Lock(); *value = m_SkipRdtscPatching; Unlock(); } + void SetSkipRdtscPatching(int* value) { Lock(); m_SkipRdtscPatching = *value; Unlock(); } void GetScaleViewport(int* value) { Lock(); *value = m_ScaleViewport; Unlock(); } void SetScaleViewport(int* value) { Lock(); m_ScaleViewport = *value; Unlock(); } @@ -198,7 +198,7 @@ class EmuShared : public Mutex int m_DisablePixelShaders; int m_UncapFramerate; int m_UseAllCores; - int m_PatchCpuFrequeny; + int m_SkipRdtscPatching; float m_MSpF; float m_FPS; bool m_bMultiXbeFlag; diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index 3fc3c1a5f..f9710a005 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -954,15 +954,7 @@ BOOL WINAPI XTL::EMUPATCH(QueryPerformanceCounter) { FUNC_EXPORTS; - //if the rdtsc is patched, we shall keep using scaled PerformanceCounter. - /*if (g_PatchCpuFrequency) - { - lpPerformanceCount->QuadPart = (LONGLONG)__rdtsc(); - return TRUE; - - }*/ - - lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter(); + lpPerformanceCount->QuadPart = xboxkrnl::KeQueryPerformanceCounter(); return TRUE; }