From ebdad42105c7d3816e1b54cc68a1d52c5ae7a386 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 15 Apr 2023 17:57:31 +0200 Subject: sdl messagebox on runtime error --- src/orgaemu.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/orgaemu.c b/src/orgaemu.c index ecc9c4d..f8f642a 100644 --- a/src/orgaemu.c +++ b/src/orgaemu.c @@ -56,6 +56,13 @@ fail(void) return 1; } +static void +error(const char *msg) +{ + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "orgaemu", msg, window); + fprintf(stderr, "%s\n", msg); +} + static uint16_t get_short(const unsigned char *s) { @@ -142,7 +149,7 @@ push(uint16_t v) stack[stack_ptr] = v; stack_ptr += 1; if (stack_ptr >= MEM_SIZE) { - fprintf(stderr, "stack overflow\n"); + error("stack overflow"); exit(fail()); } } @@ -151,7 +158,7 @@ static uint16_t pop(void) { if (stack_ptr == 0) { - fprintf(stderr, "stack underflow\n"); + error("stack underflow"); exit(fail()); } stack_ptr -= 1; @@ -164,7 +171,7 @@ push_rs(uint16_t v) rstack[rstack_ptr] = v; rstack_ptr += 1; if (rstack_ptr >= MEM_SIZE) { - fprintf(stderr, "return stack overflow\n"); + error("return stack overflow"); exit(fail()); } } @@ -173,7 +180,7 @@ static uint16_t pop_rs(void) { if (rstack_ptr == 0) { - fprintf(stderr, "return stack underflow\n"); + error("return stack underflow"); exit(fail()); } rstack_ptr -= 1; @@ -334,7 +341,7 @@ exec_op(uint16_t *mem, long pc) fputc('\n', stderr); return pc + 1; default: - fprintf(stderr, "unhandled opcode %04x\n", mem[pc]); + error("unsupported opcode %04x"); if (mem[pc] <= OP_SLP) fprintf(stderr, "(%s)\n", ops[mem[pc]]); exit(fail()); -- cgit v1.2.3