comparison d144/edata-input-decomp.c @ 54:8deebf9c410a

d144: "decompile" binary input format into ASCII
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 04:32:32 +0000
parents trau-ul-compile/trau-ul-decomp.c@f80e64139670
children
comparison
equal deleted inserted replaced
53:c93ecd225b7f 54:8deebf9c410a
1 /*
2 * This program reads an E-data compiled binary file (the kind intended
3 * as input to itt-ater-16) and converts it into ASCII form. The ASCII
4 * output from this program is not in the same format as input to
5 * edata-input-compile, but it is a more compact ASCII-based format
6 * that will be useful for unit tests on the future sw implementation
7 * of RAA' function.
8 */
9
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13
14 main(argc, argv)
15 char **argv;
16 {
17 FILE *binf, *outf;
18 uint8_t frame[38];
19 int rc;
20 unsigned n;
21
22 if (argc < 2 || argc > 3) {
23 fprintf(stderr, "usage: %s input.bin [output.asc]\n", argv[0]);
24 exit(1);
25 }
26 binf = fopen(argv[1], "r");
27 if (!binf) {
28 perror(argv[1]);
29 exit(1);
30 }
31 if (argc > 2) {
32 outf = fopen(argv[2], "w");
33 if (!outf) {
34 perror(argv[2]);
35 exit(1);
36 }
37 } else
38 outf = stdout;
39 for (;;) {
40 rc = fread(frame, 1, 38, binf);
41 if (!rc)
42 break;
43 if (rc != 38) {
44 inv_input: fprintf(stderr, "error: %s is not in expected format\n",
45 argv[1]);
46 exit(1);
47 }
48 if (frame[0] != 0xD4)
49 goto inv_input;
50 fprintf(outf, "%u%u ", (frame[1] & 2) >> 1, frame[1] & 1);
51 for (n = 0; n < 36; n++)
52 fprintf(outf, "%02x", frame[n+2]);
53 putc('\n', outf);
54 }
55 exit(0);
56 }