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