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