From 091727e004d1b1483685d6e2fe45a79790a89ebf Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Fri, 15 Jul 2016 06:24:43 -0400 Subject: [PATCH] Bugfixes all over the damn place, and yet another useless feature (tm) More specifically: * Fixed an issue in handling R on boot when ctr9_io adaptation was done * Don't force logging on (introduced again in the ctr9_io branch) * Printing of colored text was incorrect - B and R were swapped * Accent color is now customizable. --- source/chain.c | 4 ++-- source/config.c | 1 + source/config.h | 3 +++ source/display.c | 36 +++++++++++++++++++++++++----------- source/main.c | 4 +--- source/menu.c | 19 ++++++++++++------- source/std/draw.c | 8 ++++---- 7 files changed, 48 insertions(+), 27 deletions(-) diff --git a/source/chain.c b/source/chain.c index 9421771..4efa517 100644 --- a/source/chain.c +++ b/source/chain.c @@ -130,11 +130,11 @@ list_chain_build(char *name) { current_chain_index = 0; - strncpy(chains[0].name, "\x1b[40;32mChainloader Payloads\x1b[0m", 64); + strncpy(chains[0].name, "Chainloader Payloads", 64); strncpy(chains[0].desc, "", 255); chains[0].index = 0; chains[0].allowed = not_option; - chains[0].a = 0; + chains[0].a = 1; chains[0].b = 0; current_chain_index += 1; diff --git a/source/config.c b/source/config.c index d6bbc3a..b0bf8f1 100644 --- a/source/config.c +++ b/source/config.c @@ -12,6 +12,7 @@ regenerate_config() memset(&config, 0, sizeof(config)); memcpy(&(config.magic), CONFIG_MAGIC, 4); config.config_ver = config_version; + config.options[OPTION_ACCENT_COLOR] = 0x2; if (!(conf_handle = fopen(PATH_CONFIG, "w"))) abort("Failed to open config for write?\n"); diff --git a/source/config.h b/source/config.h index 54b6928..ba5f154 100644 --- a/source/config.h +++ b/source/config.h @@ -79,6 +79,9 @@ struct options_s // Dim background for readability. #define OPTION_DIM_MODE 8 +// Accent color in menus. +#define OPTION_ACCENT_COLOR 9 + // Enable L2 cache. #define OPTION_LOADER_CPU_L2 11 diff --git a/source/display.c b/source/display.c index dba9481..6197b64 100644 --- a/source/display.c +++ b/source/display.c @@ -16,6 +16,13 @@ void show_help(char* help) { wait_key(1); } +void accent_color(void* screen, int fg) { + char color[] = "\x1b[30m"; + if (!fg) color[2] = '4'; + color[3] = ("01234567")[config.options[OPTION_ACCENT_COLOR]]; + fprintf(screen, "%s", color); +} + int show_menu(struct options_s *options, uint8_t *toggles) { @@ -85,28 +92,35 @@ show_menu(struct options_s *options, uint8_t *toggles) set_cursor(TOP_SCREEN, 0, i-window_top+2); if (options[i].allowed == boolean_val || (is_n3ds && options[i].allowed == boolean_val_n3ds)) { - if (cursor_y == i) - fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); - else + if (cursor_y == i) { + accent_color(TOP_SCREEN, 1); + fprintf(TOP_SCREEN, ">>\x1b[0m "); + } else { fprintf(TOP_SCREEN, " "); + } fprintf(TOP_SCREEN, "[%c] %s", (toggles[options[i].index] ? '*' : ' '), options[i].name); } else if (options[i].allowed == call_fun || options[i].allowed == break_menu) { - if (cursor_y == i) - fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); - else + if (cursor_y == i) { + accent_color(TOP_SCREEN, 1); + fprintf(TOP_SCREEN, ">>\x1b[0m "); + } else { fprintf(TOP_SCREEN, " "); + } fprintf(TOP_SCREEN, "%s", options[i].name); } else if (options[i].allowed == ranged_val) { - if (cursor_y == i) - fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); - else + if (cursor_y == i) { + accent_color(TOP_SCREEN, 1); + fprintf(TOP_SCREEN, ">>\x1b[0m "); + } else { fprintf(TOP_SCREEN, " "); - + } fprintf(TOP_SCREEN, "[%u] %s ", toggles[options[i].index], options[i].name); } else if (options[i].allowed == not_option) { - fprintf(TOP_SCREEN, "%s", options[i].name); + if (options[i].a == 1) + accent_color(TOP_SCREEN, 1); + fprintf(TOP_SCREEN, "%s\x1b[0m", options[i].name); } ++i; } diff --git a/source/main.c b/source/main.c index 994ab2d..8a5316e 100644 --- a/source/main.c +++ b/source/main.c @@ -46,15 +46,13 @@ main(int argc, char** argv) load_config(); // Load configuration. - config.options[OPTION_SAVE_LOGS] = 1; - if (CFG_BOOTENV == 7) { fprintf(stderr, "Rebooted from AGB, disabling EmuNAND.\n"); 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_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; diff --git a/source/menu.c b/source/menu.c index 1392b59..6e8adc5 100644 --- a/source/menu.c +++ b/source/menu.c @@ -11,7 +11,7 @@ uint8_t *enable_list = (uint8_t *)FCRAM_PATCHLIST_LOC; static struct options_s options[] = { // Patches. - { 0, "\x1b[32;40mGeneral Options\x1b[0m", "", not_option, 0, 0 }, + { 0, "General Options", "", not_option, 1, 0 }, { OPTION_SVCS, "svcBackdoor Fixup", "Reinserts svcBackdoor on 11.0 NATIVE_FIRM. svcBackdoor allows executing arbitrary functions with ARM11 kernel permissions, and is required by some (poorly coded) applications.", boolean_val, 0, 0 }, @@ -25,10 +25,12 @@ static struct options_s options[] = { { OPTION_SILENCE, " Silent mode", "Suppress all debug output during autoboot. You'll see the screen turn on and then off once.", boolean_val, 0, 0 }, { OPTION_DIM_MODE, "Dim Background", "Experimental! Dims colors on lighter backgrounds to improve readability with text. You won't notice the change until scrolling or exiting the current menu due to the way rendering works.", boolean_val, 0, 0 }, + { OPTION_ACCENT_COLOR, "Accent color", "Changes the accent color in menus.", ranged_val, 1, 7}, + // space { 0, "", "", not_option, 0, 0 }, // Patches. - { 0, "\x1b[32;40mLoader Options\x1b[0m", "", not_option, 0, 0 }, + { 0, "Loader Options", "", not_option, 1, 0 }, { OPTION_LOADER, "Use Loader Replacement", "Replaces loader with one capable of extra features. You should enable this even if you don't plan to use loader-based patches to kill ASLR and the Ninjhax/OOThax checks.", boolean_val, 0, 0 }, { OPTION_LOADER_CPU_L2, " CPU - L2 cache", "Forces the system to use the L2 cache on all applications. If you have issues with crashes, try turning this off.", boolean_val_n3ds, 0, 0 }, @@ -45,7 +47,7 @@ static struct options_s options[] = { // space { 0, "", "", not_option, 0, 0 }, // Patches. - { 0, "\x1b[32;40mDeveloper Options\x1b[0m", "", not_option, 0, 0 }, + { 0, "Developer Options", "", not_option, 1, 0 }, { OPTION_TRACE, "Step Through", "After each important step, [WAIT] will be shown and you'll need to press a key. Debug feature.", boolean_val, 0, 0 }, { OPTION_OVERLY_VERBOSE, "Verbose", "Output more debug information than the average user needs.", boolean_val, 0, 0 }, @@ -61,12 +63,15 @@ static struct options_s options[] = { extern unsigned int font_w; +void accent_color(void* screen, int fg); + void header(char *append) { set_cursor(TOP_SCREEN, 0, 0); - fill_line(stdout, 0, 0x2); - fprintf(stdout, "\x1b[30;42m ." FW_NAME " // %s\x1b[0m\n\n", append); + 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); } static int current_menu_index_patches = 0; @@ -140,11 +145,11 @@ list_patches_build(char *name, int desc_is_fname) memset(enable_list, 0, FCRAM_SPACING / 2); if (!desc_is_fname) { - strncpy(patches[0].name, "\x1b[40;32mPatches\x1b[0m", 64); + strncpy(patches[0].name, "Patches", 64); strncpy(patches[0].desc, "", 255); patches[0].index = 0; patches[0].allowed = not_option; - patches[0].a = 0; + patches[0].a = 1; patches[0].b = 0; current_menu_index_patches += 1; diff --git a/source/std/draw.c b/source/std/draw.c index 89b1693..d2c7ae5 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -356,9 +356,9 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co screen[pos + 2] = buffer_bg[pos + 2] - dim_factor; } } else { - screen[pos] = color_bg >> 16; + screen[pos] = color_bg; screen[pos + 1] = color_bg >> 8; - screen[pos + 2] = color_bg; + screen[pos + 2] = color_bg >> 16; } if (char_dat & 0x80) { @@ -379,9 +379,9 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co screen[pos + 2] = buffer_bg[pos + 2] - dim_factor; } } else { - screen[pos] = color_fg >> 16; + screen[pos] = color_fg; screen[pos + 1] = color_fg >> 8; - screen[pos + 2] = color_fg; + screen[pos + 2] = color_fg >> 16; } } -- 2.39.5