diff options
author | kdx <kikoodx@paranoici.org> | 2023-06-10 17:32:00 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-06-10 18:25:31 +0200 |
commit | a44b870228b9dcabfe9a200e4a16182082570160 (patch) | |
tree | ab35973e810eba8f2728e68ca5768f7cf3ccc337 | |
parent | ebdad42105c7d3816e1b54cc68a1d52c5ae7a386 (diff) | |
download | orga-a44b870228b9dcabfe9a200e4a16182082570160.tar.gz |
improve opcode error message
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | src/orgaemu.c | 14 |
2 files changed, 11 insertions, 5 deletions
@@ -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()); |