]> Chaos Git - corbenik/corbenik.git/commitdiff
General cleanup
authorchaoskagami <chaos.kagami@gmail.com>
Sat, 2 Jul 2016 17:04:48 +0000 (13:04 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sat, 2 Jul 2016 17:04:48 +0000 (13:04 -0400)
source/input.c [new file with mode: 0644]
source/input.h
source/interp.c
source/menu.c
source/std/abort.c [new file with mode: 0644]
source/std/abort.h
source/std/draw.h

diff --git a/source/input.c b/source/input.c
new file mode 100644 (file)
index 0000000..0fbdd26
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdint.h>
+#include "std/unused.h"
+#include "std/draw.h"
+#include "input.h"
+
+extern void waitcycles(uint32_t cycles);
+
+uint32_t
+wait_key(_UNUSED int sleep)
+{
+    // If your dpad has issues, please add this to the makefile.
+    if (sleep) {
+        #define ARM9_APPROX_DELAY_MAX 134058675 / 95
+        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) {
+        get = HID_PAD;
+
+        if ((get & (BUTTON_L | BUTTON_R | BUTTON_STA)) == (BUTTON_L | BUTTON_R | BUTTON_STA)) {
+            screenshot();
+            waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!)
+        } else if (get & BUTTON_UP)
+            ret = BUTTON_UP;
+        else if (get & BUTTON_DOWN)
+            ret = BUTTON_DOWN;
+        else if (get & BUTTON_RIGHT)
+            ret = BUTTON_RIGHT;
+        else if (get & BUTTON_LEFT)
+            ret = BUTTON_LEFT;
+        else if (get & BUTTON_A)
+            ret = BUTTON_A;
+        else if (get & BUTTON_B)
+            ret = BUTTON_B;
+        else if (get & BUTTON_X)
+            ret = BUTTON_X;
+        else if (get & BUTTON_SEL)
+            ret = BUTTON_SEL;
+
+    }
+    while (HID_PAD & ret);
+
+    return ret;
+}
+
index fbe44564224ef3233d72405b8a2fc10fff427d1f..4051a83221ad703df00b1ddc7c4fabd920b04173 100644 (file)
@@ -20,4 +20,6 @@
 
 #define HID_PAD ((*(volatile uint32_t *)0x10146000) ^ BUTTON_ANY)
 
+uint32_t wait_key(_UNUSED int sleep);
+
 #endif
index 855d21f482e628e4a63624b728e8b39b4a373c9d..991a4c1728cda72e4420de95b03ff80d3b2bf385 100644 (file)
 #define OP_NEXT 0xFF
 
 #ifdef LOADER
-#define log(a) logstr(a)
-#define abort(a)                                                                                                                                               \
-    {                                                                                                                                                          \
-        logstr(a);                                                                                                                                             \
-        svcBreak(USERBREAK_ASSERT);                                                                                                                            \
-    }
+  #define log(a) logstr(a)
+  #define abort(a)                                                                                                                                               \
+      {                                                                                                                                                          \
+          logstr(a);                                                                                                                                             \
+          svcBreak(USERBREAK_ASSERT);                                                                                                                            \
+      }
 #else
-#define log(a) fprintf(stderr, a)
-int wait();
+  #define log(a) fprintf(stderr, a)
+  int wait();
 #endif
 
 struct mode
@@ -459,49 +459,49 @@ exec_bytecode(uint8_t *bytecode, uint32_t len, uint8_t* stack, uint32_t stack_si
                 if (debug)
                     log("abort\n");
 
-                abort("abort triggered, halting VM!\n")
+                abort("abort triggered, halting VM!\n");
                 break;
             case OP_ABORTEQ:
                 code++;
                 if (debug)
                     log("aborteq\n");
                 if (eq)
-                    abort("eq flag not set, halting VM!\n")
+                    abort("eq flag not set, halting VM!\n");
                 break;
             case OP_ABORTNE:
                 code++;
                 if (debug)
                     log("abortlt\n");
                 if (!eq)
-                    abort("eq flag not set, halting VM!\n")
+                    abort("eq flag not set, halting VM!\n");
                 break;
             case OP_ABORTLT:
                 code++;
                 if (debug)
                     log("abortlt\n");
                 if (lt)
-                    abort("lt flag set, halting VM!\n")
+                    abort("lt flag set, halting VM!\n");
                 break;
             case OP_ABORTGT:
                 code++;
                 if (debug)
                     log("abortgt\n");
                 if (gt)
-                    abort("gt flag set, halting VM!\n")
+                    abort("gt flag set, halting VM!\n");
                 break;
             case OP_ABORTF:
                 code++;
                 if (debug)
                     log("abortf\n");
                 if (found)
-                    abort("f flag set, halting VM!\n")
+                    abort("f flag set, halting VM!\n");
                 break;
             case OP_ABORTNF:
                 code++;
                 if (debug)
                     log("abortnf\n");
                 if (!found)
-                    abort("f flag is not set, halting VM!\n")
+                    abort("f flag is not set, halting VM!\n");
                 break;
             case OP_NEXT:
                 if (debug) {
index 03e18063929667302f27f41b963112af82fdac0f..a3f33cf797297177b0210286e93a7af1fae85f79 100644 (file)
@@ -57,47 +57,6 @@ static struct options_s options[] = {
     { -1, "", "", 0, -1, -1 }, // cursor_min and cursor_max are stored in the last two.
 };
 
-extern void waitcycles(uint32_t cycles);
-
-uint32_t
-wait_key(_UNUSED int sleep)
-{
-    // If your dpad has issues, please add this to the makefile.
-    if (sleep) {
-        #define ARM9_APPROX_DELAY_MAX 134058675 / 95
-        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) {
-        get = HID_PAD;
-
-        if ((get & (BUTTON_L | BUTTON_R | BUTTON_STA)) == (BUTTON_L | BUTTON_R | BUTTON_STA)) {
-            screenshot();
-            waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!)
-        } else if (get & BUTTON_UP)
-            ret = BUTTON_UP;
-        else if (get & BUTTON_DOWN)
-            ret = BUTTON_DOWN;
-        else if (get & BUTTON_RIGHT)
-            ret = BUTTON_RIGHT;
-        else if (get & BUTTON_LEFT)
-            ret = BUTTON_LEFT;
-        else if (get & BUTTON_A)
-            ret = BUTTON_A;
-        else if (get & BUTTON_B)
-            ret = BUTTON_B;
-        else if (get & BUTTON_X)
-            ret = BUTTON_X;
-        else if (get & BUTTON_SEL)
-            ret = BUTTON_SEL;
-
-    }
-    while (HID_PAD & ret);
-
-    return ret;
-}
-
 extern unsigned int font_w;
 
 void
diff --git a/source/std/abort.c b/source/std/abort.c
new file mode 100644 (file)
index 0000000..414e37a
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __ABORT_H
+#define __ABORT_H
+
+#include <stdarg.h>
+#include "draw.h"
+
+void poweroff();
+uint32_t wait_key(int sleep);
+
+void abort(const char* x, ...) {
+    va_list ap;
+    va_start(ap, x);
+
+    vfprintf(stderr, x, ap);
+
+    va_end(ap);
+
+    wait_key(1);
+    clear_disp(stderr);
+    set_cursor(stderr, 0, 0);
+    poweroff();
+}
+
+#endif
index b0e0bca9e7b6ce362951cba0091c84382cc44dcd..b90919373c68ad191f5a1fd5b1b4ef3985f58cdc 100644 (file)
@@ -1,18 +1,6 @@
 #ifndef __ABORT_H
 #define __ABORT_H
 
-#include "draw.h"
-
-void poweroff();
-uint32_t wait_key(int sleep);
-
-#define abort(x...)                                                                                                                                            \
-    {                                                                                                                                                          \
-        fprintf(stderr, x);                                                                                                                                    \
-        wait_key(1);                                                                                                                                           \
-        clear_disp(stderr);                                                                                                                                    \
-        set_cursor(stderr, 0, 0);                                                                                                                              \
-        poweroff();                                                                                                                                            \
-    }
+void abort(const char* x, ...);
 
 #endif
index 4a4024206247bdb7051dd52bceff083c61ddce33..61fdbfef796bdc105a7bbd9ea7dc953a70e552f1 100644 (file)
@@ -5,6 +5,7 @@
    It isn't perfect, but it does work. */
 
 #include <stdint.h>
+#include <stdarg.h>
 
 #define TOP_WIDTH 400
 #define TOP_HEIGHT 240
@@ -81,6 +82,8 @@ void clear_disp(uint8_t *screen);
 //  eventually)
 void fprintf(void *channel, const char *format, ...);
 
+void vfprintf(void *channel, const char *format, va_list ap);
+
 #define BLACK 0
 #define BLUE 1
 #define GREEN 2