From: chaoskagami Date: Sat, 2 Jul 2016 17:04:48 +0000 (-0400) Subject: General cleanup X-Git-Tag: v0.2.0~34 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=316b6c63627ac2f8c254a88686352d6c143f5ad5;p=corbenik%2Fcorbenik.git General cleanup --- diff --git a/source/input.c b/source/input.c new file mode 100644 index 0000000..0fbdd26 --- /dev/null +++ b/source/input.c @@ -0,0 +1,46 @@ +#include +#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; +} + diff --git a/source/input.h b/source/input.h index fbe4456..4051a83 100644 --- a/source/input.h +++ b/source/input.h @@ -20,4 +20,6 @@ #define HID_PAD ((*(volatile uint32_t *)0x10146000) ^ BUTTON_ANY) +uint32_t wait_key(_UNUSED int sleep); + #endif diff --git a/source/interp.c b/source/interp.c index 855d21f..991a4c1 100644 --- a/source/interp.c +++ b/source/interp.c @@ -50,15 +50,15 @@ #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) { diff --git a/source/menu.c b/source/menu.c index 03e1806..a3f33cf 100644 --- a/source/menu.c +++ b/source/menu.c @@ -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 index 0000000..414e37a --- /dev/null +++ b/source/std/abort.c @@ -0,0 +1,24 @@ +#ifndef __ABORT_H +#define __ABORT_H + +#include +#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 diff --git a/source/std/abort.h b/source/std/abort.h index b0e0bca..b909193 100644 --- a/source/std/abort.h +++ b/source/std/abort.h @@ -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 diff --git a/source/std/draw.h b/source/std/draw.h index 4a40242..61fdbfe 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -5,6 +5,7 @@ It isn't perfect, but it does work. */ #include +#include #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