annotate d144/edata-input-decomp.c @ 56:b32b644b7d96

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