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