include/mgba/core/timing.h (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef M_CORE_TIMING
7#define M_CORE_TIMING
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13struct mTiming;
14struct mTimingEvent {
15 void* context;
16 void (*callback)(struct mTiming*, void* context, uint32_t);
17 const char* name;
18 uint32_t when;
19 unsigned priority;
20
21 struct mTimingEvent* next;
22};
23
24struct mTiming {
25 struct mTimingEvent* root;
26 struct mTimingEvent* reroot;
27
28 uint64_t globalCycles;
29 uint32_t masterCycles;
30 int32_t* relativeCycles;
31 int32_t* nextEvent;
32};
33
34void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent);
35void mTimingDeinit(struct mTiming* timing);
36void mTimingClear(struct mTiming* timing);
37void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when);
38void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent*);
39bool mTimingIsScheduled(const struct mTiming* timing, const struct mTimingEvent*);
40int32_t mTimingTick(struct mTiming* timing, int32_t cycles);
41int32_t mTimingCurrentTime(const struct mTiming* timing);
42uint64_t mTimingGlobalTime(const struct mTiming* timing);
43int32_t mTimingNextEvent(struct mTiming* timing);
44int32_t mTimingUntil(const struct mTiming* timing, const struct mTimingEvent*);
45
46CXX_GUARD_END
47
48#endif