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#include "gb/timer.h"
15#include "gb/video.h"
16
17extern const uint32_t DMG_LR35902_FREQUENCY;
18extern const uint32_t CGB_LR35902_FREQUENCY;
19extern const uint32_t SGB_LR35902_FREQUENCY;
20
21// TODO: Prefix GBAIRQ
22enum GBIRQ {
23 GB_IRQ_VBLANK = 0x0,
24 GB_IRQ_LCDSTAT = 0x1,
25 GB_IRQ_TIMER = 0x2,
26 GB_IRQ_SIO = 0x3,
27 GB_IRQ_KEYPAD = 0x4,
28};
29
30enum GBIRQVector {
31 GB_VECTOR_VBLANK = 0x40,
32 GB_VECTOR_LCDSTAT = 0x48,
33 GB_VECTOR_TIMER = 0x50,
34 GB_VECTOR_SIO = 0x58,
35 GB_VECTOR_KEYPAD = 0x60,
36};
37
38struct GB {
39 struct LR35902Component d;
40
41 struct LR35902Core* cpu;
42 struct GBMemory memory;
43 struct GBVideo video;
44 struct GBTimer timer;
45
46 int* keySource;
47
48 void* pristineRom;
49 size_t pristineRomSize;
50 size_t yankedRomSize;
51 uint32_t romCrc32;
52 struct VFile* romVf;
53
54 const char* activeFile;
55};
56
57struct GBCartridge {
58 uint8_t entry[4];
59 uint8_t logo[48];
60 union {
61 char titleLong[16];
62 struct {
63 char titleShort[11];
64 char maker[4];
65 uint8_t cgb;
66 };
67 };
68 char licensee[2];
69 uint8_t sgb;
70 uint8_t type;
71 uint8_t romSize;
72 uint8_t ramSize;
73 uint8_t region;
74 uint8_t oldLicensee;
75 uint8_t version;
76 uint8_t headerChecksum;
77 uint16_t globalChecksum;
78 // And ROM data...
79};
80
81void GBCreate(struct GB* gb);
82void GBDestroy(struct GB* gb);
83
84void GBReset(struct LR35902Core* cpu);
85
86void GBUpdateIRQs(struct GB* gb);
87void GBHalt(struct LR35902Core* cpu);
88void GBStop(struct LR35902Core* cpu);
89
90struct VFile;
91bool GBLoadROM(struct GB* gb, struct VFile* vf, struct VFile* sav, const char* fname);
92void GBYankROM(struct GB* gb);
93void GBUnloadROM(struct GB* gb);
94
95struct Patch;
96void GBApplyPatch(struct GB* gb, struct Patch* patch);
97
98bool GBIsROM(struct VFile* vf);
99
100void GBFrameStarted(struct GB* gb);
101void GBFrameEnded(struct GB* gb);
102
103#endif