all repos — mgba @ a506f6cd9d6fd025410f62e3b663b0aaea3f0b82

mGBA Game Boy Advance Emulator

src/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 "util/common.h"
 10
 11#include "arm/arm.h"
 12#include "core/log.h"
 13#include "core/timing.h"
 14
 15#include "gba/interface.h"
 16#include "gba/memory.h"
 17#include "gba/video.h"
 18#include "gba/audio.h"
 19#include "gba/sio.h"
 20#include "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 GBA;
 54struct Patch;
 55struct VFile;
 56
 57mLOG_DECLARE_CATEGORY(GBA);
 58mLOG_DECLARE_CATEGORY(GBA_DEBUG);
 59
 60DECL_BITFIELD(GBADebugFlags, uint16_t);
 61DECL_BITS(GBADebugFlags, Level, 0, 3);
 62DECL_BIT(GBADebugFlags, Send, 8);
 63
 64struct GBA {
 65	struct mCPUComponent d;
 66
 67	struct ARMCore* cpu;
 68	struct GBAMemory memory;
 69	struct GBAVideo video;
 70	struct GBAAudio audio;
 71	struct GBASIO sio;
 72
 73	struct mCoreSync* sync;
 74	struct mTiming timing;
 75
 76	struct ARMDebugger* debugger;
 77
 78	uint32_t bus;
 79	int performingDMA;
 80
 81	struct GBATimer timers[4];
 82
 83	int springIRQ;
 84	uint32_t biosChecksum;
 85	int* keySource;
 86	struct mRotationSource* rotationSource;
 87	struct GBALuminanceSource* luminanceSource;
 88	struct mRTCSource* rtcSource;
 89	struct mRumble* rumble;
 90
 91	struct GBARRContext* rr;
 92	void* pristineRom;
 93	size_t pristineRomSize;
 94	size_t yankedRomSize;
 95	uint32_t romCrc32;
 96	struct VFile* romVf;
 97	struct VFile* biosVf;
 98
 99	struct mAVStream* stream;
100	struct mKeyCallback* keyCallback;
101	struct mStopCallback* stopCallback;
102	struct mCoreCallbacks* coreCallbacks;
103
104	enum GBAIdleLoopOptimization idleOptimization;
105	uint32_t idleLoop;
106	uint32_t lastJump;
107	bool haltPending;
108	int idleDetectionStep;
109	int idleDetectionFailures;
110	int32_t cachedRegisters[16];
111	bool taintedRegisters[16];
112
113	bool realisticTiming;
114	bool hardCrash;
115	bool allowOpposingDirections;
116
117	bool debug;
118	char debugString[0x100];
119	GBADebugFlags debugFlags;
120};
121
122struct GBACartridge {
123	uint32_t entry;
124	uint8_t logo[156];
125	char title[12];
126	uint32_t id;
127	uint16_t maker;
128	uint8_t type;
129	uint8_t unit;
130	uint8_t device;
131	uint8_t reserved[7];
132	uint8_t version;
133	uint8_t checksum;
134	// And ROM data...
135};
136
137void GBACreate(struct GBA* gba);
138void GBADestroy(struct GBA* gba);
139
140void GBAReset(struct ARMCore* cpu);
141void GBASkipBIOS(struct GBA* gba);
142
143void GBAWriteIE(struct GBA* gba, uint16_t value);
144void GBAWriteIME(struct GBA* gba, uint16_t value);
145void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
146void GBATestIRQ(struct ARMCore* cpu);
147void GBAHalt(struct GBA* gba);
148void GBAStop(struct GBA* gba);
149void GBADebug(struct GBA* gba, uint16_t value);
150
151void GBAAttachDebugger(struct GBA* gba, struct mDebugger* debugger);
152void GBADetachDebugger(struct GBA* gba);
153
154void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode,
155                      uint32_t* opcode);
156void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
157
158bool GBALoadROM(struct GBA* gba, struct VFile* vf);
159bool GBALoadSave(struct GBA* gba, struct VFile* sav);
160void GBAYankROM(struct GBA* gba);
161void GBAUnloadROM(struct GBA* gba);
162void GBALoadBIOS(struct GBA* gba, struct VFile* vf);
163void GBAApplyPatch(struct GBA* gba, struct Patch* patch);
164
165bool GBALoadMB(struct GBA* gba, struct VFile* vf);
166
167bool GBAIsROM(struct VFile* vf);
168bool GBAIsMB(struct VFile* vf);
169bool GBAIsBIOS(struct VFile* vf);
170void GBAGetGameCode(const struct GBA* gba, char* out);
171void GBAGetGameTitle(const struct GBA* gba, char* out);
172
173void GBAFrameStarted(struct GBA* gba);
174void GBAFrameEnded(struct GBA* gba);
175
176#endif