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

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

Removed form-feed comments.

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