aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-10 17:32:00 +0200
committerkdx <kikoodx@paranoici.org>2023-06-10 18:25:31 +0200
commita44b870228b9dcabfe9a200e4a16182082570160 (patch)
treeab35973e810eba8f2728e68ca5768f7cf3ccc337
parentebdad42105c7d3816e1b54cc68a1d52c5ae7a386 (diff)
downloadorga-a44b870228b9dcabfe9a200e4a16182082570160.tar.gz
improve opcode error message
-rwxr-xr-xbuild.sh2
-rw-r--r--src/orgaemu.c14
2 files changed, 11 insertions, 5 deletions
diff --git a/build.sh b/build.sh
index 14866da..d742611 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-CFLAGS='-std=c99 -Wall -Wextra -O2'
+CFLAGS='-std=c99 -Wall -Wextra -O3 -s'
[ "$CC" = "" ] && CC=gcc
printf 'orgaasm\n'
$CC $CFLAGS -o orgaasm src/orgaasm.c
diff --git a/src/orgaemu.c b/src/orgaemu.c
index f8f642a..a9f29d2 100644
--- a/src/orgaemu.c
+++ b/src/orgaemu.c
@@ -1,4 +1,5 @@
#include "ops.h"
+#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <SDL2/SDL.h>
@@ -57,10 +58,15 @@ fail(void)
}
static void
-error(const char *msg)
+error(const char *fmt, ...)
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "orgaemu", msg, window);
- fprintf(stderr, "%s\n", msg);
+ char buf[256] = {0};
+ va_list va;
+ va_start(va, fmt);
+ vsnprintf(buf, sizeof(buf) - 1, fmt, va);
+ va_end(va);
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "orgaemu", buf, window);
+ fprintf(stderr, "%s\n", buf);
}
static uint16_t
@@ -341,7 +347,7 @@ exec_op(uint16_t *mem, long pc)
fputc('\n', stderr);
return pc + 1;
default:
- error("unsupported opcode %04x");
+ error("unsupported opcode %04x (pc: %04x)", mem[pc], pc);
if (mem[pc] <= OP_SLP)
fprintf(stderr, "(%s)\n", ops[mem[pc]]);
exit(fail());