all repos — mgba @ 20f8baa82cb9916ce0e690239cee8efa9eceebf9

mGBA Game Boy Advance Emulator

include/mgba/internal/gba/gba.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 GBA_H
  7#define GBA_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/log.h>
 14#include <mgba/core/timing.h>
 15
 16#include <mgba/internal/gba/memory.h>
 17#include <mgba/internal/gba/video.h>
 18#include <mgba/internal/gba/audio.h>
 19#include <mgba/internal/gba/sio.h>
 20#include <mgba/internal/gba/timer.h>
 21
 22#define GBA_ARM7TDMI_FREQUENCY 0x1000000U
 23
 24enum GBAIRQ {
 25	IRQ_VBLANK = 0x0,
 26	IRQ_HBLANK = 0x1,
 27	IRQ_VCOUNTER = 0x2,
 28	IRQ_TIMER0 = 0x3,
 29	IRQ_TIMER1 = 0x4,
 30	IRQ_TIMER2 = 0x5,
 31	IRQ_TIMER3 = 0x6,
 32	IRQ_SIO = 0x7,
 33	IRQ_DMA0 = 0x8,
 34	IRQ_DMA1 = 0x9,
 35	IRQ_DMA2 = 0xA,
 36	IRQ_DMA3 = 0xB,
 37	IRQ_KEYPAD = 0xC,
 38	IRQ_GAMEPAK = 0xD
 39};
 40
 41enum GBAIdleLoopOptimization {
 42	IDLE_LOOP_IGNORE = -1,
 43	IDLE_LOOP_REMOVE = 0,
 44	IDLE_LOOP_DETECT
 45};
 46
 47enum {
 48	SP_BASE_SYSTEM = 0x03007F00,
 49	SP_BASE_IRQ = 0x03007FA0,
 50	SP_BASE_SUPERVISOR = 0x03007FE0
 51};
 52
 53struct ARMCore;
 54struct GBA;
 55struct Patch;
 56struct VFile;
 57
 58mLOG_DECLARE_CATEGORY(GBA);
 59mLOG_DECLARE_CATEGORY(GBA_DEBUG);
 60
 61DECL_BITFIELD(GBADebugFlags, uint16_t);
 62DECL_BITS(GBADebugFlags, Level, 0, 3);
 63DECL_BIT(GBADebugFlags, Send, 8);
 64
 65struct GBA {
 66	struct mCPUComponent d;
 67
 68	struct ARMCore* cpu;
 69	struct GBAMemory memory;
 70	struct GBAVideo video;
 71	struct GBAAudio audio;
 72	struct GBASIO sio;
 73
 74	struct mCoreSync* sync;
 75	struct mTiming timing;
 76
 77	struct ARMDebugger* debugger;
 78
 79	uint32_t bus;
 80	int performingDMA;
 81
 82	struct GBATimer timers[4];
 83
 84	int springIRQ;
 85	struct mTimingEvent irqEvent;
 86
 87	uint32_t biosChecksum;
 88	int* keySource;
 89	struct mRotationSource* rotationSource;
 90	struct GBALuminanceSource* luminanceSource;
 91	struct mRTCSource* rtcSource;
 92	struct mRumble* rumble;
 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
101	struct mAVStream* stream;
102	struct mKeyCallback* keyCallback;
103	struct mCoreCallbacksList coreCallbacks;
104
105	enum GBAIdleLoopOptimization idleOptimization;
106	uint32_t idleLoop;
107	uint32_t lastJump;
108	bool haltPending;
109	bool cpuBlocked;
110	bool earlyExit;
111	uint32_t dmaPC;
112	uint32_t biosStall;
113
114	int idleDetectionStep;
115	int idleDetectionFailures;
116	int32_t cachedRegisters[16];
117	bool taintedRegisters[16];
118
119	bool vbaBugCompat;
120	bool hardCrash;
121	bool allowOpposingDirections;
122
123	bool debug;
124	char debugString[0x100];
125	GBADebugFlags debugFlags;
126};
127
128struct GBACartridge {
129	uint32_t entry;
130	uint8_t logo[156];
131	char title[12];
132	uint32_t id;
133	uint16_t maker;
134	uint8_t type;
135	uint8_t unit;
136	uint8_t device;
137	uint8_t reserved[7];
138	uint8_t version;
139	uint8_t checksum;
140	// And ROM data...
141};
142
143void GBACreate(struct GBA* gba);
144void GBADestroy(struct GBA* gba);
145
146void GBAReset(struct ARMCore* cpu);
147void GBASkipBIOS(struct GBA* gba);
148
149void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq, uint32_t cyclesLate);
150void GBATestIRQ(struct GBA* gba, uint32_t cyclesLate);
151void GBAHalt(struct GBA* gba);
152void GBAStop(struct GBA* gba);
153void GBADebug(struct GBA* gba, uint16_t value);
154
155#ifdef USE_DEBUGGERS
156struct mDebugger;
157void GBAAttachDebugger(struct GBA* gba, struct mDebugger* debugger);
158void GBADetachDebugger(struct GBA* gba);
159#endif
160
161void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode,
162                      uint32_t* opcode);
163void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
164
165bool GBALoadROM(struct GBA* gba, struct VFile* vf);
166bool GBALoadSave(struct GBA* gba, struct VFile* sav);
167void GBAYankROM(struct GBA* gba);
168void GBAUnloadROM(struct GBA* gba);
169void GBALoadBIOS(struct GBA* gba, struct VFile* vf);
170void GBAApplyPatch(struct GBA* gba, struct Patch* patch);
171
172bool GBALoadMB(struct GBA* gba, struct VFile* vf);
173bool GBALoadNull(struct GBA* gba);
174
175void GBAGetGameCode(const struct GBA* gba, char* out);
176void GBAGetGameTitle(const struct GBA* gba, char* out);
177
178void GBATestKeypadIRQ(struct GBA* gba);
179
180void GBAFrameStarted(struct GBA* gba);
181void GBAFrameEnded(struct GBA* gba);
182
183CXX_GUARD_END
184
185#endif