all repos — mgba @ 09cce3627bfbe45ab3234ddae06105d5e4cf29c7

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
113	struct mCoreCallbacksList coreCallbacks;
114	struct mAVStream* stream;
115
116	bool cpuBlocked;
117	bool earlyExit;
118	struct mTimingEvent eiPending;
119	unsigned doubleSpeed;
120
121	bool allowOpposingDirections;
122};
123
124struct GBCartridge {
125	uint8_t entry[4];
126	uint8_t logo[48];
127	union {
128		char titleLong[16];
129		struct {
130			char titleShort[11];
131			char maker[4];
132			uint8_t cgb;
133		};
134	};
135	char licensee[2];
136	uint8_t sgb;
137	uint8_t type;
138	uint8_t romSize;
139	uint8_t ramSize;
140	uint8_t region;
141	uint8_t oldLicensee;
142	uint8_t version;
143	uint8_t headerChecksum;
144	uint16_t globalChecksum;
145	// And ROM data...
146};
147
148void GBCreate(struct GB* gb);
149void GBDestroy(struct GB* gb);
150
151void GBReset(struct LR35902Core* cpu);
152void GBSkipBIOS(struct GB* gb);
153void GBMapBIOS(struct GB* gb);
154void GBUnmapBIOS(struct GB* gb);
155void GBDetectModel(struct GB* gb);
156
157void GBUpdateIRQs(struct GB* gb);
158void GBHalt(struct LR35902Core* cpu);
159
160struct VFile;
161bool GBLoadROM(struct GB* gb, struct VFile* vf);
162bool GBLoadSave(struct GB* gb, struct VFile* vf);
163void GBUnloadROM(struct GB* gb);
164void GBSynthesizeROM(struct VFile* vf);
165
166void GBLoadBIOS(struct GB* gb, struct VFile* vf);
167
168void GBSramClean(struct GB* gb, uint32_t frameCount);
169void GBResizeSram(struct GB* gb, size_t size);
170void GBSavedataMask(struct GB* gb, struct VFile* vf, bool writeback);
171void GBSavedataUnmask(struct GB* gb);
172
173struct Patch;
174void GBApplyPatch(struct GB* gb, struct Patch* patch);
175
176void GBGetGameTitle(const struct GB* gba, char* out);
177void GBGetGameCode(const struct GB* gba, char* out);
178
179void GBTestKeypadIRQ(struct GB* gb);
180
181void GBFrameStarted(struct GB* gb);
182void GBFrameEnded(struct GB* gb);
183
184CXX_GUARD_END
185
186#endif