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

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

Fixed libdsp.c.

  • Property mode set to 100644
File size: 31.3 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(int16_t c)
160{
161 uint16_t r;
162
163 r = (uint16_t)c & 0x000F; /* use low 4 bits as the basis */
164 r |= r << 4; /* turn them into 8 bits */
165 r |= r << 8; /* make it a full 16 bits */
166
167 return(r);
168}
169
170/*
171 =============================================================================
172 ldwmsg() -- display a message in the message window
173 =============================================================================
174*/
175
176void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, int16_t fgcolor, int16_t bgcolor)
177{
178 lderrsw = FALSE; /* clear error switch */
179 lmwtype = 2; /* message type */
180 submenu = FALSE;
181
182 if (ndisp NE 0)
183 return;
184
185 if (v_regs[5] & 0x0180)
186 vbank(0);
187
188 /* clear the window */
189
190 vbfill4(librob, 128, ldbox[10][0], ldbox[10][1],
191 ldbox[10][2], ldbox[10][3], exp_c(bgcolor));
192
193 if ((int8_t *)NULL NE line1)
194 tsplot4(librob, 64, fgcolor, ldbox[10][6], ldbox[10][7],
195 line1, 14);
196
197 if ((int8_t *)NULL NE line2)
198 tsplot4(librob, 64, fgcolor, (ldbox[10][6] + 1), ldbox[10][7],
199 line2, 14);
200
201 if ((int8_t *)NULL NE line3)
202 tsplot4(librob, 64, fgcolor, (ldbox[10][6] + 2), ldbox[10][7],
203 line3, 14);
204}
205
206/*
207 =============================================================================
208 chksum() -- checksum an area of memory
209 =============================================================================
210*/
211
212int32_t chksum(void *area, int32_t len)
213{
214 uint8_t *area8;
215 int32_t cs, i;
216
217 area8 = area;
218 cs = 0L;
219
220 for (i = 0; i < len; i++)
221 cs += 0x000000FFL & *area8++;
222
223 return(cs);
224}
225
226/*
227 =============================================================================
228 makelh() -- make a library header
229 =============================================================================
230*/
231
232void makelh(int16_t kind)
233{
234 memset(ldhead.l_csum, '?', 8); /* checksum */
235 memcpy(ldhead.l_name, ldfile, 8); /* file name */
236 memcpy(ldhead.l_type, ftypes[kind - 1][0], 3); /* file type */
237 memcpy(ldhead.l_cmnt, ldcmnt, 37); /* comment */
238
239 lcsum = chksum(ldhead.l_name, (int32_t)(LH_LEN - 8));
240}
241
242/*
243 =============================================================================
244 ldbusy() -- put up a "Busy" message
245 =============================================================================
246*/
247
248void ldbusy(int8_t *msg)
249{
250 if (ndisp NE 0)
251 return;
252
253 ldwmsg((int8_t *)NULL, " Busy - Please stand by", msg,
254 ldbox[10][4], ldbox[10][5]);
255}
256
257/*
258 =============================================================================
259 noslot() -- complain about not finding a slot we expected
260 =============================================================================
261*/
262
263void noslot(int16_t fctype)
264{
265 sprintf(ldmsg1, " the %s file,", ftypes[fctype - 1][2]);
266
267 ldermsg("Can't find a slot for",
268 ldmsg1, " and one was expected", LD_EMCF, LD_EMCB);
269}
270
271/*
272 =============================================================================
273 wr_ec() -- write with error checking
274 =============================================================================
275*/
276
277int16_t wr_ec(FILE *fp, void *from, int32_t len)
278{
279 uint8_t *from8, c;
280 int32_t count;
281
282 from8 = from;
283
284 for (count = 0; count < len; count++) {
285
286 errno = 0;
287 c = *from8++;
288
289 if (EOF EQ putc(c, fp)) {
290
291 sprintf(errbuf, "errno = %d", errno);
292
293 ldermsg("Disk may be full",
294 errbuf, (int8_t *)NULL, LD_EMCF, LD_EMCB);
295
296 fclose(fp);
297 postio(); /* restore LCD backlight */
298 return(FAILURE);
299 }
300
301#if DEBUGWE
302 if (debugsw AND debugwe)
303 printf(" %02.2X", 0x00FF & c);
304#endif
305 }
306
307 return(SUCCESS);
308}
309
310/*
311 =============================================================================
312 rd_ec() -- read with error checking
313 =============================================================================
314*/
315
316int16_t rd_ec(FILE *fp, void *to, int32_t len)
317{
318 uint8_t *to8;
319 int32_t count;
320 int16_t c;
321
322 to8 = to;
323
324 for (count = 0; count < len; count++) {
325
326 errno = 0;
327
328 if (EOF EQ (c = getc(fp))) {
329
330 sprintf(errbuf, "errno = %d", errno);
331
332 ldermsg("Unexpected EOF",
333 errbuf, (int8_t *)NULL, LD_EMCF, LD_EMCB);
334
335 fclose(fp);
336 postio(); /* restore LCD backlight */
337 return(FAILURE);
338
339 } else {
340
341 *to8++ = (uint8_t)c;
342
343#if DEBUGRE
344 if (debugsw AND debugre)
345 printf(" %02.2X", 0x00FF & c);
346#endif
347 }
348 }
349
350 return(SUCCESS);
351}
352
353/*
354 =============================================================================
355 srchcat() -- search the file catalog
356
357 returns -1 on 'not found', slot 0..FCMAX-1 if found
358 =============================================================================
359*/
360
361int16_t srchcat(int8_t extn[])
362{
363 register int16_t fcslot;
364
365 for (fcslot = 0; fcslot < FCMAX; fcslot++) {
366
367 if (ocslot(fcslot))
368 if (0 EQ (memcmp(filecat[fcslot].fcname, ldfile, 8))
369 AND (0 EQ memcmpu(filecat[fcslot].fcextn, extn, 3)))
370 return(fcslot);
371 }
372
373 return(-1);
374}
375
376/*
377 =============================================================================
378 clrcat() -- clear the file catalog
379 =============================================================================
380*/
381
382void clrcat(void)
383{
384 register int16_t i;
385 int8_t fcebuf[1 + sizeof (struct fcat)];
386
387 for (i = 0; i < FCMAX; i++) {
388
389 sprintf(fcebuf, "000 Empty-%02.2d ??? %-37.37s%c%c",
390 i, "1234567890123456789012345678901234567",
391 A_CR, A_LF);
392
393 memcpy(&filecat[i], fcebuf, sizeof (struct fcat));
394 }
395}
396
397/*
398 =============================================================================
399 clreq() -- return number of clusters needed for a file
400
401 Assumes the BPB pointer is valid.
402 =============================================================================
403*/
404
405int16_t clreq(int32_t bytes)
406{
407 register int16_t rclusts;
408 register int32_t clmask;
409
410 clmask = _thebpb->clsizb - 1;
411
412 rclusts = (int16_t)(bytes / _thebpb->clsizb)
413 + ((bytes & clmask) ? 1 : 0);
414
415 return(rclusts);
416}
417
418/*
419 =============================================================================
420 spacerq() -- return space required for storing a file
421 =============================================================================
422*/
423
424int16_t spacerq(int16_t kind)
425{
426 register int16_t howmuch;
427 register int32_t k;
428
429 k = 0L;
430
431 switch (kind) {
432
433 case FT_ASG: /* Assignment file */
434
435 k = (sizeof (struct asgent) * (int32_t)NASGLIB) + (int32_t)LH_LEN;
436 break;
437
438 case FT_ORL:
439 case FT_ORH:
440 case FT_ORC:
441
442 k = ((OR_LEN1 + (2 * OR_LEN2)) * (int32_t)NINORC) + (int32_t)LH_LEN;
443 break;
444
445 case FT_PAT: /* Patch file */
446
447 k = ptsizer() + (int32_t)LH_LEN;
448 break;
449
450 case FT_SCR: /* Score file */
451
452 k = scsizer() + (int32_t)LH_LEN;
453 break;
454
455 case FT_SEQ: /* Sequence file */
456
457 k = sqsizer() + (int32_t)LH_LEN;
458 break;
459
460 case FT_TUN: /* Tuning file */
461
462 k = (NTUNSLIB * 256L) + (NTUNSLIB * 32L) + (int32_t)LH_LEN;
463 break;
464
465 case FT_WAV: /* Waveshape file */
466
467 k = ((int32_t)NUMWAVS * OR_LEN2) + (int32_t)LH_LEN;
468 break;
469
470 default:
471
472 k = 0L;
473 break;
474 }
475
476 howmuch = k ? clreq(k) : -1;
477 ndbytes = k;
478 return(howmuch);
479}
480
481/*
482 =============================================================================
483 ckstor() -- check for storage type selection
484 =============================================================================
485*/
486
487int16_t ckstor(void)
488{
489 if (lasgsw) /* assignments */
490 return(SUCCESS);
491
492 if (lorchsw) /* hi orch */
493 return(SUCCESS);
494
495 if (lorclsw) /* lo orch */
496 return(SUCCESS);
497
498 if (lpatsw) /* patches */
499 return(SUCCESS);
500
501 if (lscrsw) /* score */
502 return(SUCCESS);
503
504 if (lseqsw) /* sequences */
505 return(SUCCESS);
506
507 if (ltunsw) /* tunings */
508 return(SUCCESS);
509
510 if (lwavsw) /* waveshapes */
511 return(SUCCESS);
512
513 return(FAILURE);
514}
515
516/*
517 =============================================================================
518 ckdups() -- check for duplicate file type entries in the file catalog
519 =============================================================================
520*/
521
522int16_t ckdups(void)
523{
524 if (lasgsw)
525 if (-1 NE srchcat("asg"))
526 return(FT_ASG);
527
528 if (lorchsw)
529 if (-1 NE srchcat("orh"))
530 return(FT_ORH);
531
532 if (lorclsw)
533 if (-1 NE srchcat("orl"))
534 return(FT_ORL);
535
536 if (lorchsw OR lorclsw)
537 if (-1 NE srchcat("orc"))
538 return(FT_ORC);
539
540 if (lpatsw)
541 if (-1 NE srchcat("pat"))
542 return(FT_PAT);
543
544 if (lscrsw)
545 if (-1 NE srchcat("scr"))
546 return(FT_SCR);
547
548 if (lseqsw)
549 if (-1 NE srchcat("seq"))
550 return(FT_SEQ);
551
552 if (ltunsw)
553 if (-1 NE srchcat("tun"))
554 return(FT_TUN);
555
556 if (lwavsw)
557 if (-1 NE srchcat("wav"))
558 return(FT_WAV);
559 return(0);
560}
561
562/*
563 =============================================================================
564 showsiz() -- display disk capacity and usage
565
566 Forces the disk to be read to get the BPB and FAT.
567 =============================================================================
568*/
569
570int16_t showsiz(void)
571{
572 register int16_t dcap, drem, dused;
573
574 _bpbin = FALSE; /* force disk to be read */
575
576 dcap = dspace(0);
577
578 if (dcap EQ -1) {
579
580 ldermsg("Disk not ready ?",
581 (int8_t *)NULL, (int8_t *)NULL,
582 LD_EMCF, LD_EMCB);
583
584 return(FAILURE);
585 }
586
587 drem = dspace(1);
588 dused = dcap - drem;
589
590 sprintf(ldmsg1, "Microdisk capacity %4u blocks", dcap);
591 sprintf(ldmsg2, "This disk consumes %4u blocks", dused);
592 sprintf(ldmsg3, "Available space is %4u blocks", drem);
593
594 ldwmsg(ldmsg1, ldmsg2, ldmsg3, ldbox[10][4], ldbox[10][5]);
595 return(SUCCESS);
596}
597
598/*
599 =============================================================================
600 getcat() -- get the file catalog from disk
601 =============================================================================
602*/
603
604int16_t getcat(int16_t msgsw)
605{
606 register FILE *fp;
607 int16_t rc, fesize;
608
609 ldidsiz = FALSE; /* we didn't show the size (yet) */
610 _bpbin = FALSE; /* guarantee we read the directory */
611 catin = FALSE; /* catalog not valid */
612
613 errno = 0;
614 preio(); /* kill LCD backlight */
615 fp = fopenb(CATNAME, "r"); /* open the catalog file */
616
617 if (NULL EQ fp) {
618
619 clrcat();
620 catin = TRUE;
621
622 if (msgsw) { /* see if we show the message */
623
624 showsiz();
625 ldidsiz = TRUE; /* showed the size */
626 }
627
628 return(SUCCESS); /* no catalog is OK, too */
629 }
630
631 fesize = sizeof(struct fcat);
632 memset(filecat, 0, sizeof (struct fcat) * FCMAX);
633
634
635 errno = 0;
636 rc = fread(filecat, fesize, FCMAX, fp);
637
638 if (rc NE FCMAX) {
639
640 if (rc) {
641
642 sprintf(ldmsg1, " fread returned %d", rc);
643 sprintf(ldmsg2, " errno = %d, fesize=%d",
644 errno, fesize);
645
646 ldermsg("Unable to read catalog",
647 ldmsg1, ldmsg2, LD_EMCF, LD_EMCB);
648
649 catin = FALSE;
650
651 } else {
652
653 ldermsg("File catalog is NULL",
654 (int8_t *)NULL, (int8_t *)NULL,
655 LD_EMCF, LD_EMCB);
656
657 clrcat();
658 catin = TRUE;
659 }
660
661 fclose(fp);
662 postio(); /* restore LCD backlight */
663 return(FAILURE);
664 }
665
666 catin = TRUE;
667 fclose(fp);
668 postio(); /* restore LCD backlight */
669 return(SUCCESS);
670}
671
672/*
673 =============================================================================
674 putcat() -- write the updated catalog on disk
675 =============================================================================
676*/
677
678int16_t putcat(void)
679{
680 register FILE *fp;
681 register int16_t i, rc, fesize;
682
683 for (i = 0; i < FCMAX; i++) { /* clean up the catalog */
684
685 filecat[i].fceol[0] = A_CR;
686 filecat[i].fceol[1] = A_LF;
687 }
688
689 errno = 0;
690 preio(); /* kill LCD backlight */
691 fp = fopenb(CATNAME, "w"); /* open the catalog file */
692
693 if (NULL EQ fp) {
694
695 sprintf(ldmsg2, " errno = %d", errno);
696
697 ldermsg("Unable to open catalog",
698 (int8_t *)NULL, ldmsg2, LD_EMCF, LD_EMCB);
699
700 return(FAILURE);
701 }
702
703 fesize = sizeof (struct fcat);
704
705
706 errno = 0;
707 rc = fwrite(filecat, fesize, FCMAX, fp);
708
709 if (rc NE FCMAX) {
710
711 if (rc) {
712
713 sprintf(ldmsg1, " fwrite returned %d", rc);
714 sprintf(ldmsg2, " errno = %d, fesize=%d",
715 errno, fesize);
716
717 ldermsg("Can't write catalog",
718 ldmsg1, ldmsg2, LD_EMCF, LD_EMCB);
719
720 } else {
721
722 sprintf(ldmsg2, " errno = %d", errno);
723
724 ldermsg("Disk may be full",
725 (int8_t *)NULL, ldmsg2,
726 LD_EMCF, LD_EMCB);
727 }
728
729 fclose(fp);
730 postio(); /* restore LCD backlight */
731 return(FAILURE);
732 }
733
734 fclose(fp);
735 postio(); /* restore LCD backlight */
736 return(SUCCESS);
737}
738
739/*
740 =============================================================================
741 dslslot() -- display a file catalog entry
742 =============================================================================
743*/
744
745void dslslot(int16_t slot, int16_t fg, int16_t row)
746{
747 int16_t color, chilon, chilorc;
748 int16_t c;
749 int8_t buf[40];
750
751 if (ndisp NE 0)
752 return;
753
754 color = fg; /* foreground color */
755 chilon = ldbox[1][4];
756 chilorc = HILORC;
757
758 /* file type */
759
760 vcputsv(librob, 64, color, ldbox[1][5], row, 1, fctstr(slot, 0), 14);
761
762 /* load letter */
763
764 c = filecat[slot].fcp0;
765 buf[0] = 0x007F & c;
766 buf[1] = '\0';
767 vcputsv(librob, 64, (c & 0x0080) ? chilorc : chilon,
768 ldbox[1][5], row, 11, buf, 14);
769
770 /* file name */
771
772 memcpy(buf, filecat[slot].fcname, 8);
773 buf[8] = '\0';
774 vcputsv(librob, 64, color, ldbox[1][5], row, 13, buf, 14);
775
776 /* comment */
777
778 memcpy(buf, filecat[slot].fccmnt, 37);
779 buf[37] = '\0';
780 vcputsv(librob, 64, chilon, ldbox[1][5], row, 22, buf, 14);
781
782 /* size */
783
784 memcpy(buf, filecat[slot].fcsize, 3);
785 buf[3] = '\0';
786 vcputsv(librob, 64, chilon, ldbox[1][5], row, 60, buf, 14);
787}
788
789/*
790 =============================================================================
791 showcat() -- display the file catalog entries
792 =============================================================================
793*/
794
795int16_t showcat(void)
796{
797 int16_t fcslot, fcrow, fcount;
798 uint16_t bg;
799 int16_t fg;
800
801 if (ndisp NE 0)
802 return(FAILURE);
803
804 ldswin(0); /* fix up the title */
805
806 bg = 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], bg);
813
814 fg = 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, fg, 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 uint16_t cx;
1296 int16_t cy;
1297
1298 if (ndisp NE 0)
1299 return;
1300
1301 if ((n EQ 10) AND (lmwtype EQ 1))
1302 cx = exp_c(TTBACK); /* use black for the typewriter */
1303 else
1304 cx = exp_c(ldbox[n][5]); /* expand the background color */
1305
1306 /* first, fill the box with the background color */
1307
1308 if (v_regs[5] & 0x0180)
1309 vbank(0);
1310
1311 vbfill4(librob, 128, ldbox[n][0], ldbox[n][1], ldbox[n][2],
1312 ldbox[n][3], cx);
1313
1314 /* put in the box label */
1315
1316 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1317 ldbxlb0[n], 14);
1318
1319
1320 switch (n) { /* final text - overlays above stuff */
1321
1322 case 0: /* titles */
1323
1324 point = ldpoint;
1325
1326 lseg( 8, 13, 79, 13, LUNDRLN);
1327 lseg( 88, 13, 95, 13, LUNDRLN);
1328 lseg(104, 13, 167, 13, LUNDRLN);
1329 lseg(176, 13, 471, 13, LUNDRLN);
1330 lseg(480, 13, 504, 13, LUNDRLN);
1331
1332 return;
1333
1334 case 1: /* index area */
1335
1336 return;
1337
1338 case 3: /* current file name */
1339
1340 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1341 ldfile, 14);
1342 return;
1343
1344 case 5: /* current comment field */
1345
1346 tsplot4(librob, 64, ldbox[n][4], ldbox[n][6], ldbox[n][7],
1347 ldcmnt, 14);
1348 return;
1349
1350 case 7: /* "Replace" / "Append" */
1351
1352 if (lrasw)
1353 cy = LD_SELC;
1354 else
1355 cy = ldbox[n][4];
1356
1357 tsplot4(librob, 64, cy, ldbox[n][6], ldbox[n][7],
1358 "Content", 14);
1359
1360 return;
1361
1362 case 8: /* "Hi Orch" / "Lo Orch" */
1363
1364 if (lselsw) {
1365
1366 ldkind = ftkind(ldslot);
1367
1368 if ((ldkind EQ FT_ORC) OR
1369 (ldkind EQ FT_ORL) OR
1370 (ldkind EQ FT_ORH))
1371 cy = LD_SELC;
1372 else
1373 cy = ldbox[n][4];
1374
1375 } else {
1376
1377 cy = ldbox[n][4];
1378 }
1379
1380 tsplot4(librob, 64, cy, ldbox[n][6], ldbox[n][7],
1381 (lorchl ? "Hi Orch" : "Lo Orch"), 14);
1382
1383 return;
1384
1385 case 9: /* "Store" status */
1386
1387 cy = lstrsw ? LD_SELC : ldbox[n][4];
1388 tsplot4(librob, 64, cy, 22, 10, "Store", 14);
1389
1390 cy = lscrsw ? LD_SELC : ldbox[n][4];
1391 tsplot4(librob, 64, cy, 22, 17, "Score", 14);
1392
1393 cy = lorchsw ? LD_SELC : ldbox[n][4];
1394 tsplot4(librob, 64, cy, 22, 24, "Hi Orch", 14);
1395
1396
1397 cy = lwavsw ? LD_SELC : ldbox[n][4];
1398 tsplot4(librob, 64, cy, 23, 10, "Waves", 14);
1399
1400 cy = lpatsw ? LD_SELC : ldbox[n][4];
1401 tsplot4(librob, 64, cy, 23, 17, "Patch", 14);
1402
1403 cy = lorclsw ? LD_SELC : ldbox[n][4];
1404 tsplot4(librob, 64, cy, 23, 24, "Lo Orch", 14);
1405
1406
1407 cy = lasgsw ? LD_SELC : ldbox[n][4];
1408 tsplot4(librob, 64, cy, 24, 10, "Assgn", 14);
1409
1410 cy = lseqsw ? LD_SELC : ldbox[n][4];
1411 tsplot4(librob, 64, cy, 24, 17, "Seqnc", 14);
1412
1413 cy = ltunsw ? LD_SELC : ldbox[n][4];
1414 tsplot4(librob, 64, cy, 24, 24, "Tunings", 14);
1415
1416 return;
1417
1418 case 10: /* typewriter / error messages */
1419
1420 tsplot4(librob, 64, ldbox[n][4], 22, ldbox[n][7], lmln22, 14);
1421 tsplot4(librob, 64, ldbox[n][4], 23, ldbox[n][7], lmln23, 14);
1422 tsplot4(librob, 64, ldbox[n][4], 24, ldbox[n][7], lmln24, 14);
1423
1424 return;
1425 }
1426}
1427
1428/*
1429 =============================================================================
1430 lwins() -- display all librarian windows
1431 =============================================================================
1432*/
1433
1434void lwins(void)
1435{
1436 register int16_t i;
1437
1438 for (i = 0; i < 11; i++)
1439 ldswin(i);
1440}
1441
1442/*
1443 =============================================================================
1444 ldpoint() -- plot a point for the lseg function
1445 =============================================================================
1446*/
1447
1448void ldpoint(int16_t x, int16_t y, int16_t pen)
1449{
1450 if (v_regs[5] & 0x0180)
1451 vbank(0);
1452
1453 vputp(ldoct, x, y, pen);
1454}
1455
1456/*
1457 =============================================================================
1458 ldbord() -- draw the border for the librarian display
1459 =============================================================================
1460*/
1461
1462void ldbord(void)
1463{
1464 point = ldpoint;
1465
1466 lseg( 0, 0, 511, 0, LBORD); /* outer border */
1467 lseg(511, 0, 511, 349, LBORD);
1468 lseg(511, 349, 0, 349, LBORD);
1469 lseg( 0, 349, 0, 0, LBORD);
1470
1471 lseg( 0, 293, 511, 293, LBORD); /* windows - H lines */
1472 lseg(511, 308, 0, 308, LBORD);
1473
1474 lseg( 79, 293, 79, 308, LBORD); /* windows - V lines */
1475 lseg(144, 293, 144, 308, LBORD);
1476 lseg(215, 293, 215, 308, LBORD);
1477 lseg( 71, 308, 71, 349, LBORD);
1478 lseg(256, 308, 256, 349, LBORD);
1479}
1480
1481/*
1482 =============================================================================
1483 lwclr() -- clear the message window text strings
1484 =============================================================================
1485*/
1486
1487void lmwclr(void)
1488{
1489 lmwtype = 0;
1490 submenu = FALSE;
1491
1492 lmln22 = "";
1493 lmln23 = "";
1494 lmln24 = "";
1495}
1496
1497/*
1498 =============================================================================
1499 lmwvtyp() -- load the typewriter into the message window text strings
1500 =============================================================================
1501*/
1502
1503void lmwvtyp(void)
1504{
1505 lmwtype = 1;
1506 submenu = TRUE;
1507
1508 lmln22 = vtlin1;
1509 lmln23 = vtlin2;
1510 lmln24 = vtlin3;
1511}
1512
1513/*
1514 =============================================================================
1515 libdsp() -- put up the librarian display
1516 =============================================================================
1517*/
1518
1519void libdsp(void)
1520{
1521 librob = &v_score[0]; /* setup display object pointer */
1522 obj0 = &v_curs0[0]; /* setup cursor object pointer */
1523 obj2 = &v_tcur[0]; /* setup typewriter cursor pointer */
1524 ldoct = &v_obtab[LIBROBJ]; /* setup object control table pointer */
1525
1526 lselsw = FALSE;
1527 ldelsw = FALSE;
1528 lstrsw = FALSE;
1529
1530 lasgsw = FALSE;
1531 lorchsw = FALSE;
1532 lorclsw = FALSE;
1533 lpatsw = FALSE;
1534 lscrsw = FALSE;
1535 lseqsw = FALSE;
1536 ltunsw = FALSE;
1537 lwavsw = FALSE;
1538
1539 lderrsw = FALSE;
1540 ltagged = FALSE;
1541 lksel = -1;
1542
1543 clrcat(); /* void the catalog */
1544 catin = FALSE;
1545
1546 lmwclr(); /* clear the message window text strings */
1547
1548 dswap(); /* initialize display */
1549
1550 if (v_regs[5] & 0x0180)
1551 vbank(0);
1552
1553 memsetw(librob, 0, 32767);
1554 memsetw(librob+32767L, 0, 12033);
1555
1556 SetObj(LIBROBJ, 0, 0, librob, 512, 350, 0, 0, LIBRFL, -1);
1557 SetObj( 0, 0, 1, obj0, 16, 16, LCURX, LCURY, OBFL_00, -1);
1558 SetObj( TTCURS, 0, 1, obj2, 16, 16, 0, 0, TTCCFL, -1);
1559
1560 arcurs(TTCURC); /* setup arrow cursor object */
1561 itcini(TTCURC); /* setup text cursor object */
1562 ttcini(TTCURC); /* setup typewriter cursor object */
1563
1564 ldbord(); /* draw the border */
1565 lwins();
1566
1567 vsndpal(lbrpal); /* setup the palette */
1568
1569 SetPri(LIBROBJ, LIBRPRI);
1570 SetPri(0, GCPRI); /* display the graphic cursor */
1571
1572 setgc(LCURX, LCURY);
1573
1574 chtime = thcwval; /* turn it into a text cursor */
1575 cvtime = tvcwval;
1576 cmtype = CT_TEXT;
1577 itcpos(cyval / 14, cxval >> 3);
1578}
1579
Note: See TracBrowser for help on using the repository browser.