2016-04-05 05:27:28 +02:00
|
|
|
/*
|
|
|
|
* config.c
|
|
|
|
* by Aurora Wright
|
|
|
|
* Copyright (c) 2016 All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "screeninit.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "fs.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "buttons.h"
|
|
|
|
|
2016-04-11 05:15:44 +02:00
|
|
|
void configureCFW(const char *configPath)
|
2016-04-05 05:27:28 +02:00
|
|
|
{
|
|
|
|
initScreens();
|
|
|
|
|
|
|
|
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
|
|
|
|
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
|
|
|
|
|
2016-04-05 23:01:46 +02:00
|
|
|
const char *optionsText[] = { "Screen-init brightness: 4( ) 3( ) 2( ) 1( )",
|
2016-04-11 05:15:44 +02:00
|
|
|
"( ) Autoboot SysNAND",
|
2016-04-05 23:01:46 +02:00
|
|
|
"( ) Updated SysNAND mode (A9LH-only)",
|
2016-04-05 05:27:28 +02:00
|
|
|
"( ) Force A9LH detection",
|
|
|
|
"( ) Use second EmuNAND as default",
|
|
|
|
"( ) Show current NAND in System Settings",
|
2016-04-05 23:01:46 +02:00
|
|
|
"( ) Show GBA boot screen in patched AGB_FIRM",
|
2016-04-11 21:14:51 +02:00
|
|
|
"( ) Enable splash screen with no screen-init",
|
|
|
|
"( ) Use developer UNITINFO" };
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
u32 optionsAmount = sizeof(optionsText) / sizeof(char *);
|
|
|
|
|
|
|
|
struct option {
|
|
|
|
int posY;
|
|
|
|
u32 enabled;
|
|
|
|
} options[optionsAmount];
|
|
|
|
|
|
|
|
//Parse the existing configuration
|
2016-04-11 05:15:44 +02:00
|
|
|
options[0].enabled = CONFIG(14, 3);
|
|
|
|
for(u32 i = optionsAmount - 1; i; i--)
|
2016-04-06 14:51:07 +02:00
|
|
|
options[i].enabled = CONFIG((i - 1), 1);
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
//Pre-select the first configuration option
|
2016-04-05 23:01:46 +02:00
|
|
|
u32 selectedOption = 1,
|
|
|
|
oldSelectedOption = 0,
|
|
|
|
optionChanged = 0;
|
|
|
|
|
|
|
|
//Character to display a selected option
|
|
|
|
char selected = 'x';
|
|
|
|
|
|
|
|
//Starting position
|
|
|
|
options[0].posY = 52;
|
|
|
|
|
|
|
|
//Display all the normal options in white, brightness will be displayed later
|
|
|
|
for(u32 i = 1; i < optionsAmount; i++)
|
|
|
|
{
|
2016-04-11 05:15:44 +02:00
|
|
|
static int endPos = 59;
|
|
|
|
options[i].posY = endPos + SPACING_Y;
|
|
|
|
endPos = drawString(optionsText[i], 10, options[i].posY, COLOR_WHITE);
|
2016-04-05 23:01:46 +02:00
|
|
|
if(options[i].enabled) drawCharacter(selected, 10 + SPACING_X, options[i].posY, COLOR_WHITE);
|
|
|
|
}
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
//Boring configuration menu
|
|
|
|
while(1)
|
|
|
|
{
|
2016-04-05 23:01:46 +02:00
|
|
|
u32 pressed = 0;
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
do {
|
2016-04-06 14:51:07 +02:00
|
|
|
//The status of the selected option changed, black out the previously visible 'x' if needed
|
2016-04-05 23:01:46 +02:00
|
|
|
if(optionChanged)
|
|
|
|
{
|
|
|
|
if(!selectedOption)
|
|
|
|
drawCharacter(selected, 10 + (26 + 5 * (optionChanged - 1)) * SPACING_X, options[0].posY, COLOR_BLACK);
|
|
|
|
else if(!options[selectedOption].enabled)
|
|
|
|
drawCharacter(selected, 10 + SPACING_X, options[selectedOption].posY, COLOR_BLACK);
|
|
|
|
|
|
|
|
optionChanged = 0;
|
|
|
|
}
|
2016-04-05 05:27:28 +02:00
|
|
|
|
2016-04-05 23:01:46 +02:00
|
|
|
//The selected option changed, draw the new one in red and the old one (with its 'x') in white
|
|
|
|
else if(selectedOption != oldSelectedOption)
|
2016-04-05 05:27:28 +02:00
|
|
|
{
|
2016-04-05 23:01:46 +02:00
|
|
|
drawString(optionsText[oldSelectedOption], 10, options[oldSelectedOption].posY, COLOR_WHITE);
|
|
|
|
drawString(optionsText[selectedOption], 10, options[selectedOption].posY, COLOR_RED);
|
|
|
|
|
|
|
|
if(!oldSelectedOption)
|
|
|
|
drawCharacter(selected, 10 + (26 + 5 * options[0].enabled) * SPACING_X, options[0].posY, COLOR_WHITE);
|
|
|
|
else if(options[oldSelectedOption].enabled)
|
|
|
|
drawCharacter(selected, 10 + SPACING_X, options[oldSelectedOption].posY, COLOR_WHITE);
|
2016-04-05 05:27:28 +02:00
|
|
|
}
|
|
|
|
|
2016-04-05 23:01:46 +02:00
|
|
|
//In any case, if the current option is enabled (or brightness is selected) we must display a red 'x'
|
|
|
|
if(!selectedOption)
|
|
|
|
drawCharacter(selected, 10 + (26 + 5 * options[0].enabled) * SPACING_X, options[0].posY, COLOR_RED);
|
|
|
|
else if(options[selectedOption].enabled)
|
|
|
|
drawCharacter(selected, 10 + SPACING_X, options[selectedOption].posY, COLOR_RED);
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
pressed = waitInput();
|
|
|
|
}
|
|
|
|
while(!(pressed & MENU_BUTTONS));
|
|
|
|
|
2016-04-05 23:01:46 +02:00
|
|
|
//Remember the previously selected option
|
|
|
|
oldSelectedOption = selectedOption;
|
|
|
|
|
2016-04-05 05:27:28 +02:00
|
|
|
switch(pressed)
|
|
|
|
{
|
|
|
|
case BUTTON_UP:
|
2016-04-05 23:01:46 +02:00
|
|
|
selectedOption = !selectedOption ? optionsAmount - 1 : selectedOption - 1;
|
2016-04-05 05:27:28 +02:00
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
2016-04-05 23:01:46 +02:00
|
|
|
selectedOption = selectedOption == (optionsAmount - 1) ? 1 : selectedOption + 1;
|
2016-04-05 05:27:28 +02:00
|
|
|
break;
|
|
|
|
case BUTTON_LEFT:
|
2016-04-05 23:01:46 +02:00
|
|
|
selectedOption = 1;
|
2016-04-05 05:27:28 +02:00
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
selectedOption = optionsAmount - 1;
|
|
|
|
break;
|
|
|
|
case BUTTON_A:
|
2016-04-06 14:51:07 +02:00
|
|
|
optionChanged = 1;
|
2016-04-05 23:01:46 +02:00
|
|
|
if(selectedOption) options[selectedOption].enabled = !options[selectedOption].enabled;
|
2016-04-06 14:51:07 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
optionChanged += options[0].enabled;
|
|
|
|
options[0].enabled = options[0].enabled == 3 ? 0 : options[0].enabled + 1;
|
|
|
|
}
|
2016-04-05 05:27:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pressed == BUTTON_START) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Preserve the last-used boot options (last 12 bits)
|
2016-04-11 05:15:44 +02:00
|
|
|
config &= 0xFF0000;
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
//Parse and write the new configuration
|
2016-04-11 05:15:44 +02:00
|
|
|
config |= options[0].enabled << 14;
|
|
|
|
for(u32 i = optionsAmount - 1; i; i--)
|
2016-04-05 23:01:46 +02:00
|
|
|
config |= options[i].enabled << (i - 1);
|
2016-04-05 05:27:28 +02:00
|
|
|
|
|
|
|
fileWrite(&config, configPath, 3);
|
|
|
|
|
|
|
|
//Zero the last booted FIRM flag
|
|
|
|
CFG_BOOTENV = 0;
|
|
|
|
|
|
|
|
//Reboot
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
|
|
|
while(1);
|
2016-04-11 21:14:51 +02:00
|
|
|
}
|