From d2dcd96ce186e6038273f93ecc1d8b70e32768b7 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 29 Mar 2020 22:13:54 -0400 Subject: [PATCH] emul: add useful emul_trace() debugging tool --- emul/emul.c | 10 ++++++++++ emul/emul.h | 1 + 2 files changed, 11 insertions(+) diff --git a/emul/emul.c b/emul/emul.c index 9cd45c3..a636816 100644 --- a/emul/emul.c +++ b/emul/emul.c @@ -7,6 +7,7 @@ They all run on the same kind of virtual machine: A z80 CPU, 64K of RAM/ROM. #include "emul.h" static Machine m; +static ushort traceval = 0; static uint8_t io_read(int unused, uint16_t addr) { @@ -92,6 +93,15 @@ void emul_loop() while (emul_step()); } +void emul_trace(ushort addr) +{ + ushort newval = m.mem[addr+1] << 8 | m.mem[addr]; + if (newval != traceval) { + traceval = newval; + fprintf(stderr, "trace: %04x PC: %04x\n", traceval, m.cpu.PC); + } +} + void emul_printdebug() { fprintf(stderr, "Min SP: %04x\n", m.minsp); diff --git a/emul/emul.h b/emul/emul.h index 174bdf5..9d848fe 100644 --- a/emul/emul.h +++ b/emul/emul.h @@ -30,4 +30,5 @@ Machine* emul_init(); bool emul_step(); bool emul_steps(unsigned int steps); void emul_loop(); +void emul_trace(ushort addr); void emul_printdebug();