From: chaoskagami Date: Sun, 28 Aug 2016 20:13:54 +0000 (-0400) Subject: Put a few more bits in place for reasons X-Git-Tag: v0.3.0~30 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=85a919e89f3974866b6babe60ea9c9b293abf557;p=corbenik%2Fcorbenik.git Put a few more bits in place for reasons --- diff --git a/include/option.h b/include/option.h index 4509622..746b407 100644 --- a/include/option.h +++ b/include/option.h @@ -16,6 +16,8 @@ struct config_file uint8_t options[256]; ///< Options in the menu - deliberately large to avoid ///< config version bumps. + + char firm[3][256]; ///< FIRMS. } __attribute__((packed)); #ifdef LOADER @@ -76,6 +78,10 @@ extern struct config_file *config; #define OPTION_RECONFIGURED 255 ///< This is for internal use only. It's set when any changes ///< require caches to be regenerated. +#define OPTION_NFIRM_PATH 0xFFFD +#define OPTION_TFIRM_PATH 0xFFFE +#define OPTION_AFIRM_PATH 0xFFFF + //#define HEADER_COLOR 12 // Color of header text. //#define BG_COLOR 13 // Color of background. //#define TEXT_COLOR 14 // Color of most text. @@ -95,7 +101,7 @@ void load_config(); */ void save_config(); -/* Changes an option according to internal rules. +/* Changes an option according to internal rules. Used in menus. */ void change_opt(void* val); @@ -103,13 +109,17 @@ void change_opt(void* val); */ char* get_opt(void* val); -/* Gets an option in raw form. +/* Gets an option in uint32_t form. + */ +uint32_t get_opt_u32(uint32_t val); + +/* Sets an option in uint32_t form */ -uint32_t get_opt_raw(uint32_t val); +int set_opt_u32(uint32_t key, uint32_t val); -/* Sets an option in raw form +/* Sets an option in uint32_t form */ -void set_opt_raw(uint32_t key, uint32_t val); +int set_opt_str(uint32_t key, const char* val); #endif diff --git a/source/arm11.c b/source/arm11.c index e349a5a..bb57488 100644 --- a/source/arm11.c +++ b/source/arm11.c @@ -146,7 +146,7 @@ void clearScreens(void) { void screen_mode(uint32_t mode) { static uint32_t stride, init_top, init_bottom, bright; - bright = brightness[get_opt_raw(OPTION_BRIGHTNESS)]; + bright = brightness[get_opt_u32(OPTION_BRIGHTNESS)]; stride = 240 * 3; if (mode == RGBA8) diff --git a/source/config-backend-file.c b/source/config-backend-file.c index fb1cf51..862b2f9 100644 --- a/source/config-backend-file.c +++ b/source/config-backend-file.c @@ -207,11 +207,28 @@ char* get_opt(void* val) { return str; } -uint32_t get_opt_raw(uint32_t val) { +uint32_t get_opt_u32(uint32_t val) { uint32_t opt = config->options[(uint32_t)val]; + return opt; } -void set_opt_raw(uint32_t key, uint32_t val) { +int set_opt_u32(uint32_t key, uint32_t val) { + if (key >= OPTION_NFIRM_PATH && key <= OPTION_AFIRM_PATH) + return 1; + config->options[(uint32_t)key] = (uint8_t)val; + + return 0; +} + +int set_opt_str(uint32_t key, const char* val) { + if (!(key >= OPTION_NFIRM_PATH && key <= OPTION_AFIRM_PATH)) + return 1; + + key -= OPTION_NFIRM_PATH; + + strncpy(config->firm[key], val, 255); + + return 0; } diff --git a/source/firm/firm.c b/source/firm/firm.c index 8189291..4e7c70f 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -561,7 +561,7 @@ boot_cfw() if (patch_firm_all() != 0) return; - if (get_opt_raw(OPTION_REBOOT)) { + if (get_opt_u32(OPTION_REBOOT)) { fprintf(stderr, "Saving FIRM for reboot...\n"); if (!write_file(firm_loc, PATH_NATIVE_P, firm_size)) abort("Failed to save prepatched native\n"); diff --git a/source/input.c b/source/input.c index 9b76299..15da0d5 100644 --- a/source/input.c +++ b/source/input.c @@ -43,7 +43,7 @@ extern int doing_autoboot; void wait() { - if (get_opt_raw(OPTION_TRACE) && !doing_autoboot) { + if (get_opt_u32(OPTION_TRACE) && !doing_autoboot) { fprintf(stderr, "[Waiting...]"); wait_key(0); // No delay on traces. } diff --git a/source/interpreter.c b/source/interpreter.c index 6668eac..ae38927 100644 --- a/source/interpreter.c +++ b/source/interpreter.c @@ -746,7 +746,7 @@ execb(const char *filename, int build_cache) #ifdef LOADER if (config.options[OPTION_OVERLY_VERBOSE]) { #else - if (get_opt_raw(OPTION_OVERLY_VERBOSE)) { + if (get_opt_u32(OPTION_OVERLY_VERBOSE)) { #endif debug = 1; } diff --git a/source/main.c b/source/main.c index e54ca96..f0988f5 100644 --- a/source/main.c +++ b/source/main.c @@ -33,7 +33,7 @@ main(int argc, char** argv) installArm11Stub(); if (CFG_BOOTENV == 7) - set_opt_raw(OPTION_EMUNAND, 0); // Disable EmuNAND on AGB reboot. + set_opt_u32(OPTION_EMUNAND, 0); // Disable EmuNAND on AGB reboot. set_font(PATH_TERMFONT); // Read the font before all else. @@ -48,10 +48,10 @@ main(int argc, char** argv) clear_disp(TOP_SCREEN); clear_disp(BOTTOM_SCREEN); - if (get_opt_raw(OPTION_AUTOBOOT) && !r_held) { + if (get_opt_u32(OPTION_AUTOBOOT) && !r_held) { doing_autoboot = 1; - if (get_opt_raw(OPTION_SILENCE)) + if (get_opt_u32(OPTION_SILENCE)) shut_up(); // This does exactly what it sounds like. } else { menu_handler(); diff --git a/source/menu-backend.c b/source/menu-backend.c index 5f424d3..fe6a191 100644 --- a/source/menu-backend.c +++ b/source/menu-backend.c @@ -8,7 +8,7 @@ void header(const char *append) { set_cursor(TOP_SCREEN, 0, 0); - fill_line(stdout, 0, get_opt_raw(OPTION_ACCENT_COLOR)); + fill_line(stdout, 0, get_opt_u32(OPTION_ACCENT_COLOR)); accent_color(TOP_SCREEN, 0); fprintf(stdout, "\x1b[30m ." FW_NAME " // %s\x1b[0m\n\n", append); } @@ -24,7 +24,7 @@ void show_help(const char* help) { void accent_color(void* screen, int fg) { char color[] = "\x1b[30m"; if (!fg) color[2] = '4'; - color[3] = ("01234567")[get_opt_raw(OPTION_ACCENT_COLOR)]; + color[3] = ("01234567")[get_opt_u32(OPTION_ACCENT_COLOR)]; fprintf(screen, "%s", color); } diff --git a/source/menu.c b/source/menu.c index f1e5f6b..953cc6e 100644 --- a/source/menu.c +++ b/source/menu.c @@ -147,47 +147,6 @@ void patch_func(char* fpath) { } } -// This is dual purpose. When we actually list -// patches to build the cache - desc_is_fname -// will be set to 1. - -void -list_patches_build(const char *name, int desc_is_fname) -{ - desc_is_fname_sto = desc_is_fname; - - current_menu_index_patches = 0; - - if (!patches) - patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc. - - patches[0].name = "Patches"; - patches[0].desc = ""; - patches[0].handle = unselectable; - patches[0].indent = 0; - patches[0].func = NULL; - patches[0].value = NULL; - patches[0].highlight = 1; - - current_menu_index_patches += 1; - - recurse_call(name, patch_func); - - patches[current_menu_index_patches].name = NULL; -} - -void -menu_patches() -{ - show_menu(patches); -} - -void -menu_options() -{ - show_menu(options); -} - #ifndef REL #define REL "master" #endif @@ -225,12 +184,6 @@ static struct options_s help_d[] = { { NULL, NULL, unselectable, 0, NULL, NULL, 0, 0 }, // cursor_min and cursor_max are stored in the last two. }; -void -menu_help() -{ - show_menu(help_d); -} - void reset() { @@ -264,15 +217,46 @@ void chainload_menu(); static struct options_s config_opts[] = { { "Options", "Internal options for the CFW.\nThese are part of " FW_NAME " itself.", - option, 0, menu_options, NULL, 0, 0 }, + option, options, (void(*)(void*))show_menu, NULL, 0, 0 }, { "Patches", "External bytecode patches found in `" PATH_PATCHES "`.\nYou can choose which to enable.", - option, 0, menu_patches, NULL, 0, 0 }, + option, NULL, (void(*)(void*))show_menu, NULL, 0, 0 }, // Sentinel. { NULL, NULL, 0, 0, NULL, NULL, 0, 0 }, // cursor_min and cursor_max are stored in the last two. }; +// This is dual purpose. When we actually list +// patches to build the cache - desc_is_fname +// will be set to 1. + +void +list_patches_build(const char *name, int desc_is_fname) +{ + desc_is_fname_sto = desc_is_fname; + + current_menu_index_patches = 0; + + if (!patches) + patches = malloc(sizeof(struct options_s) * 258); // FIXME - hard limit. Implement realloc. + + patches[0].name = "Patches"; + patches[0].desc = ""; + patches[0].handle = unselectable; + patches[0].indent = 0; + patches[0].func = NULL; + patches[0].value = NULL; + patches[0].highlight = 1; + + current_menu_index_patches += 1; + + recurse_call(name, patch_func); + + patches[current_menu_index_patches].name = NULL; + + config_opts[1].param = (void*)patches; +} + void config_main_menu() { show_menu(config_opts); @@ -287,7 +271,7 @@ static struct options_s main_s[] = { option, 0, config_main_menu, NULL, 0, 0 }, { "Readme", "Mini-readme.\nWhy are you opening help on this, though?\nThat's kind of silly.", - option, 0, menu_help, NULL, 0, 0 }, + option, help_d, (void(*)(void*))show_menu, NULL, 0, 0 }, { "Reboot", "Reboots the console.", option, 0, reset, NULL, 0, 0 }, diff --git a/source/patcher.c b/source/patcher.c index 5675f8e..50a39f5 100644 --- a/source/patcher.c +++ b/source/patcher.c @@ -58,22 +58,22 @@ patch_firm_all() fprintf(stderr, "VM exited without issue\n"); // Hook firmlaunch? - if (get_opt_raw(OPTION_REBOOT)) { + if (get_opt_u32(OPTION_REBOOT)) { patch_reboot(); wait(); } // Use EmuNAND? - if (get_opt_raw(OPTION_EMUNAND)) { + if (get_opt_u32(OPTION_EMUNAND)) { // Yes. - patch_emunand(get_opt_raw(OPTION_EMUNAND_INDEX)); + patch_emunand(get_opt_u32(OPTION_EMUNAND_INDEX)); wait(); } // Inject services? - if (get_opt_raw(OPTION_SVCS)) { + if (get_opt_u32(OPTION_SVCS)) { if (patch_services()) { abort("Fatal. Svc inject has failed."); } @@ -81,7 +81,7 @@ patch_firm_all() } // Replace loader? - if (get_opt_raw(OPTION_LOADER)) { + if (get_opt_u32(OPTION_LOADER)) { if (patch_modules()) { abort("Fatal. Loader inject has failed."); } diff --git a/source/std/draw.c b/source/std/draw.c index 42313d9..2da5866 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -209,7 +209,7 @@ void set_font(const char* filename) { } void dump_log(unsigned int force) { - if(!get_opt_raw(OPTION_SAVE_LOGS)) + if(!get_opt_u32(OPTION_SAVE_LOGS)) return; if (force == 0 && log_size < LOG_BUFFER_SIZE-1) @@ -241,7 +241,7 @@ clear_disp(uint8_t *screen) screen[j + 1] = top_bg[i]; screen[j + 2] = top_bg[i + 1]; screen[j + 3] = top_bg[i + 2]; - if (!kill_output && get_opt_raw(OPTION_DIM_MODE)) { + if (!kill_output && get_opt_u32(OPTION_DIM_MODE)) { screen[j + 1] = alphamap[screen[j + 1]]; screen[j + 2] = alphamap[screen[j + 2]]; screen[j + 3] = alphamap[screen[j + 3]]; @@ -256,7 +256,7 @@ clear_disp(uint8_t *screen) screen[j + 1] = bottom_bg[i]; screen[j + 2] = bottom_bg[i + 1]; screen[j + 3] = bottom_bg[i + 2]; - if (!kill_output && get_opt_raw(OPTION_DIM_MODE)) { + if (!kill_output && get_opt_u32(OPTION_DIM_MODE)) { screen[j + 1] = alphamap[screen[j + 1]]; screen[j + 2] = alphamap[screen[j + 2]]; screen[j + 3] = alphamap[screen[j + 3]]; @@ -327,7 +327,7 @@ draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, screen[pos + 1] = buffer_bg[pos_b]; screen[pos + 2] = buffer_bg[pos_b + 1]; screen[pos + 3] = buffer_bg[pos_b + 2]; - if (get_opt_raw(OPTION_DIM_MODE)) { + if (get_opt_u32(OPTION_DIM_MODE)) { screen[pos + 1] = alphamap[screen[pos + 1]]; screen[pos + 2] = alphamap[screen[pos + 2]]; screen[pos + 3] = alphamap[screen[pos + 3]]; @@ -343,7 +343,7 @@ draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, screen[pos + 1] = buffer_bg[pos_b]; screen[pos + 2] = buffer_bg[pos_b + 1]; screen[pos + 3] = buffer_bg[pos_b + 2]; - if (get_opt_raw(OPTION_DIM_MODE)) { + if (get_opt_u32(OPTION_DIM_MODE)) { screen[pos + 1] = alphamap[screen[pos + 1]]; screen[pos + 2] = alphamap[screen[pos + 2]]; screen[pos + 3] = alphamap[screen[pos + 3]]; diff --git a/source/std/fs.c b/source/std/fs.c index ef1d529..37055d3 100644 --- a/source/std/fs.c +++ b/source/std/fs.c @@ -86,7 +86,7 @@ fumount(void) if (f_mount(NULL, "SD:", 1)) return 1; - set_opt_raw(OPTION_SAVE_LOGS, 0); // FS unmounted, can't log anymore + set_opt_u32(OPTION_SAVE_LOGS, 0); // FS unmounted, can't log anymore return 0; }