From 58d34988518e04a279d1eba6225af54c4c8c2d78 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 16 Feb 2024 15:37:31 +0100 Subject: Print filenames in error messages --- src/ahoy/emulator.c | 13 ++++++++----- src/ahoy/emulator.h | 2 +- src/ahoy/main.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ahoy/emulator.c b/src/ahoy/emulator.c index 00a87ff..edb3512 100644 --- a/src/ahoy/emulator.c +++ b/src/ahoy/emulator.c @@ -17,6 +17,7 @@ static void opexec(uint16_t); [[noreturn]] static void badins(uint16_t); struct chip8 c8; +static const char *filename; /* Preload font into memory */ static uint8_t mem[MEM_TOTAL] = { @@ -39,12 +40,14 @@ static uint8_t mem[MEM_TOTAL] = { }; void -emuinit(struct u8view prog) +emuinit(struct u8view prog, const char *fn) { struct timespec tp; + filename = fn; + if (prog.len > MEM_FREE) { - diex("%s: binary of size %.1f KiB exceeds %d B maximum", "TODO", + diex("%s: binary of size %.1f KiB exceeds %d B maximum", filename, (double)prog.len / 1024, MEM_FREE); } @@ -75,7 +78,7 @@ opexec(uint16_t op) break; case 0x00EE: if (c8.SP == 0) - diex("%s: stack pointer underflow", "TODO"); + diex("%s: stack pointer underflow", filename); c8.PC = c8.callstack[--c8.SP]; break; default: @@ -90,7 +93,7 @@ opexec(uint16_t op) case 0x2: if (c8.SP == lengthof(c8.callstack)) - diex("%s: stack pointer overflow", "TODO"); + diex("%s: stack pointer overflow", filename); c8.callstack[c8.SP++] = c8.PC; c8.PC = (op & 0xFFF) - 2; break; @@ -311,5 +314,5 @@ opexec(uint16_t op) void badins(uint16_t op) { - diex("%s: invalid opcode: %04X", "TODO", op); + diex("%s: invalid opcode: %04X", filename, op); } diff --git a/src/ahoy/emulator.h b/src/ahoy/emulator.h index a9c4398..24aa8ce 100644 --- a/src/ahoy/emulator.h +++ b/src/ahoy/emulator.h @@ -24,7 +24,7 @@ struct chip8 { uint64_t screen[32]; }; -void emuinit(struct u8view); +void emuinit(struct u8view, const char *); void emutick(void); extern struct chip8 c8; diff --git a/src/ahoy/main.c b/src/ahoy/main.c index b7f0639..e52e6bd 100644 --- a/src/ahoy/main.c +++ b/src/ahoy/main.c @@ -106,7 +106,7 @@ run(int fd, const char *fn) free(buf); wininit(); - emuinit(u8strtou8(sb)); + emuinit(u8strtou8(sb), fn); while (gs != GUI_STOP) { double dt; -- cgit v1.2.3