Skip to content

Commit 16459a2

Browse files
authored
Merge pull request #51 from ahezard/card
LRU cache
2 parents 27eb813 + 0bfdab1 commit 16459a2

9 files changed

Lines changed: 193 additions & 109 deletions

File tree

arm7/source/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,27 @@ static const unsigned char dldiMagicString[] = "\xED\xA5\x8D\xBF Chishm"; // Nor
8585
void initMBK() {
8686
// give all DSI WRAM to arm7 at boot
8787

88-
// arm7 is master of WRAM-A/B/C
88+
// arm7 is master of WRAM-A, arm9 of WRAM-B & C
8989
REG_MBK_9=0x3000000F;
9090

9191
// WRAM-A fully mapped to arm7
9292
REG_MBK_1=0x8185898D;
9393

9494
// WRAM-B fully mapped to arm7
95-
REG_MBK_2=0x8185898D;
96-
REG_MBK_3=0x9195999D;
95+
REG_MBK_2=0x8D898581;
96+
REG_MBK_3=0x9D999591;
9797

9898
// WRAM-C fully mapped to arm7
99-
REG_MBK_4=0x8185898D;
100-
REG_MBK_5=0x9195999D;
99+
REG_MBK_4=0x8D898581;
100+
REG_MBK_5=0x9D999591;
101101

102102
// WRAM mapped to the 0x3700000 - 0x37AFFFF area
103103
// WRAM-A mapped to the 0x3780000 - 0x37BFFFF area : 256k
104104
REG_MBK_6=0x07C03780;
105-
// WRAM-B mapped to the 0x3740000 - 0x377FFFF area : 256k
106-
REG_MBK_7=0x07803740;
107-
// WRAM-C mapped to the 0x3700000 - 0x373FFFF area : 256k
108-
REG_MBK_8=0x07403700;
105+
// WRAM-B mapped to the 0x3700000 - 0x373FFFF area : 256k
106+
REG_MBK_7=0x07403700;
107+
// WRAM-C mapped to the 0x3740000 - 0x377FFFF area : 256k
108+
REG_MBK_8=0x07803740;
109109
}
110110

111111
//---------------------------------------------------------------------------------

arm9/source/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ void initMBK() {
144144
//REG_MBK_5=0x9094989C;
145145

146146
// WRAM-B fully mapped to arm7
147-
REG_MBK_2=0x8185898D;
148-
REG_MBK_3=0x9195999D;
147+
REG_MBK_2=0x8D898581;
148+
REG_MBK_3=0x9D999591;
149149

150150
// WRAM-C fully mapped to arm7
151-
REG_MBK_4=0x8185898D;
152-
REG_MBK_5=0x9195999D;
151+
REG_MBK_4=0x8D898581;
152+
REG_MBK_5=0x9D999591;
153153

154154
// WRAM-A not mapped (reserved to arm7)
155155
REG_MBK_6=0x00000000;
156-
// WRAM-B mapped to the 0x3740000 - 0x377FFFF area : 256k
157-
REG_MBK_7=0x07803740;
158-
// WRAM-C mapped to the 0x3700000 - 0x373FFFF area : 256k
159-
REG_MBK_8=0x07403700;
156+
// WRAM-B mapped to the 0x3700000 - 0x373FFFF area : 256k
157+
REG_MBK_7=0x07403700;
158+
// WRAM-C mapped to the 0x3740000 - 0x377FFFF area : 256k
159+
REG_MBK_8=0x07803740;
160160
}
161161

162162
int main( int argc, char **argv) {

cardengine_arm7/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CFLAGS := -g -Wall -O2\
3333
-ffast-math \
3434
$(ARCH)
3535

36+
# ADD -DDEBUG here for logging/debug
3637
CFLAGS += $(INCLUDE) -DARM7 -std=gnu99
3738

3839
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

cardengine_arm7/source/cardEngine.c

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void initLogging() {
4848
else
4949
savFile.firstCluster = CLUSTER_FREE;
5050
buildFatTableCache(romFile);
51+
#ifdef DEBUG
5152
aFile myDebugFile = getBootFileCluster ("NDSBTSRP.LOG");
5253
enableDebug(myDebugFile);
5354
dbg_printf("logging initialized\n");
@@ -59,7 +60,8 @@ void initLogging() {
5960
dbg_printf("\n");
6061
dbg_printf("save file :");
6162
dbg_hexa(saveCluster);
62-
dbg_printf("\n");
63+
dbg_printf("\n");
64+
#endif
6365
initialized=true;
6466
}
6567

@@ -75,48 +77,18 @@ void runCardEngineCheck (void) {
7577
//nocashMessage("runCardEngineCheck mutex ok");
7678

7779
if(*(vu32*)(0x027FFB14) == (vu32)0x026ff800)
78-
{
79-
dbg_printf("\ncard read received\n");
80-
81-
if(calledViaIPC) {
82-
dbg_printf("\ntriggered via IPC\n");
83-
}
84-
80+
{
81+
#ifdef DEBUG
8582
u32 src = *(vu32*)(sharedAddr+2);
8683
u32 dst = *(vu32*)(sharedAddr);
8784
u32 len = *(vu32*)(sharedAddr+1);
88-
u32 marker = *(vu32*)(sharedAddr+3);
89-
90-
dbg_printf("\nstr : \n");
91-
dbg_hexa(cardStruct);
92-
dbg_printf("\nsrc : \n");
93-
dbg_hexa(src);
94-
dbg_printf("\ndst : \n");
95-
dbg_hexa(dst);
96-
dbg_printf("\nlen : \n");
97-
dbg_hexa(len);
98-
dbg_printf("\nmarker : \n");
99-
dbg_hexa(marker);
100-
101-
dbg_printf("\nlog only \n");
102-
103-
*(vu32*)(0x027FFB14) = 0;
104-
}
85+
u32 marker = *(vu32*)(sharedAddr+3);
10586

106-
107-
if(*(vu32*)(0x027FFB14) == (vu32)0x027ff800)
108-
{
10987
dbg_printf("\ncard read received\n");
11088

11189
if(calledViaIPC) {
11290
dbg_printf("\ntriggered via IPC\n");
11391
}
114-
115-
u32 src = *(vu32*)(sharedAddr+2);
116-
u32 dst = *(vu32*)(sharedAddr);
117-
u32 len = *(vu32*)(sharedAddr+1);
118-
u32 marker = *(vu32*)(sharedAddr+3);
119-
12092
dbg_printf("\nstr : \n");
12193
dbg_hexa(cardStruct);
12294
dbg_printf("\nsrc : \n");
@@ -128,36 +100,27 @@ void runCardEngineCheck (void) {
128100
dbg_printf("\nmarker : \n");
129101
dbg_hexa(marker);
130102

131-
fileRead(0x027ff800 ,romFile,src,len);
132-
133-
dbg_printf("\nread \n");
134-
103+
dbg_printf("\nlog only \n");
104+
#endif
135105

136-
if(is_aligned(dst,4) || is_aligned(len,4)) {
137-
dbg_printf("\n aligned read : \n");
138-
//*(vu32*)(0x027FFB0C) = (vu32)2;
139-
} else {
140-
dbg_printf("\n misaligned read : \n");
141-
//*(vu32*)(0x027FFB0C) = (vu32)0;
142-
}
143106
*(vu32*)(0x027FFB14) = 0;
144107
}
145108

146109
if(*(vu32*)(0x027FFB14) == (vu32)0x025FFB08)
147110
{
148-
//dbg_printf("\ncard read received v2\n");
149-
150-
if(calledViaIPC) {
151-
//dbg_printf("\ntriggered via IPC\n");
152-
}
153-
154-
// old sdk version
155111
u32 src = *(vu32*)(sharedAddr+2);
156112
u32 dst = *(vu32*)(sharedAddr);
157113
u32 len = *(vu32*)(sharedAddr+1);
158114
u32 marker = *(vu32*)(sharedAddr+3);
115+
116+
#ifdef DEBUG
117+
dbg_printf("\ncard read received v2\n");
118+
119+
if(calledViaIPC) {
120+
dbg_printf("\ntriggered via IPC\n");
121+
}
159122

160-
/*dbg_printf("\nstr : \n");
123+
dbg_printf("\nstr : \n");
161124
dbg_hexa(cardStruct);
162125
dbg_printf("\nsrc : \n");
163126
dbg_hexa(src);
@@ -166,20 +129,20 @@ void runCardEngineCheck (void) {
166129
dbg_printf("\nlen : \n");
167130
dbg_hexa(len);
168131
dbg_printf("\nmarker : \n");
169-
dbg_hexa(marker);
170-
//*/
132+
dbg_hexa(marker);
133+
#endif
171134

172135
fileRead(dst,romFile,src,len);
173136

174-
//dbg_printf("\nread \n");
175-
137+
#ifdef DEBUG
138+
dbg_printf("\nread \n");
176139
if(is_aligned(dst,4) || is_aligned(len,4)) {
177-
//dbg_printf("\n aligned read : \n");
178-
//*(vu32*)(0x027FFB0C) = (vu32)2;
140+
dbg_printf("\n aligned read : \n");
179141
} else {
180-
//dbg_printf("\n misaligned read : \n");
181-
//*(vu32*)(0x027FFB0C) = (vu32)0;
142+
dbg_printf("\n misaligned read : \n");
182143
}
144+
#endif
145+
183146
*(vu32*)(0x027FFB14) = 0;
184147
}
185148
unlockMutex();
@@ -189,7 +152,9 @@ void runCardEngineCheck (void) {
189152
//---------------------------------------------------------------------------------
190153
void myIrqHandlerFIFO(void) {
191154
//---------------------------------------------------------------------------------
192-
//nocashMessage("myIrqHandlerFIFO");
155+
#ifdef DEBUG
156+
nocashMessage("myIrqHandlerFIFO");
157+
#endif
193158

194159
calledViaIPC = true;
195160

@@ -198,7 +163,9 @@ void myIrqHandlerFIFO(void) {
198163

199164

200165
void myIrqHandlerVBlank(void) {
201-
//nocashMessage("myIrqHandlerVBlank");
166+
#ifdef DEBUG
167+
nocashMessage("myIrqHandlerVBlank");
168+
#endif
202169

203170
calledViaIPC = false;
204171

@@ -208,12 +175,13 @@ void myIrqHandlerVBlank(void) {
208175
u32 myIrqEnable(u32 irq) {
209176
int oldIME = enterCriticalSection();
210177

211-
//nocashMessage("myIrqEnable\n");
178+
#ifdef DEBUG
179+
nocashMessage("myIrqEnable\n");
180+
#endif
212181

213182
u32 irq_before = REG_IE | IRQ_IPC_SYNC;
214183
irq |= IRQ_IPC_SYNC;
215184
REG_IPC_SYNC |= IPC_SYNC_IRQ_ENABLE;
216-
//nocashMessage("IRQ_IPC_SYNC enabled\n");
217185

218186
REG_IE |= irq;
219187
leaveCriticalSection(oldIME);
@@ -224,10 +192,14 @@ void irqIPCSYNCEnable() {
224192
if(!initializedIRQ) {
225193
int oldIME = enterCriticalSection();
226194
initLogging();
195+
#ifdef DEBUG
227196
dbg_printf("\nirqIPCSYNCEnable\n");
197+
#endif
228198
REG_IE |= IRQ_IPC_SYNC;
229199
REG_IPC_SYNC |= IPC_SYNC_IRQ_ENABLE;
200+
#ifdef DEBUG
230201
dbg_printf("IRQ_IPC_SYNC enabled\n");
202+
#endif
231203
leaveCriticalSection(oldIME);
232204
initializedIRQ = true;
233205
}
@@ -236,12 +208,15 @@ void irqIPCSYNCEnable() {
236208
// ARM7 Redirected function
237209

238210
bool eepromProtect (void) {
239-
dbg_printf("\narm7 eepromProtect\n");
211+
#ifdef DEBUG
212+
dbg_printf("\narm7 eepromProtect\n");
213+
#endif
240214

241215
return true;
242216
}
243217

244218
bool eepromRead (u32 src, void *dst, u32 len) {
219+
#ifdef DEBUG
245220
dbg_printf("\narm7 eepromRead\n");
246221

247222
dbg_printf("\nsrc : \n");
@@ -250,13 +225,15 @@ bool eepromRead (u32 src, void *dst, u32 len) {
250225
dbg_hexa((u32)dst);
251226
dbg_printf("\nlen : \n");
252227
dbg_hexa(len);
228+
#endif
253229

254230
fileRead(dst,savFile,src,len);
255231

256232
return true;
257233
}
258234

259235
bool eepromPageWrite (u32 dst, const void *src, u32 len) {
236+
#ifdef DEBUG
260237
dbg_printf("\narm7 eepromPageWrite\n");
261238

262239
dbg_printf("\nsrc : \n");
@@ -265,13 +242,15 @@ bool eepromPageWrite (u32 dst, const void *src, u32 len) {
265242
dbg_hexa(dst);
266243
dbg_printf("\nlen : \n");
267244
dbg_hexa(len);
245+
#endif
268246

269247
fileWrite(src,savFile,dst,len);
270248

271249
return true;
272250
}
273251

274252
bool eepromPageProg (u32 dst, const void *src, u32 len) {
253+
#ifdef DEBUG
275254
dbg_printf("\narm7 eepromPageProg\n");
276255

277256
dbg_printf("\nsrc : \n");
@@ -280,13 +259,15 @@ bool eepromPageProg (u32 dst, const void *src, u32 len) {
280259
dbg_hexa(dst);
281260
dbg_printf("\nlen : \n");
282261
dbg_hexa(len);
262+
#endif
283263

284264
fileWrite(src,savFile,dst,len);
285265

286266
return true;
287267
}
288268

289269
bool eepromPageVerify (u32 dst, const void *src, u32 len) {
270+
#ifdef DEBUG
290271
dbg_printf("\narm7 eepromPageVerify\n");
291272

292273
dbg_printf("\nsrc : \n");
@@ -295,24 +276,30 @@ bool eepromPageVerify (u32 dst, const void *src, u32 len) {
295276
dbg_hexa(dst);
296277
dbg_printf("\nlen : \n");
297278
dbg_hexa(len);
279+
#endif
298280

299281
//fileWrite(src,savFile,dst,len);
300282
return true;
301283
}
302284

303285
bool eepromPageErase (u32 dst) {
286+
#ifdef DEBUG
304287
dbg_printf("\narm7 eepromPageErase\n");
288+
#endif
305289

306290
return true;
307291
}
308292

309293
u32 cardId (void) {
294+
#ifdef DEBUG
310295
dbg_printf("\cardId\n");
296+
#endif
311297

312298
return 1;
313299
}
314300

315301
bool cardRead (u32 dma, u32 src, void *dst, u32 len) {
302+
#ifdef DEBUG
316303
dbg_printf("\narm7 cardRead\n");
317304

318305
dbg_printf("\ndma : \n");
@@ -323,6 +310,7 @@ bool cardRead (u32 dma, u32 src, void *dst, u32 len) {
323310
dbg_hexa((u32)dst);
324311
dbg_printf("\nlen : \n");
325312
dbg_hexa(len);
313+
#endif
326314

327315
fileRead(dst,romFile,src,len);
328316

0 commit comments

Comments
 (0)