source: buchla-68k/ram/sqexec.c@ ea9a162

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

Fixed sqexec.c.

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