all repos — mgba @ b4fa4fe77e23ed774e749608144fc0d1330b941c

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