summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..c219831
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,51 @@
+#include "util.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __3DS__
+
+#include <3ds.h>
+
+static void panic_begin(void) { consoleInit(GFX_TOP, NULL); }
+
+static noreturn void panic(void) {
+ printf("\nPress Start to exit.\n");
+
+ while (aptMainLoop()) {
+ hidScanInput();
+ u32 keys = hidKeysDown();
+ if (keys & KEY_START)
+ break;
+ gfxFlushBuffers();
+ gfxSwapBuffers();
+ gspWaitForVBlank();
+ }
+
+ gfxExit();
+ exit(1);
+}
+
+#else
+
+static void panic_begin(void) {}
+
+static noreturn void panic(void) { abort(); }
+
+#endif
+
+noreturn void assume__failed(const char *file, int line, const char *expr) {
+ panic_begin();
+ fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
+ panic();
+}
+
+noreturn void todo__impl(const char *file, int line, const char *fmt, ...) {
+ panic_begin();
+ printf("%s:%d: TODO: ", file, line);
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ panic();
+}