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