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