diff --git a/source/firm.c b/source/firm.c index c484ffe..0d9d9bb 100755 --- a/source/firm.c +++ b/source/firm.c @@ -32,9 +32,8 @@ void main(void) updatedSys, needConfig, newConfig, - emuHeader; - - u64 chronoStarted = 0; + emuHeader, + chronoStarted = 0; //Detect the console being used console = PDN_MPCORE_CFG == 7; @@ -75,9 +74,9 @@ void main(void) //Zero the last booted FIRM flag CFG_BOOTENV = 0; - chronoStarted = chrono(); - while(chrono() - chronoStarted < 2 * TICKS_PER_SEC); //Wait for 2s chronoStarted = 1; + chrono(0); + chrono(2); //Update pressed buttons pressed = HID_PAD; @@ -152,7 +151,10 @@ void main(void) //If screens are inited or the corresponding option is set, load splash screen if((PDN_GPU_CNT != 1 || CONFIG(7)) && loadSplash()) - chronoStarted = chrono(); + { + chronoStarted = 2; + chrono(0); + } //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one if(pressed & BUTTON_R1) @@ -218,7 +220,7 @@ void main(void) if(chronoStarted) { - while(chronoStarted > 1 && chrono() - chronoStarted < 3 * TICKS_PER_SEC); + if(chronoStarted == 2) chrono(3); stopChrono(); } diff --git a/source/utils.c b/source/utils.c index 5d565c6..e62c8dc 100644 --- a/source/utils.c +++ b/source/utils.c @@ -40,7 +40,7 @@ void mcuReboot(void) } //TODO: add support for TIMER IRQ -static void startChrono(u64 initialTicks) +static inline void startChrono(u64 initialTicks) { //Based on a NATIVE_FIRM disassembly @@ -53,21 +53,22 @@ static void startChrono(u64 initialTicks) for(u32 i = 1; i < 4; i++) *(vu16 *)(0x10003002 + 4 * i) = 0x84; //Count-up; enabled } -u64 chrono(void) +void chrono(u32 seconds) { - static u32 chronoStarted = 0; + static u64 startingTicks = 0; - if(!chronoStarted) + if(!startingTicks) startChrono(0); + + u64 res; + + do { - startChrono(0); - chronoStarted++; + res = 0; + for(u32 i = 0; i < 4; i++) res |= *(vu16 *)(0x10003000 + 4 * i) << (16 * i); } + while(res - startingTicks < seconds * TICKS_PER_SEC); - u64 res = 0; - - for(u32 i = 0; i < 4; i++) res |= *(vu16 *)(0x10003000 + 4 * i) << (16 * i); - - return res; + if(!seconds) startingTicks = res; } void stopChrono(void) diff --git a/source/utils.h b/source/utils.h index b6c78ee..236b048 100644 --- a/source/utils.h +++ b/source/utils.h @@ -11,5 +11,5 @@ void mcuReboot(void); #define TICKS_PER_SEC 67027964ULL -u64 chrono(void); +void chrono(u32 seconds); void stopChrono(void); \ No newline at end of file