Google
 

Trailing-Edge - PDP-10 Archives - isi-saio_19830204 - isi-sa10/syrlib.mac
There are 16 other files named syrlib.mac in the archive. Click here to see a list.
;<ISI-SA10>SYRLIB.MAC.13631	 4-Feb-83 12:09:42	Edit by ISI-SA10
;
;	SAIO Changes Copyright 1982, All Rights Reserved
;	University of Southern California
;
;#13 Fix TU78 code
;#12 Name change SEC%ST to SEC%SM since DEC added a SEC%ST 
;#11 Do not dump octal of unknown error if /Brief
;#10 Add system name to title lines
;#6 translate sense bytes for Calcomp disks
;#6 report Calcomp disk address as CYL/SURF/REC rather than CYL/SURF/SEC
;#5 Do not print a number for drive S/N for CC0x's
;#4 Change byte printout for Calcom status, sense bytes, comand chains to HEX.
;#3 update tables to agree with dev no.'s 30,31,32 for TUSA,CC01,CC02
;   temporarily, will also accept interim no.'s 25,23,24
;#2 Code 122 - Errors from mag tapes on SA10 (actually in file as 111)
;#1 Code 121 - Errors from disks on SA10 (actually in file as 111)
	TITLE	SYRLIB -- SYSERR PACKAGE LIBRARY OF COMMON ROUTINES 
SUBTTL	VERSION 15A(1363)	K. COYE/ RLD/ PJB/ ES/ TJW/ LWE/ SRL/ GSK




;COPYRIGHT (C) 1972,1975,1978,1979,1980 BY
;DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
;
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY  OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE  SOFTWARE  IS  HEREBY
;TRANSFERED.
;
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT  NOTICE
;AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY  OF  ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.





	SEARCH	SYRUNV			;UNIVERSAL  FOR SYSERR PACKAGE
	SEARCH	SYRLOW			;LOW SEG DEFINITIONS








	TWOSEG
	RELOC	400000




;	;INTERNALS ARE DEFINED HERE FOR ACCESS FROM OTHER PARTS
;	;OF THE SYSERR PACKAGE.

	INTERNAL HEADRD,ABORT,CHRCHK,DATECK,FILERR,TOOBIG,MBCHAR
	INTERNAL CNISUM,BADNAM,MASSVM,DEVCHK,ERRINT,SKIPIT,IDCHK
	INTERNAL STRCHK,DETCHK,DMPENT,HDRLST,PAGXCD,DVCHAR,TMCHAR
	INTERNAL SAYDAY,GETNBS,.OCTLE,.DECML,.ASCIE,.SIXBT,ENTRST,SPACE3
	INTERNAL .HAFWD,.SPECL,.HTIME,.PPNWW,.ODECW,OHEXB,.UDATE,.TASCI,.PPNWT
	INTERNAL .TDIRW,R5VSIX,MONVER,BADADD,TAB031,TYPAST,BLDPTR
	INTERNAL ACLST,SAVE4P,RET4P,SAVE4T,RET4T,HWDUMP,TYPBCD,LSTEB,JFLOOP
	INTERNAL CNIDCD, XORTAB,BITLST,.DVTAB,.MXBLK,.TRBLK,.SUBLK,.SECBK
	INTERNAL WDCNT,COMPAR,SKPRTN,TYPNBS,TITLST,SKIPWD,ADVBFF
	INTERNAL FIXBUF,STBUFF,INPWD,GOSUM,GETWD,FFPRNT,SLPRNT,CLPRNT
	INTERNAL TBPRNT,CHROUT,TTYSIX,MDECHR,FIXNAM,NOTRAN,ACREG
	INTERNAL SBUSFN,VERED,NEWCMD,T11ACI,TTLS1,DRVTYP,BLKTRN,JSYSER
	INTERNAL COLOUT,SBDOUT,DSERCD,FE.KLI,KR%ECD,FE%DEV,BLOKTN
	INTERNAL HKSTRG,DUMPOS,DSKPOS,TAPPOS,FIXOFF,RS4POS
	INTERNAL GTBF00,FNDB00,FNDF00,FNDN00,PTSTRG,DYNSUM
	INTERNAL LP$CFG,DH$CFG,CD$CFG,FE$DL1,FE$DLS,FE$DTE,FE$RJP,FE$DM1

	EXTERNAL ERRTBL,PDLPNT,MDE000,.TMOHW,FE$NAM,BLTTAB
;HEADRD -- ROUTINE TO VERIFY HEADER SECTION OF ENTRY
;AND XFER HEADER TO HDBUFF
;BODY OF ENTRY TO WKBUFF
;THEN DISPATCH TO ENTRY PROCESSOR

HEADRD:	TRNE	F,F.TTY			;[1221]DOING OUTPUT TO TTY?
	TLOA	F,F.TTYO		;[1221]YES. SET FLAG TO DO OUT TO TTY
	TLZ	F,F.TTYO		;SAY PUT ALL CHARS IN OUTPUT BUFFER
ABORT:	TLZ	F,F.BTCK		;SAY NO BIT CHECKING
	MOVE	P,PDLPNT		;RESET PDL STACK POINTER
	TLZ	F,F.READ		;CLEAR READING FLAG AND NAME FLAG
	SETZ	S,			;CLEAR SOFTWARE ERROR BITS
CLRBUF:	SETZM	HDVER1			;0= HEADER VER 0
	SETZM	TOPENT			;0 SAYS TOPS-10 RECORDED  [200]
	SETZM	KSMON			;CLEAR KS-10 MONITOR FLAG  [750]
	SETZM	WKBUFF			;PREPARE TO CLEAR WORKING BUFFER
	MOVE	T1,[XWD	WKBUFF,WKBUFF+1]
	MOVE	T2,ENTRWC		;GET ENTRY LENGTH
	BLT	T1,WKBUFF(T2)		;ZAP ONLY THAT MUCH
	MOVE	T1,[XWD HDBUFF,HDBUFF+1];SETUP TO ZAP HEADER BUFFER
	SETZM	HDBUFF
	BLT	T1,HDBUFF+HDSIZE-1	;ZAP
	PUSHJ	P,CLRRCV		;CLEAR IPCF MSG AREA
GETWD0:	TRNE	F,F.NOW			;[713-TJW] DOING ON-LINE LOGGING?
	 JRST	PAKWAT			;[713-TJW]YES, SLEEP TILL NEXT ENTRY 
	PUSHJ	P,GETWD			;GET WORD 0 OF ENTRY
EOFTRY:	NOTNOW
	MOVE	MASTWD,HDBUFF		;HDR WD 0 IS WHAT WE WANT
	LDB	T1,[POINT 9,MASTWD,8]	;[751]PICKUP ENTRY TYPE
					;ALSO ENTRY FOR POST EOF CODE
	MOVEM	T1,ERTYPE

FILCHK:	TLNE	MASTWD,TOPBIT		;[200]1=TOPS-20 RECORDED
	 PUSHJ	P,[ SETOM	TOPENT 	;[400]
		    SETOM	TOPONE
		    POPJ	P,0]
	CAIN	T1,ER.HIA		;DID DAEMON SEE FILE ERROR
	 JRST	FILERR			;YUP

EOFCHK:	CAIN	T1,ER.EOF		;IS THIS THE END OF ERROR FILE
	JRST	EOFVER			;EOF WAS WRITTEN IN FILE 
	MOVEM	MASTWD,HDBUFF		;STORE WD0 OF HEADER IN HDBUFF

;HERE WE CHECK TO SEE IF THIS IS A VALID CODE FOR SYSERR

	CAIGE	T1,NOTMIN
	JRST	.+3  ;ENTRY IS OK
	CAIG	T1,NOTMAX
	JRST	NOTOUR			;[303]OPPS
	PUSHJ	P,ERRINT		;OK GO FIND HIS INDEX
	SKPNOW				;DONT DO THIS IF /NOW ITS ALREADY DONE
	 PUSHJ	P,SIZCHK		;[303]FIND ENTRY SIZE
	SKIPN	HEADWC			;HDR LENGTH =0
	  JRST	HEADST			;YES
	SKIPN	ENTRWC			;BODY = 0?
	  JRST	ENTRST
	CAILE	T1,WKSIZE+HDSIZE	;IS ENTRY LARGER THAN BUFFERS
	JRST	TOOBIG			;YES
	AOS	SEQNUM			;BUMP RECORD SEQ NUMBER
	SKPNOW				;[713-TJW] HEADER FILLED IF ON-LINE
	PUSHJ	P,HEADFL		;GO FILL HDBUFF WITH HEADER INFO
	MOVE	T1,HDBUFF+HDRPSN 	;GET S/N FROM HDBUFF
	CAML	T1,[^D4096]		;IS IT A KS10 ?  (S/N > 4096.)
	SETOM	KSMON			;YES! - SET FLAG WORD
	TLNE	F,F.DATE		;DOES USER DESIRE DATE CONSTRAINTS
	PUSHJ	P,DATECK		;YES GO DO IT
	JRST	CHRCHK

HEADST:	WARN	<ZERO LENGTH HEADER FOUND!>
	JRST	STBUFF			;RE-SYNC!!
ENTRST:	WARN	<ZERO LENGTH ENTRY FOUND!>
	JRST	STBUFF

;CODE MOVED AND RENAMED WITH EDIT 303

SIZCHK:	LDB	T1,[POINT 6,MASTWD,23]	;GET HDR VER
	SKIPE	T1			;0=VER 0
	SETOM	HDVER1			;REMEMBER
	SKIPE	HDVER1			;DID WE JUST SET IT?
	LDB	T1,[POINT 3,MASTWD,26]	;YES
	SKIPN	HDVER1			;CHECK AGAIN
	LDB	T1,[POINT 3,MASTWD,29]	;GET 3 BITS OF HDR LENGTH
	MOVEM	T1,HEADWC		;SAVE WHICHEVER WE GOT
	SKIPE	HDVER1			;TRY AGAIN
	LDB	T1,[POINT 9,MASTWD,35]	;VER 1=GET 9BITS OF BODY LENGTH
	SKIPN	HDVER1			;VER 0?
	LDB	T1,[POINT 6,MASTWD,35]	;YES, GET 6 BITS
	MOVEM	T1,ENTRWC		;SAVE EITHER
	ADD	T1,HEADWC
	MOVEM	T1,TOTWC		;SAVE TOTAL # WDS IN ENTRY
	POPJ	P,0

;ROUTINE ADDED WITH EDIT 303

NOTOUR:	PUSHJ	P,SIZCHK		;FIND THE ENTRY LENGTH
	MOVE	T1,TOTWC
	SUBI	T1,1			;ALREADY HAVE WD 0 OF HEADER
	MOVEM	T1,ENTRWC		;SETUP AND
	JRST	SKIPIT			;SKIP TO NEXT ENTRY
					;END EDIT 303
;THIS CODE ADDED BY EDIT 713
;HERE WHEN WE ARE ON-LINE -REAL-TIME!!
;MAIN ROUTINE 
;CONTROLS IPCF FACILTITY
;AND THE PID HANDLING


ONLLOG::SKIPE	TOPMON			;UNDER TOPS10?
	FATAL	<NOW SWITCH ONLY SUPPORTED UNDER TOPS-10>
	PUSHJ	 P,TRPSET		;[713-TJW]SET UP THE CTRL-C TRAP
	PUSHJ	P,GETPID		;[713-TJW]GET ME A PID
	PUSHJ	P,GIPCID		;[713-TJW]GET IPCC'S PID
	PUSHJ	P,FNDSEL		;[713-TJW]GET SEL'S PID
	MOVE	T1,SELPID		;[713-TJW]SET UP TO SEE IF
	CAIN	T1,0			;[713-TJW]SEL'S PID =0?
	 PUSHJ	P,MAKSEL		;[713-TJW]YES.. MAKE ME SEL
	PUSHJ	P,TELSEL		;[713-TJW]NO..TEL SEL THAT IM HERE
	JRST	PAKWAT			;[713-TJW]AND GO WAIT FOR A MESSAGE
;ROUTINE TO GET US A PID FROM SYSTEM INFO
;CALLED WITH A PUSHJ RETURNS POPJ ALWAYS
;WITH OUR PID STORED IN MYPID

GETPID:	PUSHJ	P,CLRSND		;CLR MSG BLK
	MOVEI	T1,.IPCII		;SET FCN 3
	MOVEM	T1,SMSG			;PUT IT INTO THE MSG
	MOVE	T1,SMSGPT		;GET PTR TO MSG
	MOVEM	T1,SPDB+.IPCFP		;INTO THE PDB
	MOVE	T1,SPDBPT		;POINT AT PDB
	IPCFS.	T1,			;SEND!!
	 JRST	SNDERR			;HANDLE THE ERROR
	PUSHJ	P,CLRRCV		;CLR MSG BLK
	MOVE	T1,RMSGPT		;GET PTR TO MSG
	MOVEM	T1,RPDB+.IPCFP		;INTO THE PDB
	MOVE	T1,RPDBPT		;POINT AT THE PDB
	IPCFR.	T1,			;RECIEVE
	 JRST	RCVERR			;HANDLE ANY ERROR
	MOVE	T1,RMSG+1		;GET MY PID OUT OF THE MSG
	MOVEM	T1,OURPID		;REMEMBER IT
	POPJ	P,0			;AND RETURN
;ROUTINE TO FIND OUT [SYSTEM]ERROR LOGGER'S PID
;CALLED WITH PUSHJ ALWAYS RETURNS POPJ
;WITH SEL'S PID STORED IN SELPID

FNDSEL:	MOVE	T1,SELPTR		;SET UP TO GET SEL'S PID
	GETTAB	T1,			;GET IT
	 FATAL <CAN'T GETTAB [SYSTEM] ERROR LOGGER'S PID>
	MOVEM	T1,SELPID		;REMEMBER IT
	POPJ	P,0			;RETURN
;ROUTINE TO MAKE US SEL
;CALLED WITH PUSHJ RETURNS POPJ IF IT FAILS

MAKSEL:	MOVE	T1,PRIVPT		;SET UP TO GET PRIV WORD
	GETTAB	T1,			;GET IT
	 FATAL <CAN'T GETTAB PIVILEGE WORD>
	MOVE	T2,[JP.IPC]		;THIS IS THE BIT
	TDNN	T1,T2			;DO I HAVE IPCF PRIVS?
	 FATAL <THERE IS NO [SYSTEM]ERROR LOGGER AND YOU HAVE NO PRIVILEGES TO BE ONE>
	PUSHJ	P,CLRSND		;CLEAR MSG BLK
	MOVEI	T1,.IPCWP		;SET FCN
	MOVEM	T1,SMSG			;GET IT INTO THE MSG BLK
	MOVEI	T1,.IPCPL		;GET ITEM NUMBER
	MOVEM	T1,SMSG+1		;INTO THE MSG
	MOVE	T1,OURPID		;GET MY PID
	MOVEM	T1,SMSG+2		;INTO THE MSG
	MOVE	T1,IPCPID		;GO GET IPCC'S PID
	MOVEM	T1,SPDB+.IPCFR		;USE IT AS RECVRS PID
	MOVE	T1,SMSGPT		;GET PTR TO MSG
	MOVEM	T1,SPDB+.IPCFP		;INTO THE PDB
	MOVEI	T1,IP.CFP		;SET THE PRIV BIT
	MOVEM	T1,SPDB+.IPCFL		;AND PUT IT INTO THE PDB
	MOVE	T1,SPDBPT		;GET PTR TO PDB
	IPCFS.	T1,			;SEND!!
	 JRST	SNDERR			;GO HANDLE THE ERROR
	PUSHJ	P,CLRRCV		;CLR MSG BLK
	MOVE	T1,RMSGPT		;GET PTR TO MSG
	MOVEM	T1,RPDB+.IPCFP		;INTO THE PDB
	MOVE	T1,RPDBPT		;POINT AT PDB
	IPCFR.	T1,			;RECIEVE
	 JRST	RCVERR			;HANDLE THE ERROR
	MOVE	T1,SELPTR		;GET 
	GETTAB	T1,			;SEL'S PID
	 FATAL <CAN'T GETTAB [SYSTEM] ERROR LOGGER'S PID>
	CAME	T1,OURPID		;SELPID=MYPID?
	 POPJ	P,0			;NO- SOMEONE ELSE BEAT ME TO IT
	MOVEM	T1,SELPID		;YES MOVE PID INTO SELPID
	WARN <INITIALIZED AS [SYSTEM] ERROR LOGGER>
	SETOM	SELFLG			;SET THE FLAG
	PUSHJ	P,QUOSET		;CRANK UP MY QUOTAS
	AOS	(P)			;AND RETURN
	POPJ	P,0			;PLUS ONE
;ROUTINE TO TELL SEL THAT WE HAVE BECOME ACTIVE
;CALLED WITH PUSHJ ALWAYS RETURNS POPJ

TELSEL:	PUSHJ	P,CLRSND		;CLR SENDER PAKET
	MOVE	T1,CNCTMS		;PUT CONNECT MSG
	MOVEM	T1,SMSG			;INTO THE MSGBLK
	MOVE	T1,CMSGPT		;SEND ONLY 1 WORD
	MOVEM	T1,SPDB+.IPCFP		;SO WE CAN TELL
	MOVE	T1,SELPID		;GET MASTERS PID
	MOVEM	T1,SPDB+.IPCFR		;INTO MSG
	MOVE	T1,SPDBPT		;SET UP FOR SEND
	IPCFS.	T1,			;SEND PACKET
	 JRST	SNDERR			;ERROR ON SEND
	WARN <INITIALIZED AS SLAVE ERROR LOGGER>
	POPJ	P,0			;RETURN TO MAINLINE
;SOME UTILITY ROUTINES TO WORK WITH THE MESSAGE AREAS

CLRSND:	MOVE	T2,CLRSMS		;CLR MSG AREA..BLT ZEROS
	SETZM	SPDB+.IPCFL
	BLT	T2,SMSG+7
	POPJ	P,0

CLRRCV:	MOVE	T2,CLRRMS		;CLR MSG AREA..BLT ZEROS
	SETZM	RPDB+.IPCFL
	BLT	T2,RMSG+7
	POPJ	P,0

MOVR2S:	MOVE	T1,MOVSMR		;BLT SND MSG TO RCVD MSG
	BLT	T1,SMSG+7
	POPJ	P,0

MOVS2R:	MOVE	T1,MOVRMS		;BLT RCVD MSG TO SND MAG
	BLT	T1,RMSG+7
	POPJ	P,0
;ROUTINE TO WAIT FOR EITHER AN IPCF INTERRUPT OR
;THE END OF 15 SECONDS

PAKWAT:	MOVSI	T1,(HB.IPC)		;SETUP FOR IPC WAKEUP
	HRRI	T1,^D15000		;OR END OD 15 SECS
	HIBER	T1,			;SLEEP!!
	 FATAL <HIBER UUO FAILED>
	JRST	FNDWHY			;GO FIND OUT WHY WE WOKE

;ROUTINE TO FIND OUT WHY WE WOKE UP

FNDWHY:	PUSHJ	P,CLRRCV		;CLR MSG AREA
	MOVE	T1,RPDBPT		;PUT ANSWER IN REVR BLK
	IPCFQ.	T1,			;ANYTHING IN IPCF QUE?
	 JRST	[CAIE	T1,IPCNP%	;ANY MESSAGE ?	[1357]
		 FATAL	<IPCFQ UUO FAILED>
		 JRST	CHKSEL]		;NO LOOK AROUND	[1357]
;[1357]	HRR	T1,RPDB+.IPCFL		;GET INTERESTING FLAGS
;	HLL	T1,RPDB+.IPCFP		;AND LENGTH
;	JUMPE	T1,CHKSEL		;IF 0 THEN NO MSGS SO GO CHECK
	JRST	RCVPAK			;YES SOMETHING GO PROCESS
;ROUTINE TO LOOK AROUND AT THE WORLD AND DECIDE THAT IT HAS CHANGED
;AND THEN GET ME ONTO THE PARTY LINE

CHKSEL:	MOVE	T4,SELPID		;GET OLD SELPID
	PUSHJ	P,FNDSEL		;FIND OUT SEL'S PID
	CAMN	T4,SELPID		;SAME AS WE KNOW?
	 JRST	PAKWAT			;YUP..GO BACK TO SLEEP
	MOVEM	T4,SELPID		;SAVE OLD SELPID
	PUSHJ	P,SLEEPR		;NO LET'S WAIT BEFORE ANYTHING DRASTIC
	MOVE	T4,SELPID		;GET OLD SELPID
	PUSHJ	P,FNDSEL		;DID ANYONE ELSE TAKE UP THE SLACK?
	CAMN	T4,SELPID		;SAME AS BEFORE?(SHOULDN'T BE!!)
	 JRST	PAKWAT			;BUT IT WAS?
	MOVE	T4,SELPID		;LETS LOOK AT THIS MORE CLOSELY
	CAIN	T4,0			;NO SEL AROUND?
	 PUSHJ	P,MAKSEL		;NOPE..WE'LL TRY TO BECOME IT
	PUSHJ	P,TELSEL		;YES THERE'S ONE ..ILL TELL HIM I'M HERE
	JRST	PAKWAT			;NOW I CAN GO SLEEP

SLEEPR:	MOVEI	T1,^D35			;SET UP TO SLEEP 35 SECS
	SLEEP	T1,			;SLEEP!!
	POPJ	P,0			;RETURN
;ROUTINE TO RECIEVE A PACKET

RCVPAK:	PUSHJ	P,CLRRCV		;CLR MSG BLK
	MOVE	T2,RMSGPT		;GET PTR TO MSG
	MOVEM	T2,RPDB+.IPCFP		;INTO PDB
	MOVE	T1,RPDBPT		;GET PTR TO PDB
	IPCFR.	T1,			;RECIEVE PACKET
	 JRST	RCVERR			;HANDLE ERROR
	JRST	WHTMSG			;WHAT KIND OF MSG?

;ROUTINE TO FIND OUT WHAT KIND OF PACKET IT WAS

WHTMSG:	MOVE	T1,RPDB+.IPCFL		;GET FLAGS
	TRNE	T1,.IPCFN		;RETURNED PACKET ?
	 JRST	REMPID			;YES IT WAS..GO REMOVE PID
	MOVE	T3,RPDB+.IPCFP		;GET LENGTH,,ADDR WD
	HLRZ	T3,T3			;GET LENGTH ALONE
	CAIE	T3,1			;CONNECT MSG (LEN=1?)
	 JRST	REALMS			;NO ,ITS A REAL MSG
	JRST	MSGTYP			;YES, FIND OUT WHAT KIND
;ROUTINE TO REMOVE A PID FROM THE TABLE OF SLAVE PIDS

REMPID:	MOVE	T1,RPDB+.IPCFR		;GET RECIEVER'S PID
	MOVNI	T4,SLVCNT		;GET -NUMBER OF SLAVES
	HRL	T4,T4			;MAKE IT -SLVNUM,,0
	MOVEI	T2,SLVTBL		;GET THE ADDRESS
	HRR	T4,T2			;MAKE IT -SLVNUM,,SLVPID
REMLUP:	CAMN	T1,(T4)			;ARE PIDS THE SAME?
	 JRST	ZEROIT			;YES GO KILL PID
	AOBJN	T4,REMLUP		;NO  TRY AGAIN
	JRST	PAKWAT			;GO WAIT FOR A PACKET WHEN DONE

;ROUTINE TO KILL THE REQUESTED PID

ZEROIT:	SETZM	(T4)			;KILL THE PID
	SOS	SLVCNT			;MAKE THE COUNT RIGHT 
	PUSHJ	P,CMPTAB		;GO CLEAN UP THE TABLE
	JRST	PAKWAT			;GO WAIT FOR ANOTHER PACKET

;ROUTINE TO CLEAN UP THE SLAVE TABLE WHEN A PID IS REMOVED
;CALLED WITH A PUSHJ RETURNS POPJ

CMPTAB:	SETZ	T3,			;THIS WILL HOLD COUNT OF SLAVES
	MOVN	T4,SLVCNT		;GET 0,,-SLVNUM
	HRL	T4,T4			;MAKE IT -SLVNUM,,0
	MOVEI	T2,SLVTBL		;GET THE ADDRESS
	HRR	T4,T2			;MAKE IT -SLVNUM,,ADDRESS
CMPLUP:	MOVE	T1,(T4)			;GET A PID
	CAIN	T1,0			;IS IT ZERO?
	 SKIPA 				;YES
	JRST	STKPID			;NO GO STORE IT
STKRTN:	AOBJN	T4,CMPLUP		;DONE IT ENOUGH?
	MOVN	T4,T3			;YES SET UP FOR NEXT STEP
	HRLZ	T4,T4			;MAKE IT -CNT,,0
	MOVEI	T2,SLVTBL		;GET SLVPID ADDRESS
	HRR	T4,T2			;MAKE IT -CNT,,ADDR
STKLUP:	POP	P,T1			;GET PID OFF STACK
	MOVEM	T1,(T4)			;PUT IT AWAY
	AOBJN	T4,STKLUP		;DONE ENOUGH?
	POPJ	P,0			;YES ..RETURN

;ROUTINE TO PUSH A PID ONTO THE STACK
;CALLED WITH A PUSHJ RETURNS POPJ

STKPID:	PUSH	P,T1			;PUT PID ON STACK
	ADDI	T3,1			;COUNT UP NUMBER OF PIDS MOVED
	JRST	STKRTN			;RETURN

;ROUTINE TO CLEAR THE PID TABLE  BEFORE WE RELOAD IT
;CALLED WITH A PUSHJ RETURNS POPJ WITH A CLEAN TABLE

CLRTAB:	MOVE	T2,CLRPTB		;SET UP TO 
	SETZM	SLVTBL			;BLT ZEROS
	BLT	T2,SLVTBL+4		;BLT!!
	POPJ	P,0			;RETURN
;ROUTINE TO DETERMINE WHAT TYPE OF MSG WE RECIEVED
;AND DISPATCH OFF TO HANDLE IT

MSGTYP:	MOVE	T1,RMSG			;GET THE MSG WORD
	CAMN	T1,CNCTMS		;IS IT A CONNECT MSG?
	 JRST	HANSLV			;YES, GO HANDLE NEW SLAVE
	CAMN	T1,OCNTMS		;NO, IS IT AN OK CONNECT MSG?
	 JRST	PAKWAT			;YES  GO WAIT FOR A NEW MSG
	CAMN	T1,NCNTMS		;NO, IS IT A NO CONNECT MSG?
	 FATAL	<CAN'T CONNECT TO [SYSTEM]ERROR LOGGER>
	JRST	PAKWAT			;ITS NOTHING WE KNOW ABOUT..IGNORE IT

;ROUTINE TO HANDLE  SLAVE REQUESTS

HANSLV:	MOVE	T3,SLVCNT		;GET COUNT OF SLAVES
	CAIL	T3,SLVMAX		;5 SLAVES ALREADY?
	 JRST	NOROOM			;YES SEND ERROR MSG
	MOVE	T2,RPDB+.IPCFS		;NO GET SENDERS PID
	MOVEM	T2,SLVTBL(T3)		;INTO SLAVE TABLE
	ADDI	T3,1			;COUNT ONE MORE SLAVE
	MOVEM	T3,SLVCNT		;REMEMBER IT
	JRST	PAKWAT			;GO WAIT FOR ANOTHER PACKET

;HERE WHEN WE HAVE A REAL MESSAGE

REALMS:	SKIPE	SELFLG			;ARE WE SEL?
	 PUSHJ	P,RESEND		;YES, WE NEED TO RESEND THIS
					;AND PROCESS IT OURSELVES
					;BY FALLING INTO PRCFIL
;ROUTINE TO OPEN THE INPUT FILE AND GET TO THE RIGHT BLOCK
;AND READ IT IN

PRCFIL:	MOVE	T1,RMSG+4		;GET FILE STR FROM MSG
	MOVEM	T1,INPBLK+1		;PUT IT INTO LOOKUP BLOCK
	OPEN	INPCHN,INPBLK
	JRST	[ WARN <CAN'T OPEN INPUT DEVICE>
		JRST	GOSTRT]
	MOVE	T1,RMSG+5		;GET FILENAME
	MOVEM	T1,INPFIL		;INTO LOOKUP BLOCK
	HLLZ	T1,RMSG+6		;GET EXTENTION
	MOVEM	T1,INPFIL+1		;ALSO
	LOOKUP	INPCHN,INPFIL		;LOOKUP!!
	JRST	[WARN <LOOKUP ERROR ON INPUT FILE >
		JRST	GOSTRT]
	MOVE	T2,RMSG+1
;******************************************************************
;THIS SHOULD BE REMOVED WHEN THE BUG IN DAEMON IS FIXED
;	ADDI	T2,1			;ADJUST FOR THE BUG IN DAEMON
;******************************************************************
	USETI	INPCHN,(T2)
	IN	INPCHN,
	SKIPA
	FATAL	<ERROR READING ERROR.SYS>
	HRRZ	T1,RMSG			;GET OFFSET
	PUSHJ	P,SKIPWD		;SKIP THAT MANY WORDS
	PUSHJ	P,GETWD			;GET WORD 0
	MOVEM	MASTWD,HDBUFF		;STORE WD 0 FOR HEADFL
	PUSHJ	P,SIZCHK		;GET WORD COUNTS
	PUSHJ	P,HEADFL		;FILL HEADER BUFFER
	MOVE	T1,RMSG+2		;GET HEADER WD 0 FROM MSG
	CAME	T1,HDBUFF		;IS IT THE SAME?
	 JRST	ABEND			;NOPE..TELL US AND LEAVE QUICKLY
	MOVE	T1,RMSG+3		;WD MATCHES 
	CAME	T1,HDBUFF+1		;IS WD 1 THE SAME TOO?
	 JRST	ABEND			;NOPE..WALK AWAY PASSIVELY.
	PUSHJ	P,MOVENT		;YES IT DOES..MOVE IN REST OF ENTRY
	CLOSE	INPCHN,0		;NOW CLOSE FILE
	JRST	EOFTRY			;AND GO PROCESS

MOVENT:	SKIPG	T1,ENTRWC		;SKIP IF WC IS >0
	 JRST ABORT
	MOVNS	T1			;SET UP AOBJ PTR
	MOVS	WKINDX,T1
	HRRI	WKINDX,0
MOVEN1:	PUSHJ	P,GETWD			;FILL WKBUFF
	MOVEM	MASTWD,WKBUFF(WKINDX)
	AOBJN	WKINDX,MOVEN1
	POPJ	P,0

ABEND:	WARN	<IPCF PACKET DOES NOT MATCH FILE, ABORTING ENTRY>
	JRST	ABORT
;ROUTINE TO RESEND THE MESSAGE TO ALL KNOWN SLAVES

RESEND:	MOVE	T1,SLVCNT		;GET COUNT OF SLAVES
	CAIN	T1,0			;NO SLAVES?
	 POPJ	P,0			;YES RETURN NOW
	PUSHJ	P,CLRSND		;CLR MSG BLK
	PUSHJ	P,MOVR2S		;PUT MSG IN TO BE SENT
	MOVE	T1,SMSGPT		;POINT AT MSG
	MOVEM	T1,SPDB+.IPCFP		;IN PDB
	MOVNI	T1,SLVCNT		;GET 0,,-SLVNUM
	HRL	T1,T1			;MAKE IT -SLVNUM,,0
	MOVEI	T2,SLVTBL		;GET THE ADDRESS
	HRR	T1,T2			;MAKE IT -SLVNUM,,SLVPID
LOOPER:	MOVE	T3,0(T1)		;GET THE ENTRY
	PUSHJ	P,SENDER		;GO PROCESS IT
	AOBJN	T1,LOOPER		;DO IT SLVNUM TIMES
	POPJ	P, 0			;THEN RETURN

;ROUTINE TO DECIDE WETHER TO REALLY SEND THE MESSAGE

SENDER:	CAIN	T3,0			;PID=0?
	 POPJ	P,0			;YES RETURN NOW
	PUSHJ	P,ECHO			;NO RESEND THE MSG
	POPJ	P,0			;THEN RETURN

;ROUTINE TO ACTUALLY DO THE SENDING OF THE MESSAGE

ECHO:	MOVEM	T3,SPDB+.IPCFR		;GET THE PID INTO THE MESSAGE
	MOVE	T1,SPDBPT		;POINT AT THE PDB
	IPCFS.	T1,			;SEND!!
	 JRST	SNDERR			;HANDLE THE ERROR
	POPJ	P,0			;RETURN
;ROUTINE TO FIND OUT IPCC'S PID

GIPCID:	MOVE	T1,IPCPT		;SET UP TO GET IPCC'S PID
	GETTAB	T1,			;GET IT
	 FATAL <CAN'T GETTAB [SYSTEM] IPCC'S PID>
	MOVEM	T1,IPCPID		;PUT IT AWAY
	POPJ	P,0			;AND RETURN
;ROUTINE TO SET MY QUOTAS TO INFINITY

QUOSET:	PUSHJ	P,CLRSND		;CLR MSG BLK
	MOVEI	T1,.IPCSQ		;SET FCN
	MOVEM	T1,SMSG			;IN THE MSG
	MOVE	T1,OURPID		;GET MY PID
	MOVEM	T1,SMSG+1		;INTO THE MSG
	MOVEI	T1,-1			;SET THE QUOTAS TO INFINITY
	MOVEM	T1,SMSG+2		;IN MSG
	MOVEI	T1,IP.CFP		;SET THE PRIV BIT IN FLAGS
	MOVEM	T1,SPDB+.IPCFL		;IN THE FLAGS WORD
	MOVE	T1,SMSGPT		;POINT AT MSG
	MOVEM	T1,SPDB+.IPCFP		;IN PDB
	MOVE	T1,IPCPID		;GET IPCC'S PID
	MOVEM	T1,SPDB+.IPCFR		;USE AS RECIEVERS PID
	MOVE	T1,SPDBPT		;POINT AT PDB
	IPCFS.	T1,			;SEND!!!
	 JRST	SNDERR			;HANDLE ERRORS
	PUSHJ	P,CLRRCV		;CLR MSG BLK
	MOVE	T1,RMSGPT		;POINT AT MSG
	MOVEM	T1,RPDB+.IPCFP		;IN PDB
	MOVE	T1,RPDBPT		;POINT AT PDB
	IPCFR.	T1,			;RECIEVE
	 JRST	RCVERR			;HANDLE THE ERROR
	MOVE	T1,RMSG+2		;GET THE QUOTA
	CAIE	T1,-1			;INFINITE QUOTA?
	 FATAL <FAILED TO SET IPCF QUOTAS TO INFINITY>
	POPJ	P, 0			;YES WE DID IT!!
;ROUTINE TO SEND A MESSAGE TO A WOULD BE SLAVE TELLING HIM WE HAVE NO ROOM
;FOR HIM TO BECOME A SLAVE

NOROOM:	PUSHJ	P,CLRSND		;GO CLR MSG BLK
	MOVE	T1,NCNTMS		;PUT A "NO CONNECT" 
	MOVEM	T1,SMSG			;INTO MSG
	MOVE	T1,CMSGPT		;POINT TO A CONNECT MSG
	MOVEM	T1,SPDB+.IPCFP		;IN PDB
	MOVE	T1,RPDB+.IPCFS		;GET SENDERS PID
	MOVEM	T1,SPDB+.IPCFR		;USE IT AS RECIEVERS PID
	MOVE	T1,SPDBPT		;POINT AT PDB
	IPCFS.	T1,
	 JRST	SNDERR			;GO HANDLE ERRORS
	JRST	PAKWAT			;OR GO WAIT FOR ANOTHER PACKET
;HERE ON A SEND ERROR FROM IPCF

SNDERR:	MOVE	T2,T1			;GET ME THE ERROR CODE
	CAIG	T2,5			;GREATER THAN 5?
	FATAL	<FATAL IPCF ERROR>
	CAIN	T1,6			;ERROR 6?
	 JRST	ERR6CD			;YES ILL HANDLE IT
	CAIN	T1,7			;ERROR 7 ?
	 JRST	ERR7CD			;YES ILL HANDLE IT
	CAIN	T1,10			;ERROR 10 ?
	 JRST	ER10CD			;YES ILL HANDLE
	CAIN	T1,11			;ERROR 11?
	 JRST	ER11CD			;YES 
	FATAL	<FATAL IPCF ERROR>

;HERE ON A RECIEVE ERROR

RCVERR:	FATAL	<IPCF RECEIVE ERROR>
;ASSORTED ERROR HANDLING ROUTINES

ERR6CD:
ERR7CD:
ER11CD:	MOVE	T1,SPDB+.IPCFR		;GET RECIEVERS PID
	MOVNI	T4,SLVCNT		;GET -NUMBER OF SLAVES
	HRL	T4,T4			;MAKE IT -SLVNUM,,0
	MOVEI	T2,SLVTBL		;GET THE ADDRESS
	HRR	T4,T2			;MAKE IT -SLVNUM,,SLVPID
ERR6LP:	CAMN	T1,(T4)			;IS THIS THE ONE?
	 JRST	ZEROIT			;YES GO KILL IT
	AOBJN	T4,ERR6LP		;NO..GO LOOK AGAIN
	JRST	PAKWAT			;IF YOU DONT FIND IT..I DONT CARE




ER10CD:	FATAL 	<IPCF SEND QUOTA EXCEEDED>
;ASSORTED CONSTANT DEFINITIONS

SPDBPT:	XWD PDBLEN,SPDB			;POINTS AT PDB OF SENT MSG
RPDBPT:	XWD PDBLEN,RPDB			;POINTS AT PDB OF RECIEVED MSG
SMSGPT:	XWD MSGLEN,SMSG			;POINTS AT SENT MESSAGE
RMSGPT:	XWD MSGLEN,RMSG			;POINTS AT RECIEVED MESSAGE
CMSGPT:	XWD 1,SMSG			;POINTS AT CONNECT MSG
PRIVPT:	XWD -1,.GTPRV			;GETTAB ARG FOR PRIVS
IPCPT:	XWD .IPCPS,.GTSID		;GETTAB ARG FOR IPCC'S PID
SELPTR:	XWD .IPCPL,.GTSID		;GETTAB ARG FOR SEL'S PID
CLRSMS:	XWD SPDB,SPDB+1			;BLT WD TO CLR SMSG
CLRRMS:	XWD RPDB,RPDB+1			;BLT WD TO CLR RMSG
MOVSMR:	XWD RMSG,SMSG			;BLT WD TO MOVE SMSG TO RMSG
MOVRMS:	XWD SMSG,RMSG			;BLT WD TO MOVE RMSG TO SMSG
CLRPTB:	XWD SLVTBL,SLVTBL+1		;BLT WD TO CLR SLAVE PID TABLE
MOVIBK:	XWD IHANCD,INTBLK		;BLT WD TO SET UP INTERRUPT BLK
CNCTMS: SIXBIT/CNCT/
NCNTMS:	SIXBIT/NOCNCT/
OCNTMS:	SIXBIT/OKCNCT/
IHANCD:	XWD 4,CCTRAP
	XWD 0,ER.ICC
	Z
	Z
;ROUTINE TO SET UP CTRL-C TRAP

TRPSET:	MOVEI	T1,INTBLK		;[713-TJW]GET ^C TRAP HNDLR BLOCK ADR
	MOVEM	T1,.JBINT		;[713-TJW]PUT IT INTO THE INTERRUPT WORD
	POPJ	P,0			;[713-TJW]RETURN
;CHRCHK -- ROUTINE TO DETERMINE IF THIS ENTRY SHOULD BE LISTED
;EXITS TO SKIPIT IF ENTRY NOT DESIRED
;ELSE XFERS ENTRY TO WORK BUFFER AND DISPATCHES TO ENTRY PROCESSOR
;SPECIFIED IN PCSTBL WORD

CHRCHK:	TRNE	F,F.SEQ			;SEQ?
	JRST	XFRBUF			;YES. JUST GET BUFFER
	TRNE	F,F.ENT			;ENTRY?
	 JRST	ENTCHK			;YES
	SKIPN	ERRIND			;PICKUP ENTRY TYPE
	JRST	XFRBUF			;ALWAYS PASS ENTRY TYPE 0
	MOVE	T1,ERTYPE		;CORRECT INDEX TO ENTCHR TABLE
	MOVE	T2,ENTCHR(T1)		;PICKUP ENTRY CHAR WORD
	TLZ	F,F.BTCK		;CLEAR EXAMINE ENTRY FLAG
	TLNN	T2,E.LALL!E.LNXM!E.LPAR!E.LPER!E.LSUM	;ANY LISTING DESIRED
	JRST	SKIPIT			;SKIP THIS ENTRY
	TLNE	T2,E.LNXM!E.LPAR!E.LPER!E.LSUM	;ANY BIT CHECKING?
	TLO	F,F.BTCK		;YES-SET FLAG TO DO IT LATER
	MOVE	T3,ERTYPE		;GET CORRECT INDEX
	AOS	ENTCHR(T3)		;NO- BUMP COUNTER
	SETZ	WKINDX,			;CLEAR INDEX INTO BUFFER
XFRBUF:	SKIPG	T1,ENTRWC		;PICKUP ENTRY LENGTH AND CHECK FOR LEGALITY
	JRST	ENTRST			;OPPS TRY TO RESYNC
	MOVNS	T1			;PUT -LENGTH IN T1
	MOVS	WKINDX,T1		;SETUP FOR AOBJ USE
	HRRI	WKINDX,0		;SET RH OF WKINDX TO 0
	SKPNOW				;[713-TJW] BUFFERS ALREADY FILLED.
	TLO	F,F.READ		;[713-TJW]NOW LETS DO BUFFER XFER
XFRMOR:	NOTNOW				;[713-TJW]BUFFERS ALREADY FILLED
	 JRST	XFRDUN			;[713-TJW]IF ON-LINE LOGGING
	PUSHJ	P,GETWD			;LOOP HERE TO FILL WK BUFFER
	MOVEM	MASTWD,WKBUFF(WKINDX)
	AOBJN	WKINDX,XFRMOR		;IS ALL OF ENTRY IN WKBUFF

XFRDUN:	TLNN	F,F.REM			;/REMOTE:?
	 JRST	XFRDN2			;YES! - DON'T BOTHER CHECKING FOR KLERR
	MOVE	T3,ERTYPE		;GET ERROR CODE
	IORI	T3,100			;CHECK FOR 30 OR 130
	CAIE	T3,130			;IS IT AN FE ENTRY?
	JRST	XFRDN2			;NO. SKIP KLERR CHECK
	HRRZ	T1,WKBUFF+FE%LTH	;GET # OF 8 BIT BYTES
	LSH	T1,-1			;MAKE IT # OF 11 WORDS
	MOVEM	T1,PAKSIZ		;SAVE FOR KLE200,KLE201
	HRRZ	T2,WKBUFF+FE%COD	;GET SUB CODE
	CAIN	T2,200			;A RELOAD?
	PUSHJ	P,KLE200		;YES. CLEAR STUFF
	HRRZ	T2,WKBUFF+FE%COD	;GET SUBCODE AGAIN
	CAIN	T2,201			;KLERR ENTRY?
	PUSHJ	P,KLE201		;YES. SAVE ENTRY
XFRDN2:	TRNN	F,F.SEQ			;IS THIS SEQUENCE MODE?
	JRST	XFRDN1			;NO. SKIP CHECKS
	MOVE	T1,SEQIND		;GET CURRENT INDEX TO SEQUENCE #
	SKIPN	T2,SEQTAB(T1)		;VALID OR END OF TABLE?
	JRST	GOSUM			;END OF TABLE. ALL DONE
	CAME	T2,SEQNUM		;WANT THIS ENTRY?
	JRST	ABORT			;NO, FORGET IT
	AOS	SEQIND			;YES. DON'T FORGET TO CHANGE INDEX
XFRDN1:	TLZ	F,F.READ		;SAY THAT BUFFER XFER COMPLETED
	MOVE	T1,ERTYPE
	CAIN	T1,ER.WHY		;RELOAD? (1) [110]
	PUSHJ	P,SUMUPD##		;YES UPDATE PERM COUNTERS
	MOVE	T1,ERTYPE		;GET TYPE OF ENTRY
	CAIN	T1,ER.DPE		;DISK ENTRY? (10)
	PUSHJ	P,DVCHAR		;SETUP DEVICE TYPE ETC
	MOVE	T1,ERTYPE
	CAIN	T1,ER.MAG		;MAGTAPE ENTRY? (20)
	PUSHJ	P,TMCHAR		;SETUP
	MOVE	T1,ERTYPE		;AGAIN
	CAIN	T1,ER.MDE		;MASBUS ENTRY? (11)
	PUSHJ	P,MDECHR		;DO THIS ALSO
	MOVE	T1,ERTYPE		;AND RESTORE
	CAIN	T1,SEC%MB		;MASSBUS ENTRY FOR TOPS-20? (111)
	PUSHJ	P,MBCHAR		;YES-GO SET UP CHARACTERISTICS
	MOVE	T1,ERTYPE		;AGAIN			[1340]
	CAIN	T1,ER.DXE		;DX20 TOPS10 ? (12)	[1340]
	PUSHJ	P,DXECHR		;YES - GO DO IT		[1340]
	MOVE	T1,ERTYPE		;NO!			[510]
	CAIN	T1,SEC%DX		;DX20 ENTRY? (112)	[510]
	PUSHJ	P,DXCHAR		;YES! - DO SETUP	[510]
	MOVE	P4,ERRIND
	TLNE	F,F.BTCK		;EXAMINE ENTRY TO DETERMINE LISTING?
	PUSHJ	P,[SKIPE ERRIND
		PUSHJ P,@BITCHK##(P4)	;GO DO BIT CHECKING
		POPJ	P,0]
	SKIPN	ERRIND			;[417]
	 JRST	.+3
	TRNE	F,F.REM
	JRST	REMDAT
	SKIPE	ERRIND			;NO HEADER IF NOT FOR THIS SEGMENT
	PUSHJ	P,HDRLST		;OUTPUT HEADER TYPE,DATE,TIME,UPTIME
	MOVE	T2,ALLIND
	HRRZ	T1,PCSTBL##(T2)	
	HLRZ	CTINDX,PCSTBL(T2)	;PICKUP CONTROL TABLE ADDRESS
	JRST	(T1)			;DISPATCH TO ENTRY PROCESSOR

;ROUTINE TO MOVE RAW DATA ENTRY TO OUTPUT "DAT" FILE
;IN IMAGE BINARY.  USED WITH /REMOTE SWITCH
;ADDED WITH [417]

REMDAT::HRLZ	P1,HEADWC		;SETUP PNTR FOR HEADER
	MOVNS	P1,P1
	HRRI	P1,0

REMDA1:	MOVE	T1,HDBUFF(P1)		;GET A HEADER WORD
	SOS	HEADWC			;ADJUST # DONE
	PUSHJ	P,PUTDAT		;OUTPUT IT
	AOBJN	P1,REMDA1		;AGAIN IF REQ'D

;NOW FOR THE BODY OF THE ENTRY

	HRLZ	P1,ENTRWC
	MOVNS	P1,P1
	HRRI	P1,0
REMDA2:	MOVE	T1,WKBUFF(P1)		;GET AN ENTRY WORD
	SOS	ENTRWC
	PUSHJ	P,PUTDAT
	AOBJN	P1,REMDA2		;AGAIN
	JRST	ABORT			;NO LISTING FOR THIS ENTRY-GETNEXT
;START [731]
ENTCHK:	MOVE	T1,ERTYPE		;GET CURRENT ENTRY
	CAME	T1,ENTRY		;MATCH ARGUEMENT?
	 JRST	SKIPIT			;NOPE
	JRST	XFRBUF			;YES LIST IT
;END[731]
	SUBTTL	ROUTINES TO WORK WITH KLERROR FILE PACKETS

;START EDIT  [1226]  MOVED KLE200 & KLE201 HERE FORM SYSERC & SYSERD
; FIXED AGAIN WITH EDIT  [1235]

KLE200:	SKIPE	KLEFL2			;ALREADY PROCESSING FILE?
	 PUSHJ	P,KLEDMP		;WE SHOULDN'T BE!!
	SETOM	KLEFL1			;WATCH FOR NEXT CODE 201
	POPJ	P,0			;BACK TO XFRDUN

KLE201:	SKIPN	KLEFL2			;ALREADY BUILDING KLEFIL?
	 PUSHJ	P,KL201B		;NO-CHECK FURTHER
	SKIPE	KLEFL1			;1ST PACKET?
	 PUSHJ	P,KLEFCL		;CLEAR WORK AREA & INIT POINTERS
	SETZM	KLEFL1			;DONE THE INIT
	SETOM	KLEFL2			;NOW WE'RE BUILDING THE FILE INTO KLEFIL
	HRRZ	T1,WKBUFF+FE%OFF
	ADDI	T1,WKBUFF		;CORRECTED POINTER
	LDB	T2,[POINT 16,0(T1),15]	;GET STD STATUS BYTE
	TRNE	T2,1B30			;EOF?? IE LAST PACKET??
	 SETOM	KLEFL3			;YES-DO LISTING IF REQ'D
;NOW ADD THIS PACKET TO KLEFIL
	MOVEI	P3,1			;INIT W ORD COUNTER

	MOVE	P1,WKBUFF+FE%OFF	;GET POINTER WORD
	ADDI	P1,WKBUFF		;CORRECTED
	SKIPE	KLEFL4			;SHOULD WE SKIP SOME WORDS?
	 PUSHJ	P,SKPKLE		;YES-GO DO IT
	MOVE	P2,KLEPNT		;WHERE TO PUT WORDS
	SKIPE	KLEFL3			;WORK ON THIS PACKET AT ALL?
	 JRST	PAKDON			;NO
	LDB	T1,[POINT 16,0(P1),31]	;FORGET 1ST BYTE
	MOVEM	T1,0(P2)		;STORE IT AWAY
	AOBJN	P2,.+2			;UPDATE STORE POINTER
	 PUSHJ	P,KLEDON		;FILE IS FINISHED
	AOS	P3
	CAMN	P3,PAKSIZ
	 JRST	PAKDON
	AOBJN	P1,.+2			;UPDATE FETCH POINTER
	 JRST	PAKDON			;PACKET IS FINISHED

KL201A:	LDB	T1,[POINT 16,0(P1),15]	;GET LEFT BYTE
	MOVEM	T1,0(P2)		;PUT IT AWAY
	AOBJN	P2,.+2			;UPDATE STORE POINTER
	 PUSHJ	P,KLEDON		;FILE IS FINISHED
	AOS	P3
	CAMN	P3,PAKSIZ
	 JRST	PAKDON
	LDB	T1,[POINT 16,0(P1),31]	;GET RIGHT BYTE
	MOVEM	T1,0(P2)		;AWAY
	AOBJN	P2,.+2			;UPDATE STORE POINTER
	 PUSHJ	P,KLEDON		;FILE IS FINISHED
	AOS	P3
	CAMN	P3,PAKSIZ
	 JRST	PAKDON
	AOBJN	P1,KL201A		;GET NEXT PAIR

PAKDON:	MOVEM	P2,KLEPNT		;STORE POINTER AWAY
	SKIPN	KLEFL3			;WAS THIS LAST PACKET?
	POPJ	P,0			;NO! - DON'T CLEAR FLAGS
	SETZM	KLEFL3			;CLEAR THE FINISHED FLAG &
	SETZM	KLEFL2			;CLEAR THE BUILDING FLAG
	 POPJ	P,0

;KLEFIL IS COMPLETE-BCK130 ROUTINES WILL
;DETERMINE IF IT SHOULD BE LISTED AND DO SUMMARY.
;LISTING WILL BE DONE THROUGH PROCSD ROUTINES.


KL201B:	SKIPE	KLEFL1			;1ST PACKET ALREADY SET?
	 POPJ	P,0			;YUP-ALL IS WELL
	WARN	<UNEXPECTED CODE 130-201 FOUND,ASSUMING START OF FILE>
	TYPEIT	<
$$$$$$$  >
	TYPEIT	<UNEXPECTED CODE 130-201 FOUND,ASSUMING START OF FILE>
	PUSHJ	P,.TCRLF		;CONTINUE ON NEXT LINE
KL201C:	SETOM	KLEFL1			;FORCE START OF FILE
	POPJ	P,0
;KLEFCL--ROUTINE TO CLEAR BUFFER AREA AND INIT POINTERS

KLEFCL:	SETZM	KLEFL4
	SETZM	KLEFL5			;CLEAR SOME FLAGS
	SETZM	KLEFIL			;CLEAR START
	MOVE	T1,[XWD KLE1FL,KLE1FL+1]
	BLT	T1,KLEEND		;CLEAR IT ALL INCL KLE1FL AREA
	HRRZ	T2,WKBUFF+FE%OFF	;GET OFFSET
	ADDI	T2,WKBUFF		;CORRECTED
	LDB	T3,[POINT 16,1(T2),15]	;THAT GETS FILE LENGTH!?
	IDIVI	T3,2			;[230]CONVERT TO WORDS FROM BYTES
	SKIPN	T3			;BUT IF ZERO
	 MOVEI	T3,KLESIZ		;USE DEFAULT
	CAILE	T3,KLESIZ		;ALSO IF GREATER
	 MOVEI	T3,KLESIZ		;USE DEFAULT
	MOVN	T1,T3			;-WC
	MOVS	T1,T1			;TO LH
	HRRI	T1,KLEFIL		;START THERE 
	MOVEM	T1,KLEPNT		;STORE IT AWAY
	POPJ	P,0


;HERE WHEN WC FOR KLEFIL IS EXHAUSTED
KLEDON:	SKIPE	KLEFL5			;DOING 2ND HALF ALREADY?
	 JRST	KLEDN1			;YES
	HRRZ	T1,P2			;LAST ADDR USED
	SUBI	T1,KLEFIL		;ADJUSTED START ADDR
	IDIVI	T1,200			;# BLOCKS USED
	MOVEI	T1,200			;INTERESTED IN REMAINDER ONLY
	SUB	T1,T2			;T1 HOLDS # OF WDS TO SKIP TO GET
					;TO START OF NEXT BLOCK IN PDP-11 FORMAT
	CAIN	T1,200			;BUT IF ZERO
	 JRST	KLEDN2
KLEDN4:	HLRE	T2,P1			;P1HOLDS PACKET PNTR
	MOVMS	T2,T2			;# LEFT IN THIS PACKET
	CAMGE	T1,T2			;MORE THAN IN THIS PACKET?
	 JRST	KLEDN3			;NO
	SUB	T1,T2			;YES,T1 GETS REMAINDER TO SKIP IN
					;NEXT PACKET
	SKIPE	T1			;NOW = 0?
	 SETOM	KLEFL4			;REMEMBER TO SKIP
	MOVEM	T1,KLESKP		;SAVE THE NUMBER
	SETOM	KLEFL5			;NOW DOING 2ND HALF
	HRLZI	T1,KLESIZ		;MAX LENGTH
	MOVNS	T1,T1
	HRRI	T1,KLE1FL		;SECOND AREA
	MOVEM	T1,KLEPNT		;FOR FUTURE USE
	POPJ	P,0
;	JRST	ABORT		;NO MORE FOR THIS ENTRY

;HERE WHEN 2ND RECORD WC EXPIRES--SHOULDN'T HAPPEN BUT...
KLEDN1:	SUBI	P2,1			;ADJUST POINTER FOR THIS WORD
	MOVEM	P2,KLEPNT		;AND STORE IT
	JRST ABORT

;WASTE REST OF ENTRIES UNTIL EOF IS SEEN IN
;PACKET.  POINTER IS NOT STORED IN KLEPNT SO ALL
;SUCCEEDING WORDS WILL BE OVERWRITTEN AT END OF
;KLE1FL.


;HERE TO SKIP &STAY IN CURRENT ENTRY.
;T1 HAS # TO SKIP

KLEDN3:	IDIVI	T1,2			;2 WDS PER KL WORD
	ADD	P1,T1			;RH IS FIXED
	HLRE	T2,P1			;GET -WC
	ADD	T2,T1			;FIX IT
	HRL	P1,T2			;RETURN IT
	LSH	T1,1
	ADD	P3,T1			;UPDATE BYTE CNT
					;AND FALL INTO

;HERE IF 0 WDS TO SKIP BETWEEN RECORDS--SHOULD BE NORMAL CASE(I HOPE)
KLEDN2:	SETOM	KLEFL5			;WORK ON 2ND HALF
	HRLZI	T1,KLESIZ		;MAX
	MOVNS	T1,T1
	HRRI	T1,KLE1FL		;WHERE TO PUT WORDS
	MOVEM	T1,KLEPNT		;FOR FUTURE USE
	MOVE	P2,T1			;SETUP NEW PNTR
	POPJ	P,0			;BACK TO OUR CALLER
;	JRST	ABORT		;THIS SEEMS TO BE THE CORRECT THING
					;TO DO,IF WE WASTE THE REST OF THIS ENTRY
					;THE SECOND RECORD APPEARS TO BE BACK IN
					;SYNC FOR VERSION 1B OF THE MONITOR.

;HERE TO SKIP WORDS AT THE START OF PACKET PROCESSING
SKPKLE:	MOVE	T1,KLESKP		;# TO SKIP
	JRST	KLEDN4			;GET SOME CODE CHEAP!!

;ROUTINE TO LIST PARTIAL CONTENTS OF KLEFIL CALLED WHEN ANOTHER
;START OF FILE(CODE 201) IS DETECTED OR ERROR FILE INCONSISTENCY

;DEBUG SWITCH FOR 'KLERR' OCTAL DUMP

KLEDMP:	IFE	DEBUGA,	<
	WARN	<INCOMPLETE KLERROR ENTRY SEEN!>
	POPJ	P,0
>;END DEBUGA	[530]

	IFN	DEBUGA,	<
	PUSHJ	P,TITLST		;FRESH PAGE
	SETZM	KLEFL2
	SETZM	KLEFL3			;CLEAR FLAGS
	WARN	<DUMPING PARTIAL CONTENTS OF KLERROR FILE IN OCTAL>
	TYPEIT	<

*** DUMPING PARTIAL CONTENTS OF KLERROR FILE IN OCTAL ***
>
	SETZ	P3,
	TYPEIT	<	# OF KLERROR BYTES DUMPED:	>
	HRRZ	T1,KLEPNT		;LAST ADDR USED
	SUBI	T1,KLEFIL		;1ST USED
	ADDI	T1,1			;ADJUST FOR 1ST
	MOVMS	T1,T1			;ABSOLUTE MAGNITUDE
	MOVEI	T2,KLESIZ		;SETUP A VALUE
	IMULI	T2,2
	CAMLE	T1,T2			;TOO BIG??
	 MOVE	T1,T2			;CHANGE TO MAX
	MOVE	P4,T1			;SAVE IT
	PUSHJ	P,.ODECW		;DUMP IN DECIMAL
	TYPEIT	<
*** DUMPING 1ST RECORD ***
>
	PUSHJ	P,.TCRLF
	PUSHJ	P,.TCRLF
;SAME CODE AS IN STBUFA!
KLEDMA:	MOVEI	P1,8			;WORDS PER LINE
KLEDMB:	PUSHJ	P,SPACE3
	MOVEI	P2,^D12			;CHARACTERS PER WORD
	PUSHJ	P,KLEDMX		;GET A WORD INTO T1
	MOVE	T2,T1
KLEDMC:	MOVEI	T1,0
	ROTC	T1,3			;GET 3 BITS
	ADDI	T1,60			;CONVERT TO ASCIZ
	PUSHJ	P,.TCHAR
	SOJG	P2,KLEDMC		;NEXT 3 BITS
	MOVE	P2,P4			;ANY MORE WORDS?
	CAIN	P2,1
	 POPJ	P,0
	SOJG	P1,KLEDMB		;FINISH THE LINE
	PUSHJ	P,.TCRLF		;NEXT LINE
	JRST 	KLEDMA			;START AGAIN
KLEDMX:	SOSGE	P4
	 JRST	KLEDMZ			;BUMP AND RETURN
	AOJ	P3,
	CAILE	P3,KLESIZ		;DONE 1ST RECORD?
	 PUSHJ	P,KLEDMY		;ADJUST FOR 2ND
	MOVE	T1,KLEFIL(P3)		;GET NEXT WORD
	POPJ	P,0

KLEDMY:	MOVE	T1,[XWD KLE1FL,KLEFIL]	;DON'T BOTHER CLEARING
	BLT	T1,LOWEND-1
	TYPEIT	<
*** DUMPING 2ND RECORD ***

>
	POPJ	P,0			;NOW CONTINUE

KLEDMZ:	POP	P,T1			;DUMMY TO GET RID OF OUR CALLER
	POPJ	P,0			;NOW BACK TO KLEDMP'S CALLER
>;END DEBUGA	[530]
;END EDIT  [1226]
;START [1146]
;LSTOCT - LISTS CONTENTS OF WKBUFF
; 	IN OCTAL.
;CALL PUSHJ	USES P1&P2

LSTOCT:	TYPEIT	<
CONTENTS OF WKBUFF IN OCTAL:>
	MOVN	P1,ENTRWC		;#WDS TO LIST
	HRLZ	P1,P1			;AOB PNTR
	SETZM	P2
OCTLS1:	PUSHJ	P,.TCRLF
	TYPEIT	< WKBUFF+>
	MOVE 	T1,P2
	PUSHJ	P,.TOCTW
	TYPEIT	<:	>
	MOVE	T1,WKBUFF(P1)		;GET THE WORD TO LIST
	PUSHJ	P,.TXWDW
	ADDI	P2,1			;BUMP COUNTER
	AOBJN	P1,OCTLS1		;MORE TO DO?
	 POPJ	P,0			;NO

;END [1146]
	SUBTTL	DYNAMIC TABLE ALLOCATION ROUTINES

	SALL

;START EDIT 1200
;GETBF <PUSHJ P,GTBF00> - ALLOCATES BUFFER SPACE
;FINDB <PUSHJ P,FNDB00> - FINDS A BUFFER
;FINDF <PUSHJ P,FNDF00> - FINDS THE FIRST BUFFER IN A LIST
;FINDN <PUSHJ P,FNDN00> - FINDS THE NEXT BUFFER IN A LIST

;FOR A DESCRIPTION OF THE ROUTINES AND CALL FORMATS SEE;
;     "SUBROUTINE CALLS FOR DYNAMIC TABLE ALLOCATION"

GTBF00:	MOVE	T4,ALCFLG
	JUMPN	T4,GTBF02		;IF ALCFLG = 0
	PUSHJ	P,ALCINI		; INITIALIZE ALLOCATOR
	 RETFAL				; IF NO CORE AVAILABLE TAKE FAIL EXIT
GTBF02:	HRRZ	T3,ALCFLG+1		;GET POINTER TO WORK SPACE
	SETZM	WRKARG(T3)		; AND RESET THE 'FINDN' FLAG
	MOVE	T3,(T1)			;IF THE LIST ANCHOR EXISTS
	JUMPN	T3,GTBF08		; TEST THE PARAMETERS
	HLRZ	T3,T2
	CAILE	T3,KEYMAX		;IF ILLEGAL # OF KEYS
	RETFAL	(ALCKEY)		; TAKE FAIL EXIT
	HLRZ	T4,T1
	CAILE	T4,BUFMAX		;IF ILLEGAL BUFFER LENGTH
	RETFAL	(ALCLEN)		; TAKE FAIL EXIT
	DPB	T3,[KEYS(T1)]		;BUILD ANCHOR
	DPB	T4,[BUFSIZ(T1)]
	JUMPN	T3,GTBF05		;IF BUFFER IS UNLABLED
	PUSHJ	P,ALCORE		; GET SPACE
	 RETFAL				; TAKE FAIL EXIT IF NO CORE AVAILABLE
	HRRZM	T3,1(T1)		; CREATE ANCHOR FOR IT
	HRRZ	T1,T3
	RETPAS				; TAKE PASS EXIT

GTBF05:	SETZM	1(T1)			;HERE IF BUFFER IS LABLED
	MOVNS	T3
	HRL	T2,T3			;MAKE AOBJ POINTER
	JRST	GTBF25			;CREATE BUFFER

GTBF08:	LDB	T3,[BUFSIZ(T1)]
	HLRZ	T4,T1
	CAME	T3,T4			;IF BUFFER LENGTHS DIFFER
	RETFAL	(ALCLEN)		; TAKE FAIL EXIT
	LDB	T3,[KEYS(T1)]
	HLRZ	T4,T2
	CAME	T3,T4			;IF # OF KEYS DIFFER
	RETFAL	(ALCKEY)		; TAKE FAIL EXIT
	JUMPN	T3,GTBF10		;IF BUFFER IS LABLED - LOOK FOR IT
	HRRZ	T1,1(T1)		; ELSE GET ITS ADDRESS
	RETPAS				; AND TAKE PASS EXIT
GTBF10:	MOVNS	T3
	HRL	T2,T3			;CREATE AOBJ POINTER
GTBF12:	HRRO	T4,T1			;SAVE OLD LINK POINTER WITH '-' FLAG
	HRR	T1,1(T1)		; AND GET NEW ONE
	MOVE	T3,(T2)
GTBF14:	CAMLE	T3,0(T1)		;IF TEST ARG > CURRENT KEY
	JRST	GTBF18			; GET NEXT LIST
	CAMN	T3,0(T1)		;IF KEYS ARE THE SAME
	JRST	GTBF16			; GET NEXT KEY
	HRR	T1,T4			;GET OLD LINK POINTER
	JUMPG	T4,GTBF20		;IF + CREATE A BUFFER INSIDE A LIST
	JRST	GTBF25			; ELSE CREATE A BUFFER AT TOP OF A LIST

GTBF16:	AOBJN	T2,GTBF12		;CONTINUE IF MORE KEYS
	ADDI	T1,2			;POINT AT DATA BLOCK
	RETPAS				;TAKE PASS RETURN

GTBF18:	HLRZ	T4,1(T1)		;IF END OF LIST
	JUMPE	T4,GTBF20		; CREATE BUFFER
	HRRZ	T4,T1			;SAVE OLD LINK POINTER WITH + FLAG
	HLR	T1,1(T1)		; AND GET NEW ONE
	JRST	GTBF14			;CONTINUE SEARCHING


;ENTER HERE WITH:
; T1 LH = LENGTH OF BUFFER
;    RH = ADDRESS OF LINK POINTER TO INSERT NEW BUFFER
; T2    = -# OF UNMATCHED KEYS ,, ADDRESS OF FIRST KEY

GTBF20:	HLRE	T3,T2			;ENTER HERE FOR ADDITION INSIDE LIST
	MOVNS	T3
	HLRZ	T4,T1
	PUSHJ	P,ALCORE		;ALLOCATE CORE
	 RETFAL				;IF NONE AVAILABLE TAKE FAIL EXIT
	HLRZ	T4,1(T1)
	HRLM	T3,1(T1)
	HRLM	T4,1(T3)		;INSERT THIS BUFFER IN LINKED LIST
	JRST	GTBF40			; AND BUILD THE REST OF THE HEADER

GTBF25:	HLRE	T3,T2			;ENTER HERE FOR ADDITION AT TOP OF A LIST
	MOVNS	T3
	HLRZ	T4,T1
	PUSHJ	P,ALCORE		;ALLOCATE CORE
	 RETFAL				;IF NONE AVAILABLE TAKE FAIL EXIT
	HRRZ	T4,1(T1)
	HRRM	T3,1(T1)
	HRLM	T4,1(T3)		;INSERT THIS BUFFER IN LINKED LIST
	JRST	GTBF40			; AND BUILD THE REST OF THE HEADER

GTBF30:	HRRM	T3,-1(T3)		;INSERT POINTER TO THIS KEY
	SETZM	1(T3)			;SET POINTER TO ZERO TO MARK LIST END
GTBF40:	MOVE	T4,(T2)
	MOVEM	T4,0(T3)		;PUT NEW KEY IN BUFFER HEADER
	ADDI	T3,2			;ADJUST POINTERS
	AOBJN	T2,GTBF30		; AND CONTINUE IF MORE KEYS
	HRRZ	T1,T3			;PUT POINTER TO BUFFER IN "AC1"
	RETPAS				; AND TAKE PASS EXIT
;ALLOCATES WORK SPACE ON FIRST CALL TO 'GETBF'
;RETURNS +1: FAILURE, WITH ERROR CODE IN T1
;	 +2: SUCCESS

ALCINI:	SETZ	T3,			;CREATE AN ANCHOR
	MOVEI	T4,ALCWRK		; FOR AN UNLABLED WORK SPACE
	DPB	T3,[KEYS+ALCFLG]
	DPB	T4,[BUFSIZ+ALCFLG]
	PUSHJ	P,ALCORE		;ALLOCATE WORK SPACE
	 RETFAL				;IF NONE AVAILABLE TAKE FAIL EXIT
	HRRZM	T3,ALCFLG+1		;SAVE POINTER TO WORK SPACE
	RETPAS				;TAKE PASS EXIT


;ALLOCATES CORE FOR A NEW BUFFER -- CALLED WITH:
;	T3 = # OF KEY BLOCKS REQUIRED
;	T4 = LENGTH OF DATA BLOCK REQUIRED
;RETURNS +1: FAILURE, WITH ERROR CODE IN T1
;	 +2: SUCCESS, WITH ALL AC'S UNMODIFIED, EXCEPT T3 & T4:
;		T3 = ADDRESS OF FIRST WORD OF BUFFER

ALCORE:	IMULI	T3,2			;# OF KEYS TIMES 2
	ADD	T4,T3			; PLUS DATA BLOCK LENGTH
	HRRZ	T3,.JBFF		;SAVE BUFFER ADDRESS
	ADDB	T4,.JBFF		; AND CALCULATE END ADDRESS
	CAMG	T4,.JBREL		;IF NO MORE CORE NEEDED
	RETPAS				; TAKE PASS EXIT
	CORE	T4,0			;TRY TO ALLOCATE MORE CORE
	 RETFAL	(ALCCOR)		; IF NONE AVAILABLE TAKE FAIL EXIT
	RETPAS				;TAKE PASS EXIT
FNDB00:	SKIPN	ALCFLG			;IF ALLOCATOR NOT INITIALIZED
	RETFAL	(ALCNXA)		; TAKE FAIL EXIT
	HRRZ	T3,ALCFLG+1		;GET POINTER TO WORK SPACE
	SETZM	WRKARG(T3)		; AND RESET THE 'FINDN' FLAG
	SKIPN	0(T1)			;IF THE LIST ANCHOR DOESN'T EXIST
	RETFAL	(ALCNXL)		; TAKE FAIL EXIT
	LDB	T4,[KEYS(T1)]
	HLRZM	T2,WRKKEY(T3)		;SAVE # OF KEYS FOR 'FINDN' CALL
	CAME	T4,WRKKEY(T3)		;IF # OF KEYS DIFFER
	RETFAL	(ALCKEY)		; TAKE FAIL EXIT
	JUMPN	T4,FNDB05		;IF BUFFER IS UNLABLED
	HRRZ	T1,1(T1)		; POINT TO DATA BLOCK
	RETPAS				; AND TAKE PASS EXIT
FNDB05:	TLO	T3,T4			;LET T3 POINTER USE T4 AS AN INDEX
	HRRZS	T2			;CLEAR LEFT SIDE AND
	TLO	T2,T4			; SETUP THE KEY ARGUMENT BLOCK POINTER
	MOVEM	T2,WRKARG(T3)		; THE SAME WAY AND SAVE IT
	SETZ	T4,			;SET INDEX TO 0 - GET FIRST POINTER
	HRRZ	T2,1(T1)		; AND START SEARCHING FOR THE BUFFER
FNDB10:	MOVE	T1,0(T2)		;GET CURRENT KEY
	CAMN	T1,@WRKARG(T3)		;IF KEYS ARE THE SAME
	JRST	FNDB30			; GET NEXT KEY
	CAML	T1,@WRKARG(T3)		;IF TEST ARG < CURRENT KEY
	JRST	FNDB20			; NO SUCH BUFFER
	HLRZ	T2,1(T2)		;IF NOT END OF LIST
	JUMPN	T2,FNDB10		; TRY NEXT ONE
FNDB20:	SETZM	WRKARG(T3)		;RESET 'FINDN' FLAG
	RETFAL	(ALCNXB)		; AND TAKE FAIL EXIT

FNDB30:	HRRZ	T1,T2			;SAVE OLD POINTER IN CASE WE'RE DONE
	MOVE	T2,1(T2)		;GET NEW LINK POINTERS
	MOVEM	T2,@T3			; AND SAVE THEM IN WORK SPACE
	AOS	T4
	CAMGE	T4,WRKKEY(T3)		;IF MORE KEY LEVELS
	JRST	FNDB10			; CONTINUE
	ADDI	T1,2			;ELSE POINT AT DATA BLOCK
	RETPAS				; AND TAKE PASS EXIT
FNDF00:	SKIPN	ALCFLG			;IF ALLOCATOR NOT INITIALIZED
	RETFAL	(ALCNXA)		; TAKE FAIL EXIT
	HRRZ	T3,ALCFLG+1		;GET POINTER TO WORK SPACE
	SETZM	WRKARG(T3)		; AND RESET THE 'FINDN' FLAG
	SKIPN	0(T1)			;IF THE LIST ANCHOR DOESN'T EXIST
	RETFAL	(ALCNXL)		; TAKE FAIL EXIT
	LDB	T4,[KEYS(T1)]		;GET # OF KEYS
	JUMPN	T4,FNDF05		;IF BUFFER IS UNLABLED
	HRRZ	T1,1(T1)		; POINT TO DATA BLOCK
	RETPAS				; AND TAKE PASS EXIT
FNDF05:	MOVEM	T4,WRKKEY(T3)		;SAVE # OF KEYS FOR 'FINDN' CALL
	TLO	T3,T4			; AND LET T3 POINTER USE T4 AS AN INDEX
	TLO	T2,T4			;SETUP THE KEY ARGUMENT BLOCK POINTER
	MOVEM	T2,WRKARG(T3)		; THE SAME WAY AND SAVE IT
	SETZ	T4,			;SET INDEX TO 0 - GET FIRST POINTER
	HRRZ	T2,1(T1)		; AND START SAVING INFO FOR 'FINDN' CALL
FNDF30:	MOVE	T1,0(T2)		;PUT KEY IN SAVED
	MOVEM	T1,@WRKARG(T3)		; ARGUMENT BLOCK
	HRRZ	T1,T2			;SAVE OLD POINTER IN CASE WE'RE DONE
	MOVE	T2,1(T2)		;GET NEW LINK POINTERS
	MOVEM	T2,@T3			; AND SAVE THEM IN WORK SPACE
	AOS	T4
	CAMGE	T4,WRKKEY(T3)		;IF MORE KEY LEVELS
	JRST	FNDF30			; CONTINUE
	ADDI	T1,2			;ELSE POINT AT DATA BLOCK
	RETPAS				; AND TAKE PASS EXIT
FNDN00:	SKIPN	ALCFLG			;IF ALLOCATOR NOT INITIALIZED
	RETFAL	(ALCNXA)		; TAKE FAIL EXIT
	HRRZ	T3,ALCFLG+1		;GET POINTER TO WORK SPACE
	SKIPN	WRKARG(T3)		;IF NO PREVIOUS CALL
	RETFAL	(ALCPRE)		; TAKE FAIL EXIT
	MOVE	T4,WRKKEY(T3)		;GET # OF KEYS
	TLO	T3,T4			; AND LET T3 POINTER USE IT AS AN INDEX
FNDN10:	SOJGE	T4,FNDN20		;IF NO MORE BUFFERS
	SETZM	WRKARG(T3)		; CLEAR FLAG
	RETFAL	(ALCEND)		; TAKE FAIL EXIT
FNDN20:	HLRZ	T2,@T3			;IF END OF LIST
	JUMPE	T2,FNDN10		; GET NEXT HIGHER LIST AND TRY AGAIN
	PUSH	P,T4			;SAVE MOST SIGNIFICANT INDEX
FNDN30:	MOVE	T1,0(T2)		;PUT NEW KEY IN SAVED
	MOVEM	T1,@WRKARG(T3)		; ARGUMENT BLOCK
	HRRZ	T1,T2			;SAVE OLD POINTER IN CASE WE'RE DONE
	MOVE	T2,1(T2)		;GET NEW LINK POINTERS
	MOVEM	T2,@T3			; AND SAVE THEM IN WORK SPACE
	AOS	T4
	CAMGE	T4,WRKKEY(T3)		;IF MORE KEY LEVELS
	JRST	FNDN30			; CONTINUE
	ADDI	T1,2			;ELSE POINT AT DATA BLOCK
	POP	P,T2			; GET CHANGE INDEX BACK
	RETPAS				; AND TAKE PASS EXIT

;END EDIT 1200

	XALL
	SUBTTL	NEW COMMAND PROCESSOR - EXECUTES THE 'CMDWRD' MACRO COMMANDS

;START EDIT  [724]
;CALLED FROM PROCSx IF /BRIEF WAS USED IN COMMAND LINE
;COMMANDS MAY CONTAIN 2-4 WORDS EACH

;BUILD THE EFFECTIVE WORD

NEWCMD:	MOVE	T1,ERRIND		;GET THE OFFSET FOR THIS ENTRY TYPE
	HLRZ	CTINDX,ERRTBL(T1) 	;GET THE BRIEF CONTROL TABLE POINTER
NWCMD1:	SETZB	P2,OFFSET		;CLEAR SUB-TABLE PTR & EFFECTIVE WORD
	MOVE	P1,(CTINDX)		;GET FIRST WORD IN COMMAND
	HRRZ	T1,P1			;GET RH OF COMMAND
	CAIN	T1,-1			;ANY EFFECTIVE WORD?
	 JRST	PRETXT			;NO! - DON'T TRY TO BUILD ONE
	LDB	T1,[POINT 2,P1,16] 	;GET EFFECTIVE WORD FLAGS
	JRST	@EFWRD(T1)		;BUILD EFFECTIVE WORD

EFWRD:	EFWRD0				;SUB-TABLE & WORD OFFSETS IN WKBUFF
	EFWRD1				;SUB-TABLE OFFSET & BYTE POINTER
	EFWRD2				;REGISTER REFERENCE
	EFWRD3				;REGISTER REFERENCE & BYTE POINTER

EFWRD0:	LDB	T1,[POINT 9,P1,26] 	;GET SUB-TABLE OFFSET
	CAIE	T1,777			;ANY SUB-TABLE POINTER ?
	 PUSHJ	P,GETSUB		;YES! - WORD IS IN SUB-TABLE IN 'WKBUFF'
	LDB	P2,[POINT 9,P1,35] 	;GET WORD OFFSET
	ADD	P2,OFFSET		;ADD ANY SUB-TABLE OFFSET
	CAMLE	P2,ENTRWC		;OUTSIDE ENTRY?
	JRST	NXTCMD			;YES! - TRY NEXT COMMAND
	MOVE	P2,WKBUFF(P2)		;GET WORD
	TLNE	P1,MSK			;USE MASK?
	AND	P2,2(CTINDX)		;YES!
	JRST	TSTCMD			;EXECUTE TEST COMMAND

EFWRD1:	LDB	T1,[POINT 9,P1,26] 	;GET SUB-TABLE OFFSET
	CAIE	T1,777			;ANY SUB-TABLE POINTER ?
	 PUSHJ	P,GETSUB		;YES! - WORD IS IN SUB-TABLE IN 'WKBUFF'
	MOVEI	P2,WKBUFF		;GET LOCATION OF 'WKBUFF'
	ADD	P2,OFFSET		;ADD ANY SUB-TABLE OFFSET
	LDB	P2,2(CTINDX)		;GET BYTE - USES 'P2' AS INDEX REGISTER
	TLNE	P1,MSK			;USE MASK?
	AND	P2,3(CTINDX)		;YES!
	JRST	TSTCMD			;EXECUTE TEST COMMAND

EFWRD2:	MOVE	P2,(P1)			;GET LOWSEG REGISTER
	TLNE	P1,MSK			;USE MASK?
	AND	P2,2(CTINDX)		;YES!
	JRST	TSTCMD			;EXECUTE TEST COMMAND

EFWRD3:	SETZ	P2,			;MAKE SURE 'P2' IS ZERO
	LDB	P2,2(CTINDX)		;GET BYTE - USES 'P2' AS INDEX REGISTER
	TLNE	P1,MSK			;USE MASK?
	AND	P2,3(CTINDX)		;YES!
	JRST	TSTCMD			;EXECUTE TEST COMMAND

;GET SUB-TABLE OFFSET  (OFFSET TO WORD ALREADY IN 'T1')

GETSUB:	CAMLE	T1,ENTRWC		;OUTSIDE ENTRY?
	JRST	SUBQIT			;YES! - CLEAN STACK & TRY NEXT COMMAND
	HRRZ	T1,WKBUFF(T1)		;GET OFFSET WORD
	MOVEM	T1,OFFSET		;SAVE IT
	POPJ	P,			;RETURN

;SUB-TABLE POINTER OUT OF ENTRY RANGE

SUBQIT:	POP	P,T1			;CLEAN UP STACK
	JRST	NXTCMD			;SKIP THIS COMMAND
;EFFECTIVE WORD TEST FUNCTION TABLE
;EXECUTE DISPATCH COMMAND IF TEST IS SATISFIED

NWFUNC:	CAMA	P2,T2			;ALWAYS - ALWAYS EXECUTE DISPATCH COMMAND
	CAML	P2,T2			;IFLT - IF EFFECTIVE WORD LESS THAN VALUE
	CAMLE	P2,T2			;IFLQ - IF EFFECTIVE WORD LESS THAN OR EQUAL TO VALUE
	CAME	P2,T2			;IFEQ - IF EFFECTIVE WORD EQUALS VALUE
	CAMN	P2,T2			;IFNE - IF EFFECTIVE WORD NOT EQUAL TO VALUE
	CAMGE	P2,T2			;IFGQ - IF EFFECTIVE WORD GREATER THAN OR EQUAL TO VALUE
	CAMG	P2,T2			;IFGT - IF EFFECTIVE WORD GREATER THAN VALUE
	CAM	P2,T2			;NEVER - NEVER EXECUTE DISPATCH COMMAND - NO-OP

TSTCMD:	LDB	T1,[POINT 3,P1,2] 	;GET TEST FUNCTION
	LDB	T2,[POINT 6,P1,8] 	;GET TEST VALUE
	XCT	NWFUNC(T1)		;TEST SATISFIED?
	JRST	NXTCMD			;NO! - TRY NEXT COMMAND
PRETXT:	TLNE	P1,1B29			;POST TEXT?
	JRST	DSPCMD			;YES! - SKIP PRE TEXT ROUTINE & OUTPUT A SPACE
	HLRZ	T1,1(CTINDX)		;NO! - GET TEXT POINTER
	SKIPE	T1			;IS THERE ANY TEXT?
	PUSHJ	P,.TSTRG		;YES! - SEND IT
	SKIPA				;SKIP SPACE FOR POST TEXT
DSPCMD:	PUSHJ	P,.TSPAC		;INSURE A SPACE BETWEEN COMMANDS FOR POST TEXT
	HRRZ	T2,1(CTINDX)		;GET DISPATCH COMMAND ARGUMENT
	LDB	T1,[POINT 2,P1,10] 	;GET DISPATCH FUNCTION
	JRST	@DSPCD(T1)		;EXECUTE DISPATCH FUNCTION

DSPCD:	DSPCD0				;EXECUTE 'DO' FUNCTION
	DSPCD1				;EXECUTE 'XFR' FUNCTION
	DSPCD2				;EXECUTE 'TRANSL' FUNCTION
	DSPCD3				;NOT USED - TRY NEXT COMMAND

;DO FUNCTION	***** NOTE - "P" REGISTERS ARE FAIR GAME IN THIS CALL *****
; P1 CONTAINS THE COMMAND WORD...WE USE THIS IN HKSTRG FOR OFFSET

DSPCD0:	MOVE	T1,P2			;SOME ROUTINES ACCEPT ARGUMENTS IN "T1" (KLUDGE)
	SKIPE	T2			;NULL ROUTINE? (ie TEXT ONLY)
	PUSHJ	P,(T2)			;NO! - EXECUTE ROUTINE
	JRST	POSTXT			;DO ANY POST TEXT

;XFR FUNCTION

DSPCD1: MOVEM	T2,CTINDX		;SET UP TRANSFER ADDRESS
	JRST	NXCMD2			;CLEAN UP BUFFER

;TRANSL FUNCTION  ***** NOTE - "P" REGISTERS ARE FAIR GAME IN THIS CALL *****

DSPCD2:	MOVEM	T2,KONTYP		;SAVE TRANSLATION TEXT INDEX
	MOVE	P1,P2			;SETUP FOR TRANSLATOR
	PUSHJ	P,CNIDCD		;GO TRANSLATE
	JRST	POSTXT			;DO ANY POST TEXT

POSTXT:	MOVE	P1,(CTINDX)		;GET COMMAND BACK
	TLNN	P1,1B29			;POST TEXT?
	JRST	NXTCMD			;NO! - SKIP POST TEXT ROUTINE
	HLRZ	T1,1(CTINDX)		;YES! - GET TEXT POINTER
	SKIPE	T1			;IS THERE ANY TEXT?
	PUSHJ	P,.TSTRG		;YES! - SEND IT

DSPCD3:					;NOT USED
NXTCMD:	ADDI	CTINDX,2		;MOVE POINTER TO NEXT COMMAND
	TLNE	P1,BYT			;BYTE POINTER?
	 AOS	CTINDX			;YES! - BUMP IT ONCE MORE
	TLNE	P1,MSK			;MASK WORD?
	 AOS	CTINDX			;YES! - BUMP IT ONCE MORE
NXCMD2:	LDB	T1,[POINT 3,P1,14] 	;GET CARRIAGE CONTROL COMMAND
	PUSHJ	P,CRCCMD		;CHECK OUTPUT BUFFER
	JRST	NWCMD1			;START NEXT COMMAND

;END EDIT  [724]
	SUBTTL	ENTRY LEVEL SUBROUTINES

;DATECK -- SUBROUTINE TO COMPARE DATE OF THIS ENTRY AGAINST
;/BEFORE AND /SINCE IF SPECIFIED BY USER
;CALL	PUSHJ	P,DATECK
;
;RETURN	POPJ	P,	IF WITHIN RANGE
;	JRST	ABORT	IF OUT OF RANGE

DATECK:	MOVE	MASTWD,HDBUFF+HDRDAT	;PICKUP DATE/TIME WORD IN HEADER
	CAML	MASTWD,STDATE		;IS ENTRY DATE PRIOR TO DEFINED START DATE
	CAML	MASTWD,ENDATE		;IS ENTRY DATE PAST DEFINED END DATE
	JRST	SKIPIT			;YES TO EITHER SAYS DONT DO THIS ENTRY
	POPJ	P,

FILERR:	WARN	<DAEMON HAS FLAGGED ERROR IN SYSTEM ERROR FILE>
	JRST	STBUFF			;PROCESS NEXT ENTRY

TOOBIG:	WARN	<FILE ENTRY LARGER THAN WORKING BUFFER>
	JRST	STBUFF			;GO PROCESS NEXT ENTRY



;EOFVER MODIFIED BY EDIT 115 TO SUPPORT RE-SYNCING THE ERROR
;FILE.

EOFVER:	PUSHJ	P,GETWD			;TRY TO GET ANOTHER WORD AFTER EOF
	SKIPE	MASTWD			;=0?
	 JRST	EOFVE1			;NO-OLD FILE FORMAT
	PUSHJ	P,ADVBFF		;TRY TO GET NEXT BLOCK
	WARN	<EOF MARKER FOUND IN BODY OF SYSTEM ERROR FILE>
	JRST	HEADRD			;START ON NEXT ENTRY,SINCE THIS IS
					;1ST BLOCK OF ANOTHER FILE WE SHOULD
					;BE IN SYNC AND THE NEXT WORD HAD 
					;BETTER BE THE START OF AN ENTRY!!!

EOFVE1:	WARN	<EOF MARKER FOUND IN BODY OF SYSTEM ERROR FILE>
	JRST	EOFTRY

VOIDTY:	MOVEM	T1,BADTYP		;SAVE BAD ERROR TYPE
	SETZM	ERRIND			;LET NORMAL DISPATCH TAKE PLACE TO DUMP BUFFER AT DMPBUF
	POPJ	P,			;RETURN
;DVCHAR -- SUBROUTINE TO GET DEVICE CHARACTERISTICS AND
;	PUT CONTROLLER TYPE, DEVICE NAME INDEX INTO
;	STORAGE FOR LATER USE
;CALL	PUSHJ	P,DVCHAR
;
;RETURN	CALL+1

DVCHAR:	MOVE	P3,WKBUFF+HDENAM	;PICKUP DEVICE NAME
	HRLZI	T1,NAMLTH##		;SETUP TO CALL SCAN
	MOVNS	T1,T1			;-NAMLTH TO LH OF T1
	HRRI	T1,NAMTBL##-1		;FINISH SETUP
	PUSHJ	P,.NAME			;DO TABLE LOOKUP
	 JRST	BADNAM
	TLZ	T1,-1			;CLEAR LH OF T1
	SUBI	T1,NAMTBL		;CALC OFFSET IN NAME TABLE
	MOVEM	T1,DVINDX		;SAVE IT
	MOVE	T1,WKBUFF+HDEDCR	;PICKUP DEVCHR WORD
	SETZ	T2,			;ASSUME IT IS AN RC10
	TRNE	T1,1B25			;IS IT A RP10
	MOVEI	T2,1			;YES
	TRNE	T1,1B24			;IS IT A RH10?
	MOVEI	T2,4			;YES.
	MOVEM	T2,KONTYP		;SAVE THIS FACT
	SKIPN	T2			;RC10?
	 JRST	RCCHK
	CAIN	T2,1			;RP10?
	 JRST	RPCHK
	MOVEI	T2,4			;MUST BE RS04 ON RH10
	MOVEM	T2,MDEDTP
	POPJ	P,
RCCHK:	TRNE	T1,1B32			;RD10=0
	MOVEI	T2,1
	MOVEM	T2,MDEDTP
	POPJ	P,0
RPCHK:	MOVEI	T3,2
	TRNE	T1,1B31			;RP02?
	MOVEI	T3,3			;MUST BE RP03
	MOVEM	T3,MDEDTP
	POPJ	P,0

;TMCHAR -- COPY OF DVCHAR  FOR MAGTAPE

TMCHAR:	MOVE	P3,WKBUFF+MAGNAM
	TRNE	P3,7777			;EDIT 132 FUNNY NAME?
	 PUSHJ	P,FIXNAM		;YES GO FIXIT
	HRLZI	T1,NAMLTH		;SETUP TO CALL SCAN
	MOVNS	T1,T1			;-NAMLTH TO LH OF T1
	HRRI	T1,NAMTBL-1		;FINISH SETUP
	PUSHJ	P,.NAME
	JRST	BADNAM
	TLZ	T1,-1
	SUBI	T1,NAMTBL
	MOVEM	T1,DVINDX
	MOVEI	T1,3
	MOVEM	T1,KONTYP
	POPJ	P,0


;DXECHR - SAME AGAIN FOR DX20 ENTRY. NEEDED FOR RIB ERROR PROCESSING	[1340]

DXECHR:	LDB	T1,[POINT 9,WKBUFF+DXETYP,35]	;GET TYPE
	CAIN	T1,2			;RP20?
	 JRST	DXECH1			;YES-SKIP NEXT
	LDB	T1,[POINT 12,WKBUFF+DXENAM,11]	;GET 1ST 2 CHARS
	CAIN	T1,0754			;IS IT LABEL DDB ? ('L)
	 JRST	[MOVE	T1,5564		;YES-FIX IT (MT)
		 DPB	T1,[POINT 12,WKBUFF+DXENAM,11]	;DONE
		 JRST	.+1
]
	POPJ	P,0			;NO-GET OUT
DXECH1:	MOVE	P3,WKBUFF+DXENAM	;GET DEVICE NAME
	HRLZI	T1,NAMLTH##		;SETUP TO CALL SCAN
	MOVNS	T1,T1			;-NAMLTH TO LH OF T1
	HRRI	T1,NAMTBL-1		;FINISH SETUP
	PUSHJ	P,.NAME			;DO TABLE LOOKUP
	 JRST	BADNAM			;NO GOOD
	TLZ	T1,-1			;CLEAR LEFT HALF
	SUBI	T1,NAMTBL		;CALC OFFSET
	MOVEM	T1,DVINDX		;SAVE IT
	MOVEI	T1,5			;RH20 CONTROLLER
	MOVEM	T1,KONTYP		;SAVE FOR LATER
	POPJ	P,0
;MDECHR - SAME AGAIN FOR MASSBUS DEVICES

MDECHR:	MOVE	P3,WKBUFF+MDENAM
	HRLZI	T1,NAMLTH		;SETUP TO CALL SCAN
	MOVNS	T1,T1			;-NAMLTH TO LH OF T1
	HRRI	T1,NAMTBL-1		;FINISH SETUP
	PUSHJ	P,.NAME			;LET SCAN DO WORK
	 JRST	BADNAM
	TLZ	T1,-1
	SUBI	T1,NAMTBL
	MOVEM	T1,DVINDX
	MOVE	P3,WKBUFF+MDENAM
	HRLZI	T1,MASLTH##
	MOVNS	T1,T1			;-MASLTH TO LH OF T1
	HRRI	T1,MASNAM##-1
	PUSHJ	P,.NAME
	 JRST BADNAM
	TLZ	T1,-1
	SUBI	T1,MASNAM
	MOVEM	T1,MASIND
;START EDIT [1133]
	LDB	T2,[POINT 3,WKBUFF+MDETYP,14]	;GET BYTE VALUE OF CONTROLLER TYPE
	MOVEI	T3,4			;ASSUME RH10
	CAIN	T2,2			;RH20?
	MOVEI	T3,5			;YES
	CAIN	T2,3			;RH11?
	MOVEI	T3,6			;YES
;END[1133]
	MOVEM	T3,KONTYP		;SAVE EITHER
	MOVEM	T3,MASKON		;TWICE
	SETZB	T1,MDEDTP		;CLEAR DRIVE TYPE  [1007]
	MOVE	T2,WKBUFF+MDEDDT
	ANDI	T2,77			;TYPE ALONE
	CAIN	T2,2			;RS04?
	 MOVEI	T1,0
	CAIN	T2,20			;RP04
	 MOVEI	T1,2
	CAIN	T2,21			;RP05
	 MOVEI	T1,3
	CAIN	T2,22			;RP06
	MOVEI	T1,4
	CAIN	T2,24			;RM03??
	 MOVEI	T1,5
	CAIN	T2,42			;[1316][1107]RP07?
	 MOVEI	T1,6			;[1107]
	SKIPN	T1			;IS IT 0?
	 PUSHJ	P,MDEXX1		;YES MAKE SURE WE KNOW WHAT IT IS
	CAIL	T1,0			;RANGE CHECK  [1007]
	CAILE	T1,6			;[1107]
	 JRST	MBCHA3			;OUT OF RANGE - ABORT
	MOVEM	T1,MDEDTP
	POPJ	P,0

MDEXX1:	LDB	T3,[POINT 12,WKBUFF+MDENAM,11]	;[1007]
	CAIN	T3,4663			;FSX??
	 POPJ	P,0			;YES RETURN NOW
	MOVEI	T1,77			;NO PUT BAD VAL IN T1 SO RANGE CHECK WIIL FAIL
	POPJ	P,0			;THEN RETURN


					;EDIT 132
FIXNAM:	SETZ	P4,0			;SOME STORAGE
	LSHC	P3,-^D6			;REAL # TO P4
	LSH	P3,-^D12		;UNWANTED
	ROTC	P3,^D18			;CORRECTED
	POPJ	P,0			;NOW GO BACK
;MBCHAR - SETS UP STORAGE OF UNIT TYPE,CONTROLLER TYPE, BUILDS
;A UNIT NAME,  AND SETS UP INDEX TO TABLES

;**********
; START OF HACK FOR DX20/TU70  [512]
;**********

MBCHAR:	LDB	T1,[MB.DEV+WKBUFF]	;[513]
	CAIL	T1,.UTDX2		;[706]
	CAILE	T1,.UTP20		;[1333]
	 PJRST	MBCHR1			;THIS IS A REAL 111 - LEAVE!
	MOVE	T1,ERTYPE		;GETBAD ERTYPE
	HRRZ	T2,ENTCHR(T1)		;GET CURRENT COUNT
	SKIPE	T2			;IF NOT ZERO
	SOS	ENTCHR(T1)		;DECREMENT TYPE COUNTER
	AOS	T1			;BUMP 
	AOS	ENTCHR(T1)		;[716-RLD]BUMP CORRECT COUNT
	MOVEM	T1,ERTYPE
	MOVE 	T1,[1B8]
	ADDM	T1,HDBUFF		;FIX ENTRY WORD 0
	MOVE	T1,ERTYPE
	PUSHJ	P,ERRINT		;GO FIX UP NAME, ETC.
	PUSHJ	P,DXCHAR
	POPJ	P,0
;END OF HACK  [512]

MBCHR1:	LDB	T2,[MB.CHN+WKBUFF]	;GET CONTROLLER TYPE  [513]
	CAIE	T2,.SA10		;#1 SA10?
	 JRST	MBCHR2			;#1 no, continue
	MOVE	T1,ERTYPE		;#1 get bad ERTYPE
	HRRZ	T2,ENTCHR(T1)		;#1 get current count
	SKIPE	T2			;#1 if not zero
	SOS	ENTCHR(T1)		;#1 decrement type counter
	LDB	T2,[MB.DEV+WKBUFF]	;#2 Get device type
	MOVEI	T1,SEC%SD		;#3 assume disk;#2 Assume tape
	CAIE    T2,25			;#3 interim device #?
	CAIN	T2,.UTCT1		;#3 ;#2 Check device type to make sure
	MOVEI	T1,SEC%SM		;#3 tape;#1 should be other type
	AOS	ENTCHR(T1)		;#1 bump correct count
	MOVEM	T1,ERTYPE		;#1 fix error type
	DPB	T1,[POINT 9,HDBUFF,8]	;#1 fix in buffer too
	PUSHJ	P,ERRINT		;#1 init
	MOVE	T1,ERTYPE		;#2 Get back error type
	CAIN	T1,SEC%SM		;#2 Jump to correct routine
	JRST	STCHAR			;#2 For tapes
	JRST	SDCHAR			;#1 go to correct routine
MBCHR2:					;#1
	SETZ	T3,			;CLEAR TYPE FLAG  [600]
	CAIN	T2,.RH10		;IS IT AN RH10?
	 MOVEI	T3,..RH10		;YES! - SET FLAG FOR RH10
	CAIN	T2,.RH20		;IS IT AN RH20?
	 MOVEI	T3,..RH20		;YES! - SET FLAG FOR RH20
	CAIN	T2,.RH11		;IS IT AN RH11?  [600]
	 MOVEI	T3,..RH11		;YES! - SET FLAG FOR RH11
	SKIPN	T3			;VALID CONTROLLER?
	 JRST	MBCHA2			;NOPE!!
	MOVEM	T3,MASKON		;YES! - SAVE IT
;START EDIT  [1231]
	LDB	T2,[MB.DEV+WKBUFF]	;GET UNIT TYPE THE MONITOR GAVE US
	HRRZ	T1,WKBUFF+MB%REG+6	;GET DEVICE TYPE IN MASBUSS REGISTER
	ANDI	T1,777			; DON'T TRUST MONITOR TO DECIDE!!
	CAIN	T1,TY.RS4		;RS04?
	MOVEI	T2,.UTRS4		;SAY SO
	CAIN	T1,TY.RP4		;RP04?
	MOVEI	T2,.UTRP4		;SAY SO
	CAIN	T1,TY.RP5		;RP05?
	MOVEI	T2,.UTRP5
	CAIN	T1,TY.RP6		;RP06?
	MOVEI	T2,.UTRP6
	CAIN	T1,TY.RP7		;[1316]RP07?
	MOVEI	T2,.UTRP7
	CAIN	T1,TY.RM3		;RM03?
	MOVEI	T2,.UTRM3
	CAIN	T1,TY.T16		;TM02 AT 45IPS  (TU16)?
	MOVEI	T2,.UTTM2
	CAIE	T1,TY.T45		;TM02 AT 75IPS  (TU45)?
	CAIN	T1,TY.U45		;TM03 AT 75IPS  (TU45)?
	MOVEI	T2,.UTT45
	CAIN	T1,TY.T77		;TM03 AT 125IPS (TU77)?
	MOVEI	T2,.UTT77
	CAIL	T2,.UTMIN		;VALID UNIT TYPE?
	CAILE	T2,.UTMAX		;MAYBE! - WITHIN HIGH LIMIT?
	JRST	MBCHA3			;NO! - REPORT ERROR
	MOVEM	T2,MDEDTP		;VALID! - SAVE IT
;END EDIT  [1231]
;CONSTRUCT THE DEVICE NAME OURSELVES, SINCE THE MONITOR DOESN'T GIVE IT TO US!
	HRLZI	T1,'DPX'		;ASSUME A DSK TYPE DEVICE
	CAIN	T2,2			;RS04?
	 HRLZI	T1,'FSX'
	CAIN	T2,3			;TU45?
	 HRLZI	T1,'MTX'
	CAIN	T2,4			;TU16?
	 HRLZI	T1,'MTX'
	CAIE	T2,.UTT78		;#13 TU78?
	CAIN	T2,13			;TU77?
	 HRLZI	T1,'MTX'
	MOVE	T2,WKBUFF+MB%CAD	;GETCHANNEL #
	ADDI	T2,20			;CONVERT TO SIXBIT
	DPB	T2,[POINT 6,T1,17]	;STORE IT
	MOVE	T2,WKBUFF+MB%UAD	;GET UNIT ADDR
	ADDI	T2,20			;CONVERT TO SIXBIT
	DPB	T2,[POINT 6,T1,23]	;FINISH THE UNIT NAME
;EDITS [221] - [611]
	SETZ	T2,			;CLEAR AC
	MOVE	T3,MDEDTP		;GET DEVICE TYPE
	CAIN	T3,.UTT45		;TAPE? - TU45?
	 HRRZ	T2,WKBUFF+MB%REG+11	;GET SLAVE #
	CAIN	T3,.UTTM2		;TM02/TU16?
	 HRRZ	T2,WKBUFF+MB%REG+11	;GET SLAVE #
	CAIN	T3,.UTT77		;TU77?
	 HRRZ	T2,WKBUFF+MB%REG+11	;GET SLAVE #
	ANDI	T2,7			;STRIP IT
	ADDI	T2,20			;TO SIXBIT
	DPB	T2,[POINT 6,T1,29]
;END EDITS [221] - [611]
	MOVEM	T1,WKBUFF+MB%NAM	;STORE BUILT NAME IN WKBUFF
;OLD SUMMING ROUTINES AT 'DXFATE' REMOVED WITH EDIT  [1217]
	POPJ	P,0

MBCHA2:	WARN	<CODE 111-ILLEGAL CONTROLLER TYPE, ABORTING ENTRY!>
	JRST	ABORT			;THAT'S ALL FOR THIS ENTRY
MBCHA3:	WARN	<ILLEGAL MASSBUS UNIT TYPE, ABORTING ENTRY!>  ;[1007]
	JRST	ABORT
;STCHAR - sets up storage of unit type, controller type, builds
;a unit name, and sets up index to tables for SA10 error type 122

STCHAR:	MOVEI	T1,.UTCT1		;#2 Get our device type code
	MOVEM	T1,MDEDTP		;#2 Save device type
	MOVEI	T3,..SA10		;#2 Get index for SA10
	MOVEM	T3,MASKON		;#2  and save it
	MOVSI	T1,('MT    ')		;#2 Beginning of device name
	MOVE	T2,WKBUFF+SM%DVA	;#2 Get device address
	ANDI	T2,377			;#2 Leave only valid bits
	ROT	T2,-6			;#2 Get first digit
	TRO	T2,20			;#2 Convert to sixbit
	DPB	T2,[POINT 6,T1,17]	;#2 Store in device name
	TRZ	T2,77			;#2 Clear last character
	ROT	T2,3			;#2 Get second digit
	TRO	T2,20			;#2 Convert to sixbit
	DPB	T2,[POINT 6,T1,23]	;#2 Store in name
	TRZ	T2,77			;#2 Clear last character
	ROT	T2,3			;#2 Get third and last digit
	TRO	T2,20			;#2 Convert to sixbit
	DPB	T2,[POINT 6,T1,29]	;#2 Store in name
	MOVEM	T1,WKBUFF+MB%NAM	;#2 Save completed name
	POPJ	P,0			;#2 Back to caller
;SDCHAR - sets up storage of unit type, controller type, builds
;a unit name, and sets up index to tables for SA10 error type 121

SDCHAR:					;#1 SA10 disk error
	LDB T2,[MB.CHN+WKBUFF]		;#1 get controller type
	CAIE T2,.SA10			;#1 right?
	 JRST SDCHA2			;#1 no, abort
	MOVEI T3,..SA10			;#1 get index
	MOVEM T3,MASKON			;#1 save index
	LDB T2,[MB.DEV+WKBUFF]		;#1 get unit type
	CAIE T2,23			;#3 interim # for 3330-I?
	CAIN T2,24			;#3 interim # for 3330-II?
	JRST SDCHA1			;#3 one of them is ok
	CAIE T2,.UTCC1			;#1 3330 mod I?
	CAIN T2,.UTCC2			;#1 3330 mod II?
	JRST SDCHA1			;#3 ;#1 one of them is ok 
	JRST SDCHA3			;#1 anything else is unknown
SDCHA1:	MOVEM T2,MDEDTP			;#3 ;#1 save type 
;#1 construct the device name
	MOVE T1,['DPXX0 ']		;#1 disk device like RP0x
	MOVE T2,WKBUFF+MB%CAD		;#1 get channel number
	ADDI T2,20			;#1 convert to SIXBIT
	DPB T2,[POINT 6,T1,17]		;#1 store it
	MOVE T2,WKBUFF+MB%UAD		;#1 get unit address
	ADDI T2,20			;#1 convert to SIXBIT
	DPB T2,[POINT 6,T1,23]		;#1 finish the unit name
	MOVEM T1,WKBUFF+MB%NAM		;#1 store built name in WKBUFF
	POPJ P,0			;#1 return

SDCHA2:	WARN	<Illegal SA10 disk controller type, aborting entry!> ;#1 .
	JRST ABORT			;#1 that's all for this entry

SDCHA3:	WARN	<Illegal SA10 Disk unit type, aborting entry!> ;#1 .
	JRST	ABORT			;#1 .

SD%100::				;#1 print module ID ("S/N" routine)
	LDB T1,[POINT 3,P2,35-3]	;#1 get first 3 bits of module ID
	LDB T2,[POINT 3,P2,35]		;#1 get last 3 bits of module ID
	XORI T1,7			;#1 complement the compliment bits
	CAIE T1,(T2)			;#1 should match
	 JRST [	TYPEIT <UNKNOWN>	;#1 strange
		POPJ P,0]		;#1 quit
;#5 	LDB T1,[POINT 2,P2,35-6]	;#1 get controller bits
;#5 	IMULI T1,^D100			;#1 multiply controller by 100
;#5 	ADDI T1,(T2)			;#1 put them together
;#5 	PUSHJ P,.ODECW			;#1 output in decimal, with "."
;#5 	TRNN F,F.BRF			;#1 brief?
;#5 	 PUSHJ P,.TSPAC			;#1 no, space before module
;#5 	TYPEIT <(>			;#1 prepare for alpha
	LDB T1,[POINT 3,P2,35]		;#1 get module ID index
	MOVEI T1,"A"(T1)		;#1 make alphabetic
	PUSHJ P,.TCHAR			;#1 output it
;#5 	TYPEIT <)>			;#1 enclosing paren
	POPJ P,0			;#1 done
;DXCHAR - SETS UP UNIT TYPE, CONTROLLER TYPE
;[510]	BUILDS UNIT NAME, SETS UP INDEX INTO TABLES

DXCHAR:	MOVE	T1,WKBUFF+DX%TYP	;GET TYPES
	LDB	T2,[POINT 4,T1,17]	;CONTROLLER TYPE	[513]
	CAIE	T2,2			;RH20?
	 JRST	DXCHR1			;NO! - GIVE UP - ABORT
	MOVEI	T3,5			;YES!
	MOVEM	T3,MASKON		;SET TYPE
	LDB	T2,[POINT 5,T1,35]	;GET UNIT TYPE		[513]
	CAIGE	T2,.UTDX2		;ST[704]
	 JRST	DXCHR2
	CAILE	T2,.UTP20
	 JRST	DXCHR2
	CAIN	T2,.UTDX2		;IF DX20, CHECK SENSE BYTES
	 PUSHJ	P,DXTYPE
;END [704]

DXCHA1:	MOVEM	T2,MDEDTP		;SAVE UNIT TYPE
	HRLZI	T1,'MT '		;ASSUME TU7X
	MOVE	T3,T2			;GET IT RIGHT PLACE	[1333]
	CAIN	T3,.UTP20		;IS IT AN RP20 ?	[1333]
	 HRLZI	T1,'DP '		;YES, CHANGE NAME	[1333]
	MOVE	T2,WKBUFF+DX%CAD	;GET CHANNEL #
	ADDI	T2,20			;CONVERT TO SIXBIT
	DPB	T2,[POINT 6,T1,17]	;ADD TO UNIT NAME
	CAIE	T3,.UTP20		;RP20 ?			[1333]
	 JRST	DXCHA2			;NO- DO REGULAR WAY	[1333]
	HLRZ	T2,WKBUFF+DX%UAD	;YES- GET DX20 #	[1333]
	ADDI	T2,20			;MAKE IT SIXBIT		[1333]
	DPB	T2,[POINT 6,T1,23]	;ADD TO UNIT NAME	[1333]
	HRRZ	T2,WKBUFF+DX%MBR	;GET OFFSET		[1333]
	SKIPN	T2			; VALID ?		[1333]
	 JRST	DXCHR3			;NO- NO GOOD		[1333]
	MOVE	T2,WKBUFF+DM%TE(T2)	;GET DRIVE #		[1333]
	JRST	DXCHA3			;FINISH UP		[1333]
DXCHA2:	MOVE	T2,WKBUFF+DX%UAD	;GET UNIT ADDRESS	[1333]
	ADDI	T2,20			;CONVERT TO SIXBIT
	DPB	T2,[POINT 6,T1,23]	;ADD TO UNIT NAME
	HRRZ	T2,WKBUFF+DX%MBR	;GET OFFSET FO MASBUSS REGISTERS
	SKIPN	T2			;IF 0,NOT VALID PNTR
	 JRST	DXCHR3			;BETTER QUIT
	MOVE	T2,WKBUFF+DM%DN(T2)	;GET DRIVE INFORMATION
DXCHA3:	ANDI	T2,7			;MASK DRIVE #		[1333]
	ADDI	T2,20			;MAKE IT SIXBIT
	DPB	T2,[POINT 6,T1,29]	;FINISH UNIT NAME
	MOVEM	T1,WKBUFF+DX%NAM	;SAVE IT
	POPJ	P,0			;EXIT  [1217]

;DXCHAR ERROR EXITS

DXCHR1:	WARN	<DX20 ENTRY - NOT CONTROLLER TYPE 2 (RH20), ABORTING ENTRY!>
	JRST	ABORT			;GET NEXT ENTRY

DXCHR2:	WARN	<DX20 ENTRY - ILLEGAL UNIT TYPE, ABORTING ENTRY!>
	JRST	ABORT			;GET NEXT ENTRY
DXCHR3:	AOS	DXFNUM
	JRST	ABORT

;ADDED W [704]
;BEGIN [1333]
DXTYPE:	HRRZ	T1,WKBUFF+DX%MBR	;PNTR TO MASSBUS REGS
	ADDI	T1,DM%DT		;OFFSET TO DRIVE TYPE REG
	HRRZ	T1,WKBUFF(T1)		;GET DATA
	ANDI	T1,777			;GET RID OF BAD STUFF
	CAIN	T1,TY.P20		;IS IT RP20 ?
	 JRST	[MOVEI	T2,.UTP20	;YES
		 JRST 	DXTYP1]		;GO TO END
; END [1333]
	HRRZ	T1,WKBUFF+DX%DVL	;PNTR TO DEV INFO
	ADDI	T1,DT%SBB		;OFFSET TO SENSE BYTES 4-7
	SKIPN	T3,WKBUFF(T1)		;GET THE VALUE IF PRESENT
	 POPJ	P,0			;EMPTY, RETURN
	LDB	T1,[POINT ^D8,T3,27]	;GET SENSE BYTE 6
	TRNE	T1,1B31			;2x=TU72-E
	 JRST	[MOVEI	T2,.UTT72
		 JRST	DXTYP1]
	MOVEI	T2,.UTT70		;ASSUME TU70
	TRNE	T1,1B28			;ON=TU71
	 MOVEI	T2,.UTT71		;SO SAY SO
DXTYP1:	POPJ	P,0			;TYPE HAS BEEN FOUND IN SENSE BYTES

;END [704]
;CNISUM -- SUBROUTINE TO PERFORM CONI BIT SUMMATION
;SETUP	P2 = RETRY WORD FOR TOPS-20,OFFSET TO RETRY WORD FOR TOPS-10
;	P3 = OFFSET OF CONI WORD TO SUMMATE.
;CALL	PUSHJ	P,CNISUM
;
;RETURN	CALL+1
;NOTE THAT DVINDX AND KONTYP MUST BE SETUP FOR CORRECT DEVICE

CNISUM:	MOVE	T1,DVINDX		;PICKUP INDEX AS SPECIFIED BY DEVICE
	HLRZ	P1,DEVDSP##(T1)		;PICKUP POINTER TO COUNTER BLOCKS
	MOVE	T3,P2			;PICKUP RETRY WORD
	SKIPN	TOPENT			;P2 HOLDS OFFSET IF TOPS-10 RECORDED
	MOVE	T3,WKBUFF(P2)		;P2 HOLDS OFFSET NOT VALUE
	TLNN	T3,ERRHRD		;HARD ERROR
	HRRZ	P1,DEVDSP(T1)		;NO-PICKUP SOFTPOINTER
	MOVE	T3,WKBUFF(P3)		;PICKUP 1CONI WORD
	MOVE	T1,KONTYP		;PICKUP CONTROLLER TYPE
	AND	T3,KONMSK##(T1)		;PICKUP CONTROLLER MASK FOR ERROR BITS
	LSH	T3,@MINERB##(T1)	;SHIFT WORD TO CORRESPOND TO FIRST POSSIBLE
					;ERROR BIT IN WORD
DOJFFO:	JFFO	T3,INCREM		;LOOK FOR ERROR BIT
	JRST	JFDONE			;HERE WHEN ALL BITS DONE

INCREM:	MOVE	T1,KONTYP		;PICKUP CONTROLLER TYPE
	MOVE	T1,ERINDX##(T1)		;PICKUP ADDRESS OF ERR BIT TO INDEX BIT CONVERTER
	ADD	T1,T4			;INDEX INTO TABLE BY ERR BIT
	MOVE	T2,(T1)			;GET THE CORRELATED INDEX VALUE
	ADD	T2,P1			;ADD IN DEVICE OFFSET PASSED TO HERE
	AOS	(T2)			;INCREM COUNTER
	ROT	T3,(T4)			;MOVE BIT TO SIGN LOCATION
	TLZ	T3,400000		;CLEAR IT
	MOVNS	T4			;COMP SHIFT COUNT
	ROT	T3,(T4)			;RESTORE WORD TO ORIGINAL POSITION
	JRST	DOJFFO			;LOOP TILL ALL BITS DONE
JFDONE:	POPJ	P,			;JUST DO NORMAL RETURN

;REMOVED ROUTINE 'CNISU2' WITH EDIT  [1217]

BADNAM:	MOVE	T2,P3			;GET THE BAD NAME
	PUSHJ	P,TTYSIX		;LIST IT IN SIXBIT
	WARN	<UNKNOWN DEVICE NAME FOUND IN ENTRY-ABORTING ENTRY>
	JRST	ABORT
;MASSVM -- SIMILAR TO CNISUM BUT FOR MASSBUS DEVICES
;P1 = WORD TO SUMMATE
;P2 = LH  ADDR OF HARD ERROR COUNTER TABLE FOR THIS REG
; 	ON THIS DEVICE
;	RH  ADDR OF SOFT ERROR COUNTER
;P3=  RETRY WORD( HARD OR SOFT ERROR BIT = 1B1)
;KONTYP MUST BE SET TO POINT AT THIS REGISTER
; CALL:  PUSHJ	P,MASSVM

MASSVM:	HLRZ	P4,P2			;POINT AT HARD ERROR
	TLNN	P3,ERRHRD		;BUT IF SOFT
	HRRZ	P4,P2			;CHANGE IT
MASVM2:	MOVE	T2,KONTYP		;GET INDEX FOR THIS REG
	MOVE	T1,P1			;GET WORD
	AND	T1,KONMSK(T2)		;ERROR BITS ONLY PLEASE
	LSH	T1,@MINERB(T2)		;MOVED OVER

MASJFF:	JFFO	T1,MASINC		;DI IT
	 POPJ	P,0			;ALL DONE, GO BACK

MASINC:	MOVE	T4,KONTYP
	MOVE	T4,ERINDX(T4)
	ADD	T4,T2
	MOVE	T3,(T4)
	ADD	T3,P4			;T3 NOW = ADDRESS + OFFSET
	AOS	(T3)			;ADD ONE TO COUNTER
	ROT	T1,(T2)		
	TLZ	T1,400000		;CLEAR THE BIT
	MOVNS	T2			;CHANGE SHIFT DIRECTION
	ROT	T1,(T2)			;MOVE IT BACK
	JRST	MASJFF			;DO NEXT
;DYNSUM - SUMS ERROR BITS FOR DYNAMIC TABLE SUMMARIES  [1217]
;T1 = WORD TO SUMMATE
;P1 = KONTYP OR OFFSET
;P2 = ERROR COUNTER BASE ADDRESS
;P3 = HARD/SOFT ERROR FLAG  (HARD=1,,0  SOFT=0,,1)
; CALL:  PUSHJ	P,DYNSUM

DYNSUM:	AND	T1,KONMSK(P1)		;MASK FOR ERROR BITS ONLY
	LSH	T1,@MINERB(P1)		;SHIFT TO FIRST ERROR BIT
	SETZ	T3,			;CLEAR COUNTER
	MOVE	T4,ERINDX(P1)		;POINTER TO BIT SIGNIFICANCE TABLE
	JRST	DYNJFF			;START COUNTING

DYNCNT:	LSH	T1,(T2)			;SHIFT TO FIRST ONE BIT
	TLZ	T1,1B18			; AND CLEAR IT
	ADDB	T2,T3			;TOTAL OFFSET
	ADD	T2,T4			;GET BIT'S SIGNIFICANCE
	MOVE	T2,(T2)
	ADD	T2,P2			;T2 NOW POINTS TO CORRECT COUNTER
	ADDM	P3,(T2)			;ADD ONE TO COUNTER
DYNJFF:	JFFO	T1,DYNCNT		;FIND ONE BIT
	POPJ	P,0			;ALL DONE, GO BACK
;DEVCHK -- ROUTINE TO CHECK DEVICE NAME IN ENTRY
;AGAINST WHAT USER SAID. CAN CHECK FOR "DPA" OR JUST "DP"
;INSTEAD OF "DPA3"
;SETUP  P3=OFFSET OF DEVICE NAME IN WKBUFF
;CALL   PUSHJ P,DEVCHK
;RETURNS POPJ IF NAMES CHECK
;JRST ABORT OTHERWISE. CHANGED WITH EDIT [304]  [745]

DEVCHK:	MOVE	T1,WKBUFF(P3)		;PICKUP ENTRY DEVICE NAME
	CAMN	T1,DEV			;SAME AS ONE USER SPECIFIED?
	POPJ	P,			;YES, LIST IT
	MOVE	T3,DEV			;SETUP
	PUSHJ	P,.MKMSK		;BUILD A MASK
	MOVE	T2,WKBUFF(P3)
	AND	T2,T1			;GET CORRES BITS
	CAME	T2,DEV			;NOW A MATCH?
	 JRST	ABORT			;SORRY...
	POPJ	P,0



;NDVCHK--ADDED WITH EDIT 325  PERFORMS OPPOSITE FUNCTION
;	OF DEVCHK ROUTINE TO SUPPORT "/NDEV:" SWITCH
;	EXPANDED TO TEST FOR GENERIC DEVICES  [745]

NDVCHK::MOVE	T1,WKBUFF(P3)		;PICKUP ENTRY DEVICE NAME
	CAMN	T1,NDEV			;SAME AS ONE USER SPECIFIED?
	JRST	ABORT			;YES! - DON'T LIST IT
	MOVE	T3,NDEV			;SETUP
	PUSHJ	P,.MKMSK		;BUILD A MASK OF NON-BLANK CHARACTERS
	MOVE	T2,WKBUFF(P3)
	AND	T2,T1			;MASK ENTRY'S DEVICE WORD
	CAMN	T2,NDEV			;NOW A MATCH?
	 JRST	ABORT			;YES! - DON'T LIST IT
	POPJ	P,0			;NO! - RETURN TO OUR CALLER TO CHECK FURTHER
;ROUTINE TO FIND INDEX INTO TABLES OF ENTRY INFO
;BASED ON ERROR CODE	.
;CALL	T1=ERROR CODE
;	PUSHJ	P,ERRINT
;RETURN +1 IF INDEX FOUND AND ST]ORED IN ERRIND
;ELSE JRST SKIPIT AFTER WARNING USER

ERRINT:	JUMPE	T1,ERRIN0		;DUMP IT IF ERROR CODE '0'  [755]
	MOVEI	T2,ALLLTH##		;GET LENGTH OF TABLE
	SETZB	T3,T4			;WORK SPACE
ERRIN1:	HRRZ	T3,ALLTBL##(T4)		;GET NEXT INDEX VALUE - CHANGED  [724]
	CAMN	T1,T3			;MATCH?
	JRST	ERRIN2			;YES
	AOS	T4			;UPDATE 
	CAIE	T4,ALLLTH+1		;END OF TABLE?
	JRST	ERRIN1			;NOT YET
ERRIN0:	WARN	<EXPECTED ERROR CODE NOT FOUND IN TABLE OF SUBJECT ERROR CODES>
	MOVEM	T1,ERRIND
	JRST	DMPENT			;EDIT 141
ERRIN2:	MOVEM	T4,ALLIND		;STORE GOOD INDEX VALUE

;NOW CHECK TO SEE IF THIS SEGMENT PROCESSES IT
	MOVEI	T2,ERRLTH##		;GET LENGTH OF TABLE
	SETZB	T3,T4			;WORK SPACE
ERRIN3:	HRRZ	T3,ERRTBL(T4)		;GET NEXT INDEX VALUE - CHANGED  [724]
	CAMN	T1,T3			;MATCH?
	JRST	ERRIN4			;YES
	AOS	T4			;UPDATE 
	CAIE	T4,ERRLTH+1		;END OF TABLE?
	JRST	ERRIN3			;NO YET

;IF NOT FOUND ON 2ND SEARCH THIS SEGMENT DOESN'T PROCESS
;THE ENTRY,BUT WILL GET CORRECT SEGMENT
;VIA "PROCS-" ROUTINE.  PART OF EDIT #120.

	SETZ	T4,			;SO CLEAR IT
ERRIN4:	MOVEM	T4,ERRIND		;STORE INDEX VALUE
	POPJ	P,0			;GO BACK

;SKIPIT -- SUBROUTINE TO SKIP CURRENT ENTRY IF INVALID
;CALL	JRST	SKIPIT
;
;RETURN	JRST	ABORT

SKIPIT:	NOTNOW				;[751] DONT DO THIS IF /NOW
	 JRST ABORT
	MOVE	T1,ENTRWC		;PICKUP TOTAL # WORDS IN HEADER
	PUSHJ	P,SKIPWD		;GO MANUALLY ADVANCE INPUT BUFF POINTER
	JRST	ABORT			;RESET AND GET NEXT ENTRY
;IDCHK -- SUBROUTINE TO CHECK IF VALUE OF ID
;IN WKBUFF MATCHES ID USER TYPED.
;SETUP  P3=OFFSET OF IDWORD IN WKBUFF
;CALL   PUSHJ  P,IDCHK
;RETURN POPJ   P,0    IF VALUES MATCH
;       JRST ABORT      IF NOT.
;[1101]-SUPPORT GENERIC AND ABBREVIATED NAMES ALA DEVCHK

IDCHK:	MOVE	T1,WKBUFF(P3)		;PICKUP ENTRY DEVICE NAME
	CAMN	T1,ID			;SAME AS ONE USER SPECIFIED?
	POPJ	P,			;YES, LIST IT
	MOVE	T3,ID			;SETUP
	PUSHJ	P,.MKMSK		;BUILD A MASK
	MOVE	T2,WKBUFF(P3)
	AND	T2,T1			;GET CORRES BITS
	CAME	T2,ID			;NOW A MATCH?
	 JRST	ABORT			;SORRY...
	POPJ	P,0

;STRCHK - ROUTINE TOCHECK STR NAME IN ENTRY IF /STR SWITCH
;IS USED VERY SIMILIAR TO IDCHK

STRCHK:	MOVE	T1,WKBUFF(P3)		;GET ENTRY STR
	CAMN	T1,STR			;MATCH?
	 POPJ	P,			;YES
	MOVE	T3,STR			;[526]
	PUSHJ	P,.MKMSK
	MOVE	T2,WKBUFF(P3)
	AND	T2,T1
	CAME	T2,STR
	 JRST 	ABORT
	POPJ	P,0



;DETCHK-ROUTINE TO TEST IF USER SAID /DETAIL
;MODIFIED WITH [537] TO SUPPORT LEVEL OF DETAIL
;CALL W. P1= LEVEL TO CHECK AS MINIMUM
;CALL PUSHJ
;RETURN IF HE SAID /DETAIL ELSE JRST ABORT

DETCHK:	TLNE	F,F.DET			;SAID /DETAIL?
	 JRST	DETCH0			;OK,CHECK FURTHER
	TYPEIT	<
=====REST OF INFORMATION AVAILABLE BY USING /DETAIL SWITCH=====
>
	JRST	ABORT			;NOW START NEXT ENTRY
DETCH0:	CAMG	P1,DETAIL		;VALUE .GT. ARGUEMENT
	 POPJ	P,0			;OK-RETURN

;TEST FAILED, GIVE MESSAGE THEN ABORT ENTRY

	TYPEIT	<
*** MORE INFORMATION AVAILABLE BY USING HIGHER LEVEL OF /DETAIL:
     SWITCH SET AT >

	MOVE	T1,P1			;TYPE OUT PRESENT DETAIL LEVEL  [602]
	PUSHJ	P,.ODECW
	JRST	ABORT
;	START EDIT  [614]
;SBUSFN - ROUTINE TO PROCESS S-BUS FUNCTION SUB-TABLE IN
;	   PARITY INTERRUPT ENTRY (62 & 162)
;
;	POINTER TO SUBTABLE IS IN P2

SBUSFN:	SKIPN	P2			;[1236]IS PTR TO SUBTABLE = 0?
	POPJ	P,0			;[1236]YES RETURN NOW
	SETZ	P1,
	PUSHJ	P,DETCHK		;CHECK DETAIL SWITCH
	TYPEIT	<
SYSTEM MEMORY CONFIGURATION:
>
	MOVE	P1,P2
	ADDI	P1,WKBUFF+1		;POINT AT FUNCTION 0 FOR CONTROLLER
;[733] FIXED TO CORRECTLY SUPPORT MF20

SBUS01:	HRRZ	P3,-1(P1)		;GET CONTROLLER NUMBER
	MOVE	P2,1(P1)		;GET FUNCTION 1
	TYPEIT	<
CONTROLLER:  #>
	MOVE	T1,P3			;CONTROLLER #
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	LDB	T2,[POINT 4,P2,11]	;GET TYPE
	PUSH	P,T2			;SAVE IT
	MOVE	T1,SBSTYP(T2)
	PUSHJ	P,.TSIXN
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	POP	P,T3			;GET MEMORY TYPE BACK
	CAIN	T3,2			;DMA?
	JRST	SBDMA
	CAIN	T3,5			;MF20?
	 JRST	SBUSMF			;YES-A FEW DIFFERENCES, GO DO IT
	LDB	T2,[POINT 4,P2,7]	;# OF MODULES
	SETZ	T1,
	TRNE	T2,1B35			;SM0 PRESENT?
	 ADDI	T1,1
	TRNE	T2,1B34			;SM1?
	 ADDI	T1,1
	TRNE	T2,1B33			;SM2?
	 ADDI	T1,1
	TRNE	T2,1B32			;SM3?
	 ADDI	T1,1
	MUL	T1,SBSSIZ(T3)		;TIMES UNIT SIZE
	MOVE	T1,T2			;ANSWER TO T1
	PUSHJ	P,.TDECW
	TYPEIT	< K>
	TYPEIT	<
F0:	>
	MOVE	T1,0(P1)		;GET FUNCTION 0
	PUSHJ	P,.TXWDW
	TYPEIT	<	F1:	>
	MOVE	T1,1(P1)		;GET FUNCTOON 1
	PUSHJ	P,.TXWDW
	TYPEIT	<
	INTERLEAVE MODE:	>
	MOVE	T2,0(P1)		;GET FUNCTION 0
	LDB	T3,[POINT 2,T2,7]
	MOVE	T1,SBSINT(T3)		;POINTER TO ASCIZ OF INT. MODE
	PUSHJ	P,.TSTRG
	TYPEIT	<
	REQ ENABLED:	>
	MOVE	P2,1(P1)		;GET FUNCTION 1
	TRNN	P2,1B32			;0?
	JRST	.+3
	TYPEIT	<0 >
	TRNN	P2,1B33
	JRST	.+3
	TYPEIT	<1 >
	TRNN	P2,1B34
	JRST	.+3
	TYPEIT	<2 >
	TRNN	P2,1B35
	JRST	.+3
	TYPEIT	(3)
	TYPEIT	<
	LOWER ADDRESS BOUNDARY:	>
	MOVE	P2,1(P1)		;GET FUNCTION 1
	LDB	T1,[POINT 8,P2,21]	;GETS ADDRESS BITDS
	LSH	T1,^D14			;MOVED OVER TO CONVERT TO BETTER FORMAT
	PUSHJ	P,.TOCTW
	TYPEIT	<
	UPPER ADDRESS BOUNDARY:	>
	LDB	T1,[POINT 4,P2,25]	;GETS 18-21
	LSH	T1,^D14			;MOVED TO CORRECT PLACE
	LDB	T2,[POINT 4,P2,17]	;GET 14-17
	HRL	T1,T2			;SETSUP 14-21 FOR UPPER ADDR
	TRO	T1,37777		;SET THE OTHER BITS
	PUSHJ	P,.TOCTW
SBUSER:	TYPEIT	<
	ERRORS DETECTED:	>
	MOVE	P2,0(P1)
	LDB	P4,[POINT 6,P2,5]	;6 ERROR BITS
	SKIPN	P4			;ANY SET?
	 PUSHJ	P,[TYPEIT (NONE)
		POPJ	P,0]
	TRNE	P4,1B30			
	 PUSHJ	P,[TYPEIT (CONTR ERR)
		POPJ	P,0]
	TRNE	P4,1B31			;
	 PUSHJ	P,[TYPEIT (CORR ERR)
		POPJ	P,0]
	TRNE	P4,1B32			;INC CYCLE?
	 PUSHJ	P,[TYPEIT (INC CYCLE)
		POPJ	P,0]
	TRNE	P4,1B33			;READ PARITY
	 PUSHJ	P,[TYPEIT (READ PARITY)
		POPJ	P,0]
	TRNE	P4,1B34
	 PUSHJ	P,[TYPEIT (WRITE PARITY)
		POPJ	P,0]
	TRNE	P4,1B35
	 PUSHJ	P,[TYPEIT (ADDR PARITY)
		POPJ	P,0]

SBUS77:	HLRO	T1,-1(P1)		;GET -# OF FUNCTIONS FOR LAST CONTROLLER
	SUB	P1,T1			;ADVANCE POINTER (SUBTRACT NEG #)
	AOBJN	P1,SBUS01		;DO NEXT CONTROLLER YX
	 POPJ	P,0			;ALL DONE
;HERE TO DECODE F0 & F1 FOR MF20, RETURN TO SBUSER TO LIST ERRORS DETECTED
;P1=PNTR,P2=F0,P3=F1

SBUSMF:		TYPEIT	<
F0:	>
	MOVE	T1,0(P1)		;GET FUNCTION 0
	PUSHJ	P,.TXWDW
	TYPEIT	<	F1:	>
	MOVE	T1,1(P1)		;GET FUNCTOON 1
	PUSHJ	P,.TXWDW
	TYPEIT	<
LAST WORD REQUEST:	>
	HLRZ	P4,0(P1)		;GET 0-17 OF F0
	TRNE	P4,1B26
	 PUSHJ	P,[TYPEIT (RQ0)
		POPJ	P,0]
	TRNE	P4,1B27
	 PUSHJ	P,[TYPEIT (RQ1)
		POPJ	P,0]
	TRNE	P4,1B28
	 PUSHJ	P,[TYPEIT (RQ2)
		POPJ	P,0]
	TRNE	P4,1B29
	 PUSHJ	P,[TYPEIT (RQ3)
		POPJ	P,0]
	TRNE	P4,1B30			;READ?
	 PUSHJ	P,[ TYPEIT (- READ )
			POPJ	P,0]
	TRNE	P4,1B31			;WRITE?
	 PUSHJ	P,[ TYPEIT ( WRITE )
			POPJ	P,0]
	TYPEIT	<
LAST ADDRESS HELD:	>
	MOVE	T2,0(P1)		;GET F0
	LDB	T1,[POINT 22,T2,35]	;ADDRESS FIELD
	PUSHJ	P,.TOCTW		;LIST IT
	TYPEIT <
CONTROLLER STATUS:	>
	MOVE	P4,1(P1)		;GET F1
	TRNE	P4,1B25			;DISABLED?
	 PUSHJ	P,[ TYPEIT (DISABLED)
		POPJ	P,0]
	TYPEIT 	< SF2 & SF1= >
	LDB	T1,[POINT 2,P4,27]
	PUSHJ	P,.TOCTW		;IN OCTAL

	JRST	SBUSER			;RETURN TO LIST DETECTED ERRORS
;END OF [733]

SBSTYP:	SIXBIT/CUST/
	SIXBIT/MA20/
	SIXBIT/DMA20/
	SIXBIT/MB20/
	SIXBIT/UNKN/
	SIXBIT/MF20/

SBSSIZ:	0
	^D16
	0
	^D32
	0
	0

SBSINT:	[ASCIZ/OFF-LINE/]
	[ASCIZ/NONE/]
	[ASCIZ/2-WAY/]
	[ASCIZ/4-WAY/]
;ROUTINE TO DO OUTPUT FOR DMA SBUS FUNCTION
SBDMA:	MOVE	P3,0(P1)		;GET FUNCTION
	TYPEIT	<
	INTERLEAVE MODE:	>
	LDB	T2,[POINT 2,P3,7]	;GET INTERLEAVE MODE
	MOVE	T1,[SIXBIT/4 WAY/]	;ASSUME THE BEST
	CAIN	T2,2
	 MOVE	T1,[SIXBIT/2 WAY/]
	CAIN	T2,1
	 MOVE	T1,[SIXBIT/NONE/]	;WE TRIED
	PUSHJ	P,.TSIXN
	TYPEIT	<
	DMA:
	LAST ADDR HELD:	>
	LDB	T1,[POINT 22,P3,35]	;A FEW ADDR BITS
	PUSHJ	P,.TOCTW
	TYPEIT	<
	ERRORS DETECTED:	>
	LDB	P3,[POINT 6,P3,5]	;6 ERROR BITS
	SKIPN	P3			;ANY SET?
	 PUSHJ	P,[TYPEIT (NONE)
		POPJ	P,0]
	TRNE	P3,1B32			;NXM?
	 PUSHJ	P,[TYPEIT (INC. CYCLE)	;[435]
		POPJ	P,0]
	TRNE	P3,1B33			;READ PARITY
	 PUSHJ	P,[TYPEIT (READ PARITY)
		POPJ	P,0]
	TRNE	P3,1B34
	 PUSHJ	P,[TYPEIT (WRITE PARITY)
		POPJ	P,0]
	TRNE	P3,1B35
	 PUSHJ	P,[TYPEIT (ADDR PARITY)
		POPJ	P,0]
	JRST	SBUS77			;GET NEXT CONTROLLER

;END EDIT  [614]
	SUBTTL	SPECIAL KLINIK ROUTINES FOR BRIEF   [1006]

	[ASCIZ /CLEAR/]			;377  (8BIT -1)
FE$KLI:	[ASCIZ /ILLEGAL EVENT TYPE!!!!/]
	[ASCIZ /SET/]			;1
	[ASCIZ /LINE RING/]		;2
	[ASCIZ /LINE DISCONNECT/]	;3
	[ASCIZ /LINE CONNECT/]		;4
	[ASCIZ /BAD PASSWORD/]		;5
	[ASCIZ /UNSUCCESSFUL LOGON/]	;6
	[ASCIZ /ACTIVE ON REBOOT/]	;7

FE.KLI:	CAIGE	T1,K.LSKL		;RANGE CHECK EVENT TYPE
	 SETZ	T1,			;BAD! - MARK IT ILLEGAL
	CAIN	T1,K.LCKL		;(8BIT -1) ?
	 SETO	T1,			;YES! - MAKE IT A 36BIT -1
	CAILE	T1,K.LRBA		;HIGH END RANGE CHECK
	 SETZ	T1,			;BAD! - MARK IT ILLEGAL
	MOVE	T1,FE$KLI(T1)		;POINT TO CORRECT STRING
	PJRST	.TSTRG			;TYPE IT & RETURN

KR%ECD:	TRNN	P2,1B35
	JRST	.+3
	TYPEIT	< CLK STOP,>
	TRNN	P2,1B34
	JRST	.+3
	TYPEIT	< DRAM PAR,>
	TRNN	P2,1B33
	JRST	.+3
	TYPEIT	< CRAM PAR,>
	TRNN	P2,1B32
	JRST	.+3
	TYPEIT	< FAST MEM PAR,>
	TRNN	P2,1B31
	JRST	.+3
	TYPEIT	< FIELD SERVICE STOP>
	POPJ	P,			;RETURN

FE%DEV:	MOVE	T1,FE$NAM(T1)		;GET DEVICE NAME IN SIXBIT
	PJRST	.TSIXN			; OUTPUT IT & RETURN

; SUBROUTINE TO ADJUST FOR SUBTABLE POINTERS THAT REFERENCE FROM HDBUFF

FIXOFF:	ANDI	P1,777			;GET WKBUFF OFFSET FROM BRIEF COMMAND WORD
	SUBI	T1,HDFIX		;MAKE OFFSET ADJUSTMENT TO POINTER
	MOVEM	T1,WKBUFF(P1)		;PUT POINTER BACK IN WKBUFF
	POPJ	P,0			;NOW WE CAN USE IT NORMALLY
	SUBTTL	SUBROUTINES FOR DOING HEADERS

;HEADFL -- SUBROUTINE TO FILL THE HEADER BUFFER FROM I/O BUFF
;CALL	PUSHJ	P,HEADFL
;RETURN	CALL+1
;HEADER BUFFER FILLER AS SPECIFIED BY HEADWC

HEADFL:	SKIPN	HEADWC			;HDR LENGTH =0  [760]
	  JRST	HEADST			;YES
	SKIPN	ENTRWC			;BODY = 0?
	  JRST	ENTRST
	SETZ	WKINDX,			;CLEAR INDEX
	SKIPG	T1,HEADWC		;PICKUP # OF WORDS IN HEADER
	FATAL	<ENTRY WITH ZERO LENGTH HEADER SPECIFIED>
	SUBI	T1,1			;WD0 IS ALREADY IN HDBUFF
	MOVNS	T1
	MOVS	WKINDX,T1		;SETUP FOR AOBJ USE
	HRRI	WKINDX,1		;START AT HDBUFF+1
	TLO	F,F.READ		;SAY THAT EOF IS CLACKERS
XFRHDR:	PUSHJ	P,GETWD
	MOVEM	MASTWD,HDBUFF(WKINDX)	;STORE IT
	AOBJN	WKINDX,XFRHDR		;LOOP
	TLZ	F,F.READ		;SAY DONE WITH FILLING
	MOVE	T1,HDBUFF+HDRDAT	;PICKUP DATE/TIME OF ENTRY
	MOVEM	T1,FILEND		;CONTINUE TO SAVE AS POSSIBLE LAST ENTRY
	TLNE	F,F.ONCE		;IS THIS FIRST ENTRY SEEN IN FILE
	JRST	HDRDUN			;SKIP FOLLOWING ONCE-ONLY CODE
	MOVEM	T1,FILEST		;SAVE
	MOVE	T1,HDBUFF+HDRPSN	;GET SERIAL #  [545]  [610]
	MOVEM	T1,SYSSER		;SAVE IT FOR SYSERS
	TLO	F,F.ONCE		;SAY ONCE-ONLY CODE IS DONE
HDRDUN:	POPJ	P,			;RETURN
;DMPENT -- SUBROUTINE TO DUMP UNRECOGNIZED ENTRY
;JRST	DMPENT
;REWRITTENWITH EDIT 205
;RETURN	JRST	ABORT

DMPENT:					;#11 .
 	TRNE	F,F.BRF			;#11 Brief?
	 JRST	DMPEN1			;#11 yes, don't say dumping
	WARN	<DUMPING UNKNOWN ERROR TYPE IN OCTAL>
	TYPEIT	<DUMPING UNKNOWN ERROR IN OCTAL
>
DMPEN1:					;#11 .
	TYPEIT	<
>					;#11 Return first
	AOS	T1,SEQNUM		;#11 GET SEQ NUMBER
	PUSHJ	P,.ODECW		;#11 OUTPUT IN DECIMAL WITH '.'
	TYPEIT	< ERROR CODE =	>	;#11 showing the code

	MOVE	T1,ERRIND		;GET OFFSET
	PUSHJ	P,.TOCTW

	PUSHJ	P,.TCRLF
	MOVE	P1,HDBUFF		;GET WORD 0
	LDB	T1,[POINT 6,P1,23]	;GET HDR VER
	SKIPE	T1			;0=VER 0
	SETOM	HDVER1			;REMEMBER
	SKIPE	HDVER1			;DID WE JUST SET IT?
	LDB	T1,[POINT 3,P1,26]	;YES
	SKIPN	HDVER1			;CHECK AGAIN
	LDB	T1,[POINT 3,P1,29]	;GET 3 BITS OF HDR LENGTH
	MOVEM	T1,HEADWC		;SAVE WHICHEVER WE GOT
	SKIPE	HDVER1			;TRY AGAIN
	LDB	T1,[POINT 9,P1,35]	;VER 1=GET 9BITS OF BODY LENGTH
	SKIPN	HDVER1			;VER 0?
	LDB	T1,[POINT 6,P1,35]	;YES, GET 6 BITS
	MOVEM	T1,ENTRWC		;SAVE EITHER
	ADD	T1,HEADWC
	MOVEM	T1,TOTWC		;SAVE TOTAL # WDS IN ENTRY
	PUSHJ	P,HEADFL		;FILL UP HEADER BUFFER
	SKIPG	T1,ENTRWC		;PICKUP ENTRY LENGTH AND CHECK FOR LEGALITY
	JRST	ENTRST
	MOVNS	T1			;PUT -LENGTH IN T1
	MOVS	WKINDX,T1		;SETUP FOR AOBJ USE
	HRRI	WKINDX,0		;SET RH OF WKINDX TO 0
	TLO	F,F.READ		;NOW LETS DO BUFFER XFER
DMPMOR:	PUSHJ	P,GETWD			;LOOP HERE TO FILL WK BUFFER
	MOVEM	MASTWD,WKBUFF(WKINDX)
	AOBJN	WKINDX,DMPMOR		;IS ALL OF ENTRY IN WKBUFF

HEADDM:	TRNE	F,F.BRF			;#11 brief?
	 JRST ABORT			;#11 yes, stop now
	TYPEIT	<HEADER:
>
	SETZ	WKINDX,			;ZERO WORKING INDEX BUFFER
	MOVE	T1,HEADWC		;PICKUP HEADER ZE
	MOVNS	T1
	MOVS	WKINDX,T1		;SET_P FOR AOBJ USE
	HRRI	WKINDX,0		;CLEAR RH OF WKINDX
	ADDI	WKINDX,HDBUFF		;SET FOR START AT HDBUFF
	PUSHJ	P,DUMPIT		;DUMP HEADER
BODYDM:	TYPEIT	<
BODY:
>
	SETZ	WKINDX,
	MOVE	T1,ENTRWC		;PICKUP BODY OF ENTRY SIZE
	MOVNS	T1
	MOVS	WKINDX,T1		;SETUP FOR AOBJ USE
	HRRI	WKINDX,0		;CLEAR RH OF WKINDX
	ADDI	WKINDX,WKBUFF		;SET START OF DUMP AT WKBUFF
	PUSHJ	P,DUMPIT
	JRST	ABORT			;GO PROCESS NEXT ENTRY
DUMPIT:	MOVE	P1,(WKINDX)		;PICKUP CORRECT WORD
	PUSHJ	P,.TCRLF
	MOVE	T1,P1			;PUT WORD IN T1 FOR OUTPUT
	PUSHJ	P,.TXWDW		;GO OUTPUT IT
	AOBJN	WKINDX,DUMPIT		;LOOP TILL ENTRY DUMPED
	POPJ	P,			;RETURN
	SUBTTL	HEADER OUTPUT ROUTINES

;TITLST -- SUBROUTINE TO OUTPUT PAGE TITLE
;TTLS1 -- ENTRY POINT FOR SYSERS - DOESN'T DO PAGE LIMIT CHECK
;CALL	PUSHJ	P,TITLST
;
;RETURN	CALL+1

TITLST:	PUSHJ	P,FFPRNT		;DOES FORMFEED AND PAGE LIMIT TEST
	MOVEI	T1,[ASCIZ /  SYSTEM /]	;#10   [1200]
	MOVEM	T1,HDRLBL		;SET UP DEFAULT PAGE TITLE
TTLS1:	TYPEIT	<SYSERR %>
	PUSHJ	P,VERED			;GO TO ROUTINE TO PRINT VERSION AND EDIT NUMBERS
	MOVE	T1,HDRLBL		;PRINT PAGE TITLE  [1200]
	PUSHJ	P,.TSTRG
	MOVE	T1,HDBUFF+HDRPSN ; [1106]
	ANDI	T1,SYS.SN
	PUSHJ	P,.ODECW
	TYPEIT	<   >
	SKIPE	TOPMON			;TOPS-20 RUNNING?
	 JRST	TITLS1			;YES! - DO TOPS-20 STYLE
	PUSHJ	P,.TDATN		;GO TYPE TODAYS DATE
	PUSHJ	P,.TSPAC		;AND A SPACE
	PUSHJ	P,.TTIMN		;GO TYPE CURRENT TIME
	JRST	TITLS2			;SKIP OVER TOPS-20 STUFF

TITLS1:					;#10 .
.NULIO==377777				;#10 null I/O device
.SYSVE==13				;#10 table number for system version
.APRID==34				;#10 table number for APR serial num
OPDEF GETAB% [104000,,10]		;#10 get table JSYS
OPDEF SOUT% [104000,,53]		;#10 string output JSYS
	SKIPE	SYSNAM			;#10 already got system name?
	 JRST	TITLSX			;#10 yes, use that
	MOVEI	T1,.APRID		;#10 check this system's serial num
	GETAB%				;#10 get APR ser num
	 ERJMP	TITLSZ			;#10 skip name if this fails
	MOVE	T2,HDBUFF+HDRPSN	;#10 get APRID from file
	ANDI	T2,SYS.SN		;#10 mask off all but ser num
	CAME	T1,T2			;#10 same processor?
	 JRST	TITLSZ			;#10 no, don't do the name
	MOVSI	T2,.SYSVER		;#10 system version table
	HRROI	T1,.SYSVER		;#10 get length of table
	GETAB%				;#10 .
	 ERJMP	TITLSZ			;#10 something funny
	CAMG	T1,[-^D10]		;#10 too big
	 MOVE	T1,[-^D10]		;#10 yes, use size
	HRLZ	T3,T1			;#10 save length of table
TITLSY:	MOVS	T1,T2			;#10 get table,,disp
	GETAB%				;#10 .
	 ERJMP	TITLSZ			;#10 .
	MOVEM	T1,SYSNAM(T3)		;#10 save word
	MOVE	T4,[POINT 7,SYSNAM(T3)]	;#10 
	AOS	T2			;#10 next word from table
	AOBJN	T3,TITLSY		;#10 next word to store. done?
	HRROI	T2,SYSNAM		;#10 point to version string
	MOVEI	T1,.NULIO		;#10 to nowhere
	MOVEI	T3,^D49			;#10 max size
	MOVEI	T4,","			;#10 up to comma
	SOUT%
	SETZ	T1,			;#10 a null
	DPB	T1,T2			;#10 replace the comma with it
TITLSX:	HRRZI	T1,SYSNAM		;#10 point to the version
	PUSHJ	P,.TSTRG		;#10 output it
	TYPEIT	<  >			;#10 space before date
TITLSZ:					;#10 .
	HRROI	T1,DATLOC		;STR CONVERTED ASCIZ HERE
	SETO	T2,			;CURRENT TIME AND DATE
	HRLZI	T3,200			;LISTING OPTION ON DATE AND TIME  (NO SECONDS)
	ODTIM				;CONVERT
	HRRZI	T1,DATLOC
	PUSHJ	P,.TSTRG		;NOW LIST IT

TITLS2:	TYPEIT	<  PAGE >		;#10 .
	MOVE	T1,PAGNUM		;OUTPUT PAGE #
	PUSHJ	P,.TDECW		; IN DECIMAL
	PUSHJ	P,.TCRLF		; [724]
	POPJ	P,



VERED:	MOVEI	T1,VSYSER		;PICKUP VERSION NUMBER
	PUSHJ	P,.TOCTW

;EDIT 106
IFG <VMINOR>,<
IFG <VMINOR+"A"-"Z">,<			;IF MANY PATCHES
	MOVEI	T1,<<VMINOR-1>/<"Z"-"A">>+"A"
	PUSHJ	P,.TCHAR
>
;END MASSIVE EDITS

	MOVEI	T1,"A"+VMINOR-1-<"Z"-"A">*<<VMINOR-1>/<"Z"-"A">>
	PUSHJ	P,.TCHAR		;THANKS FOR EDIT 106!!!
>
	TYPEIT	<(>
	MOVEI	T1,VEDIT
	PUSHJ	P,.TOCTW
	TYPEIT	<)>

;MORE OF 106
IFG <VWHO>,<
	MOVNI	T1,VWHO			;IF NON-DEC
	PUSHJ	P,.TDECW		;AND LIST
>
	POPJ	P,
;START EDIT  [724]

;BRFHDR - PRINTS BRIEF HEADER

BRFHDR:	NOTNOW				;IF NOT /NOW DONT.
	 JRST BRFNOW
	MOVE	T1,LINCNT		;GET CURRENT LINE COUNT
	ADDI	T1,5			;ADD MAX BRIEF ENTRY LENGTH COUNTING DATE LINE
	CAILE	T1,0			;CAN WE PRINT THIS ENTRY WITHOUT PAGE OVERFLOW
	PUSHJ	P,TITLST		;NO! - START NEW PAGE
BRFNOW:	SKIPE	TOPMON			;TOPS-20 RUNNING?		START EDIT [737]
	SKIPN	TOPENT			;YES! - TOPS-20 ENTRY?
	 JRST	BRFHD			;NO! - MUST DO TEN STYLE
	MOVE	T2,HDBUFF+HDRDAT ;GET THE DATE
	HRLZI	T4,40000		;MAKE IT JULIAN DATE
	ODCNV				; RETURNS  [YEAR,,JULIAN DATE]  IN 'T2'
	SKIPA				;SKIP TOPS-10 LINE
BRFHD:	HLLZ	T2,HDBUFF+HDRDAT ;GET DATE ALONE - TOPS-10
	CAME	T2,BRFDAT		;DATE CHANGE?			END EDIT  [737]
	PUSHJ	P,BRFHD2		;YES! - OUTPUT NEW DATE LINE
	PUSHJ	P,.TCRLF		;CR
	NOTNOW				;DONT IF /NOW
	 JRST	BRFSHD			;SKIP SEQ NUMBER IF /NOW
	MOVE	T1,SEQNUM		;GET SEQ NUMBER
	PUSHJ	P,.ODECW		;OUTPUT IN DECIMAL WITH '.'
	PUSHJ	P,.TSPAC		;OUTPUT SPACE
BRFSHD:	SKIPE	TOPENT			;TOPS-20 RECORDED?
	 PJRST	BRFHDB			;YES! - TRY TOPS-20 STYLE
BRFHD0:	MOVE	T1,HDBUFF+HDRDAT ;GET DATE
	PUSHJ	P,.CNTDT		;CONVERT TO STANDARD FORMAT
	PUSHJ	P,.TTIME		;OUTPUT TIME
	MOVEI	T1,CCF6			;STRING CONTAINS FF's & CR's
	PJRST	CRCCMD			;DONE HEADERS - FORCE ALL OF THIS OUT & RETURN

BRFHD2:	MOVEM	T2,BRFDAT		;SAVE LATEST DATE   [737]
	PUSHJ	P,.TCRLF		;CR
	PUSHJ	P,.TCRLF		;CR
	SKPNOW				;NO SEQ NUMBER IF /NOW
	TYPEIT	<SEQ  >
	TYPEIT	<  TIME    >
	SKIPE	TOPENT			;TOPS-20 RECORDED?
	 PJRST	BRFHDA			;YES! - TRY TOPS-20 STYLE
BRFHD3:	MOVE	T1,BRFDAT		;GET DATE BACK
	PUSHJ	P,.CNTDT		;CONVERT TO STANDARD FORMAT
	MOVE	T1,T2			;POSITION DATE
	PUSHJ	P,.TDATE		;OUTPUT DATE
	PJRST	.TCRLF			;DO CR/LF & RETURN

BRFHDA:	SKIPN	TOPMON			;TOPS-20 RUNNING?
	 PJRST	BRFHD3			;NO! - MUST DO TEN STYLE
	HRROI	T1,DATLOC		;WHERE TO STORE IT
	MOVE	T2,HDBUFF+HDRDAT ;GET DATE
	HRLZI	T3,202401		;FORMAT FOR OUTPUT
	ODTIM				;TRANSLATE DATE TO TEXT
	HRRZI	T1,DATLOC		;GET STRING POINTER
	PUSHJ	P,.TSTRG		;NOW LIST IT
	PJRST	.TCRLF			;DO CR/LF & RETURN

BRFHDB:	SKIPN	TOPMON			;TOPS-20 RUNNING?
	 PJRST	BRFHD0			;NO! - MUST DO TEN STYLE
	HRROI	T1,DATLOC		;WHERE TO STORE IT
	MOVE	T2,HDBUFF+HDRDAT ;GET DATE
	HRLZI	T3,400000		;FORMAT FOR OUTPUT
	ODTIM				;TRANSLATE DATE TO TEXT
	HRRZI	T1,DATLOC		;GET STRING POINTER
	PUSHJ	P,.TSTRG		;NOW LIST IT
	MOVEI	T1,CCF6			;STRING CONTAINS FF's & CR's
	PJRST	CRCCMD			;DONE HEADERS - FORCE ALL OF THIS OUT & RETURN

;END EDIT  [724]

;HDRLST -- SUBROUTINE TO TYPE HEADER INFORMATION
;SUCH AS ENTRY TYPE, DATE OF LOGGING
;TIME OF LOGGING, AND UPTIME OF SYSTEM AT TIME OF LOGGING
;CALL	PUSHJ	P,HDRLST
;
;RETURN	CALL+1
;***
;CHANGED WITH [1146] TO ALSO LIST CONTENTS OF WKBUFF IN OCTAL
;IF SPECIFIED WITH "/OCTAL"
;***

HDRLST:	NOTNOW				;DONT IF NOT /NOW
	OUTCHR	[7]			;GIVE ME A BELL TO LET ME KNOW
	TRNE	F,F.BRF			;/BRIEF ?  [724]
	PJRST	BRFHDR			;YES! - DO HEADERS BRIEF STYLE
	NOTNOW
	 JRST HDRNOW
	MOVE	T1,LINCNT
	MOVE	T2,ERRIND		;PICKUP ENTRY TYPE
	ADD	T1,LINE##(T2)		;ADD COUNT OF LINES IN NEXT ENTRY
	MOVEM	T1,LINCNT		;SAVE NEW LINE COUNT
	CAILE	T1,0			;CAN WE PRINT THIS ENTRY WITHOUT PAGE OVERFLOW
	 JRST	HDRPNT			;NO! - GO DO HEADER TYPEOUT
HDRNOW:	TYPEIT	<

***********************************************
>
	HLRZ	T1,HDBUFF+HDRCOD
	TRNE	T1,CSHENT		;ENTRY EXTRACTED FROM A CRASH?
	 PUSHJ	P,CSHPNT		;YES-SAY SO
	MOVE	T1,ERRIND
	MOVE	T1,TYPMES##(T1)		;PICKUP APPROPIATE TEXT MESSAGE FOR HEADER
	PUSHJ	P,.TSTRG
	TYPEIT	<
 LOGGED ON >
	SKIPE	TOPENT			;TOPS-20 RECORDED?
	 JRST HDRLSA			;YES! - TRY TOPS-20 STYLE
HDRLS1:	MOVE	T1,HDBUFF+HDRDAT ;PICKUP DATE OF ENTRY CURRENTLY BEING PROCESSED
	PUSHJ	P,GETNBS
	TYPEIT	< AT >
	MOVE	T1,MSTIMX
	PUSHJ	P,.TTIME		;GO CONVERT TO HH:MM:SS AND OUTPUT

HDRLSB:	TYPEIT	<      MONITOR UPTIME WAS >
	HLRZ	T1,HDBUFF+HDRUPT ;PICKUP LH OF NBS DATE/TIME WORD
	CAIE	T1,0
	PUSHJ	P,SAYDAY		;DECODE #DAYS UPTIME IF ANY
	HRRZ	T1,HDBUFF+HDRUPT	;PICKUP RH OF DATE/TIME WORD
	HRL	T1,DUMDAY##		;PUT DUMMY NON-ZERO DAY IN LH
	PUSHJ	P,.CNTDT		;CONVERT TO 12 BIT FORMAT
	PUSHJ	P,.TTIME		;GO DECODE UPTIME AS HH:MM:SS
	SKIPE	HDVER1			;MORE TO LIST
	 PUSHJ	P,HD1PNT		;DO S/N
	NOTNOW
	 JRST	HDRLSS
	TYPEIT	<
	RECORD SEQUENCE NUMBER:	>
	MOVE	T1,SEQNUM		;GET SEQ NUMBER
	PUSHJ	P,.ODECW		;IN DECIMAL WITH "."
HDRLSS:	TYPEIT	<
***********************************************>
;START [1146]
	TRNE	F,F.OCT
	 PUSHJ	P,LSTOCT		;LIST IT IF DESIRED
;END [1146]
	POPJ	P,


;MODIFIED WITH EDITS  [426], [724]

HDRLSA:	SKIPN	TOPMON			;TOPS-20 RUNNING?
	 PJRST	HDRLS1			;NO! - MUST DO TEN STYLE
	HRROI	T1,DATLOC		;WHERE TO STORE IT
	MOVE	T2,HDBUFF+HDRDAT
	HRLZI	T3,202001		;FORMAT FOR OUTPUT
	ODTIM
	HRRZI	T1,DATLOC		;ADDR ONLY
	PUSHJ	P,.TSTRG		;NOW LIST IT
	JRST	HDRLSB			;NOW RETURN



;HDRPNT -- SUBROUTINE TO DO PAGE HEADER AND GIVE FORM FEED
;CALL	JRST	HDRPNT
;
;RETURN	JRST	HDRLST

HDRPNT:	PUSHJ	P,TITLST		;GO DO TITLE INFO
	JRST	HDRLST			;NOW  TYPE ENTRY


;ROUTINE TO PRINT VERSION 1 ENTRY HEADER
;CALLED FROM HDRLST WITH PJRST

HD1PNT:	TYPEIT	<
	DETECTED ON SYSTEM # >
	MOVE	T1,HDBUFF+HDRPSN	;GET S/N WORD  [610]
	ANDI	T1,SYS.SN		;GET S/N ALONE
	PJRST	.ODECW

CSHPNT:	TYPEIT	<  ** THIS ENTRY COPIED FROM A SAVED CRASH **>
	PJRST	.TCRLF


;PAGXCD -- SUBROUTINE TO HANDLE EXCEEDED PAGE LIMIT OCCURENCE
;CALL	PUSHJ	P,PAGXCD
;
;RETURN	CALLS SUMLST AND EXITS

PAGXCD:	WARN	<EXCEEDED PAGE LIMIT...PERFORMING SUMMARY>
	TYPEIT	<

*************   PAGE LIMIT EXCEEDED **************>
	JRST GOSUM			;EDIT 120 SUMMARY REQUIRES AN OVERLAY!!

;	CLOSE	INPCHN,  ;REMOVED IN EDIT # [724]
;	CLOSE	OUTCHN,
;	EXIT
	SUBTTL MISC LIBRARY ROUTINES

;SAYDAY -- SUBROUTINE TO EXAMINE LH OF NBS DATE/TIME WORD AND TYPEOUT
;# OF DAYS REPRESENTED IN DECIMAL
;SETUP	T1=LH NBS DATE/TIME WORD
;CALL	PUSHJ	P,SAYDAY
;
;RETURN	CALL+1

SAYDAY:	PUSH	P,T1			;SAVE T1
	PUSHJ	P,.TDECW		;TYPE OUT # IN T1
	POP	P,P4
	SUBI	P4,1			;GET # DAYS -1
	JUMPG	P4,SAYDA1		;WASSYSTEM UP FOR MORE THAN 1 DAY
	TYPEIT	< DAY >
	JRST	SAYRET			;RETURN TO CALLER
SAYDA1:	TYPEIT	< DAYS >
SAYRET:	POPJ	P,


;GETNBS -- SUBROUTINE TO OUTPUT DATE IN MM-DD-YYYY FORMAT
;GETNBS -- CONVERTS FROM NBS FORMAT TO MM-DD-YYYY
;SETUP	T1=NBS DATE/TIME WORD
;CALL	PUSHJ	P,GETNBS

GETNBS:	SKIPE	TOPENT			;TOPS-20 RECORDED?
	 PJRST	GETNB1			;YES! - TRY TOPS-20 STYLE
GETNB2:	PUSHJ	P,.CNTDT
	MOVEM	T1,MSTIMX		;STORE FRACTIONAL PART OF DAY IN MSTIMX
	MOVE	T1,T2			;PUT 12 BIT DATE IN T1 AS RETURNED FROM .CNTDT
	PJRST	.TDATE			;GO TYPE DATE

GETNB1:	SKIPN	TOPMON			;TOPS-20 RUNNING?
	 PJRST	GETNB2			;NO! - MUST DO TEN STYLE
	MOVE	T2,T1			;DATE TIME TO T2
	HRROI	T1,DATLOC		;WHERE TO PUT THE STRING
	HRLZI	T3,202000		;JSYS OPTION FLAGS
	ODTIM				;CREATE ASCIZ STRING
	HRRZI	T1,DATLOC
	PJRST	.TSTRG			;NOW DUMP THE ASCIZ.
	SUBTTL	WORD LEVEL SUBROUTINES

;THIS CODE ADDED BY EDIT 726-TJW
;HERE TO TYPE OUT ASCII STORED IN FUNNY PDP11 FORMAT
;CALLED WITH PUSHJ WITH 11 WORD IN P2 RETURNS POPJ

T11ACI:	CAIN	P2,0			;DONT WANT TO TYPE NULLS
	POPJ	P,0
	LDB	T1,[POINT 7,P2,17]
	PUSHJ	P,.TCHAR
	LDB	T1,[POINT 7,P2,9]
	PUSHJ	P,.TCHAR
	LDB	T1,[POINT 7,P2,35]
	PJRST	.TCHAR

;END EDIT 726

.OCTLE:	HRRZ	T1,P1			;PICKUP POINTER TO ASCIZ TEXT
	PUSHJ	P,.TSTRG
	MOVE	T1,P2			;PICKUP WORD TO BE OUTPUT
	PJRST	.TOCTW			;SIGNED NUM TYPEOUT

.DECML:	HRRZ	T1,P1			;PICKUP POINTER TO ASCIZ TEXT
	PUSHJ	P,.TSTRG
	MOVE	T1,P2			;PICKUP WORD TO BE OUTPUT
	PUSHJ	P,.ODECW
	POPJ	P,			;GO AWAY

.ASCIE:	HRRZI	P2,WKBUFF(T2)
	HRRZ	T1,P1			;PICKUP POINTER TO ASCIZ TEXT
	PUSHJ	P,.TSTRG
	MOVE	T1,P2			;PICKUP WORD TO BE OUTPUT
	PJRST	.TSTRG

.SIXBT:	HRRZ	T1,P1			;PICKUP POINTER TO ASCIZ TEXT
	PUSHJ	P,.TSTRG
	MOVE	T1,P2			;PICKUP WORD TO BE OUTPUT
	PJRST	.TSIXN

.HAFWD:	HRRZ	T1,P1			;PICKUP POINTER TO ASCIZ TEXT
	PUSHJ	P,.TSTRG
	MOVE	T1,P2			;PICKUP WORD TO BE OUTPUT
	PJRST	.TXWDW

.SPECL:	PUSHJ	P,(P1)
	POPJ	P,

HKSTRG:	LDB	T1,[POINT 9,P1,35]	;GET REAL OFFSET
	ADDI	T1,WKBUFF		;ADD VALUE OF WKBUFF
	PJRST	.TSTRG			;NOW TYPE IT OUT


;SUBROUTINE TO TYPE OUT A TIME WORD WHERE
; LH = # DAYS, NOT DATE
; RH =  1/3 SEC(TOPS-10) SINCE MIDNIGHT

.HTIME:	MOVE	T1,P1			;GET CORRESPONDING ASCIZ TEXT POINTER
	PUSHJ	P,.TSTRG		;DUMP IT
HTIME2::	HLRZ	T1,P2		;GET # DAYS INTO T1
	SKIPE	T1			;IF 0 DONT BOTHER OR
	PUSHJ	P,SAYDAY		;OUTPUT DAY OR DAYS
	HRRZ	T1,P2			;GET TIME SINCE MIDNIGHT
	SKIPE	TOPENT			;[201] TOPS-20 RECORDED
	 MULI	T1,^D333		;CONVERT TO 1/3 SECONDS
	PJRST	.TTIME			;NOW OUTPUT WHAT YOU GOT

;PPNWW--SUBROUTINETO DUMP [P,PN]

.PPNWW:	HRRZ	T1,P1
	PUSHJ	P,.TSTRG
	MOVE	T1,P2
	PJRST	.TPPNW


.ODECW:	PUSHJ	P,.TDECW		;GO TYPEOUT IN DECIMAL
	TYPEIT	<.>
	POPJ	P,			;SCRAM

OHEXB:	MOVEI	T3,^D16
	PUSHJ	P,.TRDXW
	POPJ	P,0


.UDATE:	MOVE	T1,P1			;DUMP COMMENTS
	PUSHJ	P,.TSTRG
	MOVE	T1,P2
	PJRST	GETNBS			;UNIVERSAL FORMAT DATE DUMPER


.TASCI:	MOVE	T1,P1			;PTR TO COMMENTS
	PUSHJ	P,.TSTRG
PTSTRG:	SKIPN	P2			;ANYTHING IN BUFFER?
	 POPJ	P,0			;NO-RETURN IMMED.
	LDB	T1,[POINT 9,HDBUFF+HDRCOD,35]
					;[1259] LOAD ENTRY SIZE
	HRRZS	P2			;[1259] HALF WORD ONLY
	CAMGE	T1,P2			;[1259] RANGE CHECK SIZE AGAINST POINTER
	PJRST	[WARN.CR <
% ILLEGAL POINTER IN 'PTSTRG' >		;[1259] GIVE ERROR MESSAGE
		POPJ	P,0]		;[1259] GET OUT
	MOVEI	T1,WKBUFF(P2)		;OUR POINTER TO FILE'S TEXT
	SKIPN	0(T1)			;ANYTHING THERE?
	 POPJ	P,0			;NOPE
	PJRST	.TSTRG


.PPNWT:	skipe	topmon			;[1263] is this tops-20 ?
	pjrst	.tdir2			;[1263] yes, check a few things
.tdir3:	HRRZ	T1,P1			;[1263] move pointer
	PUSHJ	P,.TSTRG		;output string
	MOVE	T1,P2			;move directory #
	PJRST	.TDIRW			;DO THE REAL TRANSLATION


.TDIRW:	MOVE	P1,T1			;SAVEW THE WORD
	HRLI	T1,-1
	HRRI	T1,DATLOC		;STRING STORAGE
	MOVE	T2,P1			;FIRST HALF
	DIRST
	 JRST	.TDIR1
	HRRZI	T1,DATLOC
	PUSHJ	P,.TSTRG		;DUMP IT
	POPJ	P,0			;GO BACK

.TDIR1:	TYPEIT	<UNKNOWN>
	POPJ	P,0

.tdir2:	move	t1,[sixbit/APRID/]	;[1263] get mon. table name
	sysgt				;[1263] get sys. serial #
	camn	t1,hdbuff+hdrpsn	;[1263] does sys. ser = header #
	pjrst	.tdir3			;[1263] no - do something special
	hrrzi	t1,[asciz/
	USER'S LOGGED IN DIR NUMBER:	/];[1263]
	PUSHJ	P,.TSTRG		;[1263] OUTPUT STRING
	move	t1,p2			;[1263] move directory number
	hrrz	t1,t1			;[1263] zero left half
	pushj	p,.toctw		;[1263] output number
	popj	p,0			;[1263] return


;LST36 - ROUTINE TO LIST A WORD IN T1 AS (T2) OCTAL
;	CHARACTERS INCL. LEADING ZEROS.
;	^D12 IS DEFAULT VALUE IF T2 IS 0
;	WORD MUST BE LEFT JUSTIFIED IN T1.
;LSTRJ - WILL DO IT WITH THE NUMBER IN T1 RIGHT JUSTIFIED  [724]

LSTRJ::	MOVN	T3,T2			;ROTATE RIGHT  (-)
	IMULI	T3,3			;3 BITS PER OCTAL DIGIT
	ROT	T1,(T3)			; FALL INTO OLD CODE
LST36::	PUSHJ	P,SAVE4P		;PRESERVE P1-P4
	MOVE	P1,T2			;# TO PRINT
	SKIPN	T2			;USE DEFAULT?
	 MOVEI	P1,^D12			;YES
	MOVE	T2,T1
LST36A:	MOVEI	T1,0
	ROTC	T1,3			;3 BITS TO T1
	ADDI	T1,60			;CONVERT TO ASCIZ
	PUSHJ	P,.TCHAR		;LIST IT
	CAIN	P1,7			;TIME FOR A DELIMITER?
	 PUSHJ	P,[PUSHJ P,.TCOMA
		PJRST .TCOMA]		;YES USE A COMMA
	SOJG	P1,LST36A		;DO ANOTHER
	PUSHJ	P,RET4P			;RESTORE P1-P4
	POPJ	P,0			;RETURN TO OUR CALLER
;RADIX 50 TO SIXBIT CONVERTER FOR PDP-11 WORDS.
;THIS CODE STOLEN FROM FILEX.MAC
;CALL WITH RAD50 VALUE IN RH OF T1
;RETURNS WITH SIXBIT IN RH OF T1
R5VSIX:	SETZM	P1			;CLEAR ANSWER CELL
	MOVE	T3,[POINT 6,P1,17]	;PNTR FOR OUTPUT
	ANDI	T1,177777		;GOOD SIZE
	IDIVI	T1,3100			;GET FIRST CHAR
	PUSH	P,T2			;SAVE OTHER 2
	PUSHJ	P,R5VOU1		;OUTPUT FIRST
	POP	P,T1			;RESTORE 2&3
	IDIVI	T1,50			;SPLIT APART
	PUSH	P,T2			;SAVE THIRD
	PUSHJ	P,R5VOU1		;OUTPUT 2ND
	POP	P,T1			;RESTORE 3RD
	PUSHJ	P,R5VOU1		;CONVERT
	MOVE	T1,P1
	POPJ	P,0			;RETURN

R5VOU1:	IDIVI	T1,6
	LDB	P2,R5VOU2(T2)		;GET CHAR IN SIXBIT
	IDPB	P2,T3			;PUT IT IN P3
	POPJ	P,0			;AND RETURN IT
R5VOU2:POINT	6,R5VTAB(T1),5
	POINT	6,R5VTAB(T1),11
	POINT	6,R5VTAB(T1),17
	POINT	6,R5VTAB(T1),23
	POINT	6,R5VTAB(T1),29
	POINT	6,R5VTAB(T1),35
R5VTAB:	SIXBIT	\ ABCDEFGHIJKLMNOPQRSTUVWXYZ.%0123456789?\

;SPECIAL DECODING ROUTINES

MONVER:	TYPEIT	(<
	MONITOR VERSION  %>)
	LDB	T1,[POINT 12,P2,29]	;EDIT 106
	PUSHJ	P,.TOCTW		;OUTPUT MAJOR
	LDB	T1,[POINT 6,P2,35]	;NOW MINOR
	JUMPE	T1,MONVC		;IF ANY
	SOS	T1			;MAKE ALPHA OFFSET
	IDIVI	T1,^D26			; [735]
	JUMPE	T1,MONVS2
	ADDI	T1,"A"-1		; [735]
	PUSH	P,T2
	PUSHJ	P,.TCHAR
	POP	P,T2
MONVS2:	MOVEI	T1,"A"(T2)		;GET LOW LETTER
	PUSHJ	P,.TCHAR
MONVC:	MOVEI	T1,"("
	PUSHJ	P,.TCHAR
	LDB	T1,[POINT 18,P2,17]	;CUST VER
	PUSHJ	P,.TOCTW
	MOVEI	T1,")"
	PUSHJ	P,.TCHAR
	POPJ	P,0

MN2VER::	TYPEIT	<
	MONITOR VERSION:	>
	PUSHJ P,DAEVER+2		;[504]USE SOME CODE FOR FREE
	TYPEIT	<
	U-CODE VERSION:		>
	LDB	T1,[POINT 9,HDBUFF+HDRPSN,17]	;GET VER # FROM HEADER
	PUSHJ	P,.TOCTW		;IN OCTAL
	POPJ	P,0			;ABOVE 4 LINES ADDED WITH [540]

DAEVER::	TYPEIT	(<
	DAEMON VERSION  >)
	LDB	T1,[POINT 9,P2,11]	;EDIT 106
	PUSHJ	P,.TOCTW		;OUTPUT MAJOR
	LDB	T1,[POINT 6,P2,17]	;NOW MINOR
	JUMPE	T1,DAEVC		;IF ANY
	SOS	T1			;MAKE ALPHA OFFSET
	IDIVI	T1,^D26			; [735]
	JUMPE	T1,DAEVS2
	ADDI	T1,"A"-1		; [735]
	PUSH	P,T2
	PUSHJ	P,.TCHAR
	POP	P,T2
DAEVS2:	MOVEI	T1,"A"(T2)		;GET LOW LETTER
	PUSHJ	P,.TCHAR
DAEVC:	MOVEI	T1,"("
	PUSHJ	P,.TCHAR
	LDB	T1,[POINT 18,P2,35]	;CUST VER
	PUSHJ	P,.TOCTW
	MOVEI	T1,")"
	PUSHJ	P,.TCHAR
	POPJ	P,0

BADADD:	SKIPL	P2,AOBPNT		;GET THE AOBJN POINTER
	POPJ	P,			;EXIT IF NOT NEGATIVE
	TYPEIT	<

ADDRESSES DETECTED BY SWEEP
>
TAB031:	PUSHJ	P,TBPRNT		;HORIZ. TAB
	MOVE	T1,WKBUFF(P2)		;GET AN ADDRESS
	PUSHJ	P,.TOCTW		;DUMP IT IN OCTAL
	PUSHJ	P,.TCRLF		;CRLF
	AOBJN	P2,TAB031		;GET ANOTHER
	POPJ	P,

TYPAST:	TYPEIT	<*  >
	POPJ	P,

BLDPTR:	HRRZ	T1,P1			;OFFSET ALONE
	SUB	T1,HEADWC
	ADDI	T1,WKBUFF
	HRR	P1,T1
	POPJ	P,0
;ACLST-ROUTINE TO LIST CONTENTS OF 16 AC'S
;SETUP P1 AS AOBJN POINTER W RH = OFFSET TO 1ST

ACLST:	HLLZ	P2,P1			;SECOND POINTER
	PUSHJ	P,.TCRLF
	MOVE 	T1,ACREG(P2)		;SIXBIT NAME OF REG
	PUSHJ	P,.TSIXN
	PUSHJ	P,.TTABC
	MOVE	T1,WKBUFF(P1)		;VALUE TO DUMP
	PUSHJ	P,.TXWDW		;IN HALF WORD
	AOBJN	P2,.+1
	AOBJN	P1,ACLST+1		;ALWAYS GET TO SECOND AOBJN
	POPJ	P,0			;ALL DONE-RETURN TO CALLER

ACREG:	SIXBIT/    0:/
	SIXBIT/    1:/
	SIXBIT/    2:/
	SIXBIT/    3:/
	SIXBIT/    4:/
	SIXBIT/    5:/
	SIXBIT/    6:/
	SIXBIT/    7:/
	SIXBIT/   10:/
	SIXBIT/   11:/
	SIXBIT/   12:/
	SIXBIT/   13:/
	SIXBIT/   14:/
	SIXBIT/   15:/
	SIXBIT/   16:/
	SIXBIT/   17:/

;ROUTINE TO TYPE OUT DEVICE NAME

DRVTYP:	SKIPN	TOPENT			;[1233] TOPS10 ENTRY ?	[1325]
	MOVE	P2,MDEDTP		;[1233]YES GET INDEX FROM MDEDTP- OTHERWISE
	MOVE	T1,MDE000(P2)		;GET DEVICE NAME OUT OF TABLE  [1204]
	PJRST	.TSIXN			;TYPE IT OUT AND RETURN


;DUMMY ROUTINE TO DO LBN TO CYL/SURF/SEC FOR RP02/3

BLOKTN:	LDB	T1,[POINT 3,P2,32]
	CAIN	T1,1
	 JRST	RP02PS
	CAIN	T1,2
	 JRST	RP03PS
	POPJ	P,0

RP02PS:	MOVE	P2,WKBUFF+HDEHBN
	MOVEI	P1,2
	PJRST	DSKP1S

RP03PS:	MOVE	P2,WKBUFF+HDEHBN
	MOVEI	P1,3
	PJRST	DSKP1S


;ROUTINE TO TYPE OUT CYL/SURF/SEC GIVEN LBN AND DRIVE TYPE

BLKTRN:	MOVE	P1,MDEDTP		;GET DEVICE TYPE
	HRRZ	T2,BLTTAB(P1)		;GET ADDRESS TO DISPATCH TO
	PJRST	@T2			;GO TO IT!!

;BLTTAB  TABLE MOVED TO PROCESx  [1007]

DUMPOS:	POPJ	P,0			;NO TRANSLATION..RETURN NOW

TAPPOS:	TYPEIT	< FILE/RECORD >
	HLRZ	T1,WKBUFF+MB%LOC	;GET LOCATION
	PUSHJ	P,.ODECW		;TYPE OUT FILE
	TYPEIT	</>
	HRRZ	T1,WKBUFF+MB%LOC
	PJRST	.ODECW

;ROUTINE TO TYPE OUT CYL./SURF./SEC./ GIVEN MDEDTP IN P1

DSKPOS:					;#6 .
;;;#6 	TYPEIT	< CYL/SURF/SEC= >
;;;#6 	MOVE	P2,WKBUFF+MB%LOC
	HLRZ	T1,BLTTAB(P1)
	MOVE	P1,T1
	SKIPG	.SECBK(P1)		;#6 sectors=blocks?
	 JRST	[TYPEIT <CYL/SURF/REC= > ;#6 no, showing records, not sectors
		JRST DSKP1X]		;#6 .
	TYPEIT	< CYL/SURF/SEC= >
DSKP1X:					;#6 .
	MOVE	P2,WKBUFF+MB%LOC	;#6 .
DSKP1S:	CAIN	P1,10			;[1133]RM03?
	JRST	[SKIPE	TOPENT		;TOPS20 RECORDED?
		 JRST	.+1		;YES
		 CAIGE	P2,^D123000
		 JRST	DSKPO1		;ITS OK
		 SUBI	P2,^D123000
		 JRST	DSKP1S]		;END [1133]
	CAMGE	P2,.MXBLK(P1)
	 JRST	DSKPO1
	SUB	P2,.MXBLK(P1)
	JRST	.-3

DSKPO1:	CAIN	P1,10			;[1133]RM03?
	JRST	[SKIPE	TOPENT		;[1270]TOPS20?
		 JRST	.+1		;[1270]YES
		 IDIVI	P2,^D150	;FIX FOR TOPS10
		 JRST	DSKP02]		;AND RETURN
	IDIV	P2,.TRBLK(P1)
DSKP02:	MOVE	T1,P2
	PUSHJ	P,.ODECW
	TYPEIT	</>
	MOVE	P2,P3
	IDIV	P2,.SUBLK(P1)
	MOVE	T1,P2
	PUSHJ	P,.ODECW
	TYPEIT	</>
	MOVE	P2,P3
	SKIPG	P3,.SECBK(P1)	;#1 get sectors per block
	 JRST [	TLNE P3,(1B1)	;#1 record indices start at 1?
		 ADDI P2,0(P3)	;#1 yes, bump by one record
		IDIVI P2,0(P3)	;#1 divide to get hardware block number
		JRST .+2]	;#1 skip multiply
	IMUL	P2,.SECBK(P1)
	MOVE	T1,P2
	PJRST	.ODECW

;ROUTINE TO TYPEOUT SERIAL NUMBERS OF MASSBUSS DEVICES
; S/N IN P2  (4 BCD DIGITS RIGHT JUSTIFIED)   [1206]

DSERCD:	PUSH	P,P3			;GET SOME TEMPORARY STORAGE
	PUSH	P,P4
	MOVEI	P3,4			;SET UP FOR 4 DIGITS
	MOVE	P4,[POINT 4,P2,19] ; & BYTE POINTER
DSERLP:	ILDB	T1,P4			;GET BYTE
	ADDI	T1,"0"			; & MAKE IT AN ASCII #
	CAILE	T1,"9"			;IF GREATER THAN "9"
	MOVEI	T1,"?"			; MAKE IT A "?"
	PUSHJ	P,.TCHAR		;OUTPUT IT
	SOJG	P3,DSERLP		; & LOOP BACK IF MORE TO DO
	MOVEI	T1,"."			;ADD A PERIOD AT END
	PUSHJ	P,.TCHAR
	POP	P,P4			;RESTORE THE TEMPORARIES
	POP	P,P3
	POPJ	P,0			; AND RETURN

;RS4POS - ROUTINE TO GIVE TRACK/SECTOR FOR RS04'S
;CALLED PUSHJ P,RS4POS WITH LBN IN P2

RS4POS:	TYPEIT	< TRK/SEC >
	CAMGE	P2,.MXBLK+4
	 JRST	RSPS01
	SUB	P2,.MXBLK+4
	JRST	.-3
RSPS01:	IDIV	P2,.TRBLK+4
	MOVE	T1,P2
	PUSHJ	P,.ODECW
	TYPEIT	</>
	MOVE	P2,P3
	IMUL	P2,.SECBK+4
	MOVE	T1,P2
	PJRST	.ODECW

;ROUTINE TO TYPEOUT 4 COLUMNS OF OCTAL NUMBERS
;CALL		MOVE P2,[XWD -NUMBER OF WORDS,OFFSET TO FIRST]
;		PUSHJ	P,COLOUT
;PRESERVES P REGS CLOBBERS T REGS

COLOUT:	PUSH	P,P1
	PUSH	P,P2
	MOVE	P1,[XWD -4,0]
COLLUP:	PUSHJ	P,.TTABC
	MOVE	T1,WKBUFF(P2)
	MOVEI	T2,^D12
	PUSHJ	P,LST36
	AOBJN	P1,NOCRTM
	PUSHJ	P,.TCRLF
	MOVE	P1,[XWD -4,0]
NOCRTM:	AOBJN	P2,COLLUP
	POP	P,P2
	POP	P,P1
	POPJ	P,0

;ROUTINE TO TYPE OUT SBDIAG FUNCTIONS FOR ALL REPORTED CONTROLLERS
;CALL	MOVE	P2,[- NUMBER OF CTRLRS,OFFSET TO FIRST]
;	PUSHJ	P,SBDOUT	CHANGED WITH EDIT [754]

SBDOUT:	ADDI	P2,WKBUFF+1		;POINT AT FUNCTION 0 FOR CONTROLLER
SBDOU1:	PUSHJ	P,.TCRLF
	PUSHJ	P,.TTABC
	HRRZ	T1,-1(P2)		;GET CONTROLLER NUMBER
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	MOVE	T1,0(P2)		;GET FUNCTION 0
	MOVEI	T2,^D12
	PUSHJ	P,LSTRJ
	PUSHJ	P,.TTABC
	MOVE	T1,1(P2)		;GET FUNTION 1
	MOVEI	T2,^D12
	PUSHJ	P,LSTRJ
	PUSHJ	P,.TTABC
	HLRO	T1,-1(P2)		;GET - NUMBER OF FUNCTIONS FOR LAST CTRLR
	SUB	P2,T1			;ADVANCE POINTER
	AOBJN	P2,SBDOU1		;DO NEXT CTRLR
	POPJ	P,0			;ALL DONE











;A LITTLE ROUTINE TO SAVE AND RETURN P1-P4

SAVE4P:	MOVEM P1,SAVEAC
	MOVEM P2,SAVEAC+1
	MOVEM	P3,SAVEAC+2
	MOVEM	P4,SAVEAC+3
	POPJ	P,0

RET4P:	MOVE	P1,SAVEAC
	MOVE	P2,SAVEAC+1
	MOVE	P3,SAVEAC+2
	MOVE	P4,SAVEAC+3
	POPJ	P,0

SAVE4T:	MOVEM	T1,SAVEAC+4
	MOVEM	T2,SAVEAC+5
	MOVEM	T3,SAVEAC+6
	MOVEM	T4,SAVEAC+7
	POPJ	P,0

RET4T:	MOVE	T1,SAVEAC+4
	MOVE	T2,SAVEAC+5
	MOVE	T3,SAVEAC+6
	MOVE	T4,SAVEAC+7
	POPJ	P,0
;HWDUMP -- ROUTINE TO DUMP REGISTER INFORMATION  AT ERROR
;AT END, DIFF AND TEXT TRANSLATION.
;IF WORD IN ENTRY IS 0 - NO OUTPUT
;SETUP P1 = PRINT MODE,,#ITEMS IN LIST
;	WHERE PRINT MODE 1= HALF WORD OCTAL
;		         2=  "    "    8 BIT LEFT JUS BYTES(NOT IMPLEMENTED
;			 3= FULL WORD OCTAL
;			 4=  "     "   8 BIT LEFT JUSTIFIED BYTES
;      P2 = ADDR OF ITEM TITLE TABLE, ADDR OF CONTROL TABLE
;	P3 = OFFSET IN WKBUFF OF "AT ERROR" WORD (1ST),,
;		OFFSET TO "AT END" WORD
;CALL- PUSHJ	RETURN POPJ

;FIRST SOME TABLE GENERATIONS

LISTIT:	XWD	0,NOTRAN
	XWD	0,LSTHO
	XWD	0,LSTHB
	XWD	0,LSTFO
	XWD	0,LSTFB
	XWD	0,LSTFX			;#4 8bit bytes in hex
CHKLXT:	XWD	0,NOTRAN
	XWD	0,CHKLSH
	XWD	0,CHKLSH
	XWD	0,CHKLSF
	XWD	0,CHKLSF
	XWD	0,NOTRAN		;#4 .
HWDUMP:MOVEM	P1,ITCNT		;SAVE ITERATION COUNT
	MOVEM	P2,ADCNT		;AND ADDR
	MOVEM	P3,OFFCNT		;SAVE FIRST OFFSETS TOO
	SETZM	PASCNT			;OK
HWDCON:	HRRZ	T1,ITCNT		;GET #OF ITERATIONS
	CAMG	T1,PASCNT		;DONE ENOUGH?
	 POPJ	P,0			;YES
	HRRZ	P1,PASCNT		;GET INDEX
	HLRZ	P2,ITCNT		;PRINT MODE
;[307]	PUSHJ	P,@CHKLXT(P2)		;GO SEE IF NEXT ENTRY SHOULD
					;BE PRINTED  =0?
;[307]	 JRST	HWDC00			;NO-JUST UPDATE COUNTER
	PUSHJ	P,.TTABC
	HLRZ	T1,ADCNT		;GET BASE ADDR OF TITLES
	ADD	T1,P1
	MOVE	T1,(T1)			;GET SIXBIT REGISTER NAME
	PUSHJ	P,.TSIXN		;DUMP IT
	PUSHJ	P,.TCOLN
	PUSHJ	P,.TTABC
	PUSHJ	P,@LISTIT(P2)		;GO DO LISTING OF VALUES,RETURN TO
					;WORRY ABOUT ALL X-LATION, CALLED
					;ROUTINES LEAVE WORD TOBE X-LATED
					;IN P2 AND LEAVE P1 INTACT.
					;NOW TO TRANSLATE THOSE ONE'S & ZEROS

	HRRZ	T1,ADCNT		;GET BASE OF CONTROL TABLE
	ADD	T1,P1			;FUTURE CONTENTS OF KONTYP
	HLRE	T1,(T1)
	MOVEM	P1,PASCNT		;SAVE INDX FOR NOW
	JUMPL	T1,HDWC01		;SPECIAL CASE
	MOVEM	T1,KONTYP		;SETTUP
	HRRZ	P4,ADCNT		;SETUP
	ADD	P4,P1			;ADDR OF XXXXDV(BIT/TEXT TABLE)
	HRRZ	P4,(P4)
	AND	P2,KONMSK(T1)		;STRIP UNWANTED BITS
	LSH	P2,@MINERB(T1)		;MOVE IT OVER
	PUSHJ	P,JFLOOP		;GO DECODE
	TLNE	F,F.JFFO		;SEE ANY ERRORS?
	 JRST HDWC02			;YES
	TYPEIT	<NO ERROR BITS DETECTED>
HDWC02:	AOJ	P1,
	MOVEM	P1,PASCNT		;STORE NEW INDX
	PUSHJ	P,.TCRLF		;LOOKS BETTER THIS WAY
	JRST	HWDCON			;START ON NEXT LINE
					;HERE TO CALL SPECIAL BIT TRANSLATORS
HDWC01:	MOVE	T1,P2			;GET ERROR WORD FOR ROUTINE
	HRRZ	P3,ADCNT		;INDEX
	ADD	P3,P1			;SETUP ROUTINE ADDRESS
	HRRZ	P3,(P3)
	PUSHJ	P,(P3)			;GOTO THAT ROUTINE

;****CALLED ROUTINES MUST LEAVE P1 INTACT****
	PUSHJ	P,.TCRLF		;START NEXT LINE ON PAPER
	AOJ	P1,			;COME BACK HERE
	MOVEM	P1,PASCNT		;STORE NEW VALUE
	JRST	HWDCON			;DO IT OVER AGAIN

;SMALL DUMMY ROUTINE USED IF NO BIT TRANSLATION
;IS DESIRED--NOTRAN--

NOTRAN:	POPJ	P,0			;EASY HUH?


HDWXXX:	TYPEIT	<   >
	SETZ	T1,			;MAKE IT BLANK
	POPJ	P,0			;USED TO FILL BLANKS
LSTHO:	HRRZ	T1,OFFCNT		;OFFSET
	ADD	T1,P1			;CURRENT INDEX
	MOVS	P2,WKBUFF(T1)
	HLRZ	T1,P2
	skipn	t1			;anything there?
	PUSHJ	P,HDWXXX
	pushj	P,.TOCTW		;DUMP IT
	PUSHJ	P,.TTABC
	PUSHJ	P,.TTABC		;YET ANOTHER
	HRRZ	T1,P2			;GET ENDING WORD
	skipn	t1			;anything there?
	PUSHJ	P,HDWXXX
	PUSHJ	P,.TOCTW		;AT LEAST THIS IS A GOOD TEST
					;OF PUSHJ' & POPJ'S.
	PUSHJ	P,.TTABC		;KEEP ON TESTIN'
	PUSHJ	P,.TTABC
	HLRZ	T2,P2			;GET LH ALONE
	HRRZ	T1,P2			;RH ALONE
	XOR	T1,T2			;DIFFERENCE TO T1
	skipn	t1
	PUSHJ	P,HDWXXX
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC		;WHY STOP NOW
	PUSHJ	P,.TTABC
	POPJ	P,0			;THAT'S ALL FOLKS
LSTHB:	POPJ	P,0			;FOR NOW
LSTFO:	HLRZ	T1,OFFCNT		;ERROR WORD FIRST
	ADD	T1,P1
	MOVE	T1,WKBUFF(T1)
	MOVE	P4,T1
	PUSHJ	P,.TXWDW
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TTABC
	HRRZ	T1,OFFCNT		;END WORD NOW
	ADD	T1,P1
	MOVE	T1,WKBUFF(T1)
	MOVE	P3,T1
	PUSHJ	P,.TXWDW
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TTABC
	XOR	P3,P4
	MOVE	T1,P3
	PUSHJ	P,.TXWDW
	PUSHJ	P,.TTABC
	MOVE	P2,P4			;WORD TO TRANSLATE
	POPJ	P,0			;GO BACK

LSTFB:	PUSH	P,P1			;SAVE P1
	HLRZ	P2,OFFCNT		;ERROR WORD FIRST
	ADD	P2,P1
	MOVE	P1,WKBUFF(P2)
	MOVE	P4,P1
	PUSHJ	P,TYPBYT		;DUMPIT
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TTABC
	POP	P,P1			;GET INDEX BACK BUT
	PUSH	P,P1			;STILL SAVE IT
	HRRZ	P2,OFFCNT		;END WORD NOW
	SKIPN	P2			;[510] IF NO AT END WORDS
	 JRST	LSTFB0			;SKIP THAT CODE
	ADD	P2,P1	
	MOVE	P1,WKBUFF(P2)
	MOVE	P3,P1
	PUSHJ	P,TYPBYT
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TTABC
	XOR	P3,P4
	MOVE	P1,P3
	PUSHJ	P,TYPBYT
	PUSHJ	P,.TTABC
LSTFB0:	POP	P,P1			;RESTORE INDEX
	MOVE	P2,P4			;X-LATE ERROR WORD
	POPJ	P,0

LSTFX:	PUSH	P,P1			;#4 SAVE P1
	HLRZ	P2,OFFCNT		;#4 ERROR WORD FIRST
	ADD	P2,P1			;#4 .
	MOVE	P1,WKBUFF(P2)		;#4 .
	MOVE	P4,P1			;#4 .
	PUSHJ	P,TYPBYX		;#4 DUMPIT
	PUSHJ	P,.TSPAC		;#4 .
	PUSHJ	P,.TSPAC		;#4 .
	PUSHJ	P,.TTABC		;#4 .
	POP	P,P1			;#4 GET INDEX BACK BUT
	PUSH	P,P1			;#4 STILL SAVE IT
	HRRZ	P2,OFFCNT		;#4 END WORD NOW
	SKIPN	P2			;#4 [510] IF NO AT END WORDS
	 JRST	LSTFX0			;#4 SKIP THAT CODE
	ADD	P2,P1			;#4 .
	MOVE	P1,WKBUFF(P2)		;#4 .
	MOVE	P3,P1			;#4 .
	PUSHJ	P,TYPBYX		;#4 .
	PUSHJ	P,.TSPAC		;#4 .
	PUSHJ	P,.TSPAC		;#4 .
	PUSHJ	P,.TTABC		;#4 .
	XOR	P3,P4			;#4 .
	MOVE	P1,P3			;#4 .
	PUSHJ	P,TYPBYX		;#4 .
	PUSHJ	P,.TTABC		;#4 .
LSTFX0:	POP	P,P1			;#4 RESTORE INDEX
	MOVE	P2,P4			;#4 X-LATE ERROR WORD
	POPJ	P,0			;#4 .


TYPBYT:	LDB	T1,[POINT 8,P1,7]	;GET FIRST
	PUSHJ	P,.TOCTW		;IN OCTAL
	PUSHJ	P,.TSPAC		;SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,15]	;GET SECOND
	PUSHJ	P,.TOCTW		;IN OCTAL
	PUSHJ	P,.TSPAC		;SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,23]	;GET THIRD
	PUSHJ	P,.TOCTW		;IN OCTAL
	PUSHJ	P,.TSPAC		;SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,31]	;GET LAST
	PUSHJ	P,.TOCTW		;IN OCTAL
	POPJ	P,0			;GO BACK

TYPBYX:	LDB	T1,[POINT 8,P1,7]	;#4 GET FIRST
	PUSHJ	P,.THEXB		;#4 IN HEX
	PUSHJ	P,.TSPAC		;#4 SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,15]	;#4 GET SECOND
	PUSHJ	P,.THEXB		;#4 IN HEX
	PUSHJ	P,.TSPAC		;#4 SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,23]	;#4 GET THIRD
	PUSHJ	P,.THEXB		;#4 IN HEX
	PUSHJ	P,.TSPAC		;#4 SPACE IN BETWEEN
	LDB	T1,[POINT 8,P1,31]	;#4 GET LAST
	PUSHJ	P,.THEXB		;#4 IN hex
	POPJ	P,0			;#4 GO BACK

CHKLSH:	HRRZ	T1,OFFCNT		;STARTING OFFSET
	ADD	T1,P1			;CURRENT INDEX
	MOVE	T1,WKBUFF(T1)
	SKIPE	T1			;LIST IT?
	 AOS	0(P)
	POPJ	P,0			;YES

CHKLSF:	HLRZ	T1,OFFCNT		;ERROR WORD FIRST
	ADD	T1,P1			;CURRENT INDEX
	MOVE	T1,WKBUFF(T1)
	SKIPE	T1			;VALUE =0?
	 JRST	SKPRTN			;NO-LIST IT
	HRRZ	T1,OFFCNT		;YES-CHECK END WORD
	ADD	T1,P1			;CURRENT INDEX
	MOVE	T1,WKBUFF(T1)
	SKIPE	T1			;THIS ONE =0?
	 AOS	0(P)			;NO LIST
	POPJ	P,0			;GO BACK EITHER WAY

HWDC00:	AOS	P1			;JUST BUMPCOUNTER
	MOVEM	P1,PASCNT
	JRST	HWDCON			;AND TRY NEXT
;#1 B8HEX-- Routine to type a word as 4 8 bit hexadecimal bytes
;#1 P1/ address of descriptor to be output preceeding
;#1 P2/ data word to be output

.B8HEX::				;#1 output 8 bit bytes in hexadecimal
	MOVE T1,P1			;#1 descriptor
	PUSHJ P,.TSTRG			;#1 type it
	MOVE P1,P2			;#1 copy word
	PUSHJ P,TYPBYX			;#1 output octal bytes in std fashion
	POPJ P,0			;#1 return

.THEXB::				;#4 output 8bit number in T1 in hex
	SETZ T2,			;#4 clear ac for storage, shift
	LSHC T1,-4			;#4 isolate 1st 4 bits
	PUSHJ P,THEXB1			;#4 type digit
	SETZ T1,			;#4 clear receiving AC
	LSHC T1,4			;#4 get back 2nd 4 bits
;;	PJRST THEXB1			;#4 type 2nd digit
THEXB1:	MOVE T1,[EXP "0","1","2","3","4","5","6","7"
		 EXP "8","9","A","B","C","D","E","F"](T1) ;#4 make it ascii
	PJRST .TCHAR			;#4 output the character and return
;TYPBCD-- ROUTINE TO TYPE AN 8 CHAR. BCD NUMBER
;	LEFT JUSTIFIED IN P1

TYPBCD:	PUSH	P,P3			;SAVE IT
	TLZ	F,F.SAWD		;HAVENT SEEN ANY YET
	MOVE	T4,[POINT 4,P1,]	;BUILD BYTE POINTER
	MOVEI	P3,10			;OUR PASS COUNTER
TYPBC0:	SKIPG	P3			;=0?
	 JRST	TYPBC2			;YUP
	ILDB	T1,T4			;GET ONE
	SKIPN	T1			;=0?
	 JRST	TYPBC1			;YA CKECK SOME MORE
	TLO	F,F.SAWD
	PUSHJ	P,.TDECW		;TYPE IT IN DECIMAL
	PUSHJ	P,.TSPAC		;TYPE A SPACE TO FORMAT
	SOJA	P3,TYPBC0		;UPDATE COUNTER
TYPBC1:	TLNN	F,F.SAWD		;SEEN ANY YET?
	JRST	.+3			;NOT YET
	 PUSHJ	P,.TDECW		;YES LIST THIS ONE TOO
	PUSHJ	P,.TSPAC
	SOJA	P3,TYPBC0		;GO GET NEXT
TYPBC2:	POP	P,P3			;RETURN IT
	POPJ	P,0			;RETURN
;LSTEB -A ROUTINE TO LIST PDP11 DEVICE REGISTERS FROM BYTES PACKED
;IN THE ERROR FILE AS IN CODE 130 ENTRIES.
;P1  -# BYTES TO LIST,,ADDRESS TO FIRST
;P2  ADDR OF REG NAMES(SIXBIT),,ADDR OF CONTROL TABLE


LSTEB:	MOVE	P3,[POINT 16,(P1)]	;BUILD A POINTER
	HLRE	P4,P1			;AND A PASS COUNTER
	MOVEM	P4,PASCNT		;SAVE IT
	SETZ	P4,			;# WE'VE DONE
LSTEB1:	ILDB	T4,P3			;GET A WORD
;[307]	SKIPN	T4		;=0?
;[307]	 JRST	LSTEB2			;YES JUST GET NEXT WORD
	PUSH	P,T4			;SAVE THE WORD
	PUSHJ	P,.TTABC
	HLRZ	T2,P2			;ADDR OF REG NAMES
	ADD	T2,P4
	MOVE	T1,(T2)			;A SIXBIT NAME
	PUSHJ	P,.TSIXN
	PUSHJ	P,.TCOLN
	PUSHJ	P,.TTABC
	POP	P,T1			;GET THE WORD BACK
	PUSH	P,T1			;BUT SAVE IT STILL
	PUSHJ	P,.TOCTW		;DUMP IN OCTAL
	PUSHJ	P,.TTABC
	HRRZ	T1,P2			;GET CONTROL TABLE ADDR
	ADD	T1,P4
	MOVE	T2,(T1)			;THEN THE CONTENTS
	JUMPL	T2,LSTEB3		;SPECIAL XLATION?
	HLRM	T2,KONTYP		;OFFSET TO SETUP
	POP	P,T1			;WORD TO XLATE
	PUSHJ	P,SAVE4P		;SAVE P1-P4
	MOVE	P1,T1			;WHEREIT BELONGS
	TYPEIT	< = >
	PUSHJ	P,CNIDCD		;1 FOR 1 XLATION
	PUSHJ	P,RET4P			;GET P1-P4 BACK
	PUSHJ	P,.TCRLF		;NEXT LINE PLEASE


;NOW UPDATE COUNTERS,THEN START OVER

LSTEB2:	AOS	P4			;# WE'VE DONE
	HRLZI	T1,1B35			;SET BIT 17
	ADD	P1,T1			;+1 TO LH OF P1

;AOBJN WON'T WORK SINCE THERE ARE TWO BYTES PER WORD

	JUMPL	P1,LSTEB1		;START OVER?
	 POPJ	P,0			;NO-RETURN

;HERE DO SPECIAL XLATION
;T2 HAS CONTROL TABLE ENTRY AND WORD TO XLATE
;IS ON TOP OF PUSHDOWN STACK

LSTEB3:	POP	P,T1			;WORD TO T1
	PUSHJ	P,SAVE4P		;SAVE P1-P4
	PUSHJ	P,0(T2)			;TO SPECIAL ROUTINE
	PUSHJ	P,RET4P			;RESTORE P1-P4
	PUSHJ	P,.TCRLF		;NEXT LINE
	JRST	LSTEB2			;UPDATE AND START OVER
;JFLOOP -- SUBROUTINE TO DECODE BITS IN WORD AND GIVE ASCIZ EXPANSION
;SETUP	P2=WORD TO BE DECODED
;	P4=ADDRESS OF ASCIZ TEXT POINTER TABLE CORRESPONDING TO BITS
;CALL	PUSHJ	P,JFLOOP
;
;RETURN	CALL+1

JFLOOP:	TLZ	F,F.JFFO		;INITIALIZE ERROR FLAG
JFMORE:	JFFO	P2,JFFDCD		;LOOK FOR FIRST NON-ZERO BIT
	POPJ	P,			;ALL DONE
JFFDCD:	MOVE	T1,KONTYP		;PICKUP CONTROLLER TYPE
	MOVE	T1,ERINDX(T1)		;PICKUP ADDRESS OF BIT TO INDEX CONVERTER
	ADD	T1,P3			;SETUP TO ADDRESS OF BIT WE WANT
	MOVE	T2,(T1)			;GET CORRESPONDING INDEX BIT
	ADD	T2,P4			;ADD IN DEVICE OFFSET
	MOVE	T1,@T2			;PICKUP ADDRESS OF TEXT
	TLO	F,F.JFFO		;SAY WE SAY A TEXT-BIT
	PUSHJ	P,.TSTRG		;TYPEIT
JFCONT:	ROT	P2,(P3)			;BRING BIT TO SIGN POSITION
	TLZ	P2,400000		;CLEAR IT
	MOVNS	P3			;NEGATE TO ALLOW RIGHT SHIFT
	ROT	P2,(P3)			;RESTORE IT TO ORIGINAL POSIION
	JRST	JFMORE			;LOOP TILL ALL BITS DONE



;GENERAL ROUTINE TO DO "ONE-FOR-ONE" BIT TRANSLATION
; TO TEXT. SETUP P1 =WORD TO BE DECODED
;	KONTYP = CORRECT INDEX FOR THIS TYPE WORD

CNIDCD:	MOVE	T1,KONTYP		;GET CONTROLLER TYPE.
	AND	P1,KONMSK(T1)		;SAVE ONLY ERROR BITS.
	SKIPN	P1			;ANY BITS SET?
	 JRST	CNIDC1			;NO
	LSH	P1,@MINERB(T1)		;SHIFT LEFT UNTIL FIRST KNOWN
					;ERROR BIT IS IN SIGN BIT
	MOVE 	P4,DEVTYP##(T1)		;GET ADDRESS OF ASCIZ TEXT.
	MOVE	P2,P1			;SETUP WORD TO BE DECODED.
	PUSHJ	P,JFLOOP		;GO DO THE REAL WORK
	POPJ	P,0			;RETURN


CNIDC1:	TYPEIT	< NO ERROR BITS DETECTED>
	POPJ	P,0			;RETURN TO CALLER
;ADDED WITH EDIT 134
;XORTAB -- SMALL ROUTINE TO XOR TWO TABLES BEFORE
;CALLING BITLST,  SETUP P1=ADJUSTED POINTER TO 1 TABLE
;P2=ADJUSTED POINTER TO THE OTHER,  RETURNS
;ADJUSTED POINTER TO RESULTING TABLE IN P2.

XORTAB:	HLRZ	T1,P1
	HLRZ	T2,P2
	CAME	T1,T2			;EQUAL LENGTH?
	 WARN	<MEM. CONFIG. TABLES OF DIFFERENT LENGTH?>
	PUSH	P,P2			;SAVE ONE FOR LATER

XORTB1:	MOVE	T1,0(P1)		;GET ONE WORD
	XORM	T1,0(P2)		;OTHER ONE IS IN MEM
	AOBJN	P1,.+1			;ALWAYS TAKE NEXT INSTR.
	AOBJN	P2,XORTB1		;GET NEXT PAIR
	POP	P,P2			;DONE-GET A POINTER TO RETURN
	POPJ	P,0	
;ADDED WITH EDIT 134
;BITLST -- A SUBROUTINE TO LIST "FROM XXX"  "TO YYY"
;INFORMATION FROM A BIT TABLE LOOKING LIKE THE 
;MONITOR'S NXMTAB.
;CALLED WITH THE AOBJN POINTER IN P2 WITH PUSHJ
;RETURNS POPJ WHEN ALL DONE USES P1-P4,T1-T4
;ALSO SET KFLAG TO 0 IF EACH BIT IN TABLE =
;1 PAGE OF PHYSICAL CORE ELSE KFLAG=-1 MEANS K OF CORE.

BITLST:	SKIPL	P2			;[1237]IS THE PTR REALLY A PTR?
	POPJ	P,0			;[1237]NO RETURN NOW
	SETZM	WDCTR			;CLEAR AND 
	SETZM	ENDADR			;INITIALIZE
	SETZM	MEMCTR		

WORDLP:	SKIPN	T3,0(P2)		;GET A WORD AND IF 0
	JRST	ZEROWD			;HANDLE ALL 0
	TDC	T3,[-1]			;COMPLEMENT
	TDCN	T3, [-1]		;STILL 0?
	JRST	ONESWD			;HANDLE ALL 1'S

NXTBIT:	SKIPN	ENDADR
	JRST	NXTBT1
	MOVE	T1,[SIXBIT/  TO: /]
	TLNN	T3,1B18
	PUSHJ	P,PNTADR
	JRST	NXTBT2
NXTBT1:	MOVE	T1,[SIXBIT/FROM: /]
	TLNE	T3,1B18
	PUSHJ	P,PNTADR
NXTBT2:	TLNE	T3,1B18			;LEADING 0?
	TDC	T3,[-1]			;NO CONVERT
	JFFO	T3,.+2			;COUNT ZEROS
	 JRST	NEXTWD			;NO ONES GET ANOTHER
	MOVE	T2,WDCTR		;# COUNTED SO FAR IN THIS WORD
	ADD	T2,T4			;+ RESULT LAST JFFO
	CAIL	T2,^D36			;DONE ENOUGH?
	 JRST	NEXTWD			;YES-GET ANOTHER
	ADDM	T4,MEMCTR		;UPDATE # BITS SEEN IN TABLE SO FAR
	LSH	T3,0(T4)		;STRIP OF THOSE COUNTED
	MOVE	T1,[SIXBIT/FROM: /]	;ASSUME LOOKING FOR
					;CHANGE FROM 0 TO 1
	SKIPE	ENDADR			;0=LOOKING FOR CHANGE TO A 1 BIT
					;AND THEN WE PRINT "FROM: XXX"
	 MOVE	T1,[SIXBIT/  TO: /]
	PUSHJ	P,PNTADR		;WE SAW A CHANGE, GO LIST IT
	ADDM	T4,WDCTR		;UPDATE COUNT SEEN IN THIS WORD
	JRST	NXTBT2			;GO DO IT AGAIN

NEXTWD:	MOVN	T1,WDCTR
	ADDI	T1,^D36			;ADJUST
	ADDM	T1,MEMCTR		;UPDATE # BITS LOOKED AT
	SETZM	WDCTR			;CLEAR IT TO START ON NEXT WD
	AOBJN	P2,WORDLP		;ANY MORE WORDS?
	SKIPN	ENDADR			;ARE WE REALLY FINISHED?
	 POPJ	P,0			;THATS ALL
	MOVE	T1,[SIXBIT/  TO: /]	;SET FOR LAST LISTING
	PJRST	PNTADR			;AND LEAVE VIA THAT POPJ
	
ZEROWD:	MOVE	T1,[SIXBIT/  TO: /]	;SETUP
	SKIPE	ENDADR			;ARE WE LOOKING FOR A CHANGE?
	 PUSHJ	P,PNTADR		;YES, GO LIST IT
	JRST	NEXTWD			;GO DO ACCOUNTING A NEXT WORD

ONESWD:	MOVE	T1,[SIXBIT/FROM: /]	;SETUP
	SKIPN	ENDADR			;LOOKING FOR A CHANGEZ?
	 PUSHJ	P,PNTADR		;GO LIST
	JRST	NEXTWD			;ACCOUNTING & NEXT WORD.

PNTADR:	PUSH	P,T3			;SAVE SOME AC'S
	PUSH	P,T4
	PUSHJ	P,.TSIXN		;SIXBIT ALREADY IN T1
	TYPEIT	<  >
	MOVE	T1,MEMCTR		;GET # OF BITS COUNTED
	PUSHJ	P,.TDECW		;GO DUMP IT IN DECMIL
	MOVE	T1,[SIXBIT/ K /]
	SKIPN	KFLAG			;0= 1BIT = 1PAGE
	 MOVE	T1,[SIXBIT/ P /]
	PUSHJ	P,.TSIXN		;SAY EITHER
	SKIPE	ENDADR			;IF 0 START ANOTHER LINE
	 PUSHJ	P,.TCRLF
	SETCMM	ENDADR			;REVERSE THE FLAG
	POP	P,T4
	POP	P,T3
	POPJ	P,0			;GO BACK AND CHECK SOME MORE.
;TABLES

.DVTAB:					;#1 indexing these tables by absolute
					;#1  #s is terrible...
	PHASE 0				;#1 let's make some indices
	ASCIZ/RD10/			;CAUTION DEVICE NAME MUST BE 4 CHAR OR
	ASCIZ/RM10/			; LESS TO CORRECTLY INDEX INTO TABLE
	ASCIZ/RP02/			; (4 CHARACTERS AND NULL IN ONE WORD)
	ASCIZ/RP03/
	ASCIZ/RS04/
	ASCIZ/RP04/
	ASCIZ/RP05/
	ASCIZ/RP06/
	ASCIZ/RM03/			;  [601]
	ASCIZ/RP07/			;[1107]
	ASCIZ/RP20/			;[1333]
$$CC01::!ASCIZ/CC01/			;#1 3330 mod I
$$CC02::!ASCIZ/CC02/			;#1 3330 mod II
$$CT01::!ASCIZ/TUSA/			;#2 Magtape on SA-10

	DEPHASE				;#1 end of table


.MXBLK:	^D4000				;4000 BLOCKS PER RD10
	^D2700				;2700 BLOCKS PER RM10B
	^D40000				;40000 BLOCKS PER RP02
	^D80000				;80000 BLOCKS PER RP03
	^D2048				;2048 BLOCKS PER RS04
	^D156180			;154280 BLOCKS PER RP04
	^D156180			;154280 BLOCKS PER RP05
	^D309700			;FOR AN RP06
	^D121360			;BLOCKS/PACK RM03  (820 CLY/PACK)
	^D865504			;[1316][1107]BLKS/RP07
	^D201600			;[1333] BLKS/RP20
	^D156180			;#1 "sectors" on 3330 mod I
	^D309700			;#1 "sectors" on 3330 mod II

.TRBLK:	^D20				;20 BLOCKS/TRACK ON RD10
	^D30				;30 BLOCKS/TRACK ON RM10B
	^D200				;200 BLOCKS/CYLINDER ON RP02
	^D200				;200 BLOCKS/CYLINDER ON RP03
	^D32				;32 BLOCKS/TRACK ON RS04
	^D380				;380 BLOCKS/CYL RP04
	^D380				;380 BLOCKS/CYL RP05
	^D380				;380 BLOCKS/CYL RP06
	^D148				;BLOCKS/CYL RM03  (LAST 2 SECTORS LOST)
	^D1376				;[1316][1107]BLKS/CYL RP07
	^D180				;[1333] BLKS/CYL RP20
	^D380				;#1 "sectors"/cyl on 3330 mod I
	^D380				;#1 "sectors"/cyl on 3330 mod II

.SUBLK:	0				;RD10 BLOCKS/SURFACE
	0				;RM10B BLOCKS/SURFACE
	^D10				;RP02 BLOCKS/SURFACE
	^D10				;RP03 BLOCKS/SURFACE
	^D0				;RS04 BLOCKS/SURFACE
	^D20				;RP04 BLOCKS/SURFACE
	^D20				;RP05 BLOCKS/SURFACE
	^D20				;RP06 BLOCKS/SURFACE
	^D30				;BLOCKS / SURFACE FOR RM03
	^D43				;[1316][1107]BLKS/SURF RP07
	^D6				;[1333] BLKS/SURF RP20
	^D20				;#1 "sectors"/Surface on 3330 mod I
	^D20				;#1 "sectors"/Surface on 3330 mod II

.SECBK:	4				;4 SECTORS/BLOCK ON RD10
	2				;2 PHYSICAL SECTORS PER RM10B BLOCK
	1				;1 FOR RP02
	1				;AND RP03
	2				;2/BLOCK FOR RS04
	1				;1 PER FOR RP04
	1				;1 PER FOR RP05
	1				;1 PER FOR RP06
	1				;1 SECTOR / BLOCK FOR RM03
	1				;[1107]1 SEC/BLK RP07
	0				;[1333] RP20
	1B0+1B1+4		;#1 4 "sectors"/block, Rec 1 1st: 3330 mod I
	1B0+1B1+4		;#1 4 "sectors"/block, Rec 1 1st: 3330 mod II
Repeat 1,<Internal SN.LST	;#1 moved here from SYSERD
;DISPATCH TABLE OF DEVICE SERIAL NUMBER DECODING ROUTINES IN RH OF LIST
;THIS TABLE MUST BE KEPT IN LINE WITH THE UNIT TYPE TABLE IN THE UNIVERSAL
; FILE.  IN PARTICULAR THERE MUST BE AT LEAST ".UTMAX" ITEMS IN THE TABLE.

SN.LST:	[JRST ABORT]		;ILLEGAL DEVICE
	XWD	0,DSERCD	;RP04
	XWD	0,DSERCD	;RS04
	XWD	0,DSERCD	;TU45
	XWD	0,DSERCD	;TU16
	XWD	0,DSERCD	;RP05
	XWD	0,DSERCD	;RP06
	XWD	0,DSERCD	;RP07
	XWD	0,.ODECW	;RP08
	XWD	0,DSERCD	;RM03
	XWD	0,DSERCD	;TM03
	XWD	0,DSERCD	;TU77
	XWD	0,DSERCD	;TM78
	XWD	0,DSERCD	;TU78
	XWD	0,.ODECW	;DX20
	XWD	0,.ODECW	;TU70
	XWD	0,.ODECW	;TU71
	XWD	0,.ODECW	;TU72
	XWD	0,.ODECW	;TU73
	XWD	0,SD%100	;#3 23 interim device no.;#1 CC01
	XWD	0,SD%100	;#3 24 interim device no.;#1 CC02
	XWD	0,[JRST ABORT]	;#3 25 dummy
	XWD	0,[JRST ABORT]	;#3 26 dummy
	XWD	0,[JRST ABORT]	;#3 27 dummy
	XWD	0,.TOCTW	;#3 30 changing order ;#2 TUSA 
	XWD	0,SD%100	;#3 31 ;#1 CC01
	XWD	0,SD%100	;#3 32 ;#1 CC02

>				;#1 End of Repeat 1
;ROUTINE TO UPDATE RUNNING COUNT OF #WDS READ
;P1= # TO BE ADDED
;P3= BASE ADDR OF DEVICE COUNTER TABLES (MTA0HD ETC)

WDCNT:	TLNE	P1,400000		;[1256] IS THIS A NEGATIVE NUMBER
	POPJ	P,0			;[1256] YES, IGNORE AND LOOK FOR NEXT
	CAML	P1,[^D1M]		;LESS THAN 1 MILLION WORDS
	 JRST WDCNT1			;NO

WDCNT2:	ADDB	P1,10(P3)		;JUST ADD TO 2ND HALF
	CAMGE	P1,[^D1M]		;RESULT GT 1 MEG
	 POPJ	P,0			;NO ALL DONE
	IDIV	P1,[^D1M]		;YES ADJUST ANS
	ADDM	P1,7(P3)		;ADD NEW QUOTIENT
	MOVEM	P2,10(P3)		;RESTORE NEW PORTION OF A MILLION
	POPJ	P,0

WDCNT1:	IDIV	P1,[^D1M]		;
	ADDM	P1,7(P3)		;ADD QUOTIENT(#MILLION)
	MOVE	P1,P2			;MOVE REMAINDER
	JRST	WDCNT2			;GO CHECK,ADJUST,ANDEXIT
;COMPAR -- SUBROUTINE CALLED BY SUMMATION ROUTINES
;TO SEE IF COUNTER IS CHANGED SINCE LAST LOOK
;CALL	MOVEI	T1,XXXTMP	ADDRESS OF COUNT SINCE LAST RELOAD ENTRY
;	MOVEI	T2,XXXPER	ADDRESS OF COUNT SINCE START OF SUMMATION
;	MOVE	T3,CURRENT COUNT
;	PUSHJ	P,COMPAR
;
;RETURN	CALL+1



COMPAR:	TLZ	F,F.CHNG		;CLEAR CHANGE IN COUNT FLAG
	CAME	T3,@T1			;COUNT SAME AS OLD?
	SKIPN	T3			;COUNT =0
	POPJ	P,			;YES TO EITHER ABOVE
	TLO	F,F.CHNG		;SAY COUNT CHANGED SINCE LAST LOOK
	CAML	T3,@T1			;COUNT LESS THAN TEMP?
	JRST	CNTMOR			;NO-COUNT IS MORE THAN TEMP
	MOVE	T4,@T1			;RELOAD OCCURRED THEN ERROR
					;PICKUP TEMP
	ADDM	T4,@T2			;PERM =PERM+TEMP
	SETZM	@T1			;CLEAR TEMP
	ADDM	T3,@T1			;TEMP=CURRENT COUNT
	POPJ	P,
CNTMOR:	movem	t3,@t1			;edit #110
	POPJ	P,


SKPRTN:	AOS	0(P)			;ADD ONE
	POPJ	P,0			;AND USE IT


TYPNBS:	PUSHJ	P,.CNTDT
	PUSH	P,T1
	MOVE	T1,T2
	PUSHJ	P,.TDATE
	TYPEIT	< AT >
	POP	P,T1
	PUSHJ	P,.TTIME
	POPJ	P,0
	SUBTTL	I/O BUFFER CONTROL ROUTINES




;SUBROUTINE SKIPWD	ADVANCES BYTE POINTER MANUALLY TO SKIP WORDS
;CALL	PUSHJ	P,SKIPWD
;RETURN
;T1= # OF WORDS TO SKIP

SKIPWD:	CAMGE	T1,IBUFF+2		;ENOUGH WORDS IN BUFFER TO SKIP AND STAY IN THIS BUFFER?
	JRST	THISBF			;YES STAY HERE
	SUB	T1,IBUFF+2
	PUSH	P,T1			;EDIT 133 SAVE T1
	PUSHJ	P,ADVBFF		;NO- GO GET ANOTHER BUFFER
	POP	P,T1			;EDIT 133 GET IT BACK
	JRST	SKIPWD			;TRY AGAIN
THISBF:	ADDM	T1,IBUFF+1		;INCREMENT BYTE POINTER
	EXCH	T1,IBUFF+2		;UPDATE BYTE POINTER AND WORD COUNT
	SUBM	T1,IBUFF+2
RETRN:	POPJ	P,


;ADVBFF	SUBROUTINE TO READ ANOTHER BUFFER
;CALL	PUSHJ	P,ADVBFF
;RETURN
;**EDIT 107** ADDED CODE TO LOOK FOR ERROR.X01
;THRU ERROR.X77 IF ERROR OR EOF DURING READ. ALSO
;STORES NEW FILES CREATION TIME THEN STARTS TO 
;PROCESS IT BY GOING TO HEADRD

ADVBFF:	IN	INPCHN,
	PJRST	FIXBUF			;EDIT 115 GO HANDLE 1ST WORD

	STATZ	INPCHN,740000		;WHAT WENT WRONG?
	 PUSHJ	P,ADVBU1		;FILE ERROR COMPLAIN!!
	SKIPE	TOPMON			;IF UNDER TOPS-20
	 JRST	GOSUM			;NO EXTENDED FILE HANDLING
	HLRZ	T1,CUREXT		;WHAT FILE WAS THAT
	CAIN	T1,'SYS'		;FIRST?
	MOVEI	T1,'X00'		;CHANGE IT
	ADDI	T1,1			;+1
	TRNN	T1,7			;SIXBIT CARRY?
	ADDI	T1,100-10		;FIX IT
	HRLZM	T1,CUREXT		;PUT IT BACK
	CAILE	T1,'X77'		;THATS FAR ENOUGH
	 JRST	GOSUM			;DO SUMMARY AND QUIT  [724]
	TLNN	F,F.DISK		;THIS ONLY WORKS FOR DISKS
	 JRST	GOSUM			;SO DONT GO FURTHER  [724]
	HRLZM	T1,INPFIL+3		;STORE IT IN SPEC.
	LOOKUP	INPCHN,INPFIL		;TRY FOR IT
	 JRST	GOSUM			;NOT THERE WRAP UP  [724]
	SETZM	BLKCNT			;START RELATIVE BLOCK COUNTER OVER
	MOVE	T1,INPFIL+.RBTIM ;NEW CREATION DATE/TIME
	HLRZ	T2,CUREXT
	MOVE	T3,T2
	ANDI	T3,77
	SUBI	T3,20
	ANDI	T2,7700
	SUBI	T2,2000
	LSH	T2,-3
	ADD	T2,T3
	MOVEM	T2,CURIND		;CURRENT 01 OR 03 IN OCTAL(I HOPE)
	MOVEM	T1,FILDAT(T2)		;PUT FILDAT AWAY NOW
	PUSHJ	P,TITLST		;START A NEW PAGE
	PUSHJ	P,.TCRLF
	PUSHJ	P,.TCRLF		;SOME SPACE
	TYPEIT	<
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>
	TYPEIT	<

	NOW PROCESSING >
	MOVE	T1,INPFIL+2		;[1250] GET FILE NAME
	PUSHJ	P,.TSIXN		;[1250] TYPE IT
	TYPEIT	<.>			;[1250]
	HLLZ	T1,INPFIL+3		;[1250] GET FILE EXT
	PUSHJ	P,.TSIXN		;[1250] TYPE IT TOO
	TYPEIT	<

	CREATED:	>
	MOVE	T2,CURIND
	MOVE	T1,FILDAT(T2)		;GET DATE
	PUSHJ	P,TYPNBS		;LIST IT TOO
	TYPEIT	<

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>
	PUSHJ	P,FFPRNT		;NEXT PAGE PLEASE
	WARN	<SYRPNF: PROCESSING NEXT ERROR FILE!>
	JRST	HEADRD			;START PROCESSING

;HERE TO COMPLAIN ABOUT INPUT FILE ERROR

ADVBU1:	WARN	<SYRERI: FATAL ERROR READING INPUT FILE!>
	POPJ	P,0			;TRY FOR NEXT ERROR FILE


;FIXBUF - ROUTINE TO GET,CHECK AND STORE IF
;NEEDED THE FIRST WORD IN A BUFFER. USED FOR RE-SYNC TO
;A GOOD ENTRY IN ERROR FILE
;[410] REMOVED SPECIAL CASE TESTING FOR TOPS-20

FIXBUF:	MOVE	T1,IBUFF+1		;GET BYTE POINTER
	ILDB	T2,T1			;USE IT
	LDB	T1,[POINT 9,T2,8]
	CAIE	T1,ER.OFF		;VALID OFFSET WORD?
	 JRST	FIXBU1			;NO-DONT PLAY WITH BUFFER
FIXBU2:	MOVE	T1,IBUFF+2		;  FOLLOWING 4 LINES MOVED WITH EDIT  [1232]
	MOVEM	T1,BLKWDS		;# WDS IN THIS BLOCK
	MOVE	T1,IBUFF+1	
	MOVEM	T1,BLKPNT		;ILDB POINTER
	PUSHJ	P,GETWD			;NOW GET THAT WORD LEGALLY
					;THIS METHOD PREVENTS MESSING UP
					;GETWD'S POINTERS IF WE DONT WANT
					;THAT FIRST WORD. IE OLD FORMAT
					;ERROR FILES.
	MOVEM	MASTWD,BUFOFF		;NOW SAVE IT
	AOS	BLKCNT			;# BLOCKS SEEN SO FAR
	POPJ	P,0			;RETURN TO ADVBFF'S CALLER

FIXBU1:	SKIPE	TOPMON			;TOPS-20 RUNNING?
	 JRST	FIXBU2			;YES-ASSUME VERSION BEFORE RELEASE 2
	SETZM	BUFOFF			;NO, TROUBLE-MAKE SURE ITS CLEAR
	POPJ	P,0			;RETURN WITH GETWD'S POINTERS OK

;STBUFF-- ROUTINE TO START AGAIN AT NEXT BLOCK TO GET
;US BACK IN SYNC IN CASE OF ERROR OR IF NEXT ENTRY
;STARTS THERE. EDIT #115

STBUFF:	MOVE	P,PDLPNT		;RESET PUSH LIST, WE WILL GO TO HDREAD LATER
	AOS	FILCNT			;[223]COUNT OF ERRORS
	TRNE	F,F.TTY			;[1221]DOING OUTPUT TO TTY?
	TLOA	F,F.TTYO		;[1221]YES. SET FLAG TO SEND ALL TO TTY
	TLZ	F,F.TTYO		;ALL CHARS TO OUTPUT BUFFER
	PUSHJ	P,TITLST		;START ON A FRESH PAGE
	TYPEIT	<

******************************************************
INCONSISTENCY FOUND IN ERROR FILE
******************************************************
>
	TYPEIT	<

	LOGICAL BLOCK IN FILE:  	>
	MOVE	T1,BLKCNT		;GET CURRENT #
	PUSHJ	P,.ODECW		;IN DEC WITH A "."
	TYPEIT	<
	# OF WORDS IN BLOCK:		>
	MOVE	T1,BLKWDS
	PUSHJ	P,.ODECW
	TYPEIT	<
	RELATIVE WORD IN BLOCK:		>
	MOVE	T1,BLKWDS		;STARTING COUNT
	SUB 	T1,IBUFF+2		;CURRENT # LEFT
	PUSHJ	P,.ODECW
	TYPEIT	<

CONTENTS OF THIS BLOCK:

>
STBUFA:	MOVEI	P1,8			;8 WORDS PER LINE
STBUFB:	PUSHJ	P,SPACE3		;DO 3 SPACES
	MOVEI	P2,^D12			;12 CHARS PER WORD
	PUSHJ	P,INPWD			;GET NEXT WORD TO DUMP
	MOVE	T2,T1
STBUFC:	MOVEI	T1,0
	ROTC	T1,3			;3 BITS TO T1
	ADDI	T1,60			;CONVERT TO ASCII
	PUSHJ	P,.TCHAR		;OUTPUT
	SOJG	P2,STBUFC		;NEXT 3 BITS
	MOVE	P2,BLKWDS		;ANY MORE WORDS?
	CAIN	P2,1
	 JRST	STBUFD			;WE'RE DONE
	SOJG	P1,STBUFB		;FINISH THE LINE
	PUSHJ	P,.TCRLF		;NEXT LINE
	JRST	STBUFA			;START AGAIN
STBUFD:	SKIPE	KLEFL2			;IN PROCESS OF BUILDING KLEFIL?
	 PUSHJ	P,KLEDMP		;YES-DUMP IT IN OCTAL
	PUSHJ	P,TITLST
STBUFE:	PUSHJ	P,ADVBFF		;START AT NEXT BLOCK
	SKIPN	T1,BUFOFF		;OFFSET THERE?
	 JRST	STBUF1			;NO-OLD FILE FORMAT OR BAD MISTAKE?!
	HRRZ	T1,T1			;CLEAR LH
	CAIL	T1,200			;SKIP THIS BLOCK ENTIRELY?
	 JRST	STBUFE			;YES, ENTRY IS MORE THAN THIS BLOCK
	SUBI	T1,1			;ADJUST FOR 1ST WORD
	SKIPE	T1			;IF 0, DON'T
	PUSHJ	P,SKIPWD		;MOVE POINTERS
	WARN	<SYRRNB:  RESTARTING IN NEXT BLOCK OF ERROR FILE>
	JRST	HEADRD			;GO DO IT

STBUF1:	WARN	<SYRCNR:  CANNOT RE-SYNC, TRYING NEXT BLOCK>
	JRST STBUFF			;KEEP ADVANCING UNITL EITHER
					;EOF & THEN NEXT FILE OF EOF
					;AND THEN DO SUMMARY AND CLOSE NICELY.


SPACE3:	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	PUSHJ	P,.TSPAC
	POPJ	P,0

INPWD:	SOSGE	BLKWDS
	 JRST STBUFD			;FINISHED
	ILDB	T1,BLKPNT
	POPJ	P,0
;GOSUM--SUBROUTINE TO GET SETUP TO CALL OVRLAY
;TO GET SYSERS TO DO SUMMARY LISTINGS.
;ADDED BY EDIT 120

GOSUM:	TLNN	F,F.LSUM		;WANT SUMMARY ?  [724]
	 JRST	GOSTRT			;NO! - CLOSE AND EXIT
	TRNE	F,F.SEQ			;/SEQ ?  [724]
	 JRST	GOSTRT			;YES! - CLOSE AND EXIT
	TRNE	F,F.BRF			;/BRIEF ?  [724]
	 JRST	GOSTRT			;YES! - CLOSE AND EXIT
	TRNE	F,F.REM			;/REMOTE ?
	 JRST	GOSTRT			;YES! - NO SUMMARY  [417]
	MOVE	T1,[SIXBIT/SYSERS/] ;THE FILE NAME
	MOVEM	T1,OVRBLK+1		;INTO THE SPEC. AREA
	SETZ	15,
	MOVEM	17,SAVEAC+17
	MOVEI	17,SAVEAC
	BLT	17,SAVEAC+16		;THAT SAVES THE AC'S
	JRST	OVRLAY

;REPLACE THIS MODULE WITH SYSERS AND THEN
; PERFORM SUMMARY LISTING.

;GOSTRT[417] GO BACK TO SYSERR NOT SYSERS

GOSTRT:	CLOSE	INPCHN,
	CLOSE	OUTCHN,
	MOVE	T1,[SIXBIT/SYSERR/]
	MOVEM 	T1,OVRBLK+1
	SETZ	15,
	MOVE	11,OVRBLK
	MOVE	7,OVRBLK+4
	MOVEM	17,SAVEAC+17
	MOVEI	17,SAVEAC
	BLT	17,SAVEAC+16
	JRST	OVRLAY


;	SUBROUTINE	GETWD	RETURNS NEXT WORD IN INPUT BUFFER
;	SIMILAR IN NATURE TO GETCHR ROUTINE IN HANDBOOK
;	CALL	PUSHJ	P,GETWD
;	RETURNS WITH WORD IN MASTWD

GETWD:	SOSGE	IBUFF+2
	JRST	GETNXI
GETOK:	ILDB	MASTWD,IBUFF+1
	POPJ	P,

GETNXI:	PUSHJ	P,ADVBFF
	JRST	GETWD


;ROUTINE TO OUTPUT RAW WORDS TO DAT FILE FOR /REMOTE

PUTDAT::	SOSG	OBUFF+2		;ROOM LEFT THIS BLOCK?
	 JRST	PUTDA2			;NO-GET NEXT BLOCK
PUTDA1:	IDPB	T1,OBUFF+1
	POPJ	P,0
PUTDA2:	OUT	OUTCHN,			;WRITE THIS BLOCK
	JRST	PUTDA3			;INIT NEXT WITH POINTER OFFSET
	FATAL	<ERROR DURING BINARY OUTPUT>

PUTDA3:	PUSH	P,T1			;SAVEWORD TO OUTPUT
	HRLZI	T1,<ER.OFF>B26		;OFFSET ID CODE
	MOVE	T2,HEADWC		;WORDS LEFT IN HEADER OF THIS ENTRY
	CAIN	T2,3			;JUST STARTING AN ENTRY?
	 JRST	PUTDA5			;YES,OFFSET IS 1
	ADD	T2,ENTRWC		;+#WORDS LEFT THIS BODY
	ADDI	T2,2			;+1-WORD WE WERE CALLED TO WRITE AND +1
					;FOR HEADER WORD
	CAIL	T2,177			;MORE THAN ONE BLOCK?
	 MOVEI	T2,200			;YES,SAY NEXT BLOCK
	HRR	T1,T2			;FINISH OFFSET WORD
PUTDA4:	SOS	OBUFF+2
	IDPB	T1,OBUFF+1
	POP	P,T1			;WORD WE WERE CALLED TO WRITE
	JRST	PUTDA1			;WRITE IT AND RETURN

PUTDA5:	HRRI	T1,1			;THIS ENTRY STARTS WITH NEXT WORD
	JRST	PUTDA4			;CONTINUE
	SUBTTL	TELETYPE OUTPUT SUBROUTINES
;SUBROUTINES TO PUT VARIOUS SPECIAL CHARACTER IN OUTPUT BUFFER

FFPRNT:	SETZM	BRFDAT			;FORCE NEW DATE LINE IN BRIEF MODE
	MOVE	T1,[-PAGLIN]		;RESET PAGE LENGTH
	MOVEM	T1,LINCNT
	AOS	T1,PAGNUM		;INCREMENT PAGE NUMBER
	CAILE	T1,PAGLM		;(EDIT 101)**SPR #10-13,341 (RLD)**
	 JRST	PAGXCD			;**SPR #10-13,341 (RLD)**
	MOVEI	T1,14			;FORM FEED
	PUSHJ	P,CHROUT
	MOVEI	T1,15			;JUST A CARRIAGE RETURN - - SOME TIMES
	PUSHJ	P,CHROUT		;   WE DON'T GET ONE WITH A FORM FEED
	POPJ	P,

SLPRNT:	MOVEI	T1,"/"
	PUSHJ	P,CHROUT
	POPJ	P,

CLPRNT:	MOVEI	T1,":"
	PUSHJ	P,CHROUT
	POPJ	P,


TBPRNT:	MOVEI	T1,"	"		;HORIZ. TAB
	PUSHJ	P,CHROUT
	POPJ	P,

;START  EDIT [724] CHANGES

;CRCCMD - OUTPUTS CHARACTERS AND TRIES TO PLACE CARRIAGE RETURNS
; AT APPROPRIATE LOCATIONS - ALSO INDENTS OVERFLOW LINES
;
;CALLED BY	PUSHJ P,CRCCMD    WITH THE COMMAND IN 'T1'

CRCCMD:	CAIN	T1,CCF7			;DO IT NOW ?
	 POPJ	P,			;WAIT !
	PUSH	P,P1			;SAVE 'P1' - WE NEED IT !
	MOVEI	P1,OUTSIZ		;GET LENGTH OF OUTPUT BUFFER
	SUB	P1,OUTCNT		;FIND # OF CHARACTERS IN BUFFER
	JUMPE	P1,CRCEXT		;LEAVE IF NO CHARACTERS IN BUFFER
	MOVE	T2,[POINT 7,OUTBUF] ;POINT AT START OF BUFFER
	MOVEM	T2,OUTBYT
	CAIN	T1,CCF6			;CONTAINS FF's or CR's ?
	 JRST	CRCMD6			;YES!
	JUMPN	T1,CRCMDA		;CCF0 ?
	MOVNI	T2,BRFTAB		;YES! - GET LINE OVERFLOW INDENT
	ADD	T2,BRIEF		;FIND MAX # OF CHARACTERS ON LINE
	CAMLE	P1,T2			;WILL THE BUFFER FIT ON A FULL LINE?
	 JRST	CRCMD1			;NO! - WE'LL TRY CR's AT SPACES
CRCMDA:	CAMG	P1,CHRCNT		;WILL IT FIT ON THIS LINE?
	 PJRST	CRCMD0			;YES! - NO NEED TO LOOK FOR SPACES
	CAIN	T1,CCF1			;CCF1 ?
	 JRST	CRCMD1			;YES! - CHECK FOR SPACES
	PUSHJ	P,NWLINE		;NO! - START A NEW LINE
	JRST	CRCMD0			;LIST IT !

;CRCMD0 - ALLOW CR AT END OF BUFFER ONLY

CRCMD0:	ILDB	T1,OUTBYT		;GET CHARACTER
	SOS	CHRCNT			;COUNT CHARACTERS
	PUSHJ	P,OUTCHA
	SOJG	P1,CRCMD0		;DONE?
	JRST	CRCEND			;CLEAN UP & LEAVE

;CRCMD1 - ALLOW CR AT SPACES OR AT END OF BUFFER  [727]

CRCMD1:	MOVE	T2,OUTBYT		;GET BUFFER POINTER
	SETZ	T3,			;ZERO COUNTER

CRC1A:	ILDB	T1,T2			;GET CHARACTER
	CAIE	T1," "			;SPACE ?
	 JRST	CRC1B			;NO! - DON'T SAVE INFO
	MOVE	T4,T3			;SAVE # OF CHARACTERS BEFORE THIS SPACE
	MOVEM	P1,SPACNT		;SAVE # OF CHARACTERS LEFT IN BUFFER
CRC1B:	AOS	T3			;COUNT CHARACTER
	SOSL	CHRCNT			;LINE OVERFLOW ?
	SOJG	P1,CRC1A		;NO! - END OF BUFFER ?
					;YES! - SHOULD NEVER DO THIS!!!
	JUMPE	T4,CRC1E		;SKIP IF NO CHARACTERS
	MOVE	P1,T4			;GET CHARACTER COUNT
CRC1D:	ILDB	T1,OUTBYT		;GET CHARACTER
	PUSHJ	P,OUTCHA		;OUTPUT IT
	SOJG	P1,CRC1D		;DONE?
CRC1E:	MOVE	P1,SPACNT		;GET # OF CHARACTERS LEFT IN BUFFER BACK
	PUSHJ	P,NWLINE		;YES! - START A NEW LINE
	CAMG	P1,CHRCNT		;WILL IT FIT ON THIS LINE?
	 JRST	CRCMD0			;YES! - NO NEED TO LOOK FOR SPACES
	JRST	CRCMD1			;NO! - KEEP LOOKING FOR SPACES

;CRCMD2			NOT ASSIGNED
;CRCMD3			NOT ASSIGNED
;CRCMD4			NOT ASSIGNED
;CRCMD5			NOT ASSIGNED

;CRCMD6 - CR's or FF's in BUFFER  (DO AS IS!)

CRCMD6:	ILDB	T1,OUTBYT		;GET CHARACTER
	SOS	CHRCNT			;COUNT CHARACTERS
	CAIN	T1,12			;LINE FEED?
	 PUSHJ	P,NEWLIN		;ADJUST POINTERS
	CAIN	T1,14			;FORM FEED?
	 PUSHJ	P,NEWPAG		;ADJUST POINTERS
	PUSHJ	P,OUTCHA
	SOJG	P1,CRCMD6		;DONE?
	JRST	CRCEND			;CLEAN UP & LEAVE

CRCEND:	MOVE	T1,[POINT 7,OUTBUF] ;POINT AT START OF BUFFER
	MOVEM	T1,OUTBYT
	MOVEI	T1,OUTSIZ		;RESET BUFFER COUNTER
	MOVEM	T1,OUTCNT
CRCEXT:	POP	P,P1			;RESTORE 'P1'
	POPJ	P,			;RETURN

NEWLIN:	AOS	LINCNT			;INCREMENT LINE COUNT
NEWPAG:	MOVE	T3,BRIEF		;GET LINE WIDTH
	MOVEM	T3,CHRCNT		;RESET CHARACTER COUNT
	POPJ	P,			;RETURN

;STARTS A NEW LINE & DOES INDENT

NWLINE:	PUSH	P,P1			;SAVE 'P1' - WE NEED IT AGAIN !
	MOVEI	T1,15			;CARRIAGE RETURN
	PUSHJ	P,OUTCHA
	MOVEI	T1,12			;LINE FEED
	PUSHJ	P,OUTCHA
	PUSHJ	P,NEWLIN		;ADJUST POINTERS
	MOVEI	P1,BRFTAB		;GET INDENT VALUE
NWLIN2:	MOVEI	T1," "			;SPACE
	SOS	CHRCNT			;COUNT CHARACTERS
	PUSHJ	P,OUTCHA
	SOJG	P1,NWLIN2		;DO INDENT
	POP	P,P1			;RESTORE 'P1'
	POPJ	P,			;RETURN

;CHROUT -- SUBROUTINE CALLED BY SCAN TO OUTPUT CHARS TO TTY
;IF F.TTYO FLAG SET IN F OR TO PLACE IN OUTPUT BUFFER
;VIA PUTCHR

CHROUT:	TRNN	F,F.BRF			;/BRIEF ?
	 PJRST	OUTCHA			;NO! - OUTPUT CHARACTER NOW
	IDPB	T1,OUTBYT		;SAVE CHARACTER IN OUTPUT BUFFER
	SOSLE	OUTCNT			;BUFFER OVERFLOW ?
	POPJ	P,			;NO! - RETURN
	MOVEI	T1,CCF6			;YES! - DUMP IT NOW
	PJRST	CRCCMD			;	WITH NO CARRIAGE CONTROL

OUTCHA:	TLNN	F,F.TTYO		;OUTPUT TO TTY?
	 PJRST	PUTCHR			;NO! - PUT IN OUTPUT BUFFER AND RETURN
TTYOUT:	OUTCHR	T1			;YES! - DO OUTPUT
	POPJ	P,			;RETURN

;END EDIT [724] CHANGES

;SUBROUTINE PUTCHR
;CALL WITH CHAR TO BE PLACED IN OUTPUT BUFFER IN T1
;CODE AS IN HANDBOOK

PUTCHR:	TRNE	F,F.REM			;[1230]/REMOTE?
	POPJ	P,			;[1230]YES. NEVER GO TO BUFFER THIS WAY.
	SOSG	OBUFF+2
	JRST	PUTOUT
PUTCH:	IDPB	T1,OBUFF+1
	POPJ	P,
PUTOUT:	OUT	OUTCHN,
	JRST	PUTCH
	FATAL	<ERROR DURING OUTPUT>


;ROUTINE TO DUMP A SIXBIT WORD IN T2 ON USER'S TTY
;CALL= PUSHJ

TTYSIX:	MOVEI	T3,6			;PASS COUNT
	MOVE	T4,[POINT 6,T2]		;INIT BYTE PTR.
TTYSXC:	ILDB	T1,T4			;GET A CHAR
	ADDI	T1,40			;CONVERT
	PUSHJ	P,TTYOUT		;DUMP IT
	SOJG	T3,TTYSXC		;AND CONTINUE
	MOVEI	T1,40			;A SPACE
	PJRST	TTYOUT			;AND LEAVE
;START EDIT [521]

;BYTE.8 -- OUTPUTS A WORD IN 'T1' IN 8 BIT BYTES
;CALL:	MOVE	T1,WORD
;	PUSHJ	P,BYTE.8
;USES T1,T2,T3,T4,P1

;BYTE.X -- OUTPUTS A WORD IN 'T1' IN 'T2' BIT BYTES
;CALL:	MOVE	T1,WORD
;	MOVEI	T2,SIZE
;	PUSHJ	P,BYTE.X
;USES T1,T2,T3,T4,P1

BYTE.8::MOVEI	T2,^D8			;SET UP FOR 8 BIT BYTES
BYTE.X::MOVE	T3,[POINT 0,T2]		;GET BASE POINTER
	DPB	T2,[POINT 6,T3,11]	;COMPLETE POINTER
	MOVEI	T4,^D36
	IDIV	T4,T2			;CALCULATE # OF BYTES IN WORD
	MOVE	T2,T1			;SAVE WORD
BYTE.N:	SOJL	T4,BYTE.S		;DONE? - DO SHORT BYTE
	 ILDB	T1,T3			;NO! - GET NEXT BYTE
	PUSHJ	P,.TOCTW		;OUTPUT IN OCTAL
	PUSHJ	P,.TCOMA		;OUTPUT COMA
	JUMPA	0,BYTE.N		;NEXT BYTE

BYTE.S:	JUMPE	P1,BYTE.E		;ANY SHORT BYTE?
	 DPB	P1,[POINT 6,T3,11]	;YES! - RESET POINTER
	ILDB 	T1,T3			;GET SHORT BYTE
	PUSHJ	P,.TOCTW		;OUTPUT IN OCTAL
BYTE.E:	POPJ	P,0			;LEAVE

;END EDIT [521]
	SUBTTL	JSYS ERROR HANDLING ROUTINE

;EDIT [737]

JSYSER:	MOVEI	T1,"?"
	PBOUT
	ERCAL	JS.ERR
	MOVEI	T1,.PRIOU		;PRIMARY OUTPUT DEVICE IS THE DESTINATION
	MOVE	T2,[.FHSLF,,-1]		;CURRENT PROCESS,,LAST ERROR
	SETZ	T3,			;NO CHARACTER LIMIT
	ERSTR
	ERCAL	JS.ERR			;FAILURE, UNDEFINED ERROR NUMBER - CAN'T HAPPEN?
	PUSHJ	P,JS.ERR		;FAILURE, BAD DESTINATION or STRING TO BIG ??
	MOVEI	T1,15			;SUCCESS! - DO CARRIAGE RETURN
	PBOUT
	ERCAL	JS.ERR
	MOVEI	T1,12			;LINE FEED
	PBOUT
	ERCAL	JS.ERR
	POPJ	P,			;RETURN

JS.ERR:	FATAL	< ERROR IN JSYS ERROR RECOVERY
>
;ROUTINE TO LIST LP20 CONFIGURATION. MOVED HERE SO TOPS-XX CAN USE IT.
; EDIT [1311]

; LP CONFIGURATION [1311]
;
LP$CFG:	TYPEIT	<
	LPT'S ON LINE = >		;TYPE GENERAL MESSAGE
	POP	P,P1			;GET THE POINTER BACK
	LDB	P1,[POINT 16,(P1),31]	;GET THE NEXT WORD
	MOVEI	P2,LP.MAX		;MAXIMUM NUMBER OF LPT'S
	MOVE	P3,[SIXBIT /LPT/]	;DEVICE NAME
	JRST	FEDVTP			;GO DO IT

;ROUTINE TO LIST DH11 CONFIGURATION. EDIT [1311]


;LIST DH11 CONFIGURATION  EDIT [1311]

DH$CFG:	TYPEIT	<
	DH11'S ON LINE = >
	LDB	P1,[POINT 16,(P1),31]	;GET THE BIT MASK WORD
	MOVEI	P2,DH.MAX		;MAXIMUM NUMBER ALLOWED
	MOVE	P3,[SIXBIT /DH11 #/]	;DEVICE NAME
	JRST	FEDVTP			;LIST IT

;ROUTINE TO LIST CD11 CONFIGURATION. EDIT [1311]

;ROUTINE TO LIST CDR CONFIGURATION [1311]

CD$CFG:	TYPEIT	<
	CDR'S ON-LINE = >
	POP	P,T1			;GET THE POINTER BACK
	LDB	P1,[POINT 16,(T1),31]	;GET THE NEXT WORD
	MOVEI	P2,CD.MAX		;MAXIMUM NUMBER OF CDR'S
	MOVE	P3,[SIXBIT /CDR/]	;DEVICE NAME
	JRST	FEDVTP
;ROUTINE TO LIST DL11 CONFIGURATION. EDIT [1311]

;DL11 DEVICE REPORT
;CURRENTLY ONLY USED FOR CONFIGURATION REPORTS [1311]

FE$DL1:	TYPEIT	<
	STD. STATUS:	>
	MOVE	P1,WKBUFF+FE%OFF	;GET FULL OFFSET WORD
	ADDI	P1,WKBUFF		;POINT INTO WKBUFF
	LDB	T1,[POINT 16,(P1),15]	;GET DV.XXX
	PUSH	P,P1			;SAVE THE POINTER
	PUSH	P,T1			;SAVE THE WORD
	PUSHJ	P,.TOCTW		;TYPE THE STATUS
	TYPEIT	< = >
	POP	P,P1			;GET THE WORD BACK
	PUSH	P,P1			;NEEDED LATER
	MOVEI	T1,34			;MAGIC NUMBER
	MOVEM	T1,KONTYP		;SAVE IT FOR THE TYPE OUT ROUTINE
	PUSHJ	P,CNIDCD		;ONE FOR ONE XLATION
	POP	P,P1			;GET THE WORD BACK
	TRNE	P1,FE.CFG		;CONFIGURATION REPORT ?
	JRST	DL$CFG			;YES
	POP	P,T1			;CLEAN UP THE STACK
	POPJ	P,			;RETURN

;ROUTINE TO LIST DL11 CONFIGURATION

DL$CFG:	TYPEIT	<
	DL11'S ON-LINE = >
	POP	P,T1			;GET THE POINTER BACK
	LDB	P1,[POINT 16,(T1),31]	;GET THE BIT MASK WORD
	MOVEI	P2,DL.MAX		;MAX # OF DL11'S
	MOVE	P3,[SIXBIT /DL11 #/]	;DEVICE NAME
	JRST	FEDVTP

;SUBROUTINE TO TYPE FRONT-END DEVICES. USED BY FRONT-END CONFIGURATION
;REPORTER IN SYSERC.
;EDIT [1311]
;
;CALL WITH:	P1 = BIT MASK WORD CONTAINING ON LINE DEVICES
;		P2 = MAXIMUM # OF DEVICES ALLOWED ON LINE
;		P3 = SIXBIT DEVICE NAME, E.G. LPT, DH11, CDR...
;DESTROYS P4

FEDVTP:	SETZ	P4,			;NEEDED FOR DEVICE LOOP
	SETZ	T1,			;TO LET US KNOW IF ANY WERE REPORTED
FEDLOP:	TRNN	P1,1B35			;IS THERE A DEVICE THERE ?
	JRST	FEDLP2			;NO, LOOK FOR ANOTHER
	MOVE	T1,P3			;GET THE DEVICE NAME
	PUSHJ	P,.TSIXN		;TYPE IT OUT
	MOVE	T1,P4			;GET THE DEVICES LOGICAL NUMBER
	PUSHJ	P,.TOCTW		;PRINT IT
	TYPEIT	<, >			;SEPERATE THEM
FEDLP2:	LSH	P1,-1			;SHIFT THEM DOWN BY ONE BIT
	AOS	P4			;UP THE LOGICAL DEVICE NUMBER
	SOJG	P2,FEDLOP		;LOOP IF MORE...
	SKIPE	T1			;ANYTHING REPORTED ?
	POPJ	P,			;ELSE, RETURN
	TYPEIT	<NONE>
	POPJ	P,
;ROUTINE TO REPORT DATA LINE SCANNER ERRORS. THE FOLLOWING DEVICES ARE
;REPORTED UNDER DATA LINE SCANNER DEVICE CODE:
;	DH11
;	DM11
;	DL11
;
; EDIT [1311]

FE$DLS:	TYPEIT	<
	STD. STATUS:	>		;GENERAL MESSAGE
	MOVE	P1,WKBUFF+FE%OFF	;GET THE OFFSET
	ADDI	P1,WKBUFF		;
	LDB	T1,[POINT 16,(P1),15]	;GET THE STATUS WORD
	PUSH	P,P1			;SAVE THE POINTER
	PUSH	P,T1			;AND THE WORD
	PUSHJ	P,.TOCTW		;PRINT THE STATUS IN OCTAL
	TYPEIT	< = >			;
	POP	P,P1			;GET WORD BACK IN P1
	MOVEI	T2,34			;SYSERC STD.STATUS
	MOVE	T1,[SIXBIT/SYSERC/]	;A S S U M E
	CAME	T1,OVRBLK+1		;THIS IS WHO IS RUNNING
	MOVEI	T2,36			;SYSERD STD.STATUS
	MOVEM	T2,KONTYP
	PUSHJ	P,CNIDCD		;ONE FOR ONE XLATION
	POP	P,P1			;POINTER IN P1
	LDB	T1,[POINT 16,(P1),31]	;GET THE DEVICE UNIBUS ADDRESS
	CAIGE	T1,DH%ADR		;IS IT A DH11 ?
	JRST	DLSUNK			;NOT KNOWN TO SYSERR
	CAIGE	T1,DM%ADR		;DM11 ?
	JRST	FE$DH2			;NO, MUST BE DH11
	CAIGE	T1,DL%ADR		;DL11 ?
	JRST	FE$DM1			;MUST BE DM11
	CAIG	T1,CT%ADR		;CTY ADDRESS ?
	JRST	FE$DLE			;DL11
DLSUNK:	TYPEIT	<
%DATA LINE SCANNER DEVICE NOT KNOWN TO SYSERR
	UNIBUS ADDRESS:	>
	LDB	T1,[DH.ADR(P1)]		;GET THE ADDRESS OF THE DEVICE
	PUSHJ	P,.TOCTW		;TYPE IN OCTAL
	TYPEIT	<
	DEVICE CSR:	>		;TYPE THE CONTROL/STATUS REGISTER
	LDB	T1,[POINT 16,1(P1),15]	;GET IT
	PUSHJ	P,.TOCTW		;TYPE IT
	TYPEIT	<
	OPTIONAL REG.:	>		;OPTIONAL REGISTER IF ANY
	LDB	T1,[POINT 16,1(P1),31]	;GET IT
	JRST	.TOCTW			;TYPE AND EXIT
;ROUTINE TO LIST DH11 ERRORS [1311]
FE$DH2:	TYPEIT	<
	DH11 UNIBUS ADDRESS:	>
	LDB	T1,[DH.ADR(P1)]		;GET ADDRESS WORD
	PUSHJ	P,.TOCTW		;DUMP IN OCTAL
	TYPEIT	< = DH11 #>
	LDB	T1,[DH.RHN(P1)]		;GET DH11 #+1
	SOS	T1			;MAKE IT REAL DH11 #
	PUSHJ	P,.TOCTW		;DUMP IN OCTAL
	LDB	P2,[DH.SCR(P1)]		;GET SYSTEM CONTROL REGISTER
	TYPEIT	<
	SYSTEM CONTROL REG:	>
	MOVE	T1,P2
	PUSH	P,P1			;SAVE A POINTER
	PUSH	P,T1			;SAVE THE WORD
	PUSHJ	P,.TOCTW
	TYPEIT	< = >
	POP	P,P1			;GET THE WORD BACK
	MOVEI	T2,44			;SYSERC DH11 SCR
	MOVE	T1,[SIXBIT/SYSERC/]	;LET'S SEE WHO IS RUNNING
	CAME	T1,OVRBLK+1		;WHERE ITS KEPT
	MOVEI	T2,57			;SYSERD DH11 SCR
	MOVEM	T2,KONTYP
	PUSHJ	P,CNIDCD		;1 FOR ONE XLATION
	TYPEIT	<  LINE #>
	POP	P,P1			;GET THE POINTER
	LDB	T1,[DH.LIN(P1)]		;GET LINE NUMBER
	PUSHJ	P,.TOCTW
	LDB	P2,[DH.NRC(P1)]		;GET RECEIVED CHARACTER REGISTER
	SKIPN	P2			; & QUIT IF 0
	POPJ	P,0
	TYPEIT	<
	RECEIVED CHAR REG:	>
	MOVE	T1,P2
	PUSH	P,P1			;SAVE A POINTER
	PUSH	P,T1			;SAVE THE WORD
	PUSHJ	P,.TOCTW
	TYPEIT	< = >
	POP	P,P1			;GET THE WORD BACK
	MOVEI	T2,45			;SYSERC REC. CHAR. REG.
	MOVE	T1,[SIXBIT/SYSERC/]	;WHO MITE BE RUNNING
	CAME	T1,OVRBLK+1		;IS IT  C
	MOVEI	T2,60			;NO, ITS D
	MOVEM	T2,KONTYP
	PUSHJ	P,CNIDCD		;1 FOR ONE XLATION
	TYPEIT	<  LINE #>		;[1247]
	POP	P,P1			;GET THE POINTER
	LDB	T1,[DH.NLN(P1)]		;GET NEXT LINE NUMBER
	PUSHJ	P,.TOCTW
	TYPEIT	<,CHAR=>		;[1247]
	LDB	T1,[DH.NCH(P1)]		;GET NEXT CHARACTER
	PJRST	.TOCTW			;THAT'S ALL TO LIST
;ROUTINE TO LIST DL11 ERRORS [1311]

FE$DLE:	TYPEIT	<
	DL11 UNIBUS ADDRESS:	>
	LDB	T1,[POINT 16,(P1),31]	;GET THE ADDRESS
	PUSHJ	P,.TOCTW		;TYPE IT
	TYPEIT	<
	RECEIVER CSR:		>
	LDB	T1,[POINT 16,1(P1),15]	;GET THE RCSR
	PUSHJ	P,.TOCTW		;TYPE IT
	TYPEIT	<
	TRANSMITTER CSR:	>	;
	LDB	T1,[POINT 16,1(P1),31]	;GET THE TRANSMITTER CSR
	JRST	.TOCTW			;TYPE AND EXIT

;ROUTINE TO LIST DM11 ERRORS [1311]
;START [1321]

FE$DM1:	TYPEIT	<
	STD. STATUS:	>		;GENERAL MESSAGE
	MOVE	P1,WKBUFF+FE%OFF	;GET THE OFFSET
	ADDI	P1,WKBUFF		;
	LDB	T1,[POINT 16,(P1),15]	;GET THE STATUS WORD
	PUSH	P,P1			;SAVE THE POINTER
	PUSH	P,T1			;AND THE WORD
	PUSHJ	P,.TOCTW		;PRINT THE STATUS IN OCTAL
	TYPEIT	< = >			;
	POP	P,P1			;GET WORD BACK IN P1
	PUSH	P,P1			;SAVE IT AGAIN
	MOVEI	T2,34			;SYSERC STD.STATUS
	MOVE	T1,[SIXBIT/SYSERC/]	;A S S U M E
	CAME	T1,OVRBLK+1		;THIS IS WHO IS RUNNING
	MOVEI	T2,36			;SYSERD STD.STATUS
	MOVEM	T2,KONTYP
	PUSHJ	P,CNIDCD		;ONE FOR ONE XLATION

;
; CHECK FOR CONFIGURATION BIT
;
	POP	P,T1			;GET THE WORD BACK
	TRNE	T1,FE.CFG		;CONFIGURATION REPORT ?
	JRST	DM$CFG			;YES
;END [1321]

	POP	P,T1			;GET EXTRA OFF STACK [1356]
	TYPEIT	<
	DM11 UNIBUS ADDRESS:	>
	LDB	T1,[POINT 16,(P1),31]	;GET THE ADDRESS OF THE DEVICE
	PUSHJ	P,.TOCTW		;TYPE THE ADDRESS
	TYPEIT	< = DM11 #>
	LDB	T1,[POINT 3,(P1),28]	;GET THE DEVICE NUMBER
	PUSHJ	P,.TOCTW		;TYPE IT
	TYPEIT	<
	DM11 CONTROL/STATUS:	>
	LDB	T1,[DH.SCR(P1)]		;GET THE CONTROLL REGISTER
	JRST	.TOCTW			;TYPE AND EXIT

;START [1321]
DM$CFG:	TYPEIT	<
	DM11BB'S ON-LINE = >
	POP	P,T1			;GET IT BACK
	LDB	P1,[POINT 16,(T1),31]	;GET BIT MASK WORD
	MOVEI	P2,DM.MAX		;MAX # OF DM11BB'S
	MOVE	P3,[SIXBIT /DM11 #/]	;DEVICE NAME
	JRST	FEDVTP			;TYPE THEM OUT
;END [1321]
; ROUTINE TO LIST DEX/EBUS ERRORS  [1311]

FE$DTE:	TYPEIT	<
	STD. STATUS:	>		;STANDARD
	MOVE	P1,WKBUFF+FE%OFF	;GET THE BUFFER
	ADDI	P1,WKBUFF		;CORRECT
	LDB	T1,[POINT 16,(P1),15]	;GET THE STATUS
	PUSH	P,P1
	PUSH	P,T1			;SAVE POINTER AND WORD
	PUSHJ	P,.TOCTW		;TYPE THE STATUS
	MOVEI	T1,34			;ASSUME SYSERC IS RUNNING
	MOVE	T2,OVRBLK+1		;SEE WHO IS
	CAME	T2,[SIXBIT/SYSERC/]	;C ?
	MOVEI	T1,36			;NO, SYSERD IS RUNNING
	MOVEM	T1,KONTYP		;SAVE IT
	TYPEIT	< = >
	POP	P,P1			;GET HTE WORD BACK
	PUSHJ	P,CNIDCD		;XLATE IT
	POP	P,P1			;GET POINTER BACK
	LDB	T1,[DV.EBS(P1)]		;CHECK FOR EBUS PARITY ERROR
	CAIE	T1,377			;377 = 8 BIT -1
	CAIE	T1,1			;1 = NOERROR
	JRST	EBSERR
	LDB	T1,[DV.DEX(P1)]		;CHECK FOR DEX FAILURE
	CAIE	T1,377			;-1 FOR RETRY FAILED
	CAIE	T1,1			;NO ERRORS ?
	JRST	DEXERR
	TYPEIT	<
%NO ERRORS REPORTED!!>
	POPJ	P,
;ROUTINE TO HANDLE EBUS ERRORS [1311]

EBSERR:	PUSH	P,T1
	TYPEIT	<
	EBUS PARITY ERROR - >
	POP	P,T2			;SAVE T1
	MOVEI	T1,[ASCIZ/RETRY SUCCESSFUL/]
	SKIPE	T2			;SKIP IF TRUE
	MOVEI	T1,[ASCIZ/RETRY FAILED/]
	PUSHJ	P,.TSTRG		;PRINT THE MESSAGE
	PUSHJ	P,DTEREG		;DO COMMON STUFF
	PUSHJ	P,DTERG1		;SECOND PIECE[1320]
	POPJ	P,0

;ROUTINE TO HANDLE DEX FAILURES

DEXERR:	TYPEIT	<
	PI 0 INTERRUPT FAILURE (AKA DEX ERROR) ->
;[1320]	MOVE	T2,T1			;SAVE T1
;[1320]	MOVEI	T1,[ASCIZ/RETRY SUCCESSFUL/]
;[1320]	SKIPE	T2			;IS IT TRUE ?
;[1320]	MOVEI	T1,[ASCIZ/RETRY FAILED/]
;[1320]	PUSHJ	P,.TSTRG		;TYPE IT
	PUSHJ	P,.TCRLF
	PJRST	DTEREG			;GO TO CAOMMON CODE
;ROUTINE TO TYPE DTE REGISTERS [1311]
;AS YOU CAN SEE, THIS ISN'T COMMENTED VERY WELL. WHAT IT DOES IS GET THE
;DTE REGISTERS IN ORDER , TYPE IT IN OCTAL. THERE ARE TWO SETS OF DTE
;REGISTERS, ONE IS AT ERROR, AND THE OTHER IS FROM RETRY.


DTEREG:	TYPEIT	<
	DTE REGISTERS FROM ERROR:

		DLYCNT:	>
	LDB	T1,[DTE101(P1)]		;GET DELAY COUNT
	PUSHJ	P,.TOCTW		;TYPE IN OCTAL
	TYPEIT	<
		DEXWD3:	>		;ADDRESS WORD 3
	LDB	T1,[DTE102(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DEXWD2:	>
	LDB	T1,[DTE103(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DEXWD1:	>
	LDB	T1,[DTE104(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TENAD1:	>
	LDB	T1,[DTE105(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TENAD2:	>
	LDB	T1,[DTE106(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10BC:	>
	LDB	T1,[DTE107(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11BC:	>
	LDB	T1,[DTE108(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10AD:	>
	LDB	T1,[DTE109(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11AD:	>
	LDB	T1,[DTE110(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10DT:	>
	LDB	T1,[DTE111(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11DT:	>
	LDB	T1,[DTE112(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG1:	>
	LDB	T1,[DTE113(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG2:	>
	LDB	T1,[DTE114(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		STATUS:	>
	LDB	T1,[DTE115(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG3:	>
	LDB	T1,[DTE116(P1)]
	PUSHJ	P,.TOCTW
	POPJ	P,0			;RETRIES AREN'T DONE SO...

;	;****
DTERG1:	TYPEIT	<

	DTE REGISTERS FROM RETRY:

		DLYCNT:	>
	LDB	T1,[DTE201(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DEXWD3:	>
	LDB	T1,[DTE202(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DEXWD2:	>
	LDB	T1,[DTE203(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DEXWD1:	>
	LDB	T1,[DTE204(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TENAD1:	>
	LDB	T1,[DTE205(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TENAD2:	>
	LDB	T1,[DTE206(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10BC:	>
	LDB	T1,[DTE207(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11BC:	>
	LDB	T1,[DTE208(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10AD:	>
	LDB	T1,[DTE209(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11AD:	>
	LDB	T1,[DTE210(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		TO10DT:	>
	LDB	T1,[DTE211(P1)]
	PUSHJ	P,.TOCTW
	PUSHJ	P,.TTABC
	TYPEIT	<TO11DT:	>
	LDB	T1,[DTE212(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG1:	>
	LDB	T1,[DTE213(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG2:	>
	LDB	T1,[DTE214(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		STATUS:	>
	LDB	T1,[DTE215(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		DIAG3:	>
	LDB	T1,[DTE216(P1)]
	JRST	.TOCTW
;RH11 ERROR REPORTING ROUTINE [1311]
;HERE IN SYRLIB SO TOPS-XX CAN USE IT.

FE$RJP:	TYPEIT	<
	STD. STATUS:	>
	MOVE	P1,WKBUFF+FE%OFF	;GET FRONT END OFFSET
	ADDI	P1,WKBUFF		;CORRECT
	LDB	T1,[STD.ST(P1)]		;GET STANDARD STATUS
	PUSH	P,P1			;SAVE THE POINTER
	PUSH	P,T1			;SAVE THE WORD
	PUSHJ	P,.TOCTW		;TYPE THE STATUS IN OCTAL
	MOVEI	T1,34			;ASSUME SYSERC STD. STATUS
	MOVE	T2,OVRBLK+1		;SEE WHO IS RUNNING
	CAME	T2,[SIXBIT/SYSERC/]	;IS IT SYSERC ?
	MOVEI	T1,36			;NO, MUST BE SYSERD
	MOVEM	T1,KONTYP		;SAVE STD. STATUS MAGIC NUMBER
	POP	P,P1			;GET THE WORD BACK IN P1
	TYPEIT	< = >
	PUSHJ	P,CNIDCD		;XLATE IT
	POP	P,P1			;GET THE POINTER BACK
	TYPEIT	<
	RH11 UNIBUS ADDRESS: >
	LDB	T1,[RH.ADR(P1)]		;GET THE UNIBUS ADDRESS IN T1
	PUSHJ	P,.TOCTW		;TYPE IT IN OCTAL
	TYPEIT	<

	RH11 REGISTERS AT ERROR:

		RJCS1:	>
	LDB	T1,[RJCS1(P1)]		;GET STATUS REG. 1
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPWC:	>
	LDB	T1,[RPWC(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPBA:	>
	LDB	T1,[RPBA(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPDA:	>
	LDB	T1,[RPDA(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPCS2:	>
	LDB	T1,[RPCS2(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPDS:	>
	LDB	T1,[RPDS(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPER1:	>
	LDB	T1,[RPER1(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPAS:	>
	LDB	T1,[RPAS(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPLA:	>
	LDB	T1,[RPLA(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPDB:	>
	LDB	T1,[RPDBB(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPMR:	>
	LDB	T1,[RPMR(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPDT:	>
	LDB	T1,[RPDT(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPSN:	>
	LDB	T1,[RPSN(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPOF:	>
	LDB	T1,[RPOF(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPDC:	>
	LDB	T1,[RPDC(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPCC:	>
	LDB	T1,[RPCC(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPER2:	>
	LDB	T1,[RPER2(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPER3:	>
	LDB	T1,[RPER3(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPEC1:	>
	LDB	T1,[RPEC1(P1)]
	PUSHJ	P,.TOCTW
	TYPEIT	<
		RPEC2:	>
	LDB	T1,[RPEC2(P1)]
	JRST	.TOCTW
;BEGIN [1341]
; A LITTLE ROUTINE STOLEN FROM SCAN SO WE CAN DO HEX CONVERSION
; CORRECTLY WITHOUT HAVING TO RELY ON THE LATEST VERSION OF SCAN
; ON EVERY SYSTEM IN THE FIELD.
.TRDXW:	JUMPGE	T1,TRDXW1		;CHECK FOR NEGATIVE
	MOVE	T2,T1			;SAVE AWAY ARGUMENT
	MOVEI	T1,"-"			;YES--GET MINUS
	PUSHJ	P,.TCHAR		;PRINT IT
	MOVE	T1,T2			;RESTORE NUMBER
TRDXW1:	IDIV	T1,T3			;DIVIDE BY RADIX
	MOVMS	T2			;GET MAGNITUDE
	HRLM	T2,(P)			;SAVE REMAINDER
	SKIPE	T1			;SEE IF ANYTHING LEFT
	PUSHJ	P,TRDXW1		;YES--LOOP BACK WITH PD LIST
	HLRZ	T1,(P)			;GET BACK A DIGIT
	ADDI	T1,"0"			;CONVERT TO ASCII
	CAILE	T1,"9"			;SEE IF OVERFLOW DIGITS
	ADDI	T1,"A"-"9"-1		;YES--SWITCH TO ALPHABETICS
	PJRST	.TCHAR			;TYPE IT AND RETURN
;END [1341]

LIBLIT:	[ENDLIB: -1]			;GIVES ADDRESS TO ALL LITERALS WHEN USING DDT

	END