source: buchla-68k/orig/RAM/SQEXEC.C@ 06ccda2

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

Imported original source code.

  • Property mode set to 100755
File size: 7.9 KB
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 sqexec.c -- MIDAS-VII sequence action execution code
4 Version 12 -- 1988-12-13 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGSX 0
9#define DEBUGSP 0
10
11#define UPD_LINE 1
12
13#include "stddefs.h"
14#include "hwdefs.h"
15#include "graphdef.h"
16#include "vsdd.h"
17#include "wordq.h"
18#include "patch.h"
19#include "timers.h"
20
21#include "midas.h"
22#include "ptdisp.h"
23
24#if (DEBUGSP|DEBUGSX)
25extern short debugsw;
26#endif
27
28#if DEBUGSP
29short debugsp = 1;
30#endif
31
32#if DEBUGSX
33short debugsx = 1;
34#endif
35
36extern unsigned short setsr();
37extern long rand24();
38
39extern char trgtab[];
40
41extern short curslin;
42extern short dsp_ok;
43extern short ndisp;
44
45extern unsigned short seqdupd;
46
47extern unsigned short *obj10;
48
49extern unsigned short cg3[];
50
51extern struct wordq ptefifo;
52
53short seqdspn;
54
55short rtab[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F,
56 0x003F, 0x003F, 0x003F };
57
58/*
59
60*/
61
62/*
63 =============================================================================
64 evaltv() -- evaluate a typed value
65 =============================================================================
66*/
67
68unsigned short
69evaltv(dat)
70register unsigned short dat;
71{
72 switch (SQ_MTYP & dat) {
73
74 case SQ_REG: /* register contents */
75
76 return(sregval[SQ_MVAL & dat]);
77
78 case SQ_VAL: /* constant value */
79
80 return(SQ_MVAL & dat);
81
82 case SQ_VLT: /* voltage input */
83
84 return(0);
85
86 case SQ_RND: /* random number */
87
88 return((short)rand24() & rtab[SQ_MVAL & dat]);
89
90 default: /* something weird got in here ... */
91
92 return(0);
93 }
94}
95
96/*
97
98*/
99
100/*
101 =============================================================================
102 dosqact() -- do a sequence action
103 =============================================================================
104*/
105
106short
107dosqact(seq, act, dat)
108unsigned short seq;
109register unsigned short act, dat;
110{
111 register unsigned short obj, val;
112 register short sv;
113
114 obj = (SQ_MOBJ & act) >> 8;
115 val = SQ_MVAL & dat;
116
117 switch (SQ_MACT & act) {
118
119 case SQ_NULL: /* null action */
120
121 return(0);
122
123 case SQ_CKEY: /* Key closure */
124
125 putwq(&ptefifo, dat & TRG_MASK);
126 return(0);
127
128 case SQ_RKEY: /* Key release */
129
130 putwq(&ptefifo, dat | 0x8000);
131 return(0);
132
133 case SQ_TKEY: /* Key transient */
134
135 putwq(&ptefifo, dat & TRG_MASK); /* closure */
136 putwq(&ptefifo, dat | 0x8000); /* release */
137 return(0);
138
139 case SQ_IKEY: /* If key active */
140
141 if (trgtab[TRG_MASK & dat])
142 return(0);
143 else
144 return(1);
145/*
146
147*/
148 case SQ_STRG: /* Trigger on */
149
150 trstate[val] = 1;
151 putwq(&ptefifo, (0x1100 | val));
152 seqdupd |= (1 << val);
153 return(0);
154
155 case SQ_CTRG: /* Trigger off */
156
157 trstate[val] = 0;
158 seqdupd |= (1 << val);
159 return(0);
160
161 case SQ_TTRG: /* Trigger toggle */
162
163 trstate[val] = trstate[val] ? 0 : 1;
164
165 if (trstate[val])
166 putwq(&ptefifo, (0x1100 | val));
167
168 seqdupd |= (1 << val);
169 return(0);
170
171 case SQ_ITRG: /* If trigger active */
172
173 return(trstate[val] ? 0 : 1);
174/*
175
176*/
177 case SQ_SREG: /* Set register */
178
179 sregval[obj] = evaltv(dat);
180 seqdupd |= (1 << obj);
181 return(0);
182
183 case SQ_AREG: /* Increment register */
184
185 if (dat & SQ_MFLG) {
186
187 sv = sregval[obj] - evaltv(dat);
188
189 if (sv < 0)
190 sv = 0;
191
192 sregval[obj] = sv;
193
194 } else {
195
196 sv = sregval[obj] + evaltv(dat);
197
198 if (sv > 99)
199 sv = 99;
200
201 sregval[obj] = sv;
202
203 }
204
205 seqdupd |= (1 << obj);
206 return(0);
207
208 case SQ_IREQ: /* If register = */
209
210 val = evaltv(dat);
211
212 if (sregval[obj] EQ val)
213 return(0);
214 else
215 return(1);
216
217 case SQ_IRLT: /* If register < */
218
219 val = evaltv(dat);
220
221 if (sregval[obj] < val)
222 return(0);
223 else
224 return(1);
225
226 case SQ_IRGT: /* If register > */
227
228 val = evaltv(dat);
229
230 if (sregval[obj] > val)
231 return(0);
232 else
233 return(1);
234/*
235
236*/
237 case SQ_ISTM: /* If stimulus active */
238
239 if (trgtab[TRG_MASK & seqstim[seq]])
240 return(0);
241 else
242 return(1);
243
244 case SQ_JUMP: /* Jump to sequence line */
245
246 seqline[seq] = dat;
247 seqtime[seq] = seqtab[dat].seqtime;
248 seqflag[seq] |= SQF_CLK;
249
250 seqdupd |= (1 << seq);
251 return(-1);
252
253
254 case SQ_STOP: /* Stop sequence */
255 default:
256
257 seqflag[seq] = 0;
258 seqtime[seq] = 0;
259
260 seqdupd |= (1 << seq);
261 return(-1);
262
263 }
264}
265
266/*
267
268*/
269
270/*
271 =============================================================================
272 sqexec() -- execute a line for a sequence
273 =============================================================================
274*/
275
276sqexec(seq)
277register unsigned short seq;
278{
279 register unsigned short act, dat, line;
280 register struct seqent *sp;
281 register short rc;
282
283 line = seqline[seq];
284 sp = &seqtab[line];
285
286 act = sp->seqact1; /* do Action 1 */
287 dat = sp->seqdat1;
288
289 rc = dosqact(seq, act, dat);
290
291#if DEBUGSX
292 if (debugsw AND debugsx)
293 printf("sqexec(%02u): Line %03u Act 1 $%04.4X $%04.4X $%04.4X %d\n",
294 seq, line, act, dat, seqflag[seq], rc);
295#endif
296
297 if (rc EQ 1) /* skip action 2 */
298 goto act3;
299 else if (rc EQ -1) /* jump or stop */
300 return;
301
302 act = sp->seqact2; /* do Action 2 */
303 dat = sp->seqdat2;
304
305 rc = dosqact(seq, act, dat);
306
307#if DEBUGSX
308 if (debugsw AND debugsx)
309 printf("sqexec(%02u): Line %03u Act 2 $%04.4X $%04.4X $%04.4X %d\n",
310 seq, line, act, dat, seqflag[seq], rc);
311#endif
312
313 if (rc EQ 1) /* skip action 3 */
314 goto nxtline;
315 else if (rc EQ -1) /* jump or stop */
316 return;
317
318act3:
319 act = sp->seqact3; /* do Action 3 */
320 dat = sp->seqdat3;
321
322 rc = dosqact(seq, act, dat);
323
324#if DEBUGSX
325 if (debugsw AND debugsx)
326 printf("sqexec(%02u): Line %03u Act 3 $%04.4X $%04.4X $%04.4X %d\n",
327 seq, line, act, dat, seqflag[seq], rc);
328#endif
329
330 if (rc EQ -1) /* jump or stop */
331 return;
332
333nxtline: /* increment line counter */
334
335 if (++seqline[seq] GE NSLINES)
336 seqline[seq] = 0;
337
338 seqtime[seq] = seqtab[seqline[seq]].seqtime;
339 seqflag[seq] |= SQF_CLK;
340
341#if DEBUGSX
342 if (debugsw AND debugsx)
343 printf("sqexec(%02u): Next %03u %5u $%04.4X\n",
344 seq, line, seqtime[seq], seqflag[seq]);
345#endif
346
347 seqdupd |= (1 << seq);
348}
349
350/*
351
352*/
353
354/*
355 =============================================================================
356 seqproc() -- process sequences
357 =============================================================================
358*/
359
360seqproc()
361{
362 register unsigned short oldsr, seq;
363 register short dspn;
364 register unsigned short *fp;
365 char linbuf[66];
366
367 if (0 EQ timers[SQTIMER]) {
368
369 for (seq = 0; seq < 16; seq++) {
370
371 fp = &seqflag[seq];
372
373 if ( (SQF_RUN|SQF_CLK) EQ
374 ((SQF_RUN|SQF_CLK) & *fp) ) {
375
376 if (seqtime[seq]) {
377
378 if (0 EQ --seqtime[seq])
379 *fp &= ~SQF_CLK;
380
381 } else {
382
383 *fp &= ~SQF_CLK;
384 }
385 }
386 }
387
388 oldsr = setsr(0x2700);
389 timers[SQTIMER] = SEQTIME;
390 setsr(oldsr);
391 }
392
393 for (seq = 0; seq < 16; seq++)
394 if (SQF_RUN EQ ((SQF_RUN|SQF_CLK) & seqflag[seq]) )
395 sqexec(seq);
396/*
397
398*/
399 if (((ndisp EQ 1) OR (ndisp EQ 3)) AND dsp_ok AND seqdupd) {
400
401#if DEBUGSX
402 if (debugsw AND debugsx)
403 printf("seqproc(): ndisp = %d seqdupd = $%04.4X\n",
404 ndisp, seqdupd);
405#endif
406 if (seqdupd & (1 << seqdspn)) {
407
408 dspn = seqdspn;
409
410 if (v_regs[5] & 0x0180)
411 vbank(0);
412
413 sprintf(linbuf, " %03d %02d %c ",
414 seqline[dspn],
415 sregval[dspn],
416 '0' + trstate[dspn]);
417
418 vvputsv(obj10, 16, PDSEQFG, PDSEQBG,
419 dspn, 1, linbuf, 14, 14, cg3);
420
421#if UPD_LINE
422 sprintf(linbuf, "%02d", dspn + 1);
423
424 vvputsv(obj10, 16,
425 (seqflag[dspn] & SQF_RUN) ?
426 PDSEQRN : PDSEQFG, PDSEQBG,
427 dspn, 2, linbuf, 14, 14, cg3);
428#else
429 vsetcv(obj10, dspn, 2,
430 ( ( (seqflag[dspn] & SQF_RUN) ?
431 PDSEQRN : PDSEQFG) << 4) | PDSEQBG, 16);
432#endif
433 seqdupd &= ~(1 << dspn);
434 }
435
436 if (++seqdspn > 15)
437 seqdspn = 0;
438 }
439}
Note: See TracBrowser for help on using the repository browser.