FreeCalypso > hg > gsm-net-reveng
annotate d144/edata-input-compile.c @ 58:a7ede064f883
atrau-parse: check sync one bit
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 17:50:41 +0000 |
parents | 4681ad8483d6 |
children |
rev | line source |
---|---|
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
2 * This program compiles E-data input from our handcrafting format |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
3 * into the binary format that will be read by itt-ater-16. |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
14 #define MAX_FIELDS 8 |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static char *infname, *outfname; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static FILE *inf, *outf; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static int lineno; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static char linebuf[256]; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static char *fields[MAX_FIELDS]; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static unsigned nfields; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
24 static uint8_t frame_nibbles[72]; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
25 static unsigned subframe_count; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 static int |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 get_line() |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 char *cp; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!fgets(linebuf, sizeof linebuf, inf)) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return 1; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 lineno++; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!index(linebuf, '\n')) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(stderr, "%s line %d: too long or missing newline\n", |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 nfields = 0; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (cp = linebuf; ; ) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 while (isspace(*cp)) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 cp++; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (*cp == '\0' || *cp == '#') |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 break; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (nfields >= MAX_FIELDS) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 fprintf(stderr, "%s line %d: too many fields\n", |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fields[nfields++] = cp; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 while (*cp && !isspace(*cp)) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 cp++; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (*cp) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 *cp++ = '\0'; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return 0; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 static int |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 get_line_nonempty() |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 int rc; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (;;) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 rc = get_line(); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (rc) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return rc; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (nfields) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return 0; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
74 static int |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
75 decode_hex_digit(c) |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
77 if (isdigit(c)) |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
78 return c - '0'; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
79 else if (isupper(c)) |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
80 return c - 'A' + 10; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
81 else |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
82 return c - 'a' + 10; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 static void |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
86 bits_line() |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
88 uint8_t *op; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 char *cp; |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
90 unsigned n; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
92 if (nfields != 2) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
93 fprintf(stderr, "%s line %d: bits command takes one argument\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
97 if (strlen(fields[1]) != 9) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
98 fprintf(stderr, "%s line %d: bits argument has wrong length\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
102 if (subframe_count >= 8) { |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 fprintf(stderr, |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
104 "%s line %d: 8 subframes already given, can't have more\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
108 op = frame_nibbles + subframe_count * 9; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
109 cp = fields[1]; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
110 for (n = 0; n < 9; n++) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
111 if (!isxdigit(*cp)) { |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 fprintf(stderr, |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
113 "%s line %d: bits argument is not valid hex\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
117 *op++ = decode_hex_digit(*cp++); |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 subframe_count++; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 static void |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
123 frame_line() |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 { |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
125 uint8_t bin[38], m_bits[2]; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
126 unsigned n, i; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (nfields != 2) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 fprintf(stderr, |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
130 "%s line %d: frame command takes one argument\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
134 for (n = 0; n < 2; n++) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
135 switch (fields[1][n]) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
136 case '0': |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
137 m_bits[n] = 0; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
138 break; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
139 case '1': |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
140 m_bits[n] = 1; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
141 break; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
142 default: |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
143 bad_arg: |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 fprintf(stderr, |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
145 "%s line %d: invalid M-bits argument \"%s\"\n", |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
146 infname, lineno, fields[1]); |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
150 if (fields[1][2]) |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
151 goto bad_arg; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
153 if (subframe_count != 8) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
154 fprintf(stderr, |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
155 "%s line %d: not preceded by exactly 8 subframes\n", |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 infname, lineno); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
159 bin[0] = 0xD4; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
160 bin[1] = (m_bits[0] << 1) | m_bits[1]; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
161 i = 0; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
162 for (n = 0; n < 36; n++) { |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
163 bin[n+2] = (frame_nibbles[i] << 4) | frame_nibbles[i+1]; |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
164 i += 2; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
166 fwrite(bin, 1, 38, outf); |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
167 |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
168 subframe_count = 0; |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 main(argc, argv) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 char **argv; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 int rc; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 if (argc != 3) { |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
177 fprintf(stderr, "usage: %s input.src output.bin\n", argv[0]); |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 infname = argv[1]; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 outfname = argv[2]; |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 inf = fopen(infname, "r"); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 if (!inf) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 perror(infname); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 outf = fopen(outfname, "w"); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 if (!outf) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 perror(outfname); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 for (;;) { |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 rc = get_line_nonempty(); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 if (rc) |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 break; |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
198 if (!strcasecmp(fields[0], "bits")) |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
199 bits_line(); |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
200 else if (!strcasecmp(fields[0], "frame")) |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
201 frame_line(); |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
202 else { |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 fprintf(stderr, |
52
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
204 "%s line %d: non-understood keyword \"%s\"\n", |
4681ad8483d6
d144: edata-input-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
205 infname, lineno, fields[0]); |
24
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 exit(1); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 exit(0); |
8e9bbb83bd16
trau-ul-compile program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |