mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 10:20:49 +00:00
Keep more careful track of microsecond time.
This commit is contained in:
parent
05f2f53358
commit
e16d1a926b
@ -76,6 +76,8 @@ int slicelength;
|
||||
|
||||
MEMORY_ALIGNED16(s64) globalTimer;
|
||||
s64 idledCycles;
|
||||
s64 lastGlobalTimeTicks;
|
||||
s64 lastGlobalTimeUs;
|
||||
|
||||
static std::recursive_mutex externalEventSection;
|
||||
|
||||
@ -84,6 +86,11 @@ void (*advanceCallback)(int cyclesExecuted) = NULL;
|
||||
|
||||
void SetClockFrequencyMHz(int cpuMhz)
|
||||
{
|
||||
// When the mhz changes, we keep track of what "time" it was before hand.
|
||||
// This way, time always moves forward, even if mhz is changed.
|
||||
lastGlobalTimeUs = GetGlobalTimeUs();
|
||||
lastGlobalTimeTicks = GetTicks();
|
||||
|
||||
CPU_HZ = cpuMhz * 1000000;
|
||||
// TODO: Rescale times of scheduled events?
|
||||
}
|
||||
@ -93,6 +100,13 @@ int GetClockFrequencyMHz()
|
||||
return CPU_HZ / 1000000;
|
||||
}
|
||||
|
||||
u64 GetGlobalTimeUs()
|
||||
{
|
||||
s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks;
|
||||
s64 usSinceLast = ticksSinceLast / GetClockFrequencyMHz();
|
||||
return lastGlobalTimeUs + usSinceLast;
|
||||
}
|
||||
|
||||
|
||||
Event* GetNewEvent()
|
||||
{
|
||||
@ -162,6 +176,8 @@ void Init()
|
||||
slicelength = INITIAL_SLICE_LENGTH;
|
||||
globalTimer = 0;
|
||||
idledCycles = 0;
|
||||
lastGlobalTimeTicks = 0;
|
||||
lastGlobalTimeUs = 0;
|
||||
hasTsEvents = 0;
|
||||
}
|
||||
|
||||
@ -624,7 +640,7 @@ void DoState(PointerWrap &p)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(externalEventSection);
|
||||
|
||||
auto s = p.Section("CoreTiming", 1);
|
||||
auto s = p.Section("CoreTiming", 1, 2);
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
@ -640,6 +656,14 @@ void DoState(PointerWrap &p)
|
||||
p.Do(slicelength);
|
||||
p.Do(globalTimer);
|
||||
p.Do(idledCycles);
|
||||
|
||||
if (s >= 2) {
|
||||
p.Do(lastGlobalTimeTicks);
|
||||
p.Do(lastGlobalTimeUs);
|
||||
} else {
|
||||
lastGlobalTimeTicks = 0;
|
||||
lastGlobalTimeUs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -79,6 +79,7 @@ namespace CoreTiming
|
||||
|
||||
u64 GetTicks();
|
||||
u64 GetIdleTicks();
|
||||
u64 GetGlobalTimeUs();
|
||||
|
||||
// Returns the event_type identifier.
|
||||
int RegisterEvent(const char *name, TimedCallback callback);
|
||||
|
Loading…
Reference in New Issue
Block a user