X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Foutput_vcd.c;h=d8ce6ef063e9ad53eb068916d8505c9d5f8d0705;hb=c4fffe1e9606e3e63a4cd0b760a37beb1f122cc5;hp=1acf4a7b10fa70cce67673e73e0b3f8348630769;hpb=5cca9adbf27252349729cdb1e1c6ca0a526561b1;p=libsigrok.git diff --git a/output/output_vcd.c b/output/output_vcd.c index 1acf4a7b..d8ce6ef0 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -158,6 +158,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in, unsigned int i, outsize; int p, curbit, prevbit; uint64_t sample, prevsample; + static uint64_t samplecount = 0; char *outbuf, *c; ctx = o->internal; @@ -180,26 +181,25 @@ static int data(struct output *o, char *data_in, uint64_t length_in, /* TODO: Are disabled probes handled correctly? */ for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) { + samplecount++; memcpy(&sample, data_in + i, ctx->unitsize); + if (i == 0) + prevsample = sample; + else + memcpy(&prevsample, data_in + i - 1, ctx->unitsize); + for (p = 0; p < ctx->num_enabled_probes; p++) { - curbit = (sample & ((uint64_t) (1 << p))) != 0; - if (i == 0) { - prevbit = ~curbit; - } else { - memcpy(&prevsample, data_in + i - 1, - ctx->unitsize); - prevbit = - (prevsample & ((uint64_t) (1 << p))) != 0; - } - - /* VCD only contains deltas/changes. */ + curbit = (sample & ((uint64_t) (1 << p))) >> p; + prevbit = (prevsample & ((uint64_t) (1 << p))) >> p; + + /* VCD only contains deltas/changes of signals. */ if (prevbit == curbit) continue; - /* FIXME: Only once per sample? */ - /* TODO: Is 'i' correct here? */ + /* Output which signal changed to which value. */ c = outbuf + strlen(outbuf); - sprintf(c, "#%i\n%i%c\n", i, curbit, (char)('!' + p)); + sprintf(c, "#%" PRIu64 "\n%i%c\n", samplecount, + curbit, (char)('!' + p)); } /* TODO: Use realloc() if strlen(outbuf) is almost "full"... */