all repos — mgba @ 644bdec47c78f4b1121a4bb3bd0fce31f5d5dced

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 = 16
17};
18
19struct GB;
20struct GBTimer {
21	struct GB* p;
22
23	int32_t nextEvent;
24	int32_t eventDiff;
25
26	uint32_t internalDiv;
27	int32_t nextDiv;
28	uint32_t timaPeriod;
29	bool irqPending;
30};
31
32void GBTimerReset(struct GBTimer*);
33int32_t GBTimerProcessEvents(struct GBTimer*, int32_t cycles);
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