comparison ringtools/fc-e1gen.c @ 175:b002c7cf5d03

fc-e1gen: support parenthesized options for bit0 and dummy time byte
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 Mar 2017 18:36:37 +0000
parents c138906889f7
children 2133c475f5bd
comparison
equal deleted inserted replaced
174:17523db6d1dc 175:b002c7cf5d03
80 exit(1); 80 exit(1);
81 } 81 }
82 return val; 82 return val;
83 } 83 }
84 84
85 input_paren_number(str, min, max)
86 char *str;
87 {
88 char *cp;
89
90 if (str[0] != '(') {
91 badparen: fprintf(stderr,
92 "%s line %d: bad parenthesized argument \"%s\"\n",
93 infname, lineno, str);
94 exit(1);
95 }
96 cp = index(str, ')');
97 if (!cp || cp[1])
98 goto badparen;
99 *cp = '\0';
100 return input_number(str + 1, min, max);
101 }
102
85 handle_time_line() 103 handle_time_line()
86 { 104 {
87 if (nfields != 2) { 105 if (nfields != 2) {
88 fprintf(stderr, "%s line %d: time header takes 1 argument\n", 106 fprintf(stderr, "%s line %d: time header takes 1 argument\n",
89 infname, lineno); 107 infname, lineno);
107 int oscn, osc_bit; 125 int oscn, osc_bit;
108 u_short word0, word1, word2, word3; 126 u_short word0, word1, word2, word3;
109 int amp, freq, length; 127 int amp, freq, length;
110 int tremT0, tremFreq; 128 int tremT0, tremFreq;
111 int sustain, t1, t2, t3, t5; 129 int sustain, t1, t2, t3, t5;
130 int bit0;
112 131
113 check_req_field(p); 132 check_req_field(p);
114 oscn = input_number(fields[p], 0, 7); 133 oscn = input_number(fields[p], 0, 7);
115 p++; 134 p++;
116 osc_bit = 1 << oscn; 135 osc_bit = 1 << oscn;
121 } 140 }
122 osc_mask |= osc_bit; 141 osc_mask |= osc_bit;
123 142
124 /* basic part */ 143 /* basic part */
125 check_req_field(p); 144 check_req_field(p);
145 if (fields[p][0] == '(') {
146 bit0 = input_paren_number(fields[p], 0, 1);
147 p++;
148 check_req_field(p);
149 } else
150 bit0 = 0;
126 if (!strcmp(fields[p], "df")) { 151 if (!strcmp(fields[p], "df")) {
127 p++; 152 p++;
128 check_req_field(p); 153 check_req_field(p);
129 freq = input_number(fields[p], -8192, 8191) & 0x3FFF; 154 freq = input_number(fields[p], -8192, 8191) & 0x3FFF;
130 p++; 155 p++;
131 check_req_field(p); 156 check_req_field(p);
132 amp = input_number(fields[p], 0, 1023); 157 amp = input_number(fields[p], 0, 1023);
133 p++; 158 p++;
134 word0 = freq << 2 | 2; 159 word0 = freq << 2 | 2 | bit0;
135 word1 = amp << 6; 160 word1 = amp << 6;
136 } else { 161 } else {
137 word0 = 0; 162 word0 = bit0;
138 if (!strcmp(fields[p], "sq1")) { 163 if (!strcmp(fields[p], "sq1")) {
139 p++; 164 p++;
140 word0 |= 4; 165 word0 |= 4;
141 check_req_field(p); 166 check_req_field(p);
142 } 167 }
248 273
249 handle_global_osc_set() 274 handle_global_osc_set()
250 { 275 {
251 int p; 276 int p;
252 int oscn, osc_bit; 277 int oscn, osc_bit;
278 int dummy_time_byte;
253 279
254 do 280 do
255 get_input_line(); 281 get_input_line();
256 while (!nfields); 282 while (!nfields);
257 if (strcmp(fields[0], "osc-set")) { 283 if (strcmp(fields[0], "osc-set")) {
258 fprintf(stderr, "%s line %d: osc-set line expected\n", 284 fprintf(stderr, "%s line %d: osc-set line expected\n",
259 infname, lineno); 285 infname, lineno);
260 exit(1); 286 exit(1);
261 } 287 }
262 if (nfields < 2) { 288 if (nfields < 2) {
263 fprintf(stderr, "%s line %d: osc-set must be non-empty\n", 289 emptyerr: fprintf(stderr, "%s line %d: osc-set must be non-empty\n",
264 infname, lineno); 290 infname, lineno);
265 exit(1); 291 exit(1);
266 } 292 }
267 for (p = 1; p < nfields; p++) { 293 p = 1;
294 if (fields[p][0] == '(') {
295 dummy_time_byte = input_paren_number(fields[p], 0, 255);
296 p++;
297 if (nfields < 3)
298 goto emptyerr;
299 } else
300 dummy_time_byte = 0;
301 for (; p < nfields; p++) {
268 oscn = input_number(fields[p], 0, 7); 302 oscn = input_number(fields[p], 0, 7);
269 osc_bit = 1 << oscn; 303 osc_bit = 1 << oscn;
270 global_osc_set |= osc_bit; 304 global_osc_set |= osc_bit;
271 } 305 }
272 putc(0, outf); 306 putc(dummy_time_byte, outf);
273 putc(global_osc_set, outf); 307 putc(global_osc_set, outf);
274 } 308 }
275 309
276 main(argc, argv) 310 main(argc, argv)
277 char **argv; 311 char **argv;