src/gb/gb.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_H
7#define GB_H
8
9#include "util/common.h"
10
11#include "lr35902/lr35902.h"
12
13#include "gb/memory.h"
14
15extern const uint32_t DMG_LR35902_FREQUENCY;
16extern const uint32_t CGB_LR35902_FREQUENCY;
17extern const uint32_t SGB_LR35902_FREQUENCY;
18
19// TODO: Prefix GBAIRQ
20enum GBIRQ {
21 GB_IRQ_VBLANK = 0x0,
22 GB_IRQ_LCDSTAT = 0x1,
23 GB_IRQ_TIMER = 0x2,
24 GB_IRQ_SIO = 0x3,
25 GB_IRQ_KEYPAD = 0x4,
26};
27
28struct GB {
29 struct LR35902Component d;
30
31 struct LR35902Core* cpu;
32 struct GBMemory memory;
33
34 int* keySource;
35
36 void* pristineRom;
37 size_t pristineRomSize;
38 size_t yankedRomSize;
39 uint32_t romCrc32;
40 struct VFile* romVf;
41
42 const char* activeFile;
43};
44
45void GBCreate(struct GB* gb);
46void GBDestroy(struct GB* gb);
47
48void GBReset(struct LR35902Core* cpu);
49
50void GBWriteIE(struct GB* gb, uint8_t value);
51void GBRaiseIRQ(struct GB* gb, enum GBIRQ irq);
52void GBTestIRQ(struct LR35902Core* cpu);
53void GBHalt(struct GB* gb);
54void GBStop(struct GB* gb);
55
56struct VFile;
57bool GBLoadROM(struct GB* gb, struct VFile* vf, struct VFile* sav, const char* fname);
58void GBYankROM(struct GB* gb);
59void GBUnloadROM(struct GB* gb);
60
61struct Patch;
62void GBApplyPatch(struct GB* gb, struct Patch* patch);
63
64bool GBIsROM(struct VFile* vf);
65
66void GBFrameStarted(struct GB* gb);
67void GBFrameEnded(struct GB* gb);
68
69#endif