all repos — mgba @ c037dada3e13727bb41ce807fe9a6caa8fd4cf95

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