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

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

Zero redundant declarations.

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