X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Foutput_vcd.c;h=eea2f0e5bcd1997ee21b28f86e8f8a8bfe0d0110;hb=340f6e7aeaf0c6cbbb27c5b535787bd09407994b;hp=a9f794ad9762dbf70599d69cf2a24ab746330128;hpb=086eac7c7bef114dd96c6ddb639fa2fa35f9182b;p=libsigrok.git diff --git a/output/output_vcd.c b/output/output_vcd.c index a9f794ad..eea2f0e5 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -61,12 +61,15 @@ static int init(struct output *o) if (!(ctx = calloc(1, sizeof(struct context)))) return SIGROK_ERR_MALLOC; + o->internal = ctx; ctx->num_enabled_probes = 0; + for (l = o->device->probes; l; l = l->next) { probe = l->data; - if (probe->enabled) - ctx->probelist[ctx->num_enabled_probes++] = probe->name; + if (!probe->enabled) + continue; + ctx->probelist[ctx->num_enabled_probes++] = probe->name; } ctx->probelist[ctx->num_enabled_probes] = 0; @@ -183,22 +186,20 @@ static int data(struct output *o, char *data_in, uint64_t length_in, 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? */ + /* Output which signal changed to which value. */ c = outbuf + strlen(outbuf); sprintf(c, "#%" PRIu64 "\n%i%c\n", samplecount, curbit, (char)('!' + p));