Skip to content

Commit

Permalink
dump VCD file
Browse files Browse the repository at this point in the history
  • Loading branch information
steveschnepp committed Sep 17, 2023
1 parent 5dc6812 commit 3470d7c
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions logicboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

0 comments on commit 3470d7c

Please sign in to comment.