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

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

More volatile hardware accesses.

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