ER[MAIN];

*I = 212+2 FOR MAXC2

%THIS FILE CONTAINS THE EMULATOR'S MAIN LOOP, PREPARATION ROUTINES,
AND COMPLETION ROUTINES.  IT CONTAINS REFERENCES TO VARIABLES AND TAGS
DEFINED IN "MAP" AND "PISYS" WHICH ARE ASSEMBLED AHEAD OF THIS FILE.

THE INSTRUCTION-FETCH LOOP CONTAINS A BRANCH CONDITIONED ON THE "LOGF" FLAG
TO A SPECIAL PROGRAM.  THIS PROGRAM CAN BE FILLED OUT BY  "LOGI", "BRKI",
OR "TRACEI" (NORMAL = "LOGI").  TIMING COMMENTS APPLY WHEN "LOGF" = 0.

THE ENTRY POINT TO THE MAIN LOOP IS CALLED "REMAPPC".  OPCODES MAY
REENTER THE MAIN LOOP IN ANY OF THE FOLLOWING WAYS:

	P←MAPVA←PC, Q←1R, ACFS, GOTO[REMAP1]; *= "ENDM"
	RETURN;		*IF THE STACK HAS BEEN POPPED ENOUGH TIMES
	GOTO[REMAPPC];

COMPLETION ROUTINES WHICH CAN SHOULD FINISH WITH "ENDM" (OR AN EQUIVALENT
FOR JUMPS AND SKIPS) SINCE THAT SAVES ONE CYCLE.

"PC" IS ADVANCED IN THE MAIN LOOP (UNLIKE THE PDP-10) SO "LOADMAP" MUST
DECREMENT "PC" BEFORE TRAPPING EXCEPT ON PURE WRITES. "PI" DECREMENTS "PC".

IT IS NECESSARY, BEFORE ENTERING THE INDIRECT ADDRESS LOOP, LOADING THE
MAP, OR TRIPLE-DISPATCHING, TO CLEAR ALL FOUR XCTN FLAGS, J AND PICYCLE.
THE MAIN LOOP MUST ALSO CHECK FOR INTERRUPT CONDITIONS.  ALL OF
THESE ARE REPRESENTED BY 1 BITS IN F SELECTED BY "INTCONDH."

TIMING:	4 CYCLES + 1R
	+4 CYCLES + 1R / INDIRECT
	+1 CYCLE IF THE INSTRUCTION DOES NOT FINISH WITH "ENDM"

DEEPEST STACK DEPTH = 4 DURING INDIRECT LOOP
		= 7 DURING INDIRECT LOOP MAP LOADING
		= 3 AT MAIN LOOP EXIT

NOTE:	R = 2 FOR AC INSTRUCTION FETCHES OR 0 FOR INDIRECT READS.  OTHERWISE,
	IT IS THE NO. OF INSTRUCTIONS WHICH ELAPSE AFTER THE ONE INITIATING
	THE READ BUT NOT INCLUDING THE ONE WHICH READS MDR.

"TFLAGS" CONTAINS 1'S FOR XCT0, XCT1, XCT2, XCT3, J, AND PICYCLE.
IN THE SPECIAL VERSION OF THE MAIN LOOP USED BY TRAP AND PICYCLES,
"TFLAGSPI" IS USED INSTEAD.  IT DOES NOT CLEAR J (J=UM) NOR PICYCLE (=1),
AND DOES CLEAR UM (TO XCT THE INSTRUCTION IN MONITOR MODE).

THE MAIN LOOP ZEROES "PC" LEFT HALF BEFORE CHECKING PI CONDITIONS OR
CALLING "LOADMAP".  THIS MEANS THAT DURING EXECUTION OF AN INSTRUCTION,
"PC" CAN ALWAYS BE MERGED WITH THE FLAGS WITHOUT CLEARING ITS LEFT HALF
FIRST, AND INSTRUCTIONS WHICH CHANGE "PC" DON'T HAVE TO CLEAR THE LEFT HALF
BEFORE REENTERING THE MAIN LOOP.  NOTE THAT THE TRAP CODE FOR "LOADMAP"
NECESSARILY CLEARS THE LEFT HALF OF "PC".  FINALLY, NOTE THAT "PC" IS
INVALID WHEN ENTRY IS MADE AT "REMAP1" SO THE NEW VALUE COMPUTED FROM P
MUST BE SAVED BEFORE GOING TO "LOADMAP" OR "PI".  AT EXIT FROM THE MAIN
LOOP, "INSTR" CONTAINS THE INSTRUCTION, P THE EFFECTIVE ADDRESS E, Q THE AC,
AC POINTS TO THE AC, G=1 IFF E POINTS TO AN AC K=0 IF NO INDIRECTION
ELSE K=XCT3 (FOR BYTE INDIRECTION), J=0 (FOR UM COMPUTATION BY INTERRUPT
INSTRUCTIONS), PC HAS BEEN INCREMENTED, AND ICTR HAS BEEN INCREMENTED
ONCE PLUS ONCE PER INDIRECT ADDRESS.  "OLDPC" ALSO CONTAINS THE PC.
"REFADR" ALSO CONTAINS E WITH GARBAGE IN THE L.H.

I = 24
%

MC[XCTN,XCTN];
MC[TFLAGS,J,PICYCLE,XCTN];
MC[XCT3&K,XCT3,K];
RVN[INSTR];
*INTCONDH IS DEFINED IN PISYS

TARGET[ILC];

*SUBROUTINES TO HANDLE THE MONITOR'S FORCED REFERENCES TO USER AC'S
RMWAMDR: P←MAPVA←(MDR) U (ACBASE), A1;
	RMWREFDXK, INHINT, RETURN;

RAMDR:	P←MAPVA←(MDR) U (ACBASE), A1;
RREFX:	RREFDXK, RETURN;


M[ENDM,(P←MAPVA←PC, Q←1R, ACFS, GOTO[REMAP1,#1])];

%SET UP TRIPLE DISPATCH.  CALL INDLP ONLY IF INDIRECT BIT IN INSTRUCTION
=1 (BOTH G AND H =0) AND D[0]=1 (B[0]=0 SETS G=1).  NOTE THAT H REMEMBERS
THE SETTING OF THE INDIRECT BIT WHEN D[0]=0 FORCES A MAIN LOOP EXIT.%

REMAPE:	NPC←STACK←D, Q←LINDX, INSTR←P, GOTO[LOGI,K=1];
	MAPVA←REFADR←P←P+Q, SAMASK[22], Q←LAC, CALL[INDLP,G=0];

INDLP1:	RTEMP←P, Q←LINDX, GOTO[PI,H=1]; *RTEMP HOLDS LAST MEM REF FOR JRST@
*ALSO ENTER HERE FOR BYTE INDIRECT SEQUENCES (K←XCT3 FOR BYTE STUFF)
BINDE:	MAPVA←REFADR←P←P+Q, BAMASK[22], Q←LAC, RETURN[G=1], SETSF[XCT3&K];
*REENTER AT "INDLP" FOR JRST INDIRECT SEQUENCES
INDLP:	IREF, MDR←X, Q←LX, REFADR←P, GOTO[INDLP2,G=0];
	ISPLIT←P←Q, SETSF[INTCONDH], GOTO[INDLP1,H=0];
	P←MAPVA←(MDR) U (ACBASE), A1, CALL[RREFX];
*INDIRECTING THROUGH AC DOESN'T INCREMENT ICTR
INDLP2:	Q←(P) U (ILE), P←ICTR, GOTO[.+2,G=1];
	ICTR←P+1, P←ISPLIT←MDR, SETSF[INTCONDH], GOTO[INDLP1];
	LEFADR←Q, Q←RMQ, CALL[LOADMAP];
	GOTO[INDLP];

XMAPL:	REFADR←P←Q, BAMASK[22], Q←XLE;
	LEFADR←P OR Q, Q←XMQ, CALL[LOADMAP];
*ENTRY HERE WITH PC IN P AFTER MAPVA←PC, 1 IN Q
REMAP1:	XREF, Q←P+Q, P←777777R, SETSF[INTCONDH], DGOTO[XRAC,G=1];
	OLDPC←P←Q←P AND Q, CLEARF[TFLAGS], GOTO[PI1,H=1];
XR2:	PC←Q, Q←P-1, P←ICTR, GOTO[XMAPL,G=1];
XREMAP:	XSPLIT←P←MDR, ICTR←P+1, SETSF[LOGF&K], CALL[REMAPE];

REMAPPC:	ENDM;

XJAC:	OLDPC←P←Q←P AND Q;
XRAC:	PC←Q, Q←LX, P←ICTR, DGOTO[REMAPPC];
	SETSF[LOGF&K], P←XSPLIT←Q, ICTR←P+1, CALL[REMAPE];

XJMP:	XREF, Q←1R, SETSF[INTCONDH], DGOTO[XJAC,G=1];
	Q←P+Q, P←777777R, CLEARF[TFLAGS], DGOTO[PI1,H=1];
	OLDPC←P←Q←P AND Q, GOTO[XR2,H=0];

%NPC HOLDS 1ST INSTRUCTION DISPATCH.  INSTRUCTIONS BELOW ARE OPTIONAL
CONTINUATIONS FROM "REMAPE".
I = 3
%
LOGI:	RMW←(LOGT) U (Y), INHINT, CALL[LOGOP];

%THE "LOGF" FLAG CAUSES THE OPCODE TO BE COUNTED IN THE TABLE POINTED
TO BY "LOGT" WHICH MUST BEGIN AT A 1000-WORD BOUNDARY.  "BLT" LOGGING
ISN'T HANDLED CORRECTLY BY THIS, NOR IS INDIRECTION.
%
LOGOP:	P, CALL[PMDR];
BRKRET:	MDR←P+1, WRESTART, P←INSTR, Q←LINDX, GOTO[BINDE];

%THE "LOGF" FLAG CAUSES THE BREAK AND SINGLE-STEP FEATURE TO BE INVOKED.
SINGLE-STEP IF "LOGT" = 0, ELSE COMPARE "LOGT" TO "PC" AND BREAK IF THEY
ARE EQUAL.  CONTINUING FROM THE BREAK WORKS FINE.

BRKI:	Q←LOGT, CALL[BRKTST];

BRKTST:	AQ, P←PC;
	P←P-1, FRZBALUBC, DGOTO[BRKRET,ALU=0];
	P#Q, SETSF[K], CALL[SPUNT,ALU=0];
	CALL[SPUNT,ALU=0];
%

%ROUTINES TO SETUP THE ARGUMENTS FOR A TASK IN A STANDARD FORM.
MOST PDP-10 INSTRUCTIONS COME IN GROUPS, EACH ELEMENT OF WHICH
PERFORMS THE SAME CONCEPTUAL TASK BUT GETS ITS ARGUMENTS IN A
DIFFERENT WAY OR STORES AWAY ITS RESULTS IN A DIFFERENT WAY.
THE MAIN LOOP LEAVES E IN P AND AC IN Q.  THIS IS THE STANDARD FORM
FOR IMMEDIATE INSTRUCTIONS.  NON-IMMEDIATE INSTRUCTIONS USUALLY
LEAVE [E] IN P AND AC IN Q, ALSO.
RARG AND RMWARG ARE CALLED AFTER MAPVA←P←E.  THEY LEAVE MEMORY DATA [E]
IN P AND THE AC IN Q.  WHEN THE FETCH IS NOT FROM AN AC, THE MEMORY
DATA IS ALSO LEFT IN WDATA.
I = 13
%
RMAPL:	LEFADR←P, Q←RMQ, CALL[LOADMAP];
RARG:	RREF, Q←REFADR←P, GOTO[.+3,G=0], P←LX;
	Q←LAC, RETURN[H=0], STEMP←Q;
	MAPVA←Q←(X) U (ACBASE), A1, CALL[RREFX];  *FOR THE AC TEST MUST DO A1
	GOTO[RMAPL,G=1], P←(RLE) U (Q);
TPMDR:	STEMP←Q;	*FOR MULTIPLY AND ANY OTHER INSTRUCTIONS
			*WHICH DO A READ FOLLOWED BY A WRITE
			*RATHER THAN A READ-MODIFY-WRITE REFERENCE
RARG1:	WDATA←P←MDR, Q←LAC, RETURN;

RW0:	P←(RMWLE) U (Q), GOTO[RARG1,G=0];
	LEFADR←P, Q←RMWMQ, CALL[LOADMAP];
RMWARG:	RMWREF, Q←REFADR←P, P←LX, GOTO[RW0,G=0], INHINT;
	Q←LAC, RETURN[H=0];
	MAPVA←Q←(X) U (ACBASE), A1;
	RMWREFDXK, INHINT, GOTO[RW0];

%THOSE SUBROUTINES WHICH CAN OVERLAP WORK WITH MEMORY FETCH TIME
GENERALLY LEAVE THE MEMORY ARGUMENT IN MDR.  RTOMDR RETURNS AC IN P,
1 000001 IN Q.  USED BY PUSH, DATAO PI
I = 8
%
RM0:	P←LAC, Q←(2 000002R) RSH 1, RETURN[G=0], STEMP←Q;
	P←STEMP, DGOTO[RTOMDR];
	Q←RMQ, LEFADR←P, CALL[LOADMAP];
*USED BY POP AND POPJ
POPX:	RTEMP←P, P←Q, SETF[J], CALL[JUMPA];
RTOMDR:	RREF, Q←(REFADR←P) U (RLE), P←LX, GOTO[RM0,G=0];
	MDR←P, Q←(2 000002R) RSH 1, RETURN[H=0], P←LAC;
	MAPVA←Q←(X) U (ACBASE), A1;
	RREFDXK, Q←(Q) U (RLE), GOTO[RM0];

%IQARG, RQARG, AND RMWQARG REVERSE AC AND E (OR [E]) AS LEFT BY
MAIN LOOP, RARG, AND RMWARG, RESPECTIVELY.
I = 13
%
*USED BY SUBI, HRLI, HRLZI, HRLOI, HRLEI, HLROI
IQARG:	Q←P, P←LAC, RETURN;

*USED BY SUB, HRL,HRLZ, HLRZ, HLRO, HLR, HRLE, HRLO, KGO
RQL:	LEFADR←P, Q←RMQ, CALL[LOADMAP];
RQARG:	RREF, REFADR←P, GOTO[.+3,G=0], Q←LX;
	P←LAC, RETURN[H=0];
	MAPVA←P←(X) U (ACBASE), A1, CALL[RREFX];
	GOTO[RQL,G=1], P←(RLE) U (P);
	WDATA←Q←MDR, P←LAC, RETURN;

*USED BY SUBM, SUBB, HLROS, HLRZS, HRLES, HRLOS, HRLZS, MOVSS
RWQ0:	P←(RMWLE) U (P), GOTO[.-1,G=0];
	LEFADR←P, Q←RMWMQ, CALL[LOADMAP];
RMWQARG: RMWREF, REFADR←P, Q←LX, GOTO[RWQ0,G=0], INHINT;
	P←LAC, RETURN[H=0];
	MAPVA←P←(X) U (ACBASE), A1;
	RMWREFDXK, INHINT, GOTO[RWQ0];

%SRARG AND ESWAP ARE THE SAME AS RARG AND THE MAIN LOOP EXCEPT THAT
THEY RCY THE MEMORY ARGUMENT 22 BEFORE RETURNING.  THESE ARE USED BY THE
TEST-AND-SET AND MOVS INSTRUCTIONS.
I = 8
%
ESWAP:	Q←P, SETSF[H];
SRAC:	PQ RCY [22], Q←LAC, RETURN[H=0];
	MAPVA←P←(X) U (ACBASE), A1, CALL[RREFX];
	GOTO[SRARG0,G=0], Q←RLE;
	LEFADR←P OR Q, Q←RMQ, CALL[LOADMAP];
SRARG:	RREF, GOTO[SRAC,G=1], P←Q←LX, REFADR←P;
	GOTO[.-2,G=1], P←REFADR, Q←RLE;
SRARG0:	P←Q←MDR, CLEARF[H], GOTO[SRAC];

%ROUTINES TO SETUP THE ARGUMENTS FOR THE VARIOUS HALF-WORD INSTRUCTIONS.
THESE ALL LEAVE THE INDICATED ARGUMENT IN P AND 777777 IN Q, WITH
REFADR HOLDING E.
***ELIMINATE AT THE COST OF 1 CYCLE BY USING "RARG" FOLLOWED BY "EHARG"
I = 15
%
*USED BY HLL, HLLZ, HLLO, HLLE, HRR, HRRZ, HRRO
RHL:	LEFADR←P, Q←RMQ, CALL[LOADMAP];
RHARG:	RREF, REFADR←P, GOTO[.+3,G=0];
	P←LX, Q←777777R, RETURN[H=0];
	MAPVA←P←(X) U (ACBASE), A1, CALL[RREFX];
	GOTO[RHL,G=1], P←(P) U (RLE);
	WDATA←P←MDR, Q←777777R, RETURN;

*USED BY HLLM , HRLM, HRLS, HLLZS
RWH0:	GOTO[.-1,G=0], P←(P) U (RMWLE);
	LEFADR←P, Q←RMWMQ, CALL[LOADMAP];
RMWHARG: RMWREF, INHINT, REFADR←P, GOTO[RWH0,G=0];
	P←LX, Q←777777R, RETURN[H=0];
	MAPVA←P←(X) U (ACBASE), A1;
	RMWREFDXK, INHINT, GOTO[RWH0];

EHARG:	Q←777777R, RETURN;

*USED BY HLLI, HLLZM, HLLOM, HLLEM, HLRI, HRROM
ACHARG: REFADR←P, P←LAC, Q←777777S, RETURN;

*FREQUENT USAGE
Q22H:	REFADR←P, QQ RCY [22], INHINT, Q←777777S, RETURN;

%FINISHING ROUTINES

ACCEPT DATA IN Q, WRITE ADDRESS IN P.
MOVEM GOES TO WREFQ DIRECTLY FROM THE MAIN LOOP SO IT IS IMPORTANT FOR THE
INSTRUCTION AT WQTOP TO DO NO MORE THAN THE EXIT INSTRUCTION OF THE
MAIN LOOP.
I = 42
%
*"WQTOP" ALSO EXECUTED WITH A DGOTO PENDING AT IOD+10
WQTOP:	MAPVA←P←P, SAMASK[22];
WREFQ:	WREF, REFADR←P, MDR←Q, GOTO[QTOLX,G=1];
WQTOP0:	P←(P) U (WLE), GOTO[REMAPPC,G=0];
	Q←WMQ, CALL[LOADMAP], LEFADR←P;
	WREF, Q←MDR←WDATA, GOTO[WQTOP0,G=0];
QTOLX:	GOTO[QTOMAC,H=0], P←(X) U (ACBASE);
	MAPVA←P←(P) U (WLE);
	WREFDXK, MDR←Q, GOTO[WQTOP0];

%"WREFP" WRITES DATA IN P TO ADDRESS IN REFADR.
MAPVA←WRITE ADDRESS MUST ALREADY HAVE BEEN DONE.  USED BY MOVSM.
%
HLREM:	REFADR←P, P←LAC, B←Q;
HLREM1:	PQ RCY [22], SAMASK[22], Q←777777R, GOTO[WPONQM,B<0];
WREFP:	WREF, MDR←Q←P, GOTO[QTOLX,G=1], P←REFADR;
	GOTO[WQTOP0];

*FINISHING ROUTINE TO WRITE DATA ALREADY IN MDR TO ADDRESS IN P
*MAPVA←P ALREADY DONE.  ENTERED FROM HLLEM, POP, LMOVEM
WTOP1:	WREF, REFADR←P, GOTO[QTOLX,G=1], Q←MDR;
	GOTO[WQTOP0];

MAGQTOP: GOTO[WREFQ,ALU>=0]; *USED BY MOVMM
NEGQTOP: REFADR←P, P←1S, WREF, DGOTO[QTOLX,G=1], INHINT;  *USED BY MOVNM
*REMEMBER THAT SETOVPC01 WON'T WORK ON P+1
	MDR←Q←P-Q-1, SETOVPC01, P←REFADR;
	GOTO[WQTOP0];

*SAVE 1 UINST PER ROUTINE BELOW AT COST OF 1 CYCLE TIME
WPAQM:	WREF, P←REFADR, MDR←Q←P AND Q, GOTO[QTOLX,G=1];
	GOTO[WQTOP0];
WPANQM:	WREF, MDR←Q←P AND NOT Q, P←REFADR, GOTO[QTOLX,G=1];
	GOTO[WQTOP0];
WPOQM:	WREF, MDR←Q←P OR Q, P←REFADR, GOTO[QTOLX,G=1];
	GOTO[WQTOP0];
WPONQM:	WREF, MDR←Q←P OR NOT Q, P←REFADR, GOTO[QTOLX,G=1];
	GOTO[WQTOP0];
NQB:	WREF, MDR←LAC←Q←NOT Q, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];
NQM:	WREF, MDR←Q←NOT Q, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];
SETZM:	WREF, MDR←Q←A0, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];
SETZB:	WREF, MDR←Q←LAC←A0, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];
SETOM:	WREF, MDR←Q←A1, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];
SETOB:	WREF, MDR←LAC←Q←A1, GOTO[QTOLX,G=1];
	REFADR←P, GOTO[WQTOP0];

HLLEM:	MDR←P AND NOT Q, DGOTO[WTOP1];
	Q←P OR Q, GOTO[WREFQ,ALU<0], P←REFADR;

HRREM:	REFADR←P, QQ RCY [22];
	B←Q←P, GOTO[HLREM1];

%FINISHING ROUTINES WHICH LEAVE RESULT IN AC
I = 25
%
MAGPTOAC: LAC←P, DGOTO[REMAPPC];
MINP:	P←NOT P, Q←1S, GOTO[.+1,ALU<0]; *USED BY MOVN, MOVNI
P+QA:	LAC←P+Q, SETOVPC01, ENDM; *USED BY DFN, ADD, ADDI

PIRDX:	Q←200000S, GOTO[POQA,K=1]; *USED BY PIREAD JMC
PTOAC:	LAC←P, ENDM;
*QTOAC: LAC←Q, ENDM;  *IN "ARITH"
*SETZ:  LAC←A0, ENDM; *IN "ARITH"
SETO:	LAC←A1, ENDM;
NPAQA:	LAC←NOT P AND Q, ENDM;
PXQA:	LAC←P#Q, ENDM;
NPANQA:	LAC←NOT P AND NOT Q, ENDM;
PEQA:	LAC←P=Q, ENDM;
NQA:	LAC←NOT Q, ENDM;
NPA:	LAC←NOT P, ENDM;
NPOQA:	LAC←NOT P OR Q, ENDM;
NPONQA:	LAC←NOT P OR NOT Q, ENDM;
PAQA:	LAC←P AND Q, ENDM;
PANQA:	LAC←P AND NOT Q, ENDM;
*POQA:	LAC←P OR Q, ENDM; *IN "BS"
PONQA:	LAC←P OR NOT Q, ENDM;
HLLA:	Q←P AND NOT Q, P←LAC, SAMASK[22], GOTO[POQA];

HLLEA:	LAC←P AND NOT Q, DGOTO[QTOAC];
	Q←P OR Q, GOTO[REMAPPC,ALU>=0];

HRRA:	MDR←P AND Q, P←LAC;
	P←(MDR) U (P AND NOT Q), GOTO[PTOAC];

HRREA:	Q←400000S, POP;
	P AND Q, Q←777777R, DGOTO[PONQA];
	LAC←P AND Q, RETURN[ALU=0];

HLREA:	P, PQ RCY [22], SAMASK[22], Q←777777R, DGOTO[PONQA], POP;
	LAC←P AND Q, RETURN[ALU>=0];

%FINISHING ROUTINES FOR RMW INSTRUCTIONS.  G MUST NOT HAVE CHANGED
DURING MODIFY.  HENCE G=0 ON NORMAL AND ACBASE REFERENCES AND
G=1 ONLY FOR AC REFERENCES.
I = 62
%
PTOMAC:	LX←P, ENDM;
QTOMCHK: GOTO[REMAPPC,G=0];
QTOMAC:	LX←Q, ENDM;
QTOM:	MDR←Q, WRESTART, GOTO[QTOMCHK];
PTOM:	MDR←Q←P, WRESTART, GOTO[QTOMCHK];
PTOB:	LAC←Q←MDR←P, WRESTART, GOTO[QTOMCHK];
PTOS:	LACS←Q←MDR←P, WRESTART, GOTO[QTOMCHK];
PAQS:	LACS←MDR←Q←P AND Q, WRESTART, GOTO[QTOMCHK];
POQS:	LACS←MDR←Q←P OR Q, WRESTART, GOTO[QTOMCHK];
PONQS:	LACS←MDR←Q←P OR NOT Q, WRESTART, GOTO[QTOMCHK];
PANQS:	LACS←MDR←Q←P AND NOT Q, WRESTART, GOTO[QTOMCHK];
PAQM:	MDR←Q←P AND Q, WRESTART, GOTO[QTOMCHK];
PAQB:	LAC←MDR←Q←P AND Q, WRESTART, GOTO[QTOMCHK];
PANQM:	MDR←Q←P AND NOT Q, WRESTART, GOTO[QTOMCHK];
PANQB:	LAC←MDR←Q←P AND NOT Q, WRESTART, GOTO[QTOMCHK];
NPAQM:	MDR←Q←NOT P AND Q, WRESTART, GOTO[QTOMCHK];
NPAQB:	LAC←MDR←Q←NOT P AND Q, WRESTART, GOTO[QTOMCHK];
PXQM:	MDR←Q←P#Q, WRESTART, GOTO[QTOMCHK];
PXQB:	LAC←MDR←Q←P#Q, WRESTART, GOTO[QTOMCHK];

POQM:	MDR←Q←P OR Q, WRESTART, GOTO[QTOMCHK];
POQB:	LAC←MDR←Q←P OR Q, WRESTART, GOTO[QTOMCHK];
NPANQM: MDR←Q←NOT P AND NOT Q, WRESTART, GOTO[QTOMCHK];
NPANQB: LAC←Q←MDR←NOT P AND NOT Q, WRESTART, GOTO[QTOMCHK];
PEQM:	MDR←Q←P=Q, WRESTART, GOTO[QTOMCHK];
PEQB:	LAC←MDR←Q←P=Q, WRESTART, GOTO[QTOMCHK];
PONQM:	MDR←Q←P OR NOT Q, WRESTART, GOTO[QTOMCHK];
PONQB:	LAC←Q←MDR←P OR NOT Q, WRESTART, GOTO[QTOMCHK];
NPM:	MDR←Q←NOT P, WRESTART, GOTO[QTOMCHK];
NPB:	LAC←Q←MDR←NOT P, WRESTART, GOTO[QTOMCHK];
NPOQM:	MDR←Q←NOT P OR Q, WRESTART, GOTO[QTOMCHK];
NPOQB:	LAC←MDR←Q←NOT P OR Q, WRESTART, GOTO[QTOMCHK];
NPONQM:	MDR←Q←NOT P OR NOT Q, WRESTART, GOTO[QTOMCHK];
NPONQB:	LAC←MDR←Q←NOT P OR NOT Q, WRESTART, GOTO[QTOMCHK];

*! MAXC1 ONLY
HLLM:	WRESTART, MDR←P AND Q, P←LAC, DGOTO[QTOMAC];
	Q←(MDR) U (P AND NOT Q), INHINT, GOTO[WABS,G=0]; **SHORT PATH PROBLEM

HRLM:	MDR←P AND Q, Q←LAC, DGOTO[.-1]; **SHORT PATH PROBLEM
	REFADR←P, QQ RCY [22], WRESTART, Q←777777S, DGOTO[QTOMAC];

*EXTRA WRESTART SHOULDN'T HURT
HLRM:	MDR←P AND NOT Q, P←Q←LAC, WRESTART;
	PQ RCY [22], SAMASK[22], Q←MDR, INHINT, GOTO[POQM];

HRRM:	WRESTART, MDR←P AND NOT Q, P←LAC, DGOTO[QTOMAC,G=1]; **SHORT PATH PROBLEM
	Q←(MDR) U (P AND Q), INHINT, GOTO[WABS,G=0];
*!
*~ MAXC2 ONLY (READING MDR AFTER WRESTART ILLEGAL ON MAXC2)
POQMAC:	LX←P OR Q, ENDM;

HLLM:	WRESTART, RTEMP←P AND Q, P←LAC;
	P←P AND NOT Q, Q←RTEMP, INHINT, GOTO[POQMAC,G=1];
POQMM:	MDR←P OR Q, GOTO[REMAPPC];
HRLM:	RTEMP←P AND Q, Q←LAC, DGOTO[.-2];
	REFADR←P, QQ RCY [22], WRESTART, Q←777777S;

HLRM:	RTEMP←P AND NOT Q, P←Q←LAC, WRESTART, DGOTO[POQMM];
	PQ RCY [22], SAMASK[22], Q←RTEMP, INHINT, GOTO[POQMAC,G=1];

HRRM:	WRESTART, RTEMP←P AND NOT Q, P←LAC, DGOTO[POQMM];
	P←P AND Q, Q←RTEMP, INHINT, GOTO[POQMAC,G=1];
*~

HRLS:	P←Q←P AND Q, POP, WRESTART;
	PQ RCY [22], INHINT, DGOTO[REMAPPC];
	MDR←LACS←Q←P OR Q, GOTO[QTOMAC,G=1];

HLRS:	P←Q←P AND NOT Q, WRESTART, POP, GOTO[.-2];

HLLES:	WRESTART, LACS←MDR←P AND NOT Q, GOTO[HLLESAC,G=1];
	INHINT, RETURN[ALU>=0];
	LACS←MDR←P OR Q, RETURN;

HLLESAC: LX←P AND NOT Q, RETURN[ALU>=0];
	LACS←Q←P OR Q, GOTO[QTOMAC];

HLRES:	P, PQ RCY [22], Q←777777R, WRESTART, GOTO[HLRESAC,G=1];
	LACS←MDR←P AND Q, INHINT, RETURN[ALU>=0];
	LACS←MDR←P OR NOT Q, RETURN;

HLRESAC: LACS←P←P AND Q, GOTO[PTOMAC,ALU>=0];
	LACS←Q←P OR NOT Q, GOTO[QTOMAC];

*~ MAXC2 ONLY (EXTRA WRESTART IS NO GOOD ON MAXC2)
MAGPTOS: LACS←MDR←P, WRESTART, GOTO[MAGPTOSAC,G=1];
	P←NOT P, Q←1S, INHINT, GOTO[REMAPPC,ALU>=0];
	LACS←MDR←Q←P+Q, SETOVPC01, GOTO[REMAPPC];

MAGPTOSAC: NOT(LX←P)Q RCY [0], Q←1R, GOTO[REMAPPC,ALU>=0];
	LACS←Q←P+Q, SETOVPC01, GOTO[QTOMAC];

NEGPS:	P←NOT P, Q←1R, WRESTART, DGOTO[QTOMAC];
	LACS←MDR←Q←P+Q, SETOVPC01, GOTO[REMAPPC,G=0];
*~
*! MAXC1 ONLY
MAGPTOS: LACS←MDR←P, WRESTART, GOTO[MAGPTOSAC,G=1];
	P←NOT P, Q←1S, INHINT, GOTO[REMAPPC,ALU>=0];
P+QS:	LACS←MDR←Q←P+Q, SETOVPC01, WRESTART, GOTO[QTOMCHK];
MAGPTOSAC: LX←P, GOTO[REMAPPC,ALU>=0];
NEGPS:	P←NOT P, Q←1S, GOTO[P+QS];
*!

NOOPR:	P←P, FRZBALUBC;