]> sigrok.org Git - libsigrok.git/blobdiff - output/vcd.c
Remove SR_MAX_NUM_PROBES, which is now no longer used.
[libsigrok.git] / output / vcd.c
index 27cc15336bf1422595ffce92be83ce4d99d7bbc7..90493f05b88540e3f5e976c544b6b2fc6a5d95bc 100644 (file)
@@ -37,8 +37,7 @@
 
 struct context {
        int num_enabled_probes;
-       char *probelist[SR_MAX_NUM_PROBES + 1];
-       int probeindices[SR_MAX_NUM_PROBES + 1];
+       GArray *probeindices;
        GString *header;
        uint8_t *prevsample;
        int period;
@@ -66,13 +65,14 @@ static int init(struct sr_output *o)
 
        o->internal = ctx;
        ctx->num_enabled_probes = 0;
+       ctx->probeindices = g_array_new(FALSE, FALSE, sizeof(int));
 
        for (l = o->sdi->probes; l; l = l->next) {
                probe = l->data;
                if (!probe->enabled)
                        continue;
-               ctx->probelist[ctx->num_enabled_probes] = probe->name;
-               ctx->probeindices[ctx->num_enabled_probes] = probe->index;
+               ctx->probeindices = g_array_append_val(
+                               ctx->probeindices, probe->index);
                ctx->num_enabled_probes++;
        }
        if (ctx->num_enabled_probes > 94) {
@@ -81,7 +81,6 @@ static int init(struct sr_output *o)
        }
 
        ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
-       ctx->probelist[ctx->num_enabled_probes] = 0;
        ctx->header = g_string_sized_new(512);
        num_probes = g_slist_length(o->sdi->probes);
 
@@ -131,9 +130,12 @@ static int init(struct sr_output *o)
        g_string_append_printf(ctx->header, "$scope module %s $end\n", PACKAGE);
 
        /* Wires / channels */
-       for (i = 0; i < ctx->num_enabled_probes; i++) {
+       for (i = 0, l = o->sdi->probes; l; l = l->next, i++) {
+               probe = l->data;
+               if (!probe->enabled)
+                       continue;
                g_string_append_printf(ctx->header, "$var wire 1 %c %s $end\n",
-                               (char)('!' + i), ctx->probelist[i]);
+                               (char)('!' + i), probe->name);
        }
 
        g_string_append(ctx->header, "$upscope $end\n"
@@ -188,7 +190,7 @@ static GString *receive(struct sr_output *o, const struct sr_dev_inst *sdi,
                sample = logic->data + i;
 
                for (p = 0; p < ctx->num_enabled_probes; p++) {
-                       index = ctx->probeindices[p % 8];
+                       index = g_array_index(ctx->probeindices, int, p);
                        curbit = (sample[p / 8] & (((uint8_t) 1) << index)) >> index;
                        prevbit = (ctx->prevsample[p / 8] & (((uint64_t) 1) << index)) >> index;