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