2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project / Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2015-03-03 06:34:51 +00:00
|
|
|
#pragma once
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-12-30 09:49:05 +00:00
|
|
|
#include <string>
|
2013-12-30 09:17:11 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// This is a system to schedule events into the emulated machine's future. Time is measured
|
|
|
|
// in main CPU clock cycles.
|
|
|
|
|
|
|
|
// To schedule an event, you first have to register its type. This is where you pass in the
|
|
|
|
// callback. You then schedule events using the type id you get back.
|
|
|
|
|
|
|
|
// See HW/SystemTimers.cpp for the main part of Dolphin's usage of this scheduler.
|
|
|
|
|
|
|
|
// The int cyclesLate that the callbacks get is how many cycles late it was.
|
|
|
|
// So to schedule a new event on a regular basis:
|
|
|
|
// inside callback:
|
|
|
|
// ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever")
|
|
|
|
|
2013-02-04 04:31:46 +00:00
|
|
|
class PointerWrap;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
//const int CPU_HZ = 222000000;
|
|
|
|
extern int CPU_HZ;
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 msToCycles(int ms) {
|
2012-11-01 15:19:01 +00:00
|
|
|
return CPU_HZ / 1000 * ms;
|
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 msToCycles(float ms) {
|
|
|
|
return (s64)(CPU_HZ * ms * (0.001f));
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 msToCycles(double ms) {
|
|
|
|
return (s64)(CPU_HZ * ms * (0.001));
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 usToCycles(float us) {
|
|
|
|
return (s64)(CPU_HZ * us * (0.000001f));
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 usToCycles(int us) {
|
|
|
|
return (CPU_HZ / 1000000 * (s64)us);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 usToCycles(s64 us) {
|
|
|
|
return (CPU_HZ / 1000000 * us);
|
2012-12-21 19:58:32 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 21:44:30 +00:00
|
|
|
inline s64 usToCycles(u64 us) {
|
|
|
|
return (s64)(CPU_HZ / 1000000 * us);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 cyclesToUs(s64 cycles) {
|
2019-04-17 00:36:29 +00:00
|
|
|
return (cycles * 1000000) / CPU_HZ;
|
2012-11-19 03:13:39 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
namespace CoreTiming
|
|
|
|
{
|
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
2014-07-02 06:01:30 +00:00
|
|
|
typedef void (*MHzChangeCallback)();
|
2012-11-01 15:19:01 +00:00
|
|
|
typedef void (*TimedCallback)(u64 userdata, int cyclesLate);
|
|
|
|
|
|
|
|
u64 GetTicks();
|
|
|
|
u64 GetIdleTicks();
|
2013-10-24 07:59:48 +00:00
|
|
|
u64 GetGlobalTimeUs();
|
2013-11-20 02:55:56 +00:00
|
|
|
u64 GetGlobalTimeUsScaled();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// Returns the event_type identifier.
|
|
|
|
int RegisterEvent(const char *name, TimedCallback callback);
|
2012-12-27 19:58:15 +00:00
|
|
|
// For save states.
|
2020-12-28 21:29:19 +00:00
|
|
|
void RestoreRegisterEvent(int &event_type, const char *name, TimedCallback callback);
|
2012-11-01 15:19:01 +00:00
|
|
|
void UnregisterAllEvents();
|
|
|
|
|
|
|
|
// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk,
|
|
|
|
// when we implement state saves.
|
2013-01-05 21:44:30 +00:00
|
|
|
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata=0);
|
2013-04-06 03:42:20 +00:00
|
|
|
s64 UnscheduleEvent(int event_type, u64 userdata);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
void RemoveEvent(int event_type);
|
|
|
|
bool IsScheduled(int event_type);
|
|
|
|
void Advance();
|
2013-09-21 21:42:38 +00:00
|
|
|
void ForceCheck();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// Pretend that the main CPU has executed enough cycles to reach the next event.
|
|
|
|
void Idle(int maxIdle = 0);
|
|
|
|
|
|
|
|
// Clear all pending events. This should ONLY be done on exit or state load.
|
|
|
|
void ClearPendingEvents();
|
|
|
|
|
|
|
|
void LogPendingEvents();
|
|
|
|
|
2012-12-27 21:08:58 +00:00
|
|
|
// Warning: not included in save states.
|
2014-07-02 06:01:30 +00:00
|
|
|
void RegisterMHzChangeCallback(MHzChangeCallback callback);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
std::string GetScheduledEventsSummary();
|
|
|
|
|
2012-12-27 21:08:58 +00:00
|
|
|
void DoState(PointerWrap &p);
|
|
|
|
|
2019-04-14 21:51:35 +00:00
|
|
|
void SetClockFrequencyHz(int cpuHz);
|
|
|
|
int GetClockFrequencyHz();
|
2012-11-01 15:19:01 +00:00
|
|
|
extern int slicelength;
|
|
|
|
|
|
|
|
}; // end of namespace
|