]> Chaos Git - corbenik/corbenik.git/commitdiff
Access all options via accessor functions (toplevel)
authorchaoskagami <chaos.kagami@gmail.com>
Sun, 28 Aug 2016 09:02:16 +0000 (05:02 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sun, 28 Aug 2016 09:02:16 +0000 (05:02 -0400)
include/option.h
source/Makefile.am
source/arm11.c
source/config-backend-file.c [moved from source/config-file.c with 74% similarity]
source/input.c
source/interpreter.c
source/main.c
source/menu-backend.c
source/menu.c
source/patcher.c

index 422e3a6a4f1a9d3875adcea2dbca3bfc60e721b9..4509622c1a3f1614da2095e6ce32689f92855372 100644 (file)
@@ -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
index 0e28efd9b63e7f74810c08222c03f17e278ae203..8fac0917f9a131184ae47694153bd95f3689ea8c 100644 (file)
@@ -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
index 9a447d13203a29fd99df716ecacb2d7f3be62ec2..e349a5a5738ade97c114655fab5df37c7d979fbb 100644 (file)
@@ -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)
similarity index 74%
rename from source/config-file.c
rename to source/config-backend-file.c
index de394d3892f9025357cbe41bd36a458e9848015c..fb1cf5102e92c4a8f75dea0ef05cc9ea62daeb98 100644 (file)
@@ -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;
+}
index 9d940035528ca442bf3aec90e04a5ae7f796c6a8..9b76299517cc8c844ca2ef5f35c87881711e8f59 100644 (file)
@@ -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.
     }
index 35e3e3fc3c846060b05cc7f7231f072f58aa4cbf..6668eac1b77d0db7cd032054bbaa49cd076a90dc 100644 (file)
@@ -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;
     }
index 43855d813314d6de508a6c7a40b16c8f143948c7..e54ca96798bef03846201170349aa8331691b7ee 100644 (file)
@@ -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();
index e77a488e5b0a8b1a72a089b05c9fc59760bd1c92..5f424d3514759916847bec95d73dd8f6f002817d 100644 (file)
@@ -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);
 }
 
index cca47d8a40206213d0568cfa579b1822e29a3e12..f1e5f6be2b9054aad1314bc5dc4a6c231ec4dd4f 100644 (file)
@@ -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 },
index decebea270b0eedb67dbd764f4eeef4863e8cb83..5675f8eb3ee46b25dc5b6ed9711f55ff9c345b08 100644 (file)
@@ -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;
 }