ER[DG2B];

TARGET[ILC];

%DG2B MUST BE ASSEMBLED WITH DG1 FOR MAXC2, DG2A WITH DG1 FOR MAXC 1.
IT CONTAINS ALL THE FLAG REGISTER TEST ROUTINES, BASIC IM READING AND
WRITING, AND OTHER TESTS PECULIAR TO EACH MACHINE.
%

*TEST OF TENF SOURCE
TENFT:	SETF[-1S], Q←A1, CALL[Q27];	*Q←37 777777
	P←TENF, CALL[PEQZ];	*BREAK IF P # 777740 000000
	CLEARF[-1S], P←B, B←Q;
	Q←TENF, CALL[QZT];	*BREAK IF Q # 0
	Q←P;
	STEMP←Q;
	P←B, B←NOT Q, SETF[STEMP];
	Q←TENF, CALL[QZT];	*TENF=0 WHEN F=37 777777

*TEST OF SAX
SAXT:	P←NULL;
	Q←P+1, SAX[1], CALL[PXCOMP];	*SAX[1] FAILED
	Q LSH 1, SAX[2], CALL[PXCOMP];	*SAX[2] FAILED
	Q LSH 1, SAX[4], CALL[PXCOMP];	*SAX[4] FAILED
	Q LSH 1, SAX[10], CALL[PXCOMP];	*SAX[10] FAILED
	Q LSH 1, SAX[20], CALL[PXCOMP];	*SAX[20] FAILED
	Q LSH 1, SAX[40], CALL[PXCOMP];	*SAX[40] FAILED
	Q LSH 1, SAX[100], CALL[PXCOMP]; *SAX[100] FAILED
	Q LSH 1, SAX[200], CALL[PXCOMP]; *SAX[200] FAILED

*TEST OF BAX
BAXT:	P←NULL;
	Q←P+1, BAX[1];
	P←X, CALL[PQCOMP];	*Z[BAX[1]] FAILED
	X←A1;
	BAX[1], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[1]] FAILED
	Q LSH 1, BAX[2];
	P←X, CALL[PQCOMP];	*Z[BAX[2]] FAILED
	X←A1;
	BAX[2], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[2]] FAILED
	Q LSH 1, BAX[4];
	P←X, CALL[PQCOMP];	*Z[BAX[4]] FAILED
	X←A1;
	BAX[4], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[4]] FAILED
	Q LSH 1, BAX[10];
	P←X, CALL[PQCOMP];	*Z[BAX[10]] FAILED
	X←A1;
	BAX[10], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[10]] FAILED
	Q LSH 1, BAX[20];
	P←X, CALL[PQCOMP];	*Z[BAX[20]] FAILED
	X←A1;
	BAX[20], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[20]] FAILED
	Q LSH 1, BAX[40];
	P←X, CALL[PQCOMP];	*Z[BAX[40]] FAILED
	X←A1;
	BAX[40], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[40]] FAILED
	Q LSH 1, BAX[100];
	P←X, CALL[PQCOMP];	*Z[BAX[100]] FAILED
	X←A1;
	BAX[100], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[100]] FAILED
	Q LSH 1, BAX[200];
	P←X, CALL[PQCOMP];	*Z[BAX[200]] FAILED
	X←A1;
	BAX[200], NOZ;
	P←X, CALL[PQCOMP];	*BS[BAX[200]] FAILED

*TEST OF AX
AXT:	P←NULL, AX[1];
	Q←P+1, P←X, CALL[PQCOMP];	*AX[1] FAILED
	Q LSH 1, AX[2], CALL[PXCOMP];	*AX[2] FAILED
	Q LSH 1, AX[4], CALL[PXCOMP];	*AX[4] FAILED
	Q LSH 1, AX[10], CALL[PXCOMP];	*AX[10] FAILED
	Q LSH 1, AX[20], CALL[PXCOMP];	*AX[20] FAILED

*TEST OF BAT
BATT:	P←NULL;
	Q←P+1, P←1IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 1
	Q LSH 1, P←2IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 2
	Q LSH 1, P←4IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 4
	Q LSH 1, P←10IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 10
	Q LSH 1, P←20IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 20
	Q LSH 1, P←40IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 40
	Q LSH 1, P←100IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 100
	Q LSH 1, P←200IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 200
	Q LSH 1, P←400IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 400
	Q LSH 1, P←1000IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 1000
	Q LSH 1, P←2000IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 2000
	Q LSH 1, P←4000IB;
	CALL[PQCOMP];		*BS[BAT] FAILED ON 4000

BATTZ:	P←NULL;
	Q←P+1, P←(1IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 1
	Q LSH 1, P←(2IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 2
	Q LSH 1, P←(4IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 4
	Q LSH 1, P←(10IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 10
	Q LSH 1, P←(20IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 20
	Q LSH 1, P←(40IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 40
	Q LSH 1, P←(100IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 100
	Q LSH 1, P←(200IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 200
	Q LSH 1, P←(400IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 400
	Q LSH 1, P←(1000IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 1000
	Q LSH 1, P←(2000IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 2000
	Q LSH 1, P←(4000IB) U (NULL);
	CALL[PQCOMP];		*Z[BAT] FAILED ON 4000

*TEST OF SM HIGH
SMHIT:	Q←A1, Y←NULL, DGOTO[.+1];
	Q LSH 1, CALL[QL3]; *Q←777777 777400
	P←B, B←Q;
	SY←Q, INCY;		*INIT SM 0-377 DISTINCTIVELY
	P←Q←B, B←P+1, GOTO[.-1,Y>=0];
	P←Q←NULL;
	SY←Q, INCY;		*INIT SM 400-777 WITH LOW 8 BITS OF ADDRESS
	P←Q←B, B←P+1, GOTO[.-1,Y<0];
*FIRST INITIATE READ USING THE BS FIELD
*FOR SA .L. 20, READSH HAS NO EFFECT
SMHIT1:	P←NULL;
	Q←P+1, CALL[QL3];
	Q LSH 1, P←H$, SA[20], CALL[PQCOMP];	*BS[READSH] FAILED ON SA=20
	Q LSH 1, P←H$, SA[40], CALL[PQCOMP];	*BS[READSH] FAILED ON SA=40
	Q LSH 1, P←H$, SA[100], CALL[PQCOMP];	*BS[READSH] FAILED ON SA=100
	Q LSH 1, P←H$, SA[200], CALL[PQCOMP];	*BS[READSH] FAILED ON SA=200

*NEXT INITIATE FROM F1 FIELD
SMHIT2:	P←NULL;
	Q←P+1, CALL[QL3];
	Q LSH 1, P←(H$) U (NULL), SA[20], CALL[PQCOMP];	*F1[READSH] FAILED ON SA=20
	Q LSH 1, P←(H$) U (NULL), SA[40], CALL[PQCOMP];	*F1[READSH] FAILED ON SA=40
	Q LSH 1, P←(H$) U (NULL), SA[100], CALL[PQCOMP];	*F1[READSH] FAILED ON SA=100
	Q LSH 1, P←(H$) U (NULL), SA[200], CALL[PQCOMP];	*F1[READSH] FAILED ON SA=200

*TEST OF EREG WRITTEN FROM Q, ALU, AND SM
EREGT:	Q←A1, CALL [EREGTX];
	P←NULL;
	Q←P+1, CALL[EREGTX];
	Q LCY 1, CALL[EREGTX];
	GOTO[.-1,Q EVEN];
	GOTO[DG2END];

EREGTX:	STEMP←Q;
	P←EREG, CALL[PQCOMP];	*EREG WRITTEN FROM Q WAS P SHOULD BE Q
	B←Q←NOT Q;
	P←EREG, CALL[PQCOMP];	*EREG WRITTEN FROM ALU WAS P SHOULD BE Q
	STEMP1←Q;
	Q←STEMP;
	P←EREG, CALL[PQCOMP];	*EREG WRITTEN FROM SM WAS P SHOULD BE Q
	Q←STEMP1;
	P←EREG, CALL[PQCOMP];	*EREG WRITTEN FROM SM WAS P SHOULD BE Q
	Q←STEMP, RETURN;

*F-REGISTER TEST ROUTINES
FZT:	P←FLAGS, GOTO[PZT];		*BREAK IF F ISN'T = 0

NFZT:	P←FLAGS, GOTO[NPZT];	*BREAK IF NOT F ISN'T 0

FQEQ:	P←FLAGS, GOTO[PQCOMP];	*BREAK IF F#Q

FQNEQ:	P←FLAGS, GOTO[PEQZ];	*BREAK IF NOT F # Q

FPEQ:	Q←FLAGS, GOTO[PEQZ];	*BREAK IF NOT F ISN'T = P

F1T:	P←FLAGS;
	Q←P-1, GOTO[AZT];		*BREAK IF F ISN'T 1

PXCOMP:	P←X, GOTO[PQCOMP];	*COMPARE X TO Q

DG2END:	GOTO[MCYCLE];		*END OF DG2.  THIS INSTRUCTION OVERWRITTEN
				*IF MORE DIAGNOSTICS ARE LOADED
IM[ILC,ADD[IP[ILC],-1]];