all repos — mgba @ 34529398bb1da3cc1e0277d05d9e4902bdb39249

mGBA Game Boy Advance Emulator

include/mgba/internal/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 <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/cpu.h>
 14#include <mgba/core/interface.h>
 15#include <mgba/core/log.h>
 16#include <mgba/core/timing.h>
 17
 18#include <mgba/internal/gb/audio.h>
 19#include <mgba/internal/gb/memory.h>
 20#include <mgba/internal/gb/sio.h>
 21#include <mgba/internal/gb/timer.h>
 22#include <mgba/internal/gb/video.h>
 23
 24extern const uint32_t DMG_LR35902_FREQUENCY;
 25extern const uint32_t CGB_LR35902_FREQUENCY;
 26extern const uint32_t SGB_LR35902_FREQUENCY;
 27
 28mLOG_DECLARE_CATEGORY(GB);
 29
 30// TODO: Prefix GBAIRQ
 31enum GBIRQ {
 32	GB_IRQ_VBLANK = 0x0,
 33	GB_IRQ_LCDSTAT = 0x1,
 34	GB_IRQ_TIMER = 0x2,
 35	GB_IRQ_SIO = 0x3,
 36	GB_IRQ_KEYPAD = 0x4,
 37};
 38
 39enum GBIRQVector {
 40	GB_VECTOR_VBLANK = 0x40,
 41	GB_VECTOR_LCDSTAT = 0x48,
 42	GB_VECTOR_TIMER = 0x50,
 43	GB_VECTOR_SIO = 0x58,
 44	GB_VECTOR_KEYPAD = 0x60,
 45};
 46
 47enum GBSGBCommand {
 48	SGB_PAL01 = 0,
 49	SGB_PAL23,
 50	SGB_PAL03,
 51	SGB_PAL12,
 52	SGB_ATTR_BLK,
 53	SGB_ATTR_LIN,
 54	SGB_ATTR_DIV,
 55	SGB_ATTR_CHR,
 56	SGB_SOUND,
 57	SGB_SOU_TRN,
 58	SGB_PAL_SET,
 59	SGB_PAL_TRN,
 60	SGB_ATRC_EN,
 61	SGB_TEST_EN,
 62	SGB_PICON_EN,
 63	SGB_DATA_SND,
 64	SGB_DATA_TRN,
 65	SGB_MLT_REQ,
 66	SGB_JUMP,
 67	SGB_CHR_TRN,
 68	SGB_PCT_TRN,
 69	SGB_ATTR_TRN,
 70	SGB_ATTR_SET,
 71	SGB_MASK_EN,
 72	SGB_OBJ_TRN
 73};
 74
 75struct LR35902Core;
 76struct mCoreSync;
 77struct mAVStream;
 78struct GB {
 79	struct mCPUComponent d;
 80
 81	struct LR35902Core* cpu;
 82	struct GBMemory memory;
 83	struct GBVideo video;
 84	struct GBTimer timer;
 85	struct GBAudio audio;
 86	struct GBSIO sio;
 87	enum GBModel model;
 88
 89	struct mCoreSync* sync;
 90	struct mTiming timing;
 91
 92	uint8_t* keySource;
 93
 94	bool isPristine;
 95	size_t pristineRomSize;
 96	size_t yankedRomSize;
 97	uint32_t romCrc32;
 98	struct VFile* romVf;
 99	struct VFile* biosVf;
100	struct VFile* sramVf;
101	struct VFile* sramRealVf;
102	uint32_t sramSize;
103	int sramDirty;
104	int32_t sramDirtAge;
105	bool sramMaskWriteback;
106
107	int sgbBit;
108	int currentSgbBits;
109	uint8_t sgbPacket[16];
110	uint8_t sgbControllers;
111	uint8_t sgbCurrentController;
112	bool sgbIncrement;
113
114	struct mCoreCallbacksList coreCallbacks;
115	struct mAVStream* stream;
116
117	bool cpuBlocked;
118	bool earlyExit;
119	struct mTimingEvent eiPending;
120	unsigned doubleSpeed;
121
122	bool allowOpposingDirections;
123};
124
125struct GBCartridge {
126	uint8_t entry[4];
127	uint8_t logo[48];
128	union {
129		char titleLong[16];
130		struct {
131			char titleShort[11];
132			char maker[4];
133			uint8_t cgb;
134		};
135	};
136	char licensee[2];
137	uint8_t sgb;
138	uint8_t type;
139	uint8_t romSize;
140	uint8_t ramSize;
141	uint8_t region;
142	uint8_t oldLicensee;
143	uint8_t version;
144	uint8_t headerChecksum;
145	uint16_t globalChecksum;
146	// And ROM data...
147};
148
149void GBCreate(struct GB* gb);
150void GBDestroy(struct GB* gb);
151
152void GBReset(struct LR35902Core* cpu);
153void GBSkipBIOS(struct GB* gb);
154void GBMapBIOS(struct GB* gb);
155void GBUnmapBIOS(struct GB* gb);
156void GBDetectModel(struct GB* gb);
157
158void GBUpdateIRQs(struct GB* gb);
159void GBHalt(struct LR35902Core* cpu);
160
161struct VFile;
162bool GBLoadROM(struct GB* gb, struct VFile* vf);
163bool GBLoadSave(struct GB* gb, struct VFile* vf);
164void GBUnloadROM(struct GB* gb);
165void GBSynthesizeROM(struct VFile* vf);
166
167void GBLoadBIOS(struct GB* gb, struct VFile* vf);
168
169void GBSramClean(struct GB* gb, uint32_t frameCount);
170void GBResizeSram(struct GB* gb, size_t size);
171void GBSavedataMask(struct GB* gb, struct VFile* vf, bool writeback);
172void GBSavedataUnmask(struct GB* gb);
173
174struct Patch;
175void GBApplyPatch(struct GB* gb, struct Patch* patch);
176
177void GBGetGameTitle(const struct GB* gba, char* out);
178void GBGetGameCode(const struct GB* gba, char* out);
179
180void GBTestKeypadIRQ(struct GB* gb);
181
182void GBFrameStarted(struct GB* gb);
183void GBFrameEnded(struct GB* gb);
184
185CXX_GUARD_END
186
187#endif