all repos — mgba @ 6ab3bdcc461e9348c30689775cc6a7fc619ce70f

mGBA Game Boy Advance Emulator

src/gb/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 GB_TIMER_H
 7#define GB_TIMER_H
 8
 9#include "util/common.h"
10
11DECL_BITFIELD(GBRegisterTAC, uint8_t);
12DECL_BITS(GBRegisterTAC, Clock, 0, 2);
13DECL_BIT(GBRegisterTAC, Run, 2);
14
15enum {
16	GB_DMG_DIV_PERIOD = 256
17};
18
19struct GB;
20struct GBTimer {
21	struct GB* p;
22
23	int mode;
24
25	int32_t nextEvent;
26	int32_t eventDiff;
27
28	int32_t nextDiv;
29	int32_t nextTima;
30	int32_t timaPeriod;
31};
32
33void GBTimerReset(struct GBTimer*);
34int32_t GBTimerProcessEvents(struct GBTimer*, int32_t cycles);
35void GBTimerDivReset(struct GBTimer*);
36uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac);
37
38#endif