1 | /*
|
---|
2 | =============================================================================
|
---|
3 | ptwrite.c -- librarian - write patch functions
|
---|
4 | Version 7 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define DEBUGWE 0
|
---|
9 | #define DEBUGPW 0
|
---|
10 |
|
---|
11 | #include "ram.h"
|
---|
12 |
|
---|
13 | #if DEBUGPW
|
---|
14 | short debugpw = 1;
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | /* |
---|
18 |
|
---|
19 | */
|
---|
20 |
|
---|
21 | int8_t ptsizes[] = {
|
---|
22 |
|
---|
23 | 0, /* NULL - end of list */
|
---|
24 | 4, /* PA_KEY */
|
---|
25 | 4, /* PA_TRG */
|
---|
26 | 3, /* PA_PLS */
|
---|
27 | 3, /* PA_LED */
|
---|
28 | 4, /* PA_SLIN */
|
---|
29 | 3, /* PA_SCTL */
|
---|
30 | 2, /* PA_TUNE */
|
---|
31 | 4, /* PA_RSET */
|
---|
32 | 4, /* PA_RADD */
|
---|
33 | 3, /* PA_INST */
|
---|
34 | 6, /* PA_OSC */
|
---|
35 | 3, /* PA_WAVA */
|
---|
36 | 3, /* PA_WAVB */
|
---|
37 | 3, /* PA_CNFG */
|
---|
38 | 5, /* PA_LEVL */
|
---|
39 | 6, /* PA_INDX */
|
---|
40 | 6, /* PA_FREQ */
|
---|
41 | 5, /* PA_FILT */
|
---|
42 | 5, /* PA_FILQ */
|
---|
43 | 5, /* PA_LOCN */
|
---|
44 | 5, /* PA_DYNM */
|
---|
45 | 4, /* PA_AUX */
|
---|
46 | 4, /* PA_RATE */
|
---|
47 | 4, /* PA_INTN */
|
---|
48 | 4, /* PA_DPTH */
|
---|
49 | 5 /* PA_VOUT */
|
---|
50 | };
|
---|
51 |
|
---|
52 | /* |
---|
53 |
|
---|
54 | */
|
---|
55 |
|
---|
56 | /*
|
---|
57 | =============================================================================
|
---|
58 | ptsizer() -- return number of bytes necessary for storing active patches
|
---|
59 | =============================================================================
|
---|
60 | */
|
---|
61 |
|
---|
62 | int32_t ptsizer(void)
|
---|
63 | {
|
---|
64 | register int16_t pp;
|
---|
65 | register int32_t nb;
|
---|
66 |
|
---|
67 | nb = 0L;
|
---|
68 |
|
---|
69 | if (pp = find1st()) {
|
---|
70 |
|
---|
71 | while (pp) {
|
---|
72 |
|
---|
73 | nb += (ptsizes[PE_SPEC & patches[pp].paspec] + 4);
|
---|
74 | pp = findnxt(pp);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (nb)
|
---|
79 | ++nb; /* ... and one for the terminator */
|
---|
80 |
|
---|
81 | #if DEBUGPW
|
---|
82 | if (debugsw AND debugpw)
|
---|
83 | printf("ptsizer(): %ld bytes required\n", nb);
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | return(nb);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /* |
---|
90 |
|
---|
91 | */
|
---|
92 |
|
---|
93 | /*
|
---|
94 | =============================================================================
|
---|
95 | ptwrite() -- store a patch table
|
---|
96 | =============================================================================
|
---|
97 | */
|
---|
98 |
|
---|
99 | int16_t ptwrite(FILE *fp)
|
---|
100 | {
|
---|
101 | register int16_t pp;
|
---|
102 | int8_t cb, zero;
|
---|
103 |
|
---|
104 | #if DEBUGPW
|
---|
105 | if (debugsw AND debugpw)
|
---|
106 | printf("ptwrite($%08lX): entered\n", fp);
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | zero = '\0';
|
---|
110 |
|
---|
111 | ldwmsg("Busy -- Please stand by", (int8_t *)0L, " writing patches",
|
---|
112 | LCFBX10, LCBBX10);
|
---|
113 |
|
---|
114 | if (pp = find1st()) {
|
---|
115 |
|
---|
116 | while (pp) {
|
---|
117 |
|
---|
118 | #if DEBUGWE
|
---|
119 | if (debugsw AND debugwe) {
|
---|
120 |
|
---|
121 | printf("ptwrite(): %3d %04.4X %04.4X %04.4X %04.4X %04.4X %04.4X\n ",
|
---|
122 | pp, patches[pp].defnum, patches[pp].stmnum,
|
---|
123 | patches[pp].paspec, patches[pp].pasuba,
|
---|
124 | patches[pp].padat1, patches[pp].padat2);
|
---|
125 | }
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | switch (cb = (PE_SPEC & patches[pp].paspec)) {
|
---|
129 |
|
---|
130 | case PA_KEY:
|
---|
131 | case PA_TRG:
|
---|
132 |
|
---|
133 | if (wr_ec(fp, &cb, 1L))
|
---|
134 | return(FAILURE);
|
---|
135 |
|
---|
136 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
137 | return(FAILURE);
|
---|
138 |
|
---|
139 | if (wr_ec(fp, &patches[pp].pasuba, 2L))
|
---|
140 | return(FAILURE);
|
---|
141 |
|
---|
142 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
143 | return(FAILURE);
|
---|
144 |
|
---|
145 | break;
|
---|
146 | /* |
---|
147 |
|
---|
148 | */
|
---|
149 | case PA_PLS:
|
---|
150 | case PA_SCTL:
|
---|
151 |
|
---|
152 | if (wr_ec(fp, &cb, 1L))
|
---|
153 | return(FAILURE);
|
---|
154 |
|
---|
155 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
156 | return(FAILURE);
|
---|
157 |
|
---|
158 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
159 | return(FAILURE);
|
---|
160 |
|
---|
161 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
162 | return(FAILURE);
|
---|
163 |
|
---|
164 | break;
|
---|
165 |
|
---|
166 | case PA_LED:
|
---|
167 |
|
---|
168 | if (wr_ec(fp, &cb, 1L))
|
---|
169 | return(FAILURE);
|
---|
170 |
|
---|
171 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
172 | return(FAILURE);
|
---|
173 |
|
---|
174 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
175 | return(FAILURE);
|
---|
176 |
|
---|
177 | if (wr_ec(fp, &patches[pp].padat1, 1L))
|
---|
178 | return(FAILURE);
|
---|
179 |
|
---|
180 | break;
|
---|
181 |
|
---|
182 | case PA_SLIN:
|
---|
183 |
|
---|
184 | if (wr_ec(fp, &cb, 1L))
|
---|
185 | return(FAILURE);
|
---|
186 |
|
---|
187 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
188 | return(FAILURE);
|
---|
189 |
|
---|
190 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
191 | return(FAILURE);
|
---|
192 |
|
---|
193 | if (wr_ec(fp, &patches[pp].padat1, 2L))
|
---|
194 | return(FAILURE);
|
---|
195 |
|
---|
196 | break;
|
---|
197 |
|
---|
198 | case PA_TUNE:
|
---|
199 |
|
---|
200 | if (wr_ec(fp, &cb, 1L))
|
---|
201 | return(FAILURE);
|
---|
202 |
|
---|
203 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
204 | return(FAILURE);
|
---|
205 |
|
---|
206 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
207 | return(FAILURE);
|
---|
208 |
|
---|
209 | break;
|
---|
210 | /* |
---|
211 |
|
---|
212 | */
|
---|
213 | case PA_RSET:
|
---|
214 | case PA_RADD:
|
---|
215 |
|
---|
216 | if (wr_ec(fp, &cb, 1L))
|
---|
217 | return(FAILURE);
|
---|
218 |
|
---|
219 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
220 | return(FAILURE);
|
---|
221 |
|
---|
222 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
223 | return(FAILURE);
|
---|
224 |
|
---|
225 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
226 | return(FAILURE);
|
---|
227 |
|
---|
228 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
229 | return(FAILURE);
|
---|
230 |
|
---|
231 | break;
|
---|
232 |
|
---|
233 | case PA_INST:
|
---|
234 | case PA_WAVA:
|
---|
235 | case PA_WAVB:
|
---|
236 | case PA_CNFG:
|
---|
237 |
|
---|
238 | if (wr_ec(fp, &cb, 1L))
|
---|
239 | return(FAILURE);
|
---|
240 |
|
---|
241 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
242 | return(FAILURE);
|
---|
243 |
|
---|
244 | if (wr_ec(fp, &patches[pp].pasuba, 1L))
|
---|
245 | return(FAILURE);
|
---|
246 |
|
---|
247 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
248 | return(FAILURE);
|
---|
249 |
|
---|
250 | break;
|
---|
251 |
|
---|
252 | case PA_OSC:
|
---|
253 | case PA_INDX:
|
---|
254 | case PA_FREQ:
|
---|
255 |
|
---|
256 | if (wr_ec(fp, &cb, 1L))
|
---|
257 | return(FAILURE);
|
---|
258 |
|
---|
259 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
260 | return(FAILURE);
|
---|
261 |
|
---|
262 | if (wr_ec(fp, &patches[pp].pasuba, 2L))
|
---|
263 | return(FAILURE);
|
---|
264 |
|
---|
265 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
266 | return(FAILURE);
|
---|
267 |
|
---|
268 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
269 | return(FAILURE);
|
---|
270 |
|
---|
271 | break;
|
---|
272 | /* |
---|
273 |
|
---|
274 | */
|
---|
275 | case PA_LEVL:
|
---|
276 | case PA_FILT:
|
---|
277 | case PA_FILQ:
|
---|
278 | case PA_LOCN:
|
---|
279 | case PA_DYNM:
|
---|
280 |
|
---|
281 | if (wr_ec(fp, &cb, 1L))
|
---|
282 | return(FAILURE);
|
---|
283 |
|
---|
284 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
285 | return(FAILURE);
|
---|
286 |
|
---|
287 | if (wr_ec(fp, &patches[pp].pasuba, 1L))
|
---|
288 | return(FAILURE);
|
---|
289 |
|
---|
290 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
291 | return(FAILURE);
|
---|
292 |
|
---|
293 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
294 | return(FAILURE);
|
---|
295 |
|
---|
296 | break;
|
---|
297 |
|
---|
298 | case PA_AUX:
|
---|
299 | case PA_RATE:
|
---|
300 | case PA_INTN:
|
---|
301 | case PA_DPTH:
|
---|
302 |
|
---|
303 | if (wr_ec(fp, &cb, 1L))
|
---|
304 | return(FAILURE);
|
---|
305 |
|
---|
306 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
307 | return(FAILURE);
|
---|
308 |
|
---|
309 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
310 | return(FAILURE);
|
---|
311 |
|
---|
312 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
313 | return(FAILURE);
|
---|
314 |
|
---|
315 | break;
|
---|
316 |
|
---|
317 | case PA_VOUT:
|
---|
318 |
|
---|
319 | if (wr_ec(fp, &cb, 1L))
|
---|
320 | return(FAILURE);
|
---|
321 |
|
---|
322 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
323 | return(FAILURE);
|
---|
324 |
|
---|
325 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
326 | return(FAILURE);
|
---|
327 |
|
---|
328 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
329 | return(FAILURE);
|
---|
330 |
|
---|
331 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
332 | return(FAILURE);
|
---|
333 |
|
---|
334 | break;
|
---|
335 | /* |
---|
336 |
|
---|
337 | */
|
---|
338 | default:
|
---|
339 |
|
---|
340 | return(FAILURE);
|
---|
341 | }
|
---|
342 |
|
---|
343 | #if DEBUGWE
|
---|
344 | if (debugsw AND debugwe)
|
---|
345 | printf("\n\n");
|
---|
346 | #endif
|
---|
347 |
|
---|
348 | pp = findnxt(pp); /* find the next patch */
|
---|
349 | }
|
---|
350 |
|
---|
351 | if (wr_ec(fp, &zero, 1L)) /* write the terminator */
|
---|
352 | return(FAILURE);
|
---|
353 |
|
---|
354 | } else {
|
---|
355 |
|
---|
356 | return(FAILURE); /* no patches to write */
|
---|
357 | }
|
---|
358 |
|
---|
359 | #if DEBUGPW
|
---|
360 | if (debugsw AND debugpw)
|
---|
361 | printf("ptwrite(): SUCCESS\n");
|
---|
362 | #endif
|
---|
363 |
|
---|
364 | return(SUCCESS);
|
---|
365 | }
|
---|
366 |
|
---|