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 struct VFile* sramRealVf;
70 uint32_t sramSize;
71
72 struct mAVStream* stream;
73
74 int32_t eiPending;
75 unsigned doubleSpeed;
76};
77
78struct GBCartridge {
79 uint8_t entry[4];
80 uint8_t logo[48];
81 union {
82 char titleLong[16];
83 struct {
84 char titleShort[11];
85 char maker[4];
86 uint8_t cgb;
87 };
88 };
89 char licensee[2];
90 uint8_t sgb;
91 uint8_t type;
92 uint8_t romSize;
93 uint8_t ramSize;
94 uint8_t region;
95 uint8_t oldLicensee;
96 uint8_t version;
97 uint8_t headerChecksum;
98 uint16_t globalChecksum;
99 // And ROM data...
100};
101
102void GBCreate(struct GB* gb);
103void GBDestroy(struct GB* gb);
104
105void GBReset(struct LR35902Core* cpu);
106void GBDetectModel(struct GB* gb);
107
108void GBUpdateIRQs(struct GB* gb);
109void GBHalt(struct LR35902Core* cpu);
110
111struct VFile;
112bool GBLoadROM(struct GB* gb, struct VFile* vf);
113bool GBLoadSave(struct GB* gb, struct VFile* vf);
114void GBResizeSram(struct GB* gb, size_t size);
115void GBYankROM(struct GB* gb);
116void GBUnloadROM(struct GB* gb);
117
118void GBLoadBIOS(struct GB* gb, struct VFile* vf);
119
120void GBSavedataMask(struct GB* gb, struct VFile* vf);
121void GBSavedataUnmask(struct GB* gb);
122
123struct Patch;
124void GBApplyPatch(struct GB* gb, struct Patch* patch);
125
126bool GBIsROM(struct VFile* vf);
127void GBGetGameTitle(struct GB* gba, char* out);
128void GBGetGameCode(struct GB* gba, char* out);
129
130void GBFrameStarted(struct GB* gb);
131void GBFrameEnded(struct GB* gb);
132
133#endif