Switch to enums for the options

This commit is contained in:
Aurora 2016-09-11 19:17:56 +02:00
parent 63160a22a6
commit da0adeb39e
9 changed files with 85 additions and 59 deletions

View File

@ -28,7 +28,7 @@ static void patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, i
static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags) static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags)
{ {
FS_Path filePath = {PATH_ASCII, strnlen(path, PATH_MAX) + 1, path}, FS_Path filePath = {PATH_ASCII, strnlen(path, 255) + 1, path},
archivePath = {PATH_EMPTY, 1, (u8 *)""}; archivePath = {PATH_EMPTY, 1, (u8 *)""};
return IFile_Open(file, archiveId, archivePath, filePath, flags); return IFile_Open(file, archiveId, archivePath, filePath, flags);
@ -342,7 +342,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
case 0x0004001000027000LL: // KOR MSET case 0x0004001000027000LL: // KOR MSET
case 0x0004001000028000LL: // TWN MSET case 0x0004001000028000LL: // TWN MSET
{ {
if(CONFIG_SHOWNAND) if(CONFIG(SHOWNAND))
{ {
static const u16 verPattern[] = u"Ver."; static const u16 verPattern[] = u"Ver.";
const u32 currentNand = BOOTCFG_NAND; const u32 currentNand = BOOTCFG_NAND;
@ -397,7 +397,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
sizeof(stopCartUpdatesPatch), 2 sizeof(stopCartUpdatesPatch), 2
); );
u32 cpuSetting = CONFIG_NEWCPU; u32 cpuSetting = MULTICONFIG(NEWCPU);
if(cpuSetting != 0) if(cpuSetting != 0)
{ {
@ -498,7 +498,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
#ifdef DEV #ifdef DEV
case 0x0004003000008A02LL: // ErrDisp case 0x0004003000008A02LL: // ErrDisp
{ {
if(CONFIG_DEVOPTIONS == 0) if(MULTICONFIG(DEVOPTIONS) == 0)
{ {
static const u8 unitinfoCheckPattern1[] = { static const u8 unitinfoCheckPattern1[] = {
0x14, 0x00, 0xD0, 0xE5, 0xDB 0x14, 0x00, 0xD0, 0xE5, 0xDB
@ -532,7 +532,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
#endif #endif
default: default:
if(CONFIG_USELANGEMUANDCODE) if(CONFIG(USELANGEMUANDCODE))
{ {
u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24; u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24;

View File

@ -2,21 +2,38 @@
#include <3ds/types.h> #include <3ds/types.h>
#define PATH_MAX 255
#define CONFIG(a) (((info.config >> (a + 21)) & 1) != 0) #define CONFIG(a) (((info.config >> (a + 21)) & 1) != 0)
#define MULTICONFIG(a) ((info.config >> (a * 2 + 7)) & 3) #define MULTICONFIG(a) ((info.config >> (a * 2 + 7)) & 3)
#define BOOTCONFIG(a, b) ((info.config >> a) & b) #define BOOTCONFIG(a, b) ((info.config >> a) & b)
#define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 1) #define BOOTCFG_FIRM BOOTCONFIG(3, 1)
#define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1) #define BOOTCFG_A9LH BOOTCONFIG(4, 1)
#define CONFIG_NEWCPU MULTICONFIG(3) #define BOOTCFG_NOFORCEFLAG BOOTCONFIG(5, 1)
#define CONFIG_USELANGEMUANDCODE CONFIG(2) #define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1)
#define CONFIG_SHOWNAND CONFIG(3)
enum multiOptions
{
DEFAULTEMU = 0,
BRIGHTNESS,
PIN,
NEWCPU
#ifdef DEV #ifdef DEV
#define CONFIG_DEVOPTIONS MULTICONFIG(4) , DEVOPTIONS
#endif #endif
};
enum singleOptions
{
AUTOBOOTSYS = 0,
USESYSFIRM,
USELANGEMUANDCODE,
SHOWNAND,
SHOWGBABOOT,
PAYLOADSPLASH
#ifdef DEV
, PATCHACCESS
#endif
};
void patchCode(u64 progId, u8 *code, u32 size); void patchCode(u64 progId, u8 *code, u32 size);

View File

@ -130,7 +130,7 @@ void configMenu(bool oldPinStatus)
//Display all the multiple choice options in white //Display all the multiple choice options in white
for(u32 i = 0; i < multiOptionsAmount; i++) for(u32 i = 0; i < multiOptionsAmount; i++)
{ {
if(!(i == CONFIG_NEWCPUINDEX && !isN3DS)) if(!(i == NEWCPU && !isN3DS))
{ {
multiOptions[i].posY = endPos + SPACING_Y; multiOptions[i].posY = endPos + SPACING_Y;
endPos = drawString(multiOptionsText[i], 10, multiOptions[i].posY, COLOR_WHITE); endPos = drawString(multiOptionsText[i], 10, multiOptions[i].posY, COLOR_WHITE);
@ -170,11 +170,11 @@ void configMenu(bool oldPinStatus)
{ {
case BUTTON_UP: case BUTTON_UP:
if(!selectedOption) selectedOption = totalIndexes; if(!selectedOption) selectedOption = totalIndexes;
else selectedOption = (selectedOption == CONFIG_NEWCPUINDEX + 1 && !isN3DS) ? selectedOption - 2 : selectedOption - 1; else selectedOption = (selectedOption == NEWCPU + 1 && !isN3DS) ? selectedOption - 2 : selectedOption - 1;
break; break;
case BUTTON_DOWN: case BUTTON_DOWN:
if(selectedOption == totalIndexes) selectedOption = 0; if(selectedOption == totalIndexes) selectedOption = 0;
else selectedOption = (selectedOption == CONFIG_NEWCPUINDEX - 1 && !isN3DS) ? selectedOption + 2 : selectedOption + 1; else selectedOption = (selectedOption == NEWCPU - 1 && !isN3DS) ? selectedOption + 2 : selectedOption + 1;
break; break;
case BUTTON_LEFT: case BUTTON_LEFT:
selectedOption = 0; selectedOption = 0;
@ -218,7 +218,7 @@ void configMenu(bool oldPinStatus)
drawCharacter(selected, 10 + multiOptions[selectedOption].posXs[oldEnabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_BLACK); drawCharacter(selected, 10 + multiOptions[selectedOption].posXs[oldEnabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_BLACK);
multiOptions[selectedOption].enabled = (oldEnabled == 3 || !multiOptions[selectedOption].posXs[oldEnabled + 1]) ? 0 : oldEnabled + 1; multiOptions[selectedOption].enabled = (oldEnabled == 3 || !multiOptions[selectedOption].posXs[oldEnabled + 1]) ? 0 : oldEnabled + 1;
if(selectedOption == CONFIG_BRIGHTNESSINDEX) updateBrightness(multiOptions[CONFIG_BRIGHTNESSINDEX].enabled); if(selectedOption == BRIGHTNESS) updateBrightness(multiOptions[BRIGHTNESS].enabled);
} }
else else
{ {
@ -238,7 +238,7 @@ void configMenu(bool oldPinStatus)
} }
} }
u32 oldPinLength = CONFIG_PIN; u32 oldPinLength = MULTICONFIG(PIN);
//Preserve the last-used boot options (last 12 bits) //Preserve the last-used boot options (last 12 bits)
configData.config &= 0x3F; configData.config &= 0x3F;
@ -249,7 +249,7 @@ void configMenu(bool oldPinStatus)
for(u32 i = 0; i < singleOptionsAmount; i++) for(u32 i = 0; i < singleOptionsAmount; i++)
configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 21); configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 21);
if(CONFIG_PIN != 0) newPin(oldPinStatus && CONFIG_PIN == oldPinLength); if(MULTICONFIG(PIN) != 0) newPin(oldPinStatus && MULTICONFIG(PIN) == oldPinLength);
else if(oldPinStatus) fileDelete(PIN_PATH); else if(oldPinStatus) fileDelete(PIN_PATH);
//Wait for the pressed buttons to change //Wait for the pressed buttons to change

View File

@ -32,26 +32,35 @@
#define CONFIG_VERSIONMAJOR 1 #define CONFIG_VERSIONMAJOR 1
#define CONFIG_VERSIONMINOR 3 #define CONFIG_VERSIONMINOR 3
#define CONFIG_BRIGHTNESSINDEX 1
#define CONFIG_NEWCPUINDEX 3
#define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_NAND BOOTCONFIG(0, 7)
#define BOOTCFG_FIRM BOOTCONFIG(3, 1) #define BOOTCFG_FIRM BOOTCONFIG(3, 1)
#define BOOTCFG_A9LH BOOTCONFIG(4, 1) #define BOOTCFG_A9LH BOOTCONFIG(4, 1)
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(5, 1) #define BOOTCFG_NOFORCEFLAG BOOTCONFIG(5, 1)
#define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1) #define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1)
#define CONFIG_DEFAULTEMU MULTICONFIG(0)
#define CONFIG_BRIGHTNESS MULTICONFIG(CONFIG_BRIGHTNESSINDEX)
#define CONFIG_PIN MULTICONFIG(2)
#define CONFIG_AUTOBOOTSYS CONFIG(0)
#define CONFIG_USESYSFIRM CONFIG(1)
#define CONFIG_SHOWGBABOOT CONFIG(4)
#define CONFIG_PAYLOADSPLASH CONFIG(5)
enum multiOptions
{
DEFAULTEMU = 0,
BRIGHTNESS,
PIN,
NEWCPU
#ifdef DEV #ifdef DEV
#define CONFIG_DEVOPTIONS MULTICONFIG(4) , DEVOPTIONS
#define CONFIG_PATCHACCESS CONFIG(6)
#endif #endif
};
enum singleOptions
{
AUTOBOOTSYS = 0,
USESYSFIRM,
USELANGEMUANDCODE,
SHOWNAND,
SHOWGBABOOT,
PAYLOADSPLASH
#ifdef DEV
, PATCHACCESS
#endif
};
typedef struct __attribute__((packed)) typedef struct __attribute__((packed))
{ {
@ -64,8 +73,8 @@ typedef struct __attribute__((packed))
typedef enum ConfigurationStatus typedef enum ConfigurationStatus
{ {
DONT_CONFIGURE = 0, DONT_CONFIGURE = 0,
MODIFY_CONFIGURATION = 1, MODIFY_CONFIGURATION,
CREATE_CONFIGURATION = 2 CREATE_CONFIGURATION
} ConfigurationStatus; } ConfigurationStatus;
extern CfgData configData; extern CfgData configData;

View File

@ -120,7 +120,7 @@ void main(void)
if(CFG_BOOTENV == 7) if(CFG_BOOTENV == 7)
{ {
nandType = FIRMWARE_SYSNAND; nandType = FIRMWARE_SYSNAND;
firmSource = CONFIG_USESYSFIRM ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM; firmSource = CONFIG(USESYSFIRM) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM;
needConfig = DONT_CONFIGURE; needConfig = DONT_CONFIGURE;
//Flag to prevent multiple boot options-forcing //Flag to prevent multiple boot options-forcing
@ -140,7 +140,7 @@ void main(void)
//Boot options aren't being forced //Boot options aren't being forced
if(needConfig != DONT_CONFIGURE) if(needConfig != DONT_CONFIGURE)
{ {
bool pinExists = CONFIG_PIN != 0 && verifyPin(); bool pinExists = MULTICONFIG(PIN) != 0 && verifyPin();
//If no configuration file exists or SELECT is held, load configuration menu //If no configuration file exists or SELECT is held, load configuration menu
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)); bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
@ -170,7 +170,7 @@ void main(void)
} }
else else
{ {
if(CONFIG_PAYLOADSPLASH && loadSplash()) pressed = HID_PAD; if(CONFIG(PAYLOADSPLASH) && loadSplash()) pressed = HID_PAD;
/* If L and R/A/Select or one of the single payload buttons are pressed, /* If L and R/A/Select or one of the single payload buttons are pressed,
chainload an external payload */ chainload an external payload */
@ -179,10 +179,10 @@ void main(void)
if(shouldLoadPayload) loadPayload(pressed); if(shouldLoadPayload) loadPayload(pressed);
if(!CONFIG_PAYLOADSPLASH) loadSplash(); if(!CONFIG(PAYLOADSPLASH)) loadSplash();
//Determine if the user chose to use the SysNAND FIRM as default for a R boot //Determine if the user chose to use the SysNAND FIRM as default for a R boot
bool useSysAsDefault = isA9lh ? CONFIG_USESYSFIRM : false; bool useSysAsDefault = isA9lh ? CONFIG(USESYSFIRM) : false;
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
if(pressed & BUTTON_R1) if(pressed & BUTTON_R1)
@ -195,7 +195,7 @@ void main(void)
with their own FIRM */ with their own FIRM */
else else
{ {
nandType = (CONFIG_AUTOBOOTSYS != !(pressed & BUTTON_L1)) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND; nandType = (CONFIG(AUTOBOOTSYS) != !(pressed & BUTTON_L1)) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND;
firmSource = nandType; firmSource = nandType;
} }
@ -215,7 +215,7 @@ void main(void)
nandType = FIRMWARE_EMUNAND4; nandType = FIRMWARE_EMUNAND4;
break; break;
default: default:
nandType = (FirmwareSource)(1 + CONFIG_DEFAULTEMU); nandType = (FirmwareSource)(1 + MULTICONFIG(DEFAULTEMU));
break; break;
} }
} }
@ -407,9 +407,9 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
#ifdef DEV #ifdef DEV
//Apply UNITINFO patch //Apply UNITINFO patch
if(CONFIG_DEVOPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[2].size); if(MULTICONFIG(DEVOPTIONS) == 1) patchUnitInfoValueSet(arm9Section, section[2].size);
if(isA9lh && CONFIG_DEVOPTIONS != 2) if(isA9lh && MULTICONFIG(DEVOPTIONS) != 2)
{ {
//Install ARM11 exception handlers //Install ARM11 exception handlers
u32 codeSetOffset; u32 codeSetOffset;
@ -428,7 +428,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
patchKernel11Panic(arm11Section1, section[1].size); patchKernel11Panic(arm11Section1, section[1].size);
} }
if(CONFIG_PATCHACCESS) if(CONFIG(PATCHACCESS))
{ {
patchArm11SvcAccessChecks(arm11SvcHandler); patchArm11SvcAccessChecks(arm11SvcHandler);
patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space); patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space);
@ -452,7 +452,7 @@ static inline void patchLegacyFirm(FirmwareType firmType)
#ifdef DEV #ifdef DEV
//Apply UNITINFO patch //Apply UNITINFO patch
if(CONFIG_DEVOPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[3].size); if(MULTICONFIG(DEVOPTIONS) == 1) patchUnitInfoValueSet(arm9Section, section[3].size);
#endif #endif
} }
@ -471,7 +471,7 @@ static inline void patch1x2xNativeAndSafeFirm(void)
else patchOldFirmWrites(arm9Section, section[2].size); else patchOldFirmWrites(arm9Section, section[2].size);
#ifdef DEV #ifdef DEV
if(CONFIG_DEVOPTIONS != 2) if(MULTICONFIG(DEVOPTIONS) != 2)
{ {
//Kernel9/Process9 debugging //Kernel9/Process9 debugging
patchArm9ExceptionHandlersInstall(arm9Section, section[2].size); patchArm9ExceptionHandlersInstall(arm9Section, section[2].size);

View File

@ -226,7 +226,7 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType)
/* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM /* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM
if the matching option was enabled (keep it as last) */ if the matching option was enabled (keep it as last) */
u32 numPatches = firmType == TWL_FIRM ? (sizeof(twlPatches) / sizeof(patchData)) : u32 numPatches = firmType == TWL_FIRM ? (sizeof(twlPatches) / sizeof(patchData)) :
(sizeof(agbPatches) / sizeof(patchData) - !CONFIG_SHOWGBABOOT); (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(SHOWGBABOOT));
const patchData *patches = firmType == TWL_FIRM ? twlPatches : agbPatches; const patchData *patches = firmType == TWL_FIRM ? twlPatches : agbPatches;
//Patch //Patch

View File

@ -55,7 +55,7 @@ void newPin(bool allowSkipping)
//Pad to AES block length with zeroes //Pad to AES block length with zeroes
u8 __attribute__((aligned(4))) enteredPassword[0x10] = {0}; u8 __attribute__((aligned(4))) enteredPassword[0x10] = {0};
u8 length = 4 + 2 * (CONFIG_PIN - 1), u8 length = 4 + 2 * (MULTICONFIG(PIN) - 1),
cnt = 0; cnt = 0;
int charDrawPos = 5 * SPACING_X; int charDrawPos = 5 * SPACING_X;
@ -112,7 +112,7 @@ bool verifyPin(void)
memcmp(pin.magic, "PINF", 4) != 0 || memcmp(pin.magic, "PINF", 4) != 0 ||
pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMajor != PIN_VERSIONMAJOR ||
pin.formatVersionMinor != PIN_VERSIONMINOR || pin.formatVersionMinor != PIN_VERSIONMINOR ||
pin.length != 4 + 2 * (CONFIG_PIN - 1)) pin.length != 4 + 2 * (MULTICONFIG(PIN) - 1))
return false; return false;
u8 __attribute__((aligned(4))) zeroes[0x10] = {0}; u8 __attribute__((aligned(4))) zeroes[0x10] = {0};

View File

@ -147,7 +147,7 @@ void initScreens(void)
//Disable interrupts //Disable interrupts
__asm(".word 0xF10C01C0"); __asm(".word 0xF10C01C0");
u32 brightnessLevel = brightness[CONFIG_BRIGHTNESS]; u32 brightnessLevel = brightness[MULTICONFIG(BRIGHTNESS)];
*(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10141200 = 0x1007F;
*(vu32 *)0x10202014 = 0x00000001; *(vu32 *)0x10202014 = 0x00000001;
@ -254,6 +254,6 @@ void initScreens(void)
else else
{ {
clearScreens(); clearScreens();
updateBrightness(CONFIG_BRIGHTNESS); updateBrightness(MULTICONFIG(BRIGHTNESS));
} }
} }

View File

@ -40,17 +40,17 @@ typedef volatile u64 vu64;
typedef enum FirmwareSource typedef enum FirmwareSource
{ {
FIRMWARE_SYSNAND = 0, FIRMWARE_SYSNAND = 0,
FIRMWARE_EMUNAND = 1, FIRMWARE_EMUNAND,
FIRMWARE_EMUNAND2 = 2, FIRMWARE_EMUNAND2,
FIRMWARE_EMUNAND3 = 3, FIRMWARE_EMUNAND3,
FIRMWARE_EMUNAND4 = 4 FIRMWARE_EMUNAND4
} FirmwareSource; } FirmwareSource;
typedef enum FirmwareType typedef enum FirmwareType
{ {
NATIVE_FIRM = 0, NATIVE_FIRM = 0,
TWL_FIRM = 1, TWL_FIRM,
AGB_FIRM = 2, AGB_FIRM,
SAFE_FIRM = 3, SAFE_FIRM,
NATIVE_FIRM1X2X = 4 NATIVE_FIRM1X2X
} FirmwareType; } FirmwareType;