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