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