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

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

Added include files for global functions and variables.

  • Property mode set to 100644
File size: 8.0 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 "all.h"
12
13extern int16_t finddpe(void);
14extern int16_t findpte(void);
15extern int16_t rd_ec(FILE *fp, int8_t *to, int32_t len);
16extern uint16_t dt_alc(void);
17extern uint16_t pt_alc(void);
18extern void clrlsel(void);
19extern void ldermsg(int8_t *p1, int8_t *p2, int8_t *p3, uint16_t p4, uint16_t p5);
20extern void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor);
21extern void voidpb(void);
22
23#if (DEBUGRE|DEBUGSP)
24extern short debugsw;
25#endif
26
27#if DEBUGRE
28extern short debugre;
29#endif
30
31#if DEBUGSP
32short debugsp = 1;
33#endif
34
35extern uint16_t dpecpos;
36extern uint16_t dpepred;
37extern uint16_t dpesucc;
38extern int16_t errno;
39extern int16_t ptecpos;
40extern int16_t ptepred;
41extern int16_t ptesucc;
42
43extern struct patch ptebuf;
44
45/*
46
47*/
48
49/*
50 =============================================================================
51 stashp() -- stash an incoming patch
52 =============================================================================
53*/
54
55int16_t stashp(void)
56{
57 register int16_t c;
58 register uint16_t np, stim;
59
60 c = findpte();
61
62 if (c EQ 0) { /* old patch -- just update it */
63
64 memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
65 patches[ptecpos].paspec |= PE_TBIT; /* define it */
66
67#if DEBUGSP
68 if (debugsw AND debugsp) {
69
70 printf("stashp(): UPDATED\n");
71 SnapPTV("stashp");
72 }
73#endif
74
75 return(SUCCESS);
76 }
77
78 /* allocate a patch entry and fill it in */
79
80 if (0 EQ (ptecpos = pt_alc())) {
81
82#if DEBUGSP
83 if (debugsw AND debugsp)
84 printf("stashp(): patch table FULL\n");
85#endif
86 return(FAILURE); /* no patch entries left */
87 }
88
89 memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
90 patches[ptecpos].paspec |= PE_TBIT; /* define it */
91 stim = TRG_MASK & ptebuf.stmnum;
92
93 if (c EQ 1) { /* new patch -- no STM entry yet */
94
95 ptepred = 0;
96 stmptr[stim] = ptecpos;
97 }
98/*
99
100*/
101 /* put patch in STM chain */
102
103 if (ptepred) { /* predecessor exits */
104
105 ptesucc = patches[ptepred].nextstm;
106
107 patches[ptecpos].nextstm = ptesucc;
108 patches[ptecpos].prevstm = ptepred;
109
110 patches[ptepred].nextstm = ptecpos;
111
112 if (ptesucc)
113 patches[ptesucc].prevstm = ptecpos;
114
115 } else { /* no predecessor */
116
117 patches[ptecpos].prevstm = 0;
118
119 if (c EQ -1) {
120
121 ptesucc = stmptr[stim];
122
123 patches[ptecpos].nextstm = ptesucc;
124
125 patches[ptesucc].prevstm = ptecpos;
126
127 stmptr[stim] = ptecpos;
128
129 } else {
130
131 patches[ptecpos].nextstm = 0;
132 }
133 }
134/*
135
136*/
137 /* update DEF table */
138
139 if (0 EQ (c = finddpe())) {
140
141#if DEBUGSP
142 if (debugsw AND debugsp) {
143
144 printf("stashp(): defent already exists -- dpecpos = %d\n",
145 dpecpos);
146
147 printf("stashp(): ENTERED\n");
148 SnapPTV("stashp");
149 }
150#endif
151 return(SUCCESS); /* defent already exists */
152 }
153
154 if (0 EQ (dpecpos = dt_alc())) {
155
156#if DEBUGSP
157 if (debugsw AND debugsp)
158 printf("stashp(): defent table FULL\n");
159#endif
160 return(FAILURE); /* no defents left */
161 }
162
163 defents[dpecpos].nextdef = 0;
164 defents[dpecpos].stm = ptebuf.stmnum;
165 defents[dpecpos].adspec = ptebuf.paspec;
166 defents[dpecpos].adsuba = ptebuf.pasuba;
167 defents[dpecpos].addat1 = ptebuf.padat1;
168
169 np = TRG_MASK & ptebuf.defnum;
170
171 if (c EQ 1) {
172
173 dpepred = 0;
174 defptr[np] = dpecpos;
175 }
176/*
177
178*/
179 if (dpepred) {
180
181 dpesucc = defents[dpepred].nextdef;
182 defents[dpecpos].nextdef = dpesucc;
183 defents[dpepred].nextdef = dpecpos;
184
185 } else {
186
187 if (c EQ -1) {
188
189 dpesucc = defptr[np];
190 defents[dpecpos].nextdef = dpesucc;
191 defptr[np] = dpecpos;
192
193 } else {
194
195 defents[dpecpos].nextdef = 0;
196 }
197 }
198
199#if DEBUGSP
200 if (debugsw AND debugsp) {
201
202 printf("stashp(): new defent created -- dpecpos = %d\n",
203 dpecpos);
204
205 printf("stashp(): ENTERED\n");
206 SnapPTV("stashp");
207 }
208#endif
209 return(SUCCESS);
210}
211
212/*
213
214*/
215
216/*
217 =============================================================================
218 ptioerr() -- put up an I/O error message
219 =============================================================================
220*/
221
222void ptioerr(void)
223{
224 int8_t erms[40];
225
226 clrlsel();
227
228 sprintf(erms, " errno = %d", errno);
229
230 ldermsg("Couldn't read", " the patch table", erms,
231 LD_EMCF, LD_EMCB);
232}
233
234/*
235 =============================================================================
236 nopatch() -- give an error message after running out of space
237 =============================================================================
238*/
239
240void nopatch(void)
241{
242 clrlsel();
243
244 ldermsg("Couldn't read", " the patch table.", " Ran out of space",
245 LD_EMCF, LD_EMCB);
246}
247
248/*
249
250*/
251
252/*
253 =============================================================================
254 ptread() -- read a patch
255 =============================================================================
256*/
257
258int16_t ptread(FILE *fp)
259{
260 register int16_t go;
261 int8_t cb;
262
263 go = TRUE;
264
265 ldwmsg(" Busy -- please stand by", (int8_t *)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, (int8_t *)&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, (int8_t *)&ptebuf.pasuba + 1, 1L))
311 return(FAILURE);
312
313 if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
314 return(FAILURE);
315
316 break;
317
318/*
319
320*/
321 case PA_LED:
322
323 if (rd_ec(fp, (int8_t *)&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, (int8_t *)&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, (int8_t *)&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, (int8_t *)&ptebuf.pasuba + 1, 1L))
354 return(FAILURE);
355
356 if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
357 return(FAILURE);
358
359 if (rd_ec(fp, (int8_t *)&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, (int8_t *)&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, (int8_t *)&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, (int8_t *)&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, (int8_t *)&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, (int8_t *)&ptebuf.pasuba + 1, 1L))
427 return(FAILURE);
428
429 if (rd_ec(fp, (int8_t *)&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();
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}
467
Note: See TracBrowser for help on using the repository browser.