source: buchla-68k/orig/RAM/PTREAD.C@ 9bf0f86

Last change on this file since 9bf0f86 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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