2014-12-17 08:38:14 +03:00
|
|
|
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
2014-04-09 03:11:21 +04:00
|
|
|
// Refer to the license.txt file included.
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
#pragma once
|
2013-10-02 03:10:47 +04: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")
|
|
|
|
|
2014-04-09 04:15:08 +04:00
|
|
|
#include "common/common.h"
|
2013-10-02 03:10:47 +04:00
|
|
|
|
|
|
|
class PointerWrap;
|
|
|
|
|
|
|
|
extern int g_clock_rate_arm11;
|
|
|
|
|
|
|
|
inline s64 msToCycles(int ms) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return g_clock_rate_arm11 / 1000 * ms;
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 msToCycles(float ms) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (s64)(g_clock_rate_arm11 * ms * (0.001f));
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 msToCycles(double ms) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (s64)(g_clock_rate_arm11 * ms * (0.001));
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 usToCycles(float us) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (s64)(g_clock_rate_arm11 * us * (0.000001f));
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 usToCycles(int us) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (g_clock_rate_arm11 / 1000000 * (s64)us);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 usToCycles(s64 us) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (g_clock_rate_arm11 / 1000000 * us);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 usToCycles(u64 us) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return (s64)(g_clock_rate_arm11 / 1000000 * us);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline s64 cyclesToUs(s64 cycles) {
|
2014-04-09 03:11:21 +04:00
|
|
|
return cycles / (g_clock_rate_arm11 / 1000000);
|
2013-10-02 03:10:47 +04:00
|
|
|
}
|
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
namespace CoreTiming {
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
typedef void(*TimedCallback)(u64 userdata, int cyclesLate);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
u64 GetTicks();
|
|
|
|
u64 GetIdleTicks();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
// Returns the event_type identifier.
|
|
|
|
int RegisterEvent(const char *name, TimedCallback callback);
|
|
|
|
// For save states.
|
|
|
|
void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback);
|
|
|
|
void UnregisterAllEvents();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk,
|
|
|
|
// when we implement state saves.
|
|
|
|
void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
|
|
|
|
void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
|
|
|
|
void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0);
|
|
|
|
s64 UnscheduleEvent(int event_type, u64 userdata);
|
|
|
|
s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
void RemoveEvent(int event_type);
|
|
|
|
void RemoveThreadsafeEvent(int event_type);
|
|
|
|
void RemoveAllEvents(int event_type);
|
|
|
|
bool IsScheduled(int event_type);
|
|
|
|
void Advance();
|
|
|
|
void MoveEvents();
|
|
|
|
void ProcessFifoWaitEvents();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
// Pretend that the main CPU has executed enough cycles to reach the next event.
|
|
|
|
void Idle(int maxIdle = 0);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
// Clear all pending events. This should ONLY be done on exit or state load.
|
|
|
|
void ClearPendingEvents();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
void LogPendingEvents();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
// Warning: not included in save states.
|
|
|
|
void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted));
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
std::string GetScheduledEventsSummary();
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
void DoState(PointerWrap &p);
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-04-09 03:11:21 +04:00
|
|
|
void SetClockFrequencyMHz(int cpuMhz);
|
|
|
|
int GetClockFrequencyMHz();
|
|
|
|
extern int slicelength;
|
2013-10-02 03:10:47 +04:00
|
|
|
|
2014-11-18 16:27:16 +03:00
|
|
|
} // namespace
|