source: buchla-68k/ram/libdsp.c@ b28a12e

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 31.8 KB
Line 
1/*
2 =============================================================================
3 libdsp.c -- MIDAS librarian display
4 Version 64 -- 1988-11-17 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGRE 0
9#define DEBUGWE 0
10
11#include "ram.h"
12
13#if DEBUGRE
14short debugre = 1;
15#endif
16
17#if DEBUGWE
18short debugwe = 1;
19#endif
20
21/*
22
23*/
24
25int8_t *ftypes[][3] = { /* file types (must match libdsp.h) */
26
27 {"ASG", "Assignmnt", "Assignmnt"}, /* FT_ASG */
28 {"ORL", "Orchestra", "Orchestra"}, /* FT_ORL */
29 {"ORH", "Orchestra", "Orchestra"}, /* FT_ORH */
30 {"SCR", " Score", "Score"}, /* FT_SCR */
31 {"TUN", " Tuning", "Tuning"}, /* FT_TUN */
32 {"WAV", "Waveshape", "Waveshape"}, /* FT_WAV */
33 {"ORC", "Orchestra", "Orchestra"}, /* FT_ORC */
34 {"PAT", " Patch", "Patch"}, /* FT_PAT */
35 {"SEQ", " Sequence", "Sequence"} /* FT_SEQ */
36};
37
38int8_t ld_em1[] = "No files stored on disk";
39int8_t ld_em2[] = " by this operation";
40
41int16_t lbrpal[16][3] = { /* librarian color palette */
42
43 {0, 0, 0}, /* 0 */
44 {3, 3, 3}, /* 1 */
45 {1, 0, 0}, /* 2 */
46 {1, 1, 0}, /* 3 */
47 {2, 1, 0}, /* 4 (was 2, 2, 0) */
48 {1, 1, 0}, /* 5 */
49 {2, 1, 0}, /* 6 (was 2, 2, 0) */
50 {1, 0, 0}, /* 7 */
51 {0, 1, 1}, /* 8 (was 0, 1, 0) */
52 {1, 0, 0}, /* 9 */
53 {1, 1, 0}, /* 10 */
54 {2, 2, 2}, /* 11 */
55 {2, 3, 3}, /* 12 */
56 {3, 3, 0}, /* 13 */
57 {3, 0, 0}, /* 14 */
58 {0, 0, 0} /* 15 */
59};
60
61/*
62
63*/
64
65/*
66 =============================================================================
67 ftkind() -- return the file type for a given file catalog slot
68
69 ns = catalog slot index
70 -1 returned on error (returns 1..NFTYPES for a good type)
71 =============================================================================
72*/
73
74int16_t ftkind(int16_t ns)
75{
76 register int16_t i;
77
78 for (i = 0; i < NFTYPES; i++)
79 if (0 EQ memcmpu(filecat[ns].fcextn, ftypes[i][0], 3))
80 return(++i);
81
82 return(-1);
83}
84
85/*
86 =============================================================================
87 fctstr() -- return a string showing the file catalog entry type
88
89 ns = catalog slot index
90 just = 0: right justify string, 1: left justify string
91 =============================================================================
92*/
93
94int8_t *fctstr(int16_t ns, int16_t just)
95{
96 static int8_t fcbad[11];
97 register int16_t i;
98
99 for (i = 0; i < NFTYPES; i++)
100 if (0 EQ memcmpu(filecat[ns].fcextn, ftypes[i][0], 3))
101 return(ftypes[i][just ? 2 : 1]);
102
103 sprintf(fcbad, "?? %3.3s ??", filecat[ns].fcextn);
104 return(fcbad);
105}
106
107/*
108
109*/
110
111/*
112 =============================================================================
113 ocslot() -- determine if a slot is occupied
114 =============================================================================
115*/
116
117int16_t ocslot(int16_t slot)
118{
119 if (memcmp(filecat[slot].fcsize, "000", 3)
120 AND (0 NE filecat[slot].fcsize[0]))
121 return(TRUE);
122 else
123 return(FALSE);
124}
125
126/*
127 =============================================================================
128 ldline() -- determine which catalog line the cursor is on, if any
129 =============================================================================
130*/
131
132int16_t ldline(int16_t cy)
133{
134 if (cy > 292)
135 return(0);
136
137 if (cy < 14)
138 return(0);
139
140 return(cy / 14);
141}
142
143/*
144
145*/
146
147/*
148 =============================================================================
149 lin2slt() -- determine which slot a line corresponds to, if any
150
151 -1 returned on error (0..FCMAX-1 returned for a good slot)
152 =============================================================================
153*/
154
155int16_t lin2slt(int16_t line)
156{
157 register int16_t slot, row;
158
159 row = 0;
160
161 for (slot = 0; slot < FCMAX; slot++)
162 if (ocslot(slot))
163 if (++row EQ line)
164 return(slot);
165
166 return(-1);
167}
168
169/*
170 =============================================================================
171 exp_c() -- expand a 4 bit color to 16 bits
172 =============================================================================
173*/
174
175uint16_t exp_c(uint16_t c)
176{
177 c &= 0x000F; /* use low 4 bits as the basis */
178 c |= c << 4; /* turn them into 8 bits */
179 c |= c << 8; /* make it a full 16 bits */
180
181 return(c);
182}
183
184/*
185
186*/
187
188/*
189 =============================================================================
190 ldwmsg() -- display a message in the message window
191 =============================================================================
192*/
193
194void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor)
195{
196 lderrsw = FALSE; /* clear error switch */
197 lmwtype = 2; /* message type */
198 submenu = FALSE;
199
200 if (ndisp NE 0)
201 return;
202
203 bgcolor = exp_c(bgcolor); /* expand background color */
204 fgcolor = exp_c(fgcolor); /* expand foreground color */
205
206 if (v_regs[5] & 0x0180)
207 vbank(0);
208
209 /* clear the window */
210
211 vbfill4(librob, 128, ldbox[10][0], ldbox[10][1],
212 ldbox[10][2], ldbox[10][3], bgcolor);
213
214 if ((int8_t *)NULL NE line1)
215 tsplot4(librob, 64, fgcolor, ldbox[10][6], ldbox[10][7],
216 line1, 14);
217
218 if ((int8_t *)NULL NE line2)
219 tsplot4(librob, 64, fgcolor, (ldbox[10][6] + 1), ldbox[10][7],
220 line2, 14);
221
222 if ((int8_t *)NULL NE line3)
223 tsplot4(librob, 64, fgcolor, (ldbox[10][6] + 2), ldbox[10][7],
224 line3, 14);
225}
226
227/*
228
229*/
230
231/*
232 =============================================================================
233 chksum() -- checksum an area of memory
234 =============================================================================
235*/
236
237int32_t chksum(int8_t *area, int32_t len)
238{
239 register int32_t cs, i;
240
241 cs = 0L;
242
243 for (i = 0; i < len; i++)
244 cs += 0x000000FFL & *area++;
245
246 return(cs);
247}
248
249/*
250 =============================================================================
251 makelh() -- make a library header
252 =============================================================================
253*/
254
255void makelh(int16_t kind)
256{
257 memset(ldhead.l_csum, '?', 8); /* checksum */
258 memcpy(ldhead.l_name, ldfile, 8); /* file name */
259 memcpy(ldhead.l_type, ftypes[kind - 1][0], 3); /* file type */
260 memcpy(ldhead.l_cmnt, ldcmnt, 37); /* comment */
261
262 lcsum = chksum(ldhead.l_name, (int32_t)(LH_LEN - 8));
263}
264
265/*
266
267*/
268
269/*
270 =============================================================================
271 ldbusy() -- put up a "Busy" message
272 =============================================================================
273*/
274
275void ldbusy(int8_t *msg)
276{
277 if (ndisp NE 0)
278 return;
279
280 ldwmsg((int8_t *)NULL, " Busy - Please stand by", msg,
281 ldbox[10][4], ldbox[10][5]);
282}
283
284/*
285 =============================================================================
286 noslot() -- complain about not finding a slot we expected
287 =============================================================================
288*/
289
290void noslot(int16_t fctype)
291{
292 sprintf(ldmsg1, " the %s file,", ftypes[fctype - 1][2]);
293
294 ldermsg("Can't find a slot for",
295 ldmsg1, " and one was expected", LD_EMCF, LD_EMCB);
296}
297
298/*
299
300*/
301
302/*
303 =============================================================================
304 wr_ec() -- write with error checking
305 =============================================================================
306*/
307
308int16_t wr_ec(FILE *fp, int8_t *from, int32_t len)
309{
310 register int32_t count;
311 register int8_t c;
312 for (count = 0; count < len; count++) {
313
314 errno = 0;
315 c = *from++;
316
317 if (EOF EQ putc(c, fp)) {
318
319 sprintf(errbuf, "errno = %d", errno);
320
321 ldermsg("Disk may be full",
322 errbuf, (int8_t *)NULL, LD_EMCF, LD_EMCB);
323
324 fclose(fp);
325 postio(); /* restore LCD backlight */
326 return(FAILURE);
327 }
328
329#if DEBUGWE
330 if (debugsw AND debugwe)
331 printf(" %02.2X", 0x00FF & c);
332#endif
333 }
334
335 return(SUCCESS);
336}
337
338/*
339
340*/
341
342/*
343 =============================================================================
344 rd_ec() -- read with error checking
345 =============================================================================
346*/
347
348int16_t rd_ec(FILE *fp, int8_t *to, int32_t len)
349{
350 register int32_t count;
351 register int16_t c;
352
353 for (count = 0; count < len; count++) {
354
355 errno = 0;
356
357 if (EOF EQ (c = getc(fp))) {
358
359 sprintf(errbuf, "errno = %d", errno);
360
361 ldermsg("Unexpected EOF",
362 errbuf, (int8_t *)NULL, LD_EMCF, LD_EMCB);
363
364 fclose(fp);
365 postio(); /* restore LCD backlight */
366 return(FAILURE);
367
368 } else {
369
370 *to++ = c;
371
372#if DEBUGRE
373 if (debugsw AND debugre)
374 printf(" %02.2X", 0x00FF & c);
375#endif
376 }
377 }
378
379 return(SUCCESS);
380}
381
382/*
383
384*/
385
386/*
387 =============================================================================
388 srchcat() -- search the file catalog
389
390 returns -1 on 'not found', slot 0..FCMAX-1 if found
391 =============================================================================
392*/
393
394int16_t srchcat(int8_t extn[])
395{
396 register int16_t fcslot;
397
398 for (fcslot = 0; fcslot < FCMAX; fcslot++) {
399
400 if (ocslot(fcslot))
401 if (0 EQ (memcmp(filecat[fcslot].fcname, ldfile, 8))
402 AND (0 EQ memcmpu(filecat[fcslot].fcextn, extn, 3)))
403 return(fcslot);
404 }
405
406 return(-1);
407}
408
409/*
410 =============================================================================
411 clrcat() -- clear the file catalog
412 =============================================================================
413*/
414
415void clrcat(void)
416{
417 register int16_t i;
418 int8_t fcebuf[1 + sizeof (struct fcat)];
419
420 for (i = 0; i < FCMAX; i++) {
421
422 sprintf(fcebuf, "000 Empty-%02.2d ??? %-37.37s%c%c",
423 i, "1234567890123456789012345678901234567",
424 A_CR, A_LF);
425
426 memcpy(&filecat[i], fcebuf, sizeof (struct fcat));
427 }
428}
429
430/*
431
432*/
433
434/*
435 =============================================================================
436 clreq() -- return number of clusters needed for a file
437
438 Assumes the BPB pointer is valid.
439 =============================================================================
440*/
441
442int16_t clreq(int32_t bytes)
443{
444 register int16_t rclusts;
445 register int32_t clmask;
446
447 clmask = _thebpb->clsizb - 1;
448
449 rclusts = (bytes / _thebpb->clsizb)
450 + ((bytes & clmask) ? 1 : 0);
451
452 return(rclusts);
453}
454
455/*
456
457*/
458
459/*
460 =============================================================================
461 spacerq() -- return space required for storing a file
462 =============================================================================
463*/
464
465int16_t spacerq(int16_t kind)
466{
467 register int16_t howmuch;
468 register int32_t k;
469
470 k = 0L;
471
472 switch (kind) {
473
474 case FT_ASG: /* Assignment file */
475
476 k = (sizeof (struct asgent) * (int32_t)NASGLIB) + LH_LEN;
477 break;
478
479 case FT_ORL:
480 case FT_ORH:
481 case FT_ORC:
482
483 k = ((OR_LEN1 + (2 * OR_LEN2)) * (int32_t)NINORC) + LH_LEN;
484 break;
485
486 case FT_PAT: /* Patch file */
487
488 k = ptsizer() + LH_LEN;
489 break;
490
491 case FT_SCR: /* Score file */
492
493 k = scsizer() + LH_LEN;
494 break;
495
496 case FT_SEQ: /* Sequence file */
497
498 k = sqsizer() + LH_LEN;
499 break;
500
501 case FT_TUN: /* Tuning file */
502
503 k = (NTUNSLIB * 256L) + (NTUNSLIB * 32L) + LH_LEN;
504 break;
505
506 case FT_WAV: /* Waveshape file */
507
508 k = ((int32_t)NUMWAVS * OR_LEN2) + LH_LEN;
509 break;
510
511 default:
512
513 k = 0L;
514 break;
515 }
516/*
517
518*/
519 howmuch = k ? clreq(k) : -1;
520 ndbytes = k;
521 return(howmuch);
522}
523
524/*
525
526*/
527
528/*
529 =============================================================================
530 ckstor() -- check for storage type selection
531 =============================================================================
532*/
533
534int16_t ckstor(void)
535{
536 if (lasgsw) /* assignments */
537 return(SUCCESS);
538
539 if (lorchsw) /* hi orch */
540 return(SUCCESS);
541
542 if (lorclsw) /* lo orch */
543 return(SUCCESS);
544
545 if (lpatsw) /* patches */
546 return(SUCCESS);
547
548 if (lscrsw) /* score */
549 return(SUCCESS);
550
551 if (lseqsw) /* sequences */
552 return(SUCCESS);
553
554 if (ltunsw) /* tunings */
555 return(SUCCESS);
556
557 if (lwavsw) /* waveshapes */
558 return(SUCCESS);
559
560 return(FAILURE);
561}
562
563/*
564
565*/
566
567/*
568 =============================================================================
569 ckdups() -- check for duplicate file type entries in the file catalog
570 =============================================================================
571*/
572
573int16_t ckdups(void)
574{
575 if (lasgsw)
576 if (-1 NE srchcat("asg"))
577 return(FT_ASG);
578
579 if (lorchsw)
580 if (-1 NE srchcat("orh"))
581 return(FT_ORH);
582
583 if (lorclsw)
584 if (-1 NE srchcat("orl"))
585 return(FT_ORL);
586
587 if (lorchsw OR lorclsw)
588 if (-1 NE srchcat("orc"))
589 return(FT_ORC);
590
591 if (lpatsw)
592 if (-1 NE srchcat("pat"))
593 return(FT_PAT);
594
595 if (lscrsw)
596 if (-1 NE srchcat("scr"))
597 return(FT_SCR);
598
599 if (lseqsw)
600 if (-1 NE srchcat("seq"))
601 return(FT_SEQ);
602
603 if (ltunsw)
604 if (-1 NE srchcat("tun"))
605 return(FT_TUN);
606
607 if (lwavsw)
608 if (-1 NE srchcat("wav"))
609 return(FT_WAV);
610 return(0);
611}
612
613/*
614
615*/
616
617/*
618 =============================================================================
619 showsiz() -- display disk capacity and usage
620
621 Forces the disk to be read to get the BPB and FAT.
622 =============================================================================
623*/
624
625int16_t showsiz(void)
626{
627 register int16_t dcap, drem, dused;
628
629 _bpbin = FALSE; /* force disk to be read */
630
631 dcap = dspace(0);
632
633 if (dcap EQ -1) {
634
635 ldermsg("Disk not ready ?",
636 (int8_t *)NULL, (int8_t *)NULL,
637 LD_EMCF, LD_EMCB);
638
639 return(FAILURE);
640 }
641
642 drem = dspace(1);
643 dused = dcap - drem;
644
645 sprintf(ldmsg1, "Microdisk capacity %4u blocks", dcap);
646 sprintf(ldmsg2, "This disk consumes %4u blocks", dused);
647 sprintf(ldmsg3, "Available space is %4u blocks", drem);
648
649 ldwmsg(ldmsg1, ldmsg2, ldmsg3, ldbox[10][4], ldbox[10][5]);
650 return(SUCCESS);
651}
652
653/*
654
655*/
656
657/*
658 =============================================================================
659 getcat() -- get the file catalog from disk
660 =============================================================================
661*/
662
663int16_t getcat(int16_t msgsw)
664{
665 register FILE *fp;
666 int16_t rc, fesize;
667
668 ldidsiz = FALSE; /* we didn't show the size (yet) */
669 _bpbin = FALSE; /* guarantee we read the directory */
670 catin = FALSE; /* catalog not valid */
671
672 errno = 0;
673 preio(); /* kill LCD backlight */
674 fp = fopenb(CATNAME, "r"); /* open the catalog file */
675
676 if (NULL EQ fp) {
677
678 clrcat();
679 catin = TRUE;
680
681 if (msgsw) { /* see if we show the message */
682
683 showsiz();
684 ldidsiz = TRUE; /* showed the size */
685 }
686
687 return(SUCCESS); /* no catalog is OK, too */
688 }
689
690 fesize = sizeof(struct fcat);
691 memset(filecat, 0, sizeof (struct fcat) * FCMAX);
692
693/*
694
695*/
696 errno = 0;
697 rc = fread(filecat, fesize, FCMAX, fp);
698
699 if (rc NE FCMAX) {
700
701 if (rc) {
702
703 sprintf(ldmsg1, " fread returned %d", rc);
704 sprintf(ldmsg2, " errno = %d, fesize=%d",
705 errno, fesize);
706
707 ldermsg("Unable to read catalog",
708 ldmsg1, ldmsg2, LD_EMCF, LD_EMCB);
709
710 catin = FALSE;
711
712 } else {
713
714 ldermsg("File catalog is NULL",
715 (int8_t *)NULL, (int8_t *)NULL,
716 LD_EMCF, LD_EMCB);
717
718 clrcat();
719 catin = TRUE;
720 }
721
722 fclose(fp);
723 postio(); /* restore LCD backlight */
724 return(FAILURE);
725 }
726
727 catin = TRUE;
728 fclose(fp);
729 postio(); /* restore LCD backlight */
730 return(SUCCESS);
731}
732
733/*
734
735*/
736
737/*
738 =============================================================================
739 putcat() -- write the updated catalog on disk
740 =============================================================================
741*/
742
743int16_t putcat(void)
744{
745 register FILE *fp;
746 register int16_t i, rc, fesize;
747
748 for (i = 0; i < FCMAX; i++) { /* clean up the catalog */
749
750 filecat[i].fceol[0] = A_CR;
751 filecat[i].fceol[1] = A_LF;
752 }
753
754 errno = 0;
755 preio(); /* kill LCD backlight */
756 fp = fopenb(CATNAME, "w"); /* open the catalog file */
757
758 if (NULL EQ fp) {
759
760 sprintf(ldmsg2, " errno = %d", errno);
761
762 ldermsg("Unable to open catalog",
763 (int8_t *)NULL, ldmsg2, LD_EMCF, LD_EMCB);
764
765 return(FAILURE);
766 }
767
768 fesize = sizeof (struct fcat);
769
770/*
771
772*/
773 errno = 0;
774 rc = fwrite(filecat, fesize, FCMAX, fp);
775
776 if (rc NE FCMAX) {
777
778 if (rc) {
779
780 sprintf(ldmsg1, " fwrite returned %d", rc);
781 sprintf(ldmsg2, " errno = %d, fesize=%d",
782 errno, fesize);
783
784 ldermsg("Can't write catalog",
785 ldmsg1, ldmsg2, LD_EMCF, LD_EMCB);
786
787 } else {
788
789 sprintf(ldmsg2, " errno = %d", errno);
790
791 ldermsg("Disk may be full",
792 (int8_t *)NULL, ldmsg2,
793 LD_EMCF, LD_EMCB);
794 }
795
796 fclose(fp);
797 postio(); /* restore LCD backlight */
798 return(FAILURE);
799 }
800
801 fclose(fp);
802 postio(); /* restore LCD backlight */
803 return(SUCCESS);
804}
805
806/*
807
808*/
809
810/*
811 =============================================================================
812 dslslot() -- display a file catalog entry
813 =============================================================================
814*/
815
816void dslslot(int16_t slot, uint16_t fg, int16_t row)
817{
818 register uint16_t color, chilon, chilorc;
819 int16_t c;
820 int8_t buf[40];
821
822 if (ndisp NE 0)
823 return;
824
825 color = exp_c(fg); /* foreground color */
826 chilon = exp_c(ldbox[1][4]);
827 chilorc = exp_c(HILORC);
828
829 /* file type */
830
831 vcputsv(librob, 64, color, ldbox[1][5], row, 1, fctstr(slot, 0), 14);
832
833 /* load letter */
834
835 c = filecat[slot].fcp0;
836 buf[0] = 0x007F & c;
837 buf[1] = '\0';
838 vcputsv(librob, 64, (c & 0x0080) ? chilorc : chilon,
839 ldbox[1][5], row, 11, buf, 14);
840
841 /* file name */
842
843 memcpy(buf, filecat[slot].fcname, 8);
844 buf[8] = '\0';
845 vcputsv(librob, 64, color, ldbox[1][5], row, 13, buf, 14);
846
847 /* comment */
848
849 memcpy(buf, filecat[slot].fccmnt, 37);
850 buf[37] = '\0';
851 vcputsv(librob, 64, chilon, ldbox[1][5], row, 22, buf, 14);
852
853 /* size */
854
855 memcpy(buf, filecat[slot].fcsize, 3);
856 buf[3] = '\0';
857 vcputsv(librob, 64, chilon, ldbox[1][5], row, 60, buf, 14);
858}
859
860/*
861
862*/
863
864/*
865 =============================================================================
866 showcat() -- display the file catalog entries
867 =============================================================================
868*/
869
870int16_t showcat(void)
871{
872 register int16_t i, fcslot, fcrow, fcount;
873 register uint16_t color;
874
875 if (ndisp NE 0)
876 return(FAILURE);
877
878 ldswin(0); /* fix up the title */
879
880 color = exp_c(ldbox[1][5]); /* background color */
881
882 if (v_regs[5] & 0x0180)
883 vbank(0);
884
885 vbfill4(librob, 128, ldbox[1][0], ldbox[1][1],
886 ldbox[1][2], ldbox[1][3], color);
887
888 color = ldbox[1][4]; /* foreground color */
889
890 fcrow = 1;
891 fcount = 0;
892
893 for (fcslot = 0; fcslot < FCMAX; fcslot++) {
894
895 if (ocslot(fcslot)) {
896
897 dslslot(fcslot, color, fcrow);
898 fcrow++;
899 fcount++;
900 }
901 }
902
903 return(fcount);
904}
905
906/*
907
908*/
909
910/*
911 =============================================================================
912 fcindex() -- display the file catalog
913 =============================================================================
914*/
915
916int16_t fcindex(void)
917{
918 if (NOT lderrsw)
919 ldbusy(" Reading catalog");
920
921 if (getcat(1)) /* get catalog, possibly display size */
922 return(FAILURE);
923
924 if (NOT lderrsw)
925 showcat(); /* display the catalog */
926
927 /* show size if getcat() didn't */
928
929 if ((NOT ldidsiz) AND (NOT lderrsw))
930 showsiz();
931
932 return(SUCCESS);
933}
934
935/*
936
937*/
938
939/*
940 =============================================================================
941 streset() -- reset the switches after a store or an error
942 =============================================================================
943*/
944
945void streset(void)
946{
947 lstrsw = FALSE;
948
949 lasgsw = FALSE;
950 lorchsw = FALSE;
951 lorclsw = FALSE;
952 lpatsw = FALSE;
953 lscrsw = FALSE;
954 lseqsw = FALSE;
955 ltunsw = FALSE;
956 lwavsw = FALSE;
957
958 ldswin(9);
959}
960
961/*
962 =============================================================================
963 fcreset() -- reset the switches after a fetch or an error
964 =============================================================================
965*/
966
967void fcreset(void)
968{
969 lselsw = FALSE;
970
971 ldswin(6);
972}
973
974/*
975
976*/
977
978/*
979 =============================================================================
980 getslot() -- find a free file catalog slot
981
982 returns -1 on error, slot # 0..FCMAX-1 if a slot was found
983 =============================================================================
984*/
985
986int16_t getslot(void)
987{
988 register int16_t i;
989
990 for (i = 0; i < FCMAX; i++)
991 if (NOT ocslot(i))
992 return(i);
993
994 return(-1);
995}
996
997/*
998 =============================================================================
999 slotnam() -- return the file name for a slot
1000 =============================================================================
1001*/
1002
1003int8_t *slotnam(uint16_t slot, uint16_t kind)
1004{
1005 static int8_t thename[13];
1006
1007 sprintf(thename, "M7SLOT%02.2u.%-3.3s",
1008 slot, ftypes[kind - 1][0]);
1009
1010 return(thename);
1011}
1012
1013/*
1014
1015*/
1016
1017/*
1018 =============================================================================
1019 wrtfile() -- write a file on the disk
1020 =============================================================================
1021*/
1022
1023int16_t wrtfile(int16_t kind)
1024{
1025 register int16_t slot, flspace, tkind;
1026 int8_t sizetmp[4];
1027
1028 slot = getslot();
1029
1030 if (-1 EQ slot) {
1031
1032 noslot(kind);
1033 streset();
1034 return(FAILURE);
1035 }
1036
1037/*
1038
1039*/
1040
1041 switch (kind) {
1042
1043 case FT_ASG:
1044
1045 if (wrt_asg(slot))
1046 return(FAILURE);
1047 else
1048 break;
1049
1050 case FT_ORL: /* lo orch write */
1051
1052 if (wrt_orc(slot, 0))
1053 return(FAILURE);
1054 else
1055 break;
1056
1057 case FT_ORH: /* hi orch write */
1058
1059 if (wrt_orc(slot, 1))
1060 return(FAILURE);
1061 else
1062 break;
1063
1064 case FT_PAT:
1065
1066 if (wrt_pat(slot))
1067 return(FAILURE);
1068 else
1069 break;
1070
1071 case FT_SCR:
1072
1073 if (wrt_scr(slot))
1074 return(FAILURE);
1075 else
1076 break;
1077
1078 case FT_SEQ:
1079
1080 if (wrt_seq(slot))
1081 return(FAILURE);
1082 else
1083 break;
1084
1085/*
1086
1087*/
1088 case FT_TUN:
1089
1090 if (wrt_tun(slot))
1091 return(FAILURE);
1092 else
1093 break;
1094
1095 case FT_WAV:
1096
1097 if (wrt_wav(slot))
1098 return(FAILURE);
1099 else
1100 break;
1101
1102 default:
1103
1104 sprintf(ldmsg1, " kind=%d", kind);
1105
1106 ldermsg("bad wrtfile argument:",
1107 ldmsg1, (int8_t *)NULL, LD_EMCF, LD_EMCB);
1108
1109 return(FAILURE);
1110 }
1111
1112/*
1113
1114*/
1115
1116 /* update the file catalog */
1117
1118 if ((kind EQ FT_ORL) OR (kind EQ FT_ORH))
1119 tkind = FT_ORC;
1120 else
1121 tkind = kind;
1122
1123 flspace = spacerq(kind);
1124
1125 sprintf(sizetmp, "%03.3d", flspace); /* size */
1126 memcpy(filecat[slot].fcsize, sizetmp, 3);
1127
1128 memcpy(filecat[slot].fcname, ldfile, 8); /* name */
1129 memcpy(filecat[slot].fcextn, ftypes[tkind - 1][0], 3); /* type */
1130 memcpy(filecat[slot].fccmnt, ldcmnt, 37); /* comment */
1131
1132 savefc(kind);
1133
1134 filecat[slot].fceol[0] = A_CR;
1135 filecat[slot].fceol[1] = A_LF;
1136
1137 return(SUCCESS);
1138}
1139
1140/*
1141
1142*/
1143
1144/*
1145 =============================================================================
1146 writem() -- write selected files
1147 =============================================================================
1148*/
1149
1150int16_t writem(void)
1151{
1152 if (lasgsw) /* Assignments */
1153 if (wrtfile(FT_ASG))
1154 return(FAILURE);
1155
1156 if (lorchsw) /* Hi Orch */
1157 if (wrtfile(FT_ORH))
1158 return(FAILURE);
1159
1160 if (lorclsw) /* Lo Orch */
1161 if (wrtfile(FT_ORL))
1162 return(FAILURE);
1163
1164 if (lpatsw) /* Patches */
1165 if (wrtfile(FT_PAT))
1166 return(FAILURE);
1167
1168 if (lscrsw) /* Score */
1169 if (wrtfile(FT_SCR))
1170 return(FAILURE);
1171
1172 if (lseqsw) /* Sequences */
1173 if (wrtfile(FT_SEQ))
1174 return(FAILURE);
1175
1176 if (ltunsw) /* Tunings */
1177 if (wrtfile(FT_TUN))
1178 return(FAILURE);
1179
1180 if (lwavsw) /* Waveshapes */
1181 if (wrtfile(FT_WAV))
1182 return(FAILURE);
1183
1184 return(SUCCESS);
1185}
1186
1187/*
1188
1189*/
1190
1191/*
1192 =============================================================================
1193 storit() -- store selected files on disk
1194 =============================================================================
1195*/
1196
1197int16_t storit(void)
1198{
1199 register int16_t weneed, i, slotnd, slothv;
1200 int16_t rc, drem;
1201
1202 /* make sure the file is named */
1203
1204 if (0 EQ memcmp(ldfile, " ", 8)) {
1205
1206 ldermsg("File must be named",
1207 ld_em1, ld_em2, LD_EMCF, LD_EMCB);
1208
1209 streset();
1210 return(FAILURE);
1211 }
1212
1213 /* make sure something was selected */
1214
1215 if (ckstor()) {
1216
1217 ldermsg("No file type selected",
1218 ld_em1, ld_em2, LD_EMCF, LD_EMCB);
1219
1220 streset();
1221 return(FAILURE);
1222 }
1223
1224 if (NOT lderrsw)
1225 ldbusy(" Storing files");
1226
1227 if (getcat(0)) { /* get the catalog */
1228
1229 streset();
1230 return(FAILURE);
1231 }
1232
1233 /* find out how much space we need to store everything */
1234
1235 drem = dspace(1);
1236 slotnd = 0;
1237 weneed = 0;
1238
1239/*
1240
1241*/
1242 if (lasgsw) {
1243
1244 weneed += spacerq(FT_ASG);
1245 ++slotnd;
1246 }
1247
1248 if (lorchsw) {
1249
1250 weneed += spacerq(FT_ORH);
1251 ++slotnd;
1252 }
1253
1254 if (lorclsw) {
1255
1256 weneed += spacerq(FT_ORL);
1257 ++slotnd;
1258 }
1259
1260 if (lpatsw) {
1261
1262 weneed += spacerq(FT_PAT);
1263 ++slotnd;
1264 }
1265
1266 if (lscrsw) {
1267
1268 weneed += spacerq(FT_SCR);
1269 ++slotnd;
1270 }
1271
1272 if (lseqsw) {
1273
1274 weneed += spacerq(FT_SEQ);
1275 ++slotnd;
1276 }
1277
1278 if (ltunsw) {
1279
1280 weneed += spacerq(FT_TUN);
1281 ++slotnd;
1282 }
1283
1284 if (lwavsw) {
1285
1286 weneed += spacerq(FT_WAV);
1287 ++slotnd;
1288 }
1289
1290 if (drem < weneed) {
1291
1292 nospace("file");
1293 streset();
1294 return(FAILURE);
1295 }
1296
1297/*
1298
1299*/
1300
1301 /* see if we have enough catalog space */
1302
1303 slothv = 0;
1304
1305 for (i = 0; i < FCMAX; i++)
1306 if (NOT ocslot(i))
1307 ++slothv;
1308
1309 if (slothv < slotnd) {
1310
1311 nospace("file");
1312 streset();
1313 return(FAILURE);
1314 }
1315
1316 /* make sure the name is unique */
1317
1318 if (rc = ckdups()) {
1319
1320 sprintf(ldmsg1, "Duplicate %s", ftypes[rc - 1][2]);
1321 ldermsg(ldmsg1, ld_em1, ld_em2, LD_EMCF, LD_EMCB);
1322
1323 streset();
1324 return(FAILURE);
1325 }
1326
1327/*
1328
1329*/
1330
1331 /* write the files */
1332
1333 rc = writem();
1334
1335 if (NOT rc)
1336 ldbusy(" Writing catalog");
1337
1338 if (putcat()) {
1339
1340 _clsvol();
1341 streset();
1342 showcat();
1343 return(FAILURE);
1344 }
1345
1346 _clsvol();
1347 streset();
1348 showcat();
1349
1350 if (rc)
1351 return(FAILURE);
1352
1353 showsiz();
1354 return(SUCCESS);
1355}
1356
1357/*
1358
1359*/
1360
1361/*
1362 =============================================================================
1363 advlcur() -- advance the librarian display text cursor
1364 =============================================================================
1365*/
1366
1367void advlcur(void)
1368{
1369 register int16_t newcol;
1370
1371 if (infield(stcrow, stccol, curfet))
1372 cfetp = infetp;
1373 else
1374 return;
1375
1376 newcol = stccol + 1;
1377
1378 if (newcol LE cfetp->frcol)
1379 itcpos(stcrow, newcol);
1380
1381 cxval = stccol * 8;
1382 cyval = stcrow * 14;
1383}
1384
1385/*
1386 =============================================================================
1387 bsplcur() -- backspace the librarian display text cursor
1388 =============================================================================
1389*/
1390
1391void bsplcur(void)
1392{
1393 register int16_t newcol;
1394
1395 if (infield(stcrow, stccol, curfet))
1396 cfetp = infetp;
1397 else
1398 return;
1399
1400 newcol = stccol - 1;
1401
1402 if (newcol GE cfetp->flcol)
1403 itcpos(stcrow, newcol);
1404
1405 cxval = stccol * 8;
1406 cyval = stcrow * 14;
1407}
1408
1409/*
1410
1411*/
1412
1413/*
1414 =============================================================================
1415 ldswin() -- display a window
1416 =============================================================================
1417*/
1418
1419void ldswin(int16_t n)
1420{
1421 register int16_t cx, cy;
1422
1423 if (ndisp NE 0)
1424 return;
1425
1426 if ((n EQ 10) AND (lmwtype EQ 1))
1427 cx = exp_c(TTBACK); /* use black for the typewriter */
1428 else
1429 cx = exp_c(ldbox[n][5]); /* expand the background color */
1430
1431 /* first, fill the box with the background color */
1432
1433 if (v_regs[5] & 0x0180)
1434 vbank(0);
1435
1436 vbfill4(librob, 128, ldbox[n][0], ldbox[n][1], ldbox[n][2],
1437 ldbox[n][3], cx);
1438
1439 /* put in the box label */
1440
1441 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1442 ldbxlb0[n], 14);
1443
1444/*
1445
1446*/
1447 switch (n) { /* final text - overlays above stuff */
1448
1449 case 0: /* titles */
1450
1451 point = ldpoint;
1452
1453 lseg( 8, 13, 79, 13, LUNDRLN);
1454 lseg( 88, 13, 95, 13, LUNDRLN);
1455 lseg(104, 13, 167, 13, LUNDRLN);
1456 lseg(176, 13, 471, 13, LUNDRLN);
1457 lseg(480, 13, 504, 13, LUNDRLN);
1458
1459 return;
1460
1461 case 1: /* index area */
1462
1463 return;
1464
1465 case 3: /* current file name */
1466
1467 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1468 ldfile, 14);
1469 return;
1470
1471 case 5: /* current comment field */
1472
1473 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1474 ldcmnt, 14);
1475 return;
1476
1477/*
1478
1479*/
1480
1481 case 7: /* "Replace" / "Append" */
1482
1483 if (lrasw)
1484 cy = exp_c(LD_SELC);
1485 else
1486 cy = ldbox[n][4];
1487
1488 tsplot4(librob, 64, cy, ldbox[n][6], ldbox[n][7],
1489 "Content", 14);
1490
1491 return;
1492
1493 case 8: /* "Hi Orch" / "Lo Orch" */
1494
1495 if (lselsw) {
1496
1497 ldkind = ftkind(ldslot);
1498
1499 if ((ldkind EQ FT_ORC) OR
1500 (ldkind EQ FT_ORL) OR
1501 (ldkind EQ FT_ORH))
1502 cy = exp_c(LD_SELC);
1503 else
1504 cy = ldbox[n][4];
1505
1506 } else {
1507
1508 cy = ldbox[n][4];
1509 }
1510
1511 tsplot4(librob, 64, cy, ldbox[n][6], ldbox[n][7],
1512 (lorchl ? "Hi Orch" : "Lo Orch"), 14);
1513
1514 return;
1515/*
1516
1517*/
1518 case 9: /* "Store" status */
1519
1520 cy = exp_c(lstrsw ? LD_SELC : ldbox[n][4]);
1521 tsplot4(librob, 64, cy, 22, 10, "Store", 14);
1522
1523 cy = exp_c(lscrsw ? LD_SELC : ldbox[n][4]);
1524 tsplot4(librob, 64, cy, 22, 17, "Score", 14);
1525
1526 cy = exp_c(lorchsw ? LD_SELC : ldbox[n][4]);
1527 tsplot4(librob, 64, cy, 22, 24, "Hi Orch", 14);
1528
1529
1530 cy = exp_c(lwavsw ? LD_SELC : ldbox[n][4]);
1531 tsplot4(librob, 64, cy, 23, 10, "Waves", 14);
1532
1533 cy = exp_c(lpatsw ? LD_SELC : ldbox[n][4]);
1534 tsplot4(librob, 64, cy, 23, 17, "Patch", 14);
1535
1536 cy = exp_c(lorclsw ? LD_SELC : ldbox[n][4]);
1537 tsplot4(librob, 64, cy, 23, 24, "Lo Orch", 14);
1538
1539
1540 cy = exp_c(lasgsw ? LD_SELC : ldbox[n][4]);
1541 tsplot4(librob, 64, cy, 24, 10, "Assgn", 14);
1542
1543 cy = exp_c(lseqsw ? LD_SELC : ldbox[n][4]);
1544 tsplot4(librob, 64, cy, 24, 17, "Seqnc", 14);
1545
1546 cy = exp_c(ltunsw ? LD_SELC : ldbox[n][4]);
1547 tsplot4(librob, 64, cy, 24, 24, "Tunings", 14);
1548
1549 return;
1550
1551 case 10: /* typewriter / error messages */
1552
1553 tsplot4(librob, 64, ldbox[n][4], 22, ldbox[n][7], lmln22, 14);
1554 tsplot4(librob, 64, ldbox[n][4], 23, ldbox[n][7], lmln23, 14);
1555 tsplot4(librob, 64, ldbox[n][4], 24, ldbox[n][7], lmln24, 14);
1556
1557 return;
1558 }
1559}
1560
1561/*
1562
1563*/
1564
1565/*
1566 =============================================================================
1567 lwins() -- display all librarian windows
1568 =============================================================================
1569*/
1570
1571void lwins(void)
1572{
1573 register int16_t i;
1574
1575 for (i = 0; i < 11; i++)
1576 ldswin(i);
1577}
1578
1579/*
1580 =============================================================================
1581 ldpoint() -- plot a point for the lseg function
1582 =============================================================================
1583*/
1584
1585void ldpoint(int16_t x, int16_t y, int16_t pen)
1586{
1587 if (v_regs[5] & 0x0180)
1588 vbank(0);
1589
1590 vputp(ldoct, x, y, exp_c(pen));
1591}
1592
1593/*
1594
1595*/
1596
1597/*
1598 =============================================================================
1599 ldbord() -- draw the border for the librarian display
1600 =============================================================================
1601*/
1602
1603void ldbord(void)
1604{
1605 point = ldpoint;
1606
1607 lseg( 0, 0, 511, 0, LBORD); /* outer border */
1608 lseg(511, 0, 511, 349, LBORD);
1609 lseg(511, 349, 0, 349, LBORD);
1610 lseg( 0, 349, 0, 0, LBORD);
1611
1612 lseg( 0, 293, 511, 293, LBORD); /* windows - H lines */
1613 lseg(511, 308, 0, 308, LBORD);
1614
1615 lseg( 79, 293, 79, 308, LBORD); /* windows - V lines */
1616 lseg(144, 293, 144, 308, LBORD);
1617 lseg(215, 293, 215, 308, LBORD);
1618 lseg( 71, 308, 71, 349, LBORD);
1619 lseg(256, 308, 256, 349, LBORD);
1620}
1621
1622/*
1623
1624*/
1625
1626/*
1627 =============================================================================
1628 lwclr() -- clear the message window text strings
1629 =============================================================================
1630*/
1631
1632void lmwclr(void)
1633{
1634 lmwtype = 0;
1635 submenu = FALSE;
1636
1637 lmln22 = "";
1638 lmln23 = "";
1639 lmln24 = "";
1640}
1641
1642/*
1643 =============================================================================
1644 lmwvtyp() -- load the typewriter into the message window text strings
1645 =============================================================================
1646*/
1647
1648void lmwvtyp(void)
1649{
1650 lmwtype = 1;
1651 submenu = TRUE;
1652
1653 lmln22 = vtlin1;
1654 lmln23 = vtlin2;
1655 lmln24 = vtlin3;
1656}
1657
1658/*
1659
1660*/
1661
1662/*
1663 =============================================================================
1664 libdsp() -- put up the librarian display
1665 =============================================================================
1666*/
1667
1668void libdsp(void)
1669{
1670 librob = &v_score[0]; /* setup display object pointer */
1671 obj0 = &v_curs0[0]; /* setup cursor object pointer */
1672 obj2 = &v_tcur[0]; /* setup typewriter cursor pointer */
1673 ldoct = &v_obtab[LIBROBJ]; /* setup object control table pointer */
1674
1675 lselsw = FALSE;
1676 ldelsw = FALSE;
1677 lstrsw = FALSE;
1678
1679 lasgsw = FALSE;
1680 lorchsw = FALSE;
1681 lorclsw = FALSE;
1682 lpatsw = FALSE;
1683 lscrsw = FALSE;
1684 lseqsw = FALSE;
1685 ltunsw = FALSE;
1686 lwavsw = FALSE;
1687
1688 lderrsw = FALSE;
1689 ltagged = FALSE;
1690 lksel = -1;
1691/*
1692
1693*/
1694 clrcat(); /* void the catalog */
1695 catin = FALSE;
1696
1697 lmwclr(); /* clear the message window text strings */
1698
1699 dswap(); /* initialize display */
1700
1701 if (v_regs[5] & 0x0180)
1702 vbank(0);
1703
1704 memsetw(librob, 0, 32767);
1705 memsetw(librob+32767L, 0, 12033);
1706
1707 SetObj(LIBROBJ, 0, 0, librob, 512, 350, 0, 0, LIBRFL, -1);
1708 SetObj( 0, 0, 1, obj0, 16, 16, LCURX, LCURY, OBFL_00, -1);
1709 SetObj( TTCURS, 0, 1, obj2, 16, 16, 0, 0, TTCCFL, -1);
1710
1711 arcurs(TTCURC); /* setup arrow cursor object */
1712 itcini(TTCURC); /* setup text cursor object */
1713 ttcini(TTCURC); /* setup typewriter cursor object */
1714
1715 ldbord(); /* draw the border */
1716 lwins();
1717
1718 vsndpal(lbrpal); /* setup the palette */
1719
1720 SetPri(LIBROBJ, LIBRPRI);
1721 SetPri(0, GCPRI); /* display the graphic cursor */
1722
1723 setgc(LCURX, LCURY);
1724
1725 chtime = thcwval; /* turn it into a text cursor */
1726 cvtime = tvcwval;
1727 cmtype = CT_TEXT;
1728 itcpos(cyval / 14, cxval >> 3);
1729}
1730
Note: See TracBrowser for help on using the repository browser.