annotate ringtools/fc-e1gen.c @ 44:b77005f6d315

loadtools: migration to /opt/freecalypso
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 26 Oct 2016 05:55:04 +0000
parents cefdc6623322
children c138906889f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program is an experimental compiler for TI's Melody E1 format
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * based on the description given in the L1M_AS001_1.pdf document
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * found in the Peek/FGW drop.
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <ctype.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #define MAX_FIELDS 16
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char *infname, *outfname;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 FILE *inf, *outf;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char linebuf[512], *fields[MAX_FIELDS+1];
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int lineno, nfields;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int start_time, osc_mask;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_short osc_words[8][4];
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 get_input_line()
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *cp;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int n;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (!fgets(linebuf, sizeof linebuf, inf)) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fprintf(stderr, "%s: unexpected EOF\n", infname);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 cp = index(linebuf, '\n');
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!cp) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, "%s line %d: too long or missing newline\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 *cp = '\0';
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /* parse it into fields */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cp = linebuf;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 n = 0;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (;;) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 while (isspace(*cp))
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 cp++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (*cp == '\0' || *cp == '#')
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (n >= MAX_FIELDS) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "%s line %d: too many fields\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fields[n++] = cp;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 while (*cp && !isspace(*cp))
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 cp++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (*cp)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 *cp++ = '\0';
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fields[n] = 0;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 nfields = n;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 input_number(str, min, max)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 char *str;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 char *endp;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 long val;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 val = strtol(str, &endp, 10);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (*endp) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 fprintf(stderr,
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 "%s line %d: \"%s\" is not a valid decimal number\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 infname, lineno, str);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (val < min || val > max) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr, "%s line %d: number %ld is out of range\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 infname, lineno, val);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return val;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 handle_time_line()
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (nfields != 2) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 fprintf(stderr, "%s line %d: time header takes 1 argument\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 start_time = input_number(fields[1], 1, 255);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 check_req_field(n)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (n >= nfields) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 fprintf(stderr, "%s line %d: too few fields\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 process_osc_line()
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 int p = 1;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 int oscn, osc_bit;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 u_short word0, word1, word2, word3;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 int amp, freq, length;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 int tremT0, tremFreq;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 int sustain, t1, t2, t3, t5;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 oscn = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 osc_bit = 1 << oscn;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (osc_mask & osc_bit) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 fprintf(stderr, "%s line %d: osc %d defined more than once\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 infname, lineno, oscn);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 osc_mask |= osc_bit;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 /* basic part */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 if (!strcmp(fields[p], "df")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 freq = input_number(fields[p], -8192, 8191) & 0x3FFF;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 amp = input_number(fields[p], 0, 1023);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 word0 = freq << 2 | 2;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 word1 = amp << 6;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 } else {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 word0 = 0;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 if (!strcmp(fields[p], "sq1")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 word0 |= 4;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (!strcmp(fields[p], "sq2")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 word0 |= 8;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 amp = input_number(fields[p], 0, 63);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 freq = input_number(fields[p], 0, 63);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 word0 |= (freq << 10) | (amp << 4);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 length = input_number(fields[p], 0, 1023);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 word1 = length << 6;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 /* optional 3rd word */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 if (p < nfields && !strcmp(fields[p], "trem")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 word1 |= 0x10;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 tremT0 = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 tremFreq = input_number(fields[p], -16, 15) & 31;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 word2 = (tremFreq << 11) | (tremT0 << 8);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 /* optional 4th word */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (p < nfields && !strcmp(fields[p], "env")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 word1 |= 0x20;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 sustain = input_number(fields[p], 0, 15);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 t1 = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 t2 = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 t3 = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 check_req_field(p);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 t5 = input_number(fields[p], 0, 7);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 p++;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 word3 = (t1 << 13) | (t2 << 10) | (t3 << 7) | (t5 << 4) |
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 sustain;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (p != nfields) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 fprintf(stderr, "%s line %d: unexpected extra fields\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 osc_words[oscn][0] = word0;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 osc_words[oscn][1] = word1;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 osc_words[oscn][2] = word2;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 osc_words[oscn][3] = word3;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 read_osc_lines()
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 osc_mask = 0;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 for (;;) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 get_input_line();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (!nfields)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 break;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 if (!strcmp(fields[0], "osc")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 process_osc_line();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 continue;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 fprintf(stderr, "%s line %d: osc line expected\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 if (!osc_mask) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 fprintf(stderr, "%s line %d: no oscillators defined\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 emit_16bit_word(word)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 u_short word;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 putc(word & 0xFF, outf);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 putc(word >> 8, outf);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 emit_record()
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 int oscn, osc_bit;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 putc(start_time, outf);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 putc(osc_mask, outf);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 for (oscn = 0; oscn < 8; oscn++) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 osc_bit = 1 << oscn;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 if (!(osc_mask & osc_bit))
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 continue;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 emit_16bit_word(osc_words[oscn][0]);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 emit_16bit_word(osc_words[oscn][1]);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 if (osc_words[oscn][1] & 0x10)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 emit_16bit_word(osc_words[oscn][2]);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 if (osc_words[oscn][1] & 0x20)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 emit_16bit_word(osc_words[oscn][3]);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 main(argc, argv)
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 char **argv;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 if (argc != 3) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 fprintf(stderr, "usage: %s src-file e1-bin-file\n", argv[0]);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 if (strcmp(argv[1], "-")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 infname = argv[1];
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 inf = fopen(infname, "r");
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 if (!inf) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 perror(infname);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 } else {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 infname = "stdin";
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 inf = stdin;
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 outfname = argv[2];
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 outf = fopen(outfname, "w");
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 if (!outf) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 perror(outfname);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 /* main loop */
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 for (;;) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 do
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 get_input_line();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 while (!nfields);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 if (!strcmp(fields[0], "time")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 handle_time_line();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 read_osc_lines();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 emit_record();
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 } else if (!strcmp(fields[0], "end")) {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 emit_16bit_word(0);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 exit(0);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 } else {
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 fprintf(stderr, "%s line %d: expected time or end\n",
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 infname, lineno);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 exit(1);
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 }
cefdc6623322 fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 }