From 3470d7c7e045d0271593be90115a629418f6258c Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Sun, 17 Sep 2023 18:01:27 +0200 Subject: [PATCH] dump VCD file --- logicboard.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/logicboard.c b/logicboard.c index 79885a7..3bc4d3f 100644 --- a/logicboard.c +++ b/logicboard.c @@ -40,6 +40,10 @@ static unsigned char shiftregisters[4*4]; static int audiotick = 0; static FILE *audioout = NULL; +char vcd_in_filename[64]; +char vcd_out_filename[64]; +FILE *vcd_out; + // for the 2x16 character display static unsigned char chardisplayram[0x80]; static unsigned char chardisplaycgram[0x40]; @@ -66,6 +70,15 @@ static void closeaudio(void) fclose(audioout); } +char *itob(int v) { + static char BUF[8]; + for (int i = 0; i < 8; i ++) { + int set = v & (1<<(8-i)); + BUF[i] = set ? '1' : '0'; + } + return BUF; +} + void logicboard_tick(struct em8051 *aCPU) { int i; @@ -417,10 +430,55 @@ void logicboard_tick(struct em8051 *aCPU) audiotick -= opt_clock_hz / (44100 * 12); } } - oldports[0] = aCPU->mSFR[REG_P0]; - oldports[1] = aCPU->mSFR[REG_P1]; - oldports[2] = aCPU->mSFR[REG_P2]; - oldports[3] = aCPU->mSFR[REG_P3]; + + // Dump ports as VCF + if (!vcd_out_filename[0]) { + strcpy(vcd_out_filename, "out.vcd"); + vcd_out = fopen(vcd_out_filename, "wb"); + + fprintf(vcd_out, "$version Generated by emu8051 $end\n"); +#if 0 + fprintf(vcd_out, "$date Wed Jun 7 11:35:32 2017 $end\n"); +#endif + fprintf(vcd_out, "$comment this is highly experimental $end\n"); + fprintf(vcd_out, "$timescale 1ns $end\n"); + + fprintf(vcd_out, "$var wire 8 P0 P0 $end\n"); + fprintf(vcd_out, "$var wire 8 P1 P1 $end\n"); + fprintf(vcd_out, "$var wire 8 P2 P2 $end\n"); + fprintf(vcd_out, "$var wire 8 P3 P3 $end\n"); + +#if 0 + fprintf(vcd_out, "$var wire 1 r RX $end\n"); + fprintf(vcd_out, "$var wire 1 t TX $end\n"); +#endif + + fprintf(vcd_out, "$dumpvars\n"); + fprintf(vcd_out, "bXXXXXXXX P0\n"); + fprintf(vcd_out, "bXXXXXXXX P1\n"); + fprintf(vcd_out, "bXXXXXXXX P2\n"); + fprintf(vcd_out, "bXXXXXXXX P3\n"); + fprintf(vcd_out, "$end\n"); + } + + static int last_emitted_time = -1; + + for (int idx = 0; idx < 4; idx ++) { + int current_time = clocks * (1.0f / opt_clock_hz * 1000 * 1000 * 1000); + int current_value = aCPU->mSFR[REG_P0 + idx * 0x10]; + if (oldports[idx] == current_value) continue; + if (last_emitted_time != current_time) { + fprintf(vcd_out, "#%d \n", current_time); + last_emitted_time = current_time; + } + fprintf(vcd_out, "b%8s P%d\n", itob(current_value), idx); + oldports[idx] = current_value; +#if 0 + if (idx==3) fprintf(vcd_out, "r%d\n", !!(aCPU->mSFR[REG_P3] & 0x01)); + if (idx==3) fprintf(vcd_out, "t%d\n", !!(aCPU->mSFR[REG_P3] & 0x02)); +#endif + } + fflush(vcd_out); } static void logicboard_render_7segs(struct em8051 *aCPU) @@ -750,5 +808,8 @@ void logicboard_update(struct em8051 *aCPU) break; } + mvprintw(18, 4, "in VCD file : %s", vcd_in_filename); + mvprintw(19, 4, "out VCD file : %s", vcd_out_filename); + refresh(); }