source: buchla-68k/orig/RAM/MSL.C@ 0170798

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

Imported original source code.

  • Property mode set to 100755
File size: 16.4 KB
Line 
1/*
2 =============================================================================
3 msl.c -- midas main scan loop
4 Version 102 -- 1989-11-14 -- D.N. Lynx Crowe
5
6 List with pr -e4 option to expand tabs to 4 spaces instead of 8.
7 =============================================================================
8*/
9
10#define DEBUGIT 0 /* enable debug code */
11
12#define OLDTIME 0 /* use old tempo time calculations */
13
14#include "stddefs.h"
15#include "biosdefs.h"
16#include "graphdef.h"
17#include "glcfns.h"
18#include "glcdefs.h"
19#include "vsdd.h"
20#include "vsddsw.h"
21#include "vsddvars.h"
22#include "hwdefs.h"
23#include "memory.h"
24#include "cmeta.h"
25#include "fields.h"
26#include "fpu.h"
27#include "macros.h"
28#include "patch.h"
29#include "smdefs.h"
30#include "sclock.h"
31#include "scwheel.h"
32#include "slice.h"
33#include "timers.h"
34#include "wordq.h"
35
36#include "midas.h"
37#include "instdsp.h"
38#include "score.h"
39#include "scdsp.h"
40#include "scfns.h"
41#include "wsdsp.h"
42#include "asgdsp.h"
43
44#define LCL_PRT 3 /* 1-origin local keyboard port number */
45
46#if DEBUGIT
47extern short debugsw;
48
49short debugms = 1;
50#endif
51
52/*
53
54*/
55
56/* variables defined elsewhere */
57
58extern short (*cx_key)();
59extern short (*cy_key)();
60extern short (*d_key)();
61extern short (*e_key)();
62extern short (*m_key)();
63extern short (*x_key)();
64
65extern PFS (*swpt)[];
66
67extern short aflag;
68extern short amplval;
69extern short ancmsw;
70extern short angroup;
71extern short asig;
72extern short astat;
73extern short aval;
74extern short clkctl;
75extern short clkrun;
76extern short ctrsw;
77extern short cxrate;
78extern short cxval;
79extern short cyrate;
80extern short cyval;
81extern short dsp_ok;
82extern short editss;
83extern short editsw;
84extern short lampsw;
85extern short ndisp;
86extern short nxtflag;
87extern short pchsw;
88extern short recsw;
89extern short runit;
90extern short swback;
91extern short swctrl;
92extern short swdelta;
93extern short swdir;
94extern short swfiin;
95extern short swflag;
96extern short swlast;
97extern short swndx;
98extern short swstop;
99extern short swthr;
100extern short swtime;
101extern short swwait;
102extern short sd;
103extern short se;
104extern short stcrow;
105extern short stccol;
106extern short tglclk;
107extern short tglpch;
108extern short timemlt;
109extern short tmpomlt;
110extern short tmpoval;
111extern short tuneval;
112extern short vtpcol;
113extern short vtprow;
114
115/*
116
117*/
118
119extern unsigned short *obj8;
120
121extern long afi;
122extern long lcdtime;
123extern long swcount;
124extern long swrate;
125extern long swrmin;
126extern long swtemp;
127
128extern short grpmode[];
129extern short grpstat[];
130extern short prstab[];
131extern short simled[];
132extern short swfifo[NSWFIFO];
133extern short tmultab[];
134extern short vce2trg[];
135extern short veltab[];
136
137extern char trgtab[];
138
139extern short grp2prt[][2];
140extern short sigtab[][2];
141extern short varmode[][16];
142
143extern struct gdsel *gdstbc[];
144
145extern struct wordq ptefifo;
146
147unsigned short fifoval;
148
149/*
150
151*/
152
153/*
154 =============================================================================
155 clk_ped() -- process clock on/off toggle pedal
156 =============================================================================
157*/
158
159clk_ped(stat)
160short stat;
161{
162 if (stat)
163 tglclk = TRUE;
164}
165
166/*
167 =============================================================================
168 pch_ped() -- process punch in/out toggle pedal
169 =============================================================================
170*/
171
172pch_ped(stat)
173short stat;
174{
175 if (stat AND pchsw)
176 tglpch = TRUE;
177}
178
179/*
180
181*/
182
183/*
184 =============================================================================
185 msl() -- MIDAS main scan loop
186 =============================================================================
187*/
188
189msl()
190{
191 register char *ioadr;
192 register unsigned *fpu;
193 register struct s_entry *ep;
194 register short i, ti, val;
195 register long rt;
196 unsigned short chan, crel, oldsr, port, trg, trig, vel;
197 short cxprev, cyprev, esi, newsig, oldclk, oldrec;
198 long fctemp;
199
200#if DEBUGIT
201 if (debugsw AND debugms)
202 printf("msl(): ENTRY ndisp=%d\n", ndisp);
203#endif
204
205 runit = TRUE; /* set run state */
206
207 while (runit) {
208
209 dsp_ok = TRUE; /* set display-OK flag for this pass */
210
211 ioadr = &io_ser + 2L; /* get edit switch status */
212 esi = *ioadr & 0x0008;
213
214 if (editss NE esi) { /* check for edit switch change */
215
216 editss = esi;
217
218 if (editss) /* toggle edit state if it went hi */
219 editsw = NOT editsw;
220 }
221
222 if (editsw) /* update edit LED */
223 io_leds = 0x9E;
224 else
225 io_leds = 0x1E;
226
227 if ((NOT lampsw) AND lcdtime) {
228
229 if (0 EQ --lcdtime)
230 io_leds = 0x1F; /* turn off the LCD backlight */
231 }
232
233 msm(); /* scan the MIDI ports */
234/*
235
236*/
237
238 if (tglclk) { /* check for clock on/off toggle */
239
240 oldsr = setsr(0x2700); /* disable interrupts */
241 tglclk = FALSE; /* cancel toggle flag */
242 setsr(oldsr); /* enable interrupts */
243
244 clkset(NOT clkrun); /* toggle clock mode */
245 dclkmd(); /* update display */
246 }
247
248 if (tglpch) { /* check for punch in/out toggle */
249
250 oldsr = setsr(0x2700); /* disable interrupts */
251 tglpch = FALSE; /* cancel toggle flag */
252 setsr(oldsr); /* enable interrupts */
253
254 if ((ndisp EQ 2) AND (v_regs[5] & 0x0180))
255 vbank(0);
256
257 for (i = 0; i < 12; i++) { /* scan the groups */
258
259 if (grpmode[i] EQ 1) { /* stdby -> rec */
260
261 grpmode[i] = 2;
262
263 if (ndisp EQ 2)
264 vputc(obj8, 2, 6 + (i * 5),
265 '*', simled[grpmode[i]]);
266
267 } else if (grpmode[i] EQ 2) { /* rec -> play */
268
269 grpmode[i] = 0;
270
271 if (ndisp EQ 2)
272 vputc(obj8, 2, 6 + (i * 5),
273 '*', simled[grpmode[i]]);
274 }
275 }
276 }
277
278/*
279
280*/
281 /* process stimulli from the patch stimulus fifo */
282
283 if (getwq(&ptefifo, &fifoval) GE 0) {
284
285 crel = 0x8000 & fifoval;
286
287 trg = TRG_MASK & fifoval;
288 port = 0x0003 & (fifoval >> 11);
289 chan = 0x000F & (fifoval >> 7);
290 trig = 0x007F & fifoval;
291
292 veltab[trg] = vel = SM_SCALE(64);
293 prstab[trg] = 0;
294
295 if (crel) { /* release */
296
297 trgtab[trg] &= ~M_KSTATE;
298
299 for (i = 0; i < 12; i++) {
300
301 if (vce2trg[i] EQ trg) {
302
303 vce2trg[i] = -1;
304 procpfl(trg);
305
306 }
307 }
308
309 stmproc(fifoval); /* do it as a patch stimulus */
310
311 } else { /* closure */
312
313 trgtab[trg] |= M_KSTATE;
314
315 stmproc(fifoval); /* do it as a patch stimulus */
316
317 for (i = 0; i < 12; i++)
318 if ((grp2prt[i][0] EQ 1 + port) AND
319 (grp2prt[i][1] EQ 1 + chan))
320 asgvce(i, port, chan, trig, vel);
321 }
322 }
323/*
324
325*/
326 if (-1L NE (afi = XBIOS(X_ANALOG))) { /* check panel inputs */
327
328 asig = (afi >> 8) & 0x007F; /* signal number */
329 astat = (afi >> 7) & 0x0001; /* status */
330 aval = afi & 0x007F; /* value */
331
332 if (asig) { /* active signal */
333
334 aflag = TRUE;
335 newsig = astat AND (NOT sigtab[asig][1]);
336
337 sigtab[asig][0] = aval;
338 sigtab[asig][1] = astat;
339
340 } else { /* all keys up */
341
342 aflag = FALSE;
343 newsig = FALSE;
344
345 for (i = 0; i < 128; i++)
346 sigtab[i][1] = 0;
347 }
348
349/*
350
351*/
352 if (aflag) { /* anything changed ? */
353
354 if ((asig GE 1) AND (asig LE 24)) {
355
356 /* local keyboard performance key */
357
358 localkb(asig);
359
360 } else if ((asig GE 25) AND (asig LE 38)) {
361
362 if (astat)
363 lcd_on();
364
365 if (NOT newsig)
366 doslide();
367
368 } else if ((asig GE 39) AND (asig LE 52)) {
369
370 if (astat)
371 lcd_on();
372
373 (*(*swpt)[asig - 39])(astat, (asig - 39));
374
375 } else if ((asig GE 60) AND (asig LE 69)) {
376
377 (*d_key)(asig - 60);
378
379/*
380
381*/
382 } else switch (asig) {
383
384 case 53: /* tablet x */
385
386 val = SM_SCALE(aval);
387
388 for (i = 0; i < 12; i++) {
389
390 if (grp2prt[i][0] EQ LCL_PRT) {
391
392 if (newsv(i, SM_HTPW, val)) {
393
394 if (recsw AND grpstat[i] AND
395 (2 EQ (ancmsw ? varmode[0][i] : grpmode[i]))) {
396
397 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
398
399 ep->e_time = t_cur;
400 ep->e_type = EV_ANVL;
401 ep->e_data1 = i;
402 ep->e_dn = (struct s_entry *)((long)val << 16);
403 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
404 ctrsw = TRUE;
405 se_disp(ep, D_FWD, gdstbc, 1);
406 ctrsw = FALSE;
407 }
408
409 } else if ((angroup - 1) EQ i) {
410
411 dsanval(0);
412 }
413 }
414 }
415 }
416
417 break;
418/*
419
420*/
421 case 54: /* tablet y */
422
423 val = SM_SCALE(aval);
424
425 for (i = 0; i < 12; i++) {
426
427 if (grp2prt[i][0] EQ LCL_PRT) {
428
429 if (newsv(i, SM_VTMW, val)) {
430
431 if (recsw AND grpstat[i] AND
432 (2 EQ (ancmsw ? varmode[1][i] : grpmode[i]))) {
433
434 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
435
436 ep->e_time = t_cur;
437 ep->e_type = EV_ANVL;
438 ep->e_data1 = 0x0010 | i;
439 ep->e_dn = (struct s_entry *)((long)val << 16);
440 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
441 ctrsw = TRUE;
442 se_disp(ep, D_FWD, gdstbc, 1);
443 ctrsw = FALSE;
444 }
445
446 } else if ((angroup - 1) EQ i) {
447
448 dsanval(1);
449 }
450 }
451 }
452 }
453
454 break;
455
456 case 55: /* cursor x */
457
458 (*cx_key)(); break;
459
460 case 56: /* cursor y */
461
462 (*cy_key)(); break;
463/*
464
465*/
466 case 58: /* longpot r */
467
468 val = SM_SCALE(aval);
469
470 for (i = 0; i < 12; i++) {
471
472 if (grp2prt[i][0] EQ LCL_PRT) {
473
474 if (newsv(i, SM_LPBR, val)) {
475
476 if (recsw AND grpstat[i] AND
477 (2 EQ (ancmsw ? varmode[2][i] : grpmode[i]))) {
478
479 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
480
481 ep->e_time = t_cur;
482 ep->e_type = EV_ANVL;
483 ep->e_data1 = 0x0020 | i;
484 ep->e_dn = (struct s_entry *)((long)val << 16);
485 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
486 ctrsw = TRUE;
487 se_disp(ep, D_FWD, gdstbc, 1);
488 ctrsw = FALSE;
489 }
490
491 } else if ((angroup - 1) EQ i) {
492
493 dsanval(2);
494 }
495 }
496 }
497 }
498
499 break;
500
501/*
502
503*/
504 case 59: /* scroll wheel */
505
506 wheel(); break;
507
508 case 70: /* X key */
509
510 (*x_key)(); break;
511
512 case 71: /* E key */
513
514#if DEBUGIT
515 if (debugsw AND debugms)
516 printf("msl(): -> e_key ($%lX) astat=%d ndisp=%d\n",
517 e_key, astat, ndisp);
518#endif
519 (*e_key)();
520
521#if DEBUGIT
522 if (debugsw AND debugms)
523 printf("msl(): <- e_key ($%lX) astat=%d ndisp=%d runit=%d\n",
524 e_key, astat, ndisp, runit);
525#endif
526
527 break;
528
529 case 72: /* M key */
530
531 (*m_key)(); break;
532
533 case 73: /* Tempo */
534
535 if (aval > 50) /* dead band */
536 if (aval < 53)
537 aval = 50;
538 else
539 aval -= 2;
540
541 tmpomlt = aval > 100 ? 100 : aval;
542#if OLDTIME
543 ti = ( (tmpomlt + 50) * tmpoval) / 100;
544 ti = (short)( (192000L / ti) - 1);
545#else
546 ti = (tmpomlt + 50) * tmpoval;
547 ti = (short)( (19200000L / ti) - 1);
548#endif
549 TIME_T2H = ti >> 8;
550 TIME_T2L = ti & 0x00FF;
551
552 if (tmpomlt EQ 50) { /* 0 */
553
554 io_leds = 0x18; /* green off */
555 io_leds = 0x19; /* red off */
556
557 } else if (tmpomlt GT 50) { /* hi */
558
559 io_leds = 0x98; /* green on */
560 io_leds = 0x19; /* red off */
561
562 } else { /* lo */
563
564 io_leds = 0x18; /* green off */
565 io_leds = 0x99; /* red on */
566 }
567
568 break;
569/*
570
571*/
572 case 74: /* Time */
573
574 if (aval > 50) /* dead band */
575 if (aval < 53)
576 aval = 50;
577 else
578 aval -= 2;
579
580 ti = aval > 100 ? 100 : aval;
581 timemlt = tmultab[ti];
582
583 if (ti EQ 50) { /* 0 */
584
585 io_leds = 0x1A; /* green off */
586 io_leds = 0x1B; /* red off */
587
588 } else if (ti GT 50) { /* hi */
589
590 io_leds = 0x9A; /* green on */
591 io_leds = 0x1B; /* red off */
592
593 } else { /* lo */
594
595 io_leds = 0x1A; /* green off */
596 io_leds = 0x9B; /* red on */
597 }
598
599 break;
600
601/*
602
603*/
604 case 75: /* Tuning */
605
606 if (aval > 50) /* dead band */
607 if (aval < 53)
608 aval = 50;
609 else
610 aval -= 2;
611
612 i = (aval > 100) ? 100 : aval;
613 tuneval = (i - 50) << 2;
614 settune();
615
616 if (i EQ 50) {
617
618 io_leds = 0x1C; /* green off */
619 io_leds = 0x1D; /* red off */
620
621 } else if (i GT 50) {
622
623 io_leds = 0x9C; /* green on */
624 io_leds = 0x1D; /* red off */
625
626 } else {
627
628 io_leds = 0x1C; /* green off */
629 io_leds = 0x9D; /* red on */
630 }
631
632 break;
633/*
634
635*/
636 case 76: /* amplitude */
637
638 aval += aval >> 2;
639
640 if (aval > 127)
641 aval = 127;
642
643 amplval = (aval << 9) ^ 0x8000;
644 sendval(0, 0, amplval);
645 break;
646
647 case 77: /* pedal 1 */
648
649 val = SM_SCALE(aval);
650
651 for (i = 0; i < 12; i++) {
652
653 if (grp2prt[i][0] EQ LCL_PRT) {
654
655 if (newsv(i, SM_PED1, val)) {
656
657 if (recsw AND grpstat[i] AND
658 (2 EQ (ancmsw ? varmode[4][i] : grpmode[i]))) {
659
660 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
661
662 ep->e_time = t_cur;
663 ep->e_type = EV_ANVL;
664 ep->e_data1 = 0x0040 | i;
665 ep->e_dn = (struct s_entry *)((long)val << 16);
666 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
667 ctrsw = TRUE;
668 se_disp(ep, D_FWD, gdstbc, 1);
669 ctrsw = FALSE;
670 }
671
672 } else if ((angroup - 1) EQ i) {
673
674 dsanval(4);
675 }
676 }
677 }
678 }
679
680 break;
681
682/*
683
684*/
685 case 79: /* cv 1 */
686
687 val = SM_SCALE(aval);
688
689 for (i = 0; i < 12; i++) {
690
691 if (grp2prt[i][0] EQ LCL_PRT) {
692
693 if (newsv(i, SM_CTL1, val)) {
694
695 if (recsw AND grpstat[i] AND
696 (2 EQ (ancmsw ? varmode[3][i] : grpmode[i]))) {
697
698 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
699
700 ep->e_time = t_cur;
701 ep->e_type = EV_ANVL;
702 ep->e_data1 = 0x0030 | i;
703 ep->e_dn = (struct s_entry *)((long)val << 16);
704 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
705 ctrsw = TRUE;
706 se_disp(ep, D_FWD, gdstbc, 1);
707 ctrsw = FALSE;
708 }
709
710 } if ((angroup - 1)EQ i) {
711
712 dsanval(3);
713 }
714 }
715 }
716 }
717
718 break;
719
720 }
721 }
722 }
723/*
724
725*/
726
727#if DEBUGIT
728 if (debugsw AND debugms AND (NOT runit))
729 printf("msl(): end of asig cases -- dsp_ok = %d\n", dsp_ok);
730#endif
731
732 /* memory allocation changed ? */
733
734 if ((ndisp EQ 2) AND se_chg AND dsp_ok) {
735
736 dsmem(); /* display memory remaining */
737 se_chg = FALSE;
738 }
739
740 nxtflag = FALSE; /* clear 'next score' flag */
741 fctemp = fc_val; /* sample the frame clock */
742
743 if (t_cur NE fctemp) { /* see if frame clock changed */
744
745 if (t_cur LT fctemp) { /* clock incremented */
746
747 if (se EQ D_BAK) /* change direction ? */
748 chgsef();
749
750 sc_trek(fctemp); /* track frame clock */
751
752 } else { /* clock decremented */
753
754 if (se EQ D_FWD) /* change direction ? */
755 chgseb();
756
757 sc_trek(fctemp); /* track frame clock */
758 }
759
760 /* handle display update if there's time for it */
761
762 } else if (dsp_ok AND (t_ctr NE t_cur)) {
763
764 if (t_ctr LT t_cur) { /* clock incremented */
765
766 if (sd EQ D_BAK) /* change direction ? */
767 chgsdf();
768
769 sc_trak(t_ctr + 1); /* track frame clock */
770
771 } else { /* clock decremented */
772
773 if (sd EQ D_FWD) /* change direction ? */
774 chgsdb();
775
776 sc_trak(t_ctr - 1); /* track frame clock */
777 }
778 }
779/*
780
781*/
782#if DEBUGIT
783 if (debugsw AND debugms AND (NOT runit))
784 printf("msl(): end of clock processing -- dsp_ok = %d\n",
785 dsp_ok);
786#endif
787
788 /* handle 'next score' flag */
789
790 if (nxtflag AND (sd EQ D_FWD)) { /* switch scores ? */
791
792 oldrec = recsw;
793 oldclk = clkrun;
794
795 ti = curscor + 1;
796
797 if (ti GE N_SCORES)
798 ti = 0;
799
800 for (i = 0; i < N_SCORES; i++) {
801
802 if (E_NULL NE scores[ti]) {
803
804 selscor(ti);
805 break;
806 }
807
808 if (++ti GE N_SCORES)
809 ti = 0;
810 }
811
812 clkset(oldclk); /* restore clock mode */
813 dsclk();
814 recsw = oldrec; /* restore record/play mode */
815 dsrpmod();
816 nxtflag = FALSE; /* clear 'next score' flag */
817 }
818
819#if DEBUGIT
820 if (debugsw AND debugms AND (NOT runit))
821 printf("msl(): curproc\n");
822#endif
823
824 curproc(); /* process wheel and ball */
825
826#if DEBUGIT
827 if (debugsw AND debugms AND (NOT runit))
828 printf("msl(): seqproc\n");
829#endif
830
831 seqproc(); /* process sequences */
832 }
833
834#if DEBUGIT
835 if (debugsw AND debugms)
836 printf("msl(): EXIT ndisp=%d\n", ndisp);
837#endif
838}
Note: See TracBrowser for help on using the repository browser.