source: buchla-68k/ram/msl.c@ b28a12e

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

Zero redundant declarations.

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