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 int32_t nextEvent;
24 int32_t eventDiff;
25
26 int32_t nextDiv;
27 int32_t nextTima;
28 int32_t timaPeriod;
29};
30
31void GBTimerReset(struct GBTimer*);
32int32_t GBTimerProcessEvents(struct GBTimer*, int32_t cycles);
33void GBTimerDivReset(struct GBTimer*);
34uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac);
35void GBTimerUpdateTIMA(struct GBTimer* timer);
36
37#endif