From b69ca4488e4479ceaa091d8435b4632d87a89d9e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 9 Apr 2020 08:26:41 -0400 Subject: [PATCH] Add emul_memdump() and stop automatically on ROM write --- emul/emul.c | 11 +++++++++++ emul/emul.h | 1 + emul/hw/rc2014/classic.c | 5 +---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/emul/emul.c b/emul/emul.c index a636816..75b6b7c 100644 --- a/emul/emul.c +++ b/emul/emul.c @@ -41,6 +41,9 @@ static void mem_write(int unused, uint16_t addr, uint8_t val) { if (addr < m.ramstart) { fprintf(stderr, "Writing to ROM (%d)!\n", addr); + emul_memdump(); + fprintf(stderr, "Press any key to continue...\n"); + while (getchar() > 0x100); } m.mem[addr] = val; } @@ -102,6 +105,14 @@ void emul_trace(ushort addr) } } +void emul_memdump() +{ + fprintf(stderr, "Dumping memory to memdump. PC %04x\n", m.cpu.PC); + FILE *fp = fopen("memdump", "w"); + fwrite(m.mem, 0x10000, 1, fp); + fclose(fp); +} + void emul_printdebug() { fprintf(stderr, "Min SP: %04x\n", m.minsp); diff --git a/emul/emul.h b/emul/emul.h index 9d848fe..db3a55f 100644 --- a/emul/emul.h +++ b/emul/emul.h @@ -31,4 +31,5 @@ bool emul_step(); bool emul_steps(unsigned int steps); void emul_loop(); void emul_trace(ushort addr); +void emul_memdump(); void emul_printdebug(); diff --git a/emul/hw/rc2014/classic.c b/emul/hw/rc2014/classic.c index 561c259..0c41e4a 100644 --- a/emul/hw/rc2014/classic.c +++ b/emul/hw/rc2014/classic.c @@ -102,10 +102,7 @@ int main(int argc, char *argv[]) char c; if (read(fileno(stdin), &c, 1) == 1) { if (c == 5) { - fprintf(stderr, "Dumping memory to memdump\n"); - FILE *fp = fopen("memdump", "w"); - fwrite(m->mem, 0x10000, 1, fp); - fclose(fp); + emul_memdump(); c = 0; // don't send to RC2014 } if (c == 4) { // CTRL+D