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

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

Removed form-feed comments.

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