FreeCalypso > hg > freecalypso-tools
annotate ringtools/fc-e1gen.c @ 413:a28c46e5a6ce
doc/Host-tools-overview: mokosrec2bin addition documented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 25 Oct 2018 19:33:16 +0000 |
parents | 2133c475f5bd |
children |
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 |
177
2133c475f5bd
fc-e1gen: MAX_FIELDS needed to be bumped for the optional bit0 field
Mychaela Falconia <falcon@freecalypso.org>
parents:
175
diff
changeset
|
14 #define MAX_FIELDS 17 |
33
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 |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
21 int global_osc_set; |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int start_time, osc_mask; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 u_short osc_words[8][4]; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 get_input_line() |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char *cp; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int n; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!fgets(linebuf, sizeof linebuf, inf)) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, "%s: unexpected EOF\n", infname); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 cp = index(linebuf, '\n'); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!cp) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 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
|
37 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 *cp = '\0'; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 /* parse it into fields */ |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 cp = linebuf; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 n = 0; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 for (;;) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 while (isspace(*cp)) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 cp++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (*cp == '\0' || *cp == '#') |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 break; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (n >= MAX_FIELDS) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 fprintf(stderr, "%s line %d: too many fields\n", |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fields[n++] = cp; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 while (*cp && !isspace(*cp)) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 cp++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (*cp) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 *cp++ = '\0'; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fields[n] = 0; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 nfields = n; |
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 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 input_number(str, min, max) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 char *str; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 char *endp; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 long val; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 val = strtol(str, &endp, 10); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*endp) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fprintf(stderr, |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 "%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
|
74 infname, lineno, str); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (val < min || val > max) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 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
|
79 infname, lineno, val); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return val; |
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 |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
85 input_paren_number(str, min, max) |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
86 char *str; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
87 { |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
88 char *cp; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
89 |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
90 if (str[0] != '(') { |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
91 badparen: fprintf(stderr, |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
92 "%s line %d: bad parenthesized argument \"%s\"\n", |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
93 infname, lineno, str); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
94 exit(1); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
95 } |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
96 cp = index(str, ')'); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
97 if (!cp || cp[1]) |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
98 goto badparen; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
99 *cp = '\0'; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
100 return input_number(str + 1, min, max); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
101 } |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
102 |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 handle_time_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 if (nfields != 2) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 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
|
107 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 start_time = input_number(fields[1], 1, 255); |
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 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 check_req_field(n) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (n >= nfields) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 fprintf(stderr, "%s line %d: too few fields\n", |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
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 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 process_osc_line() |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 int p = 1; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 int oscn, osc_bit; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 u_short word0, word1, word2, word3; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 int amp, freq, length; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 int tremT0, tremFreq; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 int sustain, t1, t2, t3, t5; |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
130 int bit0; |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 oscn = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 osc_bit = 1 << oscn; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (osc_mask & osc_bit) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 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
|
138 infname, lineno, oscn); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 osc_mask |= osc_bit; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 /* basic part */ |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 check_req_field(p); |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
145 if (fields[p][0] == '(') { |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
146 bit0 = input_paren_number(fields[p], 0, 1); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
147 p++; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
148 check_req_field(p); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
149 } else |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
150 bit0 = 0; |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (!strcmp(fields[p], "df")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 p++; |
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 freq = input_number(fields[p], -8192, 8191) & 0x3FFF; |
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 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 amp = input_number(fields[p], 0, 1023); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 p++; |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
159 word0 = freq << 2 | 2 | bit0; |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 word1 = amp << 6; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } else { |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
162 word0 = bit0; |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 if (!strcmp(fields[p], "sq1")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 word0 |= 4; |
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 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 if (!strcmp(fields[p], "sq2")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 word0 |= 8; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 amp = input_number(fields[p], 0, 63); |
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 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 freq = input_number(fields[p], 0, 63); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 word0 |= (freq << 10) | (amp << 4); |
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 length = input_number(fields[p], 0, 1023); |
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 word1 = length << 6; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 /* optional 3rd word */ |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 if (p < nfields && !strcmp(fields[p], "trem")) { |
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 word1 |= 0x10; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 tremT0 = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 tremFreq = input_number(fields[p], -16, 15) & 31; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 word2 = (tremFreq << 11) | (tremT0 << 8); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 /* optional 4th word */ |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 if (p < nfields && !strcmp(fields[p], "env")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 word1 |= 0x20; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 sustain = input_number(fields[p], 0, 15); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 t1 = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 t2 = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 t3 = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 check_req_field(p); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 t5 = input_number(fields[p], 0, 7); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 p++; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 word3 = (t1 << 13) | (t2 << 10) | (t3 << 7) | (t5 << 4) | |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 sustain; |
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 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 if (p != nfields) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 fprintf(stderr, "%s line %d: unexpected extra fields\n", |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 infname, lineno); |
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 osc_words[oscn][0] = word0; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 osc_words[oscn][1] = word1; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 osc_words[oscn][2] = word2; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 osc_words[oscn][3] = word3; |
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 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 read_osc_lines() |
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 osc_mask = 0; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 for (;;) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 get_input_line(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 if (!nfields) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 break; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 if (!strcmp(fields[0], "osc")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 process_osc_line(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 continue; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 fprintf(stderr, "%s line %d: osc line expected\n", |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 emit_16bit_word(word) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 u_short word; |
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 putc(word & 0xFF, outf); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 putc(word >> 8, outf); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 emit_record() |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 int oscn, osc_bit; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 putc(start_time, outf); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 putc(osc_mask, outf); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 for (oscn = 0; oscn < 8; oscn++) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 osc_bit = 1 << oscn; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 if (!(osc_mask & osc_bit)) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 continue; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 emit_16bit_word(osc_words[oscn][0]); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 emit_16bit_word(osc_words[oscn][1]); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (osc_words[oscn][1] & 0x10) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 emit_16bit_word(osc_words[oscn][2]); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 if (osc_words[oscn][1] & 0x20) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 emit_16bit_word(osc_words[oscn][3]); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
274 handle_global_osc_set() |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
275 { |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
276 int p; |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
277 int oscn, osc_bit; |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
278 int dummy_time_byte; |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
279 |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
280 do |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
281 get_input_line(); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
282 while (!nfields); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
283 if (strcmp(fields[0], "osc-set")) { |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
284 fprintf(stderr, "%s line %d: osc-set line expected\n", |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
285 infname, lineno); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
286 exit(1); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
287 } |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
288 if (nfields < 2) { |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
289 emptyerr: fprintf(stderr, "%s line %d: osc-set must be non-empty\n", |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
290 infname, lineno); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
291 exit(1); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
292 } |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
293 p = 1; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
294 if (fields[p][0] == '(') { |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
295 dummy_time_byte = input_paren_number(fields[p], 0, 255); |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
296 p++; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
297 if (nfields < 3) |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
298 goto emptyerr; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
299 } else |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
300 dummy_time_byte = 0; |
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
301 for (; p < nfields; p++) { |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
302 oscn = input_number(fields[p], 0, 7); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
303 osc_bit = 1 << oscn; |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
304 global_osc_set |= osc_bit; |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
305 } |
175
b002c7cf5d03
fc-e1gen: support parenthesized options for bit0 and dummy time byte
Mychaela Falconia <falcon@freecalypso.org>
parents:
172
diff
changeset
|
306 putc(dummy_time_byte, outf); |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
307 putc(global_osc_set, outf); |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
308 } |
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
309 |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 main(argc, argv) |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 char **argv; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 if (argc != 3) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 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
|
315 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 if (strcmp(argv[1], "-")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 infname = argv[1]; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 inf = fopen(infname, "r"); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 if (!inf) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 perror(infname); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 } else { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 infname = "stdin"; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 inf = stdin; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 outfname = argv[2]; |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 outf = fopen(outfname, "w"); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 if (!outf) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 perror(outfname); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 |
172
c138906889f7
fc-e1gen & e1-experiments: added global oscillator set header word
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
335 handle_global_osc_set(); |
33
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 /* main loop */ |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 for (;;) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 do |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 get_input_line(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 while (!nfields); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 if (!strcmp(fields[0], "time")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 handle_time_line(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 read_osc_lines(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 emit_record(); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 } else if (!strcmp(fields[0], "end")) { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 emit_16bit_word(0); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 exit(0); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 } else { |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 fprintf(stderr, "%s line %d: expected time or end\n", |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 infname, lineno); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 exit(1); |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 } |
cefdc6623322
fc-e1gen utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 } |