all repos — mgba @ e0ae2e89063ec7139b89358cf476d4d79fdbcc8e

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/internal/arm/arm.h>
 14#include <mgba/core/log.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 DS;
 50struct Patch;
 51struct VFile;
 52struct mDebugger;
 53
 54mLOG_DECLARE_CATEGORY(DS);
 55
 56struct DS {
 57	struct mCPUComponent d;
 58
 59	struct ARMCore* arm7;
 60	struct ARMCore* arm9;
 61	struct DSMemory memory;
 62	struct DSVideo video;
 63	int timersEnabled7;
 64	int timersEnabled9;
 65	struct DSTimer timers7[4];
 66	struct DSTimer timers9[4];
 67
 68	struct mCoreSync* sync;
 69
 70	struct ARMDebugger* debugger;
 71
 72	int springIRQ7;
 73	int springIRQ9;
 74
 75	uint32_t bios7Checksum;
 76	uint32_t bios9Checksum;
 77	int* keySource;
 78	struct mRTCSource* rtcSource;
 79	struct mRumble* rumble;
 80
 81	struct VFile* romVf;
 82	struct VFile* bios7Vf;
 83	struct VFile* bios9Vf;
 84
 85	struct mKeyCallback* keyCallback;
 86};
 87
 88struct DSCartridge {
 89	char title[12];
 90	uint32_t id;
 91
 92	uint16_t maker;
 93	uint8_t type;
 94	uint8_t encryptionSeed;
 95	uint8_t size;
 96	uint8_t reserved[8];
 97	uint8_t region;
 98	uint8_t version;
 99	uint8_t autostart;
100	uint32_t arm9Offset;
101	uint32_t arm9Entry;
102	uint32_t arm9Base;
103	uint32_t arm9Size;
104	uint32_t arm7Offset;
105	uint32_t arm7Entry;
106	uint32_t arm7Base;
107	uint32_t arm7Size;
108	uint32_t fntOffset;
109	uint32_t fntSize;
110	uint32_t fatOffset;
111	uint32_t fatSize;
112	uint32_t arm9FileOverlayOffset;
113	uint32_t arm9FileOverlaySize;
114	uint32_t arm7FileOverlayOffset;
115	uint32_t arm7FileOverlaySize;
116	uint32_t busTiming;
117	uint32_t busKEY1Timing;
118	uint32_t iconOffset;
119	uint16_t secureAreaCrc16;
120	uint16_t secureAreaDelay;
121	// TODO: Fill in more
122	// And ROM data...
123};
124
125void DSCreate(struct DS* ds);
126void DSDestroy(struct DS* ds);
127
128void DSAttachDebugger(struct DS* ds, struct mDebugger* debugger);
129void DSDetachDebugger(struct DS* ds);
130
131bool DSLoadROM(struct DS* ds, struct VFile* vf);
132void DSUnloadROM(struct DS* ds);
133void DSApplyPatch(struct DS* ds, struct Patch* patch);
134
135bool DSLoadBIOS(struct DS* ds, struct VFile* vf);
136
137bool DSIsROM(struct VFile* vf);
138void DSGetGameCode(struct DS* ds, char* out);
139void DSGetGameTitle(struct DS* ds, char* out);
140
141void DSWriteIME(struct ARMCore* cpu, uint16_t* io, uint16_t value);
142void DSWriteIE(struct ARMCore* cpu, uint16_t* io, uint32_t value);
143void DSRaiseIRQ(struct ARMCore* cpu, uint16_t* io, enum DSIRQ irq);
144
145CXX_GUARD_END
146
147#endif