Make the code more readable by defining variables locally, avoid useless redefinitions, when rebooting from TWL and NATIVE_FIRM you can now override with just A (same as pressing nothing), L(+payload buttons) or R
This commit is contained in:
parent
441c143b3e
commit
de4fea77a1
@ -18,4 +18,5 @@
|
|||||||
#define BUTTON_START (1 << 3)
|
#define BUTTON_START (1 << 3)
|
||||||
#define BUTTON_SELECT (1 << 2)
|
#define BUTTON_SELECT (1 << 2)
|
||||||
#define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP)
|
#define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP)
|
||||||
|
#define OPTION_BUTTONS (BUTTON_R1 | BUTTON_L1 | BUTTON_A)
|
||||||
#define PAYLOAD_BUTTONS ((BUTTON_L1 | BUTTON_A) ^ 0xFFF)
|
#define PAYLOAD_BUTTONS ((BUTTON_L1 | BUTTON_A) ^ 0xFFF)
|
@ -28,12 +28,12 @@ static const char *patchedFirms[] = { "/aurei/patched_firmware_sys.bin",
|
|||||||
"/aurei/patched_firmware_em2.bin",
|
"/aurei/patched_firmware_em2.bin",
|
||||||
"/aurei/patched_firmware90.bin" };
|
"/aurei/patched_firmware90.bin" };
|
||||||
static u32 firmSize,
|
static u32 firmSize,
|
||||||
mode = 1,
|
console,
|
||||||
console = 1,
|
mode,
|
||||||
emuNAND = 0,
|
emuNAND,
|
||||||
a9lhSetup = 0,
|
a9lhSetup,
|
||||||
usePatchedFirm = 0,
|
selectedFirm,
|
||||||
selectedFirm = 0;
|
usePatchedFirm;
|
||||||
|
|
||||||
void setupCFW(void){
|
void setupCFW(void){
|
||||||
|
|
||||||
@ -42,17 +42,18 @@ void setupCFW(void){
|
|||||||
//Retrieve the last booted FIRM
|
//Retrieve the last booted FIRM
|
||||||
u8 previousFirm = CFG_BOOTENV;
|
u8 previousFirm = CFG_BOOTENV;
|
||||||
//Detect the console being used
|
//Detect the console being used
|
||||||
if(PDN_MPCORE_CFG == 1) console = 0;
|
console = (PDN_MPCORE_CFG == 1) ? 0 : 1;
|
||||||
//Get pressed buttons
|
//Get pressed buttons
|
||||||
u16 pressed = HID_PAD;
|
u16 pressed = HID_PAD;
|
||||||
u32 updatedSys = 0;
|
|
||||||
|
|
||||||
//Attempt to read the configuration file
|
//Attempt to read the configuration file
|
||||||
const char configPath[] = "aurei/config.bin";
|
const char configPath[] = "aurei/config.bin";
|
||||||
u16 config = 0;
|
u16 config = 0;
|
||||||
u32 needConfig = fileRead(&config, configPath, 2) ? 1 : 2;
|
u32 needConfig = fileRead(&config, configPath, 2) ? 1 : 2;
|
||||||
|
|
||||||
//Determine if A9LH is installed
|
//Determine if A9LH is installed and the user has an updated sysNAND
|
||||||
|
u32 updatedSys;
|
||||||
|
|
||||||
if(a9lhBoot || (config >> 2) & 0x1){
|
if(a9lhBoot || (config >> 2) & 0x1){
|
||||||
if(pressed == SAFE_MODE)
|
if(pressed == SAFE_MODE)
|
||||||
error("Using Safe Mode would brick you, or remove A9LH!");
|
error("Using Safe Mode would brick you, or remove A9LH!");
|
||||||
@ -60,17 +61,24 @@ void setupCFW(void){
|
|||||||
a9lhSetup = 1;
|
a9lhSetup = 1;
|
||||||
//Check setting for > 9.2 sysNAND
|
//Check setting for > 9.2 sysNAND
|
||||||
updatedSys = config & 0x1;
|
updatedSys = config & 0x1;
|
||||||
|
} else{
|
||||||
|
a9lhSetup = 0;
|
||||||
|
updatedSys = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Determine if the user chose to use pre-patched FIRMs
|
||||||
|
u32 usePatchedFirmSet = (config >> 1) & 0x1;
|
||||||
|
|
||||||
/* If booting with A9LH, it's a MCU reboot and a previous configuration exists,
|
/* If booting with A9LH, it's a MCU reboot and a previous configuration exists,
|
||||||
try to force boot options */
|
try to force boot options */
|
||||||
if(a9lhBoot && previousFirm && needConfig == 1){
|
if(a9lhBoot && previousFirm && needConfig == 1){
|
||||||
//Always force a sysNAND boot when quitting AGB_FIRM
|
//Always force a sysNAND boot when quitting AGB_FIRM
|
||||||
if(previousFirm == 0x7){
|
if(previousFirm == 0x7){
|
||||||
if(!updatedSys) mode = (config >> 8) & 0x1;
|
if(!updatedSys) mode = (config >> 8) & 0x1;
|
||||||
|
emuNAND = 0;
|
||||||
needConfig = 0;
|
needConfig = 0;
|
||||||
//Else, force the last used boot options unless A is pressed
|
//Else, force the last used boot options unless A, L or R are pressed
|
||||||
} else if(!(pressed & BUTTON_A)){
|
} else if(!(pressed & OPTION_BUTTONS)){
|
||||||
mode = (config >> 8) & 0x1;
|
mode = (config >> 8) & 0x1;
|
||||||
emuNAND = (config >> 9) & 0x1;
|
emuNAND = (config >> 9) & 0x1;
|
||||||
needConfig = 0;
|
needConfig = 0;
|
||||||
@ -92,21 +100,20 @@ void setupCFW(void){
|
|||||||
if(PDN_GPU_CNT != 0x1) loadSplash();
|
if(PDN_GPU_CNT != 0x1) loadSplash();
|
||||||
|
|
||||||
/* If L is pressed, boot 9.0 FIRM */
|
/* If L is pressed, boot 9.0 FIRM */
|
||||||
if(pressed & BUTTON_L1) mode = 0;
|
mode = (pressed & BUTTON_L1) ? 0 : 1;
|
||||||
|
|
||||||
/* If L or R aren't pressed on a 9.0/9.2 sysNAND, or the 9.0 FIRM is selected
|
/* If L or R aren't pressed on a 9.0/9.2 sysNAND, or the 9.0 FIRM is selected
|
||||||
or R is pressed on a > 9.2 sysNAND, boot emuNAND */
|
or R is pressed on a > 9.2 sysNAND, boot emuNAND */
|
||||||
if((updatedSys && (!mode || (pressed & BUTTON_R1))) ||
|
if((updatedSys && (!mode || (pressed & BUTTON_R1))) ||
|
||||||
(!updatedSys && mode && !(pressed & BUTTON_R1))){
|
(!updatedSys && mode && !(pressed & BUTTON_R1))){
|
||||||
//If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND
|
//If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND
|
||||||
if(mode && (pressed & BUTTON_B)) emuNAND = 2;
|
emuNAND = (mode && (pressed & BUTTON_B)) ? 2 : 1;
|
||||||
else emuNAND = 1;
|
} else emuNAND = 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
||||||
and "Use pre-patched FIRMs" is set, delete all patched FIRMs */
|
and "Use pre-patched FIRMs" is set, delete all patched FIRMs */
|
||||||
u16 bootConfig = (PATCH_VER << 11) | (a9lhSetup << 10);
|
u16 bootConfig = (PATCH_VER << 11) | (a9lhSetup << 10);
|
||||||
if ((config >> 1) & 0x1 && bootConfig != (config & 0xFC00))
|
if(usePatchedFirmSet && bootConfig != (config & 0xFC00))
|
||||||
deleteFirms(patchedFirms, sizeof(patchedFirms) / sizeof(char *));
|
deleteFirms(patchedFirms, sizeof(patchedFirms) / sizeof(char *));
|
||||||
|
|
||||||
//We also need to remember the used boot mode on A9LH
|
//We also need to remember the used boot mode on A9LH
|
||||||
@ -120,14 +127,12 @@ void setupCFW(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode) selectedFirm = emuNAND ? (emuNAND == 1 ? 2 : 3) : 1;
|
//Determine which patched FIRM we need to write or attempt to use (if any)
|
||||||
|
selectedFirm = mode ? (emuNAND ? (emuNAND == 1 ? 2 : 3) : 1) :
|
||||||
|
(usePatchedFirmSet ? 4 : 0);
|
||||||
|
|
||||||
//Skip decrypting and patching FIRM
|
//Determine if we need to use a pre-patched FIRM
|
||||||
if((config >> 1) & 0x1){
|
usePatchedFirm = (usePatchedFirmSet && fileExists(patchedFirms[selectedFirm - 1])) ? 1 : 0;
|
||||||
//Only needed with this setting
|
|
||||||
if(!mode) selectedFirm = 4;
|
|
||||||
if(fileExists(patchedFirms[selectedFirm - 1])) usePatchedFirm = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load FIRM into FCRAM
|
//Load FIRM into FCRAM
|
||||||
|
@ -27,7 +27,7 @@ struct options {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static u16 waitInput(void){
|
static u16 waitInput(void){
|
||||||
u32 pressedkey = 0;
|
u32 pressedKey = 0;
|
||||||
u16 key;
|
u16 key;
|
||||||
|
|
||||||
//Wait for no keys to be pressed
|
//Wait for no keys to be pressed
|
||||||
@ -40,11 +40,10 @@ static u16 waitInput(void){
|
|||||||
|
|
||||||
//Make sure it's pressed
|
//Make sure it's pressed
|
||||||
for(u32 i = 0x13000; i; i--){
|
for(u32 i = 0x13000; i; i--){
|
||||||
if (key != HID_PAD)
|
if(key != HID_PAD) break;
|
||||||
break;
|
if(i == 1) pressedKey = 1;
|
||||||
if(i == 1) pressedkey = 1;
|
|
||||||
}
|
}
|
||||||
} while(!pressedkey);
|
} while(!pressedKey);
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user