1 | /*
|
---|
2 | =============================================================================
|
---|
3 | librw.c -- MIDAS librarian read / write functions
|
---|
4 | Version 22 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define DEBUGIT 0
|
---|
9 |
|
---|
10 | #include "stddefs.h"
|
---|
11 | #include "biosdefs.h"
|
---|
12 | #include "memory.h"
|
---|
13 | #include "stdio.h"
|
---|
14 | #include "errno.h"
|
---|
15 |
|
---|
16 | #include "ascii.h"
|
---|
17 | #include "charset.h"
|
---|
18 | #include "fpu.h"
|
---|
19 | #include "hwdefs.h"
|
---|
20 | #include "vsdd.h"
|
---|
21 | #include "vsddsw.h"
|
---|
22 | #include "vsddvars.h"
|
---|
23 | #include "graphdef.h"
|
---|
24 | #include "charset.h"
|
---|
25 | #include "fields.h"
|
---|
26 | #include "patch.h"
|
---|
27 | #include "score.h"
|
---|
28 | #include "scfns.h"
|
---|
29 |
|
---|
30 | #include "midas.h"
|
---|
31 | #include "asgdsp.h"
|
---|
32 | #include "instdsp.h"
|
---|
33 | #include "libdsp.h"
|
---|
34 | #include "wsdsp.h"
|
---|
35 |
|
---|
36 | /* |
---|
37 |
|
---|
38 | */
|
---|
39 |
|
---|
40 | #if DEBUGIT
|
---|
41 | extern short debugsw;
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | extern int8_t *slotnam(uint16_t slot, uint16_t kind);
|
---|
45 |
|
---|
46 | extern int32_t chksum(int8_t *area, int32_t len);
|
---|
47 |
|
---|
48 | extern int16_t ptread(FILE *fp);
|
---|
49 | extern int16_t ptwrite(FILE *fp);
|
---|
50 | extern int16_t rd_ec(FILE *fp, int8_t *to, int32_t len);
|
---|
51 | extern int16_t scread(int16_t ns, FILE *fp);
|
---|
52 | extern int16_t scwrite(int16_t sn, FILE *fp);
|
---|
53 | extern int16_t sqread(FILE *fp);
|
---|
54 | extern int16_t sqwrite(FILE *fp);
|
---|
55 | extern int16_t wr_ec(FILE *fp, int8_t *from, int32_t len);
|
---|
56 | extern void clrlsel(void);
|
---|
57 | extern void initpt(void);
|
---|
58 | extern void initsq(void);
|
---|
59 | extern void ldbusy(int8_t *msg);
|
---|
60 | extern void ldermsg(int8_t *p1, int8_t *p2, int8_t *p3, uint16_t p4, uint16_t p5);
|
---|
61 | extern void ldswin(int16_t n);
|
---|
62 | extern void makelh(int16_t kind);
|
---|
63 | extern void postio(void);
|
---|
64 | extern void preio(void);
|
---|
65 | extern void streset(void);
|
---|
66 |
|
---|
67 | extern int16_t ldslot, lderrsw, lrasw;
|
---|
68 | extern int16_t tunlib[][128];
|
---|
69 |
|
---|
70 | extern int32_t lcsum, schksum, sntlreq;
|
---|
71 |
|
---|
72 | extern int8_t tunname[][32];
|
---|
73 | extern int8_t ldfile[9];
|
---|
74 | extern int8_t ldcmnt[38];
|
---|
75 |
|
---|
76 | extern struct mlibhdr ldhead;
|
---|
77 | extern struct asgent asgtab[];
|
---|
78 | extern struct wstbl wslib[];
|
---|
79 | extern struct instdef idefs[];
|
---|
80 | extern struct s_time stimes[N_SCORES][N_SECTS];
|
---|
81 |
|
---|
82 | /* |
---|
83 |
|
---|
84 | */
|
---|
85 |
|
---|
86 | /*
|
---|
87 | =============================================================================
|
---|
88 | wrt_asg() -- write an assignment on the disk
|
---|
89 | =============================================================================
|
---|
90 | */
|
---|
91 |
|
---|
92 | int16_t wrt_asg(int16_t slot)
|
---|
93 | {
|
---|
94 | register FILE *fp;
|
---|
95 | register int16_t i;
|
---|
96 | int8_t cstemp[8];
|
---|
97 |
|
---|
98 | preio(); /* kill LCD backlight */
|
---|
99 |
|
---|
100 | fp = fopenb(slotnam(slot, FT_ASG), "w");
|
---|
101 |
|
---|
102 | if ((FILE *)NULL EQ fp) {
|
---|
103 |
|
---|
104 | ldermsg("Couldn't create a file",
|
---|
105 | " for the assignments", (int8_t *)NULL,
|
---|
106 | LD_EMCF, LD_EMCB);
|
---|
107 |
|
---|
108 | postio(); /* restore LCD backlight */
|
---|
109 | streset();
|
---|
110 | return(FAILURE);
|
---|
111 | }
|
---|
112 |
|
---|
113 | makelh(FT_ASG); /* make header */
|
---|
114 |
|
---|
115 | for (i = 0; i < NASGLIB; i++)
|
---|
116 | lcsum += chksum(&asgtab[i + 1], (int32_t)(sizeof (struct asgent)));
|
---|
117 |
|
---|
118 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
119 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
120 |
|
---|
121 | #if DEBUGIT
|
---|
122 | if (debugsw)
|
---|
123 | printf("wrt_asg(): hdr=[%-.56s]\n", &ldhead);
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | /* |
---|
127 |
|
---|
128 | */
|
---|
129 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
130 |
|
---|
131 | streset();
|
---|
132 | return(FAILURE);
|
---|
133 | }
|
---|
134 |
|
---|
135 | for (i = 0; i < NASGLIB; i++) {
|
---|
136 |
|
---|
137 | if (wr_ec(fp, &asgtab[i + 1], (int32_t)(sizeof (struct asgent)))) {
|
---|
138 |
|
---|
139 | streset();
|
---|
140 | return(FAILURE);
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | fclose(fp);
|
---|
145 | postio(); /* restore LCD backlight */
|
---|
146 | return(SUCCESS);
|
---|
147 | }
|
---|
148 |
|
---|
149 | /* |
---|
150 |
|
---|
151 | */
|
---|
152 |
|
---|
153 | /*
|
---|
154 | =============================================================================
|
---|
155 | get_asg() -- read an assignment library from the disk
|
---|
156 | =============================================================================
|
---|
157 | */
|
---|
158 |
|
---|
159 | int16_t get_asg(void)
|
---|
160 | {
|
---|
161 | register FILE *fp;
|
---|
162 | register int16_t i;
|
---|
163 |
|
---|
164 | preio(); /* kill LCD backlight */
|
---|
165 |
|
---|
166 | fp = fopenb(slotnam(ldslot, FT_ASG), "r");
|
---|
167 |
|
---|
168 | if ((FILE *)NULL EQ fp) {
|
---|
169 |
|
---|
170 | ldermsg("Couldn't open the file",
|
---|
171 | " for the assignments", (int8_t *)NULL,
|
---|
172 | LD_EMCF, LD_EMCB);
|
---|
173 |
|
---|
174 | postio(); /* restore LCD backlight */
|
---|
175 | clrlsel();
|
---|
176 | return(FAILURE);
|
---|
177 | }
|
---|
178 |
|
---|
179 | memcpy(ldfile, " ", 8);
|
---|
180 | memcpy(ldcmnt, " ", 37);
|
---|
181 | ldswin(3);
|
---|
182 | ldswin(5);
|
---|
183 |
|
---|
184 | /* |
---|
185 |
|
---|
186 | */
|
---|
187 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
188 |
|
---|
189 | clrlsel();
|
---|
190 | return(FAILURE);
|
---|
191 | }
|
---|
192 |
|
---|
193 | #if DEBUGIT
|
---|
194 | if (debugsw)
|
---|
195 | printf("get_asg(): hdr=[%-.56s]\n", &ldhead);
|
---|
196 | #endif
|
---|
197 |
|
---|
198 |
|
---|
199 | for (i = 0; i < NASGLIB; i++) {
|
---|
200 |
|
---|
201 | if (rd_ec(fp, &asgtab[i + 1], (int32_t)(sizeof (struct asgent)))) {
|
---|
202 |
|
---|
203 | clrlsel();
|
---|
204 | return(FAILURE);
|
---|
205 | }
|
---|
206 | }
|
---|
207 |
|
---|
208 | clrlsel();
|
---|
209 | fclose(fp);
|
---|
210 | postio(); /* restore LCD backlight */
|
---|
211 | return(SUCCESS);
|
---|
212 | }
|
---|
213 |
|
---|
214 | /* |
---|
215 |
|
---|
216 | */
|
---|
217 |
|
---|
218 | /*
|
---|
219 | =============================================================================
|
---|
220 | wrt_orc() -- write an orchestra on the disk
|
---|
221 | =============================================================================
|
---|
222 | */
|
---|
223 |
|
---|
224 | int16_t wrt_orc(int16_t slot, int16_t lorh)
|
---|
225 | {
|
---|
226 | register FILE *fp;
|
---|
227 | register int16_t i;
|
---|
228 | register struct instdef *ip;
|
---|
229 | int8_t cstemp[8];
|
---|
230 |
|
---|
231 | if (lorh)
|
---|
232 | ldbusy(" Writing Hi Orch");
|
---|
233 | else
|
---|
234 | ldbusy(" Writing Lo Orch");
|
---|
235 |
|
---|
236 | preio(); /* kill LCD backlight */
|
---|
237 |
|
---|
238 | fp = fopenb(slotnam(slot, FT_ORC), "w");
|
---|
239 |
|
---|
240 | if ((FILE *)NULL EQ fp) {
|
---|
241 |
|
---|
242 | ldermsg("Couldn't create a file",
|
---|
243 | " for the orchestra", (int8_t *)NULL,
|
---|
244 | LD_EMCF, LD_EMCB);
|
---|
245 |
|
---|
246 | postio(); /* restore LCD backlight */
|
---|
247 | streset();
|
---|
248 | return(FAILURE);
|
---|
249 | }
|
---|
250 |
|
---|
251 | makelh(FT_ORC); /* make header */
|
---|
252 |
|
---|
253 | for (i = 0; i < NINORC; i++) {
|
---|
254 |
|
---|
255 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
256 |
|
---|
257 | lcsum += chksum(ip, (int32_t)OR_LEN1);
|
---|
258 | lcsum += chksum(ip->idhwvao, (int32_t)OR_LEN2);
|
---|
259 | lcsum += chksum(ip->idhwvbo, (int32_t)OR_LEN2);
|
---|
260 | }
|
---|
261 |
|
---|
262 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
263 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
264 |
|
---|
265 | #if DEBUGIT
|
---|
266 | if (debugsw)
|
---|
267 | printf("wrt_orc(): hdr=[%-.56s]\n", &ldhead);
|
---|
268 | #endif
|
---|
269 |
|
---|
270 | /* |
---|
271 |
|
---|
272 | */
|
---|
273 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
274 |
|
---|
275 | streset();
|
---|
276 | return(FAILURE);
|
---|
277 | }
|
---|
278 |
|
---|
279 | for (i = 0; i < NINORC; i++) {
|
---|
280 |
|
---|
281 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
282 |
|
---|
283 | if (wr_ec(fp, ip, (int32_t)OR_LEN1)) { /* functions */
|
---|
284 |
|
---|
285 | streset();
|
---|
286 | return(FAILURE);
|
---|
287 | }
|
---|
288 |
|
---|
289 | if (wr_ec(fp, ip->idhwvao, (int32_t)OR_LEN2)) { /* WS A */
|
---|
290 |
|
---|
291 | streset();
|
---|
292 | return(FAILURE);
|
---|
293 | }
|
---|
294 |
|
---|
295 | if (wr_ec(fp, ip->idhwvbo, (int32_t)OR_LEN2)) { /* WS B */
|
---|
296 |
|
---|
297 | streset();
|
---|
298 | return(FAILURE);
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | fclose(fp);
|
---|
303 | postio(); /* restore LCD backlight */
|
---|
304 | return(SUCCESS);
|
---|
305 | }
|
---|
306 |
|
---|
307 | /* |
---|
308 |
|
---|
309 | */
|
---|
310 |
|
---|
311 | /*
|
---|
312 | =============================================================================
|
---|
313 | get_orc() -- read an orchestra from the disk
|
---|
314 | =============================================================================
|
---|
315 | */
|
---|
316 |
|
---|
317 | int16_t get_orc(int16_t lorh, int16_t kind)
|
---|
318 | {
|
---|
319 | register FILE *fp;
|
---|
320 | register int16_t i;
|
---|
321 | register struct instdef *ip;
|
---|
322 |
|
---|
323 | if (lorh)
|
---|
324 | ldbusy(" Reading Hi Orch");
|
---|
325 | else
|
---|
326 | ldbusy(" Reading Lo Orch");
|
---|
327 |
|
---|
328 | preio(); /* kill LCD backlight */
|
---|
329 |
|
---|
330 | fp = fopenb(slotnam(ldslot, kind), "r");
|
---|
331 |
|
---|
332 | if ((FILE *)NULL EQ fp) {
|
---|
333 |
|
---|
334 | ldermsg("Couldn't open the file",
|
---|
335 | " for the orchestra", (int8_t *)NULL,
|
---|
336 | LD_EMCF, LD_EMCB);
|
---|
337 |
|
---|
338 | postio(); /* restore LCD backlight */
|
---|
339 | clrlsel();
|
---|
340 | return(FAILURE);
|
---|
341 | }
|
---|
342 |
|
---|
343 | memcpy(ldfile, " ", 8);
|
---|
344 | memcpy(ldcmnt, " ", 37);
|
---|
345 | ldswin(3);
|
---|
346 | ldswin(5);
|
---|
347 |
|
---|
348 | /* |
---|
349 |
|
---|
350 | */
|
---|
351 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
352 |
|
---|
353 | clrlsel();
|
---|
354 | return(FAILURE);
|
---|
355 | }
|
---|
356 |
|
---|
357 | #if DEBUGIT
|
---|
358 | if (debugsw)
|
---|
359 | printf("get_orc(): hdr=[%-.56s]\n", &ldhead);
|
---|
360 | #endif
|
---|
361 |
|
---|
362 |
|
---|
363 | for (i = 0; i < NINORC; i++) {
|
---|
364 |
|
---|
365 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
366 |
|
---|
367 | if (rd_ec(fp, ip, (int32_t)OR_LEN1)) { /* functions */
|
---|
368 |
|
---|
369 | clrlsel();
|
---|
370 | return(FAILURE);
|
---|
371 | }
|
---|
372 |
|
---|
373 | if (rd_ec(fp, ip->idhwvao, (int32_t)OR_LEN2)) { /* WS A */
|
---|
374 |
|
---|
375 | clrlsel();
|
---|
376 | return(FAILURE);
|
---|
377 | }
|
---|
378 |
|
---|
379 | if (rd_ec(fp, ip->idhwvbo, (int32_t)OR_LEN2)) { /* WS B */
|
---|
380 |
|
---|
381 | clrlsel();
|
---|
382 | return(FAILURE);
|
---|
383 | }
|
---|
384 |
|
---|
385 | /* unpack offsets (and eventually harmonics) into finals */
|
---|
386 |
|
---|
387 | memcpyw(ip->idhwvaf, ip->idhwvao, NUMWPNT);
|
---|
388 | memcpyw(ip->idhwvbf, ip->idhwvbo, NUMWPNT);
|
---|
389 | }
|
---|
390 |
|
---|
391 | clrlsel();
|
---|
392 | fclose(fp);
|
---|
393 | postio(); /* restore LCD backlight */
|
---|
394 | return(SUCCESS);
|
---|
395 | }
|
---|
396 |
|
---|
397 | /* |
---|
398 |
|
---|
399 | */
|
---|
400 |
|
---|
401 | /*
|
---|
402 | =============================================================================
|
---|
403 | wrt_tun() -- write a tuning library on the disk
|
---|
404 | =============================================================================
|
---|
405 | */
|
---|
406 |
|
---|
407 | int16_t wrt_tun(int16_t slot)
|
---|
408 | {
|
---|
409 | register FILE *fp;
|
---|
410 | register int16_t i;
|
---|
411 | int8_t cstemp[8];
|
---|
412 |
|
---|
413 | preio(); /* kill LCD backlight */
|
---|
414 |
|
---|
415 | fp = fopenb(slotnam(slot, FT_TUN), "w");
|
---|
416 |
|
---|
417 | if ((FILE *)NULL EQ fp) {
|
---|
418 |
|
---|
419 | ldermsg("Couldn't create a file",
|
---|
420 | " for the tunings", (int8_t *)NULL,
|
---|
421 | LD_EMCF, LD_EMCB);
|
---|
422 |
|
---|
423 | postio(); /* restore LCD backlight */
|
---|
424 | streset();
|
---|
425 | return(FAILURE);
|
---|
426 | }
|
---|
427 |
|
---|
428 | makelh(FT_TUN); /* make header */
|
---|
429 |
|
---|
430 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
431 |
|
---|
432 | lcsum += chksum(&tunlib[i + 1], 256L);
|
---|
433 | lcsum += chksum(&tunname[i + 1], 32L);
|
---|
434 | }
|
---|
435 |
|
---|
436 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
437 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
438 |
|
---|
439 | #if DEBUGIT
|
---|
440 | if (debugsw)
|
---|
441 | printf("wrt_tun(): hdr=[%-.56s]\n", &ldhead);
|
---|
442 | #endif
|
---|
443 |
|
---|
444 | /* |
---|
445 |
|
---|
446 | */
|
---|
447 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
448 |
|
---|
449 | streset();
|
---|
450 | return(FAILURE);
|
---|
451 | }
|
---|
452 |
|
---|
453 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
454 |
|
---|
455 | if (wr_ec(fp, &tunlib[i + 1], 256L)) {
|
---|
456 |
|
---|
457 | streset();
|
---|
458 | return(FAILURE);
|
---|
459 | }
|
---|
460 |
|
---|
461 | if (wr_ec(fp, &tunname[i + 1], 32L)) {
|
---|
462 |
|
---|
463 | streset();
|
---|
464 | return(FAILURE);
|
---|
465 | }
|
---|
466 | }
|
---|
467 |
|
---|
468 | fclose(fp);
|
---|
469 | postio(); /* restore LCD backlight */
|
---|
470 | return(SUCCESS);
|
---|
471 | }
|
---|
472 |
|
---|
473 | /* |
---|
474 |
|
---|
475 | */
|
---|
476 |
|
---|
477 | /*
|
---|
478 | =============================================================================
|
---|
479 | get_tun() -- read a tuning library from the disk
|
---|
480 | =============================================================================
|
---|
481 | */
|
---|
482 |
|
---|
483 | int16_t get_tun(void)
|
---|
484 | {
|
---|
485 | register FILE *fp;
|
---|
486 | register int16_t i;
|
---|
487 |
|
---|
488 | preio(); /* kill LCD backlight */
|
---|
489 |
|
---|
490 | fp = fopenb(slotnam(ldslot, FT_TUN), "r");
|
---|
491 |
|
---|
492 | if ((FILE *)NULL EQ fp) {
|
---|
493 |
|
---|
494 | ldermsg("Couldn't open the file",
|
---|
495 | " for the tunings", (int8_t *)NULL,
|
---|
496 | LD_EMCF, LD_EMCB);
|
---|
497 |
|
---|
498 | postio(); /* restore LCD backlight */
|
---|
499 | clrlsel();
|
---|
500 | return(FAILURE);
|
---|
501 | }
|
---|
502 |
|
---|
503 | memcpy(ldfile, " ", 8);
|
---|
504 | memcpy(ldcmnt, " ", 37);
|
---|
505 | ldswin(3);
|
---|
506 | ldswin(5);
|
---|
507 |
|
---|
508 | /* |
---|
509 |
|
---|
510 | */
|
---|
511 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
512 |
|
---|
513 | clrlsel();
|
---|
514 | return(FAILURE);
|
---|
515 | }
|
---|
516 |
|
---|
517 | #if DEBUGIT
|
---|
518 | if (debugsw)
|
---|
519 | printf("get_tun(): hdr=[%-.56s]\n", &ldhead);
|
---|
520 | #endif
|
---|
521 |
|
---|
522 |
|
---|
523 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
524 |
|
---|
525 | if (rd_ec(fp, &tunlib[i + 1], 256L)) {
|
---|
526 |
|
---|
527 | clrlsel();
|
---|
528 | return(FAILURE);
|
---|
529 | }
|
---|
530 |
|
---|
531 | if (rd_ec(fp, &tunname[i + 1], 32L)) {
|
---|
532 |
|
---|
533 | clrlsel();
|
---|
534 | return(FAILURE);
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | clrlsel();
|
---|
539 | fclose(fp);
|
---|
540 | postio(); /* restore LCD backlight */
|
---|
541 | return(SUCCESS);
|
---|
542 | }
|
---|
543 |
|
---|
544 | /* |
---|
545 |
|
---|
546 | */
|
---|
547 |
|
---|
548 | /*
|
---|
549 | =============================================================================
|
---|
550 | wrt_pat() -- write a patch file on the disk
|
---|
551 | =============================================================================
|
---|
552 | */
|
---|
553 |
|
---|
554 | int16_t wrt_pat(int16_t slot)
|
---|
555 | {
|
---|
556 | register FILE *fp;
|
---|
557 | int8_t cstemp[8];
|
---|
558 |
|
---|
559 | preio(); /* kill LCD backlight */
|
---|
560 |
|
---|
561 | fp = fopenb(slotnam(slot, FT_PAT), "w");
|
---|
562 |
|
---|
563 | if ((FILE *)NULL EQ fp) {
|
---|
564 |
|
---|
565 | ldermsg("Couldn't create a file",
|
---|
566 | " for the patches", (int8_t *)NULL,
|
---|
567 | LD_EMCF, LD_EMCB);
|
---|
568 |
|
---|
569 | postio(); /* restore LCD backlight */
|
---|
570 | streset();
|
---|
571 | return(FAILURE);
|
---|
572 | }
|
---|
573 |
|
---|
574 | makelh(FT_PAT); /* make header */
|
---|
575 |
|
---|
576 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
577 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
578 |
|
---|
579 | #if DEBUGIT
|
---|
580 | if (debugsw)
|
---|
581 | printf("wrt_pat(): hdr=[%-.56s]\n", &ldhead);
|
---|
582 | #endif
|
---|
583 |
|
---|
584 | /* |
---|
585 |
|
---|
586 | */
|
---|
587 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
588 |
|
---|
589 | streset();
|
---|
590 | return(FAILURE);
|
---|
591 | }
|
---|
592 |
|
---|
593 | if (ptwrite(fp)) { /* patches */
|
---|
594 |
|
---|
595 | streset();
|
---|
596 | return(FAILURE);
|
---|
597 | }
|
---|
598 |
|
---|
599 | fclose(fp);
|
---|
600 | postio(); /* restore LCD backlight */
|
---|
601 | return(SUCCESS);
|
---|
602 | }
|
---|
603 |
|
---|
604 | /* |
---|
605 |
|
---|
606 | */
|
---|
607 |
|
---|
608 | /*
|
---|
609 | =============================================================================
|
---|
610 | get_pat() -- read a patch file from the disk
|
---|
611 | =============================================================================
|
---|
612 | */
|
---|
613 |
|
---|
614 | int16_t get_pat(void)
|
---|
615 | {
|
---|
616 | register FILE *fp;
|
---|
617 |
|
---|
618 | preio(); /* kill LCD backlight */
|
---|
619 |
|
---|
620 | fp = fopenb(slotnam(ldslot, FT_PAT), "r");
|
---|
621 |
|
---|
622 | if ((FILE *)NULL EQ fp) {
|
---|
623 |
|
---|
624 | ldermsg("Couldn't open the file",
|
---|
625 | " for the patches", (int8_t *)NULL,
|
---|
626 | LD_EMCF, LD_EMCB);
|
---|
627 |
|
---|
628 | postio(); /* restore LCD backlight */
|
---|
629 | clrlsel();
|
---|
630 | return(FAILURE);
|
---|
631 | }
|
---|
632 |
|
---|
633 | memcpy(ldfile, " ", 8);
|
---|
634 | memcpy(ldcmnt, " ", 37);
|
---|
635 | ldswin(3);
|
---|
636 | ldswin(5);
|
---|
637 |
|
---|
638 | /* |
---|
639 |
|
---|
640 | */
|
---|
641 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
642 |
|
---|
643 | clrlsel();
|
---|
644 | return(FAILURE);
|
---|
645 | }
|
---|
646 |
|
---|
647 | #if DEBUGIT
|
---|
648 | if (debugsw)
|
---|
649 | printf("get_pat(): hdr=[%-.56s]\n", &ldhead);
|
---|
650 | #endif
|
---|
651 |
|
---|
652 | if (lrasw EQ 0) /* clear all patches if in replace mode */
|
---|
653 | initpt();
|
---|
654 |
|
---|
655 | if (ptread(fp)) {
|
---|
656 |
|
---|
657 | clrlsel();
|
---|
658 | return(FAILURE);
|
---|
659 | }
|
---|
660 |
|
---|
661 | fclose(fp);
|
---|
662 | postio(); /* restore LCD backlight */
|
---|
663 | clrlsel();
|
---|
664 | return(SUCCESS);
|
---|
665 | }
|
---|
666 |
|
---|
667 | /* |
---|
668 |
|
---|
669 | */
|
---|
670 |
|
---|
671 | /*
|
---|
672 | =============================================================================
|
---|
673 | wrt_scr() -- write a score file on the disk
|
---|
674 | =============================================================================
|
---|
675 | */
|
---|
676 |
|
---|
677 | int16_t wrt_scr(int16_t slot)
|
---|
678 | {
|
---|
679 | register FILE *fp;
|
---|
680 | register int16_t i;
|
---|
681 | int32_t tnb;
|
---|
682 | int8_t cstemp[8];
|
---|
683 |
|
---|
684 | preio(); /* kill LCD backlight */
|
---|
685 |
|
---|
686 | fp = fopenb(slotnam(slot, FT_SCR), "w");
|
---|
687 |
|
---|
688 | if ((FILE *)NULL EQ fp) {
|
---|
689 |
|
---|
690 | ldermsg("Couldn't create a file",
|
---|
691 | " for the scores", (int8_t *)NULL,
|
---|
692 | LD_EMCF, LD_EMCB);
|
---|
693 |
|
---|
694 | postio(); /* restore LCD backlight */
|
---|
695 | streset();
|
---|
696 | return(FAILURE);
|
---|
697 | }
|
---|
698 |
|
---|
699 | makelh(FT_SCR); /* make header */
|
---|
700 |
|
---|
701 | lcsum += sntlreq;
|
---|
702 |
|
---|
703 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
704 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
705 |
|
---|
706 | #if DEBUGIT
|
---|
707 | if (debugsw)
|
---|
708 | printf("wrt_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
709 | #endif
|
---|
710 |
|
---|
711 | /* |
---|
712 |
|
---|
713 | */
|
---|
714 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
715 |
|
---|
716 | streset();
|
---|
717 | return(FAILURE);
|
---|
718 | }
|
---|
719 |
|
---|
720 | if (wr_ec(fp, &sntlreq, 4L)) { /* total longs required */
|
---|
721 |
|
---|
722 | streset();
|
---|
723 | return(FAILURE);
|
---|
724 | }
|
---|
725 |
|
---|
726 | for (i = 0; i < N_SCORES; i++) { /* scores */
|
---|
727 |
|
---|
728 | if (scwrite(i, fp)) {
|
---|
729 |
|
---|
730 | streset();
|
---|
731 | return(FAILURE);
|
---|
732 | }
|
---|
733 | }
|
---|
734 |
|
---|
735 | fclose(fp);
|
---|
736 | postio(); /* restore LCD backlight */
|
---|
737 | return(SUCCESS);
|
---|
738 | }
|
---|
739 |
|
---|
740 | /* |
---|
741 |
|
---|
742 | */
|
---|
743 |
|
---|
744 | /*
|
---|
745 | =============================================================================
|
---|
746 | get_scr() -- read a score file from the disk
|
---|
747 | =============================================================================
|
---|
748 | */
|
---|
749 |
|
---|
750 | int16_t get_scr(void)
|
---|
751 | {
|
---|
752 | register FILE *fp;
|
---|
753 | register int16_t i;
|
---|
754 | int32_t tnl;
|
---|
755 |
|
---|
756 | preio(); /* kill LCD backlight */
|
---|
757 |
|
---|
758 | fp = fopenb(slotnam(ldslot, FT_SCR), "r");
|
---|
759 |
|
---|
760 | if ((FILE *)NULL EQ fp) {
|
---|
761 |
|
---|
762 | ldermsg("Couldn't open the file",
|
---|
763 | " for the scores", (int8_t *)NULL,
|
---|
764 | LD_EMCF, LD_EMCB);
|
---|
765 |
|
---|
766 | postio(); /* restore LCD backlight */
|
---|
767 | clrlsel();
|
---|
768 | return(FAILURE);
|
---|
769 | }
|
---|
770 |
|
---|
771 | memcpy(ldfile, " ", 8);
|
---|
772 | memcpy(ldcmnt, " ", 37);
|
---|
773 | ldswin(3);
|
---|
774 | ldswin(5);
|
---|
775 |
|
---|
776 | /* |
---|
777 |
|
---|
778 | */
|
---|
779 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
780 |
|
---|
781 | clrlsel();
|
---|
782 | return(FAILURE);
|
---|
783 | }
|
---|
784 |
|
---|
785 | #if DEBUGIT
|
---|
786 | if (debugsw)
|
---|
787 | printf("get_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
788 | #endif
|
---|
789 |
|
---|
790 |
|
---|
791 | if (rd_ec(fp, &tnl, 4L)) { /* longs required */
|
---|
792 |
|
---|
793 | clrlsel();
|
---|
794 | return(FAILURE);
|
---|
795 | }
|
---|
796 |
|
---|
797 | if (lrasw EQ 0) /* clear all scores if in replace mode */
|
---|
798 | scinit();
|
---|
799 |
|
---|
800 | for (i = 0; i < N_SCORES; i++) { /* read scores */
|
---|
801 |
|
---|
802 | if (scread(i, fp)) {
|
---|
803 |
|
---|
804 | clrlsel();
|
---|
805 | return(FAILURE);
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 | fclose(fp);
|
---|
810 | postio(); /* restore LCD backlight */
|
---|
811 |
|
---|
812 | p_bak = p_cur = p_ctr = p_fwd = scp = E_NULL;
|
---|
813 | t_cur = t_ctr = 0L;
|
---|
814 | t_bak = t_cur - TO_BAK;
|
---|
815 | t_fwd = t_cur + TO_FWD;
|
---|
816 |
|
---|
817 | selscor(0);
|
---|
818 |
|
---|
819 | clrlsel();
|
---|
820 | return(SUCCESS);
|
---|
821 | }
|
---|
822 |
|
---|
823 | /* |
---|
824 |
|
---|
825 | */
|
---|
826 |
|
---|
827 | /*
|
---|
828 | =============================================================================
|
---|
829 | wrt_seq() -- write a sequence file on the disk
|
---|
830 | =============================================================================
|
---|
831 | */
|
---|
832 |
|
---|
833 | int16_t wrt_seq(int16_t slot)
|
---|
834 | {
|
---|
835 | register FILE *fp;
|
---|
836 | int8_t cstemp[8];
|
---|
837 |
|
---|
838 | preio(); /* kill LCD backlight */
|
---|
839 |
|
---|
840 | fp = fopenb(slotnam(slot, FT_SEQ), "w");
|
---|
841 |
|
---|
842 | if ((FILE *)NULL EQ fp) {
|
---|
843 |
|
---|
844 | ldermsg("Couldn't create a file",
|
---|
845 | " for the sequences", (int8_t *)NULL,
|
---|
846 | LD_EMCF, LD_EMCB);
|
---|
847 |
|
---|
848 | postio(); /* restore LCD backlight */
|
---|
849 | streset();
|
---|
850 | return(FAILURE);
|
---|
851 | }
|
---|
852 |
|
---|
853 | makelh(FT_SEQ); /* make header */
|
---|
854 |
|
---|
855 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
856 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
857 |
|
---|
858 | #if DEBUGIT
|
---|
859 | if (debugsw)
|
---|
860 | printf("wrt_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
861 | #endif
|
---|
862 |
|
---|
863 | /* |
---|
864 |
|
---|
865 | */
|
---|
866 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
867 |
|
---|
868 | streset();
|
---|
869 | return(FAILURE);
|
---|
870 | }
|
---|
871 |
|
---|
872 | if (sqwrite(fp)) { /* sequences */
|
---|
873 |
|
---|
874 | streset();
|
---|
875 | return(FAILURE);
|
---|
876 | }
|
---|
877 |
|
---|
878 | fclose(fp);
|
---|
879 | postio(); /* restore LCD backlight */
|
---|
880 | return(SUCCESS);
|
---|
881 | }
|
---|
882 |
|
---|
883 | /* |
---|
884 |
|
---|
885 | */
|
---|
886 |
|
---|
887 | /*
|
---|
888 | =============================================================================
|
---|
889 | get_seq() -- read a sequence file from the disk
|
---|
890 | =============================================================================
|
---|
891 | */
|
---|
892 |
|
---|
893 | int16_t get_seq(void)
|
---|
894 | {
|
---|
895 | register FILE *fp;
|
---|
896 |
|
---|
897 | preio(); /* kill LCD backlight */
|
---|
898 |
|
---|
899 | fp = fopenb(slotnam(ldslot, FT_SEQ), "r");
|
---|
900 |
|
---|
901 | if ((FILE *)NULL EQ fp) {
|
---|
902 |
|
---|
903 | ldermsg("Couldn't open the file",
|
---|
904 | " for the sequences", (int8_t *)NULL,
|
---|
905 | LD_EMCF, LD_EMCB);
|
---|
906 |
|
---|
907 | postio(); /* restore LCD backlight */
|
---|
908 | clrlsel();
|
---|
909 | return(FAILURE);
|
---|
910 | }
|
---|
911 |
|
---|
912 | memcpy(ldfile, " ", 8);
|
---|
913 | memcpy(ldcmnt, " ", 37);
|
---|
914 | ldswin(3);
|
---|
915 | ldswin(5);
|
---|
916 |
|
---|
917 | /* |
---|
918 |
|
---|
919 | */
|
---|
920 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
921 |
|
---|
922 | clrlsel();
|
---|
923 | return(FAILURE);
|
---|
924 | }
|
---|
925 |
|
---|
926 | #if DEBUGIT
|
---|
927 | if (debugsw)
|
---|
928 | printf("get_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
929 | #endif
|
---|
930 |
|
---|
931 | initsq();
|
---|
932 |
|
---|
933 | if (sqread(fp)) {
|
---|
934 |
|
---|
935 | clrlsel();
|
---|
936 | return(FAILURE);
|
---|
937 | }
|
---|
938 |
|
---|
939 | fclose(fp);
|
---|
940 | postio(); /* restore LCD backlight */
|
---|
941 | clrlsel();
|
---|
942 | return(SUCCESS);
|
---|
943 | }
|
---|
944 |
|
---|
945 | /* |
---|
946 |
|
---|
947 | */
|
---|
948 |
|
---|
949 | /*
|
---|
950 | =============================================================================
|
---|
951 | wrt_wav() -- write a waveshape library on the disk
|
---|
952 | =============================================================================
|
---|
953 | */
|
---|
954 |
|
---|
955 | int16_t wrt_wav(int16_t slot)
|
---|
956 | {
|
---|
957 | register FILE *fp;
|
---|
958 | register int16_t i;
|
---|
959 | int8_t cstemp[8];
|
---|
960 | register struct wstbl *wp;
|
---|
961 |
|
---|
962 | preio(); /* kill LCD backlight */
|
---|
963 |
|
---|
964 | fp = fopenb(slotnam(slot, FT_WAV), "w");
|
---|
965 |
|
---|
966 | if ((FILE *)NULL EQ fp) {
|
---|
967 |
|
---|
968 | ldermsg("Couldn't create a file",
|
---|
969 | " for the waveshapes", (int8_t *)NULL,
|
---|
970 | LD_EMCF, LD_EMCB);
|
---|
971 |
|
---|
972 | postio(); /* restore LCD backlight */
|
---|
973 | streset();
|
---|
974 | return(FAILURE);
|
---|
975 | }
|
---|
976 |
|
---|
977 | makelh(FT_WAV); /* make header */
|
---|
978 |
|
---|
979 | for (i = 0; i < NUMWAVS; i++) {
|
---|
980 |
|
---|
981 | wp = &wslib[i];
|
---|
982 |
|
---|
983 | lcsum += chksum(wp->offset, (int32_t)(NUMWPNT * 2));
|
---|
984 | lcsum += chksum(wp->harmon, (int32_t)(NUMHARM * 2));
|
---|
985 | }
|
---|
986 |
|
---|
987 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
988 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
989 |
|
---|
990 | #if DEBUGIT
|
---|
991 | if (debugsw)
|
---|
992 | printf("wrt_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
993 | #endif
|
---|
994 |
|
---|
995 | /* |
---|
996 |
|
---|
997 | */
|
---|
998 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
999 |
|
---|
1000 | streset();
|
---|
1001 | return(FAILURE);
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | for (i = 0; i < NUMWAVS; i++) {
|
---|
1005 |
|
---|
1006 | wp = &wslib[i];
|
---|
1007 |
|
---|
1008 | if (wr_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
1009 |
|
---|
1010 | streset();
|
---|
1011 | return(FAILURE);
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | if (wr_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
1015 |
|
---|
1016 | streset();
|
---|
1017 | return(FAILURE);
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | fclose(fp);
|
---|
1022 | postio(); /* restore LCD backlight */
|
---|
1023 | return(SUCCESS);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | /* |
---|
1027 |
|
---|
1028 | */
|
---|
1029 |
|
---|
1030 | /*
|
---|
1031 | =============================================================================
|
---|
1032 | get_wav() -- read a waveshape library from the disk
|
---|
1033 | =============================================================================
|
---|
1034 | */
|
---|
1035 |
|
---|
1036 | int16_t get_wav(void)
|
---|
1037 | {
|
---|
1038 | register FILE *fp;
|
---|
1039 | register int16_t i;
|
---|
1040 | register struct wstbl *wp;
|
---|
1041 |
|
---|
1042 | preio(); /* kill LCD backlight */
|
---|
1043 |
|
---|
1044 | fp = fopenb(slotnam(ldslot, FT_WAV), "r");
|
---|
1045 |
|
---|
1046 | if ((FILE *)NULL EQ fp) {
|
---|
1047 |
|
---|
1048 | ldermsg("Couldn't open the file",
|
---|
1049 | " for the waveshapes", (int8_t *)NULL,
|
---|
1050 | LD_EMCF, LD_EMCB);
|
---|
1051 |
|
---|
1052 | postio(); /* restore LCD backlight */
|
---|
1053 | clrlsel();
|
---|
1054 | return(FAILURE);
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | memcpy(ldfile, " ", 8);
|
---|
1058 | memcpy(ldcmnt, " ", 37);
|
---|
1059 | ldswin(3);
|
---|
1060 | ldswin(5);
|
---|
1061 |
|
---|
1062 | /* |
---|
1063 |
|
---|
1064 | */
|
---|
1065 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
1066 |
|
---|
1067 | clrlsel();
|
---|
1068 | return(FAILURE);
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | #if DEBUGIT
|
---|
1072 | if (debugsw)
|
---|
1073 | printf("get_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
1074 | #endif
|
---|
1075 |
|
---|
1076 |
|
---|
1077 | for (i = 0; i < NUMWAVS; i++) {
|
---|
1078 |
|
---|
1079 | wp = &wslib[i];
|
---|
1080 |
|
---|
1081 | if (rd_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
1082 |
|
---|
1083 | clrlsel();
|
---|
1084 | return(FAILURE);
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | if (rd_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
1088 |
|
---|
1089 | clrlsel();
|
---|
1090 | return(FAILURE);
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | /* unpack offsets (and eventually harmonics) into finals */
|
---|
1094 |
|
---|
1095 | memcpyw(wp->final, wp->offset, NUMWPNT);
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | clrlsel();
|
---|
1099 | fclose(fp);
|
---|
1100 | postio(); /* restore LCD backlight */
|
---|
1101 | return(SUCCESS);
|
---|
1102 | }
|
---|
1103 |
|
---|