FreeCalypso > hg > gsm-net-reveng
annotate trau-decode/parse-main.c @ 2:b2ef2c80fef1
trau-parse: add FR decoding
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 24 May 2024 08:11:25 +0000 |
parents | trau-parse.c@b0dcd48a1c8a |
children | d9c095357c32 |
rev | line source |
---|---|
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a 64 kbit/s timeslot recording file, examines one |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * of the four 16 kbit/s subslots (selected), looks for GSM 08.60 TRAU |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * frames, and dumps whatever it finds. |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static unsigned file_offset; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static enum { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 HUNT_FOR_0, |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 HUNT_FOUND_0, |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 GOT_8_ZEROS, |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 SYNCED |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 } state; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static unsigned hunt_for_0_count, frame_pos_count; |
2
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
22 static uint8_t in_frame_2bit[160], frame_bits[320], d_bits[260]; |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static void |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unpack_dibits() |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 int i, inb; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 uint8_t *op; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 op = frame_bits; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 for (i = 0; i < 160; i++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 inb = in_frame_2bit[i]; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (inb & 2) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 *op++ = 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 else |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 *op++ = 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (inb & 1) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 *op++ = 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 else |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 *op++ = 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 static unsigned |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 bits_to_num(bits, nbits) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 uint8_t *bits; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 unsigned nbits; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 unsigned accum; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 unsigned n; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 accum = 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (n = 0; n < nbits; n++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 accum <<= 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (*bits) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 accum |= 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 bits++; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return accum; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 static void |
2
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
63 collect_d_bits() |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
64 { |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
65 bcopy(frame_bits + 33, d_bits, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
66 bcopy(frame_bits + 49, d_bits + 15, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
67 bcopy(frame_bits + 65, d_bits + 30, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
68 bcopy(frame_bits + 81, d_bits + 45, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
69 bcopy(frame_bits + 97, d_bits + 60, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
70 bcopy(frame_bits + 113, d_bits + 75, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
71 bcopy(frame_bits + 129, d_bits + 90, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
72 bcopy(frame_bits + 145, d_bits + 105, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
73 bcopy(frame_bits + 161, d_bits + 120, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
74 bcopy(frame_bits + 177, d_bits + 135, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
75 bcopy(frame_bits + 193, d_bits + 150, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
76 bcopy(frame_bits + 209, d_bits + 165, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
77 bcopy(frame_bits + 225, d_bits + 180, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
78 bcopy(frame_bits + 241, d_bits + 195, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
79 bcopy(frame_bits + 257, d_bits + 210, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
80 bcopy(frame_bits + 273, d_bits + 225, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
81 bcopy(frame_bits + 289, d_bits + 240, 15); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
82 bcopy(frame_bits + 305, d_bits + 255, 5); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
83 } |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
84 |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
85 static void |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 process_frame() |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 unsigned c1_5, c6_11; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 printf("Frame at 0x%x:\n", file_offset - 160); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 printf(" C1-C5: %u%u%u%u%u", frame_bits[17], frame_bits[18], |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 frame_bits[19], frame_bits[20], frame_bits[21]); |
1
b0dcd48a1c8a
trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
93 c1_5 = bits_to_num(frame_bits + 17, 5); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 switch (c1_5) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 case 0x02: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 fputs(" (FR UL)", stdout); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 break; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 case 0x1C: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 fputs(" (FR DL)", stdout); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 break; |
1
b0dcd48a1c8a
trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
101 case 0x1A: |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 fputs(" (EFR)", stdout); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 break; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 case 0x10: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 fputs(" (idle UL)", stdout); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 break; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 case 0x0E: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 fputs(" (idle DL)", stdout); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 break; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 putchar('\n'); |
1
b0dcd48a1c8a
trau-parse: initial bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
112 c6_11 = bits_to_num(frame_bits + 22, 6); |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 printf(" C6-C11: %u\n", c6_11); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 printf(" C12=%u C13=%u C14=%u C15=%u\n", frame_bits[28], |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 frame_bits[29], frame_bits[30], frame_bits[31]); |
2
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
116 switch (c1_5) { |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
117 case 0x02: |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
118 case 0x1C: |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
119 collect_d_bits(); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
120 print_fr_frame(d_bits); |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
121 break; |
b2ef2c80fef1
trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
122 } |
0
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 printf(" C16=%u C17=%u C18=%u C19=%u C20=%u C21=%u\n", |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 frame_bits[310], frame_bits[311], frame_bits[312], |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 frame_bits[313], frame_bits[314], frame_bits[315]); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 printf(" T1=%u T2=%u T3=%u T4=%u\n", frame_bits[316], frame_bits[317], |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 frame_bits[318], frame_bits[319]); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 static int |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 check_sync_zeros() |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 int i; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 for (i = 0; i < 16; i++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (frame_bits[i]) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 return 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 return 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 static int |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 check_sync_ones() |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 int i; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 for (i = 1; i < 20; i++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (!frame_bits[i*16]) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 return 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 return 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 static void |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 check_sync() |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (check_sync_zeros() && check_sync_ones()) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 printf("Bad frame sync, returning to hunt state\n"); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 state = HUNT_FOR_0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 static void |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 byte_input(inb) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 switch (state) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 case HUNT_FOR_0: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 if (inb != 0) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 state = HUNT_FOUND_0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 hunt_for_0_count = 1; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 case HUNT_FOUND_0: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 if (inb != 0) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 state = HUNT_FOR_0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 hunt_for_0_count++; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 if (hunt_for_0_count >= 8) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 state = GOT_8_ZEROS; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 case GOT_8_ZEROS: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 if (inb & 2) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 printf("Found frame sync at file offset 0x%x\n", |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 file_offset - 8); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 bzero(in_frame_2bit, 8); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 in_frame_2bit[8] = inb; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 frame_pos_count = 9; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 state = SYNCED; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 if (inb != 0) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 state = HUNT_FOR_0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 case SYNCED: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 in_frame_2bit[frame_pos_count++] = inb; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 if (frame_pos_count < 160) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 frame_pos_count = 0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 unpack_dibits(); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 process_frame(); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 check_sync(); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 return; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 default: |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 fprintf(stderr, "BUG: bad sync state\n"); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 abort(); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 main(argc, argv) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 char **argv; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 FILE *inf; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 int subslot, right_shift; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 int inb; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 if (argc != 3) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 fprintf(stderr, "usage: %s binfile subslot\n", argv[0]); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 exit(1); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 inf = fopen(argv[1], "r"); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 if (!inf) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 perror(argv[1]); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 exit(1); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 subslot = atoi(argv[2]); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 if (subslot < 0 || subslot > 3) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 fprintf(stderr, "error: invalid subslot argument\n"); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 exit(1); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 right_shift = (3 - subslot) * 2; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 state = HUNT_FOR_0; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 for (file_offset = 0; ; file_offset++) { |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 inb = getc(inf); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 if (inb < 0) |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 break; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 inb >>= right_shift; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 inb &= 3; |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 byte_input(inb); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 } |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 exit(0); |
131e0f1972bb
beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 } |