]> Chaos Git - corbenik/corbenik.git/commitdiff
Multiple changes (again)
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 7 Jun 2016 21:08:09 +0000 (17:08 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 7 Jun 2016 21:08:09 +0000 (17:08 -0400)
 * Fix up patches. Specify rel in all of them for sanity purposes
 * Fix up some misc shit in the interpreter and add OP_N3DS (to check if N3DS, obviously)
 * Fix a bunch of bugs in the assembler.
 * Hide n3ds-only options on o3ds
 * Stability

20 files changed:
host/bytecode_asm.py
patch/agb_sig.pco
patch/block_cart_update.pco
patch/block_eshop_update.pco
patch/block_nim_update.pco
patch/errdisp.pco
patch/friends_ver.pco
patch/memexec.pco
patch/mset_str.pco
patch/ns_force_menu.pco
patch/regionfree.pco
patch/ro_sigs.pco
patch/secinfo_sigs.pco
patch/unitinfo.pco
source/config.h
source/display.c
source/firm/firm.c
source/interp.c
source/main.c
source/menu.c

index 27d1c3587d9f8ad84cd26d7286b9201cd47d108b..a60fd734adae0d01e9d326f0fdf7d53864e1ae73 100755 (executable)
@@ -109,7 +109,7 @@ def parse_op(token_list, instr_offs):
                index = rel_name(token_list[1])
                if index == "-1":
                        # TODO - Check if an integer was passed.
-                       syn_error("invalid argument")
+                       syn_err("invalid argument")
 
                return bytearray.fromhex("01" + index)
        elif token_list[0] == "find":
@@ -147,8 +147,7 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
                        val.reverse()
                        return bytearray.fromhex("07") + val
@@ -198,9 +197,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("17") + val
        elif token_list[0] == "jmpne":
                if s != 2:
@@ -209,9 +208,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("27") + val
        elif token_list[0] == "jmplt":
                if s != 2:
@@ -220,9 +219,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("37") + val
        elif token_list[0] == "jmpgt":
                if s != 2:
@@ -231,9 +230,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("47") + val
        elif token_list[0] == "jmple":
                if s != 2:
@@ -242,9 +241,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("57") + val
        elif token_list[0] == "jmpge":
                if s != 2:
@@ -253,9 +252,9 @@ def parse_op(token_list, instr_offs):
                if instr_offs == None:
                        return bytearray.fromhex("070000")
                else:
-                       tok = bytearray.fromhex(token_list[1])
-                       num = struct.unpack(">H", tok)[0]
+                       num = int(token_list[1])
                        val = bytearray(struct.pack(">H", instr_offs[num]))
+                       val.reverse()
                        return bytearray.fromhex("67") + val
 
 def pad_zero_r(x, c):
@@ -310,7 +309,7 @@ with open(in_file, "r") as ins:
                                offsets += [size]
                                size += len(bytes)
 
-               offsets += [size+1] # So we can jump past the last instruction for 'exit' type behavior
+               offsets += [size] # So we can jump past the last instruction for 'exit' type behavior
                lines = 0
 
                ins.seek(0)
index c0c43732907a2fe11f10440494547735748d4ae4..869164eb31b35e088c1e13f537d2e959107df172 100644 (file)
@@ -10,42 +10,27 @@ rel agb
 
 # #############################
 
-# Sigs (1)
+# New3DS Sigs (1)
 seek  0009DF64
 test  C117491C31D0
-jmpne 0006
+jmpne 8
 set   00204EB070BD
-jmp   000D
 
-# OLD3DS Sigs (6)
-seek  0009D2A8
-test  C117491C31D0
-jmpne 000B
-set   00204EB070BD
-jmp   000D
-# Failed to set sigcheck.
-
-# Abort due to failure. (11)
-rewind
-back  01
-
-# The above rewinds the file and moves backwards
-# one byte (which triggers the underflow error in
-# the VM)
-
-# ##############################
-
-# Bootscreen (13)
+# Bootscreen (5)
 seek  000D8B8A
-test  01
-jmpne 0012
 set   26
-jmp   0016
+jmp   12
+
+#########################
+
+# OLD3DS Sigs (8)
+seek  0009D2A8
+set   00204EB070BD
 
-# OLD3ds bootscreen (18)
+# OLD3ds bootscreen (10)
 seek  000D7A12
-test  01
-jmpne 000B
 set   26
 
-# End (22)
+# #######################
+
+# End (12)
index 50e427908b8b8408e36946541bc9daf1e22336bc..657590a49d4f4484add28b63f44765ae30d264f7 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  01
 
+rel exe_text
+
 # Status: needs loader
 
 find 0C18E1D8
index 303c357c8820e18e8fa9ce954c2f642cd9eab137..426f319d3a501336d35e05f0765dadb1dade2e2d 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  02
 
+rel exe_text
+
 # Status: needs loader
 
 find 30B5F1B0
index f81587dc45f248bffa3ee8c8315623abd108b939..97c45e7154e88a71ef7a93377ef7616d854109b0 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  03
 
+rel exe_text
+
 # Status: needs loader
 
 find 25790B99
index 37e357d327a948fd0029df83c47670d740edd04c..812c688e7e961cd5614ef0a7d875d1649c6d29ea 100644 (file)
@@ -5,6 +5,8 @@
 # $uuid  04
 # $flags devmode
 
+rel exe_text
+
 # Status: needs loader
 
 find 1400D0E5DB9A9FED
index 942afc8bb74cb364f7583081df621f32bb29f47c..1e99c4438d18b3b74aff84787151a4e5eea299e6 100644 (file)
@@ -5,6 +5,8 @@
 # $uuid  05
 # $flags noabort
 
+rel exe_text
+
 # Status: needs loader
 
 find E01EFF2FE1010101
index 37ceca35a097f11b0ab8e1991967f0e631cb92ac..7fb5b61d43c4c13dae5e150699ccb3270c79a36d 100644 (file)
@@ -5,15 +5,15 @@
 # $flags devmode
 
 # 0: Relative to NATIVE_FIRM, section index [1]
-rel native_s1
+rel    native_s1
 
 # 1: Find this byte string.
-find 9705000015E40000
+find   9705000015E40000
 
 # Move backwards until we find what we want.
 # LOOP (2):
 back   04
 test   16640100
-jmpne  0002
+jmpne  2
 
-and  efff
+and    ef
index a1b3bb3274d54a50c54a38b442add0b24621880b..9c8ea043f90a12f76ac27207144220930fb9cd73 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  07
 
+rel exe_text
+
 # Status: needs loader
 
 # u"Ver."
index 1e4847e9f114b1ee69df7ef3ef0ed8454ab0ec21..f463260d953e4f0686673da8fb1b70ed53f88913 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  1e
 
+rel exe_text
+
 # This was originally based on the code from @Reisyukaku's pastebin.
 
 # Suggestion from @TuxSH / @Steveice10.
index 0badc5d3f4dbf74377012e133d241d84101f1273..67e62029b57410eb19275bf8e669829af559016b 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  09
 
+rel exe_text
+
 # Status: needs loader
 
 find 000055E30110A0E3
index 69f283172ff1ebe317f618135fd016d926f3d72e..e1ef8adfb628dd2670659c22916b4baef5068882 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  0a
 
+rel exe_text
+
 # Status: needs loader
 
 find 30402DE90250A0E1
index 6fe262e380024522a1ea0179916b532cdcf36ba8..3adc642fbf4a0c7bdc128e12c3dbaa51df514ab6 100644 (file)
@@ -4,6 +4,8 @@
 # $ver   01
 # $uuid  0b
 
+rel exe_text
+
 # Status: needs loader
 
 find 06461048FC
index 4738101a565c95b1839763368cbd21b701292ea2..20e073ad8f3503de3a996a50859586bae178043c 100644 (file)
@@ -7,6 +7,7 @@
 # Status: untested, but should work
 
 rel  native_s2
+
 find 0110A013
 fwd  03
 set  E3
index 4c1d0cf5d409b9259531034fb16fe96c17b79228..f89a2c2edf270efd72229d9e778605454419372f 100644 (file)
@@ -30,11 +30,12 @@ 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 = 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
 };
 
 struct range_str
index d7ad66331882bf4527ae4ff59ad58ab8cdcaadfc..892acb24114f8f16ec4c01a940e1c5769d820925 100644 (file)
@@ -13,6 +13,8 @@
 
 void header(char *append);
 
+extern int is_n3ds;
+
 int
 show_menu(struct options_s *options, uint8_t *toggles)
 {
@@ -55,7 +57,7 @@ show_menu(struct options_s *options, uint8_t *toggles)
 
         int i = 0;
         while (options[i].index != -1) { // -1 Sentinel.
-            if (options[i].allowed == boolean_val) {
+            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
@@ -92,26 +94,26 @@ show_menu(struct options_s *options, uint8_t *toggles)
         switch (key) {
             case BUTTON_UP:
                 cursor_y -= 1;
-                while (options[cursor_y].allowed == not_option && cursor_y >= cursor_min)
+                while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min)
                     cursor_y--;
                 break;
             case BUTTON_DOWN:
                 cursor_y += 1;
-                while (options[cursor_y].allowed == not_option && cursor_y < cursor_max)
+                while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max)
                     cursor_y++;
                 break;
             case BUTTON_LEFT:
                 cursor_y -= 5;
-                while (options[cursor_y].allowed == not_option && cursor_y >= cursor_min)
+                while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min)
                     cursor_y--;
                 break;
             case BUTTON_RIGHT:
                 cursor_y += 5;
-                while (options[cursor_y].allowed == not_option && cursor_y < cursor_max)
+                while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max)
                     cursor_y++;
                 break;
             case BUTTON_A:
-                if (options[cursor_y].allowed == boolean_val) {
+                if (options[cursor_y].allowed == boolean_val || options[cursor_y].allowed == boolean_val_n3ds) {
                     toggles[options[cursor_y].index] = !toggles[options[cursor_y].index];
                 } else if (options[cursor_y].allowed == ranged_val) {
                     if (toggles[options[cursor_y].index] == options[cursor_y].b)
index 242c1304c4aa56952cb13e4a5f37516d419b253c..779443772dbf640e4d293f5eb10162525870552d 100644 (file)
@@ -423,6 +423,13 @@ void
 boot_cfw()
 {
     fprintf(BOTTOM_SCREEN, "Loading firmware...\n");
+
+    if (config.options[OPTION_RECONFIGURED]) {
+        config.options[OPTION_RECONFIGURED] = 0;
+        save_config();
+        config.options[OPTION_RECONFIGURED] = 1;
+    }
+
     load_firms();
 
     if (config.options[OPTION_RECONFIGURED]) {
@@ -446,10 +453,5 @@ boot_cfw()
             abort("Failed to save prepatched agb\n");
     }
 
-    if (config.options[OPTION_RECONFIGURED]) {
-        config.options[OPTION_RECONFIGURED] = 0;
-        save_config();
-    }
-
     boot_firm();
 }
index ff1a1de1b331d155e37f3f0ae5034471a39bacae..21b940762c9e246fff361970f758c3228c8b548e 100644 (file)
@@ -24,6 +24,7 @@
 #define OP_VER 0x0D
 #define OP_CLF 0x0E
 #define OP_SEEK 0x0F
+#define OP_N3DS 0x10
 
 #define OP_JMPEQ 0x17
 #define OP_JMPNE 0x27
@@ -54,6 +55,12 @@ struct mode
 struct mode modes[21];
 int init_bytecode = 0;
 
+#ifndef LOADER
+extern int is_n3ds;
+#else
+int is_n3ds = 1; // TODO - We don't really need to care, but it should still work from loader
+#endif
+
 int
 exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
 {
@@ -328,6 +335,13 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
                 eq = !eq;
                 code += 2;
                 break;
+            case OP_N3DS:
+                if (debug)
+                    log("ver\n");
+                code++;
+                eq = is_n3ds;
+                code += 2;
+                break;
             case OP_SEEK: // Jump to offset if greater than or equal
                 if (debug)
                     log("seek\n");
index 18669f8d1615236f71f7b535e816acdfcbfafd16..2c88764ff04f63db04c2ec07b53cb28d6efd804b 100644 (file)
@@ -7,12 +7,19 @@
 
 int menu_handler();
 
+int is_n3ds = 0;
+
 int doing_autoboot = 0;
 void shut_up();
 
+#define CONFIG_PLATFORM_REG ((volatile uint32_t*)0x10140FFC)
+
 int
 main()
 {
+       if (*CONFIG_PLATFORM_REG == 7)
+               is_n3ds = 1;
+
     int c = fmount();
     screen_init();
 
index 7275301f9a4176951232339fb34d99dc8530530f..f0dd19d714e77cc22fca3af77969aef396b3e1ce 100644 (file)
@@ -39,8 +39,8 @@ static struct options_s options[] = {
     { 0, "\x1b[32;40mLoader Options\x1b[0m", "", not_option, 0, 0 },
 
     { OPTION_LOADER, "Use Loader Replacement", "Replaces loader with one capable of the below and also applying bytecode patches.", boolean_val, 0, 0 },
-    { OPTION_LOADER_CPU_L2, "  CPU - L2 cache (n3ds)", "Forces the system to use the L2 cache. Ignored if not a N3DS.", boolean_val, 0, 0 },
-    { OPTION_LOADER_CPU_800MHZ, "  CPU - 800Mhz (n3ds)", "Forces the system to run in 800Mhz mode. Ignored if not a N3DS.", boolean_val, 0, 0 },
+    { OPTION_LOADER_CPU_L2, "  CPU - L2 cache (n3ds)", "Forces the system to use the L2 cache. Ignored if not a N3DS.", boolean_val_n3ds, 0, 0 },
+    { OPTION_LOADER_CPU_800MHZ, "  CPU - 800Mhz (n3ds)", "Forces the system to run in 800Mhz mode. Ignored if not a N3DS.", boolean_val_n3ds, 0, 0 },
     { OPTION_LOADER_LANGEMU, "  Language Emulation", "Reads language emulation configuration and imitates the region/language.", boolean_val, 0, 0 },
 
     { OPTION_LOADER_DUMPCODE, "  Dump Code Sections (dev)",
@@ -278,6 +278,10 @@ menu_help()
 int
 menu_reset()
 {
+    write_file(enable_list, PATH_TEMP "/PATCHENABLE", FCRAM_SPACING / 2);
+    config.options[OPTION_RECONFIGURED] = 1;
+       save_config(); // Save config, including the reconfigured flag.
+
     fumount(); // Unmount SD.
 
     // Reboot.
@@ -290,6 +294,10 @@ menu_reset()
 int
 menu_poweroff()
 {
+    write_file(enable_list, PATH_TEMP "/PATCHENABLE", FCRAM_SPACING / 2);
+    config.options[OPTION_RECONFIGURED] = 1;
+       save_config(); // Save config, including the reconfigured flag.
+
     fumount(); // Unmount SD.
 
     // Reboot.