source: buchla-68k/ram/stmproc.c@ 018c029

Last change on this file since 018c029 was 00c31a2, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fixed parentheses and braces.

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