From effca1e4c737500f00c52249ff8f737920c66be7 Mon Sep 17 00:00:00 2001 From: Sacha Date: Wed, 20 Nov 2013 12:55:56 +1000 Subject: [PATCH] Improvements to timer hack. --- Core/CoreTiming.cpp | 15 ++++++++++++--- Core/CoreTiming.h | 1 + Core/HLE/sceKernelTime.cpp | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index c1aca50b5b..1d81b248dd 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -102,18 +102,27 @@ int GetClockFrequencyMHz() return CPU_HZ / 1000000; } -u64 GetGlobalTimeUs() +u64 GetGlobalTimeUsScaled() { s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks; int freq = GetClockFrequencyMHz(); if (g_Config.bTimerHack) { float vps; __DisplayGetVPS(&vps); - if (vps > 5.0f) - freq = (int)(((float)CPU_HZ * vps) / (1000000.0f * 60.0f)); + if (vps > 4.0f) + freq *= (vps / 60.0f); } s64 usSinceLast = ticksSinceLast / freq; return lastGlobalTimeUs + usSinceLast; + +} + +u64 GetGlobalTimeUs() +{ + s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks; + int freq = GetClockFrequencyMHz(); + s64 usSinceLast = ticksSinceLast / freq; + return lastGlobalTimeUs + usSinceLast; } Event* GetNewEvent() diff --git a/Core/CoreTiming.h b/Core/CoreTiming.h index 8c53987e3a..03a10f2e05 100644 --- a/Core/CoreTiming.h +++ b/Core/CoreTiming.h @@ -80,6 +80,7 @@ namespace CoreTiming u64 GetTicks(); u64 GetIdleTicks(); u64 GetGlobalTimeUs(); + u64 GetGlobalTimeUsScaled(); // Returns the event_type identifier. int RegisterEvent(const char *name, TimedCallback callback); diff --git a/Core/HLE/sceKernelTime.cpp b/Core/HLE/sceKernelTime.cpp index c57c3c3394..6eb88b2fcf 100644 --- a/Core/HLE/sceKernelTime.cpp +++ b/Core/HLE/sceKernelTime.cpp @@ -71,7 +71,7 @@ u32 sceKernelGetSystemTimeLow() u64 sceKernelGetSystemTimeWide() { - u64 t = CoreTiming::GetGlobalTimeUs(); + u64 t = CoreTiming::GetGlobalTimeUsScaled(); DEBUG_LOG(SCEKERNEL,"%i=sceKernelGetSystemTimeWide()",(u32)t); hleEatCycles(250); hleReSchedule("system time");