uint8_t state;
} __attribute__((packed));
+#ifdef LOADER
extern struct config_file config;
+#else
+extern struct config_file *config;
+#endif
enum type
{
void accent_color(void* screen, int fg) {
char color[] = "\x1b[30m";
if (!fg) color[2] = '4';
- color[3] = ("01234567")[config.options[OPTION_ACCENT_COLOR]];
+ color[3] = ("01234567")[config->options[OPTION_ACCENT_COLOR]];
fprintf(screen, "%s", color);
}
load_firms();
- if (config.options[OPTION_RECONFIGURED]) {
+ if (config->options[OPTION_RECONFIGURED]) {
fprintf(stderr, "Generating patch cache...\n");
generate_patch_cache();
}
if (patch_firm_all() != 0)
return;
- if (config.options[OPTION_REBOOT] && config.options[OPTION_RECONFIGURED]) {
+ if (config->options[OPTION_REBOOT] && config->options[OPTION_RECONFIGURED]) {
fprintf(stderr, "Saving FIRM for reboot...\n");
if (!write_file(firm_loc, PATH_NATIVE_P, firm_size))
abort("Failed to save prepatched native\n");
#endif
int debug = 0;
+#ifdef LOADER
if (config.options[OPTION_OVERLY_VERBOSE]) {
+#else
+ if (config->options[OPTION_OVERLY_VERBOSE]) {
+#endif
debug = 1;
}
*(.text.start)
}
+ . = ALIGN(4);
+
.text : {
*(.text)
}
+ . = ALIGN(4);
+
.data : {
*(.data)
}
+ . = ALIGN(4);
+
+ .rodata : {
+ *(.rodata)
+ }
+
+ . = ALIGN(4);
+
+ .rel : {
+ *(.rel)
+ }
+
+ . = ALIGN(4);
+
+ .symtab : {
+ *(.symtab)
+ }
+
+ . = ALIGN(4);
+
.bss : {
__bss_start = .;
*(.bss COMMON)
}
__bss_end = .;
- .rodata : {
- *(.rodata)
- }
-
. = ALIGN(4);
+
__end__ = 0x20400000;
}
if (CFG_BOOTENV == 7) {
fprintf(stderr, "Rebooted from AGB, disabling EmuNAND.\n");
- config.options[OPTION_EMUNAND] = 0;
+ config->options[OPTION_EMUNAND] = 0;
}
// Autoboot. Non-standard code path.
- if (config.options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) {
- if (config.options[OPTION_SILENCE])
+ if (config->options[OPTION_AUTOBOOT] && !(ctr_hid_get_buttons() & CTR_HID_RT)) {
+ if (config->options[OPTION_SILENCE])
shut_up(); // This does exactly what it sounds like.
doing_autoboot = 1;
} else {
header(char *append)
{
set_cursor(TOP_SCREEN, 0, 0);
- fill_line(stdout, 0, config.options[OPTION_ACCENT_COLOR]);
+ fill_line(stdout, 0, config->options[OPTION_ACCENT_COLOR]);
accent_color(TOP_SCREEN, 0);
fprintf(stdout, "\x1b[30m ." FW_NAME " // %s\x1b[0m\n\n", append);
}
void
menu_options()
{
- show_menu(options, config.options);
+ show_menu(options, config->options);
}
#ifndef REL
FILE *conf_handle;
-struct config_file config;
+struct config_file *config;
extern uint8_t *enable_list;
void list_patches_build(char *name, int desc_is_fname);
void
regenerate_config()
{
- memset(&config, 0, sizeof(config));
- memcpy(&(config.magic), CONFIG_MAGIC, 4);
- config.config_ver = config_version;
- config.options[OPTION_ACCENT_COLOR] = 2;
+ for(int i=0; i < 4; i++)
+ config->magic[i] = CONFIG_MAGIC[i];
+
+ config->config_ver = config_version;
+ config->options[OPTION_ACCENT_COLOR] = 2;
if (!(conf_handle = fopen(PATH_CONFIG, "w")))
abort("Failed to open config for write?\n");
- fwrite(&config, 1, sizeof(config), conf_handle);
+ fwrite(config, 1, sizeof(struct config_file), conf_handle);
fclose(conf_handle);
fprintf(BOTTOM_SCREEN, "Config file written.\n");
{
int updated = 0;
- if (config.options[OPTION_ACCENT_COLOR] == 0) {
+ if (config->options[OPTION_ACCENT_COLOR] == 0) {
fprintf(stderr, "Config update: accent color\n");
- config.options[OPTION_ACCENT_COLOR] = 2;
+ config->options[OPTION_ACCENT_COLOR] = 2;
updated = 1;
}
void
load_config()
{
+ config = (struct config_file*)malloc(sizeof(struct config_file));
+ memset(config, 0, sizeof(struct config_file));
+
mk_structure(); // Make directory structure if needed.
// Zero on success.
PATH_CONFIG);
regenerate_config();
} else {
- fread(&config, 1, sizeof(config), conf_handle);
+ fread(config, 1, sizeof(struct config_file), conf_handle);
fclose(conf_handle);
- if (memcmp(&(config.magic), CONFIG_MAGIC, 4)) {
+ if (memcmp(&(config->magic), CONFIG_MAGIC, 4)) {
fprintf(BOTTOM_SCREEN, "Config file at:\n"
" %s\n"
"has incorrect magic:\n"
" '%c%c%c%c'\n"
"Regenerating with defaults.\n",
- PATH_CONFIG, config.magic[0], config.magic[1], config.magic[2], config.magic[3]);
+ PATH_CONFIG, config->magic[0], config->magic[1], config->magic[2], config->magic[3]);
f_unlink(PATH_CONFIG);
regenerate_config();
}
- if (config.config_ver < config_version) {
+ if (config->config_ver < config_version) {
fprintf(BOTTOM_SCREEN, "Config file has outdated version:\n"
" %s\n"
"Regenerating with defaults...\n",
list_patches_build(PATH_PATCHES, 0);
- if (!config.options[OPTION_SILENCE])
+ if (!config->options[OPTION_SILENCE])
fprintf(BOTTOM_SCREEN, "Config file loaded.\n");
update_config();
if (!(conf_handle = fopen(PATH_CONFIG, "w")))
abort("Failed to open config for write?\n");
- config.options[OPTION_RECONFIGURED] = 0; // This should not persist to disk.
+ config->options[OPTION_RECONFIGURED] = 0; // This should not persist to disk.
- fwrite(&config, 1, sizeof(config), conf_handle);
+ fwrite(config, 1, sizeof(struct config_file), conf_handle);
fclose(conf_handle);
- config.options[OPTION_RECONFIGURED] = 1; // Save caches on boot.
+ config->options[OPTION_RECONFIGURED] = 1; // Save caches on boot.
}
void
wait()
{
- if (config.options[OPTION_TRACE] && !doing_autoboot) {
+ if (config->options[OPTION_TRACE] && !doing_autoboot) {
fprintf(stderr, "[Waiting...]");
wait_key(0); // No delay on traces.
}
fprintf(stderr, "VM exited without issue\n");
// Hook firmlaunch?
- if (config.options[OPTION_REBOOT]) {
+ if (config->options[OPTION_REBOOT]) {
patch_reboot();
wait();
}
// Use EmuNAND?
- if (config.options[OPTION_EMUNAND]) {
+ if (config->options[OPTION_EMUNAND]) {
// Yes.
- patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
+ patch_emunand(config->options[OPTION_EMUNAND_INDEX]);
wait();
}
// Inject services?
- if (config.options[OPTION_SVCS]) {
+ if (config->options[OPTION_SVCS]) {
if (patch_services()) {
abort("Fatal. Svc inject has failed.");
}
}
// Replace loader?
- if (config.options[OPTION_LOADER]) {
+ if (config->options[OPTION_LOADER]) {
if (patch_modules()) {
abort("Fatal. Loader inject has failed.");
}
}
// Use ARM9 hook thread?
- if (config.options[OPTION_ARM9THREAD]) {
+ if (config->options[OPTION_ARM9THREAD]) {
// Yes.
// FIXME - NYI
}
void dump_log(unsigned int force) {
- if(!config.options[OPTION_SAVE_LOGS])
+ if(!config->options[OPTION_SAVE_LOGS])
return;
if (force == 0 && log_size < LOG_BUFFER_SIZE-1)
screen[j + 1] = top_bg[i];
screen[j + 2] = top_bg[i + 1];
screen[j + 3] = top_bg[i + 2];
- if (!kill_output && config.options[OPTION_DIM_MODE]) {
+ if (!kill_output && config->options[OPTION_DIM_MODE]) {
screen[j + 1] = alphamap[screen[j + 1]];
screen[j + 2] = alphamap[screen[j + 2]];
screen[j + 3] = alphamap[screen[j + 3]];
screen[j + 1] = bottom_bg[i];
screen[j + 2] = bottom_bg[i + 1];
screen[j + 3] = bottom_bg[i + 2];
- if (!kill_output && config.options[OPTION_DIM_MODE]) {
+ if (!kill_output && config->options[OPTION_DIM_MODE]) {
screen[j + 1] = alphamap[screen[j + 1]];
screen[j + 2] = alphamap[screen[j + 2]];
screen[j + 3] = alphamap[screen[j + 3]];
screen[pos + 1] = buffer_bg[pos_b];
screen[pos + 2] = buffer_bg[pos_b + 1];
screen[pos + 3] = buffer_bg[pos_b + 2];
- if (config.options[OPTION_DIM_MODE]) {
+ if (config->options[OPTION_DIM_MODE]) {
screen[pos + 1] = alphamap[screen[pos + 1]];
screen[pos + 2] = alphamap[screen[pos + 2]];
screen[pos + 3] = alphamap[screen[pos + 3]];
screen[pos + 1] = buffer_bg[pos_b];
screen[pos + 2] = buffer_bg[pos_b + 1];
screen[pos + 3] = buffer_bg[pos_b + 2];
- if (config.options[OPTION_DIM_MODE]) {
+ if (config->options[OPTION_DIM_MODE]) {
screen[pos + 1] = alphamap[screen[pos + 1]];
screen[pos + 2] = alphamap[screen[pos + 2]];
screen[pos + 3] = alphamap[screen[pos + 3]];
if (f_mount(NULL, "SD:", 1))
return 1;
- config.options[OPTION_SAVE_LOGS] = 0; // FS unmounted, can't log anymore
+ config->options[OPTION_SAVE_LOGS] = 0; // FS unmounted, can't log anymore
return 0;
}