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