]> Chaos Git - corbenik/corbenik.git/commitdiff
Make the toplevel menu use the same menuing code (and implement a few required bits.)
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 13 Jun 2016 21:09:05 +0000 (17:09 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 13 Jun 2016 21:11:21 +0000 (17:11 -0400)
source/config.h
source/display.c
source/main.c
source/menu.c

index 100822acb0455ed71cbe69dedcb8d297abd01518..9c9b0e07de0f32813ea3693a04664cc172e39c7f 100644 (file)
@@ -30,14 +30,17 @@ extern struct config_file config;
 
 enum type
 {
-    boolean_val = 0,     // Toggle
-    ranged_val = 1,      // N1 - N2, left and right to pick.
-    mask_val = 2,        // Bitmask allowed values.
-    not_option = 3,      // Skip over this.
-    call_fun = 4,        // Call a function. Treat (a) as (void)(*)(void).
-    boolean_val_n3ds = 5 // Toggle, but only show on n3DS
+    boolean_val = 0,      // Toggle
+    ranged_val = 1,       // N1 - N2, left and right to pick.
+    mask_val = 2,         // Bitmask allowed values.
+    not_option = 3,       // Skip over this.
+    call_fun = 4,         // Call a function. Treat (a) as (void)(*)(void).
+    boolean_val_n3ds = 5, // Toggle, but only show on n3DS
+    break_menu = 6
 };
 
+typedef void (*func_call_t)(void);
+
 struct range_str
 {
     int a, b;
index 892acb24114f8f16ec4c01a940e1c5769d820925..68fa67a4a93229e5599c777f915fe96bdb715651 100644 (file)
@@ -24,6 +24,8 @@ show_menu(struct options_s *options, uint8_t *toggles)
     int cursor_max = -1;
     int exit = 0;
 
+    clear_screen(TOP_SCREEN);
+
     if (options[0].index == -1) {
         set_cursor(TOP_SCREEN, 0, 0);
         header("Any:Back");
@@ -74,6 +76,16 @@ show_menu(struct options_s *options, uint8_t *toggles)
                     putc(TOP_SCREEN, ']');
                     putc(TOP_SCREEN, '\n');
                 }
+            } else if (options[i].allowed == call_fun || options[i].allowed == break_menu) {
+                if (cursor_y == i)
+                    fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m ");
+                else
+                    fprintf(TOP_SCREEN, "   ");
+
+                if (need_redraw)
+                    fprintf(TOP_SCREEN, "%s\n", options[i].name);
+                else
+                    putc(TOP_SCREEN, '\n');
             } else if (options[i].allowed == ranged_val) {
                 if (cursor_y == i)
                     fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m ");
@@ -120,6 +132,12 @@ show_menu(struct options_s *options, uint8_t *toggles)
                         toggles[options[cursor_y].index] = options[cursor_y].a;
                     else
                         toggles[options[cursor_y].index]++;
+                } else if (options[cursor_y].allowed == call_fun) {
+                    ((func_call_t)(options[cursor_y].a))(); // Call 'a' as a function.
+                    need_redraw = 1;
+                } else if (options[cursor_y].allowed == break_menu) {
+                    exit = 1;
+                    need_redraw = 1;
                 }
                 break;
             case BUTTON_X:
@@ -144,5 +162,7 @@ show_menu(struct options_s *options, uint8_t *toggles)
             cursor_y = cursor_min;
     }
 
+    clear_screen(TOP_SCREEN);
+
     return 0;
 }
index a56356a65d76608c9a9864e8794db7ff6df6159c..0034e127c5bf7402771c1758332485351e9a94f6 100644 (file)
@@ -38,12 +38,8 @@ main()
         if (config.options[OPTION_SILENCE])
             shut_up(); // This does exactly what it sounds like.
         doing_autoboot = 1;
-        boot_cfw(); // Just boot shit.
-    }
-
-    int in_menu = 1;
-    while (in_menu) {
-        in_menu = menu_handler();
+    } else {
+        menu_handler();
     }
 
     boot_cfw();
index 1d98f6a4e39cc51744a4483049afc42292685ed7..b69ffa7ad639f919c88ecc84a319aa43060503f0 100644 (file)
@@ -68,8 +68,6 @@ static struct options_s options[] = {
     { -1, "", "", 0, -1, -1 }, // cursor_min and cursor_max are stored in the last two.
 };
 
-static int cursor_y = 0;
-static int which_menu = 1;
 static int need_redraw = 1;
 
 extern void waitcycles(uint32_t cycles);
@@ -300,64 +298,26 @@ int menu_saveconfig() {
        return MENU_MAIN;
 }
 
+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 },
+    { 0, "Help/Readme",        "", call_fun, (uint32_t)menu_help,       0 },
+    { 0, "Reboot",             "", call_fun, (uint32_t)menu_reset,      0 },
+    { 0, "Power off",          "", call_fun, (uint32_t)menu_poweroff,   0 },
+    { 0, "Save Configuration", "", call_fun, (uint32_t)menu_saveconfig, 0 },
+    { 0, "Boot Firmware",      "", break_menu, 0, 0 },
+
+    // Sentinel.
+    { -1, "", "", 0, -1, -1 }, // cursor_min and cursor_max are stored in the last two.
+};
+
 int
 menu_main()
 {
     // TODO - Stop using different menu code here.
-    set_cursor(TOP_SCREEN, 0, 0);
-
-    const char *list[] = { "Options", "Patches", "Info", "Help/Readme", "Reboot", "Power off", "Save Configuration", "Boot Firmware" };
-    int menu_max = 8;
-
-    header("A:Enter DPAD:Nav");
-
-    for (int i = 0; i < menu_max; i++) {
-        if (!(i + 2 == MENU_HELP && config.options[OPTION_READ_ME])) {
-            if (cursor_y == i)
-                fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m ");
-            else
-                fprintf(TOP_SCREEN, "   ");
-
-            if (need_redraw)
-                fprintf(TOP_SCREEN, "%s\n", list[i]);
-            else
-                putc(TOP_SCREEN, '\n');
-        }
-    }
-
-    need_redraw = 0;
-
-    uint32_t key = wait_key();
-
-    int ret = cursor_y + 2;
-
-    switch (key) {
-        case BUTTON_UP:
-            cursor_y -= 1;
-            if (config.options[OPTION_READ_ME] && cursor_y + 2 == MENU_HELP)
-                cursor_y -= 1; // Disable help.
-            break;
-        case BUTTON_DOWN:
-            cursor_y += 1;
-            if (config.options[OPTION_READ_ME] && cursor_y + 2 == MENU_HELP)
-                cursor_y += 1; // Disable help.
-            break;
-        case BUTTON_A:
-            need_redraw = 1;
-            cursor_y = 0;
-            if (ret == MENU_BOOTME)
-                return MENU_BOOTME; // Boot meh, damnit!
-            clear_screen(TOP_SCREEN);
-            if (ret == MENU_OPTIONS)
-                cursor_y = 0; // Fixup positions
-            return ret;
-    }
-
-    // Loop around the cursor.
-    if (cursor_y < 0)
-        cursor_y = menu_max - 1;
-    if (cursor_y > menu_max - 1)
-        cursor_y = 0;
+    show_menu(main_s, NULL);
 
     return 0;
 }
@@ -365,39 +325,5 @@ menu_main()
 int
 menu_handler()
 {
-    int to_menu = 0;
-    switch (which_menu) {
-        case MENU_MAIN:
-            to_menu = menu_main();
-            break;
-        case MENU_OPTIONS:
-            to_menu = menu_options();
-            break;
-        case MENU_PATCHES:
-            to_menu = menu_patches();
-            break;
-        case MENU_INFO:
-            to_menu = menu_info();
-            break;
-        case MENU_HELP:
-            to_menu = menu_help();
-            break;
-        case MENU_SAVECFG:
-            to_menu = menu_saveconfig();
-            break;
-        case MENU_BOOTME:
-            return 0;
-        case MENU_RESET:
-            menu_reset();
-        case MENU_POWER:
-            menu_poweroff();
-        default:
-            fprintf(stderr, "Attempt to enter wrong menu!\n");
-            to_menu = MENU_MAIN;
-    }
-
-    if (to_menu != 0)
-        which_menu = to_menu;
-
-    return 1;
+    return menu_main();
 }