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

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

Point of no return.

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