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

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

Removed form-feed comments.

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