From cf56f40f511d134e18eccd001471f5eafae518d2 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 20 May 2023 19:24:21 +0100 Subject: Make dump available --- vm.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 63836c6..4597ba9 100644 --- a/vm.c +++ b/vm.c @@ -69,26 +69,35 @@ static uint8_t flags(uint8_t *f, uint16_t v, uint8_t mask) return (v & 0xff); } -static void dump(Tr8 *vm) +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)) +{ + memset(vm, 0, sizeof(Tr8)); + vm->write_m = write_m; + vm->read_m = read_m; + vm->port = port; + vm->f = IF; +} + +void tr8_dump(Tr8 *vm, FILE *fd) { uint8_t i; - fprintf(stderr, " PC 0x%04x: ", vm->pc); + fprintf(fd, " 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"); + fprintf(fd, "0x%02x ", vm->read_m(vm->pc + i)); + fprintf(fd, "\n"); - fprintf(stderr, " SP 0x%04x: ", vm->sp); + fprintf(fd, " SP 0x%04x: ", vm->sp); if (vm->sp == vm->ssp) - fprintf(stderr, "-"); + fprintf(fd, "-"); else { for (i = 0; i < 16 && i + vm->sp < UINT16_MAX + 1; i++) - fprintf(stderr, "0x%02x ", vm->read_m(vm->sp + i)); + fprintf(fd, "0x%02x ", vm->read_m(vm->sp + i)); } - fprintf(stderr, "\n"); + fprintf(fd, "\n"); - fprintf(stderr, " F: %c%c%c%c%c%c\n" + fprintf(fd, " 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", @@ -104,17 +113,9 @@ static void dump(Tr8 *vm) vm->regs[3], vm->icnt); - fprintf(stderr, "****\n"); + fprintf(fd, "****\n"); } -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)) -{ - memset(vm, 0, sizeof(Tr8)); - vm->write_m = write_m; - vm->read_m = read_m; - vm->port = port; - vm->f = IF; -} uint8_t tr8_frame_int(Tr8 *vm) { @@ -170,7 +171,7 @@ uint8_t tr8_eval(Tr8 *vm) { fprintf(stderr, "*HALT with IF*\n"); vm->pc -= 2; - dump(vm); + tr8_dump(vm, stderr); return 0; } return 1; @@ -454,7 +455,7 @@ uint8_t tr8_eval(Tr8 *vm) default: fprintf(stderr, "*invalid opcode 0x%01x at PC=0x%04x*\n", (instr >> 12), 2 * (vm->pc - 1)); - dump(vm); + tr8_dump(vm, stderr); return 1; } -- cgit v1.2.3