all repos — mgba @ 3fcdbd0d8983c024a1c88d85a1cc137e9c9482db

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