From 20ae01ac1f9e4533a8108169adfde6499ee3f88f Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Tue, 14 Jun 2016 16:09:33 -0400 Subject: [PATCH] Update menu code - fix a crash in wait() --- source/display.c | 4 ++-- source/menu.c | 34 +++++++++++++++++++++++++--------- source/patcher.c | 8 ++++---- source/std/abort.h | 4 ++-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/source/display.c b/source/display.c index 68fa67a..1228ce5 100644 --- a/source/display.c +++ b/source/display.c @@ -30,7 +30,7 @@ show_menu(struct options_s *options, uint8_t *toggles) set_cursor(TOP_SCREEN, 0, 0); header("Any:Back"); fprintf(stdout, "No entries.\n"); - wait_key(); + wait_key(1); return 0; } @@ -101,7 +101,7 @@ show_menu(struct options_s *options, uint8_t *toggles) need_redraw = 0; - uint32_t key = wait_key(); + uint32_t key = wait_key(1); switch (key) { case BUTTON_UP: diff --git a/source/menu.c b/source/menu.c index f00c217..4e27199 100644 --- a/source/menu.c +++ b/source/menu.c @@ -7,8 +7,6 @@ struct options_s *patches = (struct options_s *)FCRAM_MENU_LOC; uint8_t *enable_list = (uint8_t *)FCRAM_PATCHLIST_LOC; static struct options_s options[] = { - // space - { 0, "", "", not_option, 0, 0 }, // Patches. { 0, "\x1b[32;40mGeneral Options\x1b[0m", "", not_option, 0, 0 }, @@ -61,10 +59,12 @@ static int need_redraw = 1; extern void waitcycles(uint32_t cycles); uint32_t -wait_key() +wait_key(int sleep) { - #define ARM9_APPROX_DELAY_MAX 134058675 / 85 - waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) + if (sleep) { + #define ARM9_APPROX_DELAY_MAX 134058675 / 85 + waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) + } uint32_t ret = 0, get = 0; while (ret == 0) { @@ -94,7 +94,9 @@ wait_key() void header(char *append) { - fprintf(stdout, "\x1b[30;42m.corbenik//%s %s\x1b[0m\n", VERSION, append); + fprintf(stdout, "\x1b[30;42m "); + set_cursor(TOP_SCREEN, 0, 0); + fprintf(stdout, "\x1b[30;42m Corbenik//%s %s\x1b[0m\n\n", VERSION, append); } static int current_menu_index_patches = 0; @@ -158,6 +160,10 @@ list_patches_build_back(char *fpath, int desc_is_path) return 0; } +// 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(char *name, int desc_is_fname) { @@ -165,6 +171,17 @@ 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].desc, "", 255); + patches[0].index = 0; + patches[0].allowed = not_option; + patches[0].a = 0; + patches[0].b = 0; + + current_menu_index_patches += 1; + } + char fpath[256]; strncpy(fpath, name, 256); list_patches_build_back(fpath, desc_is_fname); @@ -214,7 +231,7 @@ menu_info() " Version: %s (%x)\n", native->version_string, native->version, agb->version_string, agb->version, twl->version_string, twl->version); - wait_key(); + wait_key(1); need_redraw = 1; clear_screen(TOP_SCREEN); @@ -246,7 +263,7 @@ menu_help() " \n" "\n"); - wait_key(); + wait_key(1); need_redraw = 1; clear_screen(TOP_SCREEN); @@ -277,7 +294,6 @@ poweroff() } static struct options_s main_s[] = { - // space { 0, "Options", "", call_fun, (uint32_t)menu_options, 0 }, { 0, "Patches", "", call_fun, (uint32_t)menu_patches, 0 }, { 0, "Info", "", call_fun, (uint32_t)menu_info, 0 }, diff --git a/source/patcher.c b/source/patcher.c index a203a34..3a3c277 100644 --- a/source/patcher.c +++ b/source/patcher.c @@ -9,7 +9,7 @@ // TODO - Basically all this needs to move to patcher programs. -uint32_t wait_key(); +uint32_t wait_key(int sleep); extern int patch_services(); extern int patch_modules(); @@ -23,10 +23,10 @@ void wait() { if (config.options[OPTION_TRACE] && !doing_autoboot) { - fprintf(stderr, " [WAIT]"); - wait_key(); + fprintf(stderr, "[Waiting...]"); + wait_key(0); // No delay on traces. } - fprintf(stderr, "\r \r"); + fprintf(stderr, " \r"); } void list_patches_build(char *name, int desc_is_fname); diff --git a/source/std/abort.h b/source/std/abort.h index ff8919e..1d03ab7 100644 --- a/source/std/abort.h +++ b/source/std/abort.h @@ -4,12 +4,12 @@ #include "draw.h" void poweroff(); -uint32_t wait_key(); +uint32_t wait_key(int sleep); #define abort(x...) \ { \ fprintf(stderr, x); \ - wait_key(); \ + wait_key(1); \ clear_disp(stderr); \ set_cursor(stderr, 0, 0); \ poweroff(); \ -- 2.39.5