1 | /*
|
---|
2 | =============================================================================
|
---|
3 | ptread.c -- librarian - read patch functions
|
---|
4 | Version 5 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define DEBUGRE 0
|
---|
9 | #define DEBUGSP 0
|
---|
10 |
|
---|
11 | #include "graphdef.h"
|
---|
12 | #include "stddefs.h"
|
---|
13 | #include "stdio.h"
|
---|
14 | #include "patch.h"
|
---|
15 | #include "vsdd.h"
|
---|
16 |
|
---|
17 | #include "midas.h"
|
---|
18 | #include "libdsp.h"
|
---|
19 |
|
---|
20 | #include "memory.h"
|
---|
21 |
|
---|
22 | extern int16_t finddpe(void);
|
---|
23 | extern int16_t findpte(void);
|
---|
24 | extern int16_t rd_ec(FILE *fp, int8_t *to, int32_t len);
|
---|
25 | extern uint16_t dt_alc(void);
|
---|
26 | extern uint16_t pt_alc(void);
|
---|
27 | extern void clrlsel(void);
|
---|
28 | extern void ldermsg(int8_t *p1, int8_t *p2, int8_t *p3, uint16_t p4, uint16_t p5);
|
---|
29 | extern void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor);
|
---|
30 | extern void voidpb(void);
|
---|
31 |
|
---|
32 | #if (DEBUGRE|DEBUGSP)
|
---|
33 | extern short debugsw;
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #if DEBUGRE
|
---|
37 | extern short debugre;
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #if DEBUGSP
|
---|
41 | short debugsp = 1;
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | extern uint16_t dpecpos;
|
---|
45 | extern uint16_t dpepred;
|
---|
46 | extern uint16_t dpesucc;
|
---|
47 | extern int16_t errno;
|
---|
48 | extern int16_t ptecpos;
|
---|
49 | extern int16_t ptepred;
|
---|
50 | extern int16_t ptesucc;
|
---|
51 |
|
---|
52 | extern struct patch ptebuf;
|
---|
53 |
|
---|
54 | /* |
---|
55 |
|
---|
56 | */
|
---|
57 |
|
---|
58 | /*
|
---|
59 | =============================================================================
|
---|
60 | stashp() -- stash an incoming patch
|
---|
61 | =============================================================================
|
---|
62 | */
|
---|
63 |
|
---|
64 | int16_t stashp(void)
|
---|
65 | {
|
---|
66 | register int16_t c;
|
---|
67 | register uint16_t np, stim;
|
---|
68 |
|
---|
69 | c = findpte();
|
---|
70 |
|
---|
71 | if (c EQ 0) { /* old patch -- just update it */
|
---|
72 |
|
---|
73 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
74 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
75 |
|
---|
76 | #if DEBUGSP
|
---|
77 | if (debugsw AND debugsp) {
|
---|
78 |
|
---|
79 | printf("stashp(): UPDATED\n");
|
---|
80 | SnapPTV("stashp");
|
---|
81 | }
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | return(SUCCESS);
|
---|
85 | }
|
---|
86 |
|
---|
87 | /* allocate a patch entry and fill it in */
|
---|
88 |
|
---|
89 | if (0 EQ (ptecpos = pt_alc())) {
|
---|
90 |
|
---|
91 | #if DEBUGSP
|
---|
92 | if (debugsw AND debugsp)
|
---|
93 | printf("stashp(): patch table FULL\n");
|
---|
94 | #endif
|
---|
95 | return(FAILURE); /* no patch entries left */
|
---|
96 | }
|
---|
97 |
|
---|
98 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
99 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
100 | stim = TRG_MASK & ptebuf.stmnum;
|
---|
101 |
|
---|
102 | if (c EQ 1) { /* new patch -- no STM entry yet */
|
---|
103 |
|
---|
104 | ptepred = 0;
|
---|
105 | stmptr[stim] = ptecpos;
|
---|
106 | }
|
---|
107 | /* |
---|
108 |
|
---|
109 | */
|
---|
110 | /* put patch in STM chain */
|
---|
111 |
|
---|
112 | if (ptepred) { /* predecessor exits */
|
---|
113 |
|
---|
114 | ptesucc = patches[ptepred].nextstm;
|
---|
115 |
|
---|
116 | patches[ptecpos].nextstm = ptesucc;
|
---|
117 | patches[ptecpos].prevstm = ptepred;
|
---|
118 |
|
---|
119 | patches[ptepred].nextstm = ptecpos;
|
---|
120 |
|
---|
121 | if (ptesucc)
|
---|
122 | patches[ptesucc].prevstm = ptecpos;
|
---|
123 |
|
---|
124 | } else { /* no predecessor */
|
---|
125 |
|
---|
126 | patches[ptecpos].prevstm = 0;
|
---|
127 |
|
---|
128 | if (c EQ -1) {
|
---|
129 |
|
---|
130 | ptesucc = stmptr[stim];
|
---|
131 |
|
---|
132 | patches[ptecpos].nextstm = ptesucc;
|
---|
133 |
|
---|
134 | patches[ptesucc].prevstm = ptecpos;
|
---|
135 |
|
---|
136 | stmptr[stim] = ptecpos;
|
---|
137 |
|
---|
138 | } else {
|
---|
139 |
|
---|
140 | patches[ptecpos].nextstm = 0;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | /* |
---|
144 |
|
---|
145 | */
|
---|
146 | /* update DEF table */
|
---|
147 |
|
---|
148 | if (0 EQ (c = finddpe())) {
|
---|
149 |
|
---|
150 | #if DEBUGSP
|
---|
151 | if (debugsw AND debugsp) {
|
---|
152 |
|
---|
153 | printf("stashp(): defent already exists -- dpecpos = %d\n",
|
---|
154 | dpecpos);
|
---|
155 |
|
---|
156 | printf("stashp(): ENTERED\n");
|
---|
157 | SnapPTV("stashp");
|
---|
158 | }
|
---|
159 | #endif
|
---|
160 | return(SUCCESS); /* defent already exists */
|
---|
161 | }
|
---|
162 |
|
---|
163 | if (0 EQ (dpecpos = dt_alc())) {
|
---|
164 |
|
---|
165 | #if DEBUGSP
|
---|
166 | if (debugsw AND debugsp)
|
---|
167 | printf("stashp(): defent table FULL\n");
|
---|
168 | #endif
|
---|
169 | return(FAILURE); /* no defents left */
|
---|
170 | }
|
---|
171 |
|
---|
172 | defents[dpecpos].nextdef = 0;
|
---|
173 | defents[dpecpos].stm = ptebuf.stmnum;
|
---|
174 | defents[dpecpos].adspec = ptebuf.paspec;
|
---|
175 | defents[dpecpos].adsuba = ptebuf.pasuba;
|
---|
176 | defents[dpecpos].addat1 = ptebuf.padat1;
|
---|
177 |
|
---|
178 | np = TRG_MASK & ptebuf.defnum;
|
---|
179 |
|
---|
180 | if (c EQ 1) {
|
---|
181 |
|
---|
182 | dpepred = 0;
|
---|
183 | defptr[np] = dpecpos;
|
---|
184 | }
|
---|
185 | /* |
---|
186 |
|
---|
187 | */
|
---|
188 | if (dpepred) {
|
---|
189 |
|
---|
190 | dpesucc = defents[dpepred].nextdef;
|
---|
191 | defents[dpecpos].nextdef = dpesucc;
|
---|
192 | defents[dpepred].nextdef = dpecpos;
|
---|
193 |
|
---|
194 | } else {
|
---|
195 |
|
---|
196 | if (c EQ -1) {
|
---|
197 |
|
---|
198 | dpesucc = defptr[np];
|
---|
199 | defents[dpecpos].nextdef = dpesucc;
|
---|
200 | defptr[np] = dpecpos;
|
---|
201 |
|
---|
202 | } else {
|
---|
203 |
|
---|
204 | defents[dpecpos].nextdef = 0;
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | #if DEBUGSP
|
---|
209 | if (debugsw AND debugsp) {
|
---|
210 |
|
---|
211 | printf("stashp(): new defent created -- dpecpos = %d\n",
|
---|
212 | dpecpos);
|
---|
213 |
|
---|
214 | printf("stashp(): ENTERED\n");
|
---|
215 | SnapPTV("stashp");
|
---|
216 | }
|
---|
217 | #endif
|
---|
218 | return(SUCCESS);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /* |
---|
222 |
|
---|
223 | */
|
---|
224 |
|
---|
225 | /*
|
---|
226 | =============================================================================
|
---|
227 | ptioerr() -- put up an I/O error message
|
---|
228 | =============================================================================
|
---|
229 | */
|
---|
230 |
|
---|
231 | void ptioerr(void)
|
---|
232 | {
|
---|
233 | int8_t erms[40];
|
---|
234 |
|
---|
235 | clrlsel();
|
---|
236 |
|
---|
237 | sprintf(erms, " errno = %d", errno);
|
---|
238 |
|
---|
239 | ldermsg("Couldn't read", " the patch table", erms,
|
---|
240 | LD_EMCF, LD_EMCB);
|
---|
241 | }
|
---|
242 |
|
---|
243 | /*
|
---|
244 | =============================================================================
|
---|
245 | nopatch() -- give an error message after running out of space
|
---|
246 | =============================================================================
|
---|
247 | */
|
---|
248 |
|
---|
249 | void nopatch(void)
|
---|
250 | {
|
---|
251 | clrlsel();
|
---|
252 |
|
---|
253 | ldermsg("Couldn't read", " the patch table.", " Ran out of space",
|
---|
254 | LD_EMCF, LD_EMCB);
|
---|
255 | }
|
---|
256 |
|
---|
257 | /* |
---|
258 |
|
---|
259 | */
|
---|
260 |
|
---|
261 | /*
|
---|
262 | =============================================================================
|
---|
263 | ptread() -- read a patch
|
---|
264 | =============================================================================
|
---|
265 | */
|
---|
266 |
|
---|
267 | int16_t ptread(FILE *fp)
|
---|
268 | {
|
---|
269 | register int16_t go;
|
---|
270 | int8_t cb;
|
---|
271 |
|
---|
272 | go = TRUE;
|
---|
273 |
|
---|
274 | ldwmsg(" Busy -- please stand by", (int8_t *)NULL, " Reading patches",
|
---|
275 | LCFBX10, LCBBX10);
|
---|
276 |
|
---|
277 | for (;;) {
|
---|
278 |
|
---|
279 | voidpb(); /* clear the patch buffer */
|
---|
280 |
|
---|
281 | ptecpos = ptepred = ptesucc = 0;
|
---|
282 |
|
---|
283 | #if DEBUGRE
|
---|
284 | if (debugsw AND debugre)
|
---|
285 | printf("ptread(): reading\n");
|
---|
286 | #endif
|
---|
287 | if (rd_ec(fp, &cb, 1L)) { /* get control byte */
|
---|
288 |
|
---|
289 | ptioerr();
|
---|
290 | return(FAILURE);
|
---|
291 | }
|
---|
292 |
|
---|
293 | if (0 EQ cb) /* if it's 0, we're done */
|
---|
294 | break;
|
---|
295 |
|
---|
296 | ptebuf.paspec = PE_TBIT | (PE_SPEC & cb);
|
---|
297 |
|
---|
298 | if (rd_ec(fp, &ptebuf.defnum, 4L)) /* DEF and STM */
|
---|
299 | return(FAILURE);
|
---|
300 | /* |
---|
301 |
|
---|
302 | */
|
---|
303 | switch (cb) {
|
---|
304 |
|
---|
305 | case PA_KEY:
|
---|
306 | case PA_TRG:
|
---|
307 |
|
---|
308 | if (rd_ec(fp, &ptebuf.pasuba, 2L))
|
---|
309 | return(FAILURE);
|
---|
310 |
|
---|
311 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
312 | return(FAILURE);
|
---|
313 |
|
---|
314 | break;
|
---|
315 |
|
---|
316 | case PA_PLS:
|
---|
317 | case PA_SCTL:
|
---|
318 |
|
---|
319 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
320 | return(FAILURE);
|
---|
321 |
|
---|
322 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
323 | return(FAILURE);
|
---|
324 |
|
---|
325 | break;
|
---|
326 |
|
---|
327 | /* |
---|
328 |
|
---|
329 | */
|
---|
330 | case PA_LED:
|
---|
331 |
|
---|
332 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
333 | return(FAILURE);
|
---|
334 |
|
---|
335 | if (rd_ec(fp, &ptebuf.padat1, 1L))
|
---|
336 | return(FAILURE);
|
---|
337 |
|
---|
338 | break;
|
---|
339 |
|
---|
340 | case PA_SLIN:
|
---|
341 |
|
---|
342 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
343 | return(FAILURE);
|
---|
344 |
|
---|
345 | if (rd_ec(fp, &ptebuf.padat1, 2L))
|
---|
346 | return(FAILURE);
|
---|
347 |
|
---|
348 | break;
|
---|
349 |
|
---|
350 | case PA_TUNE:
|
---|
351 |
|
---|
352 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
353 | return(FAILURE);
|
---|
354 |
|
---|
355 | break;
|
---|
356 | /* |
---|
357 |
|
---|
358 | */
|
---|
359 | case PA_RSET:
|
---|
360 | case PA_RADD:
|
---|
361 |
|
---|
362 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
363 | return(FAILURE);
|
---|
364 |
|
---|
365 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
366 | return(FAILURE);
|
---|
367 |
|
---|
368 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
369 | return(FAILURE);
|
---|
370 |
|
---|
371 | break;
|
---|
372 |
|
---|
373 | case PA_INST:
|
---|
374 | case PA_WAVA:
|
---|
375 | case PA_WAVB:
|
---|
376 | case PA_CNFG:
|
---|
377 |
|
---|
378 | if (rd_ec(fp, &ptebuf.pasuba, 1L))
|
---|
379 | return(FAILURE);
|
---|
380 |
|
---|
381 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
382 | return(FAILURE);
|
---|
383 |
|
---|
384 | break;
|
---|
385 |
|
---|
386 | case PA_OSC:
|
---|
387 | case PA_INDX:
|
---|
388 | case PA_FREQ:
|
---|
389 |
|
---|
390 | if (rd_ec(fp, &ptebuf.pasuba, 2L))
|
---|
391 | return(FAILURE);
|
---|
392 |
|
---|
393 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
394 | return(FAILURE);
|
---|
395 |
|
---|
396 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
397 | return(FAILURE);
|
---|
398 |
|
---|
399 | break;
|
---|
400 | /* |
---|
401 |
|
---|
402 | */
|
---|
403 | case PA_LEVL:
|
---|
404 | case PA_FILT:
|
---|
405 | case PA_FILQ:
|
---|
406 | case PA_LOCN:
|
---|
407 | case PA_DYNM:
|
---|
408 |
|
---|
409 | if (rd_ec(fp, &ptebuf.pasuba, 1L))
|
---|
410 | return(FAILURE);
|
---|
411 |
|
---|
412 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
413 | return(FAILURE);
|
---|
414 |
|
---|
415 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
416 | return(FAILURE);
|
---|
417 |
|
---|
418 | break;
|
---|
419 |
|
---|
420 | case PA_AUX:
|
---|
421 | case PA_RATE:
|
---|
422 | case PA_INTN:
|
---|
423 | case PA_DPTH:
|
---|
424 |
|
---|
425 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
426 | return(FAILURE);
|
---|
427 |
|
---|
428 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
429 | return(FAILURE);
|
---|
430 |
|
---|
431 | break;
|
---|
432 |
|
---|
433 | case PA_VOUT:
|
---|
434 |
|
---|
435 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
436 | return(FAILURE);
|
---|
437 |
|
---|
438 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
439 | return(FAILURE);
|
---|
440 |
|
---|
441 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
442 | return(FAILURE);
|
---|
443 |
|
---|
444 | break;
|
---|
445 | /* |
---|
446 |
|
---|
447 | */
|
---|
448 | default:
|
---|
449 |
|
---|
450 | return(FAILURE);
|
---|
451 | }
|
---|
452 |
|
---|
453 | #if DEBUGRE
|
---|
454 | if (debugsw AND debugre)
|
---|
455 | printf("\n\n");
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | if (stashp()) { /* stash the patch */
|
---|
459 |
|
---|
460 | nopatch();
|
---|
461 | ptecpos = 0;
|
---|
462 | voidpb();
|
---|
463 | return(FAILURE);
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | #if DEBUGRE
|
---|
468 | if (debugsw AND debugre)
|
---|
469 | printf("ptread(): terminator read -- end of patch file\n");
|
---|
470 | #endif
|
---|
471 |
|
---|
472 | ptecpos = 0;
|
---|
473 | voidpb();
|
---|
474 | return(SUCCESS);
|
---|
475 | }
|
---|