summaryrefslogtreecommitdiff
path: root/src/core/core_timing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core_timing.h')
-rw-r--r--src/core/core_timing.h109
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
22class PointerWrap;
23
24extern int g_clock_rate_arm11;
25
26inline s64 msToCycles(int ms) {
27 return g_clock_rate_arm11 / 1000 * ms;
28}
29
30inline s64 msToCycles(float ms) {
31 return (s64)(g_clock_rate_arm11 * ms * (0.001f));
32}
33
34inline s64 msToCycles(double ms) {
35 return (s64)(g_clock_rate_arm11 * ms * (0.001));
36}
37
38inline s64 usToCycles(float us) {
39 return (s64)(g_clock_rate_arm11 * us * (0.000001f));
40}
41
42inline s64 usToCycles(int us) {
43 return (g_clock_rate_arm11 / 1000000 * (s64)us);
44}
45
46inline s64 usToCycles(s64 us) {
47 return (g_clock_rate_arm11 / 1000000 * us);
48}
49
50inline s64 usToCycles(u64 us) {
51 return (s64)(g_clock_rate_arm11 / 1000000 * us);
52}
53
54inline s64 cyclesToUs(s64 cycles) {
55 return cycles / (g_clock_rate_arm11 / 1000000);
56}
57
58namespace CoreTiming {
59
60void Init();
61void Shutdown();
62
63typedef void(*TimedCallback)(u64 userdata, int cyclesLate);
64
65u64 GetTicks();
66u64 GetIdleTicks();
67
68// Returns the event_type identifier.
69int RegisterEvent(const char *name, TimedCallback callback);
70// For save states.
71void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback);
72void UnregisterAllEvents();
73
74// userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk,
75// when we implement state saves.
76void ScheduleEvent(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
77void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata = 0);
78void ScheduleEvent_Threadsafe_Immediate(int event_type, u64 userdata = 0);
79s64 UnscheduleEvent(int event_type, u64 userdata);
80s64 UnscheduleThreadsafeEvent(int event_type, u64 userdata);
81
82void RemoveEvent(int event_type);
83void RemoveThreadsafeEvent(int event_type);
84void RemoveAllEvents(int event_type);
85bool IsScheduled(int event_type);
86void Advance();
87void MoveEvents();
88void ProcessFifoWaitEvents();
89
90// Pretend that the main CPU has executed enough cycles to reach the next event.
91void Idle(int maxIdle = 0);
92
93// Clear all pending events. This should ONLY be done on exit or state load.
94void ClearPendingEvents();
95
96void LogPendingEvents();
97
98// Warning: not included in save states.
99void RegisterAdvanceCallback(void(*callback)(int cyclesExecuted));
100
101std::string GetScheduledEventsSummary();
102
103void DoState(PointerWrap &p);
104
105void SetClockFrequencyMHz(int cpuMhz);
106int GetClockFrequencyMHz();
107extern int slicelength;
108
109}; // namespace