+ printf("loaded bkm, %d frames, %d bytes\n", frames, count);
+ *byte_count = count;
+ return out;
+}
+
+static uint8_t *import_raw(FILE *f, int *byte_count, FILE *logf)
+{
+ uint8_t *out = NULL, val;
+ int count = 0;
+ int alloc = 0;
+ int line = 0;
+ int first = 1;
+ char buf[256];
+ char *p;
+ int i;
+
+ while ((p = fgets(buf, sizeof(buf), f)) != NULL)
+ {
+ line++;
+ if (p[0] == '#')
+ continue;
+ if (p[0] != 'e') {
+ printf("skipping: %s", p);
+ continue;
+ }
+
+ val = 0;
+ p++;
+ for (i = 6; i >= 0; i--, p++) {
+ if (*p != '0' && *p != '1')
+ goto bad;
+ if (*p == '1')
+ val |= 1 << i;
+ }
+ if (*p != ' ')
+ goto bad;
+
+ if (first && (val & 0x40))
+ continue; // XXX..
+ first = 0;
+
+ if (count >= alloc) {
+ alloc = alloc * 2 + 64;
+ out = realloc(out, alloc * sizeof(out[0]));
+ if (out == NULL) {
+ fprintf(stderr, "OOM?\n");
+ return NULL;
+ }
+ }
+
+ if (logf)
+ fwrite(&val, 1, 1, logf);
+
+ out[count++] = val & 0x3f;
+ continue;
+
+bad:
+ fprintf(stderr, "bad raw line %d: '%s'\n", line, buf);
+ return NULL;
+ }
+
+ printf("loaded raw, %d bytes\n", count);
+ *byte_count = count;