source: buchla-68k/ram/librw.c@ 6262b5c

Last change on this file since 6262b5c was 6262b5c, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Added include files for global functions and variables.

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