ER[DGREG];

%TO ASSEMBLE:	@MI@ DGREG
TO RUN:		MIDAS DGREG
		START;G

THIS DIAGNOSTIC TESTS ASSORTED REGISTERS WITH RANDOM NUMBERS.  DGBASIC AND
DGP MUST WORK BEFORE THIS IS TRIED.  PROBABLY DGRL, DGALU, DGIMH, AND DGIML
SHOULD BE TESTED FIRST, BUT NOT NECESSARILY.

THE DIAGNOSTIC PERMITS INDIVIDUAL REGISTERS TO BE TESTED IN A LOOP BY
MANUALLY LOADING Y WITH 777 AND STARTING AT THE APPROPRIATE PLACE.
%

SM[SLC,0]; RM[RLC,0]; LM[LLC,10];

TARGET[SLC];

400000 000000V;	200000 000000V;	100000 000000V;
 40000 000000V;	 20000 000000V;	 10000 000000V;
  4000 000000V;	  2000 000000V;	  1000 000000V;
   400 000000V;	   200 000000V;	   100 000000V;
    40 000000V;	    20 000000V;	    10 000000V;
     4 000000V;	     2 000000V;	     1 000000V;
400000V;		200000V;		100000V;
 40000V;		 20000V;		 10000V;
  4000V;		  2000V;		  1000V;
   400V;		   200V;		   100V;
    40V;		    20V;		    10V;
     4V;		     2V;		     1V;
-1S: 777777 777777V;

RV[X0,7654321];
RV[X1,76543210];
RV[X2,765432100];
RV[X3,7654321000];
RV[X4,76543210000];
RV[X5,765432100000];
RV[X6,654321000007];
RV[X7,543210000076];

LVN[RAN]; LVN[RRAN]; LVN[XRAN]; LVN[COUNT];

LVN[TEMP]; RVN[RTEMP]; RVN[ICOUNT];

LVN[LDATA]; RV[LMASK,777777 777777]; LVN[LBASE];
RVN[RDATA]; LV[RMASK,777777 777777]; RVN[RBASE];
RV[WLOOK,0]; RV[RLOOK,0];
SVN[ADDR]; SVN[STEMP]; SVN[STEMP1]; RV[AINC,1];

IM[ILC,0]; TARGET[ILC];

REPEAT[20,ILC[BRKP[1]]];

MCYCLE:	BRKP[1], COUNT←P+1, GOTO[LOOP];
START:	ARM←NULL, INHINT;
	IRET, INHINT, COUNT←A0, GOTO[LOOP];

PQCOMP:	P#Q;
	RETURN[ALU=0];
CBRK:	BRKP[1], RETURN;

*RETURN RANDOM NO. IN Q AND RAN
*(USES X WHICH MUST NOT BE CLOBBERED), CLOBBERS P
RGEN:	P←RAN, Q←RX, GOTO[RGEN1,X>=0];
	Q←X7, DGOTO[6];
	X←NPC, RAN←X7←Q←P+Q, RETURN;

RGEN1:	RX←RAN←Q←P+Q, DECX, RETURN;

*SAVE RANDOM NO. GEN. STATE IN LM FOR RESTORATION LATER.  RETURN RANDOM NO. IN Q.
RMARK:	P←X, DGOTO[7], Q←RAN;
	X←NPC, RRAN←Q, GOTO[.+1];
	Q←RX, XRAN←P, GOTO[.+2,X<0];
	LX←Q, DECX, GOTO[.-1];
PXRET:	X←P, Q←RAN, GOTO[RGEN];

*RESTORE RANDOM NO. GEN FROM LM
RREST:	P←RRAN, DGOTO[7];
	X←NPC, RAN←P, GOTO[.+1];
	Q←LX, GOTO[PXRET,X<0];
	RX←Q, P←XRAN, DECX, GOTO[.-1];

*START HERE--USE Y<0 TO INDICATE REPEATED ITERATIONS.  SET Y > 0 TO
*CAUSE REPEATED ITERATION OF ONE TEST
LOOP:	Y←NULL;
*~ MAXC2 ONLY
	CALL[EREGSM];
	CALL[EREGQ];
	CALL[EREGALU];
*~
	CALL[FPTEST];
	CALL[FQTEST];
	CALL[SETSFF];
	CALL[SETSFT];
	P←COUNT, GOTO[MCYCLE];

*~ MAXC2 ONLY
*READ AND WRITE EREG FROM SM USING RANDOM DATA
EREGSM:	CALL[RGEN];
	STEMP←Q;
	B←NOT Q;
	B←STEMP, SIGNOVA, DGOTO[EREGSM,Y<0];
	P←EREG, CALL[PQCOMP];
	RETURN;

*READ AND WRITE EREG FROM Q USING RANDOM DATA
EREGQ:	CALL[RGEN];
	B←NOT Q;
	B←Q, SIGNOVA, DGOTO[EREGQ,Y<0];
	P←EREG, CALL[PQCOMP];
	RETURN;

*READ AND WRITE EREG FROM ALU USING RANDOM DATA
EREGALU: CALL[RGEN];
	B←Q←NOT Q, SIGNOVA, DGOTO[EREGALU,Y<0];
	P←EREG, CALL[PQCOMP];
	RETURN;

*SET AND CLEAR F FROM STEMP USING RANDOM DATA
*(READS F INTO P WHICH HAS AN EARLY -K1 LOADING CLOCK)
FPTEST:	CALL[RGEN];
	STEMP←Q;
	CLEARF[STEMP], MDR←P←FLAGS;
	Q←P AND NOT Q, KMDR←P←FLAGS, CALL[PQCOMP];	*CLEARF FAILED
	CALL[RGEN];
	STEMP←Q;
	SETF[STEMP], MDR←P←FLAGS;
	Q←P OR Q, KMDR←P←FLAGS, CALL[PQCOMP];		*SETF FAILED
	Q←37 777777L, P←FLAGS, DGOTO[FPTEST,Y<0];
	Q←P AND NOT Q, P←TENF, CALL[PQCOMP];		*TENF FAILED
	RETURN;

*SET AND CLEAR F FROM STEMP USING RANDOM DATA
*(READS F INTO Q WHICH HAS A LATE -K1 LOADING CLOCK)
FQTEST:	CALL[RGEN];
	STEMP←Q;
	CLEARF[STEMP], MDR←Q←FLAGS, P←Q;
	P←NOT P AND Q, KMDR←Q←FLAGS, CALL[PQCOMP];	*CLEARF FAILED
	CALL[RGEN];
	STEMP←Q;
	SETF[STEMP], P←Q, MDR←Q←FLAGS;
	P←P OR Q, KMDR←Q←FLAGS, CALL[PQCOMP];		*SETF FAILED
	P←A1, SAMASK[27], DGOTO[FPTEST,Y<0];
	P←NOT P AND Q, Q←TENF, CALL[PQCOMP];		*TENF FAILED
	RETURN;
*~
*! MAXC1 ONLY
FPTEST:	CALL[RGEN];
	STEMP←Q;
	CLEARF[STEMP], MDR←P←NOT F;
	Q←P OR Q, KMDR←P←NOT F, CALL[PQCOMP];		*CLEARF FAILED
	CALL[RGEN];
	STEMP←Q;
	SETF[STEMP], MDR←P←NOT F, DGOTO[FPTEST,Y<0];
	Q←P AND NOT Q, KMDR←P←NOT F, CALL[PQCOMP];	*SETF FAILED
	RETURN;

FQTEST:	CALL[RGEN];
	STEMP←Q;
	CLEARF[STEMP], MDR←Q←NOT F, P←Q;
	P←P OR Q, KMDR←Q←NOT F, CALL[PQCOMP];		*CLEARF FAILED
	CALL[RGEN];
	STEMP←Q;
	SETF[STEMP], P←Q, MDR←Q←NOT F, DGOTO[FQTEST,Y<0];
	P←NOT P AND Q, KMDR←Q←NOT F, CALL[PQCOMP];	*SETF FAILED
	RETURN;
*!

*TEST SETSF WITH RANDOM NUMBERS--TEST ALWAYS FALSE
SETSFF:	CLEARF[-1S], CALL[RGEN];
	STEMP←Q;
	SETF[STEMP], Q←NOT Q;
	STEMP←Q;
*~ MAXC2 ONLY
	Q←FLAGS, P←Q, AMASK[4], SETSF[STEMP], DGOTO[SETSFF,Y<0];
	Q←NOT P AND Q, P←FLAGS, CALL[PQCOMP];
*~
*! MAXC1 ONLY
	Q←NOT F, P←Q, AMASK[4], SETSF[STEMP], DGOTO[SETSFF,Y<0];
	Q←P OR Q, P←NOT F, CALL[PQCOMP];
*!
	RETURN;

*CYCLE THROUGH THE VARIOUS BITS IN F TESTING SETSF ON THAT BIT WITH
*RANDOM VALUES FOR G, H, J, AND K
SETSFT:	MDR←Y;		*PRESERVE Y DURING TEST
SETST1:	Y←NULL, CALL[SETSFY];		*ADDRESS TABLE OF 2↑N IN SM
	INCY, DGOTO[.];
	P←40R, Q←Y, CALL[.+1];
	P-Q;
	GOTO[SETSFY,ALU>0];		*RETURNS TO .-3
	Y←MDR, POP, DGOTO[SETST1];
	RETURN[Y>=0];

*TEST SETSF WITH RANDOM NUMBERS--TEST ALWAYS TRUE ON BIT SY ONLY
*RANDOM BITS IN G, H, J, AND K
SETSFY:	CLEARF[-1S], CALL[RGEN];
	Q←(Q) U (SY);
	STEMP←Q;
	SETF[STEMP], CALL[RGEN];
	P←Q, BAMASK[4], Q←SY;
	Q←P OR Q;
	STEMP←Q;
*~ MAXC2 ONLY
	SETSF[STEMP], Q←FLAGS;
	P←P OR Q, Q←FLAGS, GOTO[PQCOMP];
*~
*! MAXC1 ONLY
	SETSF[STEMP], Q←NOT F;
	P←NOT P AND Q, Q←NOT F, GOTO[PQCOMP];
*!