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

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

Removed form-feed comments.

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