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 | int8_t cstemp[8];
|
---|
560 |
|
---|
561 | preio(); /* kill LCD backlight */
|
---|
562 |
|
---|
563 | fp = fopenb(slotnam(slot, FT_SCR), "w");
|
---|
564 |
|
---|
565 | if ((FILE *)NULL EQ fp) {
|
---|
566 |
|
---|
567 | ldermsg("Couldn't create a file",
|
---|
568 | " for the scores", (int8_t *)NULL,
|
---|
569 | LD_EMCF, LD_EMCB);
|
---|
570 |
|
---|
571 | postio(); /* restore LCD backlight */
|
---|
572 | streset();
|
---|
573 | return(FAILURE);
|
---|
574 | }
|
---|
575 |
|
---|
576 | makelh(FT_SCR); /* make header */
|
---|
577 |
|
---|
578 | lcsum += sntlreq;
|
---|
579 |
|
---|
580 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
581 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
582 |
|
---|
583 | #if DEBUGIT
|
---|
584 | if (debugsw)
|
---|
585 | printf("wrt_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
586 | #endif
|
---|
587 |
|
---|
588 |
|
---|
589 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
590 |
|
---|
591 | streset();
|
---|
592 | return(FAILURE);
|
---|
593 | }
|
---|
594 |
|
---|
595 | if (wr_ec(fp, &sntlreq, 4L)) { /* total longs required */
|
---|
596 |
|
---|
597 | streset();
|
---|
598 | return(FAILURE);
|
---|
599 | }
|
---|
600 |
|
---|
601 | for (i = 0; i < N_SCORES; i++) { /* scores */
|
---|
602 |
|
---|
603 | if (scwrite(i, fp)) {
|
---|
604 |
|
---|
605 | streset();
|
---|
606 | return(FAILURE);
|
---|
607 | }
|
---|
608 | }
|
---|
609 |
|
---|
610 | fclose(fp);
|
---|
611 | postio(); /* restore LCD backlight */
|
---|
612 | return(SUCCESS);
|
---|
613 | }
|
---|
614 |
|
---|
615 | /*
|
---|
616 | =============================================================================
|
---|
617 | get_scr() -- read a score file from the disk
|
---|
618 | =============================================================================
|
---|
619 | */
|
---|
620 |
|
---|
621 | int16_t get_scr(void)
|
---|
622 | {
|
---|
623 | register FILE *fp;
|
---|
624 | register int16_t i;
|
---|
625 | int32_t tnl;
|
---|
626 |
|
---|
627 | preio(); /* kill LCD backlight */
|
---|
628 |
|
---|
629 | fp = fopenb(slotnam(ldslot, FT_SCR), "r");
|
---|
630 |
|
---|
631 | if ((FILE *)NULL EQ fp) {
|
---|
632 |
|
---|
633 | ldermsg("Couldn't open the file",
|
---|
634 | " for the scores", (int8_t *)NULL,
|
---|
635 | LD_EMCF, LD_EMCB);
|
---|
636 |
|
---|
637 | postio(); /* restore LCD backlight */
|
---|
638 | clrlsel();
|
---|
639 | return(FAILURE);
|
---|
640 | }
|
---|
641 |
|
---|
642 | memcpy(ldfile, " ", 8);
|
---|
643 | memcpy(ldcmnt, " ", 37);
|
---|
644 | ldswin(3);
|
---|
645 | ldswin(5);
|
---|
646 |
|
---|
647 |
|
---|
648 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
649 |
|
---|
650 | clrlsel();
|
---|
651 | return(FAILURE);
|
---|
652 | }
|
---|
653 |
|
---|
654 | #if DEBUGIT
|
---|
655 | if (debugsw)
|
---|
656 | printf("get_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
657 | #endif
|
---|
658 |
|
---|
659 |
|
---|
660 | if (rd_ec(fp, &tnl, 4L)) { /* longs required */
|
---|
661 |
|
---|
662 | clrlsel();
|
---|
663 | return(FAILURE);
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (lrasw EQ 0) /* clear all scores if in replace mode */
|
---|
667 | scinit();
|
---|
668 |
|
---|
669 | for (i = 0; i < N_SCORES; i++) { /* read scores */
|
---|
670 |
|
---|
671 | if (scread(i, fp)) {
|
---|
672 |
|
---|
673 | clrlsel();
|
---|
674 | return(FAILURE);
|
---|
675 | }
|
---|
676 | }
|
---|
677 |
|
---|
678 | fclose(fp);
|
---|
679 | postio(); /* restore LCD backlight */
|
---|
680 |
|
---|
681 | p_bak = p_cur = p_ctr = p_fwd = scp = E_NULL;
|
---|
682 | t_cur = t_ctr = 0L;
|
---|
683 | t_bak = t_cur - TO_BAK;
|
---|
684 | t_fwd = t_cur + TO_FWD;
|
---|
685 |
|
---|
686 | selscor(0);
|
---|
687 |
|
---|
688 | clrlsel();
|
---|
689 | return(SUCCESS);
|
---|
690 | }
|
---|
691 |
|
---|
692 | /*
|
---|
693 | =============================================================================
|
---|
694 | wrt_seq() -- write a sequence file on the disk
|
---|
695 | =============================================================================
|
---|
696 | */
|
---|
697 |
|
---|
698 | int16_t wrt_seq(int16_t slot)
|
---|
699 | {
|
---|
700 | register FILE *fp;
|
---|
701 | int8_t cstemp[8];
|
---|
702 |
|
---|
703 | preio(); /* kill LCD backlight */
|
---|
704 |
|
---|
705 | fp = fopenb(slotnam(slot, FT_SEQ), "w");
|
---|
706 |
|
---|
707 | if ((FILE *)NULL EQ fp) {
|
---|
708 |
|
---|
709 | ldermsg("Couldn't create a file",
|
---|
710 | " for the sequences", (int8_t *)NULL,
|
---|
711 | LD_EMCF, LD_EMCB);
|
---|
712 |
|
---|
713 | postio(); /* restore LCD backlight */
|
---|
714 | streset();
|
---|
715 | return(FAILURE);
|
---|
716 | }
|
---|
717 |
|
---|
718 | makelh(FT_SEQ); /* make header */
|
---|
719 |
|
---|
720 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
721 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
722 |
|
---|
723 | #if DEBUGIT
|
---|
724 | if (debugsw)
|
---|
725 | printf("wrt_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
726 | #endif
|
---|
727 |
|
---|
728 |
|
---|
729 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
730 |
|
---|
731 | streset();
|
---|
732 | return(FAILURE);
|
---|
733 | }
|
---|
734 |
|
---|
735 | if (sqwrite(fp)) { /* sequences */
|
---|
736 |
|
---|
737 | streset();
|
---|
738 | return(FAILURE);
|
---|
739 | }
|
---|
740 |
|
---|
741 | fclose(fp);
|
---|
742 | postio(); /* restore LCD backlight */
|
---|
743 | return(SUCCESS);
|
---|
744 | }
|
---|
745 |
|
---|
746 | /*
|
---|
747 | =============================================================================
|
---|
748 | get_seq() -- read a sequence file from the disk
|
---|
749 | =============================================================================
|
---|
750 | */
|
---|
751 |
|
---|
752 | int16_t get_seq(void)
|
---|
753 | {
|
---|
754 | register FILE *fp;
|
---|
755 |
|
---|
756 | preio(); /* kill LCD backlight */
|
---|
757 |
|
---|
758 | fp = fopenb(slotnam(ldslot, FT_SEQ), "r");
|
---|
759 |
|
---|
760 | if ((FILE *)NULL EQ fp) {
|
---|
761 |
|
---|
762 | ldermsg("Couldn't open the file",
|
---|
763 | " for the sequences", (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 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
778 |
|
---|
779 | clrlsel();
|
---|
780 | return(FAILURE);
|
---|
781 | }
|
---|
782 |
|
---|
783 | #if DEBUGIT
|
---|
784 | if (debugsw)
|
---|
785 | printf("get_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
786 | #endif
|
---|
787 |
|
---|
788 | initsq();
|
---|
789 |
|
---|
790 | if (sqread(fp)) {
|
---|
791 |
|
---|
792 | clrlsel();
|
---|
793 | return(FAILURE);
|
---|
794 | }
|
---|
795 |
|
---|
796 | fclose(fp);
|
---|
797 | postio(); /* restore LCD backlight */
|
---|
798 | clrlsel();
|
---|
799 | return(SUCCESS);
|
---|
800 | }
|
---|
801 |
|
---|
802 | /*
|
---|
803 | =============================================================================
|
---|
804 | wrt_wav() -- write a waveshape library on the disk
|
---|
805 | =============================================================================
|
---|
806 | */
|
---|
807 |
|
---|
808 | int16_t wrt_wav(int16_t slot)
|
---|
809 | {
|
---|
810 | register FILE *fp;
|
---|
811 | register int16_t i;
|
---|
812 | int8_t cstemp[8];
|
---|
813 | register struct wstbl *wp;
|
---|
814 |
|
---|
815 | preio(); /* kill LCD backlight */
|
---|
816 |
|
---|
817 | fp = fopenb(slotnam(slot, FT_WAV), "w");
|
---|
818 |
|
---|
819 | if ((FILE *)NULL EQ fp) {
|
---|
820 |
|
---|
821 | ldermsg("Couldn't create a file",
|
---|
822 | " for the waveshapes", (int8_t *)NULL,
|
---|
823 | LD_EMCF, LD_EMCB);
|
---|
824 |
|
---|
825 | postio(); /* restore LCD backlight */
|
---|
826 | streset();
|
---|
827 | return(FAILURE);
|
---|
828 | }
|
---|
829 |
|
---|
830 | makelh(FT_WAV); /* make header */
|
---|
831 |
|
---|
832 | for (i = 0; i < NUMWAVS; i++) {
|
---|
833 |
|
---|
834 | wp = &wslib[i];
|
---|
835 |
|
---|
836 | lcsum += chksum(wp->offset, (int32_t)(NUMWPNT * 2));
|
---|
837 | lcsum += chksum(wp->harmon, (int32_t)(NUMHARM * 2));
|
---|
838 | }
|
---|
839 |
|
---|
840 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
841 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
842 |
|
---|
843 | #if DEBUGIT
|
---|
844 | if (debugsw)
|
---|
845 | printf("wrt_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
846 | #endif
|
---|
847 |
|
---|
848 |
|
---|
849 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
850 |
|
---|
851 | streset();
|
---|
852 | return(FAILURE);
|
---|
853 | }
|
---|
854 |
|
---|
855 | for (i = 0; i < NUMWAVS; i++) {
|
---|
856 |
|
---|
857 | wp = &wslib[i];
|
---|
858 |
|
---|
859 | if (wr_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
860 |
|
---|
861 | streset();
|
---|
862 | return(FAILURE);
|
---|
863 | }
|
---|
864 |
|
---|
865 | if (wr_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
866 |
|
---|
867 | streset();
|
---|
868 | return(FAILURE);
|
---|
869 | }
|
---|
870 | }
|
---|
871 |
|
---|
872 | fclose(fp);
|
---|
873 | postio(); /* restore LCD backlight */
|
---|
874 | return(SUCCESS);
|
---|
875 | }
|
---|
876 |
|
---|
877 | /*
|
---|
878 | =============================================================================
|
---|
879 | get_wav() -- read a waveshape library from the disk
|
---|
880 | =============================================================================
|
---|
881 | */
|
---|
882 |
|
---|
883 | int16_t get_wav(void)
|
---|
884 | {
|
---|
885 | register FILE *fp;
|
---|
886 | register int16_t i;
|
---|
887 | register struct wstbl *wp;
|
---|
888 |
|
---|
889 | preio(); /* kill LCD backlight */
|
---|
890 |
|
---|
891 | fp = fopenb(slotnam(ldslot, FT_WAV), "r");
|
---|
892 |
|
---|
893 | if ((FILE *)NULL EQ fp) {
|
---|
894 |
|
---|
895 | ldermsg("Couldn't open the file",
|
---|
896 | " for the waveshapes", (int8_t *)NULL,
|
---|
897 | LD_EMCF, LD_EMCB);
|
---|
898 |
|
---|
899 | postio(); /* restore LCD backlight */
|
---|
900 | clrlsel();
|
---|
901 | return(FAILURE);
|
---|
902 | }
|
---|
903 |
|
---|
904 | memcpy(ldfile, " ", 8);
|
---|
905 | memcpy(ldcmnt, " ", 37);
|
---|
906 | ldswin(3);
|
---|
907 | ldswin(5);
|
---|
908 |
|
---|
909 |
|
---|
910 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
911 |
|
---|
912 | clrlsel();
|
---|
913 | return(FAILURE);
|
---|
914 | }
|
---|
915 |
|
---|
916 | #if DEBUGIT
|
---|
917 | if (debugsw)
|
---|
918 | printf("get_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
919 | #endif
|
---|
920 |
|
---|
921 |
|
---|
922 | for (i = 0; i < NUMWAVS; i++) {
|
---|
923 |
|
---|
924 | wp = &wslib[i];
|
---|
925 |
|
---|
926 | if (rd_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
927 |
|
---|
928 | clrlsel();
|
---|
929 | return(FAILURE);
|
---|
930 | }
|
---|
931 |
|
---|
932 | if (rd_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
933 |
|
---|
934 | clrlsel();
|
---|
935 | return(FAILURE);
|
---|
936 | }
|
---|
937 |
|
---|
938 | /* unpack offsets (and eventually harmonics) into finals */
|
---|
939 |
|
---|
940 | memcpyw(wp->final, wp->offset, NUMWPNT);
|
---|
941 | }
|
---|
942 |
|
---|
943 | clrlsel();
|
---|
944 | fclose(fp);
|
---|
945 | postio(); /* restore LCD backlight */
|
---|
946 | return(SUCCESS);
|
---|
947 | }
|
---|
948 |
|
---|
949 |
|
---|