1 | /*
|
---|
2 | =============================================================================
|
---|
3 | stmproc.c -- MIDAS-VII Patch facility support functions
|
---|
4 | Version 33 -- 1988-12-06 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define DEBUGDP 0
|
---|
9 | #define DEBUGEP 0
|
---|
10 | #define DEBUGFD 0
|
---|
11 | #define DEBUGFP 0
|
---|
12 | #define DEBUGSR 0
|
---|
13 |
|
---|
14 | #define PATCHDEF /* so patch.h gets it right */
|
---|
15 |
|
---|
16 | #include "stddefs.h"
|
---|
17 | #include "graphdef.h"
|
---|
18 | #include "hwdefs.h"
|
---|
19 | #include "patch.h"
|
---|
20 | #include "vsdd.h"
|
---|
21 | #include "wordq.h"
|
---|
22 |
|
---|
23 | #include "midas.h"
|
---|
24 | #include "ptdisp.h"
|
---|
25 |
|
---|
26 | #include "memory.h"
|
---|
27 |
|
---|
28 | extern void UpdVid(int16_t row, int16_t col, int8_t *str, uint16_t atr);
|
---|
29 | extern void buf2pte(void);
|
---|
30 | extern void dopatch(struct patch *pp);
|
---|
31 | extern void dspdest(int8_t *buf, struct patch *pp);
|
---|
32 | extern void dspdfst(int8_t *buf, uint16_t val);
|
---|
33 | extern void pte2buf(void);
|
---|
34 | extern void voidpb(void);
|
---|
35 |
|
---|
36 | extern int16_t ptegood, ptedfok, ptestok, ptedsok, ptedtok;
|
---|
37 |
|
---|
38 | extern int16_t ptedef, ptestm, ptespec, ptesuba, ptedat1;
|
---|
39 |
|
---|
40 | extern int16_t pteset;
|
---|
41 |
|
---|
42 | extern int16_t ptecpos, ptepred, ptesucc;
|
---|
43 |
|
---|
44 | extern struct patch ptebuf;
|
---|
45 |
|
---|
46 | extern int8_t ptdebuf[];
|
---|
47 |
|
---|
48 | #if DEBUGDP
|
---|
49 | short debugdp = 1;
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #if DEBUGEP
|
---|
53 | short debugep = 0;
|
---|
54 | short snapep = 1;
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #if DEBUGFD
|
---|
58 | short debugfd = 0;
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #if DEBUGFP
|
---|
62 | short debugfp = 1;
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | #if DEBUGSR
|
---|
66 | short debugsr = 1;
|
---|
67 | short snapsr = 1;
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #if (DEBUGDP|DEBUGEP|DEBUGFD|DEBUGFP|DEBUGSR)
|
---|
71 | extern short debugsw;
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | uint16_t dtfree; /* defent free list index */
|
---|
75 | uint16_t ptfree; /* patch free list index */
|
---|
76 |
|
---|
77 | uint16_t dpepred; /* defent predecessor index */
|
---|
78 | uint16_t dpecpos; /* current defent index */
|
---|
79 | uint16_t dpesucc; /* defent successor index */
|
---|
80 |
|
---|
81 | int8_t ptdsbuf[50]; /* patch display build buffer */
|
---|
82 |
|
---|
83 | int8_t defptr[NDEFSTMS]; /* definition index table */
|
---|
84 | int8_t stmptr[NDEFSTMS]; /* stimulus index table */
|
---|
85 |
|
---|
86 | struct defent defents[RAWDEFS]; /* definition control table */
|
---|
87 |
|
---|
88 | struct patch patches[MAXPATCH]; /* patch table */
|
---|
89 |
|
---|
90 | struct wordq ptefifo; /* patch trigger fifo header */
|
---|
91 |
|
---|
92 | uint16_t ptewrds[NPTEQELS]; /* patch trigger fifo entries */
|
---|
93 |
|
---|
94 | int8_t dmatch[] = { /* addat1 match tags */
|
---|
95 |
|
---|
96 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0 .. 7 */
|
---|
97 | 0, 0, 0, 1, 0, 0, 0, 0, /* 8 .. 15 */
|
---|
98 | 1, 1, 1, 1, 1, 1, 1, 1, /* 16 .. 23 */
|
---|
99 | 1, 1, 1 /* 24 .. 26 */
|
---|
100 | };
|
---|
101 |
|
---|
102 | /* |
---|
103 |
|
---|
104 | */
|
---|
105 |
|
---|
106 | /*
|
---|
107 | =============================================================================
|
---|
108 | initpt() -- initialize patch table data structure
|
---|
109 | =============================================================================
|
---|
110 | */
|
---|
111 |
|
---|
112 | void initpt(void)
|
---|
113 | {
|
---|
114 | register uint16_t i;
|
---|
115 |
|
---|
116 | /* initialize the trigger fifo */
|
---|
117 |
|
---|
118 | setwq(&ptefifo, ptewrds, NPTEQELS, NPTEQHI, NPTEQLO);
|
---|
119 |
|
---|
120 | /* clear DEF / STM index tables */
|
---|
121 |
|
---|
122 | memset(defptr, 0, sizeof defptr);
|
---|
123 | memset(stmptr, 0, sizeof stmptr);
|
---|
124 |
|
---|
125 | /* setup patch free chain */
|
---|
126 |
|
---|
127 | memset(patches, 0, sizeof patches);
|
---|
128 |
|
---|
129 | for (i = 1; i < 255; i++)
|
---|
130 | patches[i].nextstm = 1 + i;
|
---|
131 |
|
---|
132 | ptfree = 1;
|
---|
133 |
|
---|
134 | /* setup defent free chain */
|
---|
135 |
|
---|
136 | memset(defents, 0, sizeof defents);
|
---|
137 |
|
---|
138 | for (i = 1; i < 255; i++)
|
---|
139 | defents[i].nextdef = 1 + i;
|
---|
140 |
|
---|
141 | dtfree = 1;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* |
---|
145 |
|
---|
146 | */
|
---|
147 |
|
---|
148 | /*
|
---|
149 | =============================================================================
|
---|
150 | pt_alc() -- allocate a patch table entry from the free list
|
---|
151 | =============================================================================
|
---|
152 | */
|
---|
153 |
|
---|
154 | uint16_t pt_alc(void)
|
---|
155 | {
|
---|
156 | register uint16_t pe;
|
---|
157 |
|
---|
158 | if (0 NE (pe = ptfree))
|
---|
159 | ptfree = patches[pe].nextstm;
|
---|
160 |
|
---|
161 | return(pe);
|
---|
162 | }
|
---|
163 |
|
---|
164 | /*
|
---|
165 | =============================================================================
|
---|
166 | pt_del() -- return a patch table entry to the free list
|
---|
167 | =============================================================================
|
---|
168 | */
|
---|
169 |
|
---|
170 | void pt_del(uint16_t pe)
|
---|
171 | {
|
---|
172 | patches[pe].nextstm = ptfree;
|
---|
173 | ptfree = pe;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /* |
---|
177 |
|
---|
178 | */
|
---|
179 |
|
---|
180 | /*
|
---|
181 | =============================================================================
|
---|
182 | dt_alc() -- allocate a def table entry from the free list
|
---|
183 | =============================================================================
|
---|
184 | */
|
---|
185 |
|
---|
186 | uint16_t dt_alc(void)
|
---|
187 | {
|
---|
188 | register uint16_t de;
|
---|
189 |
|
---|
190 | if (0 NE (de = dtfree))
|
---|
191 | dtfree = defents[de].nextdef;
|
---|
192 |
|
---|
193 | return(de);
|
---|
194 | }
|
---|
195 |
|
---|
196 | /*
|
---|
197 | =============================================================================
|
---|
198 | dt_del() -- return a def table entry to the free list
|
---|
199 | =============================================================================
|
---|
200 | */
|
---|
201 |
|
---|
202 | void dt_del(uint16_t de)
|
---|
203 | {
|
---|
204 | defents[de].nextdef = dtfree;
|
---|
205 | dtfree = de;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /* |
---|
209 |
|
---|
210 | */
|
---|
211 |
|
---|
212 | /*
|
---|
213 | =============================================================================
|
---|
214 | cprdpe() -- compare patch buffer to def table entry
|
---|
215 |
|
---|
216 | Returns:
|
---|
217 | -1 = buffer < table entry
|
---|
218 | 0 = buffer EQ table entry
|
---|
219 | +1 = buffer > table entry
|
---|
220 | =============================================================================
|
---|
221 | */
|
---|
222 |
|
---|
223 | int16_t cprdpe(uint16_t np)
|
---|
224 | {
|
---|
225 | register uint16_t ca, cb, ct;
|
---|
226 | register struct defent *pp;
|
---|
227 |
|
---|
228 | pp = &defents[np];
|
---|
229 |
|
---|
230 | if ((cb = ptestm) < (ct = pp->stm))
|
---|
231 | return(-1);
|
---|
232 |
|
---|
233 | if (cb > ct)
|
---|
234 | return(1);
|
---|
235 |
|
---|
236 | if ((ca = (PE_SPEC & ptespec)) < (ct = (PE_SPEC & pp->adspec)))
|
---|
237 | return(-1);
|
---|
238 |
|
---|
239 | if (ca > ct)
|
---|
240 | return(1);
|
---|
241 |
|
---|
242 | if ((cb = ptesuba) < (ct = pp->adsuba))
|
---|
243 | return(-1);
|
---|
244 |
|
---|
245 | if (cb > ct)
|
---|
246 | return(1);
|
---|
247 | /* |
---|
248 |
|
---|
249 | */
|
---|
250 | /* check for extended destinations -- they need further testing */
|
---|
251 |
|
---|
252 | if (dmatch[ca]) { /* check destination type */
|
---|
253 |
|
---|
254 | if ((cb = ptedat1) < (ct = pp->addat1))
|
---|
255 | return(-1);
|
---|
256 |
|
---|
257 | if (cb > ct)
|
---|
258 | return(1);
|
---|
259 | else
|
---|
260 | return(0);
|
---|
261 |
|
---|
262 | } else {
|
---|
263 |
|
---|
264 | return(0);
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | /* |
---|
269 |
|
---|
270 | */
|
---|
271 |
|
---|
272 | /*
|
---|
273 | =============================================================================
|
---|
274 | finddpe() -- find def table entry
|
---|
275 |
|
---|
276 | Returns: +1 = new def -- no DEF entry yet
|
---|
277 | 0 = old def -- entry found in DEF chain
|
---|
278 | -1 = new def -- entry not in DEF chain
|
---|
279 |
|
---|
280 | Sets: dpepred predecessor index, or 0 if none exists
|
---|
281 | dpecpos def table index, or 0 if none exists
|
---|
282 | dpesucc successor index, or 0 if none exists
|
---|
283 | =============================================================================
|
---|
284 | */
|
---|
285 |
|
---|
286 | int16_t finddpe(void)
|
---|
287 | {
|
---|
288 | register uint16_t c, idef;
|
---|
289 |
|
---|
290 | dpepred = 0; /* initialize dpepred = 0 (no predecessor) */
|
---|
291 | dpecpos = 0; /* initialize dpecpos = 0 (no current defent */
|
---|
292 | dpesucc = 0; /* initialize dpesucc = 0 (no successor) */
|
---|
293 |
|
---|
294 | #if DEBUGFD
|
---|
295 | if (debugsw AND debugfd) {
|
---|
296 |
|
---|
297 | printf("finddpe(): entry\n");
|
---|
298 |
|
---|
299 | printf(" ptb $%04.4X $%04.4X $%04.4X $%04.4X $%04.4X $%04.4X\n",
|
---|
300 | ptebuf.defnum, ptebuf.stmnum, ptebuf.paspec,
|
---|
301 | ptebuf.pasuba, ptebuf.padat1, ptebuf.padat2);
|
---|
302 | }
|
---|
303 | #endif
|
---|
304 |
|
---|
305 | /* try to find the DEF chain index for the defent in defptr[] */
|
---|
306 |
|
---|
307 | if (0 EQ (idef = defptr[TRG_MASK & ptebuf.defnum])) {
|
---|
308 |
|
---|
309 | #if DEBUGFD
|
---|
310 | if (debugsw AND debugfd) {
|
---|
311 |
|
---|
312 | printf("finddpe(): 1 -- NO DEF -- ");
|
---|
313 | printf("dpe pred: %3d cpos: %3d succ: %3d\n",
|
---|
314 | dpepred, dpecpos, dpesucc);
|
---|
315 | }
|
---|
316 | #endif
|
---|
317 |
|
---|
318 | return(1); /* +1 = new defent -- no DEF entry yet */
|
---|
319 | }
|
---|
320 |
|
---|
321 | /* |
---|
322 |
|
---|
323 | */
|
---|
324 |
|
---|
325 | while (idef) { /* search the DEF chain */
|
---|
326 |
|
---|
327 | /* compare ptebuf to defents[idef] */
|
---|
328 |
|
---|
329 | if (1 NE (c = cprdpe(idef))) {
|
---|
330 |
|
---|
331 | if (c EQ 0) { /* if we find the defent ... */
|
---|
332 |
|
---|
333 | dpecpos = idef; /* ... point at it */
|
---|
334 | dpesucc = defents[idef].nextdef;
|
---|
335 |
|
---|
336 | }
|
---|
337 |
|
---|
338 | #if DEBUGFD
|
---|
339 | if (debugsw AND debugfd) {
|
---|
340 |
|
---|
341 | printf("finddpe(): %d -- %s -- ", c,
|
---|
342 | c ? "NOT FOUND (>)" : "FOUND");
|
---|
343 |
|
---|
344 | printf("dpe pred: %3d cpos: %3d succ: %3d\n",
|
---|
345 | dpepred, dpecpos, dpesucc);
|
---|
346 | }
|
---|
347 | #endif
|
---|
348 | return(c); /* return search result */
|
---|
349 | }
|
---|
350 |
|
---|
351 | dpepred = idef; /* point at next entry in DEF chain */
|
---|
352 | idef = defents[idef].nextdef;
|
---|
353 | }
|
---|
354 |
|
---|
355 | #if DEBUGFD
|
---|
356 | if (debugsw AND debugfd) {
|
---|
357 |
|
---|
358 | printf("finddpe(): -1 -- NOT FOUND (<) -- ");
|
---|
359 | printf("dpe pred: %3d cpos: %3d succ: %3d\n",
|
---|
360 | dpepred, dpecpos, dpesucc);
|
---|
361 | }
|
---|
362 | #endif
|
---|
363 |
|
---|
364 | return(-1); /* -1 = new defent -- entry not in DEF chain */
|
---|
365 | }
|
---|
366 |
|
---|
367 | /* |
---|
368 |
|
---|
369 | */
|
---|
370 |
|
---|
371 | /*
|
---|
372 | =============================================================================
|
---|
373 | cprpte() -- compare patch buffer to patch table entry
|
---|
374 |
|
---|
375 | Returns:
|
---|
376 | -1 = buffer < table entry
|
---|
377 | 0 = buffer EQ table entry
|
---|
378 | +1 = buffer > table entry
|
---|
379 | =============================================================================
|
---|
380 | */
|
---|
381 |
|
---|
382 | int16_t cprpte(uint16_t np)
|
---|
383 | {
|
---|
384 | register uint16_t ca, cb, ct;
|
---|
385 | register struct patch *pb, *pp;
|
---|
386 |
|
---|
387 | pb = &ptebuf;
|
---|
388 | pp = &patches[np];
|
---|
389 |
|
---|
390 | if ((cb = pb->stmnum) < (ct = pp->stmnum))
|
---|
391 | return(-1);
|
---|
392 |
|
---|
393 | if (cb > ct)
|
---|
394 | return(1);
|
---|
395 |
|
---|
396 | if ((cb = pb->defnum) < (ct = pp->defnum))
|
---|
397 | return(-1);
|
---|
398 |
|
---|
399 | if (cb > ct)
|
---|
400 | return(1);
|
---|
401 |
|
---|
402 | if ((ca = (PE_SPEC & pb->paspec)) < (ct = (PE_SPEC & pp->paspec)))
|
---|
403 | return(-1);
|
---|
404 |
|
---|
405 | if (ca > ct)
|
---|
406 | return(1);
|
---|
407 |
|
---|
408 | if ((cb = pb->pasuba) < (ct = pp->pasuba))
|
---|
409 | return(-1);
|
---|
410 |
|
---|
411 | if (cb > ct)
|
---|
412 | return(1);
|
---|
413 | /* |
---|
414 |
|
---|
415 | */
|
---|
416 | /* check for extended destinations -- they need further testing */
|
---|
417 |
|
---|
418 | if (dmatch[ca]) { /* check destination type */
|
---|
419 |
|
---|
420 | if ((cb = pb->padat1) < (ct = pp->padat1))
|
---|
421 | return(-1);
|
---|
422 |
|
---|
423 | if (cb > ct)
|
---|
424 | return(1);
|
---|
425 | else
|
---|
426 | return(0);
|
---|
427 |
|
---|
428 | } else {
|
---|
429 |
|
---|
430 | return(0);
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | /* |
---|
435 |
|
---|
436 | */
|
---|
437 |
|
---|
438 | /*
|
---|
439 | =============================================================================
|
---|
440 | findpte() -- find patch table entry
|
---|
441 |
|
---|
442 | Returns: +1 = new patch -- no STM entry yet
|
---|
443 | 0 = old patch -- entry found in STM chain
|
---|
444 | -1 = new patch -- entry not in STM chain
|
---|
445 |
|
---|
446 | Sets: ptepred predecessor index, or 0 if none exists
|
---|
447 | ptecpos patch table index, or 0 if none exists
|
---|
448 | ptesucc successor index, or 0 if none exists
|
---|
449 | =============================================================================
|
---|
450 | */
|
---|
451 |
|
---|
452 | int16_t findpte(void)
|
---|
453 | {
|
---|
454 | register uint16_t c, istim;
|
---|
455 |
|
---|
456 | ptepred = 0; /* initialize ptepred = 0 (no predecessor) */
|
---|
457 | ptecpos = 0; /* initialize ptecpos = 0 (no current patch */
|
---|
458 | ptesucc = 0; /* initialize ptesucc = 0 (no successor) */
|
---|
459 |
|
---|
460 | #if DEBUGFP
|
---|
461 | if (debugsw AND debugfp) {
|
---|
462 |
|
---|
463 | printf("findpte(): entry\n");
|
---|
464 |
|
---|
465 | printf(" ptb $%04.4X $%04.4X $%04.4X $%04.4X $%04.4X $%04.4X\n",
|
---|
466 | ptebuf.defnum, ptebuf.stmnum, ptebuf.paspec,
|
---|
467 | ptebuf.pasuba, ptebuf.padat1, ptebuf.padat2);
|
---|
468 | }
|
---|
469 | #endif
|
---|
470 |
|
---|
471 | /* try to find the STM chain index for the patch in stmptr[] */
|
---|
472 |
|
---|
473 | if (0 EQ (istim = stmptr[TRG_MASK & ptebuf.stmnum])) {
|
---|
474 |
|
---|
475 | #if DEBUGFP
|
---|
476 | if (debugsw AND debugfp) {
|
---|
477 |
|
---|
478 | printf("findpte(): 1 -- NO STM -- ");
|
---|
479 | printf("pte pred: %3d cpos: %3d succ: %3d\n",
|
---|
480 | ptepred, ptecpos, ptesucc);
|
---|
481 | }
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | return(1); /* +1 = new patch -- no STM entry yet */
|
---|
485 | }
|
---|
486 |
|
---|
487 | /* |
---|
488 |
|
---|
489 | */
|
---|
490 |
|
---|
491 | while (istim) { /* search the STM chain */
|
---|
492 |
|
---|
493 | /* compare ptebuf to patches[istim] */
|
---|
494 |
|
---|
495 | if (1 NE (c = cprpte(istim))) {
|
---|
496 |
|
---|
497 | if (c EQ 0) { /* if we find the patch ... */
|
---|
498 |
|
---|
499 | ptecpos = istim; /* ... point at it */
|
---|
500 | ptesucc = patches[istim].nextstm;
|
---|
501 |
|
---|
502 | }
|
---|
503 |
|
---|
504 | #if DEBUGFP
|
---|
505 | if (debugsw AND debugfp) {
|
---|
506 |
|
---|
507 | printf("findpte(): %d -- %s -- ", c,
|
---|
508 | c ? "NOT FOUND (>)" : "FOUND");
|
---|
509 |
|
---|
510 | printf("pte pred: %3d cpos: %3d succ: %3d\n",
|
---|
511 | ptepred, ptecpos, ptesucc);
|
---|
512 | }
|
---|
513 | #endif
|
---|
514 | return(c); /* return search result */
|
---|
515 | }
|
---|
516 |
|
---|
517 | ptepred = istim; /* point at next entry in STM chain */
|
---|
518 | istim = patches[istim].nextstm;
|
---|
519 | }
|
---|
520 |
|
---|
521 | #if DEBUGFP
|
---|
522 | if (debugsw AND debugfp) {
|
---|
523 |
|
---|
524 | printf("findpte(): -1 -- NOT FOUND (<) -- ");
|
---|
525 | printf("pte pred: %3d cpos: %3d succ: %3d\n",
|
---|
526 | ptepred, ptecpos, ptesucc);
|
---|
527 | }
|
---|
528 | #endif
|
---|
529 |
|
---|
530 | return(-1); /* -1 = new patch -- entry not in STM chain */
|
---|
531 | }
|
---|
532 |
|
---|
533 | /* |
---|
534 |
|
---|
535 | */
|
---|
536 |
|
---|
537 | /*
|
---|
538 | =============================================================================
|
---|
539 | entrpte() -- enter or update a patch table entry
|
---|
540 | =============================================================================
|
---|
541 | */
|
---|
542 |
|
---|
543 | void entrpte(void)
|
---|
544 | {
|
---|
545 | register int16_t c;
|
---|
546 | register uint16_t np, stim;
|
---|
547 |
|
---|
548 | ptegood = ptedfok AND ptestok AND ptedsok AND ptedtok;
|
---|
549 |
|
---|
550 | if (ptegood) {
|
---|
551 |
|
---|
552 | buf2pte();
|
---|
553 |
|
---|
554 | c = findpte();
|
---|
555 |
|
---|
556 | if (c EQ 0) { /* old patch -- just update it */
|
---|
557 |
|
---|
558 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
559 |
|
---|
560 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
561 |
|
---|
562 | #if DEBUGEP
|
---|
563 | if (debugsw AND debugep) {
|
---|
564 |
|
---|
565 | if (snapep)
|
---|
566 | SnapPTV("entrpte");
|
---|
567 |
|
---|
568 | printf("entrpte(): UPDATED\n");
|
---|
569 | }
|
---|
570 | #endif
|
---|
571 |
|
---|
572 | return;
|
---|
573 | }
|
---|
574 | /* |
---|
575 |
|
---|
576 | */
|
---|
577 | /* allocate a patch entry and fill it in */
|
---|
578 |
|
---|
579 | if (0 EQ (ptecpos = pt_alc())) {
|
---|
580 |
|
---|
581 | #if DEBUGEP
|
---|
582 | if (debugsw AND debugep)
|
---|
583 | printf("entrpte(): patch table FULL\n");
|
---|
584 | #endif
|
---|
585 | return; /* no patch entries left */
|
---|
586 | }
|
---|
587 |
|
---|
588 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
589 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
590 | stim = TRG_MASK & ptebuf.stmnum;
|
---|
591 |
|
---|
592 | if (c EQ 1) { /* new patch -- no STM entry yet */
|
---|
593 |
|
---|
594 | ptepred = 0;
|
---|
595 | stmptr[stim] = ptecpos;
|
---|
596 | }
|
---|
597 | /* |
---|
598 |
|
---|
599 | */
|
---|
600 | /* put patch in STM chain */
|
---|
601 |
|
---|
602 | if (ptepred) { /* predecessor exits */
|
---|
603 |
|
---|
604 | ptesucc = patches[ptepred].nextstm;
|
---|
605 |
|
---|
606 | patches[ptecpos].nextstm = ptesucc;
|
---|
607 | patches[ptecpos].prevstm = ptepred;
|
---|
608 |
|
---|
609 | patches[ptepred].nextstm = ptecpos;
|
---|
610 |
|
---|
611 | if (ptesucc)
|
---|
612 | patches[ptesucc].prevstm = ptecpos;
|
---|
613 |
|
---|
614 | } else { /* no predecessor */
|
---|
615 |
|
---|
616 | patches[ptecpos].prevstm = 0;
|
---|
617 |
|
---|
618 | if (c EQ -1) {
|
---|
619 |
|
---|
620 | ptesucc = stmptr[stim];
|
---|
621 |
|
---|
622 | patches[ptecpos].nextstm = ptesucc;
|
---|
623 |
|
---|
624 | patches[ptesucc].prevstm = ptecpos;
|
---|
625 |
|
---|
626 | stmptr[stim] = ptecpos;
|
---|
627 |
|
---|
628 | } else {
|
---|
629 |
|
---|
630 | patches[ptecpos].nextstm = 0;
|
---|
631 | }
|
---|
632 | }
|
---|
633 | /* |
---|
634 |
|
---|
635 | */
|
---|
636 | /* update DEF table */
|
---|
637 |
|
---|
638 | if (0 EQ (c = finddpe())) {
|
---|
639 |
|
---|
640 | #if DEBUGEP
|
---|
641 | if (debugsw AND debugep)
|
---|
642 | printf("entrpte(): defent already exists\n");
|
---|
643 | #endif
|
---|
644 | return; /* defent already exists */
|
---|
645 | }
|
---|
646 |
|
---|
647 | if (0 EQ (dpecpos = dt_alc())) {
|
---|
648 |
|
---|
649 | #if DEBUGEP
|
---|
650 | if (debugsw AND debugep)
|
---|
651 | printf("entrpte(): defent table FULL\n");
|
---|
652 | #endif
|
---|
653 | return; /* no defents left */
|
---|
654 | }
|
---|
655 |
|
---|
656 | defents[dpecpos].nextdef = 0;
|
---|
657 | defents[dpecpos].stm = ptestm;
|
---|
658 | defents[dpecpos].adspec = ptespec;
|
---|
659 | defents[dpecpos].adsuba = ptesuba;
|
---|
660 | defents[dpecpos].addat1 = ptedat1;
|
---|
661 |
|
---|
662 | np = TRG_MASK & ptebuf.defnum;
|
---|
663 |
|
---|
664 | if (c EQ 1) {
|
---|
665 |
|
---|
666 | dpepred = 0;
|
---|
667 | defptr[np] = dpecpos;
|
---|
668 | }
|
---|
669 |
|
---|
670 | if (dpepred) {
|
---|
671 |
|
---|
672 | dpesucc = defents[dpepred].nextdef;
|
---|
673 | defents[dpecpos].nextdef = dpesucc;
|
---|
674 | defents[dpepred].nextdef = dpecpos;
|
---|
675 |
|
---|
676 | } else {
|
---|
677 |
|
---|
678 | if (c EQ -1) {
|
---|
679 |
|
---|
680 | dpesucc = defptr[np];
|
---|
681 | defents[dpecpos].nextdef = dpesucc;
|
---|
682 | defptr[np] = dpecpos;
|
---|
683 |
|
---|
684 | } else {
|
---|
685 |
|
---|
686 | defents[dpecpos].nextdef = 0;
|
---|
687 | }
|
---|
688 | }
|
---|
689 |
|
---|
690 | #if DEBUGEP
|
---|
691 | if (debugsw AND debugep) {
|
---|
692 |
|
---|
693 | if (snapep)
|
---|
694 | SnapPTV("entrpte");
|
---|
695 |
|
---|
696 | printf("entrpte(): ENTERED\n");
|
---|
697 | }
|
---|
698 | #endif
|
---|
699 | return;
|
---|
700 | }
|
---|
701 |
|
---|
702 | #if DEBUGEP
|
---|
703 | if (debugsw AND debugep) {
|
---|
704 |
|
---|
705 | if (snapep)
|
---|
706 | SnapPTV("entrpte");
|
---|
707 |
|
---|
708 | printf("entrpte(): INVALID\n");
|
---|
709 | }
|
---|
710 | #endif
|
---|
711 | }
|
---|
712 |
|
---|
713 | /* |
---|
714 |
|
---|
715 | */
|
---|
716 |
|
---|
717 | /*
|
---|
718 | =============================================================================
|
---|
719 | find1st() -- find the first patch in the patch table
|
---|
720 | =============================================================================
|
---|
721 | */
|
---|
722 |
|
---|
723 | int16_t find1st(void)
|
---|
724 | {
|
---|
725 | register int16_t cp, pp;
|
---|
726 |
|
---|
727 | for (cp = 0; cp < NDEFSTMS; cp++)
|
---|
728 | if (0 NE (pp = ADR_MASK & stmptr[cp]))
|
---|
729 | return(pp);
|
---|
730 |
|
---|
731 | return(0);
|
---|
732 | }
|
---|
733 |
|
---|
734 | /*
|
---|
735 | =============================================================================
|
---|
736 | findnxt() -- find the next patch in the patch table
|
---|
737 | =============================================================================
|
---|
738 | */
|
---|
739 |
|
---|
740 | int16_t findnxt(int16_t cp)
|
---|
741 | {
|
---|
742 | register int16_t np, stim;
|
---|
743 |
|
---|
744 | if (0 NE (np = patches[cp].nextstm))
|
---|
745 | return(np);
|
---|
746 |
|
---|
747 | stim = TRG_MASK & patches[cp].stmnum;
|
---|
748 |
|
---|
749 | while (++stim < NDEFSTMS)
|
---|
750 | if (0 NE (np = ADR_MASK & stmptr[stim]))
|
---|
751 | return(np);
|
---|
752 |
|
---|
753 | return(0);
|
---|
754 | }
|
---|
755 |
|
---|
756 | /* |
---|
757 |
|
---|
758 | */
|
---|
759 |
|
---|
760 | /*
|
---|
761 | =============================================================================
|
---|
762 | findprv() -- find the previous patch in the patch table
|
---|
763 | =============================================================================
|
---|
764 | */
|
---|
765 |
|
---|
766 | int16_t findprv(int16_t cp)
|
---|
767 | {
|
---|
768 | register int16_t np, pp, stim;
|
---|
769 |
|
---|
770 | if (0 NE (np = patches[cp].prevstm)) /* return prevstm if set */
|
---|
771 | return(np);
|
---|
772 |
|
---|
773 | stim = TRG_MASK & patches[cp].stmnum; /* extract the stimulus */
|
---|
774 |
|
---|
775 | while (--stim GE 0) { /* back up one stimulus if we can */
|
---|
776 |
|
---|
777 | if (0 NE (np = ADR_MASK & stmptr[stim])) { /* any there ? */
|
---|
778 |
|
---|
779 | /* find the end of the chain for the stimulus */
|
---|
780 |
|
---|
781 | while (pp = patches[np].nextstm)
|
---|
782 | np = pp;
|
---|
783 |
|
---|
784 | return(np);
|
---|
785 | }
|
---|
786 | }
|
---|
787 |
|
---|
788 | return(0); /* backed up to the start of the table */
|
---|
789 | }
|
---|
790 |
|
---|
791 | /* |
---|
792 |
|
---|
793 | */
|
---|
794 |
|
---|
795 | /*
|
---|
796 | =============================================================================
|
---|
797 | dpte() -- display a patch at a given line on the screen
|
---|
798 | =============================================================================
|
---|
799 | */
|
---|
800 |
|
---|
801 | void dpte(int16_t pe, int16_t row, int16_t atr)
|
---|
802 | {
|
---|
803 | register int16_t i;
|
---|
804 |
|
---|
805 | memset(ptdsbuf, ' ', 50);
|
---|
806 |
|
---|
807 | if (pe) {
|
---|
808 |
|
---|
809 | dspdfst(&ptdsbuf[ 2], patches[pe].defnum);
|
---|
810 | dspdfst(&ptdsbuf[15], patches[pe].stmnum);
|
---|
811 | dspdest(&ptdsbuf[28], &patches[pe]);
|
---|
812 |
|
---|
813 | for (i = 0; i < 50; i++)
|
---|
814 | if (ptdsbuf[i] EQ '\0')
|
---|
815 | ptdsbuf[i] = ' ';
|
---|
816 |
|
---|
817 | ptdsbuf[48] = '\0';
|
---|
818 | }
|
---|
819 |
|
---|
820 | UpdVid(row, 0, "\260 ", PTBATR);
|
---|
821 | UpdVid(row, 1, &ptdsbuf[1], atr);
|
---|
822 | }
|
---|
823 |
|
---|
824 | /* |
---|
825 |
|
---|
826 | */
|
---|
827 |
|
---|
828 | /*
|
---|
829 | =============================================================================
|
---|
830 | dptw() -- display window around current patch at ptecpos
|
---|
831 | =============================================================================
|
---|
832 | */
|
---|
833 |
|
---|
834 | void dptw(void)
|
---|
835 | {
|
---|
836 | register int16_t cp, r, row, pp;
|
---|
837 |
|
---|
838 | #if DEBUGDP
|
---|
839 | if (debugsw AND debugdp)
|
---|
840 | printf("dptw(): ENTRY ptecpos = %d\n", ptecpos);
|
---|
841 | #endif
|
---|
842 |
|
---|
843 | if (ptecpos) {
|
---|
844 |
|
---|
845 | /* search back from ptecpos for predecessors */
|
---|
846 |
|
---|
847 | row = 7;
|
---|
848 | pp = ptecpos;
|
---|
849 |
|
---|
850 | while (0 NE (cp = findprv(pp))) {
|
---|
851 |
|
---|
852 | pp = cp;
|
---|
853 |
|
---|
854 | if (--row EQ 0)
|
---|
855 | break;
|
---|
856 | }
|
---|
857 |
|
---|
858 | #if DEBUGDP
|
---|
859 | if (debugsw AND debugdp)
|
---|
860 | printf("dptw(): backed up to row = %d pp = %d\n", row, pp);
|
---|
861 | #endif
|
---|
862 |
|
---|
863 | if (row) { /* blank any unused lines (rows 0..6) */
|
---|
864 |
|
---|
865 | for (r = 0; r < row; r++)
|
---|
866 | dpte(0, r, PTPATR);
|
---|
867 | }
|
---|
868 |
|
---|
869 | while (row < 7) { /* display predecessors (rows 0..6) */
|
---|
870 |
|
---|
871 | dpte(pp, row++, PTPATR);
|
---|
872 | pp = findnxt(pp);
|
---|
873 | }
|
---|
874 | /* |
---|
875 |
|
---|
876 | */
|
---|
877 | /* display ptecpos at the center (row 7) */
|
---|
878 |
|
---|
879 | #if DEBUGDP
|
---|
880 | if (debugsw AND debugdp)
|
---|
881 | printf("dptw(): row = %d pp = %d ptecpos = %d\n",
|
---|
882 | row, pp, ptecpos);
|
---|
883 | #endif
|
---|
884 |
|
---|
885 | dpte(pp, row++, PTEATR);
|
---|
886 |
|
---|
887 | /* display forward from ptecpos (rows 8..15) */
|
---|
888 |
|
---|
889 | while (0 NE (pp = findnxt(pp))) {
|
---|
890 |
|
---|
891 | dpte(pp, row++, PTPATR);
|
---|
892 |
|
---|
893 | if (row > 15)
|
---|
894 | break;
|
---|
895 | }
|
---|
896 |
|
---|
897 | /* blank any unused display lines (rows 8..15) */
|
---|
898 | while (row < 16)
|
---|
899 | dpte(0, row++, PTPATR);
|
---|
900 | /* |
---|
901 |
|
---|
902 | */
|
---|
903 | } else {
|
---|
904 |
|
---|
905 | if (0 NE (ptecpos = find1st())) {
|
---|
906 |
|
---|
907 | #if DEBUGDP
|
---|
908 | if (debugsw AND debugdp)
|
---|
909 | printf("dptw(): found 1st at %d\n", ptecpos);
|
---|
910 | #endif
|
---|
911 |
|
---|
912 | /* clear lines above the center (rows 0..6) */
|
---|
913 |
|
---|
914 | for (row = 0; row < 7; ++row)
|
---|
915 | dpte(0, row, PTPATR);
|
---|
916 |
|
---|
917 | /* display ptecpos at the center (row 7) */
|
---|
918 |
|
---|
919 | dpte(pp = ptecpos, row++, PTEATR);
|
---|
920 |
|
---|
921 | /* display forward from ptecpos (rows 8..15) */
|
---|
922 |
|
---|
923 | while (0 NE (pp = findnxt(pp))) {
|
---|
924 |
|
---|
925 | dpte(pp, row++, PTPATR);
|
---|
926 |
|
---|
927 | if (row > 15)
|
---|
928 | break;
|
---|
929 | }
|
---|
930 |
|
---|
931 | /* blank any unused display lines (rows 8..15) */
|
---|
932 |
|
---|
933 | while (row < 16)
|
---|
934 | dpte(0, row++, PTPATR);
|
---|
935 | /* |
---|
936 |
|
---|
937 | */
|
---|
938 | } else {
|
---|
939 |
|
---|
940 | #if DEBUGDP
|
---|
941 | if (debugsw AND debugdp)
|
---|
942 | printf("dptw(): no patches to display\n");
|
---|
943 | #endif
|
---|
944 |
|
---|
945 | /* clear the patch display */
|
---|
946 |
|
---|
947 | for (row = 0; row < 16; ++row)
|
---|
948 | dpte(0, row, (row EQ 7) ? PTEATR : PTPATR);
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 | if (ptecpos) {
|
---|
953 |
|
---|
954 | memcpyw(&ptebuf.defnum, &patches[ptecpos].defnum, 6);
|
---|
955 | pteset = TRUE;
|
---|
956 | pte2buf();
|
---|
957 |
|
---|
958 | #if DEBUGDP
|
---|
959 | if (debugsw AND debugdp)
|
---|
960 | printf("dptw(): EXIT -- LOADED buffer, ptecpos = %d\n",
|
---|
961 | ptecpos);
|
---|
962 | #endif
|
---|
963 |
|
---|
964 | } else {
|
---|
965 |
|
---|
966 | pteset = FALSE;
|
---|
967 | voidpb();
|
---|
968 |
|
---|
969 | #if DEBUGDP
|
---|
970 | if (debugsw AND debugdp)
|
---|
971 | printf("dptw(): EXIT -- VOIDED buffer, ptecpos = %d\n",
|
---|
972 | ptecpos);
|
---|
973 | #endif
|
---|
974 |
|
---|
975 |
|
---|
976 | }
|
---|
977 | }
|
---|
978 |
|
---|
979 | /* |
---|
980 |
|
---|
981 | */
|
---|
982 |
|
---|
983 | /*
|
---|
984 | =============================================================================
|
---|
985 | srdspte() -- search for and display patch table entry
|
---|
986 | =============================================================================
|
---|
987 | */
|
---|
988 |
|
---|
989 | void srdspte(void)
|
---|
990 | {
|
---|
991 | int16_t oldcpos, oldpred, oldsucc;
|
---|
992 | #if DEBUGSR
|
---|
993 | register short i;
|
---|
994 | char dbuf[50];
|
---|
995 | #endif
|
---|
996 |
|
---|
997 | ptegood = ptedfok AND ptestok AND ptedsok AND ptedtok;
|
---|
998 |
|
---|
999 | #if DEBUGSR
|
---|
1000 | if (debugsw AND debugsr) {
|
---|
1001 |
|
---|
1002 | printf("srdspte(): ENTRY pte good=%d dfok=%d stok=%d dsok=%d dtok=%d\n",
|
---|
1003 | ptegood, ptedfok, ptestok, ptedsok, ptedtok);
|
---|
1004 |
|
---|
1005 | memcpy(dbuf, ptdebuf, 48);
|
---|
1006 |
|
---|
1007 | for (i = 0; i < 48; i++)
|
---|
1008 | if (dbuf[i] EQ '\0')
|
---|
1009 | dbuf[i] = ' ';
|
---|
1010 | else if (dbuf[i] & 0x0080)
|
---|
1011 | dbuf[i] = '~';
|
---|
1012 |
|
---|
1013 | dbuf[48] = '\0';
|
---|
1014 |
|
---|
1015 | printf(" ptdebuf = \"%s\"\n", dbuf);
|
---|
1016 | }
|
---|
1017 | #endif
|
---|
1018 |
|
---|
1019 | if (ptegood) {
|
---|
1020 |
|
---|
1021 | oldcpos = ptecpos; /* save patch pointers */
|
---|
1022 | oldpred = ptepred;
|
---|
1023 | oldsucc = ptesucc;
|
---|
1024 |
|
---|
1025 | buf2pte();
|
---|
1026 |
|
---|
1027 | if (0 EQ findpte()) {
|
---|
1028 |
|
---|
1029 | #if DEBUGSR
|
---|
1030 | if (debugsw AND debugsr)
|
---|
1031 | printf("srdspte(): FOUND patch at ptecpos = %d\n", ptecpos);
|
---|
1032 | #endif
|
---|
1033 |
|
---|
1034 | memcpyw(&ptebuf.defnum, &patches[ptecpos].defnum, 6);
|
---|
1035 | pteset = TRUE;
|
---|
1036 | pte2buf();
|
---|
1037 | dptw();
|
---|
1038 |
|
---|
1039 | } else {
|
---|
1040 |
|
---|
1041 | ptecpos = oldcpos; /* restore patch pointers */
|
---|
1042 | ptepred = oldpred;
|
---|
1043 | ptesucc = oldsucc;
|
---|
1044 |
|
---|
1045 | #if DEBUGSR
|
---|
1046 | if (debugsw AND debugsr) {
|
---|
1047 |
|
---|
1048 | printf("srdspte(): patch not found\n");
|
---|
1049 |
|
---|
1050 | if (snapsr)
|
---|
1051 | SnapPTV("srdspte");
|
---|
1052 |
|
---|
1053 | }
|
---|
1054 | #endif
|
---|
1055 |
|
---|
1056 | }
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | #if DEBUGSR
|
---|
1060 | if (debugsw AND debugsr)
|
---|
1061 | printf("srdspte(): EXIT -- ptecpos = %d\n", ptecpos);
|
---|
1062 | #endif
|
---|
1063 |
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | /* |
---|
1067 |
|
---|
1068 | */
|
---|
1069 |
|
---|
1070 | /*
|
---|
1071 | =============================================================================
|
---|
1072 | stmproc() -- process a trigger as a definer and a stimulus
|
---|
1073 | =============================================================================
|
---|
1074 | */
|
---|
1075 |
|
---|
1076 | void stmproc(uint16_t trg)
|
---|
1077 | {
|
---|
1078 | register struct defent *nextdef;
|
---|
1079 | register struct patch *nextpch;
|
---|
1080 | register uint16_t adspec, adsuba, np, stim;
|
---|
1081 | uint16_t addat1, adrtag;
|
---|
1082 |
|
---|
1083 | /* ***** DEFINER PROCESSING PHASE ***** */
|
---|
1084 |
|
---|
1085 | np = ADR_MASK & defptr[TRG_MASK & trg];
|
---|
1086 | nextdef = np ? &defents[np] : (struct defent *)NULL; /* point at DEF chain */
|
---|
1087 |
|
---|
1088 | /* |
---|
1089 |
|
---|
1090 | */
|
---|
1091 | while ((struct defent *)NULL NE nextdef) { /* process DEF chain */
|
---|
1092 |
|
---|
1093 | /* setup search criteria */
|
---|
1094 |
|
---|
1095 | adspec = nextdef->adspec;
|
---|
1096 | adsuba = nextdef->adsuba;
|
---|
1097 | addat1 = nextdef->addat1;
|
---|
1098 | stim = nextdef->stm;
|
---|
1099 | adrtag = dmatch[adspec];
|
---|
1100 |
|
---|
1101 | /* point at the start of the STM chain */
|
---|
1102 |
|
---|
1103 | np = ADR_MASK & stmptr[TRG_MASK & stim];
|
---|
1104 | nextpch = np ? &patches[np] : (struct patch *)NULL;
|
---|
1105 |
|
---|
1106 | while ((struct patch *)NULL NE nextpch) { /* process STM chain */
|
---|
1107 |
|
---|
1108 | /* if this patch matches our search criteria ... */
|
---|
1109 |
|
---|
1110 | if ((stim EQ nextpch->stmnum) AND
|
---|
1111 | (adspec EQ (nextpch->paspec & PE_SPEC)) AND
|
---|
1112 | (adsuba EQ nextpch->pasuba)) {
|
---|
1113 |
|
---|
1114 | if ((NOT adrtag) OR
|
---|
1115 | (adrtag AND addat1 EQ nextpch->padat1)) {
|
---|
1116 |
|
---|
1117 | if (nextpch->defnum EQ trg)
|
---|
1118 | nextpch->paspec |= PE_TBIT; /* define */
|
---|
1119 | else
|
---|
1120 | nextpch->paspec &= ~PE_TBIT; /* undefine */
|
---|
1121 | }
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | /* point at the next patch in the STM chain */
|
---|
1125 |
|
---|
1126 | np = nextpch->nextstm;
|
---|
1127 | nextpch = np ? &patches[np] : (struct patch *)NULL;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | /* point at the next DEF entry */
|
---|
1131 |
|
---|
1132 | np = nextdef->nextdef;
|
---|
1133 | nextdef = np ? &defents[np] : (struct defent *)NULL;
|
---|
1134 | }
|
---|
1135 | /* |
---|
1136 |
|
---|
1137 | */
|
---|
1138 |
|
---|
1139 | /* ***** STIMULUS PROCESSING PHASE ***** */
|
---|
1140 |
|
---|
1141 | /* setup initial STM chain pointer */
|
---|
1142 |
|
---|
1143 | np = ADR_MASK & stmptr[TRG_MASK & trg];
|
---|
1144 | nextpch = np ? &patches[np] : (struct patch *)NULL;
|
---|
1145 |
|
---|
1146 | /* process the STM chain */
|
---|
1147 |
|
---|
1148 | while ((struct patch *)NULL NE nextpch) { /* for each patch .. */
|
---|
1149 |
|
---|
1150 | if ((nextpch->paspec & PE_TBIT) AND /* if it's defined ... */
|
---|
1151 | (nextpch->stmnum EQ trg)) /* ... and stm matches */
|
---|
1152 | dopatch(nextpch); /* ... do the patch */
|
---|
1153 |
|
---|
1154 | /* point at the next patch */
|
---|
1155 |
|
---|
1156 | np = nextpch->nextstm;
|
---|
1157 | nextpch = np ? &patches[np] : (struct patch *)NULL;
|
---|
1158 | }
|
---|
1159 | }
|
---|