2016-03-23 02:27:53 +01:00
|
|
|
/*
|
2016-03-23 03:45:32 +01:00
|
|
|
* utils.c
|
2016-03-23 02:27:53 +01:00
|
|
|
* by Aurora Wright
|
|
|
|
* Copyright (c) 2016 All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
2016-03-23 03:45:32 +01:00
|
|
|
#include "utils.h"
|
|
|
|
#include "screeninit.h"
|
2016-03-23 02:27:53 +01:00
|
|
|
#include "draw.h"
|
|
|
|
#include "fs.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "buttons.h"
|
|
|
|
|
|
|
|
#define COLOR_TITLE 0xFF9900
|
2016-03-23 03:45:32 +01:00
|
|
|
#define COLOR_WHITE 0xFFFFFF
|
|
|
|
#define COLOR_RED 0x0000FF
|
2016-03-23 02:27:53 +01:00
|
|
|
#define COLOR_BLACK 0x000000
|
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
struct option {
|
|
|
|
int posY;
|
|
|
|
u32 enabled;
|
2016-03-23 02:27:53 +01:00
|
|
|
};
|
|
|
|
|
2016-04-02 22:02:08 +02:00
|
|
|
static u32 waitInput(void)
|
2016-04-02 17:58:06 +02:00
|
|
|
{
|
2016-03-27 16:26:09 +02:00
|
|
|
u32 pressedKey = 0;
|
2016-04-02 22:02:08 +02:00
|
|
|
u32 key;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
|
|
|
//Wait for no keys to be pressed
|
|
|
|
while(HID_PAD);
|
|
|
|
|
|
|
|
do {
|
|
|
|
//Wait for a key to be pressed
|
|
|
|
while(!HID_PAD);
|
|
|
|
key = HID_PAD;
|
|
|
|
|
|
|
|
//Make sure it's pressed
|
2016-04-02 17:58:06 +02:00
|
|
|
for(u32 i = 0x13000; i; i--)
|
|
|
|
{
|
2016-03-27 16:26:09 +02:00
|
|
|
if(key != HID_PAD) break;
|
|
|
|
if(i == 1) pressedKey = 1;
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
2016-04-02 18:48:31 +02:00
|
|
|
}
|
|
|
|
while(!pressedKey);
|
2016-03-23 02:27:53 +01:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2016-04-04 01:08:42 +02:00
|
|
|
void configureCFW(const char *configPath, const char *patchedFirms[])
|
2016-04-02 17:58:06 +02:00
|
|
|
{
|
2016-03-23 16:10:26 +01:00
|
|
|
initScreens();
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-03-27 18:39:16 +02:00
|
|
|
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
|
2016-03-23 03:45:32 +01:00
|
|
|
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
const char *optionsText[] = { "( ) Updated SysNAND mode (A9LH-only)",
|
|
|
|
"( ) Use pre-patched FIRMs",
|
|
|
|
"( ) Force A9LH detection",
|
|
|
|
"( ) Use 9.0 FIRM as default",
|
|
|
|
"( ) Use second EmuNAND as default",
|
2016-04-04 01:08:42 +02:00
|
|
|
"( ) Show current NAND in System Settings",
|
|
|
|
"( ) Show splash screen in patched AGB_FIRM" };
|
2016-03-29 17:43:53 +02:00
|
|
|
|
|
|
|
u32 optionsAmount = sizeof(optionsText) / sizeof(char *);
|
|
|
|
struct option options[optionsAmount];
|
|
|
|
|
2016-03-23 02:27:53 +01:00
|
|
|
//Read and parse the existing configuration
|
2016-03-29 17:43:53 +02:00
|
|
|
u32 tempConfig = 0;
|
|
|
|
fileRead(&tempConfig, configPath, 3);
|
2016-04-02 17:58:06 +02:00
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
for(u32 i = 0; i < optionsAmount; i++)
|
2016-03-31 01:38:28 +02:00
|
|
|
options[i].enabled = (tempConfig >> i) & 1;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
|
|
|
//Pre-select the first configuration option
|
2016-03-29 17:43:53 +02:00
|
|
|
u32 selectedOption = 0;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
|
|
|
//Boring configuration menu
|
2016-04-02 17:58:06 +02:00
|
|
|
while(1)
|
|
|
|
{
|
2016-03-23 02:27:53 +01:00
|
|
|
u16 pressed = 0;
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
do {
|
|
|
|
for(u32 i = 0; i < optionsAmount; i++)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
options[i].posY = drawString(optionsText[i], 10, !i ? 60 : options[i - 1].posY + SPACING_Y, selectedOption == i ? COLOR_RED : COLOR_WHITE);
|
|
|
|
drawCharacter('x', 10 + SPACING_X, options[i].posY, options[i].enabled ? (selectedOption == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
2016-04-02 17:58:06 +02:00
|
|
|
|
2016-03-23 02:27:53 +01:00
|
|
|
pressed = waitInput();
|
2016-04-02 18:48:31 +02:00
|
|
|
}
|
|
|
|
while(!(pressed & MENU_BUTTONS));
|
2016-03-29 17:43:53 +02:00
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
switch(pressed)
|
|
|
|
{
|
2016-03-29 17:43:53 +02:00
|
|
|
case BUTTON_UP:
|
|
|
|
selectedOption = !selectedOption ? optionsAmount - 1 : selectedOption - 1;
|
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
selectedOption = selectedOption == optionsAmount - 1 ? 0 : selectedOption + 1;
|
|
|
|
break;
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
selectedOption = 0;
|
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
selectedOption = optionsAmount - 1;
|
|
|
|
break;
|
|
|
|
case BUTTON_A:
|
|
|
|
options[selectedOption].enabled = !options[selectedOption].enabled;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
if(pressed == BUTTON_START) break;
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
//If the user has been using A9LH and the "Updated SysNAND" setting changed, delete the patched 9.0 FIRM
|
2016-04-04 01:08:42 +02:00
|
|
|
if(((tempConfig >> 16) & 1) && ((tempConfig & 1) != options[0].enabled)) fileDelete(patchedFirms[3]);
|
|
|
|
|
|
|
|
//If the "Show splash screen in patched AGB_FIRM" setting changed, delete the patched AGB_FIRM
|
|
|
|
if(((tempConfig >> 6) & 1) != options[6].enabled) fileDelete(patchedFirms[5]);
|
2016-03-29 17:43:53 +02:00
|
|
|
|
|
|
|
//Preserve the last-used boot options (last 12 bits)
|
|
|
|
tempConfig &= 0xFFF000;
|
2016-03-23 02:27:53 +01:00
|
|
|
|
|
|
|
//Parse and write the selected options
|
2016-03-29 17:43:53 +02:00
|
|
|
for(u32 i = 0; i < optionsAmount; i++)
|
|
|
|
tempConfig |= options[i].enabled << i;
|
2016-04-02 17:58:06 +02:00
|
|
|
|
2016-03-29 17:43:53 +02:00
|
|
|
fileWrite(&tempConfig, configPath, 3);
|
2016-03-23 02:27:53 +01:00
|
|
|
|
2016-03-29 17:58:33 +02:00
|
|
|
//Zero the last booted FIRM flag
|
|
|
|
CFG_BOOTENV = 0;
|
|
|
|
|
2016-03-23 02:27:53 +01:00
|
|
|
//Reboot
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void deleteFirms(const char *firmPaths[], u32 firms)
|
|
|
|
{
|
|
|
|
while(firms)
|
|
|
|
{
|
2016-03-23 02:27:53 +01:00
|
|
|
fileDelete(firmPaths[firms - 1]);
|
|
|
|
firms--;
|
|
|
|
}
|
2016-03-23 03:45:32 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 17:58:06 +02:00
|
|
|
void error(const char *message)
|
|
|
|
{
|
2016-03-23 16:10:26 +01:00
|
|
|
initScreens();
|
2016-03-23 03:45:32 +01:00
|
|
|
|
|
|
|
drawString("An error has occurred:", 10, 10, COLOR_RED);
|
2016-03-29 17:43:53 +02:00
|
|
|
int posY = drawString(message, 10, 30, COLOR_WHITE);
|
|
|
|
drawString("Press any button to shutdown", 10, posY + 2 * SPACING_Y, COLOR_WHITE);
|
2016-03-23 03:45:32 +01:00
|
|
|
|
|
|
|
waitInput();
|
|
|
|
|
|
|
|
//Shutdown
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1);
|
|
|
|
while(1);
|
2016-03-23 02:27:53 +01:00
|
|
|
}
|