From a44b870228b9dcabfe9a200e4a16182082570160 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 10 Jun 2023 17:32:00 +0200 Subject: improve opcode error message --- build.sh | 2 +- src/orgaemu.c | 14 ++++++++++---- 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 #include #include #include @@ -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()); -- cgit v1.2.3