diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-07 23:57:23 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-07 23:57:23 +0100 |
commit | fdd6efd9ad3e0e213a50ed962ec628c17779794a (patch) | |
tree | 2c4bb3fbb6e20bfcbca0e58c4051ce74ba3e30b2 /vm.c | |
parent | 856a86a7f7796e34efaeada0dc11f771fedf2c67 (diff) | |
download | tr8vm-fdd6efd9ad3e0e213a50ed962ec628c17779794a.tar.gz tr8vm-fdd6efd9ad3e0e213a50ed962ec628c17779794a.zip |
Report non recoverable errors on the playerui-test
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 63 |
1 files changed, 35 insertions, 28 deletions
@@ -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)) |