source: buchla-68k/ram/ptwrite.c@ 0c834c5

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

Point of no return.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 =============================================================================
3 ptwrite.c -- librarian - write patch functions
4 Version 7 -- 1988-11-18 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGWE 0
9#define DEBUGPW 0
10
11#include "stddefs.h"
12#include "stdio.h"
13#include "hwdefs.h"
14#include "graphdef.h"
15#include "vsdd.h"
16#include "patch.h"
17
18#include "midas.h"
19#include "libdsp.h"
20
21#if (DEBUGPW|DEBUGWE)
22extern short debugsw;
23#endif
24
25#if DEBUGPW
26short debugpw = 1;
27#endif
28
29#if DEBUGWE
30extern short debugwe;
31#endif
32
33extern long chksum(char *area, long len);
34
35/*
36
37*/
38
39char ptsizes[] = {
40
41 0, /* NULL - end of list */
42 4, /* PA_KEY */
43 4, /* PA_TRG */
44 3, /* PA_PLS */
45 3, /* PA_LED */
46 4, /* PA_SLIN */
47 3, /* PA_SCTL */
48 2, /* PA_TUNE */
49 4, /* PA_RSET */
50 4, /* PA_RADD */
51 3, /* PA_INST */
52 6, /* PA_OSC */
53 3, /* PA_WAVA */
54 3, /* PA_WAVB */
55 3, /* PA_CNFG */
56 5, /* PA_LEVL */
57 6, /* PA_INDX */
58 6, /* PA_FREQ */
59 5, /* PA_FILT */
60 5, /* PA_FILQ */
61 5, /* PA_LOCN */
62 5, /* PA_DYNM */
63 4, /* PA_AUX */
64 4, /* PA_RATE */
65 4, /* PA_INTN */
66 4, /* PA_DPTH */
67 5 /* PA_VOUT */
68};
69
70/*
71
72*/
73
74/*
75 =============================================================================
76 ptsizer() -- return number of bytes necessary for storing active patches
77 =============================================================================
78*/
79
80long ptsizer(void)
81{
82 register short pp;
83 register long nb;
84
85 nb = 0L;
86
87 if (pp = find1st()) {
88
89 while (pp) {
90
91 nb += (ptsizes[PE_SPEC & patches[pp].paspec] + 4);
92 pp = findnxt(pp);
93 }
94 }
95
96 if (nb)
97 ++nb; /* ... and one for the terminator */
98
99#if DEBUGPW
100 if (debugsw AND debugpw)
101 printf("ptsizer(): %ld bytes required\n", nb);
102#endif
103
104 return(nb);
105}
106
107/*
108
109*/
110
111/*
112 =============================================================================
113 ptwrite() -- store a patch table
114 =============================================================================
115*/
116
117short ptwrite(FILE *fp)
118{
119 register short pp;
120 char cb, zero;
121
122#if DEBUGPW
123 if (debugsw AND debugpw)
124 printf("ptwrite($%08lX): entered\n", fp);
125#endif
126
127 zero = '\0';
128
129 ldwmsg("Busy -- Please stand by", (char *)0L, " writing patches",
130 LCFBX10, LCBBX10);
131
132 if (pp = find1st()) {
133
134 while (pp) {
135
136#if DEBUGWE
137 if (debugsw AND debugwe) {
138
139 printf("ptwrite(): %3d %04.4X %04.4X %04.4X %04.4X %04.4X %04.4X\n ",
140 pp, patches[pp].defnum, patches[pp].stmnum,
141 patches[pp].paspec, patches[pp].pasuba,
142 patches[pp].padat1, patches[pp].padat2);
143 }
144#endif
145
146 switch (cb = (PE_SPEC & patches[pp].paspec)) {
147
148 case PA_KEY:
149 case PA_TRG:
150
151 if (wr_ec(fp, &cb, 1L))
152 return(FAILURE);
153
154 if (wr_ec(fp, &patches[pp].defnum, 4L))
155 return(FAILURE);
156
157 if (wr_ec(fp, &patches[pp].pasuba, 2L))
158 return(FAILURE);
159
160 if (wr_ec(fp, (char *)&patches[pp].padat2 + 1, 1L))
161 return(FAILURE);
162
163 break;
164/*
165
166*/
167 case PA_PLS:
168 case PA_SCTL:
169
170 if (wr_ec(fp, &cb, 1L))
171 return(FAILURE);
172
173 if (wr_ec(fp, &patches[pp].defnum, 4L))
174 return(FAILURE);
175
176 if (wr_ec(fp, (char *)&patches[pp].pasuba + 1, 1L))
177 return(FAILURE);
178
179 if (wr_ec(fp, (char *)&patches[pp].padat2 + 1, 1L))
180 return(FAILURE);
181
182 break;
183
184 case PA_LED:
185
186 if (wr_ec(fp, &cb, 1L))
187 return(FAILURE);
188
189 if (wr_ec(fp, &patches[pp].defnum, 4L))
190 return(FAILURE);
191
192 if (wr_ec(fp, (char *)&patches[pp].pasuba + 1, 1L))
193 return(FAILURE);
194
195 if (wr_ec(fp, &patches[pp].padat1, 1L))
196 return(FAILURE);
197
198 break;
199
200 case PA_SLIN:
201
202 if (wr_ec(fp, &cb, 1L))
203 return(FAILURE);
204
205 if (wr_ec(fp, &patches[pp].defnum, 4L))
206 return(FAILURE);
207
208 if (wr_ec(fp, (char *)&patches[pp].pasuba + 1, 1L))
209 return(FAILURE);
210
211 if (wr_ec(fp, &patches[pp].padat1, 2L))
212 return(FAILURE);
213
214 break;
215
216 case PA_TUNE:
217
218 if (wr_ec(fp, &cb, 1L))
219 return(FAILURE);
220
221 if (wr_ec(fp, &patches[pp].defnum, 4L))
222 return(FAILURE);
223
224 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
225 return(FAILURE);
226
227 break;
228/*
229
230*/
231 case PA_RSET:
232 case PA_RADD:
233
234 if (wr_ec(fp, &cb, 1L))
235 return(FAILURE);
236
237 if (wr_ec(fp, &patches[pp].defnum, 4L))
238 return(FAILURE);
239
240 if (wr_ec(fp, (char *)&patches[pp].pasuba + 1, 1L))
241 return(FAILURE);
242
243 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
244 return(FAILURE);
245
246 if (wr_ec(fp, (char *)&patches[pp].padat2 + 1, 1L))
247 return(FAILURE);
248
249 break;
250
251 case PA_INST:
252 case PA_WAVA:
253 case PA_WAVB:
254 case PA_CNFG:
255
256 if (wr_ec(fp, &cb, 1L))
257 return(FAILURE);
258
259 if (wr_ec(fp, &patches[pp].defnum, 4L))
260 return(FAILURE);
261
262 if (wr_ec(fp, &patches[pp].pasuba, 1L))
263 return(FAILURE);
264
265 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
266 return(FAILURE);
267
268 break;
269
270 case PA_OSC:
271 case PA_INDX:
272 case PA_FREQ:
273
274 if (wr_ec(fp, &cb, 1L))
275 return(FAILURE);
276
277 if (wr_ec(fp, &patches[pp].defnum, 4L))
278 return(FAILURE);
279
280 if (wr_ec(fp, &patches[pp].pasuba, 2L))
281 return(FAILURE);
282
283 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
284 return(FAILURE);
285
286 if (wr_ec(fp, &patches[pp].padat2, 2L))
287 return(FAILURE);
288
289 break;
290/*
291
292*/
293 case PA_LEVL:
294 case PA_FILT:
295 case PA_FILQ:
296 case PA_LOCN:
297 case PA_DYNM:
298
299 if (wr_ec(fp, &cb, 1L))
300 return(FAILURE);
301
302 if (wr_ec(fp, &patches[pp].defnum, 4L))
303 return(FAILURE);
304
305 if (wr_ec(fp, &patches[pp].pasuba, 1L))
306 return(FAILURE);
307
308 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
309 return(FAILURE);
310
311 if (wr_ec(fp, &patches[pp].padat2, 2L))
312 return(FAILURE);
313
314 break;
315
316 case PA_AUX:
317 case PA_RATE:
318 case PA_INTN:
319 case PA_DPTH:
320
321 if (wr_ec(fp, &cb, 1L))
322 return(FAILURE);
323
324 if (wr_ec(fp, &patches[pp].defnum, 4L))
325 return(FAILURE);
326
327 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
328 return(FAILURE);
329
330 if (wr_ec(fp, &patches[pp].padat2, 2L))
331 return(FAILURE);
332
333 break;
334
335 case PA_VOUT:
336
337 if (wr_ec(fp, &cb, 1L))
338 return(FAILURE);
339
340 if (wr_ec(fp, &patches[pp].defnum, 4L))
341 return(FAILURE);
342
343 if (wr_ec(fp, (char *)&patches[pp].pasuba + 1, 1L))
344 return(FAILURE);
345
346 if (wr_ec(fp, (char *)&patches[pp].padat1 + 1, 1L))
347 return(FAILURE);
348
349 if (wr_ec(fp, &patches[pp].padat2, 2L))
350 return(FAILURE);
351
352 break;
353/*
354
355*/
356 default:
357
358 return(FAILURE);
359 }
360
361#if DEBUGWE
362 if (debugsw AND debugwe)
363 printf("\n\n");
364#endif
365
366 pp = findnxt(pp); /* find the next patch */
367 }
368
369 if (wr_ec(fp, &zero, 1L)) /* write the terminator */
370 return(FAILURE);
371
372 } else {
373
374 return(FAILURE); /* no patches to write */
375 }
376
377#if DEBUGPW
378 if (debugsw AND debugpw)
379 printf("ptwrite(): SUCCESS\n");
380#endif
381
382 return(SUCCESS);
383}
Note: See TracBrowser for help on using the repository browser.