source: buchla-68k/ram/ldselbx.c@ 3fcb810

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

Fixed libdsp.c.

  • Property mode set to 100644
File size: 16.0 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 ldselbx.c -- librarian box selection functions
4 Version 46 -- 1988-11-18 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGIT 0
9
[b28a12e]10#include "ram.h"
[e225e77]11
[7258c6a]12int16_t ft2lt[] = { /* file type to load type map */
[f40a309]13
14 LT_ASG,
15 LT_ORL,
16 LT_ORH,
17 LT_SCR,
18 LT_TUN,
19 LT_WAV,
20 LT_ORL,
21 LT_PAT,
22 LT_SEQ
23};
24
25struct selbox ldboxes[] = {
26
27 { 1, 1, 510, 13, 0, ldfnbox}, /* 0 - index area label */
28 { 1, 14, 510, 293, 1, ldfnbox}, /* 1 - index area */
29 { 1, 294, 78, 307, 2, ldfnbox}, /* 2 - file name label */
30 { 80, 294, 143, 307, 3, ldfnbox}, /* 3 - file name */
31 {145, 294, 214, 307, 4, ldfnbox}, /* 4 - comment label */
32 {216, 294, 510, 307, 5, ldfnbox}, /* 5 - comment */
33 { 1, 308, 70, 321, 6, ldfnbox}, /* 6 - fetch */
34 { 1, 322, 70, 335, 7, ldfnbox}, /* 7 - replace / append */
35 { 1, 336, 70, 349, 8, ldfnbox}, /* 8 - lo orch / hi orch */
36 { 72, 308, 255, 349, 9, ldfnbox}, /* 9 - store */
37 {257, 308, 510, 349, 10, ldfnbox}, /* 10 - message window */
38
39 { 0, 0, 0, 0, 0, FN_NULL} /* end of table */
40};
41
42/*
43 =============================================================================
44 skperr() -- complain about an error while skipping a score
45 =============================================================================
46*/
47
[7258c6a]48void skperr(int16_t sn)
[f40a309]49{
[7258c6a]50 int8_t scid[32];
51 int8_t erms[64];
[f40a309]52
53 clrlsel();
54
55 sprintf(scid, " score %d", sn + 1);
56 sprintf(erms, " errno = %d", errno);
57
58 ldermsg("Couldn't skip", scid, erms,
59 LD_EMCF, LD_EMCB);
60}
61
62/*
63 =============================================================================
64 skp_ec() -- skip with error checking
65 =============================================================================
66*/
67
[7258c6a]68int16_t skp_ec(FILE *fp, int32_t len)
[f40a309]69{
[7258c6a]70 register int32_t count;
71 register int16_t c;
72 int8_t errbuf[64];
[f40a309]73
74 for (count = 0; count < len; count++) {
75
76 errno = 0;
77
78 if (EOF EQ (c = getc(fp))) {
79
80 sprintf(errbuf, "errno = %d", errno);
81
82 ldermsg("Unexpected EOF",
[7258c6a]83 errbuf, (int8_t *)NULL, LD_EMCF, LD_EMCB);
[f40a309]84
85#if DEBUGIT
86 if (debugsw)
87 FILEpr(fp);
88#endif
89
90 fclose(fp);
91 postio(); /* restore LCD backlight */
92 return(FAILURE);
93 }
94 }
95
96 return(SUCCESS);
97}
98
99/*
100 =============================================================================
101 scskip() -- skip a score starting with its section list
102 =============================================================================
103*/
104
[7258c6a]105int16_t scskip(FILE *fp, int16_t ns)
[f40a309]106{
[7ecfb7b]107 register int16_t go;
[7258c6a]108 int8_t etype;
109 int8_t erms[64];
[f40a309]110
111 go = TRUE;
112
[7258c6a]113 if (skp_ec(fp, (int32_t)(N_SECTS * 12))) { /* skip section times */
[f40a309]114
115 skperr(ns);
116 return(FAILURE);
117 }
118
119 if (rd_ec(fp, &etype, 1L)) { /* read first score header event */
120
121 skperr(ns);
122 return(FAILURE);
123 }
124
125 if (etype NE EV_SCORE) { /* complain if it's not a score event */
126
127 sprintf(erms, " score %d etype = %d", ns + 1, etype);
128
129 ldermsg("Bad score --", " 1st event is wrong",
130 erms, LD_EMCF, LD_EMCB);
131
132 return(FAILURE);
133 }
134
[7258c6a]135 if (skp_ec(fp, (int32_t)(scsizes[etype][1] - 1))) { /* skip data */
[f40a309]136
137 skperr(ns);
138 return(FAILURE);
139 }
140
[fa38804]141
[f40a309]142 do { /* skip remaining score events */
143
144 if (rd_ec(fp, &etype, 1L)) { /* get event type */
145
146 skperr(ns);
147 return(FAILURE);
148 }
149
150 /* skip the event's data */
151
[7258c6a]152 if (skp_ec(fp, (int32_t)(scsizes[etype][1] - 1))) {
[f40a309]153
154 skperr(ns);
155 return(FAILURE);
156 }
157
158 if (etype EQ EV_FINI) /* check for score end */
159 go = FALSE;
160
161 } while (go);
162
163 return(SUCCESS);
164}
165
166/*
167 =============================================================================
168 ldermsg() -- display an error message if none is up already
169 =============================================================================
170*/
171
[7258c6a]172void ldermsg(int8_t *p1, int8_t *p2, int8_t *p3, uint16_t p4, uint16_t p5)
[f40a309]173{
[7258c6a]174 int8_t msgbuf[64];
[f40a309]175
176 if (NOT lderrsw) { /* put up new messages only */
177
178 strcpy(msgbuf, "ERROR: ");
179 strcat(msgbuf, p1);
180
181 ldwmsg(p1, p2, p3, p4, p5);
182 }
183
184 lderrsw = TRUE; /* set error state */
185}
186
187/*
188 =============================================================================
189 clrerms() -- clear an error message from the message window
190 =============================================================================
191*/
192
[0580615]193void clrerms(void)
[f40a309]194{
195 if (lderrsw) {
196
197 lderrsw = FALSE;
198 lmwclr();
199 ldswin(10);
200 }
201}
202
203/*
204 =============================================================================
205 clrlsel() -- clear library selection
206 =============================================================================
207*/
208
[0580615]209void clrlsel(void)
[f40a309]210{
211 if (lselsw) {
212
213 if (lrasw) {
214
215 lksel = -1;
216 ldpass = 0;
217 pkctrl = oldpk;
218 sliders = oldsl;
219 swpt = oldsw;
220 lcdlbls();
221 setleds();
222 fcindex();
223
224 } else {
225
[494d8ff]226 dslslot(ldslot, ldbox[1][4], ldrow);
[f40a309]227 }
228 }
229
230 fcreset();
231}
232
233/*
234 =============================================================================
235 endltyp() -- end function for virtual typewriter
236 =============================================================================
237*/
238
[0580615]239void endltyp(void)
[f40a309]240{
241 lmwclr();
242 ldswin(10);
243}
244
245/*
246 =============================================================================
247 savefc() -- save name and comment from loaded or stored file
248 =============================================================================
249*/
250
[7258c6a]251void savefc(int16_t kind)
[f40a309]252{
[7258c6a]253 int16_t fi;
[f40a309]254
255 fi = ft2lt[kind - 1];
256
257 if (kind EQ FT_ORC)
258 fi = lorchl ? LT_ORH : LT_ORL;
259
260 memcpy(loadedf[fi], ldfile, 8);
261 memcpy(loadedc[fi], ldcmnt, 37);
262}
263
264/*
265 =============================================================================
266 lcancel() -- cancel librarian selections
267 =============================================================================
268*/
269
[7258c6a]270int16_t lcancel(int16_t lct)
[f40a309]271{
[7258c6a]272 int16_t rc;
[f40a309]273
274 rc = FALSE;
275
276 if ((lct NE 0) AND lselsw) {
277
278 rc = TRUE;
279 clrlsel();
280 }
281
282 if ((lct NE 1) AND (lstrsw OR (NOT ckstor()))) {
283
284 rc = TRUE;
285 streset();
286 }
287
288 if ((lct NE 2) AND ldelsw) {
289
290 rc = TRUE;
291 ldelsw = FALSE;
[494d8ff]292 dslslot(ldslot, ldbox[1][4], ldrow);
[f40a309]293 }
294
295 return(rc);
296}
297
298/*
299 =============================================================================
300 dpy_scr() -- display score contents entry
301 =============================================================================
302*/
303
[7258c6a]304void dpy_scr(uint16_t color, int16_t ns)
[f40a309]305{
[7258c6a]306 int8_t buf[40];
307 int32_t scl;
[f40a309]308
309 if (ndisp NE 0)
310 return;
311
312 if (v_regs[5] & 0x0180)
313 vbank(0);
314
315 if (ldmap[ns] EQ -1)
316 strcpy(buf, " ");
317 else
318 sprintf(buf, "%02d", 1 + ldmap[ns]);
319
320 vcputsv(librob, 64, ldbox[1][4], ldbox[1][5], 1 + ns, 1, buf, 14);
321
322 if (-1L EQ (scl = sindex[ns].sclen))
323 strcpy(buf, "{ empty score } 0");
324 else
325 sprintf(buf, "%-16.16s %5ld", sindex[ns].scfnm, scl);
326
327 vcputsv(librob, 64, color, ldbox[1][5], 1 + ns, 4, buf, 14);
328}
329
330/*
331 =============================================================================
332 lst_scr() -- list the score contents directory
333 =============================================================================
334*/
335
[0580615]336void lst_scr(void)
[f40a309]337{
[7258c6a]338 register int16_t i;
339 uint16_t cx;
[f40a309]340
341 if (ndisp NE 0)
342 return;
343
344 point = ldpoint;
345
346 cx = exp_c(ldbox[0][5]);
347
348 if (v_regs[5] & 0x0180)
349 vbank(0);
350
351 vbfill4(librob, 128, ldbox[0][0], ldbox[0][1],
352 ldbox[0][2], ldbox[0][3], cx);
353
354 tsplot4(librob, 64, ldbox[0][4], ldbox[0][6], ldbox[0][7],
355 "No Score Name Length", 14);
356
357 lseg( 8, 13, 23, 13, LUNDRLN);
358 lseg( 32, 13, 159, 13, LUNDRLN);
359 lseg(168, 13, 215, 13, LUNDRLN);
360
361 cx = exp_c(ldbox[1][5]);
362
363 vbfill4(librob, 128, ldbox[1][0], ldbox[1][1],
364 ldbox[1][2], ldbox[1][3], cx);
365
366 for (i = 0; i < N_SCORES; i++)
367 dpy_scr(ldbox[1][4], i);
368}
369
370/*
371 =============================================================================
372 ndx_scr() -- display the table of contents for a score
373 =============================================================================
374*/
375
[7258c6a]376int16_t ndx_scr(int16_t slot)
[f40a309]377{
378 register FILE *fp;
[7258c6a]379 register int16_t i;
380 register int32_t rlen;
381 int32_t rdlen;
382 int8_t msgbuf1[64];
383 int8_t msgbuf2[64];
[f40a309]384
385 ldpass = 0;
386
387 for (i = 0; i < N_SCORES; i++) {
388
389 sindex[i].sclen = -1L;
390 memset(sindex[i].scfnm, ' ', 16);
391 }
392
393 errno = 0;
394
395 if ((FILE *)NULL EQ (fp = fopenb(slotnam(slot, FT_SCR), "r"))) {
396
397 sprintf(msgbuf2, " errno = %d", errno);
398
399 ldermsg("Couldn't open the file",
400 " for the scores", msgbuf2,
401 LD_EMCF, LD_EMCB);
402
403 clrlsel();
404 return(FAILURE);
405 }
406
407 errno = 0;
408
409 if (fseek(fp, 60L, 1)) { /* seek past header */
410
411 sprintf(msgbuf2, " errno = %d", errno);
412
413 ldermsg("Seek failure",
[7258c6a]414 (int8_t *)NULL, msgbuf2,
[f40a309]415 LD_EMCF, LD_EMCB);
416
417
418#if DEBUGIT
419 if (debugsw)
420 FILEpr(fp);
421#endif
422
423 fclose(fp);
424 postio(); /* restore LCD backlight */
425 clrlsel();
426 return(FAILURE);
427 }
428
[fa38804]429
[f40a309]430#if DEBUGIT
431 if (debugsw)
432 FILEpr(fp);
433#endif
434
435 for (i = 0; i < N_SCORES; i++) {
436
437 if (rd_ec(fp, &rdlen, 4L)) {
438
439 sprintf(msgbuf1, " of score %d", i + 1);
440 sprintf(msgbuf2, " errno = %d", errno);
441
442 ldermsg("Unable to read the length",
443 msgbuf1, msgbuf2,
444 LD_EMCF, LD_EMCB);
445
446
447#if DEBUGIT
448 if (debugsw)
449 FILEpr(fp);
450#endif
451
452 clrlsel();
453 return(FAILURE);
454 }
455
456 sindex[i].sclen = rdlen;
457
458 if (-1L NE rdlen) {
459
460 if (rd_ec(fp, sindex[i].scfnm, 16L)) {
461
462 sprintf(msgbuf1, " of score %d", i + 1);
463 sprintf(msgbuf2, " errno = %d", errno);
464
465 ldermsg("Unable to read the name",
466 msgbuf1, msgbuf2,
467 LD_EMCF, LD_EMCB);
468
469
470#if DEBUGIT
471 if (debugsw)
472 FILEpr(fp);
473#endif
474
475 clrlsel();
476 return(FAILURE);
477 }
478
479 errno = 0;
480
481 if (scskip(fp, i)) {
482
483 sprintf(msgbuf1, " score %d", i + 1);
484 sprintf(msgbuf2, " errno=%d rlen=%ld",
485 errno, rlen);
486
487 ldermsg("Unable to skip past",
488 msgbuf1, msgbuf2,
489 LD_EMCF, LD_EMCB);
490
491
492#if DEBUGIT
493 if (debugsw)
494 FILEpr(fp);
495#endif
496
497 fclose(fp);
498 postio(); /* restore LCD backlight */
499 clrlsel();
500 return(FAILURE);
501 }
502 }
503 }
504
505 fclose(fp);
506 postio(); /* restore LCD backlight */
507 ldpass = 1;
508 lst_scr();
509
[fa38804]510
[f40a309]511 point = GLCplot;
512 GLCcurs(G_ON);
513
514 if (ismode NE IS_NULL) { /* cancel inst. mode */
515
516 ismode = IS_NULL;
517 pkctrl = oldpk;
518 sliders = oldsl;
519 swpt = oldsw;
520 lcdlbls();
521 }
522
523 if (gomode NE GO_NULL) { /* cancel goto mode */
524
525 gomode = GO_NULL;
526 pkctrl = oldpk;
527 lseg(GOTO_XL, GOTO_Y, GOTO_XR, GOTO_Y, 0);
528 }
529
530 if (asmode) { /* cancel assign mode */
531
532 asmode = 0;
533 pkctrl = oldpk;
534 swpt = oldsw;
535 lseg(ASGN_XL, ASGN_Y, ASGN_XR, ASGN_Y, 0);
536 }
537
538 if ((pkctrl EQ PK_PFRM) OR (pkctrl EQ PK_NOTE))
539 oldpk = pkctrl;
540
541 if (sliders NE LS_LIBR)
542 oldsl = sliders;
543
544 oldsw = swpt;
[6dd74a9]545 swpt = &t_libr;
[f40a309]546 pkctrl = PK_LIBR;
547 sliders = LS_LIBR;
[9519422]548
[f40a309]549 lcdlbls();
550 setleds();
551
552 return(SUCCESS);
553}
554
555/*
556 =============================================================================
557 getit() -- read selected file
558 =============================================================================
559*/
560
[7258c6a]561int16_t getit(void)
[f40a309]562{
563 ldkind = ftkind(ldslot);
564
565 if (ldkind EQ -1) {
566
567 ldermsg("Unknown file type",
[7258c6a]568 (int8_t *)NULL, (int8_t *)NULL,
[f40a309]569 LD_EMCF, LD_EMCB);
570
571 clrlsel();
572 return(FAILURE);
573 }
574
575 ldbusy(" Reading file");
[fa38804]576
[f40a309]577 switch (ldkind) {
578
579 case FT_ASG:
580
581 if (get_asg())
582 return(FAILURE);
583
584 break;
585
586 case FT_ORH:
587 case FT_ORL:
588 case FT_ORC:
589
590 if (get_orc(lorchl, ldkind))
591 return(FAILURE);
592
593 break;
594
595 case FT_PAT:
596
597 if (get_pat())
598 return(FAILURE);
599
600 break;
601
602 case FT_SCR:
603
604 if (get_scr())
605 return(FAILURE);
606
607 break;
608
609 case FT_SEQ:
610
611 if (get_seq())
612 return(FAILURE);
613
614 break;
615
616 case FT_TUN:
617
618 if (get_tun())
619 return(FAILURE);
620
621 break;
622
623 case FT_WAV:
624
625 if (get_wav())
626 return(FAILURE);
627
628 break;
629
630 default:
631
632 ldermsg("ldkind bad",
[7258c6a]633 (int8_t *)NULL, (int8_t *)NULL,
[f40a309]634 LD_EMCF, LD_EMCB);
635
636 clrlsel();
637 return(FAILURE);
638 }
639
640 memcpy(ldfile, filecat[ldslot].fcname, 8);
641 memcpy(ldcmnt, filecat[ldslot].fccmnt, 37);
642 savefc(ldkind);
643
644 clrlsel();
645
646 if (lrasw) {
647
648 ldswin(0);
649 ldswin(8);
650 }
651
652 ldswin(3);
653 ldswin(5);
654 showsiz();
655 return(SUCCESS);
656}
657
658/*
659 =============================================================================
660 ldfnbox() -- librarian display box hit processor
661 =============================================================================
662*/
663
[7258c6a]664int16_t ldfnbox(int16_t n)
[f40a309]665{
[7258c6a]666 register int16_t col, i, slot, sn;
[f40a309]667
668 col = hitcx >> 3;
669
670 if (lderrsw)
671 clrerms();
672
673 switch (n) {
674
675 case 1: /* index area */
676
677 if (lcancel(0))
678 return(SUCCESS);
679
680 if (lselsw) { /* something already selected ? */
681
682 if (lrasw) { /* content mode ? */
683
684 if (ldkind EQ FT_SCR) { /* score */
685
686 sn = ldline(hitcy) - 1;
687
688 if (sindex[sn].sclen NE -1L) {
689
690 if ((1 + sn) NE ldrow) {
691
692 dpy_scr(ldbox[1][4], ldrow - 1);
693 ldrow = 1 + sn;
694 }
695
696 dpy_scr(LD_SELC, sn);
697 lksel = sn;
698
699 } else {
700
701 lksel = -1;
702 }
703
704 return(SUCCESS);
705 }
706 }
707
708 if (ldrow NE ldline(hitcy)) {
709
710 clrlsel();
711 return(SUCCESS);
712 }
713
714 return(getit());
[fa38804]715
[f40a309]716 } else { /* nothing selected yet */
717
718 if (0 NE (ldrow = ldline(hitcy))) {
719
720 if (col EQ 11) {
721
722 if (catin AND ltagged) {
723
724 slot = lin2slt(ldrow);
725
726 if (slot EQ tagslot) {
727
728 putcat();
729 ltagged = FALSE;
730 showcat();
731 }
732 }
733
734 } else {
735
736 if (-1 NE (ldslot = lin2slt(ldrow))) {
737
738 lselsw = TRUE;
739 ldswin(8);
740 ldkind = ftkind(ldslot);
741
742 for (i = 0; i < N_SCORES; i++)
743 ldmap[i] = i;
744
745 if (lrasw AND (ldkind EQ FT_SCR))
746 return(ndx_scr(ldslot));
747
[494d8ff]748 dslslot(ldslot, LD_SELC, ldrow);
[f40a309]749 return(SUCCESS);
750 }
751 }
752 }
753
754 clrlsel();
755 return(FAILURE);
756 }
[fa38804]757
[f40a309]758 case 3: /* file name field */
759
760 if (lcancel(3))
761 return(SUCCESS);
762
763 if (lmwtype NE 1) {
764
765 lmwvtyp(); /* setup for the typewriter */
766 ldswin(10); /* display the typewriter */
767
768 vtsetup(librob, vtdisp, 10, ldfile, 22, 33,
769 advlcur, bsplcur, nokey, nokey, endltyp,
770 ldbox[n][4], ldbox[n][5]);
771
772 } else {
773
774 vtyper();
775 }
776
777 return(SUCCESS);
778
779 case 5: /* comment field */
780
781 if (lcancel(3))
782 return(SUCCESS);
783
784 if (lmwtype NE 1) {
785
786 lmwvtyp(); /* setup for the typewriter */
787 ldswin(10); /* display the typewriter */
788
789 vtsetup(librob, vtdisp, 27, ldcmnt, 22, 33,
790 advlcur, bsplcur, nokey, nokey, endltyp,
791 ldbox[n][4], ldbox[n][5]);
792
793 } else {
794
795 vtyper();
796 }
797
798 return(SUCCESS);
799
800 case 6: /* "Index" */
801
802 if (lcancel(0))
803 return(SUCCESS);
804
805 clrlsel();
806 return(fcindex());
807
808 case 7: /* "Content" */
809
810 if (lselsw AND lrasw)
811 return(getit());
812
813 lrasw = NOT lrasw;
814 ldswin(7);
815 return(SUCCESS);
816
817 case 8: /* "Hi Orch" / "Lo Orch" */
818
819 lorchl = NOT lorchl;
820 ldswin(8);
821 return(SUCCESS);
822
[fa38804]823
[f40a309]824 case 9: /* "Store" */
825
826 if (lcancel(1))
827 return(SUCCESS);
828
829 if (cyval < 321) {
830
831 /* row 22: "Store", "Score", or "Hi Orch" */
832
833 if (cxval < 120) {
834
835 /* "Store" */
836
837 if (lstrsw) {
838
839 storit();
840
841 } else {
842
843 lstrsw = TRUE;
844 ldswin(9);
845 }
846
847 return(SUCCESS);
848
849 } else if ((cxval > 135) AND (cxval < 176)) {
850
851 /* "Score" */
852
853 lscrsw = NOT lscrsw;
854 ldswin(9);
855
856 if (lstrsw)
857 storit();
858
859 return(SUCCESS);
860
861 } else if (cxval > 191) {
862
863 /* "Hi Orch" */
864
865 lorchsw = NOT lorchsw;
866 ldswin(9);
867
868 if (lstrsw)
869 storit();
870
871 return(SUCCESS);
872 }
[fa38804]873
[f40a309]874 } else if ((cyval > 321) AND (cyval < 335)) {
875
876 /* row 23: "Waves", "Patch", or "Lo Orch" */
877
878 if (cxval < 120) { /* "Waves" */
879
880 lwavsw = NOT lwavsw;
881 ldswin(9);
882
883 if (lstrsw)
884 storit();
885
886 return(SUCCESS);
887
888 } else if ((cxval > 135) AND (cxval < 176)) {
889
890 /* "Patch" */
891
892 lpatsw = NOT lpatsw;
893 ldswin(9);
894
895 if (lstrsw)
896 storit();
897
898 return(SUCCESS);
899
900 } else if (cxval > 191) { /* "Lo Orch" */
901
902 lorclsw = NOT lorclsw;
903 ldswin(9);
904
905 if (lstrsw)
906 storit();
907
908 return(SUCCESS);
909 }
[fa38804]910
[f40a309]911 } else if (cyval > 335) {
912
913 /* row 24: "Assgn", "Seqnc", or "Tunings" */
914
915 if (cxval < 120) { /* "Assgn" */
916
917 lasgsw = NOT lasgsw;
918 ldswin(9);
919
920 if (lstrsw)
921 storit();
922
923 return(SUCCESS);
924
925 } else if ((cxval > 135) AND (cxval < 176)) {
926
927 /* "Seqnc" */
928
929 lseqsw = NOT lseqsw;
930 ldswin(9);
931
932 if (lstrsw)
933 storit();
934
935 return(SUCCESS);
936
937 } else if (cxval > 191) { /* "Tunings" */
938
939 ltunsw = NOT ltunsw;
940 ldswin(9);
941
942 if (lstrsw)
943 storit();
944
945 return(SUCCESS);
946 }
947 }
948
949 return(FAILURE);
950
951 default:
952
953 lcancel(3);
954 return(FAILURE);
955 }
956}
[6262b5c]957
Note: See TracBrowser for help on using the repository browser.