FreeCalypso > hg > freecalypso-tools
annotate ffstools/tiaud/decomp.c @ 887:3e398f9c31a0
fc-imy2pwt: overhaul melody error handling, report position
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Apr 2022 04:17:08 +0000 |
parents | 516066ac5bc1 |
children |
rev | line source |
---|---|
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility decompiles a binary /aud/*.cfg file read out of FFS |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * into our ASCII text representation. |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/file.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/stat.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <endian.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <unistd.h> |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "binstruct.h" |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 struct audio_cfg_bin bin; |
835
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
17 int is_new_aec; |
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 FILE *outf; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 read_bin_file(filename) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 char *filename; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int fd; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct stat st; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fd = open(filename, O_RDONLY); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (fd < 0) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror(filename); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fstat(fd, &st); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!S_ISREG(st.st_mode)) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fprintf(stderr, "%s is not a regular file\n", filename); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
835
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
36 if (st.st_size == MODE_FILE_SIZE_OLDAEC) |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
37 is_new_aec = 0; |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
38 else if (st.st_size == MODE_FILE_SIZE_NEWAEC) |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
39 is_new_aec = 1; |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
40 else { |
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, "%s has the wrong length\n", filename); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
835
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
44 read(fd, &bin, st.st_size); |
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 close(fd); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 emit_fir(table) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 uint16_t *table; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 int i; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (i = 0; i < 31; i++) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if ((i % 8) == 0) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(outf, "\tfir %2d", i); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fprintf(outf, " 0x%04X", le16toh(table[i])); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (i == 7 || i == 15 || i == 23 || i == 30) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 putc('\n', outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 emit_ascii() |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
835
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
64 int i, num_aec; |
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 fprintf(outf, "voice-path %u\n", bin.voice_path); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 switch (bin.mic_mode) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 case AUDIO_MICROPHONE_HANDHELD: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(outf, "mic default {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 case AUDIO_MICROPHONE_HANDFREE: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 fprintf(outf, "mic aux {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 case AUDIO_MICROPHONE_HEADSET: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fprintf(outf, "mic headset {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 default: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fprintf(stderr, "error: unknown microphone mode 0x%02X\n", |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 bin.mic_mode); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 fprintf(outf, "\tgain %d\n", bin.mic_bytes[0]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (bin.mic_mode == AUDIO_MICROPHONE_HANDFREE) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 fprintf(outf, "\textra-gain %d\n", bin.mic_bytes[1]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 fprintf(outf, "\toutput-bias %d\n", bin.mic_bytes[2]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } else |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 fprintf(outf, "\toutput-bias %d\n", bin.mic_bytes[1]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 emit_fir(bin.mic_fir); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 fputs("}\n", outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 switch (bin.speaker_mode) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 case AUDIO_SPEAKER_HANDHELD: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 fprintf(outf, "speaker ear {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 case AUDIO_SPEAKER_HANDFREE: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fprintf(outf, "speaker aux {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 case AUDIO_SPEAKER_HEADSET: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fprintf(outf, "speaker headset {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 case AUDIO_SPEAKER_BUZZER: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 fprintf(outf, "speaker buzzer {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 case AUDIO_SPEAKER_HANDHELD_HANDFREE: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(outf, "speaker ear+aux {\n"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 break; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 default: |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fprintf(stderr, "error: unknown speaker mode 0x%02X\n", |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 bin.speaker_mode); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (bin.speaker_mode != AUDIO_SPEAKER_BUZZER) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 fprintf(outf, "\tgain %d\n", bin.speaker_bytes[0]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 fprintf(outf, "\taudio-filter %d\n", bin.speaker_bytes[1]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 emit_fir(bin.speaker_fir); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 } else |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 fprintf(outf, "\tactivate %d\n", bin.speaker_bytes[0]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 fputs("}\n", outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 fprintf(outf, "sidetone %d\n", bin.sidetone_gain); |
835
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
122 if (is_new_aec) { |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
123 fputs("aec-new", outf); |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
124 num_aec = 12; |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
125 } else { |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
126 fputs("aec", outf); |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
127 num_aec = 5; |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
128 } |
516066ac5bc1
tiaud-decomp: support both old-AEC and new-AEC mode files
Mychaela Falconia <falcon@freecalypso.org>
parents:
834
diff
changeset
|
129 for (i = 0; i < num_aec; i++) { |
163
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 putc(' ', outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 if (bin.aec_words[i]) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 fprintf(outf, "0x%X", le16toh(bin.aec_words[i])); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 else |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 putc('0', outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 putc('\n', outf); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 main(argc, argv) |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 char **argv; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (argc < 2 || argc > 3) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 read_bin_file(argv[1]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 if (argc > 2) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 outf = fopen(argv[2], "w"); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 if (!outf) { |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 perror(argv[2]); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 exit(1); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 } |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 } else |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 outf = stdout; |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 emit_ascii(); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 exit(0); |
568e2a2b49c8
tiaud-decomp utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |