source: buchla-68k/ram/ptread.c@ b28a12e

Last change on this file since b28a12e was b28a12e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Zero redundant declarations.

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