Small chrono function refactoring
This commit is contained in:
parent
ffee64c67f
commit
050f433046
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -11,5 +11,5 @@ void mcuReboot(void);
|
||||
|
||||
#define TICKS_PER_SEC 67027964ULL
|
||||
|
||||
u64 chrono(void);
|
||||
void chrono(u32 seconds);
|
||||
void stopChrono(void);
|
Reference in New Issue
Block a user