From: chaoskagami Date: Sun, 28 Aug 2016 09:02:16 +0000 (-0400) Subject: Access all options via accessor functions (toplevel) X-Git-Tag: v0.3.0~33 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=3f3419dbf5911f9260819f61cbe5d974de2634af;p=corbenik%2Fcorbenik.git Access all options via accessor functions (toplevel) --- diff --git a/include/option.h b/include/option.h index 422e3a6..4509622 100644 --- a/include/option.h +++ b/include/option.h @@ -83,6 +83,10 @@ extern struct config_file *config; #ifndef LOADER +/// Bear in mind the following functions are only defined insofar +/// as that they exist. Do not make assumptions as to what is +/// backing these functions on disk. + /* Loads the config file off SD from the configured location. */ void load_config(); @@ -91,6 +95,22 @@ void load_config(); */ void save_config(); +/* Changes an option according to internal rules. + */ +void change_opt(void* val); + +/* Gets an option as a readable string. + */ +char* get_opt(void* val); + +/* Gets an option in raw form. + */ +uint32_t get_opt_raw(uint32_t val); + +/* Sets an option in raw form + */ +void set_opt_raw(uint32_t key, uint32_t val); + #endif #endif diff --git a/source/Makefile.am b/source/Makefile.am index 0e28efd..8fac091 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -19,4 +19,4 @@ corbenikdir = $(top_srcdir)/source inc_dir = $(top_srcdir)/include -corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c std/fs.c std/draw.c std/memory.c std/abort.c std/allocator.c menu.c firm/version.c firm/firm.c firm/decryptor.c interpreter.c input.c patcher.c chainloader.c config-file.c menu-backend.c start.s interrupt.c arm11.c +corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c std/fs.c std/draw.c std/memory.c std/abort.c std/allocator.c menu.c firm/version.c firm/firm.c firm/decryptor.c interpreter.c input.c patcher.c chainloader.c config-backend-file.c menu-backend.c start.s interrupt.c arm11.c diff --git a/source/arm11.c b/source/arm11.c index 9a447d1..e349a5a 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[config->options[OPTION_BRIGHTNESS]]; + bright = brightness[get_opt_raw(OPTION_BRIGHTNESS)]; stride = 240 * 3; if (mode == RGBA8) diff --git a/source/config-file.c b/source/config-backend-file.c similarity index 74% rename from source/config-file.c rename to source/config-backend-file.c index de394d3..fb1cf51 100644 --- a/source/config-file.c +++ b/source/config-backend-file.c @@ -157,3 +157,61 @@ save_config() fclose(conf_handle); } + +void change_opt(void* val) { + uint32_t opt = (uint32_t)val; + uint8_t* set = & (config->options[opt]); + switch(opt) { + case OPTION_EMUNAND_INDEX: + // 0-9 + set[0]++; + if (set[0] > 9) + set[0] = 0; + break; + case OPTION_BRIGHTNESS: + // 0-3 + set[0]++; + if (set[0] > 3) + set[0] = 0; + break; + case OPTION_ACCENT_COLOR: + // 1-7 + set[0]++; + if (set[0] > 7 || set[0] < 1) + set[0] = 1; + break; + default: + set[0] = !(set[0]); + break; + } +} + +char* get_opt(void* val) { + uint32_t opt = (uint32_t)val; + char raw = config->options[opt]; + static char str[2] = "0"; + str[0] = '0'; + switch(opt) { + case OPTION_EMUNAND_INDEX: + case OPTION_BRIGHTNESS: + case OPTION_ACCENT_COLOR: + str[0] += raw; + break; + default: + if (raw) + str[0] = '*'; + else + str[0] = ' '; + break; + } + return str; +} + +uint32_t get_opt_raw(uint32_t val) { + uint32_t opt = config->options[(uint32_t)val]; + return opt; +} + +void set_opt_raw(uint32_t key, uint32_t val) { + config->options[(uint32_t)key] = (uint8_t)val; +} diff --git a/source/input.c b/source/input.c index 9d94003..9b76299 100644 --- a/source/input.c +++ b/source/input.c @@ -43,7 +43,7 @@ extern int doing_autoboot; void wait() { - if (config->options[OPTION_TRACE] && !doing_autoboot) { + if (get_opt_raw(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 35e3e3f..6668eac 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 (config->options[OPTION_OVERLY_VERBOSE]) { + if (get_opt_raw(OPTION_OVERLY_VERBOSE)) { #endif debug = 1; } diff --git a/source/main.c b/source/main.c index 43855d8..e54ca96 100644 --- a/source/main.c +++ b/source/main.c @@ -33,7 +33,7 @@ main(int argc, char** argv) installArm11Stub(); if (CFG_BOOTENV == 7) - config->options[OPTION_EMUNAND] = 0; // Disable EmuNAND on AGB reboot. + set_opt_raw(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 (config->options[OPTION_AUTOBOOT] && !r_held) { + if (get_opt_raw(OPTION_AUTOBOOT) && !r_held) { doing_autoboot = 1; - if (config->options[OPTION_SILENCE]) + if (get_opt_raw(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 e77a488..5f424d3 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, config->options[OPTION_ACCENT_COLOR]); + fill_line(stdout, 0, get_opt_raw(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")[config->options[OPTION_ACCENT_COLOR]]; + color[3] = ("01234567")[get_opt_raw(OPTION_ACCENT_COLOR)]; fprintf(screen, "%s", color); } diff --git a/source/menu.c b/source/menu.c index cca47d8..f1e5f6b 100644 --- a/source/menu.c +++ b/source/menu.c @@ -6,55 +6,6 @@ struct options_s *patches = NULL; uint8_t *enable_list; -void change_opt(void* val) { - uint32_t opt = (uint32_t)val; - uint8_t* set = & (config->options[opt]); - switch(opt) { - case OPTION_EMUNAND_INDEX: - // 0-9 - set[0]++; - if (set[0] > 9) - set[0] = 0; - break; - case OPTION_BRIGHTNESS: - // 0-3 - set[0]++; - if (set[0] > 3) - set[0] = 0; - break; - case OPTION_ACCENT_COLOR: - // 1-7 - set[0]++; - if (set[0] > 7 || set[0] < 1) - set[0] = 1; - break; - default: - set[0] = !(set[0]); - break; - } -} - -char* get_opt(void* val) { - uint32_t opt = (uint32_t)val; - char raw = config->options[opt]; - static char str[2] = "0"; - str[0] = '0'; - switch(opt) { - case OPTION_EMUNAND_INDEX: - case OPTION_BRIGHTNESS: - case OPTION_ACCENT_COLOR: - str[0] += raw; - break; - default: - if (raw) - str[0] = '*'; - else - str[0] = ' '; - break; - } - return str; -} - static struct options_s options[] = { // Patches. { "General Options", "", unselectable, 0, NULL, NULL, 0, 1 }, diff --git a/source/patcher.c b/source/patcher.c index decebea..5675f8e 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 (config->options[OPTION_REBOOT]) { + if (get_opt_raw(OPTION_REBOOT)) { patch_reboot(); wait(); } // Use EmuNAND? - if (config->options[OPTION_EMUNAND]) { + if (get_opt_raw(OPTION_EMUNAND)) { // Yes. - patch_emunand(config->options[OPTION_EMUNAND_INDEX]); + patch_emunand(get_opt_raw(OPTION_EMUNAND_INDEX)); wait(); } // Inject services? - if (config->options[OPTION_SVCS]) { + if (get_opt_raw(OPTION_SVCS)) { if (patch_services()) { abort("Fatal. Svc inject has failed."); } @@ -81,7 +81,7 @@ patch_firm_all() } // Replace loader? - if (config->options[OPTION_LOADER]) { + if (get_opt_raw(OPTION_LOADER)) { if (patch_modules()) { abort("Fatal. Loader inject has failed."); } @@ -89,13 +89,5 @@ patch_firm_all() wait(); } - // Use ARM9 hook thread? - if (config->options[OPTION_ARM9THREAD]) { - // Yes. - - // FIXME - NYI - wait(); - } - return 0; }