Skip to content

Commit 5ffa2c2

Browse files
committed
Fix NAND save R/W issues
1 parent 9cfb5ee commit 5ffa2c2

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

retail/cardenginei/arm7/source/cardengine.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ static void log_arm9(void) {
11571157
}
11581158
#endif
11591159

1160-
static bool nandRead(void) {
1160+
static void nandRead(void) {
11611161
u32 flash = *(vu32*)(sharedAddr+2);
11621162
u32 memory = *(vu32*)(sharedAddr);
11631163
u32 len = *(vu32*)(sharedAddr+1);
@@ -1181,11 +1181,13 @@ static bool nandRead(void) {
11811181

11821182
//driveInitialize();
11831183
//cardReadLED(true, true); // When a file is loading, turn on LED for card read indicator
1184-
return fileRead((char *)memory, savFile, flash, len);
1184+
sdmmc_set_ndma_slot(4);
1185+
fileRead((char *)memory, savFile, flash, len);
1186+
sdmmc_set_ndma_slot(0);
11851187
//cardReadLED(false, true);
11861188
}
11871189

1188-
static bool nandWrite(void) {
1190+
static void nandWrite(void) {
11891191
u32 flash = *(vu32*)(sharedAddr+2);
11901192
u32 memory = *(vu32*)(sharedAddr);
11911193
u32 len = *(vu32*)(sharedAddr+1);
@@ -1210,7 +1212,9 @@ static bool nandWrite(void) {
12101212
//driveInitialize();
12111213
saveTimer = 1; // When we're saving, power button does nothing, in order to prevent corruption.
12121214
//cardReadLED(true, true); // When a file is loading, turn on LED for card read indicator
1213-
return fileWrite((char *)memory, savFile, flash, len);
1215+
sdmmc_set_ndma_slot(4);
1216+
fileWrite((char *)memory, savFile, flash, len);
1217+
sdmmc_set_ndma_slot(0);
12141218
//cardReadLED(false, true);
12151219
}
12161220

@@ -1462,17 +1466,17 @@ void runCardEngineCheck(void) {
14621466
log_arm9();
14631467
sharedAddr[3] = 0;
14641468
//IPC_SendSync(0x8);
1465-
}
1469+
} else
14661470
#endif
14671471

14681472
if (sharedAddr[3] == (vu32)0x025FFC01) {
14691473
//dmaLed = (sharedAddr[3] == (vu32)0x025FFC01);
1470-
sharedAddr[3] = nandRead();
1471-
}
1472-
1473-
if (sharedAddr[3] == (vu32)0x025FFC02) {
1474+
nandRead();
1475+
sharedAddr[3] = 0;
1476+
} else if (sharedAddr[3] == (vu32)0x025FFC02) {
14741477
//dmaLed = (sharedAddr[3] == (vu32)0x025FFC02);
1475-
sharedAddr[3] = nandWrite();
1478+
nandWrite();
1479+
sharedAddr[3] = 0;
14761480
}
14771481

14781482
/*if (sharedAddr[3] == (vu32)0x025FBC01) {

retail/cardenginei/arm9/source/cardengine.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ extern void setExceptionHandler2();
360360
static inline void waitForArm7(void) {
361361
// IPC_SendSync(0x4);
362362
while (sharedAddr[3] != (vu32)0) {
363-
swiDelay(100);
363+
#ifdef DLDI
364+
swiDelay(50);
365+
#else
366+
sleepMs(1);
367+
#endif
364368
}
365369
}
366370

@@ -496,9 +500,7 @@ static inline void cardReadNormal(u8* dst, u32 src, u32 len) {
496500
sharedAddr[2] = ((ce9->valueBits & overlaysCached) && src >= newOverlayOffset && src < newOverlayOffset+newOverlaysSize) ? sector+0x80000000 : sector;
497501
sharedAddr[3] = commandRead;
498502

499-
while (sharedAddr[3] == commandRead) {
500-
sleepMs(1);
501-
}
503+
waitForArm7();
502504

503505
#ifdef ASYNCPF
504506
updateDescriptor(slot, sector);
@@ -861,8 +863,10 @@ bool nandRead(void* memory,void* flash,u32 len,u32 dma) {
861863
return true;
862864
}
863865
#endif
866+
DC_InvalidateRange(memory, len);
867+
864868
// Send a command to the ARM7 to read the nand save
865-
u32 commandNandRead = 0x025FFC01;
869+
const u32 commandNandRead = 0x025FFC01;
866870

867871
// Write the command
868872
sharedAddr[0] = (u32)memory;
@@ -881,8 +885,10 @@ bool nandWrite(void* memory,void* flash,u32 len,u32 dma) {
881885
return true;
882886
}
883887
#endif
888+
DC_FlushRange(memory, len);
889+
884890
// Send a command to the ARM7 to write the nand save
885-
u32 commandNandWrite = 0x025FFC02;
891+
const u32 commandNandWrite = 0x025FFC02;
886892

887893
// Write the command
888894
sharedAddr[0] = (u32)memory;
File renamed without changes.

0 commit comments

Comments
 (0)