Skip to content

Commit ef7b9a0

Browse files
committed
After saving, wait 1 second before being able to exit out of nds-bootstrap
1 parent 107c45d commit ef7b9a0

1 file changed

Lines changed: 86 additions & 78 deletions

File tree

cardengine/arm7/source/cardengine.c

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static aFile* romFile = (aFile*)ROM_FILE_LOCATION;
7070
static aFile* savFile = (aFile*)SAV_FILE_LOCATION;
7171

7272
static int cardReadTimeOut = 0;
73+
static int saveTimer = 0;
7374

7475
static int softResetTimer = 0;
7576
static int volumeAdjustDelay = 0;
@@ -78,7 +79,6 @@ static bool volumeAdjustActivated = false;
7879
//static bool ndmaUsed = false;
7980

8081
static int cardEgnineCommandMutex = 0;
81-
static int saveMutex = 0;
8282

8383
static const tNDSHeader* ndsHeader = NULL;
8484
static const char* romLocation = NULL;
@@ -133,63 +133,67 @@ static void initialize(void) {
133133
}
134134

135135
static void cardReadLED(bool on) {
136-
if (on) {
137-
switch(romread_LED) {
138-
case 0:
139-
default:
140-
break;
141-
case 1:
142-
i2cWriteRegister(0x4A, 0x30, 0x13); // Turn WiFi LED on
143-
break;
144-
case 2:
145-
i2cWriteRegister(0x4A, 0x63, 0xFF); // Turn power LED purple
146-
break;
147-
case 3:
148-
i2cWriteRegister(0x4A, 0x31, 0x01); // Turn Camera LED on
149-
break;
150-
}
151-
} else {
152-
switch(romread_LED) {
153-
case 0:
154-
default:
155-
break;
156-
case 1:
157-
i2cWriteRegister(0x4A, 0x30, 0x12); // Turn WiFi LED off
158-
break;
159-
case 2:
160-
i2cWriteRegister(0x4A, 0x63, 0x00); // Revert power LED to normal
161-
break;
162-
case 3:
163-
i2cWriteRegister(0x4A, 0x31, 0x00); // Turn Camera LED off
164-
break;
136+
if (consoleModel < 2) {
137+
if (on) {
138+
switch(romread_LED) {
139+
case 0:
140+
default:
141+
break;
142+
case 1:
143+
i2cWriteRegister(0x4A, 0x30, 0x13); // Turn WiFi LED on
144+
break;
145+
case 2:
146+
i2cWriteRegister(0x4A, 0x63, 0xFF); // Turn power LED purple
147+
break;
148+
case 3:
149+
i2cWriteRegister(0x4A, 0x31, 0x01); // Turn Camera LED on
150+
break;
151+
}
152+
} else {
153+
switch(romread_LED) {
154+
case 0:
155+
default:
156+
break;
157+
case 1:
158+
i2cWriteRegister(0x4A, 0x30, 0x12); // Turn WiFi LED off
159+
break;
160+
case 2:
161+
i2cWriteRegister(0x4A, 0x63, 0x00); // Revert power LED to normal
162+
break;
163+
case 3:
164+
i2cWriteRegister(0x4A, 0x31, 0x00); // Turn Camera LED off
165+
break;
166+
}
165167
}
166168
}
167169
}
168170

169171
static void asyncCardReadLED(bool on) {
170-
if (on) {
171-
switch(romread_LED) {
172-
case 0:
173-
default:
174-
break;
175-
case 1:
176-
i2cWriteRegister(0x4A, 0x63, 0xFF); // Turn power LED purple
177-
break;
178-
case 2:
179-
i2cWriteRegister(0x4A, 0x30, 0x13); // Turn WiFi LED on
180-
break;
181-
}
182-
} else {
183-
switch(romread_LED) {
184-
case 0:
185-
default:
186-
break;
187-
case 1:
188-
i2cWriteRegister(0x4A, 0x63, 0x00); // Revert power LED to normal
189-
break;
190-
case 2:
191-
i2cWriteRegister(0x4A, 0x30, 0x12); // Turn WiFi LED off
192-
break;
172+
if (consoleModel < 2) {
173+
if (on) {
174+
switch(romread_LED) {
175+
case 0:
176+
default:
177+
break;
178+
case 1:
179+
i2cWriteRegister(0x4A, 0x63, 0xFF); // Turn power LED purple
180+
break;
181+
case 2:
182+
i2cWriteRegister(0x4A, 0x30, 0x13); // Turn WiFi LED on
183+
break;
184+
}
185+
} else {
186+
switch(romread_LED) {
187+
case 0:
188+
default:
189+
break;
190+
case 1:
191+
i2cWriteRegister(0x4A, 0x63, 0x00); // Revert power LED to normal
192+
break;
193+
case 2:
194+
i2cWriteRegister(0x4A, 0x30, 0x12); // Turn WiFi LED off
195+
break;
196+
}
193197
}
194198
}
195199
}
@@ -428,23 +432,21 @@ void myIrqHandlerVBlank(void) {
428432
softResetTimer = 0;
429433
} else {
430434
if (softResetTimer == 60 * 2) {
431-
if (lockMutex(&saveMutex)) {
435+
if (saveTimer == 0) {
432436
memcpy((u32*)0x02000300, sr_data_srloader, 0x020);
433437
i2cWriteRegister(0x4A, 0x70, 0x01);
434438
i2cWriteRegister(0x4A, 0x11, 0x01); // Reboot into DSiMenu++
435-
unlockMutex(&saveMutex);
436439
}
437440
}
438441
softResetTimer++;
439442
}
440443

441444
if (REG_KEYINPUT & (KEY_L | KEY_R | KEY_START | KEY_SELECT)) {
442445
} else if (!gameSoftReset) {
443-
if (lockMutex(&saveMutex)) {
446+
if (saveTimer == 0) {
444447
memcpy((u32*)0x02000300, dsiMode ? sr_data_srllastran_twltouch : sr_data_srllastran, 0x020); // SDK 5
445448
i2cWriteRegister(0x4A, 0x70, 0x01);
446449
i2cWriteRegister(0x4A, 0x11, 0x01); // Reboot game
447-
unlockMutex(&saveMutex);
448450
}
449451
}
450452

@@ -648,6 +650,14 @@ void myIrqHandlerVBlank(void) {
648650
}
649651
}
650652
}
653+
654+
if (saveTimer > 0) {
655+
saveTimer++;
656+
if (saveTimer == 60) {
657+
i2cWriteRegister(0x4A, 0x12, 0x00); // If saved, power button works again.
658+
saveTimer = 0;
659+
}
660+
}
651661

652662
#ifdef DEBUG
653663
nocashMessage("cheat_engine_start\n");
@@ -715,10 +725,9 @@ bool eepromRead(u32 src, void *dst, u32 len) {
715725

716726
if (!ROMinRAM && saveSize > 0 && saveSize <= 0x00100000) {
717727
memcpy(dst, saveLocation + src, len);
718-
} else if (lockMutex(&saveMutex)) {
728+
} else {
719729
initialize();
720730
fileRead(dst, *savFile, src, len, -1);
721-
unlockMutex(&saveMutex);
722731
}
723732
return true;
724733
}
@@ -735,16 +744,16 @@ bool eepromPageWrite(u32 dst, const void *src, u32 len) {
735744
dbg_hexa(len);
736745
#endif
737746

738-
if (lockMutex(&saveMutex)) {
739-
initialize();
747+
initialize();
748+
if (saveTimer == 0) {
740749
i2cWriteRegister(0x4A, 0x12, 0x01); // When we're saving, power button does nothing, in order to prevent corruption.
741-
if (!ROMinRAM && saveSize > 0 && saveSize <= 0x00100000) {
742-
memcpy(saveLocation + dst, src, len);
743-
}
744-
fileWrite(src, *savFile, dst, len, -1);
745-
i2cWriteRegister(0x4A, 0x12, 0x00); // If saved, power button works again.
746-
unlockMutex(&saveMutex);
747750
}
751+
saveTimer = 1;
752+
if (!ROMinRAM && saveSize > 0 && saveSize <= 0x00100000) {
753+
memcpy(saveLocation + dst, src, len);
754+
}
755+
fileWrite(src, *savFile, dst, len, -1);
756+
748757
return true;
749758
}
750759

@@ -760,16 +769,16 @@ bool eepromPageProg(u32 dst, const void *src, u32 len) {
760769
dbg_hexa(len);
761770
#endif
762771

763-
if (lockMutex(&saveMutex)) {
764-
initialize();
765-
i2cWriteRegister(0x4A, 0x12, 0x01); // When we're saving, power button does nothing, in order to prevent corruption.
766-
if (!ROMinRAM && saveSize > 0 && saveSize <= 0x00100000) {
767-
memcpy(saveLocation + dst, src, len);
768-
}
769-
fileWrite(src, *savFile, dst, len, -1);
770-
i2cWriteRegister(0x4A, 0x12, 0x00); // If saved, power button works again.
771-
unlockMutex(&saveMutex);
772+
initialize();
773+
if (saveTimer == 0) {
774+
i2cWriteRegister(0x4A, 0x12, 0x01); // When we're saving, power button does nothing, in order to prevent corruption.
775+
}
776+
saveTimer = 1;
777+
if (!ROMinRAM && saveSize > 0 && saveSize <= 0x00100000) {
778+
memcpy(saveLocation + dst, src, len);
772779
}
780+
fileWrite(src, *savFile, dst, len, -1);
781+
773782
return true;
774783
}
775784

@@ -824,7 +833,7 @@ bool cardRead(u32 dma, u32 src, void *dst, u32 len) {
824833

825834
if (ROMinRAM) {
826835
memcpy(dst, romLocation + src, len);
827-
} else if (lockMutex(&saveMutex)) {
836+
} else {
828837
initialize();
829838
cardReadLED(true); // When a file is loading, turn on LED for card read indicator
830839
//ndmaUsed = false;
@@ -834,7 +843,6 @@ bool cardRead(u32 dma, u32 src, void *dst, u32 len) {
834843
fileRead(dst, *romFile, src, len, 2);
835844
//ndmaUsed = true;
836845
cardReadLED(false); // After loading is done, turn off LED for card read indicator
837-
unlockMutex(&saveMutex);
838846
}
839847

840848
return true;

0 commit comments

Comments
 (0)