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
11CXX_GUARD_START
12
13#include "core/timing.h"
14
15DECL_BITFIELD(GBRegisterTAC, uint8_t);
16DECL_BITS(GBRegisterTAC, Clock, 0, 2);
17DECL_BIT(GBRegisterTAC, Run, 2);
18
19enum {
20 GB_DMG_DIV_PERIOD = 16
21};
22
23struct GB;
24struct GBTimer {
25 struct GB* p;
26
27 struct mTimingEvent event;
28 struct mTimingEvent irq;
29
30 uint32_t internalDiv;
31 int32_t nextDiv;
32 uint32_t timaPeriod;
33};
34
35void GBTimerReset(struct GBTimer*);
36void GBTimerDivReset(struct GBTimer*);
37uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac);
38
39struct GBSerializedState;
40void GBTimerSerialize(const struct GBTimer* timer, struct GBSerializedState* state);
41void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* state);
42
43CXX_GUARD_END
44
45#endif