From 7f3e55cb513ad40921bb8e30dd8e9a5233c78461 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 23 May 2020 14:42:36 -0400 Subject: [PATCH] emul: add live register stats in the corner --- emul/emul.c | 6 ++++++ emul/emul.h | 1 + emul/forth.c | 20 +++++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/emul/emul.c b/emul/emul.c index b4efb34..4c82643 100644 --- a/emul/emul.c +++ b/emul/emul.c @@ -173,6 +173,12 @@ void emul_memdump() fclose(fp); } +void emul_debugstr(char *s) +{ + sprintf(s, "SP %04x (%04x) IX %04x (%04x)", + m.cpu.R1.wr.SP, m.minsp, m.cpu.R1.wr.IX, m.maxix); +} + void emul_printdebug() { fprintf(stderr, "Min SP: %04x\n", m.minsp); diff --git a/emul/emul.h b/emul/emul.h index 5bacb9b..1374d80 100644 --- a/emul/emul.h +++ b/emul/emul.h @@ -35,4 +35,5 @@ bool emul_steps(unsigned int steps); void emul_loop(); void emul_trace(ushort addr); void emul_memdump(); +void emul_debugstr(char *s); void emul_printdebug(); diff --git a/emul/forth.c b/emul/forth.c index 5525250..f50d1f6 100644 --- a/emul/forth.c +++ b/emul/forth.c @@ -20,7 +20,15 @@ static FILE *fp; static int retcode = 0; -WINDOW *bw, *w; +WINDOW *bw, *dw, *w; + +void debug_panel() +{ + char buf[30]; + emul_debugstr(buf); + mvwaddnstr(dw, 0, 0, buf, 30); + wrefresh(dw); +} static uint8_t iord_stdio() { @@ -28,6 +36,7 @@ static uint8_t iord_stdio() if (fp != NULL) { c = getc(fp); } else { + debug_panel(); c = wgetch(w); } if (c == EOF) { @@ -74,13 +83,18 @@ int main(int argc, char *argv[]) } else if (argc == 1) { fp = NULL; initscr(); cbreak(); noecho(); nl(); clear(); + // border window bw = newwin(WLINES+2, WCOLS+2, 0, 0); wborder(bw, 0, 0, 0, 0, 0, 0, 0, 0); wrefresh(bw); + // debug panel + dw = newwin(1, 30, LINES-1, COLS-30); w = newwin(WLINES, WCOLS, 1, 1); scrollok(w, 1); - while (emul_step()); - nocbreak(); echo(); delwin(w); delwin(bw); endwin(); + while (emul_steps(1000)) { + debug_panel(); + } + nocbreak(); echo(); delwin(w); delwin(bw); delwin(dw); endwin(); printf("\nDone!\n"); emul_printdebug(); } else {