mirror of
https://github.com/rvtr/TDT.git
synced 2025-10-31 13:51:07 -04:00
Fix FAT mismatch if exited by holding POWER
This commit is contained in:
parent
342c9b4b3b
commit
040ddd6db3
@ -27,11 +27,12 @@
|
||||
distribution.
|
||||
|
||||
---------------------------------------------------------------------------------*/
|
||||
#include <nds.h>
|
||||
#include "my_sdmmc.h"
|
||||
|
||||
//#include <dswifi7.h>
|
||||
//#include <maxmod7.h>
|
||||
#include "string.h"
|
||||
#include "my_sdmmc.h"
|
||||
#include <nds.h>
|
||||
#include <string.h>
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void VblankHandler(void) {
|
||||
@ -47,11 +48,24 @@ void VcountHandler() {
|
||||
}
|
||||
|
||||
volatile bool exitflag = false;
|
||||
volatile bool reboot = false;
|
||||
|
||||
// https://github.com/devkitPro/libnds/blob/154a21cc3d57716f773ff2b10f815511c1b8ba9f/source/common/interrupts.c#L51-L69
|
||||
//---------------------------------------------------------------------------------
|
||||
void powerButtonCB() {
|
||||
TWL_CODE void i2cIRQHandlerCustom() {
|
||||
//---------------------------------------------------------------------------------
|
||||
exitflag = true;
|
||||
int cause = (i2cReadRegister(I2C_PM, I2CREGPM_PWRIF) & 0x3) | (i2cReadRegister(I2C_GPIO, 0x02)<<2);
|
||||
|
||||
switch (cause & 3) {
|
||||
case 1:
|
||||
reboot = true;
|
||||
exitflag = true;
|
||||
break;
|
||||
case 2:
|
||||
reboot = false;
|
||||
exitflag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void set_ctr(u32* ctr){
|
||||
@ -96,6 +110,7 @@ int main() {
|
||||
ledBlink(0);
|
||||
|
||||
irqInit();
|
||||
irqSetAUX(IRQ_I2C, i2cIRQHandlerCustom);
|
||||
// Start the RTC tracking IRQ
|
||||
initClockIRQ();
|
||||
fifoInit();
|
||||
@ -159,8 +174,6 @@ int main() {
|
||||
|
||||
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
|
||||
|
||||
setPowerButtonCB(powerButtonCB);
|
||||
|
||||
// Keep the ARM7 mostly idle
|
||||
while (!exitflag) {
|
||||
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
|
||||
@ -174,5 +187,12 @@ int main() {
|
||||
fifoWaitValue32(FIFO_USER_02);
|
||||
fifoCheckValue32(FIFO_USER_02);
|
||||
|
||||
if (reboot) {
|
||||
i2cWriteRegister(I2C_PM, I2CREGPM_RESETFLAG, 1);
|
||||
i2cWriteRegister(I2C_PM, I2CREGPM_PWRCNT, 1);
|
||||
} else {
|
||||
writePowerManagement(PM_CONTROL_REG,PM_SYSTEM_PWR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
bool programEnd = false;
|
||||
bool sdnandMode = true;
|
||||
bool arm7Exiting = false;
|
||||
|
||||
PrintConsole topScreen;
|
||||
PrintConsole bottomScreen;
|
||||
@ -51,7 +52,6 @@ static int _mainMenu(int cursor)
|
||||
iprintf("\tTitle Manager for HiyaCFW\n");
|
||||
iprintf("\nversion %s\n", VERSION);
|
||||
iprintf("\n\n\x1B[41mWARNING:\x1B[47m This tool can write to\nyour internal NAND!\n\nThis always has a risk, albeit\nlow, of \x1B[41mbricking\x1B[47m your system\nand should be done with caution!\n");
|
||||
iprintf("\nDo not exit by holding POWER,\ntap it or choose \"Shut Down\".\n");
|
||||
iprintf("\x1b[22;0HJeff - 2018-2019");
|
||||
iprintf("\x1b[23;0HPk11 - 2022");
|
||||
|
||||
@ -95,7 +95,10 @@ static int _mainMenu(int cursor)
|
||||
void fifoHandler(u32 value32, void* userdata)
|
||||
{
|
||||
if (value32 == 0x54495845) // 'EXIT'
|
||||
{
|
||||
programEnd = true;
|
||||
arm7Exiting = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -138,7 +141,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
messageBox("\x1B[41mWARNING:\x1B[47m This tool can write to\nyour internal NAND!\n\nThis always has a risk, albeit\nlow, of \x1B[41mbricking\x1B[47m your system\nand should be done with caution!");
|
||||
messageBox("Do not exit by holding POWER,\ntap it or choose \"Shut Down\".");
|
||||
|
||||
//main menu
|
||||
int cursor = 0;
|
||||
@ -194,6 +196,9 @@ int main(int argc, char **argv)
|
||||
|
||||
fifoSendValue32(FIFO_USER_02, 0x54495845); // 'EXIT'
|
||||
|
||||
while (arm7Exiting)
|
||||
swiWaitForVBlank();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user