all repos — mgba @ d41b904485e18f85a287101722351f93b6d9764e

mGBA Game Boy Advance Emulator

include/mgba/internal/ds/ds.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 DS_H
  7#define DS_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#include <mgba-util/circle-buffer.h>
 16
 17#include <mgba/internal/ds/memory.h>
 18#include <mgba/internal/ds/timer.h>
 19#include <mgba/internal/ds/video.h>
 20
 21extern const uint32_t DS_ARM946ES_FREQUENCY;
 22extern const uint32_t DS_ARM7TDMI_FREQUENCY;
 23extern const uint8_t DS_CHIP_ID[4];
 24
 25enum DSIRQ {
 26	DS_IRQ_VBLANK = 0x0,
 27	DS_IRQ_HBLANK = 0x1,
 28	DS_IRQ_VCOUNTER = 0x2,
 29	DS_IRQ_TIMER0 = 0x3,
 30	DS_IRQ_TIMER1 = 0x4,
 31	DS_IRQ_TIMER2 = 0x5,
 32	DS_IRQ_TIMER3 = 0x6,
 33	DS_IRQ_SIO = 0x7,
 34	DS_IRQ_DMA0 = 0x8,
 35	DS_IRQ_DMA1 = 0x9,
 36	DS_IRQ_DMA2 = 0xA,
 37	DS_IRQ_DMA3 = 0xB,
 38	DS_IRQ_KEYPAD = 0xC,
 39	DS_IRQ_SLOT2 = 0xD,
 40	DS_IRQ_IPC_SYNC = 0x10,
 41	DS_IRQ_IPC_EMPTY = 0x11,
 42	DS_IRQ_IPC_NOT_EMPTY = 0x12,
 43	DS_IRQ_SLOT1_TRANS = 0x13,
 44	DS_IRQ_SLOT1 = 0x14,
 45	DS_IRQ_GEOM_FIFO = 0x15,
 46	DS_IRQ_LID = 0x16,
 47	DS_IRQ_SPI = 0x17,
 48	DS_IRQ_WIFI = 0x18,
 49};
 50
 51struct ARMCore;
 52struct DS;
 53struct Patch;
 54struct VFile;
 55struct mDebugger;
 56
 57mLOG_DECLARE_CATEGORY(DS);
 58
 59struct DSCommon {
 60	struct DS* p;
 61
 62	struct ARMCore* cpu;
 63	struct GBATimer timers[4];
 64	struct mTiming timing;
 65	int springIRQ;
 66
 67	struct DSCoreMemory memory;
 68	struct DSCommon* ipc;
 69
 70	struct CircleBuffer fifo;
 71};
 72
 73struct mCoreCallbacks;
 74struct DS {
 75	struct mCPUComponent d;
 76
 77	struct DSCommon ds7;
 78	struct DSCommon ds9;
 79	struct DSMemory memory;
 80	struct DSVideo video;
 81
 82	struct mCoreSync* sync;
 83	struct mTimingEvent slice;
 84	struct ARMCore* activeCpu;
 85	uint32_t sliceStart;
 86	int32_t cycleDrift;
 87
 88	struct ARMDebugger* debugger;
 89
 90	bool cpuBlocked;
 91	bool earlyExit;
 92
 93	uint32_t bios7Checksum;
 94	uint32_t bios9Checksum;
 95	int* keySource;
 96	struct mRTCSource* rtcSource;
 97	struct mRumble* rumble;
 98
 99	struct VFile* romVf;
100	struct VFile* bios7Vf;
101	struct VFile* bios9Vf;
102	struct VFile* firmwareVf;
103
104	struct mKeyCallback* keyCallback;
105	struct mCoreCallbacks* coreCallbacks;
106
107	struct mTimingEvent divEvent;
108	struct mTimingEvent sqrtEvent;
109};
110
111struct DSCartridge {
112	char title[12];
113	uint32_t id;
114
115	uint16_t maker;
116	uint8_t type;
117	uint8_t encryptionSeed;
118	uint8_t size;
119	uint8_t reserved[8];
120	uint8_t region;
121	uint8_t version;
122	uint8_t autostart;
123	uint32_t arm9Offset;
124	uint32_t arm9Entry;
125	uint32_t arm9Base;
126	uint32_t arm9Size;
127	uint32_t arm7Offset;
128	uint32_t arm7Entry;
129	uint32_t arm7Base;
130	uint32_t arm7Size;
131	uint32_t fntOffset;
132	uint32_t fntSize;
133	uint32_t fatOffset;
134	uint32_t fatSize;
135	uint32_t arm9FileOverlayOffset;
136	uint32_t arm9FileOverlaySize;
137	uint32_t arm7FileOverlayOffset;
138	uint32_t arm7FileOverlaySize;
139	uint32_t busTiming;
140	uint32_t busKEY1Timing;
141	uint32_t iconOffset;
142	uint16_t secureAreaCrc16;
143	uint16_t secureAreaDelay;
144	// TODO: Fill in more
145	// And ROM data...
146};
147
148void DSCreate(struct DS* ds);
149void DSDestroy(struct DS* ds);
150
151void DSRunLoop(struct DS* ds);
152void DS7Step(struct DS* ds);
153void DS9Step(struct DS* ds);
154
155void DSAttachDebugger(struct DS* ds, struct mDebugger* debugger);
156void DSDetachDebugger(struct DS* ds);
157
158bool DSLoadROM(struct DS* ds, struct VFile* vf);
159bool DSLoadSave(struct DS* ds, struct VFile* vf);
160void DSUnloadROM(struct DS* ds);
161void DSApplyPatch(struct DS* ds, struct Patch* patch);
162
163bool DSIsBIOS7(struct VFile* vf);
164bool DSIsBIOS9(struct VFile* vf);
165bool DSLoadBIOS(struct DS* ds, struct VFile* vf);
166
167bool DSIsFirmware(struct VFile* vf);
168bool DSLoadFirmware(struct DS* ds, struct VFile* vf);
169
170bool DSIsROM(struct VFile* vf);
171void DSGetGameCode(struct DS* ds, char* out);
172void DSGetGameTitle(struct DS* ds, char* out);
173
174void DSWriteIME(struct ARMCore* cpu, uint16_t* io, uint16_t value);
175void DSWriteIE(struct ARMCore* cpu, uint16_t* io, uint32_t value);
176void DSRaiseIRQ(struct ARMCore* cpu, uint16_t* io, enum DSIRQ irq);
177
178void DSFrameStarted(struct DS* ds);
179void DSFrameEnded(struct DS* ds);
180
181CXX_GUARD_END
182
183#endif