; DMT1Test.asm
; Copyright Xerox Corporation 1979
; Last modified November 21, 1979  7:30 PM by Boggs

	.TXTM B

.DUSR	BREAK = 77400	;CALLS THE DEBUGGER

; outgoing procedures
.ENT	A1INIT, A1TMF, A1TMS, A1PBC, A1PEINT

; incoming procedures
.BEXTZ	PMSG1, PDEC, POCT, RANDOM, ERROR

; incoming statics
.BEXTZ	SOM, EOM, VINT, pACT, pWW, pSAD, pDISPLAY
.BEXTZ	PEAC0, PEAC1, PEAC2, PEAC3, PEPC, pIRET
.BEXTZ	pSBCTAB, pEBCTAB

	.SREL

A1INIT:		.A1INIT
A1TMF:		.A1TMF
A1TMS:		.A1TMS
A1PBC:		.A1PBC
A1PEINT:	.A1PEINT

BLTTEST:	.BLTTEST
CONVERTTEST:	.CONVERTTEST
DISPLAYTEST:	.DISPLAYTEST
SWEEPTEST:	.SWEEPTEST

	.ZREL

pXNWRDS:	XNWRDS

LOGCHIP:	.LOGCHIP

BLKLEN:		0	;LENGTH OF SOURCE AND DEST BLOCKS
SRLOW:		0	;SOURCE BLOCK LOW ADDRESS
SRHIGH:		0	;1 PAST END OF SOURCE BLOCK
DLOW:		0	;DEST BLOCK LOW ADDRESS
DHIGH:		0	;1 PAST END OF DEST BLOCK
CHKSM:		0	;CHECKSUM OVER SOURCE BLOCK

PBCRET: 	0

C3:		3
C7:		7

;ERROR COUNTERS
MBCNT:		0	;LOGCHIP CALLS WITH MULTIPLE BAD BITS
CVERS:		0	;ERRORS DETECTED BY CONVERT
CFUNNY:		0	;ERRORS DETECTED BY CONVERT WITH ADDRESS DISAGREE
UNKSC:		0	;COUNT OF ERRORS FROM UNKNOWN SOURCE
SWPTAC:		0	;ERRORS IN TEST AREA DETECTED BY SWEEP
SWPCAC:		0	;ERRORS IN CODE AREA DETECTED BY SWEEP
BLKCHC:		0	;HARD ERRORS DETECTED IN BLOCK CHECK
BLKCNC:		0	;NORMAL ERRORS DETECTED IN BLOCKCHECK
BLTMFC:		0	;MULTIPLE ERRORS DETECTED IN SOURCE BLOCK BY BLT
BCHKSMC:	0	;ZERO ERRORS AND INCORRECT CHECKSUM (BLT)
PHANC:		0	;PHANTOM ERRORS DETECTED BY BLT
NADC:		0	;ONE ERROR (BLT) BUT ADDRESS DISAGREES
BLTBPBC:	0	;BAD PARITY BITS DETECTED BY BLT
BLTNSEC:	0	;BLT DETECTED NORMAL SINGLE BIT ERROR
CONVERTERRORS:	0	;ERRORS DURING CONVERT INSTRUCTION
DISPLAYERRORS:	0	;ERRORS CAUSED BY DISPLAY FETCHES
FUNNYADRC:	0	;COUNT OF ERRORS DETECTED BY SWEEP WITH
			;DISAGREEMENT ABOUT SOURCE ADDRESS

	.NREL

;-----------------------------------------------------------------------------
.A1INIT:JMP 1 3			;ALTO 1 TEST INITIALIZATION
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
.A1TMS:				;ALTO 1 TEST MEMORY SLOW
;-----------------------------------------------------------------------------
	STA 3 TMSRET

	JSRII ppSWEEPTEST	;SWEEP CORE 
	JSRII ppDISPLAYTEST	;TEST USING DISPLAY 

	LDA 3 TMSRET
	JMP 1 3			;SKIP RETURN

ppDISPLAYTEST:	DISPLAYTEST
ppSWEEPTEST:	SWEEPTEST
TMSRET:		0

;-----------------------------------------------------------------------------
.A1TMF:				;ALTO 1 TEST MEMORY FAST
;-----------------------------------------------------------------------------
	STA 3 TMFRET

;GENERATE A RANDOM LENGTH FOR THE TWO TEST BLOCKS
GLEN:	JSR @RANDOM
	LDA 1 C7777		;MUST BE LESS THAN 10K
	AND 1 0 SNR		;AND GREATER THAN 0
	 JMP GLEN
	STA 0 BLKLEN

;GET A SOURCE BLOCK WHICH FITS IN THE TEST AREA
	JSR GETBLK
	STA 0 SRLOW
	STA 1 SRHIGH

;GET A DESTINATION BLOCK WHICH FITS IN THE TEST AREA
;AND DOES NOT OVERLAP THE SOURCE BLOCK
GDST:	JSR GETBLK		;GET A TENTATIVE DESTINATION BLOCK
	LDA 2 SRHIGH
	SLTU 0 2
	 JMP DOK		;DEST LOW GREATER THAN SRC HIGH IS OK
	LDA 2 SRLOW
	SGTU 2 1
	 JMP GDST		;BLOCKS OVERLAP. PICK ANOTHER DESTINATION
DOK:	STA 0 DLOW
	STA 1 DHIGH

	JSRII ppBLTTEST		;TEST USING BLT INSTRUCTION
	JSR CLEARBB
	JSRII ppCONVERTTEST	;TEST USING CONVERT INSTRUCTION
	JSR CLEARBB

	LDA 3 TMFRET
	JMP 1 3			;SKIP RETURN

ppCONVERTTEST:	CONVERTTEST
ppBLTTEST:	BLTTEST
C7777:		7777
TMFRET:		0

;-----------------------------------------------------------------------------
 ;GET A BLOCK. DESIRED LENGTH IS IN BLKLEN
 ; RETURNS:	AC0: BLOCK LOW ADDRESS
 ;		AC1: BLOCK HIGH ADDRESS
;-----------------------------------------------------------------------------

GETBLK:	STA 3 GBRET
	JSR @RANDOM	;BLOCK START
	LDA 1 SOM	;MUST BE ABOVE PROGRAM
	SGTU 0 1
	 MOV 1 0	;OTHERWISE START = END OF PROGRAM
	LDA 1 BLKLEN
	ADDZ 0 1 SZC	;END OF BLOCK +1
	 JMP BBLK
	LDA 2 EOM
	SGTU 1 2
	 JMP@ GBRET	;BLOCK FITS
BBLK:	LDA 0 EOM	;BLOCK END OVERFLOWS TEST AREA
	LDA 1 BLKLEN	;SLIDE IT DOWN
	SUB 1 0
	ADD 0 1
	JMP@ GBRET

GBRET:	0

;-----------------------------------------------------------------------------
CLEARBB:		;CLEAR BOTH BLOCKS
;-----------------------------------------------------------------------------
	MOV 3 2
	MKZERO 0 0
	LDA 3 BLKLEN
	NEG 3 3
	LDA 1 SRHIGH	;END + 1
	NEG 1 1
	COM 1 1		;END OF SOURCE BLOCK
	BLKS
	LDA 1 DHIGH	;END + 1
	NEG 1 1
	COM 1 1		;END OF DEST BLOCK
	LDA 3 BLKLEN
	NEG 3 3
	BLKS
	JMP 0 2

;-----------------------------------------------------------------------------
.A1PBC:			;ALTO 1 PRINT BAD CHIPS
;-----------------------------------------------------------------------------
	STA 3 PBCRET

	LDA 1 UNKSC
	SNZ 1 1
	 JMP PBC1
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Parity errors from wrong place in code*N"

PBC1:	LDA 1 DISPLAYERRORS
	SNZ 1 1
	 JMP PBC2
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Errors detected by display*N"

PBC2:	LDA 1 FUNNYADRC
	SNZ 1 1
	 JMP PBC3
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Sweep errors with address disagreement*N"

PBC3:	LDA 1 SWPTAC
	SNZ 1 1
	 JMP PBC4
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Sweep errors in test area*N"

PBC4:	LDA 1 SWPCAC
	SNZ 1 1
	 JMP PBC5
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Sweep errors not in test area*N"

PBC5:	LDA 1 BLKCHC
	SNZ 1 1
	 JMP PBC6
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Hard errors in block check*N"

PBC6:	LDA 1 BLKCNC
	SNZ 1 1
	 JMP PBC7
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Normal errors in block check*N"

PBC7:	LDA 1 BLTMFC
	SNZ 1 1
	 JMP PBC10
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Multiple errors in source block of BLT*N"

PBC10:	LDA 1 BCHKSMC
	SNZ 1 1
	 JMP PBC11
	JSR @PDEC
	JSR @PMSG1
	 .TXT " BLT incorrect chksm with no parity*N"

PBC11:	LDA 1 PHANC
	SNZ 1 1
	 JMP PBC12
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Phantom errors detected by BLT*N"

PBC12:	LDA 1 NADC
	SNZ 1 1
	 JMP PBC13
	JSR @PDEC
	JSR @PMSG1
	 .TXT " BLT address disagrees with P.E. in chksm*N"

PBC13:	LDA 1 BLTBPBC
	SNZ 1 1
	 JMP PBC14
	JSR @PDEC
	JSR @PMSG1
	 .TXT " BLT detected bad parity bit*N"

PBC14:	LDA 1 CVERS
	SNZ 1 1
	 JMP PBC15
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Errors detected by convert*N"

PBC15:	LDA 1 CFUNNY
	SNZ 1 1
	 JMP PBC16
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Convert errors with bad address*N"

PBC16:	LDA 1 CONVERTERRORS
	SNZ 1 1
	 JMP PBC17
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Errors during convert instruction*N"

PBC17:	LDA 1 BLTNSEC
	SNZ 1 1
	 JMP PBC20
	JSR @PDEC
	JSR @PMSG1
	 .TXT " BLT detected single errors*N"

PBC20:	LDA 1 MBCNT
	SNZ 1 1
	 JMP PBC21
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Logchip calls with multiple bad bits*N"

PBC21:	LDA 2 pSBCTAB	;COUNT ERRORS
	LDA 3 pEBCTAB
	MKZERO 1 1
PBC22:	LDA 0 0 2
	SZ 0 0
	 INC 1 1
	INC 2 2
	SGEU 2 3
	 JMP PBC22

	STA 1 NBCS	;NUMBER OF BAD CHIPS
	JSR @PDEC
	JSR @PMSG1
	 .TXT " Bad main memory chips*N"
	LDA 0 NBCS
	SNZ 0 0
	 JMP PBC24
	JSR @PMSG1
	 .TXT "*N Card Column   Row Errors*N"

	LDA 2 pSBCTAB
PBC23:	LDA 0 0 2
	SZ 0 0
	 JSR PER2	;PRINT A LINE DESCRIBING THE ERROR
	INC 2 2
	LDA 3 pEBCTAB
	SGEU 2 3
	 JMP PBC23

PBC24:	LDA 3 PBCRET
	JMP 1 3		;SKIP RETURN

NBCS:		0
NERS:		0

;-----------------------------------------------------------------------------
PER2:		;CONVERT THE ADDRESS INTO CARD,ROW,COLUMN AND PRINT IT
;-----------------------------------------------------------------------------
	STA 3 PE2RET
	STA 0 NERS	;NUMBER OF ERRORS
	STA 2 TADR
	LDA 0 pSBCTAB
	SUB 0 2
	LDA 0 EC7
	AND 2 0
	CYCLE 1
	LDA 1 C13	;MEMORY STARTS AT SLOT 13
	ADD 1 0
	STA 0 ECARD
	LDA 0 EC70
	AND 2 0
	CYCLE 13.
	STA 0 EROW
	LDA 0 EC3700
	AND 2 0
	CYCLE 10.	;COLUMN (0-16D) INTO AC0
	LDA 1 EC11
	SGTU 0 1	;IF COLUMN > 11 THEN...
	JMP PIT
	LDA 1 C5
	SUB 1 0		;SUBTRACT 5 FROM COLUMN AND INCREMENT CARD
	ISZ ECARD
PIT:	STA 0 ECOL
	LDA 1 ECARD
	JSR @PDEC
	JSR @PMSG1
	 .TXT "  "
	LDA 1 ECOL
	JSR @PDEC
	JSR @PMSG1
	 .TXT "  "
	LDA 1 EROW
	JSR @PDEC
	JSR @PMSG1
	 .TXT "  "
	LDA 1 NERS
	JSR @PDEC
	JSR @PMSG1
	 .TXT "*N"
	LDA 2 TADR
	JMP@ PE2RET

PE2RET:		0
TADR:		0
EC70:		70
EC7:		7
C13:		13.
EROW:		0
ECARD:		0
ECOL:		0
EC3700:		3700
EC11:		11.
C5:		5

;-----------------------------------------------------------------------------
.BLTTEST:		;TEST USING BLT INSTRUCTION
;-----------------------------------------------------------------------------
	STA 3 BLTTRET

;FILL THE SOURCE BLOCK WITH RANDOM NUMBERS
	LDA 0 SRLOW
	STA 0 CADR
	LDA 0 BLKLEN
	STA 0 CNT
	MKZERO 0 0
	STA 0 CHKSM

RLP:	JSR .BLTRANDOM
	STA 0 @CADR
	ISZ CADR	;CAN'T SKIP
	DSZ CNT
	 JMP RLP

;BLT FROM SOURCE TO DESTINATION
	LDA 0 SRLOW
	MKMINUSONE 1 1
	ADD 1 0		;FIRST SOURCE WORD -1
	LDA 2 DHIGH
	ADD 2 1		;LAST DESTINATION WORD
	LDA 3 BLKLEN
	NEG 3 3		;NEGATIVE BLOCK LENGTH

BLTAD:	BLT

;TOUCH SOURCE AND DESTINATION
	LDA 0 BLKLEN
	STA 0 CNT
	LDA 2 SRLOW
	LDA 3 DLOW

CMPLP:	LDA 0 0 2	;TOUCH SOURCE
LDAD0:	NOP
	INC 2 2
	LDA 1 0 3	;TOUCH DESTINATION
LDAD1:	NOP
	INC 3 3
	DSZ CNT
	 JMP CMPLP

	JMP @BLTTRET

BLTTRET:	0
CADR:		0
CNT:		0

;-----------------------------------------------------------------------------
.BLTRANDOM:		;GENERATE A CHECKSUMED RANDOM NUMBER
;-----------------------------------------------------------------------------
;RESULT IN AC0
;CHKSUM XOR RESULT -> CHKSUM

	STA 3 CSRRET
	LDA 0 XRAN
	INC 0 0
	LDA 3 C20D
	SLTU 0 3
	 MKZERO 0 0
	STA 0 XRAN
	LDA 1 C3
	ADD 0 1
	SLTU 1 3
	 SUB 3 1
	LDA 3 YRAN
	ADD 0 3
	LDA 0 0 3
	LDA 3 YRAN
	ADD 1 3
	LDA 1 0 3
	ADD 1 0
	STA 0 0 3	;RESULT
	LDA 1 CHKSM
	MOV 1 3		;XOR
	ANDZL 0 3
	ADD 0 1
	SUB 3 1 
	STA 1 CHKSM	;CHKSUM XOR RESULT
	JMP @CSRRET

XRAN:		16.
C20D:		20.
YRAN:		XYRAN
CSRRET:		0

	.SREL

XYRAN:	30200.
	27432.
	62096.
	39855.
	17884.
	58726.
	55595.
	20904.
	28164.
	27447.
	34709.
	35231.
	33770.
	31508.
	40689.
	1411.
	20373.
	3422.
	62938.
	40035.

	.NREL

;-----------------------------------------------------------------------------
.CONVERTTEST:		;TEST USING THE CONVERT INSTRUCTION
;-----------------------------------------------------------------------------
;BUILDS A ONE CHARACTER 'FONT' OF RANDOM DATA IN THE SOURCE
;BLOCK, AND USES CONVERT TO COPY AS MANY 'CHARACTERS' AS WILL FIT
;INTO THE DESTINATION BLOCK.  

	STA 3 CTRET
	LDA 0 BLKLEN	;LENGTH OF THE CURRENT BLOCK
	LDA 1 MINBLKT	;MINIMUM SIZE BLOCK THIS TEST WILL TRY
	SGTU 0 1
	 JMP 0 3

	JSR @RANDOM
	LDA 2 C177
	AND 0 2 SNR
	 JMP .-3
	STA 2 XXH	;RANDOM POSITIVE 'CHARACTER HEIGHT' <128.
	MKZERO 0 0
	LDA 1 BLKLEN
	DIV		;NWRDS (NUMBER OF CHARACTERS WHICH WILL
	 NOP		;FIT AT THE CURRENT XH) ← BLKLEN/XH
	LDA 0 C177	;MUST BE < 128.
	AND 0 1 SNR
	 MOV 0 1	;SET TO MAX
	STA 1 XNWRDS

;SET UP A FONT IN THE SOURCE BLOCK
	LDA 0 XXH
	STA 0 FCNT
	LDA 0 SRLOW
	STA 0 FPTR

CT1:	JSR @RANDOM
	STA 0 @FPTR
	ISZ FPTR	;CANT SKIP
	DSZ FCNT
	 JMP CT1

	LDA 3 FPTR
	MKZERO 0 0
	STA 0 0 3	;XH TH WORD OF FONT ← 0
	LDA 0 XXH
	STA 0 1 3

	LDA 0 DLOW
	LDA 1 XNWRDS
	SUB 1 0		;AC0← DWA(DLOW)-NWRDS
	LDA 2 pXNWRDS	;POINTER TO 2 WORD TABLE
	STA 1 FCNT	;NUMBER OF 'CHARACTERS' TO DO

CT2:	CONVERT 0	;PARITY ERROR MAY HAPPEN HERE...
CVLP1:	INC 0 0		;OR HERE
	LDA 3 FPTR
	DSZ FCNT
	 JMP CT2

	MKZERO 0 0	;SCAN THE BLOCK STARTING AT DLOW
	LDA 1 XXH
	LDA 2 XNWRDS
	MUL		;BLOCK SIZE
	NEG 1 1
	LDA 2 DLOW

CT3:	LDA 0 0 2	;PARITY ERROR MAY HAPPEN HERE...
CVLP2:	NOP		;OR HERE
	INC 2 2
	INC 1 1 SZR
	 JMP CT3
	JMP @CTRET

CTRET:		0
C177:		177
MINBLKT:	132.	;128+2 + 2 MORE BECAUSE I'M CHICKEN
XXH:		0
XNWRDS:		0	;DONT MOVE NEXT WORD!!
		17	;DBA FOR CONVERT.
FCNT:		0
FPTR:		0

;-----------------------------------------------------------------------------
.SWEEPTEST:		;SWEEP CORE LOOKING FOR RANDOM ERRORS
;-----------------------------------------------------------------------------
	MKZERO 2 2
	LDA 1 EOM
SWP:	LDA 0 0 2	;PARITY ERROR MAY HAPPEN HERE...
SWPCX:	NOP		;OR HERE
	INC 2 2
	SGTU 2 1
	 JMP SWP
	JMP 0 3

;-----------------------------------------------------------------------------
.DISPLAYTEST:		;TEST USING THE DISPLAY
;-----------------------------------------------------------------------------
	STA 3 DTRET

	LDA 0 SOM	;SET UP FIRST BLOCK
	LDA 1 C7
	ADD 1 0
	COM 1 1
	AND 1 0

MDLOOP:	LDA 1 EOM	;BLOCK S.A. IN AC0
	LDA 2 C3200
	SUB 0 1
	SGEU 1 2
	 JMP SMBLK
	LDA 1 C400
	JMP TESTIT	;TEST 3200. WORD BLOCK

SMBLK:	LDA 2 C10	;BLOCK TOO SMALL FOR FULL SCREEN
	SGEU 1 2
	 JMP @DTRET	;BLOCK TOO SMALL FOR ONE LINE.  RETURN
	MOVZR 1 1	;SLC← (EOM-BLOCK S.A.) / 8
	MOVZR 1 1
	MOVZR 1 1
	JMP TESTIT

TESTIT:	STA 0 CBLKS	;AC0 HAS S.A., AC1 HAS SLC
	STA 1 CSLC
	MKZERO 0 0
DSTDAT1:STA 0 DDATA
DSTDAT:	LDA 0 DDATA
	LDA 1 CSLC
	ADDZL 1 1	;FORM WORD COUNT
	MOVZL 1 1
	NEG 1 1
	LDA 2 CBLKS
DSTLOOP:STA 0 0 2
	INC 2 2
	INC 1 1 SZR
	 JMP DSTLOOP

	JSR DT1
	.BLK 5		;*** DCB BUILT IN HERE ***
DT1:	SKEVEN 3 3	;FORCE EVEN
	 INC 3 3
	LDA 0 CBLKS
	STA 0 2 3
	LDA 0 CSLC
	STA 0 3 3
	LDA 0 CNWRD	;8 WORDS HALF RESOLUTION
	STA 0 1 3
	MKZERO 0 0
	STA 0 0 3	;ZERO CHAIN POINTER
	STA 0 @pDWA	;ZERO PARITY POST WORD
	LDA 1 @pDISPLAY
	STA 3 @pDISPLAY	;START DISPLAY ON OUR DCB
	STA 0 VINT
	LDA 0 VINT	;WAIT FOR DISPLAY TO START
	SNZ 0 0
	 JMP .-2

	STA 1 @pDISPLAY	;GO BACK TO DEFAULT DCB
	MKZERO 0 0
	STA 0 VINT
	LDA 0 VINT
	SNZ 0 0
	 JMP .-2	;WAIT FOR DISPLAY TO STOP

	LDA 2 @pDWA
	SZ 2 2		;PARITY ERROR DURING FRAME?
	 JMP PER	;YES

	LDA 0 DDATA
	SZ 0 0		;DATA NONZERO AND NO ERROR MEANS WE HAVE
	 JMP REPORT1	; FOUND THE BAD BIT.  REPORT IT

GNBLOCK:LDA 0 CBLKS	;DONE WITH THIS BLOCK
	LDA 1 CSLC
	MOVZL 1 1
	ADDZL 1 1	;BLOCK S.A. ← BLOCK S.A. + 8*SLC
	ADD 1 0
	JMP MDLOOP

REPORT1:LDA 1 ERADR
REPORT2:JSR @LOGCHIP
	ISZ DISPLAYERRORS
	 JMP GNBLOCK
	DSZ DISPLAYERRORS	;CANT SKIP
	 JMP GNBLOCK

DTRET:		0
pDWA:		616
CBLKS:		0
C3200:		3200.
C400:		400.
C10:		10
CSLC:		0
DDATA:		0
ERADR:		0
CNWRD:		140010	;LOW RES, WHITE ON BLACK 10B SCAN LINES

PER:	LDA 0 DDATA
	SNZ 0 0
	 JMP PER1	;GOT AN ERROR WITH ZERO DATA
	MOVZL 0 0 SZR	;SHIFT DATA AND TRY AGAIN UNLESS RESULT 0
	 JMP DSTDAT1
	JMP REPORT1	;BAD PARITY BIT

PER1:	LDA 0 @pDWA	;ERROR ADDRESS, MORE OR LESS
	LDA 1 CBLKS
	LDA 2 CSLC
	ADDZL 2 2
	MOVZL 2 2
	ADD 2 1		;ADDRESS OF FIRST LOCATION AFTER BLOCK
	LDA 1 C7
	AND 0 1 SNR
	 SUBZL 1 1 SKP	;ADDRESS 0 MOD 8 MEANS ERROR IS AT 
			; RV 616-1 WITH HIGH PROBABILITY
	LDA 1 C3	;ELSE AT RV 616-3
	SUB 1 0		;ERROR ADDRESS TO AC0
	MOV 0 2
	LDA 0 0 2	;CHECK FOR NONZERO DOUBLEWORD.  IF SO, 
	SNZ 0 0		; WE HAVE THE ERROR WITHOUT FURTHER WORK
	 JMP ZWRD
	MOV 2 1
	JMP REPORT2 	;REPORT THE ERROR
ZWRD:	LDA 0 -1 2
	SNZ 0 0
	 JMP ZWRD1
	MKMINUSONE 1 1
	ADD 2 1		;DECREMENT THE ERROR ADDRESS IN AC2
	JMP REPORT2	;REPORT THE ERROR

;THE EVIDENCE IS CONVINCING THAT THE DISPLAY DOUBLEWORD FETCH FAILED.
;SET DATA TO 1 AND LOOP TRYING TO FIND A PATTERN OF ASINGLE 1 BIT
;WHICH CAUSES NO PARITY ERROR, I.E. WHICH ITSELF IS IN ERROR

ZWRD1:	STA 2 ERADR
	MKONE 0 0
	JMP DSTDAT1

;-----------------------------------------------------------------------------
.A1PEINT:		;PARITY INTERRUPT ANALYZER
;-----------------------------------------------------------------------------
;CONTROL COMES HERE WHEN A PARITY INTERRUPT HAPPENS.  THE PARITY CHANNEL
;IS OFF, BUT OTHER INTERRUPTS ARE ON.  THIS ROUTINE SEARCHES A TABLE
;WHICH ASSOCIATES TEST ROUTINE LOCATIONS WHERE PARITY ERRORS ARE
;LIKELY TO OCCUR WITH ANALYSIS ROUTINES.
	LDA 3 pIST	;-> TABLE
	LDA 1 PEPC	;PC WHEN INTERRUPT HAPPENED
	LDA 2 C2
PEINT1:	LDA 0 0 3	;PLACE WHERE AN PARITY INTERRUPT IS EXPECTED
	SNZ 0 0		;ZERO MEANS END OF TABLE
	 JMP PEINT2	;INTERRUPT CAME FROM AN UNEXPECTED PLACE
	ADD 2 3
	SNE 0 1		;DID ERROR COME FROM EXPECTED PLACE?
	 JMP@ -1,3	;YES.  GO ANALYZE IT
	INC 0 0		;INTERRUPT CAN ALSO COME FROM EXPECTED PLACE+1
	SNE 0 1
	 JMP@ -1,3
	JMP PEINT1

PEINT2:	ISZ UNKSC	;UNKNOWN SOURCE
	 JMP @pIRET
	DSZ UNKSC	;CANT SKIP
	 JMP @pIRET

C2:	2
pIST:	IST

	.SREL

IST:	BLTAD		;SOURCE OF INTERRUPT (BLT INSTRUCTION)
	ERBLT		;ROUTINE TO HANDLE THIS SOURCE

	LDAD0		;ERROR IN BLT SOURCE DURING SWEEP
	ERBLKCS

	LDAD1		;ERROR IN BLT DEST DURING SWEEP
	ERBLKCD

	SWPCX		;ERROR DURING CORE SWEEP
	ERINSWP

	CVLP1		;ERROR DURING CONVERT INSTRUCTION
	ERINCONVERT

	CVLP2		;ERROR DURING SWEEP AFTER CONVERT
	ERINCV2

	0		;END OF TABLE

	.NREL

;-----------------------------------------------------------------------------
 ;THE FOLLOWING ROUTINES ANALYSE PARITY ERROR INTERRUPS
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
ERINSWP:		;ERROR DETECTED IN CORE SWEEP
;-----------------------------------------------------------------------------
	LDA 2 PEAC2	;THE ADDRESS IN ERROR
	LDA 1 @pSAD	;POSTED EFF. ADD. OF THE LDA WHICH FAILED
	SE 2 1		;THEY SHOULD AGREE
	 JMP FUNNYADR	;WUPS
	LDA 3 SOM
	SLEU 3 1	;DID THE ERROR CAME FROM THE TEST AREA?
	 JMP ERINCODE	;NO. ERROR CAME FROM CODE AREA
	LDA 0 0 2	;DATA SHOULD BE ZERO; WHAT IS THERE IS WRONG
	JSR @LOGCHIP
	ISZ SWPTAC
	 JMP @pIRET
	DSZ SWPTAC	;CANT SKIP
	 JMP @pIRET

FUNNYADR:ISZ FUNNYADRC	;SAD DISAGREES WITH AC2
	 JMP @pIRET
	DSZ FUNNYADRC	;CANT SKIP
	 JMP @pIRET

ERINCODE:ISZ SWPCAC	;ADDRESS IS IN THE CODE AREA
	 JMP @pIRET
	DSZ SWPCAC	;CANT SKIP
	 JMP @pIRET

;-----------------------------------------------------------------------------
ERBLKCS:		;ERROR IN SOURCE BLOCK DURING BLOCK CHECK
;-----------------------------------------------------------------------------
;THIS SHOULDN'T HAPPEN, SINCE THE ERROR SHOULD HAVE
;BEEN FOUND AND CORRECTED BY THE BLT
	ISZ BLKCHC
	 JMP @pIRET
	DSZ BLKCHC	;CANT SKIP
	 JMP @pIRET

;-----------------------------------------------------------------------------
ERBLKCD:		;ERROR IN DESTINATION BLOCK DURING BLOCK CHECK
;-----------------------------------------------------------------------------
	LDA 0 PEAC0	;SOURCE DATA
	LDA 1 PEAC1	;DESTINATION DATA
	MOV 0 3
	ANDZL 1 3
	ADD 1 0
	SUB 3 0		;AC0 ← SOURCE XOR DESTINATION
	LDA 1 PEAC3	;FAILING ADDRESS
	JSR @LOGCHIP
	ISZ BLKCNC
	 JMP @pIRET
	DSZ BLKCNC	;CANT SKIP
	 JMP @pIRET

;-----------------------------------------------------------------------------
ERBLT:			;ERROR WAS DETECTED BY BLT.
;-----------------------------------------------------------------------------
	LDA 0 @pWW
	MOVZR 0 0
	MOVZL 0 0
	STA 0 @pWW
	STA 0 PECNT	;COUNT OF PARITY ERRORS DURING CHECKSUMMING
	LDA 0 BLKLEN
	STA 0 BLKCNT	;LOOP COUNTER
	LDA 2 SRLOW	;SOURCE BLOCK STARTING ADDRESS
	LDA 0 CHKSM

;CHECKSUM THE SOURCE BLOCK

ERBLT1:	LDA 1 0 2	;DATA
	MOV 1 3		;XOR WITH PARTIAL CHECKSUM
	ANDZL 0 3
	ADD 1 0
	SUB 3 0

	LDA 3 @pWW
	MOVZR 3 3 SNC	;DID A PARITY ERROR OCCUR?
	 JMP ERBLT2	;NOPE
	MOVZL 3 3
	STA 3 @pWW
	ISZ PECNT	;CANT SKIP
	STA 2 PEAD	;REMEMBER THAT ADDRESS 
	STA 1 0 2	;CORRECT THE PARITY OF THE SOURCE BLOCK

ERBLT2:	INC 2 2
	DSZ BLKCNT	;DONE?
	 JMP ERBLT1	;ON TO NEXT WORD

;AC0 CONTAINS THE CHECKSUM, PECNT CONTAINS THE NUMBER OF ERRORS IN THE BLOCK

	LDA 1 PECNT
	SNZ 1 1		;DID WE EVOKE ANY PARITY ERRORS?
	 JMP ERBLT3	;CURSES!
	MOVZR 1 1 SNR	;DID WE GET EXACTLY ONE?
	 JMP ERBLT5	;HURRAY!

	ISZ BLTMFC	;COUNT OF MULTIPLE ERRORS IN SOURCE BLOCK
	 JMP @pIRET
	DSZ BLTMFC	;CANT SKIP
	 JMP @pIRET

ERBLT3:	SNZ 0 0		;NO PARITY ERRORS DETECTED
	 JMP ERBLT4
	ISZ BCHKSMC	;NEVER SHOULD HAPPEN.
	 JMP @pIRET	;ZERO ERRORS AND INCORRECT CHECKSUM
	DSZ BCHKSMC	;CANT SKIP
	 JMP @pIRET

ERBLT4:	ISZ PHANC	;PHANTOM PARITY ERROR
	 JMP @pIRET
	DSZ PHANC	;CANT SKIP
	 JMP @pIRET

ERBLT5:	LDA 2 PEAC0	;THE SOURCE BLOCK ADDRESS FROM BLT
	LDA 1 PEAD	;THE SOURCE BLOCK ADDRESS FROM THE CHECK
	SNE 1 2		;THEY SHOULD BE THE SAME
	 JMP ERBLT6
	ISZ NADC
	 JMP @pIRET
	DSZ NADC	;CANT SKIP
	 JMP @pIRET

ERBLT6:	SZ 0 0		;CHECKSUM NONZERO?
	 JMP ERBLT7	;BAD DATA BIT
	ISZ BLTBPBC	;BAD PARITY BIT
	 JMP .+2
	DSZ BLTBPBC	;CANT SKIP
	JSR @LOGCHIP
	JMP @pIRET

ERBLT7:	ISZ BLTNSEC	;NORMAL SOURCE BLOCK ERRORS
	 JMP .+2
	DSZ BLTNSEC	;CANT SKIP
	JSR @LOGCHIP
	JMP @pIRET

PECNT:		0
PEAD:		0
BLKCNT:		0

;-----------------------------------------------------------------------------
ERINCONVERT:		;CONVERT GOT A PARITY ERROR.
;-----------------------------------------------------------------------------
	ISZ CONVERTERRORS	;COUNT BUT DO NOT LOG IT
	 JMP @pIRET
	DSZ CONVERTERRORS	;CANT SKIP
	 JMP @pIRET

;-----------------------------------------------------------------------------
ERINCV2:		;SWEEP AFTER CONVERT DETECTED A PARITY ERROR.
;-----------------------------------------------------------------------------
	LDA 1 PEAC2	;ADDRESS WHICH FAILED
	LDA 2 @pSAD	;POSTED ADDRESS
	SE 1 2
	 JMP FUNNYCSW
	LDA 0 DLOW	;OFFSET INTO BLOCK
	SUB 0 1
	MKZERO 0 0
	LDA 2 @pXNWRDS
	DIV		;OFFSET IN 'FONT' OF CORRECT DATA
	 NOP
	LDA 2 SRLOW
	ADD 1 2
	LDA 0 0 2	;CORRECT DATUM
	LDA 1 @PEAC2	;BAD DATUM
	MOV 0 3
	ANDZL 1 3
	ADD 1 0
	SUB 3 0

	LDA 1 PEAC2
	JSR @LOGCHIP
	ISZ CVERS
	 JMP @pIRET
	DSZ CVERS	;CANT SKIP
	 JMP @pIRET

FUNNYCSW:ISZ CFUNNY
	 JMP @pIRET
	DSZ CFUNNY	;CANT SKIP
	 JMP @pIRET

;-----------------------------------------------------------------------------
.LOGCHIP:		;ENTER WITH DATA IN AC0, ADDRESS IN AC1
;-----------------------------------------------------------------------------
	STA 3 LCRET
	STA 0 SDATA	;SAVE THE DATA

	MKZERO 2 2	;COUNT BAD BITS
	STA 2 BITCNT
XLOOP:	MOVZL 0 0 SZC
	 ISZ BITCNT
	SZ 0 0
	 JMP XLOOP
	LDA 2 BITCNT	;VERIFY CALLED WITH 0 OR 1 BAD BITS
	MKONE 3 3
	SGTU 2 3
	 JMP CONFIG
	ISZ MBCNT	;LOGCHIP CALLED WITH MULTIPLE BAD BITS
	 JMP LBCRET
	DSZ MBCNT	;CANT SKIP
	 JMP LBCRET	;PUNT

CONFIG:	MOVL# 1 1 SZC	;HIGH 32K ADDRESSES?
	 JMP BITSOK	;YES. NOT MAPPED BY CONFIG SWITCH.
	LDA 0 @pUTILIN	;CHECK MEMORY CONFIGURATION SWITCH
	LDA 2 C1000	;BIT 6
	AND 0 2 SNR
	 JMP BITSOK	;'NORMAL' OR LEFT OR UP
	LDA 0 C40000	;ADDRESS XOR 40000 (FLIP BIT 1)
	MOV 1 2
	ANDZL 0 2
	ADD 0 1
	SUB 2 1

BITSOK:	MOV 1 0		;ADDRESS STILL IN AC1
	MKONE 3 3
	AND 1 3		;LSB OF CARD # INTO AC3 [15]
	CYCLE 3
	LDA 2 C6
	AND 0 2		;2 MSBs OF CARD NO INTO AC2 [13:14]
	ADD 2 3		;ADDRESS BITS 0,1,15 IN AC3 [13:15]
	CYCLE 5
	LDA 2 C70
	AND 0 2
	ADD 2 3		;ROW NUMBER INTO AC3 [10:12]
	LDA 1 SDATA
	MKZERO 0 0 SKP
BLOOP:	 INC 0 0	;FIND THE NUMBER OF THE BAD BIT
	MOVOL 1 1 SNC
	 JMP BLOOP

	CYCLE 6		;BAD BIT (0-16D) INTO AC0 [5:9]
	ADD 0 3		;COLUMN,ROW,CARD INTO AC3

;BAD CHIP TABLE OFFSET:
;	BADBIT	= OFFSET [5:9]  (0 = PARITY, 1 = BIT 0...)
;	ROW	= OFFSET [10:12]
;	QUAD	= OFFSET [13:14]  (ADDR 0-37777 = QUAD 0)
;	ODDADDR	= OFFSET [15]  (1 = ODD)
;
;ALGORITHM FOR RECONSITUTING CARD, COLUMN ROW IS:
;	CARD = 13+QUAD*2+ODDADDR*2+(BADBIT GR 11 ? 1,0)
;	COLUMN = BADBIT GR 11 ? BADBIT-5,BADBIT
;	ROW = ROW

	MOV 3 2
	LDA 0 pSBCTAB	;BAD CHIP TABLE
	ADD 0 3
	ISZ 0 3		;INCREMENT ERROR COUNT IN TABLE
	 JMP LBCRET
	DSZ 0 3		;IF ERROR COUNT OVERFLOWS, COUNT "MANY"

LBCRET:	JSR @ERROR	;NOTIFY REPORT GENERATOR OF THE ERROR
	JMP @LCRET

BITCNT:		0	;NUMBER OF BAD BITS
pUTILIN:	177030
C6:		6
C70:		70
C1000:		1000
C40000:		40000
SDATA:		0
LCRET:		0

; This table shows address => card, col, row mapping when the
; memory configuration switch is in the normal or left position.
; If switch is in right position, interchange cards 13-16 & 17-20
;
; Note that the row address is bits 2-4 of the address
; There are a total of 1088. chips
;
; from	 to		row	card
;---------------------------------------------------------------
; 000000-003777		0	Even addresses
; 004000-007777		1	13: bits 0-11	(ecard = 0)
; 010000-013777		2	14: bits 12-15 & parity
; 014000-017777		3
; 020000-023777		4	Odd addresses
; 024000-027777		5	15: bits 0-11	(ecard = 1)
; 030000-033777		6	16: bits 12-15 & parity
; 034000-037777		7
;---------------------------------------------------------------
; 040000-043777		0	Even addresses
; 044000-047777		1	17: bits 0-11	(ecard = 2)
; 050000-053777		2	18: bits 12-15 & parity
; 054000-057777		3
; 060000-063777		4	Odd addresses
; 064000-067777		5	19: bits 0-11	(ecard = 3)
; 070000-073777		6	20: bits 12-15 & parity
; 074000-077777		7
;---------------------------------------------------------------
; 100000-103777		0	Even addresses
; 104000-107777		1	21: bits 0-11	(ecard = 4)
; 110000-113777		2	22: bits 12-15 & parity
; 114000-117777		3
; 120000-123777		4	Odd addresses
; 124000-127777		5	23: bits 0-11	(ecard = 5)
; 130000-133777		6	24: bits 12-15 & parity
; 134000-137777		7
;---------------------------------------------------------------
; 140000-143777		0	Even addresses
; 144000-147777		1	25: bits 0-11	(ecard = 6)
; 150000-153777		2	26: bits 12-15 & parity
; 154000-157777		3
; 160000-163777		4	Odd addresses
; 164000-167777		5	27: bits 0-11	(ecard = 7)
; 170000-173777		6	28: bits 12-15 & parity
; 174000-177777		7
;
;
;bit	column		bit	column
;---------------------------------------------------------------
;0	0		12	7
;1	1		13	8
;2	2		14	9
;3	3		15	10
;4	4		parity	11
;5	5
;6	6
;7	7
;8	8
;9	9
;10	10
;11	11

	.END