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