source: buchla-68k/ram/sqselbx.c@ 7c0efb6

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

Fix sqselbx.c.

  • Property mode set to 100644
File size: 13.0 KB
Line 
1/*
2 =============================================================================
3 sqselbx.c -- MIDAS-VII sequence editor box selection functions
4 Version 19 -- 1988-11-18 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10#define ST_0 0x01 /* initial Action 1 or Action 2*/
11#define ST_1 0x02 /* operand type */
12#define ST_2 0x04 /* initial Action 3*/
13
14#define ST_OFF 0x00 /* cancel highlighting */
15
16int16_t action; /* current action column */
17int16_t sqdeflg; /* sequence data entry buffer filled */
18int16_t sqmenu; /* sqeuence submenu state */
19
20int8_t sqdebuf[50]; /* sequence data entry buffer */
21
22struct seqent seqbuf; /* sequence line buffer */
23
24int8_t sqhilit[][8] = { /* submenu highlight table */
25
26 /* start, width, row1, row2, row3, row4, row5, pad */
27
28 { 2, 13, ST_0|ST_2, ST_0|ST_2, ST_0|ST_2, ST_0, 0, 0},
29 { 17, 11, ST_0|ST_2, ST_0|ST_2, ST_0|ST_2, ST_0, 0, 0},
30 { 30, 11, ST_0|ST_2, ST_0|ST_2, 0, ST_0, 0, 0},
31 { 43, 8, ST_0|ST_2, ST_0|ST_2, ST_0, ST_0, ST_0, 0},
32 { 53, 8, ST_1, ST_1, ST_1, ST_1, 0, 0},
33};
34
35struct selbox sqboxes[] = { /* selection boxes */
36
37 {CTOX(1), RTOY(DATAROW), CTOX(48)-1, RTOY(1+DATAROW)-1, 0, sqfnbox}, /* current patch */
38
39 { 0, 0, 0, 0, 0, FN_NULL}
40};
41
42int8_t sqopreq[] = { /* action needs operand type flag table */
43
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1
45};
46
47int8_t nextact[] = { 24, 36, 6 }; /* next column after action entry */
48
49uint16_t sqidata[] = { /* intial data by box */
50
51 0x0000, /* " " 0 */
52 0x0000, /* "Kt 001 1 01" 1 */
53 0x0000, /* "Kc 001 1 01" 2 */
54 0x0000, /* "Kr 001 1 01" 3 */
55 0x0000, /* "If 001 1 01" 4 */
56 0x0000, /* "Trig on 01" 5 */
57 0x0000, /* "Trig off 01" 6 */
58 0x0000, /* "Trig tgl 01" 7 */
59 0x0000, /* "If trig 01" 8 */
60 0x0000, /* "Stop " 9 */
61 0x0000, /* "Jump to 000" 10 */
62 0x0000, /* "???????????" 11 */
63 0x0000, /* "If stim act" 12 */
64 SQ_VAL, /* "Set R01=00 " 13 */
65 SQ_VAL, /* "Inc R01+00 " 14 */
66 SQ_VAL, /* "If R01=00 " 15 */
67 SQ_VAL, /* "If R01<00 " 16 */
68 SQ_VAL /* "If R01>00 " 17 */
69};
70
71int8_t actcol[] = { /* action data entry column by action */
72
73 0, 3, 3, 3, 3, 9, 9, 9, 9, 5, 5, 5, 5, 10, 8, 3, 5
74};
75
76int8_t sqvcol[] = { 9, 8, 9, 9 }; /* value entry column - type order */
77
78int8_t seqvcol[] = { 8, 8, 9, 9, 9 }; /* value entry column - box order */
79
80uint16_t sqndata[] = { /* data types in box order */
81
82 SQ_VAL, SQ_REG, SQ_VLT, SQ_RND
83};
84
85/*
86 =============================================================================
87 hilitsq() -- highlight sequence submenu
88 =============================================================================
89*/
90
91void hilitsq(int8_t n)
92{
93 register int16_t chr, h, v, w;
94
95 sqmenu = n; /* set current submenu type */
96
97 for (h = 0; h < 5; h++) { /* scan the columns */
98
99 for (v = 0; v < 5; v++) { /* scan the rows */
100
101 chr = sqhilit[h][0]; /* starting character */
102
103 for (w = sqhilit[h][1]; w-- > 0; )
104 vsetcv(obj11, v + 1, chr++,
105 (sqhilit[h][v + 2] & n) ?
106 PTIATR : PTMATR, 64);
107 }
108 }
109}
110
111/*
112 =============================================================================
113 postcm() -- determine state after cursor motion
114 =============================================================================
115*/
116
117void postcm(void)
118{
119 if (inrange(stccol, 12, 22)) {
120
121 if (inrange(stccol, 12, 13))
122 hilitsq(ST_0);
123 else if ((sqopreq[seqbuf.seqact1 & SQ_MACT]) AND (stccol EQ 19))
124 hilitsq(ST_1);
125 else
126 hilitsq(ST_OFF);
127
128 return;
129
130 } else if (inrange(stccol, 24, 34)) {
131
132 if (inrange(stccol, 24, 25))
133 hilitsq(ST_0);
134 else if ((sqopreq[seqbuf.seqact2 & SQ_MACT]) AND (stccol EQ 31))
135 hilitsq(ST_1);
136 else
137 hilitsq(ST_OFF);
138
139 return;
140
141 } else if (inrange(stccol, 36, 46)) {
142
143 if (inrange(stccol, 36, 37))
144 hilitsq(ST_2);
145 else if ((sqopreq[seqbuf.seqact3 & SQ_MACT]) AND (stccol EQ 43))
146 hilitsq(ST_1);
147 else
148 hilitsq(ST_OFF);
149
150 return;
151
152 } else {
153
154 hilitsq(ST_OFF);
155 return;
156 }
157}
158
159/*
160 =============================================================================
161 movestc() -- move cursor and reset highlighting
162 =============================================================================
163*/
164
165void movestc(int16_t r, int16_t c)
166{
167 ctcpos(r, c);
168 postcm();
169}
170
171/*
172 =============================================================================
173 endssm() -- end patch submenu data entry
174 =============================================================================
175*/
176
177void endssm(int16_t row, int16_t col)
178{
179 submenu = FALSE;
180 cmtype = CT_SMTH;
181
182 mtcoff();
183 ctcon();
184 movestc(row, col);
185}
186
187/*
188 =============================================================================
189 setsqm() -- setup submenu
190 =============================================================================
191*/
192
193void setsqm(int16_t r, int16_t c)
194{
195 submenu = TRUE;
196 cmtype = CT_MENU;
197 mtcpos(r, c);
198}
199
200/*
201 =============================================================================
202 sqenter() -- enter an action
203 =============================================================================
204*/
205
206int16_t sqenter(void)
207{
208 register int16_t i, lcol;
209 register int32_t ltemp;
210 register uint16_t *ap, *dp;
211 int16_t theact, port, chan, key, val, obj, dtype;
212
213 switch (action) {
214
215 case 0:
216
217 ap = &seqbuf.seqact1;
218 dp = &seqbuf.seqdat1;
219 break;
220
221 case 1:
222
223 ap = &seqbuf.seqact2;
224 dp = &seqbuf.seqdat2;
225 break;
226
227 case 2:
228
229 ap = &seqbuf.seqact3;
230 dp = &seqbuf.seqdat3;
231 break;
232
233 default:
234
235 action = 0;
236 movestc(DATAROW, actlft[action]);
237 return(FAILURE);
238 }
239
240
241 lcol = actlft[action];
242 theact = SQ_MACT & *ap;
243
244 switch (theact) {
245
246 case SQ_TKEY: /* "Kt 001 1 01" */
247 case SQ_CKEY: /* "Kc 001 1 01" */
248 case SQ_RKEY: /* "Kr 001 1 01" */
249 case SQ_IKEY: /* "If 001 1 01" */
250
251 ltemp = 0;
252
253 for (i = lcol + 3; i < lcol + 6; i++)
254 ltemp = (ltemp * 10) + (sqdebuf[i] - '0');
255
256 if ((ltemp < 1L) OR (ltemp > 128L)) {
257
258 movestc(DATAROW, actlft[action] + 3);
259 return(FAILURE);
260 }
261
262 key = (int16_t)(ltemp - 1);
263
264 i = sqdebuf[lcol + 7];
265
266 if ((i EQ '1') OR (i EQ '2')) {
267
268 port = i - '1';
269
270 } else if (i EQ 'L') {
271
272 port = 2;
273
274 } else {
275
276 movestc(DATAROW, actlft[action] + 7);
277 return(FAILURE);
278 }
279
280 ltemp = ((sqdebuf[lcol + 9] - '0') * 10) +
281 (sqdebuf[lcol + 10] - '0');
282
283 if ((ltemp < 1L) OR (ltemp > 16L)) {
284
285 movestc(DATAROW, actlft[action] + 9);
286 return(FAILURE);
287 }
288
289 chan = (int16_t)(ltemp - 1);
290 *dp = ((uint16_t)port << 11) | ((uint16_t)chan << 7) |
291 (uint16_t)key;
292
293 break;
294
295 case SQ_STRG: /* "Trig on 01" */
296 case SQ_CTRG: /* "Trig off 01" */
297 case SQ_TTRG: /* "Trig tgl 01" */
298
299 ltemp = ((sqdebuf[lcol + 9] - '0') * 10)+
300 (sqdebuf[lcol + 10] - '0');
301
302 if ((ltemp < 1L) OR (ltemp > 16)) {
303
304 movestc(DATAROW, actlft[action] + 9);
305 return(FAILURE);
306 }
307
308 *dp = (uint16_t)(ltemp - 1);
309
310 break;
311
312 case SQ_NULL: /* " " */
313 case SQ_ITRG: /* "If trig act" */
314 case SQ_STOP: /* "Stop " */
315 case SQ_ISTM: /* "If stim act" */
316
317 break;
318
319 case SQ_JUMP: /* "Jump to 000" */
320
321 ltemp = 0;
322
323 for (i = lcol + 8; i < lcol + 11; i++)
324 ltemp = (ltemp * 10) + (sqdebuf[i] - '0');
325
326 *dp = (uint16_t)ltemp;
327
328 break;
329
330 case SQ_SREG: /* "Set R01=00 " */
331 case SQ_AREG: /* "Inc R01+00 " */
332 case SQ_IREQ: /* "If R01=00 " */
333 case SQ_IRLT: /* "If R01<00 " */
334 case SQ_IRGT: /* "If R01>00 " */
335
336 dtype = *dp & SQ_MTYP;
337
338 ltemp = ((sqdebuf[lcol + 5] - '0') * 10) +
339 (sqdebuf[lcol + 6] - '0');
340
341 if ((ltemp < 1) OR (ltemp > 16)) {
342
343 movestc(DATAROW, actlft[action] + 5);
344 return(FAILURE);
345 }
346
347 obj = (int16_t)(ltemp - 1);
348
349 switch (dtype) {
350
351 case SQ_REG: /* register */
352
353 ltemp = ((sqdebuf[lcol + 9] - '0') * 10) +
354 (sqdebuf[lcol + 10] - '0');
355
356 if ((ltemp < 1) OR (ltemp > 16)) {
357
358 movestc(DATAROW, actlft[action] + 9);
359 return(FAILURE);
360 }
361
362 val = (int16_t)(ltemp - 1);
363 break;
364
365 case SQ_VAL: /* constant value */
366
367 val = ((sqdebuf[lcol + 8] - '0') * 10) +
368 (sqdebuf[lcol + 9] - '0');
369
370 break;
371
372 case SQ_VLT: /* control voltage */
373
374 val = (sqdebuf[lcol + 9] - '0') - 1;
375 break;
376
377 case SQ_RND: /* random value */
378
379 val = sqdebuf[lcol + 9] - '0';
380 break;
381
382 default:
383
384 movestc(DATAROW, actlft[action] + 8);
385 return(FAILURE);
386 }
387
388 if (((*ap & SQ_MACT) EQ SQ_AREG) AND
389 (sqdebuf[lcol + 7] EQ '-'))
390 val |= 0x1000;
391
392 *ap = (*ap & SQ_MACT) | ((uint16_t)obj << 8);
393 *dp = (*dp & SQ_MTYP) | (uint16_t)val;
394
395 break;
396
397 default:
398
399 movestc(DATAROW, actlft[action]);
400 return(FAILURE);
401 }
402
403 memcpyw(&seqtab[curslin], &seqbuf, NSEQW);
404 dsqlin(sqdebuf, curslin);
405 sqdeflg = TRUE;
406 dcursq();
407 movestc(DATAROW, nextact[action]);
408 return(SUCCESS);
409}
410
411/*
412 =============================================================================
413 sqfnbox() -- sequence display box hit processor
414 =============================================================================
415*/
416
417int16_t sqfnbox(int16_t n)
418{
419 int16_t act, vtype;
420 register int16_t box;
421 register int16_t i;
422 register int32_t ltemp;
423
424 (void)n;
425
426 if (NOT submenu) { /* SEQUENCE DATA ENTRY LINE */
427
428 if (inrange(stccol, 2, 4)) { /* Line */
429
430 ltemp = 0;
431
432 for (i = 2; i < 5; i++)
433 ltemp = (ltemp * 10) + (sqdebuf[i] - '0');
434
435 curslin = (int16_t)ltemp;
436 sqdeflg = FALSE;
437 dstw();
438 movestc(DATAROW, 2);
439 return(SUCCESS);
440
441 } else if (inrange(stccol, 6, 10)) { /* Time */
442
443 ltemp = 0;
444
445 for (i = 6; i < 8; i++)
446 ltemp = (ltemp * 10) + (sqdebuf[i] - '0');
447
448 for (i = 9; i < 11; i++)
449 ltemp = (ltemp * 10) + (sqdebuf[i] - '0');
450
451 seqtab[curslin].seqtime = (uint16_t)ltemp;
452 seqbuf.seqtime = (uint16_t)ltemp;
453 dsqlin(sqdebuf, curslin);
454 sqdeflg = TRUE;
455 dcursq();
456 movestc(DATAROW, 12);
457 return(SUCCESS);
458
459 } else if (inrange(stccol, 12, 22)) { /* Action 1 */
460
461 action = 0;
462
463 if (inrange(stccol, 12, 13)) {
464
465 setsqm(19, 2);
466 return(SUCCESS);
467
468 } else if ((sqopreq[seqbuf.seqact1 & SQ_MACT]) AND
469 (stccol EQ 19)) {
470
471 setsqm(19, 53);
472 return(SUCCESS);
473
474 } else {
475
476 return(sqenter());
477 }
478
479 } else if (inrange(stccol, 24, 34)) { /* Action 2 */
480
481 action = 1;
482
483 if (inrange(stccol, 24, 25)) {
484
485 setsqm(19, 2);
486 return(SUCCESS);
487
488 } else if ((sqopreq[seqbuf.seqact2 & SQ_MACT]) AND
489 (stccol EQ 31)) {
490
491 setsqm(19, 53);
492 return(SUCCESS);
493
494 } else {
495
496 return(sqenter());
497 }
498
499 } else if (inrange(stccol, 36, 46)) { /* Action 3 */
500
501 action = 2;
502
503 if (inrange(stccol, 36, 37)) {
504
505 setsqm(19, 2);
506 return(SUCCESS);
507
508 } else if ((sqopreq[seqbuf.seqact3 & SQ_MACT]) AND
509 (stccol EQ 43)) {
510
511 setsqm(19, 53);
512 return(SUCCESS);
513
514 } else {
515
516 return(sqenter());
517 }
518
519 } else
520 return(FAILURE);
521
522 } else { /* SUBMENU SELECTION */
523
524 /* determine the "box" we're pointing at */
525
526 if (inrange(vtccol, 2, 14))
527 box = vtcrow - 18;
528 else if (inrange(vtccol, 17, 27))
529 box = vtcrow - 14;
530 else if (inrange(vtccol, 30, 40))
531 box = vtcrow - 10;
532 else if (inrange(vtccol, 43, 50))
533 box = vtcrow - 6;
534 else if (inrange(vtccol, 53, 60))
535 box = vtcrow - 1;
536 else
537 return(FAILURE);
538
539 switch (sqmenu) { /* switch on submenu type */
540
541 case ST_0: /* Action 1 or Action 2 type */
542 case ST_2: /* Action 3 type */
543
544 if (inrange(box, 18, 21))
545 return(FAILURE);
546
547 switch (action) {
548
549 case 0: /* action 1 */
550
551 act = SQ_MACT & (seqbuf.seqact1 = sqatype[box]);
552 vtype = 0x000F & ((seqbuf.seqdat1 = sqidata[box]) >> 8);
553 break;
554
555 case 1: /* action 2 */
556
557 act = SQ_MACT & (seqbuf.seqact2 = sqatype[box]);
558 vtype = 0x000F & ((seqbuf.seqdat2 = sqidata[box]) >> 8);
559 break;
560
561 case 2: /* action 3 */
562
563 if ((box EQ 4) OR (box EQ 8) OR (box EQ 12) OR
564 inrange(box, 15, 17))
565 return(FAILURE);
566
567 act = SQ_MACT & (seqbuf.seqact3 = sqatype[box]);
568 vtype = 0x000F & ((seqbuf.seqdat3 = sqidata[box]) >> 8);
569 break;
570 }
571
572 memcpyw(&seqtab[curslin], &seqbuf, NSEQW);
573 dsqlin(sqdebuf, curslin);
574 sqdeflg = TRUE;
575 dcursq();
576
577 if (sqopreq[act])
578 endssm(stcrow, actlft[action] + sqvcol[vtype]);
579 else if ((act EQ SQ_ISTM) OR (act EQ SQ_STOP))
580 endssm(stcrow, nextact[action]);
581 else
582 endssm(stcrow, actlft[action] + actcol[act]);
583
584 return(SUCCESS);
585
586 case ST_1: /* operand type */
587
588 if (NOT inrange(box, 18, 21))
589 return(FAILURE);
590
591 switch (action) {
592
593 case 0: /* action 1 */
594
595 if (NOT sqopreq[act = SQ_MACT & seqbuf.seqact1])
596 return(FAILURE);
597
598 seqbuf.seqdat1 = (seqbuf.seqdat1 & SQ_MFLG) | sqndata[box - 18];
599 break;
600
601 case 1: /* action 2 */
602
603 if (NOT sqopreq[act = SQ_MACT & seqbuf.seqact2])
604 return(FAILURE);
605
606 seqbuf.seqdat2 = (seqbuf.seqdat2 & SQ_MFLG) | sqndata[box - 18];
607 break;
608
609 case 2: /* action 3 */
610
611 if (NOT sqopreq[act = SQ_MACT & seqbuf.seqact3])
612 return(FAILURE);
613
614 seqbuf.seqdat3 = (seqbuf.seqdat3 & SQ_MFLG) | sqndata[box - 18];
615 break;
616 }
617
618 break;
619
620 default: /* -BOGUS- */
621
622 endssm(stcrow, stccol);
623 return(FAILURE);
624 }
625
626 memcpyw(&seqtab[curslin], &seqbuf, NSEQW);
627 dsqlin(sqdebuf, curslin);
628 sqdeflg = TRUE;
629 dcursq();
630 endssm(stcrow, actlft[action] + seqvcol[box - 18]);
631 return(SUCCESS);
632 }
633
634 return(FAILURE);
635}
636
Note: See TracBrowser for help on using the repository browser.