Google
 

Trailing-Edge - PDP-10 Archives - klad_sources - klad.sources/smmtpb.mac
There are no other files named smmtpb.mac in the archive.
;*MAINDEC-10-SMMTPB

	MCNVER==0
	DECVER==2

								XLIST

	DEFINE	PTITL	(MCNVER,DECVER)<

TITLE	SMMTPB DECSYSTEM 2020 DIAGNOSTIC MAGTAPE PRE-BOOT, VER MCNVER,DECVER>
								LIST
								LALL
	PTITL	\MCNVER,\DECVER

								SALL

;*JOHN R. KIRCHOFF

;*COPYRIGHT(C) 1978
;*DIGITAL EQUIPMENT CORPORATION
;*MARLBORO, MASS. 01752

	NOSYM

INTERN	SMMTPB	;LET EXTERNAL PROGRAM KNOW WHERE THIS IS
SMMTPB:		;INTERNAL REFERENCE ADDRESS
INTERN	SMMTEND	;INTERNAL REFERENCE END ADDRESS
PHASE	1000	;THE PRE-BOOT IS REALLY AT LOC 1000
SUBTTL	PROGRAM PARAMETERS

;*ACCUMULATOR ASSIGNMENTS

	A=1				;GENERAL PURPOSE ACS
	B=2
	C=3
	D=4
	P1=5

PBMADR=1
PBLIM=2
PBBITS=3
PBERR=4

;*MAGTAP DEFINITIONS

RCDSIZ==^D512		;SIZE OF RECORDS ON TAPE

MTCS1=	00		;CONTROL AND STATUS 1
MTWC=	02		;WORD COUNT REGISTER
MTBA=	04		;UNIBUS ADDRESS REGISTER
MTFC=	06		;FRAME COUNT REGISTER
MTCS2=	10		;CONTROL AND STATUS 2
MTDS=	12		;DRIVE STATUS
MTER=	14		;ERROR REGISTER
MTAS=	16		;ATTENTION SUMMARY
MTCK=	20		;CHARACTER CHECK REGISTER
MTDB=	22		;DATA BUFFER
MTMR=	24		;MAINTENANCE REGISTER
MTDT=	26		;DRIVE TYPE
MTSN=	30		;SERIAL NUMBER
MTTC=	32		;TAPE CONTROL REGISTER
SUBTTL	EXEC MAGTAPE LOAD ROUTINES

;*I/O INSTRUCTION DEFINITIONS

OPDEF	WRUBR	[701B8+3B12]	;WRITE USER BASE REGISTER
OPDEF	RDIO	[712B8]		;READ I/O
OPDEF	WRIO	[713B8]		;WRITE I/O

;*MAGTAPE CONTROL COMMANDS

MT.NOP=	01		;NO-OP
MT.RWO=	03		;REWIND OFF-LINE
MT.RW=	07		;REWIND
MT.DC=	11		;DRIVE CLEAR
MT.ERS=	25		;ERASE
MT.WTM=	27		;WRITE TAPE MARK
MT.SF=	31		;SPACE FORWARD
MT.SR=	33		;SPACE REVERSE
MT.WCF=	51		;WRITE CHECK FORWARD
MT.WCR=	57		;WRITE CHECK REVERSE
MT.WF=	61		;WRITE FORWARD
MT.RF=	71		;READ FORWARD
MT.RR=	77		;READ REVERSE

;*MAGTAPE CONTROL AND STATUS 1 BITS

MTSC=	100000		;SPECIAL CONDITION
MTTRE=	40000		;TRANSFER ERROR
MTMCPE=	20000		;MASSBUS CONTROL PARITY ERROR
MTDVA=	4000		;DRIVE AVAILABLE
MTPSEL=	2000		;PORT SELECT
MTRDY=	200		;READY
MTIE=	100		;INTERRUPT ENABLE
;*MAGTAPE CONTROL AND STATUS REG 2 BITS

MTDLT=	100000		;DATA LATE
MTWCE=	40000		;WRITE CHECK ERROR
MTPE=	20000		;PARITY ERROR
MTNED=	10000		;NON-EXISTENT DRIVE
MTNEM=	4000		;NON-EXISTENT MEMORY
MTPGE=	2000		;PROGRAM ERROR
MTMXF=	1000		;MISSED TRANSFER
MTMDPE=	400		;MASSBUS DATA PARITY ERROR
MTOR=	200		;OUTPUT READY
MTIR=	100		;INPUT READY
MTCLR=	40		;CONTROLLER CLEAR
MTPAT=	20		;PARITY TEST
MTBAI=	10		;BUS ADR INCREMENT INHIBIT

;*MAGTAPE DRIVE STATUS REG BITS

MTATA=	100000		;ATTENTION
MTERR=	40000		;ERROR
MTPIP=	20000		;POSITIONING IN PROGRESS
MTMOL=	10000		;MEDIUM ON-LINE
MTWRL=	4000		;WRITE LOCKED
MTEOT=	2000		;END OF TAPE
MTDPR=	400		;DRIVE PRESENT
MTDRY=	200		;DRIVE READY
MTSSC=	100		;SLAVE STATUS CHANGE
MTPES=	40		;PHASE ENCODED
MTSDWN=	20		;SLOWING DOWN
MTIDB=	10		;IDENTIFICATION BURST
MTTM=	4		;TAPE MARK
MTBOT=	2		;BEGINNING OF TAPE
MTSLA=	1		;SLAVE ATTENTION

;*MAGTAPE ERROR REG BITS

MTCOR=	100000		;CORRECTABLE DATA ERROR
MTUNS=	40000		;UNSAFE
MTOPI=	20000		;OPERATION INCOMPLETE
MTDTE=	10000		;DRIVE TIMING ERROR
MTNEF=	4000		;NON-EXECUTABLE FUNCTION
MTCS=	2000		;CORRECTABLE SKEW
MTFCE=	1000		;FRAME COUNT ERROR
MTNSG=	400		;NON STANDARD GAP
MTPEF=	200		;PE FORMAT ERROR
MTINC=	100		;INCORRECTABLE DATA
MTDPAR=	40		;DATA BUS PARITY
MTFMT=	20		;FORMAT ERROR
MTCPAR=	10		;CONTROL BUS PARITY
MTRMR=	4		;REGISTER MODIFICATION REFUSED
MTILR=	2		;ILLEGAL REGISTER
MTILF=	1		;ILLEGAL FUNCTION
;*MAGTAPE TAPE CONTROL BITS

MTACCL=	100000		;ACCELERATION
MTFCS=	40000		;FRAME CONTROL STATUS
MTTCW=	20000		;TAPE CONTROL WRITE
MTEOA=	10000		;ENABLE ABORT ON DATA TRANSFER ERROR

MT200=	0		;200 BPI
MT556=	400		;556 BPI
MT800=	1000		;800 BPI
MT1600=	2000		;1600 BPI

MTFMT1=	0		;FORMAT ?????

MTEVP=	10		;EVEN PARITY

;*UNIBUS DEFINITIONS

MTPGSZ=	^D512*2			;PAGE SIZE FOR MAGTAPE TRANSFER

UBAP0=	763000			;ADDRESS OF UNIBUS MAP
UBSTAT=	763100			;ADDRESS OF UNIBUS STATUS
UNVBIT=	40000			;VALID UNIBUS BIT
UNV36X=	100000			;36 BIT UNIBUS TRANSFER
UNVDPB=	20000			;DISABLE UNIBUS PARITY BITS

KPALIVE=31			;KEEP ALIVE & STATUS WORD
MSRH=36				;RH-11 BASE ADDRESS
MSDRIVE=37			;DRIVE NUMBER
MSSLAVE=40			;SLAVE NUMBER, BPI & FORMAT
RDIBUF=	2000			;READ BUFFER
;*RH-11 MAGTAPE READ-IN

MTSTRT:!JRST	MTSTAR
MTHLT0:!HALT	.		;TRIED TO OVERLOAD PRE-BOOT PAGE
MTHLT1:!HALT	.		;MAGTAPE READ ERROR
MTHLT2:!HALT	.		;NO RH-11 BASE ADDRESS
MTHLT3:!HALT	.		;MAGTAPE SKIP  ERROR

PBPAGP:	0			;THIS WORD 0 FOR MAGTAPE
BC2RES:	JRST	BC2S		;BC2 RESTART ADDRESS FOR "SMMAG"

;VERIFY ACCUMULATOR AC0

MTSTAR:!SETZM	0		;SET AC 0 TO ALL ZEROS
	SKIPE			;SHOULD CAUSE A SKIP
	HALT	.		;ERROR, DIDN'T SKIP
	SKIPN			;THIS SHOULD NOT SKIP
	SKIPA			;WHICH COMES HERE AND THEN SKIPS
	HALT	.		;ERROR, EITHER SKIPN OR SKIPA FAILED
	CAME	0,PBZERO
	HALT	.		;ERROR, DOES NOT COMPARE

	SETOM	0		;SET AC 0 TO ALL ONES
	SKIPN			;SHOULD CAUSE A SKIP
	HALT	.		;ERROR, DIDN'T SKIP
	SKIPE			;THIS SHOULD NOT SKIP
	JUMPN	0,.+2		;BUT THIS JUMP SHOULD JUMP
	HALT	.		;ERROR, EITHER SKIPE OR JUMPN FAILED
	JUMPG	0,.+2		;THIS SHOULD NOT JUMP
	JUMPL	0,.+2		;THIS ONE SHOULD JUMP
	HALT	.		;ERROR, EITHER JUMPG OR JUMPL FAILED
	CAME	0,PBMONE
	HALT	.		;ERROR, DOES NOT COMPARE

	SETCMM	0		;COMPLEMENT AC0
	JUMPE	0,.+2		;THIS JUMP SHOULD JUMP
	HALT	.		;ERROR, DATA WRONG OR JUMP DIDN'T JUMP
	CAME	0,PBZERO
	HALT	.		;ERROR, DOES NOT COMPARE
;VERIFY BASIC CPU OPERATION

	SETZ	0,		;CLEAR AC0
	ADDI	0,1		;ADD ONE
	CAIE	0,1		;DID IT ADD CORRECTLY ?
	HALT	.		;ERROR, CPU CAN'T ADD
	CAIN	0,1		;THIS COMPARE SHOULDN'T SKIP
	JUMPN	0,.+2		;BUT THIS JUMP SHOULD
	HALT	.		;ERROR, EITHER CAIN OR JUMPN FAILED
	JUMPL	0,.+2		;THIS SHOULD NOT JUMP
	JUMPG	0,.+2		;THIS ONE SHOULD JUMP
	HALT	.		;ERROR, EITHER JUMPL OR JUMPG FAILED

	ADDI	0,1		;ADD ONE AGAIN
	CAIE	0,2		;SHOULD NOW BE TWO
	HALT	.		;ERROR, CPU CAN'T ADD

	SUBI	0,2		;SUBTRACT TWO
	CAIE	0,0		;SHOULD NOW BE ZERO AGAIN
	HALT	.		;ERROR, CPU CAN'T SUBTRACT EITHER

	AOS	0		;ADD ONE A DIFFERENT WAY
	CAIE	0,1		;THIS SHOULD GIVE A ONE
	HALT	.		;ERROR, CPU STILL CAN'T ADD

	MOVSS	0,0		;SWAP AC0
	CAME	0,PBLONE	;DID IT SWAP CORRECTLY ?
	HALT	.		;NO, ERROR

	MOVNI	0,2000		;GENERATE A NEGATIVE NUMBER (BOOT WORD COUNT)
	CAME	0,PBNEG		;SHOULD GIVE A MINUS 2000
	HALT	.		;DIDN'T, ERROR

	SETZ	0,		;ZERO AC0
	IORI	0,140000	;OR IN SAME BITS AS UBVBIT AND UNV36X
	CAME	0,PBIOR		;ARE THE CORRECT BIT SET ?
	HALT	.		;NO, ERROR

	MOVEI	0,2		;START WITH A TWO
	SOJLE	0,.+2		;SUBTRACT ONE BUT SHOULD NOT JUMP
	SKIPA			;WHICH SHOULD COME HERE AND SKIP
	HALT	.		;ERROR, SOJLE MUST HAVE JUMPED
	CAIE	0,1		;DID SUBTRACT WORK ?
	HALT	.		;NO, ERROR
	SOJLE	0,.+2		;DO IT AGAIN, THIS SHOULD JUMP
	HALT	.		;DIDN'T, ERROR
;VERIFY BASIC ADDITION

	SETZ	0,		;CLEAR AC 0
	ADD	0,PBONES	;ADD A SET OF OCTAL ONES
	CAME	0,PBONES	;DID IT ADD CORRECTLY ?
	HALT	.		;ERROR, CPU CAN'T ADD

	ADD	0,PBONES	;ADD A SET OF OCTAL ONES AGAIN
	CAME	0,PBTWOS	;SHOULD GIVE A SET OF OCTAL TWOS
	HALT	.		;ERROR

	ADD	0,PBONES	;ADD AGAIN
	CAME	0,PBTHRE	;SHOULD GIVE A SET OF OCTAL THREES
	HALT	.		;ERROR

	ADD	0,PBONES	;ADD AGAIN
	CAME	0,PBFOUR	;SHOULD GIVE A SET OF OCTAL FOURS
	HALT	.		;ERROR

	ADD	0,PBONES	;ADD AGAIN
	CAME	0,PBFIVE	;SHOULD GIVE A SET OF OCTAL FIVES
	HALT	.		;ERROR

	ADD	0,PBONES	;ADD AGAIN
	CAME	0,PBSIX		;SHOULD GIVE A SET OF OCTAL SIXES
	HALT	.		;ERROR

	ADD	0,PBONES	;ADD AGAIN
	CAME	0,PBMONE	;SHOULD GIVE A SET OF OCTAL SEVENS
	HALT	.		;ERROR

	ADDI	0,1		;ADD JUST A ONE
	JUMPE	0,.+2		;COMPARE IT A DIFFERENT WAY
	HALT	.		;DIDN'T GIVE A FULL WORD OF ZEROS

;VERIFY AOBJN ADDITION AND JUMP TRANSFER

	AOBJN	0,.+2		;ADD 1 TO BOTH HALVES OF THE WORD
	CAME	0,PB11		;GIVE THE RIGHT ANSWER AND NO JUMP ?
	HALT	.		;NO, ERROR

	SETO	0,		;PRESET AC 0 TO -1
	AOBJN	0,.+2		;GIVE THE RIGHT ANSWER AND NO JUMP ?
	CAME	0,PBZERO
	HALT	.		;NO, ERROR

	MOVE	0,PBSIX		;VERIFY THAT AOBJN DOES JUMP
	AOBJN	0,.+2
	HALT	.		;ERROR, DIDN'T DO THE JUMP
;VERIFY ACCUMULATOR ADDRESSING

	MOVEI	0,0		;LOAD EACH AC WITH ITS OWN ADDRESS
	MOVEI	1,1
	MOVEI	2,2
	MOVEI	3,3
	MOVEI	4,4
	MOVEI	5,5
	MOVEI	6,6
	MOVEI	7,7
	MOVEI	10,10
	MOVEI	11,11
	MOVEI	12,12
	MOVEI	13,13
	MOVEI	14,14
	MOVEI	15,15
	MOVEI	16,16
	MOVEI	17,17

	CAIE	17,17		;VERIFY THAT EACH AC ADDRESSES CORRECTLY
	HALT	.		;ERROR
	CAIE	16,16
	HALT	.
	CAIE	15,15
	HALT	.
	CAIE	14,14
	HALT	.
	CAIE	13,13
	HALT	.
	CAIE	12,12
	HALT	.
	CAIE	11,11
	HALT	.
	CAIE	10,10
	HALT	.
	CAIE	7,7
	HALT	.
	CAIE	6,6
	HALT	.
	CAIE	5,5
	HALT	.
	CAIE	4,4
	HALT	.
	CAIE	3,3
	HALT	.
	CAIE	2,2
	HALT	.
	CAIE	1,1
	HALT	.
	CAIE	0,0
	HALT	.
;VERIFY ACCUMULATOR INDEXING

	CAME	1,(1)		;SHOULD COMPARE AC1 AGAINST CONTENTS OF AC1
	HALT	.		;ERROR
	CAME	2,(2)
	HALT	.
	CAME	3,(3)
	HALT	.
	CAME	4,(4)
	HALT	.
	CAME	5,(5)
	HALT	.
	CAME	6,(6)
	HALT	.
	CAME	7,(7)
	HALT	.
	CAME	10,(10)
	HALT	.
	CAME	11,(11)
	HALT	.
	CAME	12,(12)
	HALT	.
	CAME	13,(13)
	HALT	.
	CAME	14,(14)
	HALT	.
	CAME	15,(15)
	HALT	.
	CAME	16,(16)
	HALT	.
	CAME	17,(17)
	HALT	.

;VERIFY INDIRECT ADDRESSING

	MOVE	0,@17		;FETCH THE CONTENTS OF AC17
	CAIE	0,17		;SHOULD BE 17
	HALT	.		;WASN'T, ERROR

;VERIFY INDIRECT AND INDEXING

	MOVE	0,@4(3)		;SHOULD FETCH THE CONTENTS OF AC7
	CAIE	0,7		;CONTENTS OF 4 PLUS CONTENTS OF 3
	HALT	.		;DIDN'T, ERROR
;VERIFY ACCUMULATOR AC17

	SETZM	17		;SET ZEROS TO AC17
	CAME	17,PBZERO	;IS IT CORRECT ?
	HALT	.		;NO, COULD BE ABOUT ANYTHING

	SETOM	17		;SET ONES TO AC17
	CAME	17,PBMONE	;IS IT CORRECT ?
	HALT	.		;NO, COULD BE ABOUT ANYTHING

;VERIFY ACCUMULATOR DATA STORAGE

	MOVSI	17,-17
	CAME	17,PB17		;DID MOVE SWAPPED IMMEDIATE WORK ?
	HALT	.		;NO, ERROR

	SETOM	(17)		;SET ONES TO AC'S 0 TO 16
	AOBJN	17,.-1

	MOVSI	17,-17
	SETCMM	(17)		;COMPLEMENT AC, SHOULD THEN BE ZERO
	SKIPE	(17)
	HALT	.		;WASN'T, STILL COULD BE ABOUT ANYTHING
	AOBJN	17,.-3
	SETZM	17

;VERIFY SUBROUTINE CALLING

	JRSTF	@.+1		;CLEAR PROCESSOR FLAGS
		0,,.+1
	JSR	.+3		;TRANSFER TO SUBROUTINE
PBJSR:!	HALT	.		;DIDN'T TRANSFER

	JRST	.+7		;CONTINUE AFTER SUBROUTINE FROM HERE

	0			;SAVED PC STORAGE
	MOVE	0,.-1		;GET SAVED PC
	CAME	0,PBSPC		;DID CORRECT PC GET STORED ?
	HALT	.		;NO, ERROR
	AOS	PBJSR+2		;PLUS ONE TO PC TO SKIP HALT
	JRSTF	@PBJSR+2	;NOW CONTINUE BACK IN MAINLINE
;VERIFY BIT TESTS USED IN PRE-BOOT

	MOVEI	0,200		;SAME BIT AS MAGTAPE READY
	TRNN	0,200		;SHOULD SKIP
	HALT	.		;ERROR, DIDN'T
	TRNE	0,200		;SHOULD NOT SKIP
	JUMPA	.+2		;WHICH COMES HERE AND JUMPA SHOULD JUMP
	HALT	.		;EITHER TRNE OR JUMPA FAILED
	CAIE	0,200		;DO IMMEDIATE MODE COMPARE
	HALT	.		;ERROR, DOES NOT COMPARE

	MOVEI	0,40000		;SAME BIT AS TRE ERROR
	TRNN	0,40000		;SHOULD SKIP
	HALT	.		;ERROR, DIDN'T
	TRNE	0,40000		;SHOULD NOT SKIP
	JUMPA	.+2		;WHICH COMES HERE AND JUMPA SHOULD JUMP
	HALT	.		;EITHER TRNE OR JUMPA FAILED
	CAIE	0,40000		;DO IMMEDIATE MODE COMPARE
	HALT	.		;ERROR, DOES NOT COMPARE

;SAVE BOOT MAGTAPE PARAMETERS

	MOVE	0,MSRH		;GET MAGTAPE ADDRESS
	MOVEM	0,MTRHSV
	SKIPN	0
	JRST	MTHLT2		;NO RH-11 BASE ADDRESS ?
	HLLM	UNBMP0		;SETUP UBA MAP POINTER
	HLLM	MTUBST

	MOVE	0,MSSLAVE
	MOVEM	0,MTSLSV	;SAVE SLAVE & FORMAT

	MOVE	0,KPALIVE
	MOVEM	0,MTKPAL	;SAVE KEEP-ALIVE WORD

	MOVE	0,MSDRIVE
	MOVEM	0,MTDRSV	;SAVE DRIVE SELECTION

;VERIFY XOR INSTRUCTION

	SETZ	0,		;XOR 0 WITH 0
	XOR	0,0
	CAIE	0,0		;SHOULD GIVE ALL ZEROS
	HALT	.		;DIDN'T, ERROR

	SETO	0,		;XOR -1 WITH -1
	XOR	0,0
	CAIE	0,0		;SHOULD GIVE ALL ZEROS
	HALT	.		;DIDN'T, ERROR
	SETO	1,		;ALL ONES TO AC1
	XOR	0,1		;XOR 0 AND -1
	CAME	0,PBMONE	;SHOULD GIVE ALL ONES
	HALT	.		;DIDN'T, ERROR

	SETZ	1,		;ALL ZEROS TO AC1
	XOR	0,1		;XOR -1 AND 0
	CAME	0,PBMONE	;SHOULD GIVE ALL ONES
	HALT	.		;DIDN'T, ERROR

;VERIFY MEMORY FROM 20 TO 777
;	ALSO BOOT CHECK 2 RESTART ADDRESS, NOW LOAD SMMAG

BC2S:	MOVEI	PBMADR,20	;TEST MEMORY 20 TO 777 FOR ONES
	MOVEI	PBLIM,777
	SETOM	PBBITS
	JSR	PBTST1		;DO MEMORY TEST

	MOVEI	PBMADR,20	;TEST MEMORY 20 TO 777 FOR ADDRESS
	MOVEI	PBLIM,777
	JSR	PBTST2		;DO MEMORY TEST

	MOVEI	PBMADR,20	;TEST MEMORY 20 TO 777 FOR ZEROS
	MOVEI	PBLIM,777
	SETZM	PBBITS
	JSR	PBTST1		;DO MEMORY TEST

;VERIFY MEMORY FROM 2000 TO END OF 32K

	MOVEI	PBMADR,2000	;TEST MEMORY 2000 TO 77777 FOR ONES
	MOVEI	PBLIM,77777
	SETOM	PBBITS
	JSR	PBTST1		;DO MEMORY TEST

	MOVEI	PBMADR,2000	;TEST MEMORY 2000 TO 77777 FOR ADDRESS
	MOVEI	PBLIM,77777
	JSR	PBTST2		;DO MEMORY TEST

	MOVEI	PBMADR,2000	;TEST MEMORY 2000 TO 77777 FOR ZEROS
	MOVEI	PBLIM,77777
	SETZM	PBBITS
	JSR	PBTST1		;DO MEMORY TEST

	JRST	PBSTA1		;NOW GO LOAD FROM MAGTAPE
;MEMORY DATA SUBROUTINE

PBTST1:!	0
	MOVEM	PBBITS,(PBMADR)	;MOVE DATA TO MEMORY
	MOVE	PBERR,(PBMADR)	;READ DATA BACK FROM MEMORY
	XOR	PBERR,PBBITS	;XOR DATA, WILL BE ZERO IF NO ERROR
	JUMPE	PBERR,.+2
	HALT	.		;MEMORY DATA ERROR
	CAIGE	PBMADR,(PBLIM)	;COMPLETED MEMORY SECTION ?
	AOJA	PBMADR,PBTST1+1	;NO, CONTINUE TO NEXT ADDRESS
	JRSTF	@PBTST1		;YES, RETURN TO MAIN LINE

;MEMORY ADDRESS SUBROUTINE

PBTST2:!	0
	MOVE	PBBITS,PBMADR	;SETUP ADDRESS AS TEST DATA
	MOVEM	PBBITS,(PBMADR)	;MOVE DATA TO MEMORY
	MOVE	PBERR,(PBMADR)	;READ DATA BACK FROM MEMORY
	CAME	PBBITS,PBERR	;DATA WILL BE THE SAME IF NO ERROR
	HALT	.		;MEMORY DATA ERROR
	CAIGE	PBMADR,(PBLIM)	;COMPLETED MEMORY SECTION ?
	AOJA	PBMADR,PBTST2+1	;NO, CONTINUE TO NEXT ADDRESS
	JRSTF	@PBTST2		;YES, RETURN TO MAIN LINE

PBSTA1:!MOVE	P1,MTRHSV	;SETUP UNIBUS ADDRESS INDEX

GORH:!	JSR	SETRH		;SETUP RH-11

	MOVEI	A,MT.SF		;SPACE FORWARD ONE FILE
	WRIO	A,MTCS1(P1)

	JSR	MSRDY		;WAIT FOR TAPE TO STOP
	TRNN	A,MTTM		;CHECK FOR TAPE MARK DETECTED
	JRST	MTSERR		;SPACE FORWARD ERROR
	SETZM	B		;GET POINTER FIRST TIME
	MOVEI	D,^D100		;RETRY 100 TIMES

RDRH:!	JSR	SETRH

	MOVEI	A,<RDIBUF_-^D9>+UNVBIT
	WRIO	A,@UNBMP0	;SET UNIBUS MAP

	SETZ	A,
	WRIO	A,MTBA(P1)	;SET UNIBUS ADDRESS

	MOVEI	A,-MTPGSZ
	WRIO	A,MTWC(P1)	;SET WORD COUNT

	MOVEI	A,MT.RF		;READ FORWARD
	WRIO	A,MTCS1(P1)

	JSR	MSRDY		;WAIT FOR READY
	TRNE	A,MTTM
	JRST	MTFAIL		;READ ERROR, EOF DETECTED

	RDIO	A,MTER(P1)
	TRNE	A,177777-MTFCE
	JRST	MSRTRX		;ERROR OTHER THAN LENGTH ERROR

	JSR	LOADPG		;LOAD DATA FROM THIS RECORD

	JRST	RDRH		;READ NEXT RECORD

MSRDY:!	0
	RDIO	A,MTDS(P1)	;READ DRIVE STATUS

	TRNN	A,MTPIP		;IS DRIVE STOPPED ?
	TRNN	A,MTDRY		;DRIVE READY ?
	JRST	MSRDY+1
	JRSTF	@MSRDY		;RETURN
SETRH:!	0
	MOVEI	A,MTCLR
	WRIO	A,MTCS2(P1)	;CLEAR MAGTAPE

	MOVE	A,MTDRSV
	WRIO	A,MTCS2(P1)	;SELECT DRIVE

	MOVE	A,MTSLSV
	WRIO	A,MTTC(P1)	;LOAD TAPE CONTROL REGISTER

	SETZ	A,
	WRIO	A,MTFC(P1)	;CLEAR FRAME COUNTER

	JRSTF	@SETRH		;RETURN

MSRTRX:	SOJL	D,MTFAIL	;DONE ALL RETRIES ?

	JSR	SETRH		;SETUP RH-11

	MOVNI	A,1
	WRIO	A,MTFC(P1)	;SET FRAME COUNT TO -1

	MOVEI	A,MT.SR
	WRIO	A,MTCS1(P1)	;BACKSPACE THE TAPE

	JSR	MSRDY		;WAIT FOR TAPE TO STOP

	JRST	RDRH		;NOW TRY AGAIN
;*LOADPG, LOAD THE DATA BUFFER INTO CORE AND START SMMAG AT END

LOADPG:!0
	MOVSI	A,-RCDSIZ	;GET COUNT OF WORDS IN BUFFER
	HRRI	A,RDIBUF	;AND ADDRESS OF BUFFER

LOADWD:!MOVE	(A)		;GET A WORD FROM BUFFER
	JUMPGE	B,LOADPT	;JUMP IF LOOKING FOR POINTER
	AOBJP	B,.+1		;INCREMENT POINTER
	HRRZ	C,B		;STORE ADDRESS CAN'T BE
	CAIL	C,1000		; 1000 TO 1777 - PRE-BOOT
	CAILE	C,2777		; OR 2000 TO 2777 - READ BUFFER
	JRST	.+2
	JRST	MTBADR		;TRIED TO OVER-LOAD PRE-BOOT
	MOVEM	(B)		;PUT WORD IN MEMORY

LOADNX:!AOBJN	A,LOADWD	;COUNT AND GET NEXT WORD IN BUFFER
	JRSTF	@LOADPG		;RETURN TO READ NEXT BUFFER

LOADPT:!JUMPGE	PGMST		;START PROGRAM IF START WORD
	MOVEM	B		;STORE POINTER IN B
	JRST	LOADNX		;GET NEXT WORD FROM BUFFER

PGMST:!	MOVEM	20		;SAVE START ADDRESS
	MOVE	MTRHSV		;REINSTALL RH-11 ADDRESS
	MOVEM	MSRH
	MOVE	MTDRSV		;REINSTALL DRIVE NUMBER
	MOVEM	MSDRIVE
	MOVE	MTSLSV		;REINSTALL SLAVE NUMBER
	MOVEM	MSSLAVE
	MOVE	MTKPAL
	MOVEM	KPALIVE		;REINSTALL KEEP-ALIVE
	WRUBR	PBACB7
	JSR	PBWRAC		;CLEAR AC BLOCK 7

	WRUBR	PBACB6
	JSR	PBWRAC		;CLEAR AC BLOCK 6

	WRUBR	PBACB5
	JSR	PBWRAC		;CLEAR AC BLOCK 5

	WRUBR	PBACB4
	JSR	PBWRAC		;CLEAR AC BLOCK 4

	WRUBR	PBACB3
	JSR	PBWRAC		;CLEAR AC BLOCK 3

	WRUBR	PBACB2
	JSR	PBWRAC		;CLEAR AC BLOCK 2

	WRUBR	PBACB1
	JSR	PBWRAC		;CLEAR AC BLOCK 1

	WRUBR	PBACB0
	JSR	PBWRAC		;CLEAR AC BLOCK 0

	JRST	@20		;START SMMAG

;AC BLOCK CLEAR SUBROUTINE

PBWRAC:!0
	MOVSI	17,-17
	SETZM	(17)		;ZERO AC'S
	AOBJN	17,.-1
	SETZM	17
	JRSTF	@PBWRAC
MTSERR:!MOVEI	17,MTHLT3	;SET HALT ADDRESS
	JRST	.+5

MTBADR:!MOVEI	17,MTHLT0	;SET HALT ADDRESS
	JRST	.+2

MTFAIL:!MOVEI	17,MTHLT1	;SET HALT ADDRESS

	SETZM	100		;NO DEVICE ADDRESS
	SETZM	101		;NO MEMORY PAGE ADDRESS
	SETZM	103		;NO SELECTION PICKUP POINTER

	RDIO	MTCS1(P1)
	MOVEM	103		;SAVE CONTROL AND STATUS 1
	RDIO	MTCS2(P1)
	MOVEM	104		;SAVE CONTROL AND STATUS 2
	RDIO	MTDS(P1)
	MOVEM	105		;SAVE DRIVE STATUS
	RDIO	MTER(P1)
	MOVEM	106		;SAVE ERROR 1
	SETZ
	MOVEM	107		;NO ERROR 2
	SETZ
	MOVEM	110		;NO ERROR 3

	RDIO	@UNBMP0
	MOVEM	111		;SAVE UBA PAGING RAM LOC 0
	RDIO	@MTUBST
	MOVEM	112		;SAVE UBA STATUS REG

	MOVE	MTVER
	MOVEM	113		;SAVE PRE-BOOT VERSION

	MOVE	MTRHSV
	MOVEM	MSRH		;REINSTALL RH-11 BASE ADDRESS
	MOVE	MTDRSV
	MOVEM	MSDRIVE		;REINSTALL DRIVE NUMBER
	MOVE	MTSLSV
	MOVEM	MSSLAVE		;REINSTALL SLAVE NUMBER
	MOVE	MTKPAL
	MOVEM	KPALIVE		;REINSTALL KEEP-ALIVE

	JRST	@17		;HALT AT APPROPRIATE HALT
;PRE-BOOT PARAMETERS AND STORAGE

PBZERO:!0			;CONSTANT ZERO TEST WORD
PBMONE:!-1			;CONSTANT ONE TEST WORD
PBLONE:!1,,0			;CONSTANT LEFT HALF ONE
PBNEG:!	-2000			;CONSTANT MINUS 2000
PBIOR:!	0,,140000		;CONSTANT FOR IORI CHECK
PBONES:!111111,,111111		;CONSTANT ONES TEST WORD
PBTWOS:!222222,,222222		;CONSTANT TWOS TEST WORD
PBTHRE:!333333,,333333		;CONSTANT THREES TEST WORD
PBFOUR:!444444,,444444		;CONSTANT FOURS TEST WORD
PBFIVE:!555555,,555555		;CONSTANT FIVES TEST WORD
PBSIX:!	666666,,666666		;CONSTANT SIXES TEST WORD
PB11:!	1,,1			;CONSTANT ONE IN EACH HALF
PB17:!	-17,,0			;CONSTANT AC'S AOBJN POINTER
PBSPC:!	0,,PBJSR		;CONSTANT FOR SUBROUTINE TEST PC

PBACB7:!	1B0!7B8		;WRUBR ARGUMENTS
PBACB6:!	1B0!6B8
PBACB5:!	1B0!5B8
PBACB4:!	1B0!4B8
PBACB3:!	1B0!3B8
PBACB2:!	1B0!2B8
PBACB1:!	1B0!1B8
PBACB0:!	1B0!0B8

MTKPAL:!	0	;KEEP-ALIVE & STATUS WORD
MTRHSV:!	0	;RH-11 BASE ADDRESS
MTDRSV:!	0	;DRIVE NUMBER
MTSLSV:!	0	;SLAVE NUMBER

MTVER:!	MCNVER,,DECVER		;PRE-BOOT VERSION

UNBMP0:!	3,,763000	;UBA PAGE 0 ADDRESS
MTUBST:!	3,,763100	;UBA STATUS ADDRESS

DEPHASE
SMMTEND:0			;ENDING REFERENCE ADDRESS
	END