include/mgba/internal/ds/timer.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 DS_TIMER_H
7#define DS_TIMER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13DECL_BITFIELD(DSTimerFlags, uint32_t);
14DECL_BITS(DSTimerFlags, PrescaleBits, 0, 4);
15DECL_BIT(DSTimerFlags, CountUp, 4);
16DECL_BIT(DSTimerFlags, DoIrq, 5);
17DECL_BIT(DSTimerFlags, Enable, 6);
18
19struct DSTimer {
20 uint16_t reload;
21 uint16_t oldReload;
22 int32_t lastEvent;
23 int32_t nextEvent;
24 int32_t overflowInterval;
25 DSTimerFlags flags;
26};
27
28// TODO: Merge back into GBATimer
29struct ARMCore;
30void DSTimerUpdateRegister(struct DSTimer* timer, struct ARMCore* cpu, uint16_t* io);
31void DSTimerWriteTMCNT_LO(struct DSTimer* timer, uint16_t reload);
32void DSTimerWriteTMCNT_HI(struct DSTimer* timer, struct ARMCore* cpu, uint16_t* io, uint16_t control);
33
34struct DS;
35int32_t DSTimersProcessEvents(struct DS* ds, int32_t cycles);
36
37CXX_GUARD_END
38
39#endif