From fdd6efd9ad3e0e213a50ed962ec628c17779794a Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 7 May 2023 23:57:23 +0100 Subject: Report non recoverable errors on the player --- vm.c | 63 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 5f4b1ce..ff6bcb8 100644 --- a/vm.c +++ b/vm.c @@ -69,42 +69,49 @@ static uint8_t flags(uint8_t *f, uint16_t v, uint8_t mask) return v; } -static void dump(Tr8 *vm) +void tr8_dump(Tr8 *vm, char *buffer) { uint8_t i; + size_t s; - fprintf(stderr, " PC 0x%04x: ", vm->pc); - for (i = 0; i < 16 && i + vm->pc < UINT16_MAX + 1; i++) - fprintf(stderr, "0x%02x ", vm->read_m(vm->pc + i)); - fprintf(stderr, "\n"); + s = sprintf(buffer, " PC 0x%04x: ", vm->pc); + for (i = 0; i < 8 && i + vm->pc < UINT16_MAX + 1; i++) + s += sprintf(buffer + s, "0x%02x ", vm->read_m(vm->pc + i)); + s += sprintf(buffer + s, "\n"); - fprintf(stderr, " SP 0x%04x: ", vm->sp); + s += sprintf(buffer + s, " SP 0x%04x: ", vm->sp); if (vm->sp == vm->ssp) - fprintf(stderr, "-"); + s += sprintf(buffer + s, "-"); else { - for (i = 0; i < 16 && i + vm->sp < UINT16_MAX + 1; i++) - fprintf(stderr, "0x%02x ", vm->read_m(vm->sp + i)); + for (i = 0; i < 8 && i + vm->sp < UINT16_MAX + 1; i++) + s += sprintf(buffer + s, "0x%02x ", vm->read_m(vm->sp + i)); } - fprintf(stderr, "\n"); - - fprintf(stderr, " F: %c%c%c%c%c%c\n" - " A: 0x%02x B: 0x%02x\n" - " X: 0x%02x Y: 0x%02x\n\n" - " %d instr run\n", - (vm->f & ZF) ? 'Z' : 'z', - (vm->f & CF) ? 'C' : 'c', - (vm->f & OF) ? 'O' : 'o', - (vm->f & SF) ? 'S' : 's', - (vm->f & IF) ? 'I' : 'i', - (vm->f & BF) ? 'B' : 'b', - vm->regs[0], - vm->regs[1], - vm->regs[2], - vm->regs[3], - vm->icnt); - - fprintf(stderr, "****\n"); + s += sprintf(buffer + s, "\n"); + + s += sprintf(buffer + s, " F: %c%c%c%c%c%c\n" + " A: 0x%02x B: 0x%02x\n" + " X: 0x%02x Y: 0x%02x\n\n" + " %d instr run\n", + (vm->f & ZF) ? 'Z' : 'z', + (vm->f & CF) ? 'C' : 'c', + (vm->f & OF) ? 'O' : 'o', + (vm->f & SF) ? 'S' : 's', + (vm->f & IF) ? 'I' : 'i', + (vm->f & BF) ? 'B' : 'b', + vm->regs[0], + vm->regs[1], + vm->regs[2], + vm->regs[3], + vm->icnt); +} + +static void dump(Tr8 *vm) +{ + char buffer[256]; + + tr8_dump(vm, buffer); + fputs(buffer, stderr); } void tr8_init(Tr8 *vm, void (*write_m)(uint16_t, uint8_t), uint8_t (*read_m)(uint16_t), uint8_t (*port)(uint8_t, uint8_t)) -- cgit v1.2.3