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