diff --git a/tools/ana.c b/tools/ana.c new file mode 100644 index 0000000..7fe56f9 --- /dev/null +++ b/tools/ana.c @@ -0,0 +1,153 @@ +#include + +unsigned line = 0, frame = 0; + + +void +byte (FILE * f, unsigned c) +{ + static int len; + static int plen; + static int state; + static unsigned last_frame; + + unsigned diff; + + diff = frame - last_frame; + last_frame = frame; + + + if (diff > 1) + printf ("/* GAP ~%d frames */\n", diff); + + if (state == 0) + { + if (c == 0x55) + return; + if (c == 0xaa) + state++; + else + printf ("ERR %02x ERR\n", c); + } + if (state == 1) + { + if (c == 0xaa) + return; + state++; + } + + if (state == 2) + { + plen = c; + len = 1; + state++; + printf ("0x%02x, ", c); + putc (c, f); + return; + } + + if (state == 3) + { + printf ("0x%02x, ", c); + putc (c, f); + len++; + + if (len == plen) + { + if (plen & 1) + { + state = 4; + printf ("/* 0x00, */\n"); + } + else + { + state = 2; + printf ("\n"); + } + } + else + { + if ((len % 16) == 15) + { + printf ("\n/**/ "); + } + } + + return; + } + + if (state == 4) + { + if (c) + printf ("ERR %02x ERR\n", c); + state = 2; + } + + + +} + +int +main (int argc, char *argv) +{ + char buf[1024]; + unsigned i, j, c, b; + + FILE *f = fopen ("timex.dat", "r"); + FILE *fo = fopen ("foo.bin", "w"); + + fwrite ("Timex", 5, 1, fo); + + while (fgets (buf, sizeof (buf), f)) + { + + while (line > 480) + { + line -= 480; + frame++; + } + + line++; + + if (strncmp (buf, "255\n", 4)) + continue; + + c = 0; + + fgets (buf, sizeof (buf), f); + fgets (buf, sizeof (buf), f); + fgets (buf, sizeof (buf), f); + fgets (buf, sizeof (buf), f); + + line += 4; + + for (i = 0; i < 8; ++i) + { + + for (j = 0; j < 7; ++j) + fgets (buf, sizeof (buf), f); + line += 7; + + b = 0; + for (j = 0; j < 8; ++j) + { + fgets (buf, sizeof (buf), f); + line++; + b = b || (!strncmp (buf, "255\n", 4)); + } + b = !b; + +//printf("%d",b); + + c |= b << i; + } + + byte (fo, c); + + + + } + fclose (fo); + + +}