diff options
Diffstat (limited to 'src/core/core_timing.h')
| -rw-r--r-- | src/core/core_timing.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h new file mode 100644 index 000000000..b62acea6c --- /dev/null +++ b/src/core/core_timing.h | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | // This is a system to schedule events into the emulated machine's future. Time is measured | ||
| 8 | // in main CPU clock cycles. | ||
| 9 | |||
| 10 | // To schedule an event, you first have to register its type. This is where you pass in the | ||
| 11 | // callback. You then schedule events using the type id you get back. | ||
| 12 | |||
| 13 | // See HW/SystemTimers.cpp for the main part of Dolphin's usage of this scheduler. | ||
| 14 | |||
| 15 | // The int cyclesLate that the callbacks get is how many cycles late it was. | ||
| 16 | // So to schedule a new event on a regular basis: | ||
| 17 | // inside callback: | ||
| 18 | // ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") | ||
| 19 | |||
| 20 | #include "common.h" | ||
| 21 | |||
| 22 | class PointerWrap; | ||
| 23 | |||
| 24 | extern int g_clock_rate_arm11; | ||
| 25 | |||
| 26 | inline s64 msToCycles(int ms) { | ||
| 27 | return g_clock_rate_arm11 / 1000 * ms; | ||
| 28 | } | ||
| 29 | |||
| 30 | inline s64 msToCycles(float ms) { | ||
| 31 | return (s64)(g_clock_rate_arm11 * ms * (0.001f)); | ||
| 32 | } | ||
| 33 | |||
| 34 | inline s64 msToCycles(double ms) { | ||
| 35 | return (s64)(g_clock_rate_arm11 * ms * (0.001)); | ||
| 36 | } | ||
| 37 | |||
| 38 | inline s64 usToCycles(float us) { | ||
| 39 | return (s64)(g_clock_rate_arm11 * us * (0.000001f)); | ||
| 40 | } | ||
| 41 | |||
| 42 | inline s64 usToCycles(int us) { | ||
| 43 | return (g_clock_rate_arm11 / 1000000 * (s64)us); | ||
| 44 | } | ||
| 45 | |||
| 46 | inline s64 usToCycles(s64 us) { | ||
| 47 | return (g_clock_rate_arm11 / 1000000 * us); | ||
| 48 | } | ||
| 49 | |||
| 50 | inline s64 usToCycles(u64 us) { | ||
| 51 | return (s64)(g_clock_rate_arm11 / 1000000 * us); | ||
| 52 | } | ||
| 53 | |||
| 54 | inline s64 cyclesToUs(s64 cycles) { | ||
| 55 | return cycles / (g_clock_rate_arm11 / 1000000); | ||
| 56 | } | ||
| 57 | |||
| 58 | namespace CoreTiming { | ||
| 59 | |||
| 60 | void Init(); | ||
| 61 | void Shutdown(); | ||
| 62 | |||
| 63 | typedef void(*TimedCallback)(u64 userdata, int cyclesLate); | ||
| 64 | |||
| 65 | u64 GetTicks(); | ||
| 66 | u64 GetIdleTicks(); | ||
| 67 | |||
| 68 | // Returns the event_type identifier. | ||
| 69 | int RegisterEvent(const char *name, TimedCallback callback); | ||
| 70 | // For save states. | ||
| 71 | void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback); | ||
| 72 | void UnregisterAllEvents(); | ||
| 73 | |||
| 74 | // userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk, | ||
| 75 | // when we implement state saves. | ||
| 76 | void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0); | ||
| 77 | void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata = 0); | ||
| 78 | void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0); | ||
| 79 | s64 UnscheduleEvent(int event_type, u64 userdata); | ||
| 80 | s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata); | ||
| 81 | |||
| 82 | void RemoveEvent(int event_type); | ||
| 83 | void RemoveThreadsafeEvent(int event_type); | ||
| 84 | void RemoveAllEvents(int event_type); | ||
| 85 | bool IsScheduled(int event_type); | ||
| 86 | void Advance(); | ||
| 87 | void MoveEvents(); | ||
| 88 | void ProcessFifoWaitEvents(); | ||
| 89 | |||
| 90 | // Pretend that the main CPU has executed enough cycles to reach the next event. | ||
| 91 | void Idle(int maxIdle = 0); | ||
| 92 | |||
| 93 | // Clear all pending events. This should ONLY be done on exit or state load. | ||
| 94 | void ClearPendingEvents(); | ||
| 95 | |||
| 96 | void LogPendingEvents(); | ||
| 97 | |||
| 98 | // Warning: not included in save states. | ||
| 99 | void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted)); | ||
| 100 | |||
| 101 | std::string GetScheduledEventsSummary(); | ||
| 102 | |||
| 103 | void DoState(PointerWrap &p); | ||
| 104 | |||
| 105 | void SetClockFrequencyMHz(int cpuMhz); | ||
| 106 | int GetClockFrequencyMHz(); | ||
| 107 | extern int slicelength; | ||
| 108 | |||
| 109 | }; // namespace | ||