Google
 

Trailing-Edge - PDP-10 Archives - AP-D543V_SB - oncmod.mac
There are 15 other files named oncmod.mac in the archive. Click here to see a list.
TITLE	ONCMOD  LEVEL D OPTIONAL & MANDATORY ONCE ONLY CODE V6725
SUBTTL	C. WHITE/DJB/RCC/EVS	  10 OCT 78
	SEARCH	F,S
	$RELOC
	$LOW



;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1973,1974,1975,1976,1977,1978 BY DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
XP VONCMD,6725
;SPECIAL SHORT DIALOG OPTIONS BY ERNIE SOCCI

ENTRY ONCMOD

ONCMOD::
MXSADA==^D118
;THIS IS THE CODE FOR THE SHORT DIALOG....

;ROUTINE FOR SYSTEM START UP (DESTROY OPTION)

SHRTST::MOVEI	T1,[ASCIZ/%WARNING-ALL STRS WILL BE REFRESHED.
PROCEED?(Y OR <CR>)/]
	JSP	T2,SVOTAC
	PUSHJ	P,YESNO##	;GET ANSWER
	JRST	ALTM1		;GO BACK TO BEGINNING.(NO).
	SETOM	BATMAN
	SETOM	SHUTUP
	SETOM	KON		;SET STARTUP FLAGS
	PUSHJ	P,REDHOM	;DO WONDDEFUL THINGS
	JFCL			;IGNORE ERRORS
	SETZM	KON		;AND RESET KONTROLLER CHECK FLAG.
	JSP	T2,SVOTAC	;SAVE AC'S
	PUSHJ	P,DMKSTR	;SET UP STRS
	JSP	T2,SVOTAC	;SAVE P4,J,F,AND U AGAIN
	PUSHJ	P,DMKUNI	;SET UP UNIT DEFAULTS
	PUSHJ	P,DEFASL	;AND ACTIVE SWAPPING LIST
	PUSHJ	P,DEFSSL	;AND SYS SEARCH LIST
	PUSHJ	P,WRTHOM	;WRITE OUT HOM BLOCKS, THEN READ
				;THEM IN AGAIN&SET UP DATA BASE
	MOVEI	T1,[ASCIZ /START SYSTEM? (Y OR <CR>)/]
	PUSHJ	P,YESNO##
	JRST	ALTM1	;NO-ASK LONG DIALOG QUEST AGAIN
	MOVE	F,DATADR	;SET UP FILE DATA BLOCK ADR
	HLRZ	P2,SYSSTR##	;GET ADDR. OF 1ST SDB
	SKIPE	P2
	PUSHJ	P,RFRES2	;REFRESH ALL STRS
	POP	P,(P)		;FIX UP PD LIST
	PJRST	PVQCK##		;AND GO THROUGH QUICK STUFF

NOSTART:;ROUTINE FOR REFRESH ONLY (REFRESH)

SHRTRF::PUSHJ	P,READ		;GO READ HOME & BAT BLOCKS
	PJRST	RFRESH		;REFRESH YOUR STRS.

;ROUTINE FOR CHANGING PARAMETERS ONLY (CHANGE)

SHRTPM::PUSHJ	P,READ		;READ HOME AND BAT BLOCKS
	PUSHJ	P,CHGSTA	;CHANGE STRS?
	PUSHJ	P,CHGUNA	;UNITS?
	PUSHJ	P,CHGASL	;ACTIVE SWAPPING LIST?
	PUSHJ	P,CHGSRC	;SYS SEARCH LIST?
	PUSHJ	P,CHKCHG	;SEE IF ANYTHING HAS BEEN CHANGED
	POPJ	P,		;NO-NO NEED FOR FOOLING
	SETOM	SHUTUP		;TELL RWRHOM TO KEEP IT QUIET
	PUSHJ	P,RWRHOM	;GO READ & WRITE NEW HOM BLOCKS
	PJRST	RFRESH		;ONLY STRS THAT NEED IT.
;UNITID OPTION

SHRTID::MOVE	F,DATADR		;FILE DATA BLOCK ADDR
	SKIPE	SHUTUP		;SKIP IF VIRGIN SYSTEM
	PUSHJ	P,GVMNB0##	;GIVE MBF BACK-#1 TOOK IT
	PUSHJ	P,READ		;IN ANY EVENT, SET UP STUFF
	MOVEI	T1,[ASCIZ /CHANGE ALL UNIT ID'S? (Y OR <CR>)/]
	PUSHJ	P,YESNO##	;GET ANSWER
	PJRST	SOMIDS	;ONLY CHANGE SOME.
ALLIDS:	MOVEI	T1,[ASCIZ /AFTER EACH UNIT NAME, TYPE THE I.D.
/]
	PUSHJ	P,SVMOUT
	HLRZ	U,SYSUNI##	;1ST UNIT IN SYSTEM.
	SKIPA
ALLID2:	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT
	JUMPE	U,SOMID2
	MOVSI	T1,UNPWPO##
	TDNE	T1,UNIDES##(U)
	JRST	ALLID2
ALLID1:	SETZB	P1,P4
	PUSHJ	P,TYPUN1	;TYPE OUT UNINAM AND ID
	MOVEI	T1,[ASCIZ /:/]	;AND COLON
	PUSHJ	P,SVOSET	;INITIALIZE BUFFER
	PUSHJ	P,SCONMS	;PUT IT IN
	PUSHJ	P,SOPOUT	;OUTPUT IT
	MOVE	P1,UNIHID##(U)
	PUSHJ	P,GETSIX
	JRST	ALLID2		;NO CHANGE IN VALUE
	JUMPE	P1,ALLID1	;0 IS NO GOOD, GO BACK AGAIN FOR SAME UNIT
	MOVEM	P1,UNIHID##(U)	;OK, YOU PASS...
	PUSHJ	P,SETRFS	;MARK HOM BLOCKSAS NEEDING REWRITING
	JRST	ALLID2
SOMIDS:	MOVEI	T1,[ASCIZ/
TYPE UNIT NAME, A COMMA, AND NEW UNIT ID FOR EACH DESIRED UNIT.
(EXTRA <CR> WHEN THROUGH)
/]
	PUSHJ	P,SVMOUT	;OUTPUT MESSAGE
SOMID1:	PUSHJ	P,GETUNI	;GET UNIT, SETUP U
	PJRST	SOMID2		;END OF LINE
	JUMPE	U,ALLIDS	;IF U=0, DO ALL
	CAIE	T3,","	;USE EITHER COMMA
	CAIN	T3," "		;OR BLANK
	CAIA
	JRST	SOMIDS		;YOU DIDNT GET THE MESSAGE!!
	MOVE	P1,UNIHID##(U)	;GET OLD ID
	JSP	T2,SVOTAC
	PUSHJ	P,GETSX1
	JRST	SOMID1	;NO CHANGE IN VALUE
	JUMPE	P1,SOMIDS	;ZERO ID NO GOOD-GO BACK AGAIN
	MOVEM	P1,UNIHID##(U)	;PUT IT IN
	PUSHJ	P,SETRFS	;MARK HOME BLOCKS AS NEEDING REWRITING
	JRST	SOMID1		;LOOP BACK FOR MORE POSSIBLE UNITS
SOMID2:	PUSHJ	P,CHKCHG	;ANY NEED CHANGING??
	PJRST	RFRESH		;NO-JUST GO BACK
	SETOM	SHUTUP
	PUSHJ	P,RWRHOM	;REWRITE HOM BLOCKS
	PJRST RFRESH	;GO TO IT..
SHRTGO::PUSHJ	P,READ			;READ HOM AND BAT BLOCKS.
	SETOM	SHUTUP		;ONLY TELL IF THEY NEED
	PJRST	RFRESH		;REFRESHING. BYE!

;ROUTINE FOR INITIALIZING KONTROLLER DATA BLOCKS.
SETKON::SETZM	HOMFLG		;INDICATE MUST READ HOME BLOCKS
	MOVSI	T1,UNPWPO##	;SETUP UNIT WRITE PROTECT & OFF-LINE BITS
	MOVSI	T2,KOPDWN##	;SETUP KONTROLLER DOWN BIT
	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
SETKN1:	ANDCAM	T1,UNIDES##(U)	;UNIT INITIALIZED TO BE ON-LINE & WRITE ENABLED
	DPB	T1,UNYUST##	;CLEAR UNIT STATUS(LOW ORDER BITS OF AC T1 = 0)
	HRRZ	J,UNIKON##(U)	;GET UNIT'S KONTROLLER DATA BLOCK ADR.
	ANDCAM	T2,KONDWN##(J)	;KONTROLLER IS ON-LINE
	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,SETKN1	;REPEAT IF THERE IS ONE
	POPJ	P,

READ:	SETZM	TYPONL
	SETZM	REFLAG##
	PUSHJ	P,SETKON	;SETUP UNIT WRITE PROTECT AND OFFLINE BITS
	PUSHJ	P,REDHOM	;READ HOM BLOCKS,
	  JFCL			;IGNORING ERRORS
	PUSHJ	P,REDBAT	;AND BAT BLOCKS
	POPJ	P,		;THEN GO BACK.

SETRFS:	HRRZ	P2,UNISTR##(U)	;HWAT STR?
	SKIPE	P2		;NOT A MEMBER OF STR
	HRROS	STRREF##(P2)	;MARK AS NEEDS REFRESHING
	PJRST	SETCHG

;SUBROUTINE TO DO OPTIONAL ONCE ONLY THINGS

FILOPT::PUSHJ	P,SETKON	;SET UP KDBS
	MOVEI	T1,[ASCIZ /
IN THE FOLLOWING DIALOG, ALL NUMBERS ARE DECIMAL.
TYPE <CR> IF OK, OR A NEW NUMBER TO CHANGE VALUE.
/]
	PUSHJ	P,SVMOUT
	SETZM	TYPONL		;CLEAR TYPE ONLY FLAG
	SETZM	REFLAG##	;CLEAR REFLAG - SET IF REFRESH ANYTHING
	MOVEI	T1,[ASCIZ .# MONITOR BUFFERS = .]
	SKIPN	P1,MBFNUM##
	AOS	P1,MBFNUM##	;MUST HAVE AT LEAST 1 MON. BUF
	PUSHJ	P,ASKDEC	;TYPE MSG. & VALUE & GET USER'S RESPONSE
	  CAIA			;CR OR NO CHANGE IN VALUE
	MOVEM	P1,MBFNUM##	;STORE NEW VALUE
	SETZM	BATMAN
FILOP2:	PUSHJ	P,REDHOM	;READ ALL "HOME" BLOCKS ON ALL UNITS IN SYSTEM
	  JFCL			;IGNORE ERRORS
FILCHG:	SETZM	BATANY		;CLEAR NO. OF BAD REGIONS FOR SYSTEM
	PUSHJ	P,REDBAT	;GO READ & VERIFY "BAT" BLOCKS ON ALL UNITS IN SYSTEM
	SKIPE	BATANY		;ANY BAD REGIONS ON ANY UNITS?
	PUSHJ	P,TYPBAT	;YES, ASK IF HE WANTS TO LIST ANY
	MOVEI	T1,[ASCIZ .
DSK FILE STRUCTURES(STRS):.]
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	SKIPE	SYSSTR##	;DON'T ASK FOLLOWING QUESTION IF NO STR'S
	PUSHJ	P,TYPSYS	;TYPE ALL STR NAMES & THEIR PHYSICAL UNIT NAMES
	PUSHJ	P,TYPUNS	;TYPE ALL UNIT NAMES THAT ARE NOT IN STR'S
	PUSHJ	P,TYPASL	;TYPE ALL UNITS IN ACTIVE SWAPPING LIST
	PUSHJ	P,TYPSRC	;TYPE "SYS" SEARCH LIST
	SKIPE	SYSSTR##	;DON'T ASK FOLLOWING QUESTION IF NO STR'S
	PUSHJ	P,TYPSTA	;ASK FOR STR NAMES TO TYPE PARAMETERS
	PUSHJ	P,TYPUNA	;ASK FOR UNIT NAMES TO TYPE PARAMETERS
	SKIPN	HOMFLG
	PUSHJ	P,CHKCHG	;ANY "HOME" BLOCKS NEED REWRITING AT THIS POINT?
	  JRST	ANYCHG		;NONE DO - SEE IF ANYTHING TO BE CHANGED
	MOVEI	T1,[ASCIZ .
BEFORE "HOME" BLOCKS ARE REWRITTEN,
 DO YOU WANT TO CHANGE ANY DISK PARAMETERS?
.]
	PUSHJ	P,ASKQUE	;ASK QUESTION & GET USER'S RESPONSE
	  JRST	RWRHOM		;THE ANSWER WAS "NO" - JUST REWRITE HOME BLOCKS
	JRST	CHGLUP		;FALL INTO CHANGE DIALOG
ANYCHG:	PUSHJ	P,ASKYCR	;ASK IF ANYTHING TO BE CHANGED
	  JRST	RFRESH		;APPARENTLY NOT - SEE IF ANY STR'S TO BE REFRESHED
CHGLUP:	PUSHJ	P,ASKDIS	;ASK IF ANY STR'S TO BE DISSOLVED-DISSOLVE THEM
	PUSHJ	P,ASKDEF	; "  "   "   "    "  "    DEFINED-  DEFINE  "
	SKIPE	SYSSTR##	;DON'T ASK FOLLOWING QUESTION IF NO STR'S
	PUSHJ	P,CHGSTA	;ASK FOR STR NAMES TO TYPE & CHANGE PARAMETERS
	PUSHJ	P,CHGUNA	;ASK FOR UNIT NAMES TO TYPE & CHANGE PARAMETERS
	PUSHJ	P,TYPASL	;TYPE ACTIVE SWAPPING LIST
	PUSHJ	P,CHGASL	;ASK IF ACTIVE SWAPPING LIST TO BE CHANGED
	PUSHJ	P,TYPSRC	;TYPE "SYS" SEARCH LIST
	PUSHJ	P,CHGSRC	;ASK IF "SYS" SEARCH LIST TO BE CHANGED
	SKIPE	SHUTUP
	JRST	RWRHM1
	PUSHJ	P,CHKCHG	;SEE IF ANY "HOME" BLOCKS NEED REWRITING
	  JRST	ANYCHG		;NONE DO - SEE IF ANYTHING TO BE CHANGED

;HERE WHEN "HOME" BLOCKS MUST BE REWRITTEN

CHGSOM:	MOVEI	T1,[ASCIZ .
BEFORE "HOME" BLOCKS ARE WRITTEN.]
	PUSHJ	P,CONOUT	;ADD CRLF & O/P MSG.
	PUSHJ	P,TYPSTA	;ASK FOR STR NAMES TO TYPE PARAMETERS
				; ASK EVEN IF THERE ARE NO STR'S JUST AS A REMINDER
	PUSHJ	P,TYPUNA	;ASK FOR UNIT NAMES TO TYPE PARAMETERS
	PUSHJ	P,ASKYCR	;ASK IF ANYTHING TO BE CHANGED
	  CAIA			;NO - SEE IF ANY UNITS NEED "HOME" BLOCKS REWRITTEN
	JRST	CHGLUP		;YES - GO CHANGE THINGS

;HERE TO JUST REWRITE "HOME" BLOCKS

RWRHOM:	PUSHJ	P,RWRSUB	;ASK FOR UNITS TO REWRITE HOME BLOCKS
	MOVE	F,DATADR	;SETUP FILE DATA BLOCK ADR.
	PUSHJ	P,GVMNB0##	;RETURN MONITOR BUFFER USED FOR "HOME" BLOCK
	SKIPE	SHUTUP
	JRST	RWRHM1		;IF SHORT DIALOG, DONT GO BACK
	PUSHJ	P,CHKCHG	;DID WE WRITE ALL HOME BLOCKS?
	  JRST	FILOP2		;YES, REREAD THEM AS A CHECK
	SETOM	HOMFLG		;NO, INDICATE DON'T REREAD
	PUSHJ	P,GTMNBF##	;GET MON BUF TO READ BAT BLOCKS
	JRST	FILCHG		;GO READ ALL "HOME" BLOCKS & SET UP DATA BASE
RWRHM1:	PUSHJ	P,REDHOM
	JFCL
	PUSHJ	P,REDBAT
	POPJ	P,		;YES.

;ROUTINE TO JUST WRITE OUT ALL HOME BLOCKS(FOR OPTION NUMBER 1)
;DOESN'T WRITE ON OFF LINE OR WRITE PROTECTED UNITS

WRTHOM:	MOVSI	P4,UNPCHG##
	HLRZ	U,SYSUNI##
WRTHM1:	MOVSI	T1,300000	;HARDWARE WRITE PROTECT & OFF LINE BITS
	TDNE	T1,UNIDES##(U)		;IF UNABLE TO WRITE, GO TO NEXT UNIT
	JRST	WRTHM2
	PUSHJ	P,HOMWRT
	ANDCAM	P4,UNIDES##(U)		;CLEAR OUT UNPCHG
WRTHM2:	HLRZ	U,UNISYS##(U)
	JUMPN	U,WRTHM1		;UNITS ARE LEFT-GO FOR MORE
	MOVEI	T1,[ASCIZ .
HOME BLOCKS WRITTEN ON ALL UNITS.]
	PUSHJ	P,SVMOUT
	MOVE	F,DATADR	;GET FDB ADDRESS
	PUSHJ	P,GVMNB0##	;GIVE BACK MONITOR BUFFER
	PUSHJ	P,REDHOM
	JFCL
	PUSHJ	P,REDBAT	;READ BAT BLOCKS ALSO
	POPJ	P,		;GO AWAY

;HERE TO REFRESH FILE STRUCTURES

RFRESH:	SKIPN	HOMFLG
	PUSHJ	P,CHKCHG	;ANY "HOME" BLOCKS NEED REWRITING?
	  CAIA			;NO - GO REFRESH STRS
	JRST	CHGSOM		;YES - WARN USER BEFORE WRITING THEM
	MOVE	P1,STRAOB##	;LH=-NUMBER OF STR'S, RH=INDEX OF 1ST
	SETZ	P3,		;P3=0 FOR 1ST THAT NEEDS REFRESHING
RFRESA:	MOVE	P2,TABSTR##(P1)	;ADDR OF NEXT STR DATA BLOCK
	JUMPE	P2,RFRESB	;JUMP IF NOT AN STR
	HLLZ	T2,STRREF##(P2)	;NEEDS REFRESHING FLAG
	JUMPN	T2,RFRESC	;JUMP IF NEEDS REFRESHING
RFRESB:	AOBJN	P1,RFRESA	;LOOP FOR ALL STRS
	SKIPE	SHUTUP
	JUMPE	P3,CPOPJ##
	JUMPE	P3,RFRES1
	PUSHJ	P,SVOSET
	PUSHJ	P,SCRLFO
	JRST	RFRES1
RFRESC:	JUMPN	P3,RFRESD
	PUSHJ	P,SVOSET
	MOVEI	T1,[ASCIZ .
%NEED REFRESHING:
.]
	PUSHJ	P,SCONMS
RFRESD:	PUSHJ	P,TYPSTS	;TYPE STR NAME
	AOJA	P3,RFRESB	;BUMP P3 TO SHOW ONE PRINTED AND KEEP ON
RFRES1:	PUSHJ	P,SOPOUT
RFRES3:	MOVEI	T1,[ASCIZ .TYPE STR NAME TO BE REFRESHED(CR IF NONE, ALL IF ALL).]
	MOVE	F,DATADR	;SETUP FILE DATA BLOCK ADR
	PUSHJ	P,ASKSTR	;TYPE MSG. & GET RESPONSE
	  POPJ	P,		;CR WAS TYPED - EXIT
	JUMPN	P2,WUNSTR	;WAS "ALL" TYPED?
	HLRZ	P2,SYSSTR##	;YES - DO FOR ALL STR'S IN SYSTEM
RFRES2:	PUSHJ	P,REFSTR##	;REFRESH STR
	  STOPCD .+1,DEBUG,EWR,	;++ERROR WHILE REFRESHING
	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR IN SYSTEM
	JUMPN	P2,RFRES2	;REPEAT IF ANY LEFT
	POPJ	P,		;CR WAS TYPED - EXIT

WUNSTR:	PUSHJ	P,REFSTR##	;REFRESH STR
	  STOPCD .+1,DEBUG,ERD,	;++ERROR REFRESHING DISK
	JRST	RFRES3		;ASK FOR ANOTHER STR NAME TO BE REFRESHED
;ROUTINE TO SEE IF ALTMODE WAS TYPED IN RESPONSE TO A QUESTION
;IF SO, USE SAVED PDP AND POPJ BACK TO QUICK

ALTM::	JUMPGE	J,CPOPJ##		;JUST GO BACK IF ALT WASN'T TYPED.
ALTM1:	SKIPE	F,DATADR	;FILE DATA BLOCK ADR
	SKIPN	DEVMBF##(F)
	JRST ALTM2
	PUSHJ	P,GVMNB0##
	JRST	ALTM1
ALTM2:	MOVEI	P,ONCPDL##	;FIX PDP
	PUSH	P,.		;POSITIVE NUMBER ON LIST IS
				; THE ALT-MODE FLAG
	JRST	SHORTD##	;GO BACK TO BEGINNING.

SHUTUP::BLOCK 1
KON:	BLOCK 1
;MANDATORY ONCE ONLY CODE

FILMAN::SETZM	SERIUS
	PUSHJ	P,REDHOM	;READ ALL UNIT'S "HOME" BLOCKS THAT CAN BE
				; & SET UP UPPER CORE DATA BLOCKS
	  JRST	.+2		;ERRORS - CALL OPTIONAL ONCE-ONLY
	JRST	FILMN1		;NO ERRORS IN "HOME" BLOCK-PROCEED
	SKIPN	OPTQIK		;QUICK OPTION?
	SKIPGE	DEBUGF##	; OR DEBUGGING?
	SKIPE	SERIUS		;YES, SERIOUS ERROR
	CAIA			;YES, DO LONG DIAGLOGUE
	JRST	FILMN1		;NO, START UP SYSTEM
	SETZM	BATMAN		;ASSUME OPTIONAL FOR VENDING BAT BLOCKS
	PUSHJ	P,FILCHG	;CALL OPTIONAL ONCE-ONLY
	PUSHJ	P,REDHOM	;MUST READ "HOME" BLOCKS AGAIN-MAY HAVE BEEN CHANGED
	  JFCL			;IGNORE ERRORS
FILMN1:	SETOM	BATMAN		;NOTE IN MANDANTORY PART NOW
	PUSHJ	P,REDBAT	;READ BAT BLOCKS TO SET UP SWAPPING SATS
	HLRZ	P2,SYSSTR##	;GET ADR. OF 1ST. STR IN SYSTEM
NXTSIS:	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT IN STR
	PUSHJ	P,GTSRB		;READ SAT.SYS "RIB" BLOCK FOR THIS STR - P2 DESTROYED
	  STOPCD NXTSIE,DEBUG,ERS, ;++ERR READING SAT
	HRRZ	T1,P1		;GET ADR. OF "RIB" BLOCK IN CORE
	ADD	T1,RIBFIR##(P1)	;CREATE AOBJN PTR. FOR SCANNING RET. INFO.
	AOBJN	T1,.+2		;SKIP OVER 1ST. PTR. AS IT IS A "RIB"
	STOPCD	NXTSIE,DEBUG,NRS, ;++NO RIB IN SAT
	HRRZ	P2,UNISTR##(U)	;GET ADR. OF STR - P2 CLOBBERED BY GTSRB
	SETZB	P4,STRTAL##(P2)	;CLEAR FREE BLOCK TALLY & LAST RET. PTR. FLAG FOR STR
NXTUIS:	PUSH	P,T1		;SAVE PTR.
	LDB	T3,UNYLUN##	;GET LOG. UNIT # OF THIS UNIT IN STR
	SKIPN	T3		;IF THIS UNIT IS LOG. UNIT # 0
	SKIPA	T2,-1(T1)	; SKIP BACK OVER "RIB" TO GET NEW UNIT PTR.
	MOVE	T2,(T1)		;GET NEW UNIT PTR.
	TRNN	T2,RIPNUB##	;IS IT REALLY A NEW UNIT PTR?
	STOPCD	NXTSIE,DEBUG,NNU, ;++NOT NEW UNIT
	ANDI	T2,77		;IT SHOULD BE LOG. UNIT # SO MASK OUT EXTRA BITS
	CAME	T2,T3		;IS IT?
	STOPCD	NXTSIE,DEBUG,RPM, ;++RET. PTR. MISMATCH
	HRRZ	T4,UNISPT##(U)	;GET ADR. OF UNIT'S SPT TABLE
MOVPTR:	AOBJP	T1,MOVPT2	;HAVE WE RUN OUT OF RET. INFO?
	MOVE	T2,(T1)		;NO - GET NEXT WORD
	LDB	T3,STYCNP##(P2)	;GET CLUSTER COUNT
	JUMPE	T3,MOVPT1	;IF 0 WE MUST HAVE RUN OUT OF PTRS. FOR THIS UNIT
	LDB	T2,STYCLP##(P2)	;GET CLUSTER ADR.
	DPB	T2,SPYCLA##	;STORE IN SPT TABLE FOR THIS UNIT
	AOJA	T4,MOVPTR	;BUMP SPT TABLE ADR. & RETURN FOR MORE PTRS.

NXTSIE:	HRRZ	P2,UNISTR##(U)	;RESET P2 TO POINT TO STR
	JRST	LSTRT1		;AND GO ON TO NEXT STR

MOVPT1:	MOVEM	T1,(P)		;SAVE PTR. ON STACK FOR NEXT UNIT SCAN
	JUMPN	T2,MOVPT3	;WAS IT 0 ENTRY INDICATING END OF LIST?
MOVPT2:	SUBI	T4,1		;YES - DECREMENT T4 SO THAT LAST ENTRY IN SPT TABLE,
				; WHICH IS A "RIB", GETS CLEARED
	SETOM	P4		;YES - SET END OF LIST FLAG
MOVPT3:	SETZM	(T4)		;ZERO END OF SPT TABLE FOR THIS UNIT
	SETZM	UNITAL##(U)	;CLEAR FREE BLOCK TALLY FOR THIS UNIT
;NOW READ ALL SATS ON THIS UNIT - COMPUTE THE # OF FREE CLUSTERS LEFT IN EACH SAT

	PUSH	P,P2		;SAVE ADR. OF THIS STR
	LDB	P1,UNYSPU##	;GET # SAT BLOCKS ON THIS UNIT
	MOVNS	P1		;MAKE -VE
	HRLZS	P1		;MAKE IT INTO AN AOBJN PTR.
	MOVEI	P2,DIFSAB##(U)	;SETUP OFFSET TO POINT TO 1ST. SAB BLOCK ADR.
NXTSAT:	HLRZ	P2,SABRNG##(P2)	;GET ADR. OF NEXT SAB BLOCK FOR THIS UNIT
	HRRZ	T4,UNISPT##(U)	;GET ADR. OF SPT TABLE
	ADDI	T4,(P1)		;ADD IN INDEX FOR LDB SPYCLA
	LDB	T1,SPYCLA##	;GET CLUSTER ADR. OF THIS SAT BLOCK
	LDB	T2,UNYBPC##	;GET # BLOCKS PER CLUSTER
	IMUL	T2,T1		;COMPUTE LOGICAL BLOCK # FOR THIS SAT
	PUSHJ	P,REDSAT	;GO READ SAT & COMPUTE # FREE CLUSTERS LEFT IN IT
	  STOPCD LSTRT1,DEBUG,SRE, ;++SAT READ ERROR
	HRRZ	T4,UNISPT##(U)	;GET ADR. OF SPT TABLE FOR THIS UNIT
	ADDI	T4,(P1)		;ADD IN INDEX FOR DPB SPYTAL
	DPB	T2,SPYTAL##	;STORE # FREE CLUSTERS IN THIS SAT BLOCK IN SPT TABLE
	LDB	T1,UNYBPC##	;GET # BLOCKS PER CLUSTER FOR THIS UNIT
	IMUL	T1,T2		;COMPUTE # FREE BLOCKS IN THIS SAT BLOCK
	HRRZ	T2,UNISTR##(U)	;LOC OF STR DATA BLOCK
	HLLZ	T3,STRREF##(T2)
	JUMPE	T3,NXTSA1	;IF STR NEEDS REFRESHING,
	MOVSI	T3,UNPHWP##	; PRETEND IT'S WRITE-LOCKED
	IORM	T3,UNIDES##(U)
	JRST	NXTSA2		; AND LEAVE UNITAL=STRTAL=0
NXTSA1:	ADDM	T1,UNITAL##(U)	;ADD TO TOTAL FOR THIS UNIT
	ADDM	T1,STRTAL##(T2)	;ADD TO TOTAL FOR THIS STR
NXTSA2:	AOBJN	P1,NXTSAT	;GO READ NEXT SAT IF THERE IS ONE
	MOVE	T2,UNIBPU##(U)	;GET NO OF BLOCK ON UNIT
	LDB	T3,UNYK4S##	;K FOR SWAPPING
	LSH	T3,BLKSPK##	;CONVERT TO BLOCKS
	SUB	T2,T3		;COMPUTE SAFETY FACTOR
	IDIVI	T2,UNVRSF##	; BLOCKS TO USE WHEN UNIT FULL
	CAILE	T2,^D500	;MAX SAFETY FACTOR = 500 BLOCKS
	MOVEI	T2,^D500
	MOVNS	T2
	ADDM	T2,UNITAL##(U)	;SUBTRACT FACTOR FROM UNIT
	MOVE	T1,UNISTR##(U)
	ADDM	T2,STRTAL##(T1)	; AND FROM STR
	POP	P,P2		;POP OFF ADR. OF THIS STR DATA BLOCK FROM STACK
	POP	P,T1		;RESTORE PTR. TO RET. INFO. FROM STACK
	HLRZ	U,UNISTR##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	JUMPL	P4,LSTRTP	;HAS LAST RET. PTR. BEEN SEEN?
	JUMPN	U,NXTUIS	;NO - IS THERE ANOTHER UNIT IN THIS STR TO CHECK
	STOPCD	.,HALT,ROU,	;++RAN OUT OF UNITS
LSTRTP:	SKIPE	U		;IS THERE ANOTHER UNIT IN THIS STR TO CHECK
	STOPCD	.,HALT,TMU,	;++TOO MANY UNITS
LSTRT1:	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK IN SYSTEM
	JUMPN	P2,NXTSIS	;IF THERE IS ONE REPEAT
IFN FTSTR,<			;IF MORE THAN ONE STR
	PUSH	P,P2		;INIT TEMP PTR TO SYS. SL.
	MOVE	P2,SYSSRC##
	MOVEM	P2,TEMPTR
	PUSHJ	P,SLINI##	;AND EMPTY THE SYS SL.
	POP	P,P2
	MOVE	P4,[PUSHJ P,DEPCLR]	;SETUP INSTR. FOR XCT IN FNDSRC
>
IFE FTSTR,<
	MOVE	P4,CPOPJ##
>
	PUSHJ	P,FNDSRC	;GO SETUP "SYS" SEARCH LIST
	MOVE	T4,DDSTAR##	;COMPUTE OFFSET OF HI CORE DATA BLOCKS ETC.
	SUB	T4,SYSSIZ##
	MOVEI	T1,BUFLST##	;SETUP LINK POINTING TO 1ST. MBF IN SYSTEM
	SKIPA	T2,MBFNUM##	;GET # OF MONITOR BUFFERS IN SYSTEM
ADJMBF:	MOVEI	T1,MBFLNK##(P1)	;SETUP LINK POINTING TO NEXT MBF IN SYSTEM
	MOVE	P1,(T1)		;GET ADR. OF NEXT MONITOR BUFFER
	HRRZ	T3,P1
	SUB	T3,T4		;DECREMENT RH OF PTR. TO NEXT MBF BY OFFSET
	HRRM	T3,(T1)
	SOJG	T2,ADJMBF	;REPEAT IF ANY MORE BUFFERS
	MOVEI	T2,SYSSTR##	;SETUP LINK POINTING TO 1ST. STR IN SYSTEM
	JRST	ADJSR1

ADJSTR:	SETZM	STRMNT##(P1)	;CLEAR MOUNT COUNT(TIMESHARED AS STRSAT)
	SETZM	STRJOB##(P1)	;CLEAR SINGLE ACCESS OWNER(TIMESHARED AS STRSRC)
	HRRZ	T3,P1
	SUB	T3,T4		;DECREMENT LH OF PTR. TO NEXT STR BY OFFSET
	HRLM	T3,(T2)
	MOVEI	T2,STRSYS##(P1)	;SETUP LINK POINTING TO NEXT STR IN SYSTEM
ADJSR1:	HLRZ	P1,(T2)		;GET ADR. OF NEXT STR IN SYSTEM
	JUMPN	P1,ADJSTR	;REPEAT IF ANY MORE STRS
	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST UNIT DATA BLOCK IN SYSTEM
ADJUNI:	LDB	T1,UNYSIC##	;GET # SAT BLOCKS IN CORE FOR THIS UNIT
	JUMPE	T1,ADJSA1	;MUST BE A UNIT NOT IN AN STR
	MOVEI	T3,UNISAB##(U)	;SETUP LINK POINTING TO 1ST. SAB BLOCK FOR THIS UNIT
	CAIA
ADJSAB:	MOVEI	T3,SABRNG##(P1)	;SETUP LINK POINTING TO NEXT SAB BLOCK FOR THIS UNIT
	HLRZ	P1,(T3)		;GET ADR. OF NEXT SAB BLOCK FOR THIS UNIT
	HRRZ	T2,P1
	SUB	T2,T4		;DECREMENT LH OF THIS SAB'S(OR UNIT DATA BLOCK'S)
	HRLM	T2,(T3)		; PTR. TO NEXT SAB BY OFFSET
	HRRZ	T2,SABSCN##(P1)
	SUB	T2,T4		;DECR. RH OF NEXT SAB BLK'S "LAST LEFT" PTR. BY OFFSET
	HRRM	T2,SABSCN##(P1)
	SOJG	T1,ADJSAB	;REPEAT IF ANY MORE SAB BLOCKS FOR THIS UNIT
	HLRZ	T2,UNISAB##(U)	;GET ADR. OF 1ST. SAB BLOCK
	HRLM	T2,SABRNG##(P1)	;MAKE LAST SAB BLOCK POINT TO 1ST.(RING)
	HRRZ	T2,UNIPTR##(U)
	SUB	T2,T4		;DECREMENT RH OF AOBJN PTR. TO SWAPPING SAT TABLE
	HRRM	T2,UNIPTR##(U)
	HRRZ	T2,UNISPT##(U)
	JUMPE	T2,ADJSA1	;NO SPT TABLE FOR THIS UNIT?
	SUB	T2,T4		;DECREMENT ADR. OF SPT TABLE IN UNIT DATA BLOCK
	HRRM	T2,UNISPT##(U)
ADJSA1:	HRRZ	T2,UNISTR##(U)	;GET STR ADR. THIS UNIT IS IN
	JUMPE	T2,ADJSA2	;IS IT 0?
	SUB	T2,T4		;NO - DECREMENT ITS ADR.
	HRRM	T2,UNISTR##(U)	;STORE NEW ADR.
ADJSA2:	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,ADJUNI	;REPEAT IF ANY LEFT
	MOVE	T3,STRAOB##	;ADJUST ALL ADRS. IN STR TABLE
ADJSTT:	HRRZ	T2,TABSTR##(T3)	;GET NEXT STR ADR. FROM TABLE
	JUMPE	T2,SWPFAC	;END OF TABLE?
	SUB	T2,T4		;NO - DECREMENT THIS STR ADR.
	HRRM	T2,TABSTR##(T3)	;STORE NEW STR ADR.
	AOBJN	T3,ADJSTT	;REPEAT IF NOT END OF TABLE
SWPFAC:	PUSHJ	P,GVMNB0##	;RETURN MONITOR BUFFER USED FOR "RIB" BLOCK


;CALCULATE DATA NEEDED FOR THE MCU FUNCTION.
;SET PROT AND PROT0 ACCORDING TO THE FIRST UNIT
;IN THE ACTIVE SWAPPING LIST USING THE AVERAGE TIME PER PAGE
;FOR PROT AND THE AVERAGE LATENCY TIME FOR PROT0


	MOVEI	P1,BKPMAX	;LAST ENTRY IN UNIT TYPE TABLES
SWPFC1:	MOVEI	T1,PAGSIZ##	;GET WORDS PER PAGE
	LSH	T1,-7		;CONVERT TO BLOCKS PER PAGE (128 WORDS PER BLOCK)
	IMUL	T1,MSPREV(P1)	;MULTIPLY BY MICROSECS PER REVOLUTION
	IDIV	T1,BKPREV(P1)	;DIVIDE BY BLOCKS PER REVOLUTION TO
				;GET MICROSECS PER PAGE
	MOVEM	T1,MCUATP##(P1)	;SAVE IN TABLE FOR MCU CALCULATION
	MOVE	T1,AVSEEK(P1)	;GET AVG SEEK TIME IN MICROSECS
	LSH	T1,1		;*2
	ADD	T1,MSPREV(P1)	;ADD IN MICROSECS PER REV
	LSH	T1,-1		;/2 TO GET AVERAGE LATENCY
	MOVEM	T1,MCUALT##(P1)	;IN MICROSECS. SAVE FOR MCU.
	SOJGE	P1,SWPFC1	;LOOP FOR ALL TYPES OF UNIT.

;NOW CALCULATE DEFAULT PROT AND PROT0 WHICH WILL BE USED
;IN THE ABSENCE OF THE MINIMUM CORE USAGE FUNCTION.

	MOVSI	T3,MSWPMX##	;AOBJN POINTER TO SWPTAB
	SKIPN	U,SWPTAB##(T3)	;GET FIRST NON-ZERO ENTRY
	AOBJN	T3,.-1
	LDB	T1,UNYKTP##	;GET KONTROLLER TYPE
	MOVE	T1,TYPTAB##(T1)	;GET OFFSET INTO UNIT TYPE TABLES
	LDB	P1,UNYUTP##	;GET UNIT TYPE
	ADD	P1,T1		;GET FINAL POSITION IN UNIT TYPE TABLES
	MOVE	T1,PRT0TB(P1)	;GET PROT0 FOR THIS DEVICE
	MOVEM	T1,PROT0##	;(MICRO SECONDS)
	IMUL	T1,TICSEC##	;TICS PER SECOND
	IDIV	T1,[^D1000000]	;CONVERT PROT0 TO TICKS
	MOVEM	T1,PROT1##	;AND SAVE AS TICS VERSION OF PROT0
	MOVE	T1,PROTTB(P1)	;GET MULTIPLIER FOR THIS DEVICE
	MOVEM	T1,PROT##	;(MICRO SECONDS)
	MOVE	T1,PRTMTB(P1)	;GET MAXIMUM FOR THIS DEVICE
	MOVEM	T1,PROTM##	;(MICRO SECONDS)
IFN FTNSCHED,<
	MOVE	T1,MCUATP##(P1)	;AVG TIME PER PAGE IN MICROSEC.
	IMULI	T1,PAVJSP##	;PREDICTED AVG JOB SIZE IN PAGES
IFN FTKA10,<
	LSH	T1,-1		;FIX UP FOR MCUATP CALCULATED IN K
>
	ADD	T1,MCUALT##(P1)	;PLUS AVG LATENCY IN MICROSEC.
	IMUL	T1,TICSEC##	;MICROTICS
	IDIV	T1,[^D1000000]	;CONVERT TO TICS
	ADDI	T1,1		;ROUND UP TO NEXT TIC
	MOVEM	T1,SCDSWP##	;CYCLE TIME FOR PQ2 SWAPIN SCAN
>
; NOW SET QUANTUM TABLES
	MOVE	T1,MAXTAB(P1)	;GET MAXIMUM PQ2 QUANTUM RUN TIME
	IMUL	T1,TICSEC	;CONVERT TO TICKS
	IDIV	T1,[^D1000000]
	MOVEM	T1,QMXTAB##+1
	MOVE	T1,ADDTAB(P1)	;GET MINIMUM PQ2 QUANTUM RUN TIME
	IMUL	T1,TICSEC	;CONVERT TO TICKS
	IDIV	T1,[^D1000000]
	MOVEM	T1,QADTAB##+1
	MOVE	T1,MULTAB(P1)	;GET PQ2 QUANTUM RUN TIME MULTIPLIER
	IMUL	T1,TICSEC	;CONVERT TO TICKS
	IDIV	T1,[^D1000000]
	MOVEM	T1,QMLTAB##+1	;AND AS PQ2 MULTIPLIER
				;PQ1 QUANTA ARE INITIALIZED IN COMMON.
				;INSERT ANY NON-STANDARD CODE FOR
				;INITIALIZING PQ1 QUANTA HERE.
SWPFC3:

	MOVSI	T1,UNPCHG##
	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
	ANDCAM	T1,UNIDES##(U)	;CLEAR CHANGE BIT
	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,.-2		;REPEAT IF ANY LEFT
	SETZM	DINITF##	;CLEAR FLAG THAT INDICATES ONCE ONLY IN PROGRESS
	MOVEI	T1,STRSYS##
	HRRM	T1,SYSSTR##
	SKIPN	REFLAG##	;AUTOMATIC "LOGIN" WANTED?
	POPJ	P,		;NO - RETURN
	MOVE	T1,FSFPPN##
	MOVEM	T1,REFLAG##
	PJRST	REFLOG##
KONCNI:	JFCL			;(NEW) DRUM
	XCT	FHXCI1##(J)
	XCT	DPXCIT##(J)
	JFCL			;MOBY DISK
	XCT	FSXCI2##(J)
	XCT	RPXCI2##(J)

KONCNO:	JFCL
	XCT	FHXCO1##(J)
	XCT	DPXCO1##(J)
	JFCL
	XCT	FSXCO2##(J)
	XCT	RPXCO2##(J)

SKPPIA:	JFCL
	TRNN	T2,7
	TRNN	T1,7
	JFCL
	TRNN	T2,7
	TRNN	T2,7

IFN FT22BIT,<
SKP22B:	JFCL
	TLNN	T2,40000
	TLNN	T1,20
	JFCL
	TLNN	T2,4000
	TLNN	T2,4000
>
IFE FT22BIT,<
SKP22B:	SKIPA
	TLNE	T2,40000
	TLNE	T1,20
	SKIPA
	TLNE	T2,4000
	TLNE	T2,4000
>
;BLOCKS PER REVOLUTION TABLE

BKPREV:	0	;NEW DRUM
	0	;DITTO
	^D20	;RD10
	^D30	;RM10B
	^D5	;RP01
	^D10	;RP02
	^D10	;RP03
	^D11	;DUAL POSITIONER MD10
	^D11	;SINGLE POSITIONER MD10
	^D32	;RS04
	^D20	;RP04
	^D20	;RP06
BKPMAX==.-BKPREV-1		;MAXIMUM INDEX TO THESE TABLES

;MICROSECONDS PER REVOLUTION TABLE

MSPREV:	0	;NEW DRUM
	0	;DITTO
	^D33000	;RD10
	^D17000	;RM10B
	^D25000	;RP01
	^D25000	;RP02
	^D25000	;RP03
	^D50000	;DUAL POSITIONER MD10
	^D50000	;SINGLE POSITIONER MD10
	^D17000	;RS04
	^D17000	;RP04
	^D17000	;RP06

AVSEEK:	0	;NEW DRUM
	0	;DITTO
	0	;RD10
	0	;RM10B
	^D50000	;RP01
	^D50000	;RP02
	^D50000	;RP03
	^D110000	;DUAL POSITIONER MD10
	^D110000	;SINGLE POSITIONER MD10
	0	;RS04
	^D27000	;RP04
	^D27000	;RP06


IFN FTSTR,<			;IF MAY BE MORE THAN 1 STR
SRCPTR:	POINT	4,SYSSRC##	;MASTER BYTE PTR. FOR CREATING "SYS" SEARCH LIST
TEMPTR:	0			;ACTUAL PTR. USED
>
;TABLE OF MINIMUM IN-CORE-PROTECT TIMES FOR VARIOUS DEVICES (PROT0)
PRT0TB:	^D3000000	;NEW DRUM - UNKNOWN
	^D3000000	;DITTO
	^D3000000	;RD10
	^D1500000	;RM10B
	^D7000000	;RP01
	^D5000000	;RP02
	^D5000000	;RP03
	^D8000000	;DUAL POSITIONER MD10
	^D8000000	;SINGLE POSITIONER MD10
	^D1500000	;RS04
	^D2000000	;RP04
	^D2000000	;RP06

;TABLE OF IN-CORE-PROTECT TIME MULTIPLIERS BY DEVICE (PROT)
PROTTB:	0		;NEW DRUM - UNKNOWN
	0		;DITTO
	0		;RD10
	0		;RM10B
	0		;RP01
	0		;RP02
	0		;RP03
	0		;DUAL POSITIONER MD10
	0		;SINGLE POSITIONER MD10
	0		;RS04
	0		;RP04
	0		;RP06

;TABLE OF MAXIMUM IN-CORE-PROTCT TIMES FOR VARIOUS DEVICES (PROTM)
PRTMTB:	^D3000000	;NEW DRUM - UNKNOWN
	^D3000000	;DITTO
	^D3000000	;RD10
	^D1500000	;RM10B
	^D7000000	;RP01
	^D5000000	;RP02
	^D5000000	;RP03
	^D8000000	;DUAL POSITIONER MD10
	^D8000000	;SINGLE POSITIONER MD10
	^D1500000	;RS04
	^D2000000	;RP04
	^D2000000	;RP06

;TABLE OF MINIMUM PQ2 IN QUEUE TIMES BY DEVICE (QADTAB+1)
ADDTAB:	^D3000000/4	;NEW DRUM - UNKNOWN
	^D3000000/4	;DITTO
	^D3000000/4	;RD10
	^D1500000/4	;RM10B
	^D7000000/4	;RP01
	^D5000000/4	;RP02
	^D5000000/4	;RP03
	^D8000000/4	;DUAL POSITIONER MD10
	^D8000000/4	;SINGLE POSITIONER MD10
	^D1500000/4	;RS04
	^D2000000/4	;RP04
	^D2000000/4	;RP06
;TABLE OF PQ2 MULTIPLIERS FOR IN QUEUE TIME BY DEVICE (QMLTAB+1)
MULTAB:	^D3000000/4	;NEW DRUM - UNKNOWN
	^D3000000/4	;DITTO
	^D3000000/4	;RD10
	^D1500000/4	;RM10B
	^D7000000/4	;RP01
	^D5000000/4	;RP02
	^D5000000/4	;RP03
	^D8000000/4	;DUAL POSITIONER MD10
	^D8000000/4	;SINGLE POSITIONER MD10
	^D1500000/4	;RS04
	^D2000000/4	;RP04
	^D2000000/4	;RP06

;TABLE OF MAXIMUM PQ2 IN QUEUE TIMES BY DEVICE (QMXTAB+1)
MAXTAB:	^D3000000/2	;NEW DRUM - UNKNOWN
	^D3000000/2	;DITTO
	^D3000000/2	;RD10
	^D1500000/2	;RM10B
	^D7000000/2	;RP01
	^D5000000/2	;RP02
	^D5000000/2	;RP03
	^D8000000/2	;DUAL POSITIONER MD10
	^D8000000/2	;SINGLE POSITIONER MD10
	^D1500000/2	;RS04
	^D2000000/2	;RP04
	^D2000000/2	;RP06
;SUBROUTINE TO READ THE "RIB" BLOCK FOR SAT.SYS

GTSRB:	MOVE	P4,STRSAT##(P2)	;GET LOG. BLOCK #'S OF 1ST. & 2ND. "RIB" BLOCKS
	MOVE	P3,[EXP CODRIB##]	;GET CODE WORD FOR "RIB" BLOCKS
	MOVSI	P2,(SIXBIT .SAT.)
	PJRST	REDRUN		;READ & VERIFY "RIB" BLOCKS

;SUBROUTINE TO READ A SAT BLOCK & COUNT THE # OF FREE CLUTERS IN IT

REDSAT:	HLLZ	T1,SABSCN##(P2)	;GET -VE LENGTH OF THIS SAT BLOCK
	ADDI	T1,-1+SABBIT##(P2)	;MAKE AN IOWD PTR. FOR MONRED
	PUSH	P,DEVMBF##(F)	;PRESERVE CURRENT MON. BUFFER ADR.
	MOVEM	T1,DEVMBF##(F)	;STORE NEW IOWD FOR SAT BLOCK
	PUSHJ	P,OMNRED	;GO READ IN "SAT" BLOCK
	  JRST	REDST1		;ERROR WHILE READING SAT BLOCK - NON SKIP RETURN
	AOS	T1,DEVMBF##(F)	;MAKE IOWD BACK INTO AN AOBJN PTR.
	PUSHJ	P,SATCN##	;COUNT 0 BITS IN SAT BLOCK
	HRRM	T2,SABTAL##(P2)	;STORE FREE CLUSTERS IN THIS SAT
	SETOM	SABHOL##(P2)	;DONT KNOW SIZE OF LARGEST HOLE
	HRRZS	T2		;CLEAR OUT LH
	MOVSI	T1,SAPDOB##	;CLEAR SAT BAD & SAT IN CORE DIFFERENT FROM ON DISK
	ANDCAM	T1,SABFIR##(P2)
	DPB	P1,SAYNDX##	;STORE SAT BLOCK INDEX # IN IN SAB BLOCK
	HRRZ	T1,UNICPS##(U)	;GET # CLUSTERS PER SAT FOR THIS UNIT
	IMULI	T1,(P1)		;TIMES SAT BLOCK INDEX
	DPB	T1,SAYCLA##
	AOS	-1(P)		;SKIP RETURN
REDST1:	POP	P,DEVMBF##(F)	;RESTORE ORIGINAL MON BUFFER ADR.
	POPJ	P,		;RETURN
;SUBROUTINE TO READ & VERIFY HOME BLOCKS AT SYSTEM INITIALIZATION
; REDHOM GETS A MONITOR BUFFER(GTMNBF), BUT DOESN'T RELINQUISH IT(GVMNB0)
;CALL	PUSHJ	P,REDHOM
;	  ERROR RETURN	AN ERROR WAS DETECTED WHILE READING THE "HOME" BLOCKS
;			 OF 1 OR MORE UNITS AND/OR NO STR'S WERE CREATED
;	OK RETURN	ALL HOME BLOCKS THAT WERE NOT DOWN READ OK

REDHOM::SKIPE	HOMFLG		;HOME BLOCKS SAME IN CORE AND DISK?
	JRST	CPOPJ1##	;NO, LEAVE CORE IMAGE ALONE

	SETZM	DOFLOK		;CLEAR FLAG
	SETZM	SWPUN2##
	SKIPE	.UONCE##	;SKIP IF EXEC MODE
	SKIPA	T1,ONCEND##	;USER MODE, GET ADDR OF FIRST FREE LOC
	MOVEI	T1,ONCEND##	;EXEC MODE, ADDR OF FIRST FREE LOC
	MOVEM	T1,DATADR
	MOVEM	T1,HICORE##
	MOVEI	T2,DDBLEN##	;SETUP LENGTH OF DDB FOR CORE GRABBER
	PUSHJ	P,CORGRB	;GET CORE
	MOVEM	T2,DDSTAR##	;SAVE HIGH CORE START ADR. OF DDB'S ETC.
	MOVEI	P4,BUFLST##	; TO START AT END OF ONCE
	SKIPA	P3,MBFNUM##	;GET # OF MONITOR BUFFERS TO BE CREATED
BUFSET:	MOVEI	P4,MBFLNK##(T1)	;GET ADR. OF LINK TO THIS MBF
	MOVEI	T2,MBFLEN##	;SETUP LENGTH OF MBF FOR CORE GRABBER
	PUSHJ	P,CORGRB	;GET CORE
	MOVEM	T1,(P4)		;SAVE ADR. OF THIS MBF IN PREVIOUS MBF(OR BUFLST)
	SOJG	P3,BUFSET	;REPEAT UNTIL NONE LEFT
	SETZM	MBFLNK##(T1)	;PUT ZERO IN LAST MBF LINK
	SETOM	DINITF##	;SET FLAG THAT INDICATES THAT ONCE ONLY IN PROGRESS
	SKIPE	.UONCE##
	JRST	BUFSE1
;HERE TO INITIALIZE FOR 18/22 BIT CHANNEL
TEST22::JFCL	OK22B
	MOVSI	T1,(JRST)
	HLLM	T1,TEST22
	SETZ	T4,
	HLRZ	U,SYSUNI##
LOOP22:	LDB	T3,UNYKTP##
	MOVE	J,UNIKON##(U)
	MOVEI	T2,7
	XCT	KONCNO(T3)
	XCT	KONCNI(T3)
	XCT	SKPPIA(T3)
	JRST	LOOP2A
	XCT	SKP22B(T3)
	PUSHJ	P,DCLR22
	PUSHJ	P,DSET22
LOOP2A:	HLRZ	U,UNISYS##(U)
	JUMPN	U,LOOP22

	SKIPN	W,CNFMTK##	;1ST CONTROLLER
	JRST	CHN18B
MTLP22:	MOVE	U,TKBUDB##(W)
	LDB	T3,TUYKTP##	;GET TYPE
	MOVEI	T1,7
	CAIN	T3,2		;TC10?
	TRO	T1,20		;YES, SET LOAD BIT
	CAIN	T3,K.TMB	;TM10B HACK
	MOVEI	T1,70
	XCT	TAPCNO(T3)	;SET PIA
	XCT	TAPCIC(T3)
	XCT	TAPPIA(T3)	;SKIP IF PIA WAS SET
	JRST	MTLP2A
	XCT	TAPCIS(T3)	;GET BITS
	XCT	TAPSKP(T3)	;SKIP IN CORRECT SENSE
	PUSHJ	P,TCLR22
	PUSHJ	P,TSET22
MTLP2A:	HRRZ	W,TKBKDB##(W)
	JUMPN	W,MTLP22
CHN18B:
IFE FT22BIT,<
	SKIPN	T4
	JRST	OK22B
	MOVEI	T1,[ASCIZ/?DF10C IN KI MODE NOT SUPPORTED
SET SWITCH INSIDE THE DF10C TO KA MODE.
/]
	PUSHJ	P,CONOUT	;COMPLAIN TO OPR
	STOPCD	.,STOP,NDC,	;++NO DF10C CODE
>
IFN FT22BIT,<
	SKIPE	FLG256##	;GTR THAN 256K?
	SKIPN	T4		;YES, AN 18-BIT DF?
	JRST	OK22B		;ALL IS OK
;HERE IF AN 18-BIT CHAN AND MORE THAN 256K
	MOVEI	T1,[ASCIZ /%MEMORY ABOVE 256K AND AN 18-BIT DF10!
SYSTEM WILL ONLY USE UP TO 256K.
/]
	PUSHJ	P,CONOUT
	SETZM	FLG256##	;ONLY USE FIRST 256 K
	JRST	OK22B
>;END FT22BIT

;SET/CLEAR KA/KI FLAG

TCLR22:	SKIPA	T2,TKBCDB##(W)	;TAPES
DCLR22:	MOVE	T2,UNICHN##(U)	;DISKS/ETC...
	MOVE	T1,CHB22B##(T2)	;CHAN-TYPE WORD
IFN FTKL10,<
	TLNE	T1,CP.RH2##	;IF AN RH20,
	POPJ	P,		; ALWAYS 22-BIT
>
	TLZ	T1,CP.22B##	;NOT AN RH20, 18-BIT
	MOVEM	T1,CHB22B##(T2)	;CLEAR 22-BIT BIT
	SETO	T4,		;SAY WE'VE SEEN AN 18-BIT CHAN
	JRST	CPOPJ1##	;SKIP RETURN

TSET22:	SKIPA	T2,TKBCDB##(W)
DSET22:	MOVE	T2,UNICHN##(U)
	MOVSI	T1,CP.22B##
	IORM	T1,CHB22B##(T2)	;SET BIT
	POPJ	P,		;RETURN

;TAPE KONTROLLER IOT PNTRS

TAPCNO:	JFCL			;TM10A
	XCT	TTMCOC##(W)	;TM10B
	XCT	TTCCOS##(W)	;TC10C
	XCT	TTXCOS##(W)	;TX01
	XCT	TT2CO1##(W)	;TM02

TAPCIC:	JFCL			;TM10A
	XCT	TTMCIC##(W)	;TM10B
	XCT	TTCCIS##(W)	;TC10C
	XCT	TTXCIS##(W)	;TX01
	XCT	TT2CI2##(W)	;TM02

TAPPIA:	JFCL			;TM10A - NO CHL
	TRNN	T1,70		;TM10B
	TRNN	T1,7		;TC10C
	TRNN	T1,7		;TX01
	TRNN	T2,7		;TM02

TAPCIS:	JFCL			;TM10A
	XCT	TTMCIS##(W)	;TM10B
	XCT	TTCCIS##(W)	;TC10C
	XCT	TTXCIS##(W)	;TX01
	XCT	TT2CI2##(W)	;TM02

IFN FT22BIT,<
TAPSKP:	JFCL			;TM10A
	TLNN	T1,400		;TM10B
	TRNN	T1,40		;TC10C
	SKIPA			;TX01
	TLNN	T2,4000		;TM02
>
IFE FT22BIT,<
TAPSKP:	SKIPA
	TLNE	T1,400
	SKIPA
	SKIPA
	TLNE	T2,4000		;TM02
>

OK22B:
	HRRZ	T1,DSKDSP##+DINI
	PUSHJ	P,(T1)		;SET DISK QUEUES AND CLEAR ALL FLAGS
	CONO	PI,PION##	;TURN PI SYSTEM ON FOR WAITS
BUFSE1:	MOVE	T1,DATADR
	HRRZS	DSKDDB##+DEVSER	;CLEAR LINK SO ONCE WONT LOOP
	PUSHJ	P,SETDDO##	;CREATE A DDB FOR ONCE ONLY I/O
	STOPCD	.,HALT,NMC,	;++NO MORE CORE
	AOS	MQREQ##		;COUNT IT UP, GVMNB WILL COUNT IT DOWN
	PUSHJ	P,GTMNB1##	;GET A MONITOR BUFFER FOR READING "HOME" BLOCKS
	SETZM	SYSSTR##	;INITIALLY THERE ARE NO FILE STRUCTURES IN SYSTEM
	HRRZS	SWPUNI##	;INITIALLY NO UNITS IN ASL
	SETZM	SWPUNM		;CLEAR OUT # UNITS IN ASL WORD
	MOVE	T1,STRAOB##	;CLEAR OUT TABLE OF STR DATA BLOCK ADRS.
	SETZM	TABSTR##(T1)
	AOBJN	T1,.-1
	MOVSI	T1,MSWPMX##	;CLEAR OUT TABLE OF UNIT ADRS. IN ASL
	SETZM	SWPTAB##(T1)
	AOBJN	T1,.-1

	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
	SETZM	ERRHOM		;CLEAR ERROR(S) WHILE READING "HOME" BLOCKS FLAG
SCNUNI:	HRRZ	J,UNIKON##(U)	;GET ADR. OF KONTROLLER DATA BLOCK FOR THIS UNIT
	SKIPGE	KONUPA##(J)	;HAS KONTROLLER BEEN FLAGGED AS DOWN?
	JRST	FLGDWN		;YES - FLAG UNIT AS DOWN ALSO
TRYKON:	PUSHJ	P,@KONUPA##(J)	;SEE IF KONTROLLER IS UP
	  JRST	KDOWN		;KONTROLLER IS OFF-LINE
	JUMPN	T1,KONTOK	;OK IF WRITE-HEADER LOCKOUT IS ON
	JRST	WHLBAD		;IT'S SET WRONG
KDOWN:	MOVEI	T4,[ASCIZ . IS OFF-LINE.]
	HLLZ	P1,UNINAM##(U)	;GET SIXBIT CONTROLLER NAME
	MOVEI	T3,[ASCIZ .DO YOU WANT IT TO BE 1)ON-LINE, OR 2)DOWN? (TYPE #)
.]
	PUSHJ	P,MCKKON	;PRINT MSG & GET ANSWER
	  JRST	TRYKON		;ILLEGAL RESPONSE
	CAIE	T2,2		;WAS "2" TYPED?
	JRST	TRYKON		;NO - CHECK AGAIN IF "1" OR ANYTHING ELSE WAS TYPED
KOPSET:	MOVSI	T1,KOPDWN##	;KONTROLLER DOWN BIT(SIGN BIT)
	IORM	T1,KONDWN##(J)	;FLAG KONTROLLER AS DOWN
	JRST	FLGDWN		;FLAG UNIT DOWN AS WELL

;HERE WHEN THE WHL SWITCH IS SET WRONG
WHLBAD:	MOVSI	T1,KOPWHL##	;WE ALREADY ASK ABOUT SWITCH!
	TDNE	T1,KONUPA##(J)
	JRST	KONTOK		;YES, HE SAID IT WAS OK
	MOVEI	T4,[ASCIZ . WRITE-HEADER-LOCKOUT SWITCH ALLOWS WRITING HEADERS.]
	HLLZ	P1,UNINAM##(U)	;SIXBIT CONTROLLER NAME
	MOVEI	T3,[ASCIZ .DO YOU WANT IT TO BE 1)SET, OR 2)IGNORED? (TYPE#).]
	PUSHJ	P,MCKKON	;PRINT MSG, GET ANSWER
	  JRST	TRYKON		;ILLEGAL ANSWER
	CAIE	T2,2		;TRY AGAIN?
	JRST	TRYKON		;YES
	PUSHJ	P,OFFDWN
	AOSG	DOFLOK
	JRST	WHLBD1
	MOVEI	T1,[ASCIZ .
NOT NORMALLY DONE, ARE YOU SURE?
.]
	PUSHJ	P,ASKQUE
	  JRST	TRYKON		;HE ISN'T SURE
WHLBD1:	MOVSI	T1,KOPWHL##	;INDICATE OPR SAID CONTROLLER
	IORM	T1,KONUPA##(J)	; HAS SWITCH WRONG
;HERE IF KONTROLLER ON-LINE - TO CHECK IF UNIT OK

KONTOK:	MOVSI	T1,UNPOFL##
	TDNE	T1,UNIDES##(U)	;IS UNIT OFF-LINE OR DOWN?
	JRST	SCNUN2		;YES - CONTINUE SCAN ON NEXT UNIT
	SKIPE	.UONCE##	;USER MODE?
	PUSHJ	P,USRCPY##	;YES, CALL USER-MODE ROUTINE
	  JFCL			;USRCPY HAS SKIP RETURN
	SKIPN	.UONCE##
	PUSHJ	P,@KONCPY##(J)	;NO, DETERMINE CAPACITY & TYPE OF UNIT
	  JFCL			;UNIT OFF-LINE (OR NO ILLEGAL SECTOR, OR NO SUCH UNIT)
	MOVEM	T1,UNIBPU##(U)	;BLKS PER UNIT (REGULAR)
	MOVEM	T2,UNIBPM##(U)	;BLKS PER UNIT INCL. MAINT CYLS
IFN FTRP04,<
	MOVEM	T3,UNIBUC##(U)	;BLKS PER UNIT IN COMPAT. MODE
>
	DPB	W,UNYBPY##	;# OF BLOCKS PER CYLINDER
	HLRZ	T3,W		;BLOCKS PER TRACK
	DPB	T3,UNYBPT##	;STORE # OF BLOCKS PER TRACK ON THIS UNIT
	DPB	T4,UNYUTP##	;STORE UNIT TYPE #
IFN FTDUAL,<
	HLRZ	T1,J		;SERIAL NUMBER
	SKIPE	T1		;IF SN = 0 UNISER = 0
	HLL	T1,UNISER##(U)	; ELSE LH=DRIVE TYPE
	MOVEM	T1,UNISER##(U)	;STORE IN UDB
	PUSHJ	P,MATUN##	;ANY OTHER DRIVE WITH SAME NUMBER?
	  JRST	KONTO1		;NO
	HRRZM	U,UNI2ND##(T2)	;POINT MAIN UNIT AT THIS ONE
	HRROM	T2,UNI2ND##(U)	;POINT THIS UNIT AT MAIN UNIT
	PUSHJ	P,UNLUN##	;UNLINK THIS UNIT FROM UNISYS/UNICHN/UNIKON RINGS
	JRST	SCNUN2		;DONT READ HOME BLOCKS, TRY NEXT UNIT
KONTO1:>
	TLNN	T4,KOPUHE##	;UNIT ON-LINE?
	JRST	WCKUNI		;YES, SEE IF IT IS WRITE-ENABLED
	TLNE	T4,KOPNSU##	;WAS THIS NO SUCH UNIT ERROR?
	JRST	FLGDWN		;YES, SKIP QUESTION, FLAG AS DOWN

	MOVEI	T3,[ASCIZ .DO YOU WANT IT TO BE 1)ON-LINE, 2)OFF-LINE, OR 3)DOWN? (TYPE #)
.]
	PUSHJ	P,OFLUNM	;PRINT MSG & GET ANSWER
	  JRST	TRYKON		;ILLEGAL RESPONSE
	CAIN	T2,2		;WAS "2" TYPED?
	JRST	FLGOFL		;YES - FLAG UNIT AS OFF-LINE
	CAIE	T2,3		;WAS "3" TYPED?
	JRST	TRYKON		;NO - CHECK AGAIN IF "1" OR ANYTHING ELSE WAS TYPED
;HERE TO FLAG UNIT AS DOWN & OFF-LINE

FLGDWN:	MOVEI 	T1,UNVDWN##	;VALUE FOR UNIT DOWN
	JRST	FLGOFF		;ALSO SET OFF-LINE STATUS BIT

;HERE TO FLAG UNIT AS OFF-LINE ONLY AND NO PACK MOUNTED
FLGOFL:	MOVEI	T1,UNVNPM##	;SET STATUS TO NO PACK MOUNTED
				; SO RES COMMAND WILL PRINT AS AVAIL.
FLGOFF:	DPB	T1,UNYUST##	;STORE UNIT STATUS(DOWN OR NO PACK MOUNTED)
	MOVSI	T1,UNPOFL##	;OFF-LINE BIT
	IORM	T1,UNIDES##(U)	;SET BIT IN LH. OF UNIDES WORD
	SETZB	T1,UNILOG##(U)	;MAKE SURE NOT IN STR FLAG CLEARED
				;COULD HAVE BEEN SET IF UNIT TURNED
				;OFF AND THE ONCE ONLY RESTARTED
	DPB	T1,UNYSIC##	;MAKE SURE NO SATS IN CORE SO WONT ADJUST
				;SAB'S LATER. COULD ALSO HAPPEN AS ABOVE
	MOVEI	T1,O2COD##	;IF DEVICE DOES POSITIONS,
	SKIPL	KONPOS##(J)	; WE'LL GET AN INTERRUPT WHEN IT COMES UP,
	MOVEM	T1,UNISTS##(U)	; SO MARK IT DOWN FOR NOW
	SETZM	UNISTR##(U)	;IN CASE IT WAS UP, <ALT> TYPE
	JRST	SCNUN2		;CONTINUE SCAN ON NEXT UNIT
;HERE IF UNIT ON-LINE - TO CHECK IF UNIT WRITE ENABLED

WCKUNI:	LDB	P2,UNYKTP##	;GET KONTROLLER TYPE
	PUSHJ	P,@ONCHWP(P2)	;SEE IF UNIT WRITE PROTECTED
	  JRST	CHKHOM		;UNIT IS WRITE ENABLED - GO READ "HOME" BLOCK
	MOVEI	T3,[ASCIZ .DO YOU WANT IT TO BE 1)WRITE-ENABLED, OR 2)WRITE-PROTECTED? (TYPE #)
.]
	PUSHJ	P,WRPUNM	;PRINT MSG & GET ANSWER
	  JRST	TRYKON		;ILLEGAL RESPONSE
	CAIE	T2,2		;WAS "2" TYPED?
	JRST	TRYKON		;NO - CHECK AGAIN IF "1" OR ANYTHING ELSE WAS TYPED
WCKSET:	MOVSI	T1,UNPHWP##	;HARDWARE WRITE-PROTECT BIT
	IORM	T1,UNIDES##(U)	;FLAG UNIT AS WRITE PROTECTED
;HERE IF UNIT ON-LINE & LEGALLY WRITE PROTECTED OR ENABLED - CHECK ITS "HOME" BLOCKS

CHKHOM:
	MOVEI	T1,UNVPIM##	;IF WE READ HOME BLOCKS
	DPB	T1,UNYUST##	;A PACK MUST BE MOUNTED
IFN FTRP04,<
	LDB	T1,UNYKTP##
	CAIE	T1,TYPRP##	;IF THIS IS AN RP04
	JRST	CHKHM1
	MOVEI	T2,0		;FORMAT ERROR CAN ONLY BE DETECTED
	PUSHJ	P,OMNRED	; ON SECTOR 0, SO READ IT
	TRNE	S,IODTER	;IODTER = IODERR = 1
	TRNN	S,IODERR	; MEANS FORMAT ERROR (PDP-11 PACK)
	JRST	CHKHM1
	MOVEI	T1,[ASCIZ .
PDP-11 PACK MOUNTED - UNIT CONSIDERED OFF-LINE
.]
	PUSHJ	P,SVMOUT
	JRST	FLGOFL
CHKHM1:>
	SKIPE	KON		;SKIP IF NOT SHORT DIALOG OPTION 1
	JRST	SCNUN2		;SKIP THIS PART IF IT IS OPTION 1
	PUSHJ	P,GTHOM		;GET "HOME" BLOCK INTO CORE
	  CAIA			;ERROR(S) ON BOTH "HOME" BLOCKS - T2 RETURNED NON 0
	JRST	HMBOK		;AT LEAST ONE "HOME" BLOCK OK
	MOVSI	T2,UNPHWP##
	SETZM	HOMSIC##(P1)	;0 SAT BLOCKS IN CORE FOR THIS UNIT(FOR CRESAB CODE)
	MOVEI	T1,[ASCIZ .
DO YOU WANT TO INITIALIZE THE HOME BLOCKS ON THIS UNIT?
.]
	TDNE	T2,UNIDES##(U)
	JRST	ASIS
	SKIPE	SHUTUP
	JRST	.+3
	PUSHJ	P,ASKQUE
	JRST	ASIS
	MOVE	T1,P1		;USE ANOTHER AC AS P1 IS NEEDED
	SETZM	(T1)		;CLEAR 1ST. WORD OF IN CORE "HOME" BLOCK
	HRLS	T1		;MAKE A BLT PTR. TO CLEAR ALL OF "HOME" BLOCK
	ADDI	T1,1
	BLT	T1,BLKSLF##(P1)	;CLEAR "HOME" BLOCK
	MOVEM	P2,BLKNAM##(P1)	;STORE SIXBIT "HOM"
	MOVEM	P3,BLKCOD##(P1)	;STORE "HOME" BLOCK CODE
	MOVEM	P4,HOMHOM##(P1)	;STORE LOG. BLOCK #'S OF "HOME" BLOCKS
	SETOM	HOMSUN##(P1)	;INDICATE UNIT NOT IN ASL
	SETOM	HOMSRC##(P1)	;INDICATE STR THIS UNIT WILL BE IN
				; WILL NOT BE IN "SYS" SEARCH LIST
	LDB	T1,UNYUTP##
	MOVEM	T1,HOMUTP##(P1)	;SET RIGHT UNIT IN HOME BLOCK
	PUSHJ	P,WRTRUN	;WRITE BOTH "HOME" BLOCKS
	  JFCL			;IGNORE ERRORS - FOR THE MOMENT
ASIS:	PUSHJ	P,SETCHG	;FLAG THAT THIS UNIT'S "HOME" BLOCK MUST BE REWRITTEN
	PUSHJ	P,MOVUNI	;MOVE PARAMS FROM "HOME" BLOCK TO UNIT DATA BLOCK
	JRST	NOSTR		;TRY & SETUP SAB RING & SPT TABE FOR UNIT
OFFDWN:	SKIPE	OPTQIK		;SEE IF QUICK OPTION
	SETOM	DOFLOK		;YES--SET DEFAULT FLAG
	SKIPN	SHUTUP
	SKIPGE	DEBUGF##	;IS SYS PROG DEBUGGING?
	SETOM	DOFLOK		;YES--SET DEFAULT FLAG
	POPJ	P,


;HERE IF "HOME" BLOCK(S) READ INTO CORE OK
; GENERATE STR DATA BLOCK & LINK UNIT DATA BLOCKS CORRECTLY

HMBOK:	JUMPN	T2,HMBOK2	;FLAG REWRITE HOME BLOCKS IF ERRORS
	LDB	T2,UNYKTP##	;GET KONTROLLER TYPE
	CAIE	T2,TYPDP##	;SKIP IF RP10
	JRST	HMBOK3		;NOT RP10 PROCEED
	LDB	T1,UNYUTP##	;GET UNIT TYPE TO MAKE SURE PACK IS
	CAIE	T1,2		; COMPATIBLE, SKIP IF RP03
	JRST	HMBOK3		;NOT RP03, PROCEED
	CAMN	T1,HOMUTP##(P1)	;SINCE RP03 DRIVE CAN READ RP02 PACKS
	JRST	HMBOK3		;PACK WRITTEN BY RP03, PROCEED
				;WRONG PACK! NOTIFY OPERATOR.
	MOVEI	T3,[ASCIZ . DO YOU WANT IT TO BE 1)ON-LINE, 2)OFF-LINE, OR 3)DOWN? (TYPE #)
.]
	MOVEI	T4,[ASCIZ . IS RP03 DRIVE, PACK WRITTEN ON RP02.]
	MOVE	P1,UNINAM##(U)	;GET SIXBIT UNIT NAME
	MOVEI	T1,[ASCIZ .
%.]
	PUSHJ	P,NASTYP	;PRINT MESSAGE AND GET RESPONSE
	JRST	TRYKON		;ILLEGAL RESPONSE
	CAIN	T2,2		;WAS "2" TYPED?
	JRST	FLGOFL		;YES, FLAG AS OFF-LINE
	CAIE	T2,3		;WAS "3" TYPED?
	JRST	TRYKON		;NO, CHECK AGAIN IF "1" OR SOMETHING ELSE
	JRST	FLGDWN		;WAS "3", FLAG AS DOWN.
HMBOK2:	PUSHJ	P,SETCHG	;FLAG HOME BLOCKS NEED REWRITING
HMBOK3:	PUSHJ	P,MOVUNI	;MOVE PARAMS FROM "HOME" BLOCK TO UNIT DATA BLOCK
	MOVEI	P2,0		;SET STR DATA BLOCK ADR. = 0 IN CASE NO STR FOUND
	MOVE	T1,HOMSNM##(P1)	;GET STR NAME FROM HOME BLOCK
	JUMPE	T1,OLDSTR	;DON'T LOOK FOR OR CREATE A ZERO STR NAME
	PUSHJ	P,FNSTR		;FIND STR(IF IT EXISTS)
	  CAIA			;NOT FOUND
	JRST	OLDSTR		;FOUND - GO SEE IF THIS UNIT IN ACTIVE SWAPPING LIST
	PUSHJ	P,GETSTR	;CREATE STR DATA BLOCK IN UPPER CORE
	  JRST	NOSTR		;ATTEMPT TO CREATE MORE STR'S THAN ALLOWED
	PUSHJ	P,MOVSTR	;MOVE PARAMS FROM "HOME" BLOCK TO STR DATA BLOCK
;HERE WHEN STR UNIT BELONGS IN ALREADY EXISTS - SEE IF UNIT IS IN ASL

OLDSTR:	SKIPL	P4,UNISUN##(U)	;IS UNIT IN ACTIVE SWAPPING LIST?
	CAMLE	P4,MAXSWP##	;ABOVE HIGHEST LEGAL UNIT?
	JRST	NOTISL		;NO - TRY TO LINK UNIT WITH OTHER UNITS IN STR
	SKIPE	HOMSID##(P1)	;IS UNIT LAST UNIT IN SWAPPING LIST?
	JRST	NOTLSL		;NO
	SKIPN	SWPUNM		;HAS THERE ALREADY BEEN A LAST UNIT?
	JRST	LSTASL		;NO - GO INDICATE THAT THERE HAS NOW
	MOVEI	T1,[ASCIZ .
?MORE THAN ONE LAST UNIT IN ACTIVE SWAPPING LIST.]
	PUSHJ	P,SVMOTE	;O/P MSG. & ADD CRLF & SET ERRHOM

;HERE WHEN UNIT READ IS THE LAST IN THE ACTIVE SWAPPING LIST

LSTASL:	MOVEM	P4,SWPUNM	;STORE LOG. # OF LAST UNIT IN ASL
	AOS	SWPUNM		;MAKE IT # OF UNITS IN ASL

;HERE WHEN UNIT READ IS NOT LAST IN THE ACTIVE SWAPPING LIST
; LINK UNIT TO OTHER UNITS IN ASL & STORE ITS DATA BLOCK ADR. IN SWPTAB

NOTLSL:	MOVEI	T4,SWPUNI##	;GET ADR. OF LINK TO 1ST. UNIT DATA BLOCK IN ASL
	JRST	SINKT1
SINKIT:	MOVE	T3,UNISUN##(T1)	;GET LOG. UNIT # OF NEXT UNIT IN ASL
	CAMLE	T3,P4		;IS IT GREATER THAN UNIT JUST READ?
	JRST	INSENT		;YES - INSERT UNIT DATA BLOCK HERE
	MOVEI	T4,UNISWP##(T1)	;GET ADR. OF LINK TO NEXT UNIT
SINKT1:	HLRZ	T1,(T4)		;GET ADR. OF NEXT UNIT DATA BLOCK IN ASL
	JUMPN	T1,SINKIT	;MORE DATA BLOCKS?
INSENT:	HRLM	T1,UNISWP##(U)	;SAVE LINK TO NEXT UNIT DATA BLOCK
	HRLM	U,(T4)		;SAVE THIS UNIT ADR. IN PREVIOUS UNIT DATA BLOCK
				; (OR SWPUNI)
	MOVEM	U,SWPTAB##(P4)	;PUT THIS UNIT DATA BLOCK ADR. IN ASL
	SKIPN	T2,SWPUN2##	;SLOW SWAPPING CLASS SET?
	JRST	INSEN1		;NO, CAUSE THIS TO BE IT
	LDB	T1,UNYCFS##
	SUBI	T1,(T2)		;YES, THIS UNIT IN LOWER CLASS?
	JUMPL	T1,NOTISL	;IF SO IGNORE IT
	JUMPN	T1,INSEN1	;IF IN HIGER CLASS USE IT
	HLRS	T2		;IF IN SAME CLASS
	CAML	P4,UNISUN##(T2)	; IF LOWER IN ASL USE IT
	JRST	NOTISL
INSEN1:	HRLM	U,SWPUN2##	;SAVE UNIT
	LDB	T1,UNYCFS##
	HRRM	T1,SWPUN2##	;SAVE CLASS
;HERE WHEN UNIT READ IS NOT IN THE ACTIVE SWAPPING LIST

NOTISL:	JUMPE	P2,NTISTR	;IF UNIT NOT IN STR SETUP SAB RING & SPT TABLE
	LDB	T2,UNYLUN##	;GET LOGICAL UNIT # WITHIN STR
	SKIPE	HOMNXT##(P1)	;IS THIS LAST UNIT IN STR?
	JRST	NLSUNI		;NO - GO LINK UNIT DATA BLOCK INTO STR
	HRRZ	T1,STRUNM##(P2)	;HAVE WE ALREADY SEEN A LAST UNIT FOR THIS STR?
	JUMPE	T1,LSTUNI	;NO - NOW WE HAVE
	PUSH	P,T2		;SAVE LOG. UNIT #
	MOVEI	T1,[ASCIZ .
?MORE THAN ONE LAST UNIT IN STR .]
	PUSHJ	P,MSGSTR	;PRINT MSG FOLLOWED BY SIXBIT STR NAME
	POP	P,T2		;RESTORE LOG. UNIT #

;HERE WHEN UNIT READ IS THE LAST IN AN STR

LSTUNI:	ANDI	T2,77		;MAX. OF 64 UNITS IN STR!!!!!!!
	HRRM	T2,STRUNM##(P2)	;STORE LOG. # OF LAST UNIT IN STR
	AOS	STRUNM##(P2)	;LEAVE T2 ALONE BUT MAKE MEMORY OK

;HERE WHEN UNIT READ ISN'T LAST IN THE STR
; LINK UNIT TO STR & OTHER UNITS IN STR

NLSUNI:	MOVEI	T4,STRUNI##(P2)	;GET ADR. OF LINK TO 1ST. UNIT DATA BLOCK IN STR
	JRST	LINKT1
LINKIT:	LDB	T3,UNYLN1##	;YES - GET LOG. UNIT # OF NEXT UNIT
	CAMLE	T3,T2		;IS IT GREATER THAN UNIT JUST READ?
	JRST	INSERT		;YES - INSERT UNIT DATA BLOCK HERE
	MOVEI	T4,UNISTR##(T1)	;GET ADR. OF LINK TO NEXT UNIT
LINKT1:	HLRZ	T1,(T4)		;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	JUMPN	T1,LINKIT	;MORE DATA BLOCKS?
INSERT:	HRLM	T1,UNISTR##(U)	;SAVE LINKS TO STR & NEXT UNIT DATA BLOCK
	HRRM	P2,UNISTR##(U)	; IN THIS UNIT DATA BLOCK
	HRLM	U,(T4)		;SAVE THIS UNIT ADR. IN PREVIOUS UNIT DATA BLOCK
				; (OR STR DATA BLOCK)
	JRST	CRESAB		;TRY & SETUP SAB RING & SPT TABLE FOR THIS UNIT
;HERE TO CREATE RING OF SAB BLOCKS FOR THIS UNIT

NOSTR:	SETOM	UNISUN##(U)	;INDICATE UNIT NOT IN ASL
	SETOM	ERRHOM		;INDICATE ERROR IN "REDHOM"
NTISTR:	SETZM	UNILOG##(U)	;INDICATE UNIT NOT IN AN STR
CRESAB:	LDB	P1,UNYSIC##	;GET # SATS TO BE IN CORE FOR THIS UNIT
	JUMPLE	P1,SCNUN1	;DON'T TRY TO SETUP ANYTHING IF 0 OR -VE
	PUSHJ	P,CMCWPS	;COMPUTE # CLUSTERS & WORDS PER SAT
	LDB	P3,UNYWPS##	;GET # WORDS PER SAT
	MOVN	P2,P3		;MAKE -VE
	HRLZS	P2		;SETUP LH. OF PTR. FOR SABSCN
	ADDI	P3,SABBIT##	;COMPUTE # WORDS FOR EACH SAB BLOCK
	MOVEI	P4,DIFSAB##(U)	;SETUP ADR. OF LINK TO 1ST. SAB BLOCK IN RING
CRESB1:	MOVE	T2,P3		;SETUP ARG. FOR CORE GRABBER
	PUSHJ	P,CORGRB	;GET CORE
	HRLZM	T1,SABRNG##(P4)	;STORE LINK FROM PREVIOUS TO CURRENT SAB
	MOVE	P4,T1		;PREVIOUS SAB _ CURRENT SAB
	HRRI	P2,SABBIT##(P4)	;FILL IN RH. OF AOBJN PTR.
	MOVEM	P2,SABSCN##(P4)	;STORE IT IN THIS SAB BLOCK
	SKIPN	UNILOG##(U)
	SETZM	SABFIR##(P4)
	SOJG	P1,CRESB1	;LOOP IF ANY MORE SATS
	HLRZ	T1,UNISAB##(U)	;GET ADR. OF 1ST. SAB BLOCK IN RING
	HRLM	T1,SABRNG##(P4)	;MAKE LAST POINT TO FIRST
;HERE TO CREATE SPT TABLE AND SWAPPING SAT TABLE FOR THIS UNIT

SPTSSB:	LDB	P3,UNYSPU##	;GET # SATS ON THIS UNIT
	ADDI	P3,SPTFIR##+1	;COMPUTE LENGTH OF SPT TABLE
	LDB	T2,UNYK4S##	;GET # K FOR SWAPPING ON THIS UNIT
IFN <FTKI10!FTKL10><
	LSH	T2,K2PLSH##	;DOUBLE SIZE IF SWAPPING PAGES
>
IFN FTVM,<
	ADDI	T2,1
>
	ADDI	T2,^D35		;COMPUTE LENGTH OF SWAPPING SAT TABLE
	SKIPGE	UNISUN##(U)	;IS UNIT IN ASL?
	MOVEI	T2,0		;NO, DONT GET SWAP-SAT SPACE
	IDIVI	T2,^D36
	MOVN	T1,T2		;MAKE LENGTH -VE FOR AOBJN WORD
	HRLM	T1,UNIPTR##(U)	;STORE IT IN UNIT DATA BLOCK
	LSH	T2,1		;DOUBLE ALLOCATION FOR COPY FOR 143 RESTARTS
	ADD	T2,P3		;COMPUTE # WORDS FOR SAT TABLE & SPT TABLE
	PUSHJ	P,CORGRB	;GET CORE
	HRRM	T1,UNISPT##(U)	;STORE ADR. OF SPT TABLE IN UNIT DATA BLOCK
	ADDI	T1,-1(P3)	;COMPUTE ADR. OF LAST WORD IN SPT TABLE
	SETZM	(T1)		;ZERO IT TO INDICATE END OF TABLE
	ADDI	T1,1		;COMPUTE ADR. OF SWAPPING SAT TABLE
	HRRM	T1,UNIPTR##(U)	;STORE IT IN UNIT DATA BLOCK FOR AOBJN WORD
SCNUN1:	SKIPN	UNILOG##(U)	;SKIP IF UNIT IS IN A FILE STRUCTURE
	JRST	SCNUN2		;NOT IN A FILE STRUCTURE
	HRRZ	P2,UNISTR##(U)	;ADDR OF STR DATA BLOCK
	HLLZ	T1,STRREF##(P2)	;NEEDS REFRESHING FLAG
	JUMPN 	T1,SCNUN2	;NO MFD IF NEEDS REFRESHING
	HRRZ	P1,DEVMBF##(F)	;ADDR FROM IOWD PTR TO HOME BLOCK
	ADDI	P1,1
	LDB	T2,UNYLUN##	;LOGICAL UNIT IN FILE STRUCTURE
	CAME	T2,HOMUN1##(P1)	;SKIP IF MFD STARTS ON THIS UNIT
	JRST	SCNUN2
	IMUL	T2,STRBPU##(P2)	;T2=1ST LOGICAL BLOCK ON THIS UNIT
	SUB	T2,HOMMFD##(P1)	;MINUS BLOCK FOR MFD RIB
	MOVNS	T2		;T2=BLOCK ON UNIT FOR MFD RIB
	PUSHJ	P,OMNRED	;READ MFD RIB
	STOPCD	SCNUN2,DEBUG,ERM, ;++ERROR READING MFD
	HRRZ	T1,P1		;ADDR OF 1ST WORD OF MFD RIB
	ADD	T1,(P1)		;PTR TO 1ST RETRIEVAL PTR
	SKIPE	2(T1)		;SKIP IF ONLY 1 PTR
	JRST	SCNUN2
	MOVEI	T1,STP1PT##	;ONLY 1 PTR BIT
	ORM	T1,STR1PT##(P2)
SCNUN2:	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT DATA BLOCK ADR. IN SYSTEM
	JUMPN	U,SCNUNI	;AROUND AGAIN IF ANY LEFT
	SKIPE	KON		;SKIP IF NOT OPTION 1 OF SHORT DIALOG
	POPJ	P,		;RETURN , YOU WERE PUSHJ ED TO.
;HERE WHEN ALL UNITS IN SYSTEM HAVE TRIED TO BE READ
; NOW CHECK THAT THE ACTIVE SWAPPING LIST LOOKS CORRECT

SCNASL:	HLRZ	U,SWPUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN ASL
	JUMPN	U,SOMUSL	;ARE THERE ANY UNITS IN ASL?
	MOVEI	T1,[ASCIZ .
?NO UNITS IN ACTIVE SWAPPING LIST.]
	PUSHJ	P,SVMOTS	;O/P MSG. & ADD CRLF & SET ERRHOM
	JRST	SCNSTR		;GO CHECK STRS

;HERE WHEN THERE IS AT LEAST ONE UNIT IN ASL

SOMUSL:	MOVE	T1,SWPUNI##	;FIRST UNIT IN ASL
	CAIG	T1,7		;IS THERE ONE?
	HLRS	SWPUNI##	;NO, ALL SWAPPING IS FAST
	MOVEI	T1,[ASCIZ .
%LAST UNIT IN ACTIVE SWAPPING LIST NOT FOUND.]
	SKIPN	SWPUNM		;LAST UNIT IN ASL FOUND?
	PUSHJ	P,SVMOTE	;NO - O/P MSG. & ADD CRLF & SET ERRHOM
LSTUSL:	SETOM	P4		;SETUP FAKE PREVIOUS LOGICAL UNIT #
CHKUSL:	MOVE	P1,UNISUN##(U)	;GET LOG. UNIT # IN ASL OF THIS UNIT
	EXCH	P1,P4		;PUT THIS & PREVIOUS LOG. UNIT #'S IN PROPER ACS
	CAME	P4,P1		;ARE LOG. UNIT #'S THE SAME
	JRST	MISUSL		;NO - SEE IF ANY LOG. UNITS MISSING FROM ASL
	MOVEI	T1,[ASCIZ .
?TWO LOGICAL UNIT .]
	PUSHJ	P,TYPMSN	;TYPE MSG. FOLLOWED BY A DECIMAL #
	MOVEI	T1,[ASCIZ .'S FOUND IN ACTIVE SWAPPING LIST.]
	PUSHJ	P,SVMOTS	;O/P MSG. & ADD CRLF & SET ERRHOM
	JRST	CHKUS1		;CHECK NEXT PAIR OF UNITS

MISUSL:	CAIN	P4,1(P1)	;IS THIS UNIT 1 GREATER THAN PREVIOUS UNIT
	JRST	CHKUS1		;YES - CHECK NEXT PAIR OF UNITS
	ADDI	P1,1		;INCREMENT TO GET CORRECT MISSING LOG. UNIT #
	MOVEI	T1,[ASCIZ .
%LOGICAL UNIT .]
	PUSHJ	P,TYPMSN	;TYPE MSG. FOLLOWED BY A DECIMAL #
	MOVEI	T1,[ASCIZ . MISSING FROM ACTIVE SWAPPING LIST.]
	PUSHJ	P,SVMOTE	;O/P MSG. & ADD CRLF & SET ERRHOM
	JRST	MISUSL		;REPEAT UNTIL ALL MISSING ARE TYPED OUT

CHKUS1:	HLRZ	U,UNISWP##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN ASL
	JUMPN	U,CHKUSL	;REPEAT IF ANY LEFT
;HERE WHEN ALL UNITS IN SYSTEM HAVE TRIED TO BE READ &
; ALL STR DATA BLOCKS HAVE BEEN CREATED THAT CAN BE.
; NOW CHECK THAT ALL UNITS THAT SHOULD BE ARE PRESENT IN ALL STR'S

SCNSTR:	HLRZ	P2,SYSSTR##	;GET ADR. OF 1ST. STR DATA BLOCK IN SYSTEM
	JUMPE	P2,CPOPJ##	;THERE ARE NONE - NON SKIP RETURN
SCNST1:	HRRZ	T1,STRUNM##(P2)
	JUMPN	T1,LSTRED	;WAS THE LAST UNIT IN THIS STR FOUND?
	MOVEI	T1,[ASCIZ .
?LAST UNIT WASN'T FOUND IN STR .]
	PUSHJ	P,MSGSTR	;NO - PRINT MSG. FOLLOWED BY SIXBIT STR NAME
	HLRZ	T1,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
SCNST2:	MOVE	U,T1
	HLRZ	T1,UNISTR##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	JUMPN	T1,SCNST2	;REPEAT UNTIL LAST ONE FOUND
	LDB	T1,UNYLUN##	;GET ITS LOG. UNIT # IN STR
	ADDI	T1,1		;MAKE INTO # UNITS IN STR
	HRRM	T1,STRUNM##(P2)	; & STORE IT
	HRRZS	STRREF##(P2)	;CLEAR 'STR NEEDS REFRESHING' FLAG SET BY MSGSTR

;HERE TO CHECK FOR THE PRESENCE OF ALL UNITS BUT THE LAST IN AN STR

LSTRED:	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN THIS STR
	SETOM	P4		;SETUP FAKE PREVIOUS LOG. UNIT #
	CAIA
CHKUNI:	HLLM	T2,UNIGRP##(U)	;STORE # CONSEC. CLUSTERS TRIED  ON O/P IN EACH UNIT
	LDB	P1,UNYLUN##	;GET LOG. UNIT # OF THIS UNIT WITHIN STR
	EXCH	P1,P4		;PUT THIS & PREVIOUS LOG. UNIT #'S IN PROPER ACS
	CAME	P4,P1		;ARE LOG. UNIT #'S THE SAME?
	JRST	MISUNI		;NO - CHECK FOR MISSING UNITS
	MOVEI	T3,[ASCIZ .
?TWO LOGICAL UNIT .]
	MOVEI	T1,[ASCIZ .'S FOUND IN STR .]
	PUSHJ	P,MSGLNG	;PRINT MSGS FOLLOWED BY SIXBIT STR NAME
	JRST	CHKUN1		;CHECK NEXT PAIR OF UNITS

MISUNI:	CAIN	P4,1(P1)	;IS THIS UNIT 1 GREATER THAN LAST ONE?
	JRST	CHKUN1		;YES - CHECK NEXT PAIR OF UNITS
	ADDI	P1,1		;INCREMENT TO GET CORRECT MISSING LOG. UNIT #
	MOVEI	T3,[ASCIZ .
?LOGICAL UNIT .]
	MOVEI	T1,[ASCIZ . MISSING FROM STR .]
	PUSHJ	P,MSGLNG
	JRST	MISUNI		;REPEAT UNTIL ALL MISSING ARE TYPED OUT
CHKUN1:	MOVE	T1,UNIBPU##(U)	;GET # BLOCKS ON THIS UNIT
	ADDM	T1,STRSIZ##(P2)	;ADD TO TOTAL # IN THIS STR
	MOVE	T1,STRBPU##(P2)	;GET # OF BLOCKS ON LARGEST UNIT IN STR
	ADDM	T1,STRHGH##(P2)	;ADD TO TOTAL LOGICAL # IN THIS STR
	HLL	T2,UNIGRP##(U)	;GET # OF CONSECUTIVE CLUSTERS TRIED FOR ON O/P
	HLRZ	U,UNISTR##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	JUMPN	U,CHKUNI
	SOS	STRHGH##(P2)	;MAKE STRHGH BE HIGHEST LOG. BLOCK # IN STR
;HERE WHEN THROUGH CHECKING ALL UNITS WITHIN AN STR

	HLRZ	P2,STRSYS##(P2)	;GET NEXT STR DATA BLOCK ADR. WITHIN SYSTEM
	JUMPN	P2,SCNST1	;REPEAT IF THERE IS ONE
	SETOM	SRCFLG		;SETUP FAKE PREVIOUS LOG. STR #
	MOVE	P4,[PUSHJ P,CHKSRC]	;SETUP INSTR. FOR XCT IN FNDSRC
	PUSHJ	P,FNDSRC	;GO CHECK "SYS" SEARCH IS OK
	MOVEI	T1,[ASCIZ .
?NO STR'S IN SYS SEARCH LIST.]
	SKIPGE	SRCFLG		;SKIP IF ANY STRS IN SYS SEARCH LIST
	PUSHJ	P,SVMOTS	;NO, TYPE MESSAGE
	SKIPN	ERRHOM		;ANY ERRORS?
	AOS	(P)		;NO - SKIP RETURN
	POPJ	P,

ERRHOM:	0			;FLAG FOR ERRORS WHILE READING A "HOME" BLOCK

SWPUNM:	0			;# OF UNITS IN ACTIVE SWAPPING LIST - 0 MEANS:-
				; 1)EMPTY LIST OR 2)LAST UNIT IN LIST NOT YET READ

SRCFLG:	-1			;CONTAINS PREVIOUS LOG. STR #(INITIALLY -1)
SERIUS:	0			;-1 WHEN CAN'T START SYSTEM EVEN IF
				; QUICK OPTION (SERIOUS ERROR)
;SUBROUTINE TO CHECK WHETHER ANY LOGICAL STRS ARE MISSING OR DUPLICATED IN  SYSSRC

CHKSRC:	PUSHJ	P,SAVE4##	;SAVE P1-P4
	MOVE	P4,SRCFLG	;SETUP FAKE PREVIOUS LOG. STR #
	MOVE	P1,T1		;GET LOG. STR # OF THIS STR WITHIN "SYS" SEARCH LIST
	CAILE	P1,.SLMXS	;GREATER THAN ALLOWED?
	MOVEI	P1,.SLMXS	;YES - SET IT TO BE MAX.
	EXCH	P1,P4		;PUT THIS & PREVIOUS LOG. STR #'S IN PROPER ACS
	CAME	P4,P1		;ARE THEY THE SAME?
	JRST	MISSRC		;NO - CHECK FOR MISSING LOG. STR #'S
	MOVEI	T1,[ASCIZ .
?TWO LOGICAL STR .]
	PUSHJ	P,TYPMSN	;TYPE MSG. FOLLOWED BY A DECIMAL #
	MOVEI	T1,[ASCIZ .'S FOUND IN "SYS" SEARCH LIST.]
	PUSHJ	P,SVMOTE	;O/P MSG. & ADD CRLF & SET ERRHOM
	JRST	CHKSR1		;CHECK NEXT PAIR OF LOG. STR #'S

MISSRC:	CAIN	P4,1(P1)	;IS LOG. STR # 1 GREATER THAN LAST ONE?
	JRST	CHKSR1		;YES - CHECK NEXT PAIR OF LOG. STR #'S
	ADDI	P1,1		;INCREMENT TO GET CORRECT MISSING LOG. STR #
	MOVEI	T1,[ASCIZ .
%LOGICAL STR # .]
	PUSHJ	P,TYPMSN	;TYPE MSG. FOLLOWED BY A DECIMAL #
	MOVEI	T1,[ASCIZ . MISSING FROM "SYS" SEARCH LIST.]
	PUSHJ	P,SVMOTE	;O/P MSG. & ADD CRLF & SET ERRHOM
	JRST	MISSRC		;REPEAT UNTIL ALL MISSING ARE TYPED OUT

CHKSR1:	MOVEM	P4,SRCFLG	;SAVE CURRENT LOG. STR #
	POPJ	P,		;EXIT
WRPUNM:	SKIPA	T4,[[ASCIZ . IS WRITE PROTECTED.]]
OFLUNM:	MOVEI	T4,[ASCIZ . IS OFF-LINE.]
	MOVE	P1,UNINAM##(U)	;GET SIXBIT UNIT NAME
	MOVEI	T1,[ASCIZ .
%.]
	PUSHJ	P,OFFDWN	;FOR SPECIAL CASE SETTING OF DOFLOK
	PJRST	NASTYP		;TYPE MSGS. & GET USER'S RESPONSE


;SUBROUTINE TO PRINT "CONTROLLER" FOLLOWED BY A "NAME"
; FOLLOWED BY A MESSAGE ASKING WHAT STATE OF THE KONTROLLER IS DESIRED
; THEN IT WAITS FOR OPERATOR TO TYPE AN OCTAL NUMBER TERMINATED BY CRLF
;CALL	MOVE	P1,SIXBIT KONTROLLER NAME
;	MOVEI	T3,MSG. ADR.
;	PUSHJ	P,MCKKON
;	  ERROR RETURN	MSG. PRINTED BUT RESPONSE WASN'T AN OCTAL #
;	OK RETURN	 "      "    T2 CONTAINS OCTAL # TYPED

MCKKON:	MOVEI	T1,[ASCIZ .
%CONTROLLER .]
	PUSHJ	P,OFFDWN	;SET DOFLOK IF APPROPRIATE
NASTYP:	SKIPGE	DEBUGF##	;SEE IF DEBUGGING
	JRST	NASTY1		;YES--SKIP MESSAGE
	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	PUSH	P,T3		;SAVE 2ND. MSG ADR.
	PUSH	P,T4		;SAVE 1ST. MSG. ADR.
	PUSHJ	P,ICONM##	;PUT MSG IN BUFFER
	MOVE	T2,P1		;GET UNIT/KONTROLLER SIXBIT NAME
	PUSHJ	P,PRNAME##	;PUT IT IN BUFFER
	POP	P,T1		;RESTORE 1ST. MSG. ADR.
	PUSHJ	P,CONMES##	;PUT MSG. IN BUFFER
	PUSHJ	P,CRLFOP	;ADD CRLF & O/P MSG.
	POP	P,T1		;RESTORE 2ND. MSG ADR.
NASTY1:	MOVEI	T2,2		;PRESET DEFAULT
	AOSG	DOFLOK		;SEE IF NEED DEFAULT
	JRST	CPOPJ1##	;YES--RETURN
	PUSHJ	P,CONOUT	;O/P MSG. & ADD CRLF
	PUSHJ	P,GETLIN##	;GET USER'S RESPONSE
	  POPJ	P,		;CR TYPED
	PUSHJ	P,ALTM		;ALTMODE TYPED? IF SO, NEVER RETURN.
	PUSHJ	P,OCTIN##	;READ IT AS AN OCTAL NO.
	  POPJ	P,		;NOTHING BUT A BREAK CH.
	  POPJ	P,		;ILLEGAL CH.
	JRST	CPOPJ1##	;OK RETURN WITH NO. IN T2
;*** DISPATCH TABLES FOR UNIT ON-LINE & WRITE PROTECT TESTING ***


ONCHWP:	XWD	ZERO5,DRMHWP
	XWD	ZERO5,FHDHWP
	XWD	ZERO5,DPCHWP
	XWD	ZERO5,MDFHWP
	XWD	ZERO5,FSDHWP
	XWD	ZERO5,RPXHWP

DRMHWP:
DRMHLT:	STOPCD	.,HALT,IDC,	;++IMPOSSIBLE DRUM CONDITION


DPCHWP:	PUSHJ	P,DPXSTS##	;GET STATUS FOR THIS UNIT IN T2
	TLNE	T2,2		;WRITE PROTECT ON?
	AOS	(P)		;YES -SKIP
	POPJ	P,		;RETURN


FHDHWP:

MDFHWP:	POPJ	P,

FSDHWP:	POPJ	P,

RPXHWP:
IFN FTKL10,<
	PUSHJ	P,RPXSTW##	;MASSBUS ENABLE IF AN RH20
>
	MOVSI	T2,10000	;READ STATUS REGISTER
	PUSHJ	P,DODTI4##
	TRNE	T2,4000
	AOS	(P)		;WRITE LOCKED
	POPJ	P,		;RETURN
IFE FTDHIA,<

;HERE TO CHECK THE CAPACITY & STATUS OF A UNIT
; ******THIS ROUTINE IS WRITTEN TO BE CALLED AT ONCE-ONLY TIME******
; ******IT WILL NOT NECESSARILY DO ALL GOOD THINGS IF CALLED FROM FILSER******
; REQUIRES F AND DEVMBF(F) TO BE SET UP

FHXCPY::MOVSI	T4,KOPUHE##	;SET FOR UNIT HAD ERROR RETURN
	XCT	FHXCI1##(J)	;CONI FH'N,T2
	TLNE	T2,(1B5)	;MAINT. SEGMENT SWITCH ON?
	JRST	FHXCLR		;OFF LINE - NON-SKIP RETURN
	MOVEI	T3,^D5		;NUMBER OF TIMES TO RETRY BEFORE SAYING OFF-LINE
FHXCP1:	MOVE	T1,KONCOM##(J)
	HRRZM	T1,@KONIOC##(J)	;SETUP LOW CORE CHANNEL WORD
	MOVE	T2,DEVMBF##(F)
	MOVEM	T2,(T1)		;SETUP IOWD
	SETZB	T2,1(T1)	;END OF LIST
	XCT	FHXCO1##(J)	;CONO FH'N,(T2)
	LDB	T1,UNYPUN##	;GET PHYSICAL UNIT #
	ROT	T1,-2		;POSITION FOR DATAO
	TLO	T1,160		;SECTOR BCD 70, TRACK 0. ILLEGAL ON RM10B
	IOR	T1,KONIOC##(J)
	XCT	FHXDOT##(J)	;DATAO FH'N,T1 , CAUSE READ INTO MONITOR BUFFER
	MOVEI	T1,^D120000	;SETUP COUNT FOR TIME OUT ON DONE FLAG TEST
FHXCP2:	XCT	FHXCI1##(J)	;CONI FH'N,T1
	TRNE	T2,1B31		;BUSY STILL UP?
	SOJG	T1,FHXCP2	;YES, TRY AGAIN
	TRNN	T2,1B32		;NO, DONE UP?
	SOJG	T1,FHXCP2	;NO, TRY AGAIN
	TDNN	T2,[1377,,170220]  ;YES. ANY ERRORS?
	JUMPG	T1,FHXCP6	;NO. IT'S THERE IF IT DIDNT TIME OUT
	MOVEI	T1,FHALCL##
	XCT	FHXCOT##(J)
	SOJG	T3,FHXCP1	;TRY AGAIN
	JRST	FHXCLR		;COUNT EXPIRED & NO DONE FLAG -OFF-LINE RETURN
FHXCP6:	MOVEI	T4,0		;ASSUME IT'S AN RD10 (WITH NO ERRORS)
	TRNE	T2,1B19		;SEARCH ERROR (ON IF AN RM10B)?
	MOVEI	T4,1		;YES - IT'S AN RM10B OR A SICK RD10,
				; WHICH CAN'T EASILY BE DISTINGUISHED
	HRRZ	T2,CAPDAT(T4)	;GET # BLOCKS ON UNIT
	MOVE	W,CAPDAT(T4)	;GET # BLOCKS PER TRACK
	AOS	0(P)		;SKIP RETURN AFTER FHXCLR
FHXCLR:	MOVEI	T1,FHALCL##
	XCT	FHXCOT##(J)
	MOVE	T1,T2		;RESTORE # BLOCKS ON UNIT
	SETZ	T3,		;NO COMPATABILITY MODE
FHXPOP::TRZ	T1,KONERM##	;***CLEAR ERROR BITS FOR NOW***
IFN FTDUAL,<
	HRRZS	J		;NO SERIAL NUMBER
>
	POPJ	P,
CAPDAT:	XWD	^D20,^D4000		;RD-10 DATA
	XWD	^D30,^D2700		;RM-10B DATA

;STILL IN FTDHIA CONDITIONAL
;HERE TO CHECK CAPACITY & STATUS OF A UNIT

DPXCPY::PUSHJ	P,DPXSTS##	;GET STATUS OF OF THIS UNIT IN T2
	PUSH	P,T2		;SAVE STATUS
	MOVSI	T4,KOPUHE##	;ASSUME ERRORS
	TLO	T4,KOPNSU##	;ALSO SUCH UNIT
	TLNE	T2,4		;DOES NOT EXIST
	JRST	DPXCP3		;NO, GIVE DON'T ASK QUESTION RETURN
	SETZ	T4,		;ASSUME UNIT IS UP
	TLCN	T2,60		;UNIT ON CYLINDER & ON-LINE?
	TLNE	T2,110		;YES - SEEK INCOMPLETE,FILE UNSAFE
	TLO	T4,KOPUHE##	;YES - INDICATE UNIT HAD ERROR
	LDB	T2,[POINT 11,T2,10]	;GET DRIVE & CYLINDER # FOR DATAO
	TLO	T2,417400	;(10,,370000)_^D14 - SELECT AN ILLEGAL SECTOR
	ROT	T2,-^D14	;SHIFT INTO CORRECT POSITION FOR DATAO
	OR	T2,KONIOC##(J)
	XCT	DPXDO1##(J)	;DO A DATAO DPX,T2
	MOVEI	T2,^D1000	;LOOP 1000 TIMES
DPXCP1:	XCT	DPXCIT##(J)	;DO A CONI DPX,T1
	TRNE	T1,DPDONE##	;DONE YET?
	JRST	DPXCP2		;YES
	SOJG	T2,DPXCP1	;NO, LOOP
	JRST	DPXCP3		;CONTROLLER IS DEAD
DPXCP2:	TRNN	T1,200		;ILLEGAL SECTOR?
	TLO	T4,KOPUHE##	;NO - SOMETHING'S AMISS!
DPXCP3:	POP	P,T2		;RESTORE UNIT STATUS TO T2
	TRNE	T2,2000		;SKIP IF UNIT NOT RP03
	JRST	DPXCP4		;IS RP03, SET UP
	MOVEI	T1,^D40000	;# BLOCKS PER UNIT (RP02)
	MOVEI	T2,^D40600	;# BLOCKS PER UNIT INCL. MAINT CYLS
	HRRI	T4,1		;RETURN RP02 TYPE CODE
	JRST	DPXCP5
;HERE IF UNIT IS RP03
DPXCP4:	MOVEI	T1,^D80000	;# BLOCKS PER UNIT (RP03)
	MOVEI	T2,^D81200	;# BLOCKS PER UNIT INCL. MAINT CYLS
	HRRI	T4,2		;RETURN RP03 TYPE CODE
DPXCP5:	SETZ	T3,		;NO COMPATABILITY MODE
IFN FTDUAL,<
	HRRZS	J		;NO SERIAL NUMBER
>
	MOVE	W,[^D10,,^D200]	;BLKS PER TRACK,,BLKS PER CYL
	JUMPGE	T4,CPOPJ1##	;SKIP RETURN IF UNIT IS UP
	POPJ	P,		;DO IT DOWN RETURN

;STILL IN FTDHIA CONDITIONAL
;HERE TO CHECK CAPACITY & STATUS OF RH10/RS04, RS05
FSXCPY::LDB	T3,UNYPUN##	;UNIT NUMBER
IFN FTDUAL,<
	HRRZS	J		;NO SERIAL NUMBER
>
	MOVSI	T3,060000(T3)	;SET TO DATAO DRIVE-TYPE REGISTER
	XCT	FSXDO3##(J)
	IMULI	0,1		;HAVE TO WAIT BEFORE DATAI
	XCT	FSXDI3##(J)	;READ DRIVE TYPE (& STATUS)
	TLNE	T3,2000		;CONTROL BUS TIMEOUT?
	JRST	FSXCP1		;YES, THE UNIT ISNT THERE
	ANDI	T3,777		;NO, GET UNIT TYPE
	CAIE	T3,2
	CAIN	T3,3		;SOME FLAVOR OF RS04?
	CAIA			;YES, OK
	JRST	FSXCP1		;NO, PRETEND ITS DOWN
	MOVEI	T1,^D2048	;BLOCKS PER UNIT
	MOVE	T2,T1		;NO EXTRA MAINT CYLS
	MOVEI	T3,0		;NO COMPATABILITY MODE
	MOVE	W,[^D32,,^D2048] ;BLKS PER TRK,,BLKS PER CYL
	PJRST	CPOPJ1##	;TAKE GOOD RETURN


;HERE ON CONTROL BUS TIMEOUT
FSXCP1:	MOVSI	T4,KOPUHE##	;OFF LINE OR DOWN
	TLO	T4,KOPNSU##	;NO SUCH UNIT
	POPJ	P,

;STILL IN FTDHIA CONDITIONAL
;HERE TO CHECK CAPACITY & STATUS OF RH10/RP04
RPXCPY::
IFN FTKL10,<
	PUSHJ	P,RPXSTW##	;DO MASSBUS ENABLE IF RH20
>
	MOVSI	T2,60000	;READ DRIVE-TYPE REGISTER
	PUSHJ	P,DODTI4
	LDB	T3,[POINT 9,T2,35]
	CAIL	T3,20		;IN RANGE OF RP04-PR06 ?
	CAILE	T3,22
	JRST	RPXCP1		;NO, NO SUCH DRIVE
	CAIE	T3,22		;YES, RP06 ?
	TDZA	T4,T4		;NO
	MOVEI	T4,1		;YES, UNIT TYPE=1
	MOVSI	T2,10000	;YES, READ STATUS REGISTER
	PUSHJ	P,DODTI4
	TRNN	T2,10000	;MOL?
	TLO	T4,KOPUHE	;NO, INIT IS OFF-LINE OR DOWN
	MOVSI	T2,100000	;READ DRIVE SERIAL NUMBER
	PUSHJ	P,DODTI4
	MOVEM	T2,UNIEBK##+10(U)  ;AND STORE IN UDB
IFN FTDUAL,<
	HRL	J,T2		;RETURN S.N. FOR ONCMOD
>
IFN FT22BIT,<
	XCT	RPXCI2##(J)	;CONI FN'N T2
	TLNE	T2,4000		;22 BIT CHAN?
	TLO	T4,KOP22B##	;YES
>
	MOVE	T1,BLKPRU(T4)	;BLOCKS PER UNIT
	MOVE	T2,BLKPUM(T4)	;BLOCKS PER UNIT INCLUDING MAINT CYLS
	MOVE	T3,BLKPUC(T4)	;BLOCKS PER UNIT IN 10/11 COMPAT MODE
	MOVE	W,[^D20,,^D380]	;BLKS PER TRK,, BLKS PER CYL
	AOS	(P)		;SET FOR SKIP RETURN
	JRST	RPXCP2		;CLEAR POSSIBLE RAE AND EXIT
RPXCP1:	MOVSI	T4,KOPUHE##	;OFF LINE OR DOWN
	TLO	T4,KOPNSU##	;NO SUCH UNIT

RPXCP2:
IFN FTKL10,<
	JUMPE	P1,CPOPJ##	;NO SWEAT IF AN RH10
	PUSH	P,T4		;PRESERVE T4
	PUSH	P,T2		; AND T2
	PUSHJ	P,CLRRAE	;CLEAR RAE, LIT IF NON-EX DRIVE
	HRLOI	T2,DOAS+LR	;NOT READY DRIVES LIGHT ATTENTION
	XCT	RPXDO2##(J)	; SO CLEAR IT
	POP	P,T2
	PJRST	T4POPJ##	;RESTORE T4 AND RETURN
>
	POPJ	P,

BLKPRU:	DEC	154280		;406 CYLINDERS
	DEC	307800		;810 CYLINDERS
BLKPUM:	DEC	156180		;411 CYLINDERS
	DEC	309700		;815 CYLINDERS
BLKPUC:	DEC	171798		;22*19*411
	DEC	340670		;22*19*815
>	;END FTDHIA
;SUBROUTINE TO GET CORE FOR A UNIT'S "HOME" BLOCK
; & THEN TRY TO READ BOTH BLOCKS SUCCESSFULLY
; ENTER WITH F = FILE DATA BLOCK ADR.  U = UNIT DATA BLOCK ADR.

GTHOM::	MOVSI	P2,(SIXBIT .HOM.)
	MOVE	P3,[EXP CODHOM##]	;CODE WORD FOR "HOME" BLOCKS
	MOVE	P4,UNIHOM##(U)	;GET "HOME" BLOCK NUMBERS - XWD 1ST. BLK,2ND. BLK
	PUSHJ	P,REDRUN
	  POPJ	P,
	MOVE	T1,HOMOKC##(P1)
	SKIPN	HOMVSY##(P1)
	MOVEM	T1,HOMK4C##(P1)
	JRST	CPOPJ1##
;SUBROUTINE TO MOVE PARAMETERS FROM "HOME" BLOCK TO UNIT DATA BLOCK

MOVUNI:	MOVE	T1,HOMLOG##(P1)
	MOVEM	T1,UNILOG##(U)
	MOVE	T1,HOMHID##(P1)
	MOVEM	T1,UNIHID##(U)
	MOVE	T1,HOMLUN##(P1)
	DPB	T1,UNYLUN##
	SKIPLE	T1,HOMHOM##(P1)
	MOVEM	T1,UNIHOM##(U)
	MOVE	T1,HOMGRP##(P1)
	HRLM	T1,UNIGRP##(U)
	MOVE	T1,HOMBPC##(P1)
	DPB	T1,UNYBPC##
	MOVE	T1,HOMSUN##(P1)
	MOVEM	T1,UNISUN##(U)
	MOVE	T1,HOMSLB##(P1)
	MOVEM	T1,UNISLB##(U)
	MOVE	T1,HOMK4S##(P1)
	DPB	T1,UNYK4S##
	MOVE	T1,HOMCFS##(P1)
	DPB	T1,UNYCFS##
	MOVE	T1,HOMSIC##(P1)
	DPB	T1,UNYSIC##
	MOVE	T1,HOMSPU##(P1)
	DPB	T1,UNYSPU##
	MOVSI	T2,UNPMSB##
	ANDCAM	T2,UNIDES##(U)
	CAIE	T1,1
	IORM	T2,UNIDES##(U)
	POPJ	P,
;SUBROUTINE TO FIND AN STR DATA BLOCK GIVEN A SIXBIT NAME
; ENTER WITH T1 = SIXBIT STR NAME TO BE SEARCHED FOR
; IF NO STR DATA BLOCK FOUND - RETURN WITH:
;   P2 = 0. P3 = LAST STR DATA BLOCK ADR.(DIFSTR IF NO STRS) P4 = FIRST FREE SYSTEM STR #
; IF FOUND - SKIP RETURN WITH:
;   P2 = ADR. OF THE STR DATA BLOCK. P4= SYSTEM STR # OF THIS STR
;   P3 = ADR. OF PREVIOUS STR DATA BLOCK (OR DIFSTR IF THE ONLY STR)
; IN BOTH CASES THE LEADING 4 SIXBIT CHS. IN T1 ARE RESPECTED

FNSTR:	TRZ	T1,7777		;STR NAMES CAN BE NO LONGER THAN 4 CHS.
	MOVEI	P4,.FSMIN	;CLEAR SYSTEM STR #
	MOVEI	P2,DIFSTR##	;GET (SYSSTR-STRSYS) AS 1ST. STR ADR.
FNSTR1:	MOVE	P3,P2		;SETUP P3 AS PREDECESSOR STR DATA BLOCK ADR.
	HLRZ	P2,STRSYS##(P2)	;GET NEXT STR DATA BLOCK ADR.
	JUMPE	P2,CPOPJ##	;NON SKIP RETURN IF NO STR FOUND
	CAMN	T1,STRNAM##(P2)	;A MATCH BETWEEN NAMES?
	JRST	CPOPJ1##	;YES - SKIP RETURN
	AOJA	P4,FNSTR1	;INCREMENT SYSTEM STR # & REPEAT

;SUBROUTINE TO CREATE AN STR DATA BLOCK IN UPPER CORE & ZERO IT OUT
; ENTER WITH P3=ADR. OF LAST STR DATA BLOCK. P4=SYSTEM STR # FOR THIS STR
; P2 IS RETURNED WITH ADR. OF THIS STR DATA BLOCK

GETSTR:	CAILE	P4,.FSMAX	;SEE IF THE LIMIT OF STR'S CREATED HAS BEEN EXCEEDED
	POPJ	P,		;NON SKIP RETURN IF LIMIT EXCEEDED
	MOVEI	T2,STRLEN##	;SIZE OF STR DATA BLOCK
	PUSHJ	P,CORGRB	;GET CORE FOR STR DATA BLOCK
	HRRZ	P2,T1		;GET ADR. OF NEW STR INTO A KOSHER AC
	HRLI	T1,STRDB##	;PUT ADR. OF PROTOTYPE STR DATA BLOCK IN RH
	BLT	T1,-1(T2)	;ZERO IT (T2 SET TO LAST LOC. +1 OF STR BY CORGRB)
	HRLM	P2,STRSYS##(P3)	;PUT ADR. OF NEW STR IN (OLD) LAST STR
	MOVEM	P2,TABSTR##(P4)	;STORE ADR. OF STR IN TABLE BY ITS LOG. #
	MOVEM	P4,STRSYS##(P2)	;PUT SYSTEM STR # & 0 LINK IN THIS STR
	JRST	CPOPJ1##	;SKIP RETURN IF STR CREATED OK

;SUBROUTINE TO GRAB CORE FOR THE ONCE ONLY CODE
; ENTER WITH T2 = # WORDS TO GRAB IN UPPER CORE
; RETURN WITH T1 = ADR. OF THE GRABBED CORE
; & T2 = ADR. OF 1ST. FREE WORD

CORGRB::MOVE	T1,HICORE##
	ADDB	T2,HICORE##
	SKIPE	.UONCE##	;SKIP IF EXEC MODE
	CAMG	T2,.JBREL##
	POPJ	P,
	CORE	T2,
	  JFCL
	MOVE	T2,HICORE##
	POPJ	P,
;SUBROUTINE TO MOVE PARAMETERS FROM "HOME" BLOCK TO STR DATA  BLOCK

MOVSTR:	MOVE	T1,HOMSNM##(P1)
	MOVEM	T1,STRNAM##(P2)
	MOVE	T1,HOMK4C##(P1)
	HRRM	T1,STRK4C##(P2)
	MOVE	T1,HOMSAT##(P1)
	HRLS	T1
	MOVEM	T1,STRSAT##(P2)
	MOVE	T1,UNIBPU##(U)
	CAMLE	T1,STRBPU##(P2)
	MOVEM	T1,STRBPU##(P2)
	MOVE	T1,HOMGAR##(P1)
	MOVEM	T1,STRGAR##(P2)
	MOVE	T1,HOMOVR##(P1)
	MOVEM	T1,STROVR##(P2)
	MOVE	T1,HOMPT1##(P1)
	MOVEM	T1,STRPT1##(P2)
	MOVE	T1,HOMBSC##(P1)
	HRLM	T1,STRBSC##(P2)
	MOVE	T1,HOMSCU##(P1)
	HRRM	T1,STRSCU##(P2)
	MOVE	T1,HOMSRC##(P1)
	MOVEM	T1,STRSRC##(P2)
	HLLZ	T1,HOMCNP##(P1)
	TLZ	T1,77
	HLLM	T1,STYCNP##(P2)
	HLLZ	T1,HOMCKP##(P1)
	TLZ	T1,77
	HLLM	T1,STYCKP##(P2)
	HLLZ	T1,HOMCLP##(P1)
	TLZ	T1,770077
	HLLM	T1,STYCLP##(P2)
	MOVE	T1,HOMREF##(P1)
	HLLM	T1,STRREF##(P2)
	MOVE	T1,STRUN1##(P2)
	MOVE	T2,HOMUN1##(P1)
	DPB	T2,UN1PTR##
	MOVEM	T1,STRUN1##(P2)
IFN FTPSTR,<
	LDB	T1,HOYPVS##
	DPB	T1,STYPVS##
>
	POPJ	P,
MSGLNG:	JSP	T2,REFSAV	;SAVE P4,T3,F,U & J AND INDICATE STR NEEDS REFRESHING
	PUSH	P,T1		;SAVE 2ND. MSG ADR. IN T1
	MOVE	T1,T3		;GET ADR OF 1ST. MSG
	PUSHJ	P,TYPDEC	;PUT MSG. & UNIT # IN BUFFER
	PUSHJ	P,OPOUT##	;O/P BUFFER
	POP	P,T1		;RESTORE 2ND. MSG ADR.
	CAIA

MSGSTR:	JSP	T2,REFSAV	;SAVE P4,T3,F,U & J AND INDICATE STR NEEDS REFRESHING
	PUSHJ	P,ICONM##	;PUT MSG. IN BUFFER
	SETOM	ERRHOM		;INDICATE ERROR IN "REDHOM"
	SETOM	SERIUS		;SERIOUS ERROR - CAN'T START SYSTEM
	MOVE	T2,STRNAM##(P2)	;GET SIXBIT STR NAME
	PJRST	NAMFLO		;PUT IT IN THE BUFFER FOLLOWED BY CRLF & START O/P


;SUBROUTINE TO ASK IF OPERATOR WANTS TO LIST # OF BAD REGIONS

TYPBAT:	SETOM	LSTBAT		;SET FLAG TO LIST # BAT REGIONS
	MOVEI	T1,[ASCIZ .
TYPE PHYSICAL UNIT NAME TO LIST # BAD REGIONS(CR IF NONE, ALL IF ALL).]
	PUSHJ	P,CONOUT	;ADD CRLF AND TYPE MSG.
	PUSHJ	P,GETUNI	;GET USER'S RESPONSE
	  POPJ	P,		;JUST TYPED CR - EXIT
	PJUMPE	U,REDBT1	;WAS "ALL" TYPED (YES-READ ALL UNITS)?
	PUSHJ	P,CHKBAT	;NO, JUST READ ONE UNIT
	  JFCL			;IGNORE ERROR RETURN
	JRST	TYPBAT		;ASK QUESTION AGAIN
;SUBROUTINE TO READ & VERIFY ALL "BAT" BLOCKS IN THE SYSTEM
;AND SET UP SWAPPING SAT TABLES.  LSTBAT IS FLAG TO LIST # BAD REGIONS OR NOT.

REDBAT:	SETZM	LSTBAT		;CLEAR FLAG SO DO NOT LIST # BAD REGIONS
REDBT1:	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN THE SYSTEM
	MOVSI	P4,UNPOFL##
CHKBT1:	TDNE	P4,UNIDES##(U)	;UNIT OFF-LINE?
	JRST	CHKBT2		;YES, GO READ NEXT BAT BLOCK
	PUSHJ	P,CHKBAT	;NO - GO CHECK "BAT" BLOCKS FOR THIS UNIT
	  JFCL			;IGNORE ERRORS
	SKIPN	BATMAN		;IN MANDATORY ONCE-ONLY?
	JRST	CHKBT2		;NO, NO POIN SETTING UP SWAPPING SAT IF OPTIONAL
	HRRZ	T3,P1			;LOC OF BAT BLOCK
	LDB	T1,BAYNBR##	;NO OF REGION FOUND BY MAPPER
	ADD	T1,BAFCNT##(T3)	;+ NO FOUND BY MONITOR
	HLRE	T3,BAFFIR##(T3)	;- TOTAL NO OF SLOTS
	ASH	T3,-1		;2 WORDS PER ENTRY
	ADD	T3,T1		;+ NO OF ENTRIES LEFT
	MOVNS	T3
	DPB	T3,UNYBCT##	;SAVE IN UDB
	MOVE	T2,UNIPTR##(U)	;YES, T2=AOBJN PTR TO SWAPPING SAT FOR THIS UNIT
	SKIPGE	UNISUN##(U)	;IN ACTIVE SWAPPING LIST?
	JRST	CHKBT2		;NO, NO SWAPPING SAT
	HLRE	T1,T2		;T1=-LENGTH OF SWAPPING SAT
	SUB	T2,T1		;T2=ADDR OF SECOND COPY (-T1=+LENGTH)
	MOVE	T1,T2		;T1=PTR TO SECOND COPY
	LDB	T3,UNYK4S##	;T3=K FOR SWAPPING ON UNIT
IFN FTKI10!FTKL10,<
	LSH	T3,K2PLSH##	;DOUBLE SIZE IF SWAPPING PAGES
>
IFN FTVM,<
	ADDI	T3,1		;+1 BECAUSE 0 WAS THROWN AWAY
>
	IDIVI	T3,^D36		;T3=FULL WORDS
	JUMPE	T4,FULSST	;JUMP IF NO WASTED BITS
	ADDI	T2,(T3)		;T2=ADDR OF LAST WORD
	MOVNI	T3,-1(T4)	;T3=-BITS TO SET TO 0 +1
	MOVSI	T4,400000	;SET SIGN BIT
	ASH	T4,(T3)		;SET BITS TO BE 0 TO 1
	SETCAM	T4,(T2)		;COMPLEMENT AND STORE
FULSST:	AOBJP	T1,NOSST	;JUMP IF 0 OR 1 WORD IN SWAPPING SAT
	SETZM	-1(T1)		;CLEAR FIRST WORD OF SECOND COPY
	HRLI	T1,-1(T1)	;LH=ADDR OF FIRST WORD
	MOVEI	T3,(T1)		;1ST ADDR +1 = LAST ADDR? ONLY IF EXACTLY 2 WORDS
	CAIGE	T3,(T2)		;SKIP IF YES, NO MORE LOCATIONS TO CLEAR
	BLT	T1,-1(T2)	;CLEAR REST OF SECOND COPY
NOSST:	HRRZI	T1,-1(P1)	;T1=ADDR OF BAT BLOCK IN CORE -1
	MOVE	T2,[PUSHJ P,SETSST];T2=INSTRUCTION TO EX FOR BAD BLOCKS
	PUSHJ	P,SCNBAT##	;SCAN BAT BLOCK, CALL SETSST FOR BAD BLOCKS
CHKBT2:	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,CHKBT1	;REPEAT IF THERE IS ONE
	POPJ	P,		;NONE LEFT - EXIT
CHKBAT:	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	SETZM	BATBAD		;CLEAR "BAT" BLOCK BAD FLAG
	SETZM	BTHBAD		;CLEAR BOTH BAD FLAG
	PUSHJ	P,GTBAT		;READ BOTH BAT BLOCKS & VERIFY
	  SETOM	BTHBAD		;BOTH BAD--REMEMBER
	SKIPE	REDERR		;IF READ ERRORS
	AOS	BATANY		;ALSO FLAG THAT SOME UNIT HAS ERRORS
	SKIPE	REDERR		;ANY ERRORS IN EITHER ONE
	SETOM	BATBAD		;SET BAT BLOCK BAD FLAG
	SKIPN	BATMAN		;SKIP IF MANDATORY
	JRST	CKBAT1
	JSP	T2,SVOTAC	;SAVE P4,F,U, AND J
	SKIPN	BATBAD		;ANY ERRORS IN EITHER??
	POPJ	P,		;NO, GO TO NEXT UNIT
	HRRZ	T3,P1		;ADDR OF BAT BLOCK IN CORE
	SKIPE	BTHBAD		;BOTH BAD??
	PJRST	INTBAT		;YES-MAY AS WELL REWRITE THEM
	MOVEI	T2,LBOBAT##	;ONE IS GOOD & SITTING IN MBF
	HLRZ	T3,UNIHOM##(U)
	SKIPL	REDERR		;SKIP IF BLOCK 2 IS GOOD & 1 IS BAD
	HRRZ	T3,UNIHOM##(U)
	ADD	T2,T3		;BLOCK 2 IS BAD-WRITE GOOD ONE ON IT
	MOVEM	T2,BLKSLF##(P1)	;THIS BLOCK MUST KNOW WHAT IT IS
	PUSHJ	P,OMNWRT	;WRITE PROPER BLOCK
	PUSHJ	P,WRTCHK	;ERROR-TELL OPR ABOUT IT
	POPJ	P,
CKBAT1:	HRRZ	T3,P1		;GET ADR. OF "BAT" BLOCK INTO A BETTER AC
	LDB	P1,BAYNBR##	;GET # BAD REGIONS FOUND BY MAP PROGRAM.
	ADD	P1,BAFCNT##(T3)	;ADD IN # FOUND BY MONITOR
	ADDM	P1,BATANY	;ALSO FLAG THAT SOME UNIT HAS ERRORS
	SKIPN	LSTBAT		;LISTING # BAD REGIONS?
	JRST	CHKBT3		;NO, CHECK IF BAD (SO IF NEVER WRITTEN
				;CAN GET CHANCE TO WRITE)
	HRRM	P1,BATBAD	;STORE # BAD REGIONS ON UNIT FOR PRINTING
	SETZ	P4,		;FLAG UNIT ID WANTED IN TYPUN1
	MOVEI	P1,P4		;NULL MESSAGE
	PUSH	P,T3
	PUSHJ	P,OTSET
	POP	P,T3
	PUSHJ	P,TYPUN1	;TYPE UNIT NAME AND UNIT ID
	PUSHJ	P,SOPOUT
	MOVEI	T1,[ASCIZ .
# BAD REGIONS = .]
	HRRZ	P1,BATBAD	;NUMBER OF BAD REGIONS
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JUMPE	P1,CHKBT3	;PRINT NO BAD BLOCKS IF 0 BAD REGIONS
	HRRZ	T2,BAFFIR##(T3)	;GET START ADR. OF MONITOR BAD REGION PAIRS
	CAIL	T2,BLKCOD##	;MAKE SURE IT'S WITHIN THE BLOCK
	JRST	ASKBN1		;IT ISN'T - ASK IF "BAT" BLOCKS TO BE INITILAIZED
	MOVN	T1,P1		;GET -VE # OF BAD REGIONS
	MOVEI	P1,0		;CLEAR AC FOR TOTAL # BAD BLOCKS
	HRL	T2,T1		;SETUP T2 FOR AOBJN
	ADD	T2,T3		;ADD IN MBF ADR.
	PUSH	P,T2		;SAVE AOBJN POINTER
BDBLUP:	LDB	T1,BAYNBB##	;GET # BAD BLOCKS IN THIS REGION
	ADDI	P1,1(T1)	;ADD TO TOTAL FOR THIS UNIT
	ADDI	T2,1		;EXTRA INCREMENT AS ENTRIES ARE 2 WORD PAIRS
	AOBJN	T2,BDBLUP	;REPEAT IF MORE REGIONS LEFT
	MOVEI	T1,[ASCIZ .# BAD BLOCKS = .]
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JUMPN	P1,[POP	P,P1	;ALWAYS ASK QUESTION IF ANY BAD BLOCKS ON UNIT
		JRST	ASKBIN]
	POP	P,P1		;RESTORE AOBJN PTR TO BATBLK
CHKBT3:	SKIPN	BATBAD		;LIKEWISE IF ANY BAD REGIONS OR ERRORS DETECTED
	POPJ	P,		;EXIT
ASKBIN:	MOVEI	T1,[ASCIZ/
DO YOU WANT A LIST OF BAD REGIONS?
/]
	PUSHJ	P,ASKQUE	;MAKE FRIENDLY OFFER
	  JRST	ASKBN1		;NOPE
	MOVEI	T1,[ASCIZ/
FIRST BLOCK      # BLOCKS
/]
	PUSH	P,T3
	PUSHJ	P,CONOUT	;TYPE HEADER
	MOVE	T3,P1		;SET UP AOBJN PTR
ASKBLP:	MOVE	T1,BAFELB##(T3)	;GET ADDRESS WORD
	TLZ	T1,BATMSK##	;MASK OUT ALL BUT ADDR
	MOVEI	T2,BAPNTP##	;IF OLD-STYLE
	TDNN	T2,BAFAPN##(T3)
	HRRZS	T1		; ONLY 18 BITS COUNT
	PUSHJ	P,SVOSET	;SET UP
	PUSHJ	P,SRDX10	;PLACE IN BUFFER
	PUSHJ	P,SOPOUT	;TYPE MESSAGE
	MOVEI	T1,[ASCIZ/              /]	;SPACE OVER
	MOVEI	T2,(T3)		;SET UP INDEX AC
	LDB	P1,BAYNBB##	;GET COUNT OF BAD BLOCKS IN REGION
	AOJ	P1,		;INCREMENT
	PUSHJ	P,DECLOP	;TYPE SPACE, DECIMAL #, CRLF
	AOJ	T3,		;MUST INC T3 BY 2 FOR BAT PAIRS
	AOBJN	T3,ASKBLP	;LOOP
	POP	P,T3
ASKBN1:	MOVEI	T1,[ASCIZ .
DO YOU WANT TO INITIALIZE THE BAT BLOCKS ON THIS UNIT?
.]
	MOVSI	T2,UNPHWP##
	TDNN	T2,UNIDES##(U)	;DON'T INITIALIZE IF UNIT HARDWARE WRITE-PROTECT
	PUSHJ	P,ASKQUE	;TYPE QUESTION & GET USER'S RESPONSE
	  POPJ	P,		;HE DOESN'T WANT TO
	MOVEI	T1,[ASCIZ .
NOT NORMALLY DONE, ARE YOU SURE?
.]
	PUSHJ	P,ASKQUE	;ASK AGAIN
	  POPJ	P,		;HE SAVED HIMSELF SOME BOTHER

INTBAT:	PUSHJ	P,SETBAT	;SETUP "BAT" BLOCK PARAMETERS
	MOVSI	T1,(T3)		;SETUP BLT PTR. TO CLEAR "BAT" BLOCK
	HRRI	T1,1(T3)
	SETZM	(T3)		;CLEAR OUT 1ST. WORD
	BLT	T1,BLKSLF##(T3)	;CLEAR OUT THE REST OF THE BLOCK
	MOVEM	P2,BLKNAM##(T3)	;PUT SIXBIT 'BAT' IN THE BLOCK
	MOVSI	T1,MBRMAX##	;SETUP AOBJN PTR. TO BE STORED IN BLOCK
	HRRI	T1,BAFREG##
	MOVEM	T1,BAFFIR##(T3)	;SAVE IT IN THE BLOCK
	HRRZ	J,UNIKON##(U)	;GET UNIT'S KONTROLLER DATA BLOCK ADR.
	LDB	T1,[POINT 7,KONINT##(J),9]	;GET DEVICE CODE FOR THE KONTROLLER
	DPB	T1,BAYKDC##	;SAVE IT IN THE BLOCK
	MOVEM	P3,BLKCOD##(T3)	;SAVE THE CODE FOR "BAT" BLOCKS IN THE BLOCK
	MOVE	P1,T3		;GET ADR. OF "BAT" BLOCK IN CORE INTO P1 FOR WRTRUN
	MOVEI	T1,[ASCIZ/INITIALIZING BAT BLOCKS/]
	PUSHJ	P,CONOUT
	PJRST	WRTRUN		;WRITE BOTH "BAT" BLOCKS

BATBAD:	0			;0 INDICATES VIRGIN "BAT" BLOCKS(INITIALIZED)
				; LH = -1 INDICATES ERROR(S) DETECTED WHILE READING
				; RH = # BAD REGIONS ON UNIT
BTHBAD:	0			;0=NOT BOTH BAD, -1 = BOTH BAD
BATMAN:	0			;0=OPTIONAL, -1=MANDANTORY

BATANY:	0			;NON-ZERO IF ANY BAD REGIONS ON ANY UNITS

LSTBAT:	0			;NON-ZERO IF LIST # BAD REGIONS

GTBAT:	PUSHJ	P,SETBAT	;SETUP "BAT" BLOCK PARAMETERS FOR REDRUN
	PJRST	REDRUN		;GO READ & VERIFY BLOCKS

SETBAT:	MOVSI	P2,(SIXBIT .BAT.)
	MOVE	P3,[EXP CODBAT## ]
	MOVE	P4,[XWD LBOBAT##,LBOBAT ]
	ADD	P4,UNIHOM##(U)
	POPJ	P,
;SUBROUTINE TO SET BITS IN SWAPPING SAT TABLE FOR BAD BLOCKS IN SWAPPING SPACE
;ARGS	T1=BLOCK NUMBER WITHIN UNIT

SETSST:	SKIPGE	UNISUN##(U)	;UNIT IN A.S.L?
	POPJ	P,		;NO, RETURN
	PUSHJ	P,SAVE4##	;SAVE P1-P4
	SUB	T1,UNISLB##(U)	;T1=RELATIVE BLOCK IN SWAPPING SPACE
	JUMPL	T1,CPOPJ##	;EXIT IF BLOCK BELOW SWAPPING SPACE
	LDB	P3,UNYK4S##	;P3=K FOR SWAPPING ON THIS UNIT
	JUMPE	P3,CPOPJ##	;EXIT IF NO SWAPPING SPACE ON UNIT
	MOVE	T2,P3
	LSH	T2,BLKSPK##	;CONVERT TO BLOCKS
	CAML	T1,T2		;SKIP IF BLOCK IN SWAPPPING SPACE
	POPJ	P,		;NO, PAST END
	MOVEI	P1,SWBKPP##	;8 BLOCKS PER K
	SETZ	P2,		;STARTING AT LOGICAL K 0
	SUBI	P3,1		;LAST LOGICAL J NUMBER
	MOVE	P4,UNIPTR##(U)	;PTR TO SWAPPING SAT
	HLRE	T2,P4		;T2=-LENGTH OF SWAPPING SAT
	SUB	P4,T2		;P4=AOBJN PTR TO SECOND COPY
	SUBI	P4,1		;MAKE IOWD PTR
IFN FTVM,<
	ADDI	T1,SWBKPP	;SWAPPING SPACE STARTS AT 1 FOR VM
>
	PUSHJ	P,CHKBIT##	;FIND BIT
	  ORM	T4,(T1)		;WAS NOT ON, SET IT
	POPJ	P,		;THATS ALL
;SUBROUTINE TO READ SPECIAL BLOCKS ON THE DISK ["HOME","BAT" & "RIB"]
; ENTER WITH U = UNIT U BLOCK ADR. F = FILE DATA BLOCK ADR.
; OTHER ARGS. SETUP BY 'GTHOM' , 'GTBAT' & 'GTSRB'
; RETURN WITH T2 & S AS 'REDCHK' SETS THEM
; NON SKIP RETURN IF ERRORS ON BOTH BLOCKS

REDRUN::
	MOVE	F,DATADR	;SETUP FILE DATA BLOCK ADR.
	HRRZ	P1,DEVMBF##(F)	;GET ADR. OF MONITOR BUFFER FOR DISK BLOCK
	ADDI	P1,1
	SETZM	REDERR		;CLEAR ERROR FLAG
FIROK:	SETOM	WHICH		;INDICATE READING 1ST. BLOCK
	HLRZ	T2,P4		;GET ITS BLOCK #
	PUSHJ	P,REDCHK	;READ BLOCK & CHECK FOR ERRORS
	  JRST	REDSEC		;ERROR(S) DETECTED - GO TRY 2ND. BLOCK
	JUMPG	T2,CPOPJ1##	;IF 2ND. BLOCK BAD BUT 1ST. OK - SKIP RETURN

REDSEC:	SETZM	WHICH		;INDICATE READING 2ND. BLOCK
	HRRZ	T2,P4		;GET ITS BLOCK #
	PUSHJ	P,REDCHK	;READ BLOCK & CHECK FOR ERRORS
	  JUMPL	T2,CPOPJ##	;ERROR(S) DETECTED
				; ERROR(S) ON 1ST. BLOCK AS WELL GIVES ERROR RETURN
	JUMPG	T2,FIROK	;IF 2ND. BLOCK BAD BUT 1ST. OK - GO TRY 1ST. AGAIN
	JRST	CPOPJ1##	;GIVE SKIP RETURN


;SUBROUTINE TO READ A SPECIAL BLOCK AND CHECK FOR ERRORS
; ENTER WITH T2 = BLOCK # TO BE READ. F = FILE DATA BLOCK. U = UNIT DATA BLOCK ADR.
; RETURN T2 & S = 0 IF NO ERRORS. NON SKIP RETURN IF ERROR ON EITHER BLOCK
; RETURN RH T2 =-1  IF ERROR ON 2ND. BLOCK
;   "    LH T2 =-1   "   "    " 1ST.   "
; & S HAS APPROPRIATE RH ERROR BITS SET

REDCHK:	PUSHJ	P,OMNRED	;READ THE BLOCK
	  SKIPA	T3,UNINAM##(U)	;ERROR - GET SIXBIT UNIT NAME
	JRST	CONCHK		;NO READ ERRORS - GO MAKE CONSISTANCY CHECKS
IFE FTKL10,<
	SKIPN	.UONCE##	;SKIP DATAO IF USER MODE
	DATAO	PI,UNIERR##(U)	;FLASH OPERATOR WITH KONTROLLER STATUS
>;END IFE FTKL10
	MOVEI	T1,[ASCIZ . BLOCK HARDWARE READ ERROR.]
	PUSHJ	P,RDNMSG	;PRINT ERROR MSG. FOR BLOCK TYPE
CONCHK:	CAMN	P2,[SIXBIT /SAT/]	;IS THIS THE SAT.SYS "RIB" BLOCK WE'RE READING?
	CAME	P2,RIBNAM##(P1)	;YES - IS THE NAME IN THE "RIB" = 'SAT'?
	CAMN	P2,BLKNAM##(P1)	;NO - CHECK BLOCK NAME(THIS ALWAYS FAILS WITH "RIB")
	CAME	P3,BLKCOD##(P1)	;OK - CHECK CODE WORD
	SKIPA	T3,UNINAM##(U)	;NO CHECK - GET SIXBIT UNIT NAME
	JRST	TSTCHK		;EXIT CHECKING ERRORS ON THE WAY
	MOVEI	T1,[ASCIZ . BLOCK CONSISTENCY ERROR.]
	PUSHJ	P,RDNMSG	;PRINT ERROR MSG. FOR BLOCK TYPE
	TRO	S,IOIMPM	;SET AN ERROR BIT FOR ERROR CHECK
TSTCHK:	MOVE	T2,REDERR	;PICK UP ERROR WORD FOR CHECKING BY CALLER
	JUMPE	S,CPOPJ1##	;SKIP RETURN IF NO ERRORS
	POPJ	P,
;SUBROUTINE TO PRINT ERROR MSG. FOR REDCHK
; ENTER WITH T1 = MSG. ADR. T3 = SIXBIT UNIT NAME
; RETURN LH. OR RH. OF REDERR = -1
; DEPENDING ON WHETHER IST. OR 2ND BLOCK HAD ERROR

RDNMSG:	JSP	T2,SVOTAC	;SAVE T3,F,U & J
	PUSH	P,T1		;SAVE ADDR OF MESSAGE
	PUSHJ	P,SVOSET
	MOVE	T2,T3		;SIXBIT UNIT NAME
	PUSHJ	P,SPRNAM	;PUT NAME IN BUFFER
	MOVEI	T1,[ASCIZ . FIRST .]	;PRESUME ERROR ON 1ST. BLOCK
	SKIPE	WHICH		;2ND. BLOCK WAS READ?
	JRST	FSTERR		;NO - 1ST. BLOCK
	HLLOS	REDERR		;INDICATE ERROR ON 2ND. BLOCK
	SKIPA	T1,[[ASCIZ . SECOND .]]
FSTERR:	HRROS	REDERR		;INDICATE ERROR ON 1ST. BLOCK
	PUSHJ	P,SCONMS	;PUT MSG. IN BUFFER
	MOVE	T2,P2		;GET SIXBIT BLOCK TYPE("HOME" OR "BAT")
	CAMN	P2,[SIXBIT .SAT.]	;IF THIS WAS A "RIB" BLOCK
	MOVSI	T2,(SIXBIT .RIB.)	; TYPE "RIB" INSTEAD OF "SAT"
	PUSHJ	P,SPRNAM	;PUT IT IN BUFFER
	POP	P,T1		;ADDR OF MESSAGE
	PUSHJ	P,SCONMS	;PUT MSG. IN BUFFER
	PJRST	SCRLFO		;CRLF AND TYPE MESSAGE

REDERR:	0			;ERROR WORD FOR REDRUN
				; RH=-1 IF ERROR ON 2ND. BLOCK
				; LH "  "    "   "  1ST.   "
WHICH:	0			;FLAG TO INDICATE WHETHER 2ND. OR 1ST. BLK BEING READ
;SUBROUTINE TO TYPE ALL STR'S & THEIR UNITS IN THE SYSTEM
; RETURN WITH P1,P4,F,U & J DESTROYED

TYPSYS:	PUSHJ	P,OTSET##
	SETZM	P4		;INDICATE UNIT ID TO BE PRINTED IN TYPUNI
	HLRZ	P2,SYSSTR##	;ADR. OF 1ST. STR DATA BLOCK IN SYSTEM
TYPSY1:	JUMPE	P2,SOPOUT	;NONE LEFT - EXIT
	PUSHJ	P,TYPSTR	;TYPE STR NAME & ALL ITS UNITS
	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK
	JRST	TYPSY1		; & REPEAT

TYPSTR:
IFN FTPSTR,<
	LDB	T1,STYPVS##
	JUMPE	T1,TYPST0	;JUMP IF PUBLIC
	MOVEI	T1,[ASCIZ .PRIVATE .]
	PUSHJ	P,SCONMS	;TELL HIM ITS PRIVATE
TYPST0:>
	HLLZ	T2,STRREF##(P2)
	JUMPE	T2,NOREF	;DOES STR NEED REFRESHING?
	MOVEI	T1,[ASCIZ .NEEDS REFRESHING .]	;YES
	PUSHJ	P,SCONMS	;PUT MSG IN BUFFER
NOREF:	PUSHJ	P,SPSNAM	;PUT SIXBIT STR NAME IN BUFFER
	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT IN STR
	JUMPE	U,SCRLFO	;IF NO UNITS IN STR - O/P BUFFER WITH CRLF & EXIT
	MOVEI	P1,[ASCIZ .:.]
	PUSHJ	P,TYPUN1	;TYPE ":" UNIT NAME & (ID) [IST. TIME THRU]
TYPST1:	HLRZ	U,UNISTR##(U)	;GET NEXT UNIT DATA BLOCK IN STR
	JUMPE	U,CRLF##	;IF NO MORE UNITS - ADD CRLF & EXIT
	PUSHJ	P,TYPUNI	;TYPE "," UNIT NAME & (ID)
	JRST	TYPST1		;REPEAT UNTIL NO MORE UNITS IN STR
;SUBROUTINE TO TYPE ALL UNITS IN SYSTEM THAT ARE NOT IN ANY STR
; RETURN WITH P1,P4,F,U & J DESTROYED

TYPUNS:	PUSHJ	P,OTSET
	MOVEI	P1,[ASCIZ .
UNITS NOT IN A FILE STRUCTURE:
.]
	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
	TDZA	P4,P4		;INDICATE UNIT ID TO BE TYPED IN TYPUNI
TYPNS1:	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPE	U,SOPOUT	;EXIT IF NONE LEFT
	SKIPE	UNILOG##(U)	;IS THIS UNIT IN AN STR?
	JRST	TYPNS1		;YES - CHECK NEXT UNIT
	PUSHJ	P,TYPUN1	;NO - TYPE MSG., UNIT NAME & (ID)

TYPNS2:	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPE	U,TYPSR1	;O/P CRLF & EXIT IF NONE LEFT
	SKIPN	UNILOG##(U)	;IS THIS UNIT IN AN STR?
	PUSHJ	P,TYPUNI	;YES - TYPE "," UNIT NAME & (ID)
	JRST	TYPNS2		;REPEAT
;SUBROUTINE TO TYPE ALL UNITS IN THE ACTIVE SWAPPING LIST
; RETURN WITH P1,P3,P4,F,U & J DESTROYED

TYPASL:	PUSHJ	P,OTSET##
	MOVSI	P3,MSWPMX##	;-VE LENGTH OF ASL
	HRRZ	U,SWPTAB##(P3)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN ASL
	SETOM	P4		;INDICATE CLASS FOR SWAPPING TO BE TYPED IN TYPUNI
	MOVEI	P1,[ASCIZ .
UNITS IN ACTIVE SWAPPING LIST:
.]
	PUSHJ	P,TYPUN1	;TYPE MSG., UNIT NAME & (CLASS FOR SWAPPING)
	JRST	TYPAS2

TYPAS1:	HRRZ	U,SWPTAB##(P3)	;GET ADR. OF NEXT UNIT DATA BLOCK IN ASL
	SKIPE	U		;END OF LIST WHEN ZERO ENTRY FOUND
	PUSHJ	P,TYPUNI	;TYPE "," UNIT NAME & (CLASS FOR SWAPPING)
TYPAS2:	AOBJN	P3,TYPAS1	;REPEAT IF LIST NOT COMPLETELY SCANNED
	PJRST	TYPSR1		;ADD CRLF & EXIT

;SUBROUTINE TO TYPE SIXBIT UNIT NAME FOLLOWED BY (ID/SWAPPING CLASS)
; ENTER WITH U = UNIT DATA BLOCK ADR.
; P4 = 0 TO TYPE UNIT ID. P4 = -VE TO TYPE SWAPPING CLASS

TYPUNI:	MOVEI	P1,[ASCIZ .,.]
TYPUN1:
	MOVE	T1,P1		;GET MSG. ADR. INTO KOSHER AC
	PUSHJ	P,SCONMS	;PUT "," OR MSG. IN BUFFER
	JUMPE	U,CPOPJ##	;JUST O/P MSG. IF NO UNITS IN ASL
	PUSHJ	P,SPUNAM	;PUT SIXBIT UNIT NAME IN BUFFER
	MOVEI	T1,[ASCIZ .(.]
	PUSHJ	P,SCONMS	;PUT "(" IN BUFFER
	JUMPL	P4,TYPUN2	;JUMP IF CLASS FOR SWAPPING TO BE TYPED
	SKIPE	T2,UNIHID##(U)	;GET SIXBIT UNIT ID - IF ANY
	PUSHJ	P,SPRNAM	;PUT IT IN THE BUFFER
	JRST	TYPUN3

TYPUN2:	LDB	T1,UNYCFS##	;GET CLASS FOR SWAPPING
	PUSHJ	P,SRDX10	;PUT DECIMALLY IN THE BUFFER
TYPUN3:	MOVEI	T1,[ASCIZ .).]
	PJRST	SCONMS
;SUBROUTINE TO TYPE ALL STR NAMES IN "SYS" SEARCH LIST

TYPSRC:	MOVEI	T1,[ASCIZ .
STRS IN "SYS" SEARCH LIST:.]
	PUSHJ	P,CONOUT
	PUSHJ	P,OTSET
	MOVE	P4,[PUSHJ P,TYPSTS]	;SETUP INSTR. FOR XCT IN FNDSRC
	PUSHJ	P,FNDSRC	;TYPE ALL STR NAMES IN "SYS" SEARCH LIST
TYPSR1:	PJRST	CRLFOP		;O/P CRLF


FNDSRC:	MOVE	P3,[-.SLMXS,,0]	;SETUP AOBJN PTR. FOR MAX. # STRS IN SEARCH LIST
FNDSR1:	HLRZ	P2,SYSSTR##	;GET ADR. OF 1ST. STR IN SYSTEM
	JUMPE	P2,CPOPJ##	;QUIT NOW IF NO FILE STRUCTURES
FNDSR2:	MOVE	T1,STRSRC##(P2)	;GET LOG. # OF STR IN SEARCH LIST
	CAIE	T1,(P3)		;IS IT THE ONE WE'RE LOOKING FOR?
	JRST	FNDSR3		;NO - GET NEXT STR
	XCT	P4		;EXECUTE INSTR. SUPPLIED BY CALLER
	AOBJP	P3,CPOPJ##	;EXIT IF MAX. # STRS SEEN
	JRST	FNDSR1

FNDSR3:	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK IN SYSTEM
	JUMPN	P2,FNDSR2	;REPEAT IF ANY LEFT
	AOBJN	P3,FNDSR1	;LOOK FOR NEXT LOG. STR #
	POPJ	P,		;EXIT


IFN FTSTR,<			;IF MAY BE MORE THAN ONE STR
DEPCLR:	HRRZ	T1,STRFSN##(P2)	;GET # OF THIS STR
	EXCH	P2,TEMPTR	;PUT IT IN SYS SL.
	PUSHJ	P,SLAPD##
	  PUSHJ	P,SLXAES##	;STOPCD AES IF NO ROOM
	PUSH	P,P2		;SAVE CURRENT LOC IN SL.
	MOVEI	T1,.FSFNC	;INSERT A FENCE
	PUSHJ	P,SLAPD##
	  PUSHJ	P,SLXAES##
	POP	P,P2		;BACK UP OVER THE FENCE
	EXCH	P2,TEMPTR
	POPJ	P,		;EXIT
>


TYPSTS:	JSP	T2,SVOTAC
	MOVEI	T1,[ASCIZ .,.]
	TRNE	P3,-1		;1ST STR?
	PUSHJ	P,SCONMS	;YES - NO COMMA
	PUSHJ	P,SPSNAM	;PUT SIXBIT STR NAME IN BUFFER
	POPJ	P,0
CHGUNA:	MOVEI	T1,[ASCIZ .
TYPE PHYSICAL UNIT NAME TO CHANGE ITS PARAMETERS(CR IF NONE, ALL IF ALL).]
	PUSHJ	P,CONOUT	;ADD CRLF & O/P MSG.
	PUSHJ	P,GETUNI	;GET USER'S RESPONSE
	  POPJ	P,		;JUST CR TYPED - EXIT
	PUSHJ	P,TYNMSG	;TYPE INSTRUCTIONS & CLEAR THE TYPE ONLY FLAG
	PUSHJ	P,SYSPLP	;TYPE & CHANGE PARAMETERS FOR ONE OR ALL UNITS
	  JRST	CHGUNA		;"ALL" WASN'T TYPED - ASK FOR NEXT UNIT NAME
	POPJ	P,		;EXIT


TYPUNA:	MOVEI	T1,[ASCIZ .
TYPE PHYSICAL UNIT NAME TO LIST ITS PARAMETERS(CR IF NONE, ALL IF ALL).]
	PUSHJ	P,CONOUT	;ADD CRLF & TYPE MSG.
	PUSHJ	P,GETUNI	;GET USER'S RESPONSE
	  POPJ	P,		;JUST CR TYPED - EXIT
	SETOM	TYPONL		;SET TYPE ONLY FLAG
	PUSHJ	P,SYSPLP	;TYPE PARAMETERS FOR ONE OR ALL UNITS IN SYSTEM
	  JRST	TYPUNA		;"ALL" WASN'T TYPED - ASK FOR NEXT UNIT NAME
	POPJ	P,		;EXIT


SYSPLP:	JUMPN	U,TYPUNP	;WAS "ALL" TYPED?
	HLRZ	U,SYSUNI##	;YES - GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
SYSPL1:	PUSHJ	P,SVOSET	;INITIALIZE CTY BUFFER
	PUSHJ	P,SCRLFO	;O/P A CRLF
	PUSHJ	P,SVOSET	;INITIALIZE CTY BUFFER
	PUSHJ	P,SPUNAM	;PUT SIXBIT UNIT NAME IN BUFFER
	PUSHJ	P,SOPOUT	; & O/P IT
	MOVSI	T1,UNPOFL##
	TDNN	T1,UNIDES##(U)	;IS UNIT OFF-LINE OR DOWN?
	PUSHJ	P,TYPUNP	;NO - TYPE (& CHANGE) PARAMETERS FOR THIS UNIT
	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,SYSPL1	;REPEAT IF ANY LEFT
	JRST	CPOPJ1##	;SKIP RETURN
TYPUNP:	HRRZ	P2,UNISTR##(U)	;GET ADR. OF STR DATA BLOCK UNIT BELONGS TO(IF ANY)
	MOVEI	T1,[ASCIZ .
PARAMETERS WHICH MAY NOT BE CHANGED WITHOUT REFRESHING.]
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	MOVEI	T1,[ASCIZ .
UNIT ID IS .]
	SKIPN	P1,UNIHID##(U)
ASKUID:	MOVEI	T1,[ASCIZ .
ZERO UNIT ID - NEW ID NEEDED.]
	PUSHJ	P,ASKSIX	;TYPE MSG. & TEXT(GET RESPONSE IF TYPONL=0)
	  JUMPL	T1,ASKFHB	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	JUMPE	P1,ASKUID	;NO - USER MUST SPECIFY NEW ID
	MOVEM	P1,UNIHID##(U)	;STORE NEW VALUE
	PUSHJ	P,REFCHU	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING
ASKFHB:	MOVE	T1,UNIHOM##(U)	;GET POSITION OF HOM BLOCKS
	CAME	T1,[XWD LBNHOM##,LB2HOM##]	;EITHER ORDER IS FINE
	CAMN	T1,[XWD LBNHOM##,LB2HOM##]
	JRST	ASKSPU			;EVERYTHING IS FINE
	MOVE	T1,[XWD LBNHOM##,LB2HOM##]	;GET CORRECT POSITION OF
					;HOM BLOCKS
	MOVEM	T1,UNIHOM##(U)		;PUT IN UNIT DATA BLOCK
	PUSHJ	P,REFCHU		;MAKE SURE HOM BLOCKS ARE
					;WRITTEN ON THIS UNIT
ASKSPU:	PUSHJ	P,COMLC1	;COMPUTE MIN. # SATS ON UNIT
	MOVE	T1,T2
	IDIVI	T2,MXSADA*^D36
	AOS	P4,T2
	MOVEM	P4,MIN
	IDIVI	T1,^D36		;COMPUTE GREATEST # SATS POSSIBLE ON THIS UNIT
	ADDI	T1,1
	MOVEI	T2,RIBLEN##	;# OF POINTERS
	LSH	T2,-1		;EACH SAT NEEDS TWO
	SUBI	T2,1		;SPARE
	CAILE	T1,(T2)		;LESS THAN THIS?
	MOVE	T1,T2		;NO--PUT IN AS NEW MAX
	MOVEM	T1,MAX
ASKSP1:	SKIPN	SHUTUP		;SKIP IF SHORT DIALOG
	JRST	.+4		;ELSE CONTINUE WITH NORMAL CODE
	LDB	T3,UNYKTP##	;GET KONTROLLER TYPE
	MOVE	P1,MIN	;NO. OF SAT BLOCKS DESIRED ON THIS UNIT
	JRST	SPUOK		;MAKE IT HAPPEN
	LDB	P1,UNYSPU##	;GET SAT BLOCKS ON UNIT.
	MOVEI	T1,[ASCIZ .# OF SAT BLOCKS ON UNIT = .]
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,TYPCPS	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	CAML	P1,P4		;IS NEW VALUE > THAN MIN. # POSSIBLE?
	JRST	ASKSP2		;YES - SEE IF LT. OR EQ. TO MAX. # SATS ON UNIT
	MOVEI	T1,[ASCIZ /?TOO SMALL - MIN. # = /]
	MOVE	P1,P4		;GET MIN. # INTO KOSHER AC
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKSP1		;ASK QUESTION AGAIN

ASKSP2:	CAMG	P1,MAX		;LESS THAN MAX. # ON UNIT?
	JRST	SPUOK		;YES - GO STORE VALUE & COMPUTE # CLUSTERS PER SAT
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKSP1		;ASK QUESTION AGAIN
SPUOK:	DPB	P1,UNYSPU##	;STORE NEW VALUE
	PUSHJ	P,REFCHU	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING

TYPCPS:	MOVE	T1,UNIDES##(U)
	TLZ	T1,UNPMSB##	;ASSUME ONLY 1 SAT BLOCK ON UNIT
	CAIE	P1,1		;MORE THAN 1?
	TLO	T1,UNPMSB##	;YES - FLAG THE FACT
	MOVEM	T1,UNIDES##(U)	;SAVE STATE IN UNIT DATA BLOCK
	PUSHJ	P,CMCWPS	;COMPUTE # CLUSTERS & SATS ON UNIT
	SKIPN	SHUTUP
	JRST	.+4
	LDB	T1,UNYSPU##
	DPB	T1,UNYSIC##
	PJRST	REFCHU
	HRRZ	P1,UNICPS##(U)	;GET # CLUSTERS PER SAT
	MOVEI	T1,[ASCIZ .THEREFORE CLUSTERS PER SAT = .]
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	LDB	P1,UNYWPS##	;GET # WORDS PER SAT
	MOVEI	T1,[ASCIZ .THEREFORE WORDS PER SAT = .]
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
ASKK4S:	SETZM	MIN		;0 IS ACCEPTABLE
	SKIPE	UNILOG##(U)	;SKIP IF NOT IN A FILE STRUCTURE
	JRST	CK4S1		;YES, FIGURE OUT SPACE AVAILABLE FOR SWAPPING
	MOVEI	T3,LB2HOM##+4	;FIRST BLOCK AVAILABLE FOR SWAPPING
	JRST	CK4SO		;COMPUTE MAX K FOR SWAPPING
CK4S1:	MOVEI	T1,LB2HOM##+2	;LAST BLOCK NOT AVAILABLE FOR SWAP THIS UNIT
	LDB	T2,UNYBPC##	;BLOCKS PER CLUSTER
	IDIV	T1,T2		;T1=LAST CLUSTER NOT AVAILABLE
	LDB	T3,UNYSPU##	;COUNT 1 CLUSTER FOR EACH SAT ON UNIT
	ADDI	T3,1(T1)	;PLUS CLUSTERS FOR HOME STUFF
	LDB	T1,UNYLUN##	;LOGICAL UNIT IN STR
	JUMPN	T1,CK4S2	;JUMP IF NOT 1ST UNIT IN STR
	ADDI	T3,RB1UN##	;+CLUSTERS FOR RIBS ON 1ST UNIT REFRESHER MAKES
	LDB	T1,UNYBPC##	;BLOCKS PER CLUSTER
	CAIG	T1,2
	MOVEI	T1,3
	LDB	T2,UNYBPC##	;BLOCKS PER CLUSTER
	ADDI	T1,-1(T2)
	IDIV	T1,T2		;CLUSTERS FOR MFD
	IMULI	T1,3		;COUNT SAME FOR SYS AND PRT UFD'S
	ADD	T3,T1		;COUNT CLUSTERS NECESSARY FOR REFRESHER
CK4S2:	HRRZ	T1,STRUNM##(P2)	;NUMBER OF UNITS IN STR
	LDB	T2,UNYLUN##	;LOGICAL UNIT IN STR
	CAIE	T1,1(T2)	;SKIP IF THIS IS LAST UNIT IN STR
	JRST	CK4S3		;NO
	ADDI	T3,RBLUN##	;COUNT RIBS REFRESHER WRITES ON LAST UNIT
	HRRZ	T1,STRK4C##(P2)	;K FOR CRASH SAV
	LSH	T1,BLKSPK##	;CONVERT TO BLOCKS
	ADDI	T1,2		;+2 FOR RIBS
	LDB	T2,UNYBPC##	;BLOCKS PER CLUSTER
	ADDI	T1,-1(T2)
	IDIV	T1,T2		;CLUSTERS FOR CRASH SAV
	ADD	T3,T1
	MOVEI	T1,2		;2 BLOCKS FOR SNAP SYS AND RECOV SYS
	LDB	T2,UNYBPC##
	ADDI	T1,-1(T2)
	IDIV	T1,T2		;CLUSTERS FOR SNAP SYS
	LSH	T1,2
	ADD	T3,T1
CK4S3:	LDB	T2,UNYBPC##	;BLOCKS PER CLUSTER
	IMUL	T3,T2		;T3=1ST BLOCK AVAILABLE FOR SWAPPING
CK4SO:	MOVEM	T3,TMPMIN	;SAVE FIRST BLOCK TO SWAP
	SOJ	T3,		;(T3)=LAST BLOCK NOT AVAILABLE FOR SWAP
	MOVE	T1,UNIBPU##(U)	;BLOCKS ON UNIT
	SUB	T1,T3		;T1=BLOCKS AVAILABLE FOR SWAPPING
	HRRZ	T2,UNICPS##(U)	;NOW GET CLUSTERS PER SAT
	LDB	T3,UNYBPC##	;AND GET BLOCKS PER CLUSTER
	JUMPE	T3,CK4S6	;FORGET IT IF NOT IN A STR
	IMULI	T3,-1(T2)	;MULTIPLY TO GET BLOCKS PER SAT - 1 CLUSTER
	CAMLE	T1,T3		;WILL 1 SAT BLOCK HOLD MORE THAN THIS STR
	MOVE	T1,T3		;NO, CAN'T USE ALL OF STR FOR SWAPPING
CK4S6:	LSH	T1,MBKSPK##	;CONVERT TO MAX K FOR SWAPPING
	MOVEI	T2,1
	LSH	T2,LIMK4S##
	SUBI	T2,1		;MAX THAT FITS IN FIELD
	CAMLE	T1,T2
	MOVE	T1,T2		;MIN OF FIELD, BLOCKS AVAILABLE
	MOVEM	T1,MAX		;IS MAX K FOR SWAPPING
	SKIPN	SHUTUP
	JRST	CK4S4
	LDB	T4,UNYKTP##	;KONTROLLER TYPE
	LDB	T3,UNYKNM##	;KONTROLLER NUMBER WITHIN TYPE
	LDB	T2,UNYPUN##	;PHYSICAL UNIT WITHIN KONTROLLER
	MOVE	P1,@K4STAB(T4)	;GET K4 SWAPPING ON UNIT
	JUMPE	P1,K4SOK	;ZERO SPEC IS ALWAYS GOOD.
	CAMLE	P1,MAX		;GREATER THAN MAX ALLOWED?
	MOVE	P1,MAX		;YES--USE MAX
	JRST	K4SOK		;NO-GO ALLOCATE WHAT HE ASKED FOR
CK4S4:	MOVEI	T1,[ASCIZ .
K FOR SWAPPING ON UNIT = .]
	LDB	P1,UNYK4S##
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET RESPONSE IF TYPONL=0)
	  JUMPL	T1,ASKSLB	;TYPONL=-1, CR OR NO CHANGE IN VALUE
CK4S5:	CAMG	P1,MAX		;SWAPPING  MORE BLOCKS THAN ON UNIT?
	JRST	K4SOK		;NO - GO STORE NEW VALUE IN STR DATA BLOCK
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKK4S		;ASK QUESTION AGAIN
K4SOK:	LSH	P1,BLKSPK##	;COMPUTE (# BLOCKS NEEDED FOR SWAPPING)
	MOVE	T3,UNIBPU##(U)	;PUT # BLOCKS ON UNIT INTO T2. RESPECTED BY REFCHG
	SUB	T3,P1		;COMPUTE 1ST. LOG. BLOCK FOR SWAPPING
	LSH	T3,-1		;DIVIDE BY 2 SO SWAP AREA CENTERED ON DISK
	TRZ	T3,3
	CAMGE	T3,TMPMIN	;ABOVE MINIMUM BLOCK FOR SWAPPING?
	MOVE	T3,TMPMIN	;NO, USE MINIMUM BLOCK INSTEAD
	LSH	P1,MBKSPK##	;CONVERT BLOCKS FOR SWAPPING BACK INTO J
	DPB	P1,UNYK4S##	;STORE NEW VALUE
	PUSHJ	P,REFCHU	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING
	JUMPE	P1,TYPUNN	;IF NO SWAPPING SPACE ALLOCATED SKIP QUESTIONS
	MOVE	T1,TMPMIN	;GET MIN BLOCK TO SWAP TO
	MOVEM	T1,MIN		;MIN BLOCK FOR SWAPPING SPACE
	LDB	T4,UNYK4S##	;GET # K FOR SWAPPING
	LSH	T4,BLKSPK##	;COMPUTE # BLOCKS FOR SWAPPING ON UNIT
	MOVE	T2,UNIBPU##(U)	;GET # BLOCKS ON UNIT
	SUB	T2,T4		;COMPUTE HIGHEST 1ST. LOG. BLOCK # POSSIBLE
	TRZ	T2,3
	MOVEM	T2,MAX		;MAX=HIGHEST LEGAL BLOCK
	MOVE	P1,T3
	MOVE	T1,UNISLB##(U)	;GET 1ST. LOG. BLOCK FOR SWAPPING
	CAILE	T1,LB2HOM##+1	;IS IT BETWEEN 0 & 2ND. BAT BLOCK?
	JRST	K4SOK1		;NO
	PUSHJ	P,TRFCHU	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING
	MOVEM	P1,UNISLB##(U)	;SUBSTITUTE COMPUTED VALUE OF 1ST. LOG. BLOCK
K4SOK1:	SKIPE	SHUTUP		;SKIP IF NOT SHORT DIALOG
	JRST	SLBOK		;JUST USE COMPUTED BLOCK NO.
	MOVEI	T1,[ASCIZ /COMPUTED 1ST. LOGICAL BLOCK FOR SWAPPING = /]
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKSL1

;**:
ASKSLB:	JUMPE	P1,TYPUNN	;DON'T ASK OR TYPE SWAPPING STUFF IF NO SWAPPING SPACE
ASKSL1:	MOVEI	T1,[ASCIZ /1ST. LOGICAL BLOCK FOR SWAPPING = /]
	MOVE	P1,UNISLB##(U)
	SKIPGE	TYPONL		;IF JUST LISTING VALUES,
	MOVEM	P1,MAX		;U MAX ISN'T SET UP
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,TYPUNN	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	PUSHJ	P,CANTB0	;TYPE 'CANNOT BE 0' IF P1 = 0
	  JRST	ASKSL1		;P1 = 0 - ASK QUESTION AGAIN
	CAML	P1,MIN		;IS NEW VALUE IN FORBIDDEN AREA?
	JRST	HGHSLB		;NO
	MOVEI	T1,[ASCIZ .?MUST EXCEED .]
	MOVE	P1,MIN
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKSL1		;ASK QUESTION AGAIN
HGHSLB:	CAMG	P1,MAX		;IS SPECIFIED VALUE GREATER THAN THIS?
	JRST	SLBOK		;NO - GO STORE NEW VALUE
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKSL1		;ASK QUESTION AGAIN

SLBOK:	TRZ	P1,3
	MOVEM	P1,UNISLB##(U)	;STORE NEW VALUE
	PUSHJ	P,REFCHU	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING
;HERE TO CHANGE AND/OR TYPE PARAMETRS THAT DON'T REQUIRE REFRESHING

TYPUNN:	MOVEI	T1,[ASCIZ .
PARAMETERS WHICH MAY BE CHANGED WITHOUT REFRESHING.]
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	MOVEI	P2,0		;PRETEND UNIT HAS NO STR SO CALLS TO REFCHU
				; WILL NOT SET STR NEEDS REFRESHING FLAG(STRREF)
ASKNSC:	LDB	T1,UNYSPU##	;GET NUMBER OF SAT BLOCK ON UNIT
	MOVEM	T1,MAX		;CAN'T HAVE MORE THAN THAT IN CORE
	MOVEI	T1,1		;MUST HAVE AT LEAST 1 SAT BLOCK
	MOVEM	T1,MIN		;IN CORE
	MOVEI	T1,[ASCIZ .# SAT BLOCKS IN CORE = .]
	LDB	P1,UNYSIC##
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,CPOPJ##		;TYPONL=-1, CR OR NO CHANGE IN VALUE
	LDB	T2,UNYSPU##	;GET # SATS ON UNIT
	CAMG	P1,T2		;# SATS IN CORE SHOULDN'T EXCEED # SATS ON UNIT
	JRST	ZERSIC		;THEY DON'T
	MOVEI	T1,[ASCIZ .?CANNOT EXCEED # SAT BLOCKS ON UNIT = .]
	MOVE	P1,T2		;GET # SATS ON UNIT INTO KOSHER AC
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKNSC		;ASK QUESTION AGAIN

ZERSIC:				;NO SATS IN CORE ISN'T ALLOWED EITHER
	PUSHJ	P,CANTB0	;TYPE 'CANNOT BE 0' IF P1 = 0
	  JRST	ASKNSC		;P1 = 0 - ASK QUESTION AGAIN

SICOK:	DPB	P1,UNYSIC##	;STORE NEW VALUE
	PJRST	REFCHU		;UNIT NEEDS "HOME" BLOCKS REWRITING
DMKUNI:	HLRZ	U,SYSUNI##	;GET 1ST UNIT DATA BLOCK
DMKUN1:	MOVSI	T1,UNPWPO##	;OFF LINE AND WRITE PROTECT BITS
	TDNE	T1,UNIDES##(U)	;SKIP IF ON LINE
	JRST	DMKUN3		;GET NEXT UNIT AND PROCEED
	LDB	J,UNYKTP##	;GET KONTROLLER TYPE IN J
	MOVE	T1,TIME##		;SET UP RANDOM TEMPORARY UNIT ID
	ADD	T1,U		;ADD IN THE UNIT DATA BLOCK ADRESS
	XOR	T1,THSDAT##	;OR THE DATE IN-THIS CREATES UNIQUE NUMBER.
	MOVE	T2,[XWD -1,505050]
	ANDCAM	T2,T1		;GET RID OF ALL BUT 3 NUMBERS
	MOVE	T2,[XWD 'ONC',202020]	;MAKE SURE ALL IS SIXBIT
	IORM	T2,T1		;PUT IT IN
	MOVEM	T1,UNIHID##(U)	;USE IT AS A UNIQUE ID
	MOVE	T1,[XWD LBNHOM##,LB2HOM##]	;STANDARD HOM BLOCKS AT 1 AND 10
	PUSHJ	P,ASKSPU	;SET UP SAYS PER UNIT
	PUSHJ	P,ASKK4S	;GO TO THIS SUBROUTINE FOR REST OF STUFF.
DMKUN2:	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT
	JUMPN	U,DMKUN1	;IF IT EXISTS, CONTINUE
	POPJ	P,		;OR ELSE, WERE DONE.
DMKUN3:	SETZ	T1,
	DPB	T1,UNYSIC##	;NO SATS IN CORE FOR DONW UNITS
	JRST	DMKUN2		;GET NEXT UNIT
CHGSTA:	MOVEI	T1,[ASCIZ .
TYPE STR NAME TO CHANGE ITS PARAMETERS(CR IF NONE, ALL IF ALL).]
	PUSHJ	P,ASKSTR	;TYPE MSG. & GET RESPONSE
	  POPJ	P,		;CR WAS TYPED - EXIT
	PUSHJ	P,TYNMSG	;TYPE INSTRUCTIONS & CLEAR THE TYPE ONLY FLAG
	PUSHJ	P,DSKPLP	;TYPE & CHANGE PARAMETRS
	  JRST	CHGSTA		;ASK QUESTION AGAIN IF "ALL" WAS NOT TYPED
	POPJ	P,		;"ALL" WAS TYPED - EXIT

TYPSTA:	MOVEI	T1,[ASCIZ .
TYPE STR NAME FOR A LIST OF ITS PARAMETERS(CR IF NONE, ALL IF ALL).]
	PUSHJ	P,ASKSTR	;TYPE MSG. & GET RESPONSE
	  POPJ	P,		;CR WAS TYPED - EXIT
	SETOM	TYPONL		;SET TYPE ONLY FLAG
	PUSHJ	P,DSKPLP	;TYPE PARAMETRS
	  JRST	TYPSTA		;ASK QUESTION AGAIN IF "ALL" WAS NOT TYPED
	POPJ	P,		;"ALL" WAS TYPED - EXIT

DSKPLP:	JUMPN	P2,TYPSTP	;WAS "ALL" TYPED?(P2 RETURNED 0 FROM ASKSTR)
	HLRZ	P2,SYSSTR##	;YES - GET ADR. OF 1ST. STR DATA BLOCK IN SYSTEM
	JUMPE	P2,CPOPJ1##	;SKIP RETURN IF THERE ISN'T ONE
DSKPL1:	PUSHJ	P,SVOSET	;INITIALIZE CTY BUFFER
	PUSHJ	P,SCRLFO	;O/P A CRLF
	PUSHJ	P,SVOSET	;INITIALIZE CTY BUFFER
	PUSHJ	P,SPSNAM	;PUT STR NAME IN BUFFER
	PUSHJ	P,SOPOUT	; & O/P IT
	PUSHJ	P,TYPSTP	;TYPE PARAMETERS FOR THIS STR
	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK IN SYSTEM
	JUMPN	P2,DSKPL1	;REPEAT IF NOT LAST ONE
	JRST	CPOPJ1##	;SKIP RETURN

TYNMSG:	MOVEI	T1,[ASCIZ .
AFTER EACH PRINTING OF CURRENT VALUE, TYPE NEW VALUE OR CR.]
	SETZM	TYPONL		;CLEAR TYPE ONLY FLAG
	PJRST	SVMOUT		;ADD CRLF & O/P MSG.

TYPONL:	0
TYPSTP:	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	JUMPE	U,CPOPJ##	;IF NO UNITS IN THIS STR - EXIT
	MOVEI	T1,[ASCIZ .
PARAMETERS WHICH MAY BE CHANGED WITHOUT REFRESHING.]
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	MOVEI	T1,1
	MOVEM	T1,MIN		;MUST HAVE 1 BLOCK TRIED FOR ON OUTPUT
	MOVE	T1,STRSIZ##(P2)
	TLNE	T1,-1
	MOVEI	T1,-1
	MOVEM	T1,MAX		;MAY HAVE WHOLE LEFT HALF
TYPPR1:	MOVEI	T1,[ASCIZ .# OF CONSECUTIVE BLOCKS TRIED FOR ON OUTPUT = .]
	HLRZ	P1,UNIGRP##(U)
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,ASKBGA	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	PUSHJ	P,CANTB0	;TYPE 'CANNOT BE 0' IF P1 = 0
	  JRST	TYPPR1		;P1 = 0 - ASK QUESTION AGAIN
;HERE TO STORE NEW VALUE OF UNIGRP IN ALL UNIT DATA BLOCKS IN THIS STR

TYPPR2:	HRLM	P1,UNIGRP##(U)	;STORE NEW VALUE IN THIS UNIT DATA BLOCK
	HLRZ	U,UNISTR##(U)	;GET NEXT UNIT DATA BLOCK ADR. IN THIS STR
	JUMPN	U,TYPPR2	;STORE VALUE IN IT
	PUSHJ	P,CHGSTR	;SET 'UNPCHG' BIT FOR ALL UNITS IN STR

ASKBGA:	SETZM	MIN		;MAY HAVE 0 RESERVED
	MOVE	T1,STRSIZ##(P2)	;MAX IS SIZE OF STR
	MOVEM	T1,MAX
	MOVEI	T1,[ASCIZ .SUM OF BLOCKS GUARANTEED TO USERS = .]
	MOVE	P1,STRGAR##(P2)
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,ASKBOU	;TYPONL=-1, CR OR NO CHANGE IN VALUE

ASKBG1:	CAMG	P1,STRSIZ##(P2)	;MORE BLOCKS THAN IN STR?
	JRST	ASKBG2		;NO
	MOVEI	T1,[ASCIZ .?CANNOT EXCEED # BLOCKS IN FILE STRUCTURE = .]
	MOVE	P1,STRSIZ##(P2)
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKBGA		;ASK QUESTION AGAIN

ASKBG2:	MOVEM	P1,STRGAR##(P2)	;STORE NEW VALUE
	PUSHJ	P,CHGSTR	;SET 'UNPCHG' BIT FOR ALL UNITS IN STR

ASKBOU:	MOVEI	T1,[ASCIZ .# BLOCKS ALLOWED FOR OVERDRAW PER USER = .]
	MOVM	P1,STROVR##(P2)
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,TYPSTN	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	CAMG	P1,STRSIZ##(P2)	;MORE BLOCKS THAN IN STR?
	JRST	ASKBO1		;NO - GO STORE NEW VALUE
	MOVEI	T1,[ASCIZ .CANNOT EXCEED # BLOCKS IN FILE STRUCTURE = .]
	MOVE	P1,STRSIZ##(P2)
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	JRST	ASKBOU		;ASK QUESTION AGAIN
ASKBO1:	MOVNM	P1,STROVR##(P2)	;STORE NEW VALUE
	PUSHJ	P,CHGSTR	;SET 'UNPCHG' BIT FOR ALL UNITS IN STR

TYPSTN:
IFN FTPSTR,<
	SKIPL	TYPONL		;ASKING
	JRST	ASKPRV		;YES, GO ASK
	MOVEI	T1,[ASCIZ .
NOT PRIVATE
.]
	LDB	T2,STYPVS##
	SKIPE	T2		;PRIVATE
	MOVEI	T1,[ASCIZ .
PRIVATE STRUCTURE
.]
	PUSHJ	P,SVMOUT	;TELL WHICH
	JRST	TYPNRF
ASKPRV:	MOVEI	T1,[ASCIZ .
IS THIS A PRIVATE STR? (TYPE Y IF PRIVATE, N IF NO ACCESS RESTRICTIONS)
.]
	PUSHJ	P,ASKQUE	;ASK HIM
	TDZA	T1,T1		;HE SAID NO
	MOVEI	T1,1		;HE SAID YES
	LDB	T2,STYPVS##	;GET CURRENT SETTING
	DPB	T1,STYPVS##	;STORE NEW SETTING
	CAME	T1,T2		;DID IT CHANGE?
	PUSHJ	P,CHGALL	;YES, NOTE THAT
>
TYPNRF:	MOVEI	T1,[ASCIZ .
PARAMETERS WHICH MAY NOT BE CHANGED WITHOUT REFRESHING.]
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
IFE FT22BIT&FTEXE,<
	MOVEI	T1,^D256
>
IFN FT22BIT&FTEXE,<
	MOVEI	T1,^D4096	;MAX K FOR CRASH.SAV IS 4096K IF MORE THAN 256K
				; IS SUPPORTED
>
	MOVEM	T1,MAX		;MAX K FOR CRASH.SAV IS 256
ASKK4C:
IFE FTEXE,<
	MOVEI	T1,[ASCIZ /K FOR CRASH.SAV = /]
>
IFN FTEXE,<
	MOVEI	T1,[ASCIZ  /K FOR CRASH.EXE = /]
>
	HRRZ	P1,STRK4C##(P2)
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET RESPONSE IF TYPONL=0)
	  JUMPL	T1,ASKBP2	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	CAMG	P1,MAX		;SEE IF VALUE EXCEEDS MAX. AMOUNT OF CORE POSSIBLE
	JRST	K4COK		;IT DOESN'T - GO STORE NEW VALUE
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKK4C		;ASK QUESTION AGAIN

K4COK:	HRRZ	T1,STRK4C##(P2)	;GET CURRENT VALUE
	HRRM	P1,STRK4C##(P2)	;STORE NEW VALUE
	PUSHJ	P,TRFCHS	;STR NEEDS REFRESHING, UNIT'S "HOME" BLOCKS REWRITING
ASKBP2:	AOS	T1,MIN		;MUST HAVE 1 BLOCK PER CLUSTER
	LSH	T1,LIMBPC##	;COMPUTE MAX. # OF BLOCKS PER CLUSTER+1
	SUBI	T1,1		;MAXIMUM BLOCKS PER CLUSTER
	MOVEM	T1,MAX
ASKBPC:	HLRZ	U,STRUNI##(P2)	;GET 1ST. UNIT DATA BLOCK ADR. IN THIS STR
	MOVEI	T1,[ASCIZ .BLOCKS PER CLUSTER = .]
	LDB	P1,UNYBPC##
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET RESPONSE IF TYPONL=0)
	  JUMPL	T1,TYPCLT	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	PUSHJ	P,CANTB0	;TYPE 'CANNOT BE 0' IF P1 = 0
	  JRST	ASKBPC		;P1 = 0 - ASK QUESTION AGAIN

ASKBP1:	CAMG	P1,MAX		;IS NEW VALUE < LIMIT
	JRST	BPCOK		;YES - GO STORE NEW VALUE IN ALL UNIT DATA BLOCKS
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKBPC		;ASK QUESTION AGAIN

BPCOK:	PUSHJ	P,BPCSTO	;STORE BPC AND SET UP STYCLP
TYPCLT:	MOVEI	T1,[ASCIZ /THEREFORE BITS PER CLUSTER ADR. = /]
	LDB	P1,[POINT 6,STYCLP##(P2),11]
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	MOVEI	T1,[ASCIZ .THEREFORE BLOCKS PER SUPER-CLUSTER = .]
	HLRZ	P1,STRBSC##(P2)
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	MOVEI	T1,[ASCIZ .THEREFORE SUPER-CLUSTERS PER UNIT = .]
	HRRZ	P1,STRSCU##(P2)
	PUSHJ	P,DECLOP	;TYPE MSG. & VALUE
	PUSHJ	P,SVOSET
	SKIPL	TYPONL		;SKIP IF ONLY TYPING PARAMS
	PUSHJ	P,SCRLFO	;EXTRA CRLF BEFORE NEXT QUESTION

	LDB	T3,[POINT 6,STYCLP##(P2),11]
	MOVN	T2,T3
	ADDI	T2,^D36
	CAILE	T2,LIMCNP##	;MAKE SURE DOESNT EXCEED LIMCMP
	MOVEI	T2,LIMCNP##
	MOVEM	T2,MAX		;THAT MIN IS MAX
ASKBCC:	MOVEI	T1,[ASCIZ .BITS PER CLUSTER COUNT = .]
	LDB	P1,[POINT 6,STYCNP##(P2),11]
	PUSHJ	P,ASKDMM	;TYPE MSG. & VALUE(GET NEW VALUE IF TYPONL=0)
	  JUMPL	T1,TYPBCK	;TYPONL=-1, CR OR NO CHANGE IN VALUE
	PUSHJ	P,CANTB0	;TYPE 'CANNOT BE 0' IF P1 = 0
	  JRST	ASKBCC		;P1 = 0 - REPEAT QUESTION

ASKBC1:	CAMG	P1,MAX
	JRST	CNPOK
	PUSHJ	P,CANTEX	;TYPE 'CANNOT EXCEED' & VALUE
	JRST	ASKBCC

CNPOK:	PUSHJ	P,CNPSTO
TYPBCK:	MOVEI	T1,[ASCIZ .THEREFORE BITS PER CHECKSUM = .]
	LDB	P1,[POINT 6,STYCKP##(P2),11]
	PJRST	DECLOP		;TYPE MSG. & VALUE
KILSTR:	HLRZ	U,SYSUNI##
KLSTR2:	SETZM	UNISTR##(U)
	SETZM	UNILOG##(U)
	HRRZS	UNIGRP##(U)
	SETZ	T1,
	DPB	T1,UNYBPC##
	PUSHJ	P,SETCHG
	HLRZ	U,UNISYS##(U)
	JUMPN	U,KLSTR2
	MOVE	T1,STRAOB##	;CLEAR TABSTR
	SETZM	TABSTR##(T1)
	AOBJN	T1,.-1
	POPJ	P,


ASKDIS:	MOVEI	T1,[ASCIZ .TYPE STR NAME TO BE DISSOLVED(CR IF NONE, ALL IF ALL).]
	SKIPE	SYSSTR##	;DON'T TYPE MSG. IF NO STR'S
	PUSHJ	P,ASKSTR	;TYPE MSG. & GET RESPONSE
	  POPJ	P,		;CR WAS TYPED - EXIT
	JUMPN	P2,ASKDS2	;WAS "ALL" TYPED?(P2 RETURNED 0 FROM ASKSTR)
	HLRZ	P2,SYSSTR##	;YES - GET 1ST. STR DATA BLOCK ADR. IN SYSTEM
	MOVEI	P3,DIFSTR##	;SETUP P3 AS PREDECESSOR STR DATA BLOCK
ASKDS1:	PUSHJ	P,DISSTR	;DISSOLVE STR
	HLRZ	P2,STRSYS##(P2)	;GET NEXT STR DATA BLOCK ADR. IN SYSTEM
	JUMPN	P2,ASKDS1	;REPEAT IF NOT LAST ONE
	POPJ	P,		;EXIT

ASKDS2:	PUSHJ	P,DISSTR	;DISSOLVE STR
	JRST	ASKDIS		;ASK QUESTION AGAIN

DISSTR:	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	JUMPE	U,DISST2	;JUST UNLINK STR IF IT HAS NO UNITS
	PUSHJ	P,DISST1	;GO TAKE CARE OF ALL UNITS IN STR
DISST2:	HLL	T3,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK IN SYSTEM
	HLLM	T3,STRSYS##(P3)	; & LINK IT TO PREDECESSOR DATA BLOCK(OR SYSSTR)
	HRRZ	T1,STRFSN##(P2)	;GET THIS STR'S LOG. #
	SETZM	TABSTR##(T1)	;INDICATE STR NO LONGER EXISTS
	POPJ	P,		;RETURN - DON'T WORRY ABOUT RETURNING CORE
				; AS REDHOM MUST BE CALLED AGAIN
DISST1:	SETZB	T3,UNILOG##(U)	;CLEAR OUT NAME OF LOGICAL UNIT WITHIN STR
	EXCH	T3,UNISTR##(U)	;CLEAR OUT LINKS TO STR & NEXT UNIT DATA BLOCKS
	HRRZS	UNIGRP##(U)	;CLEAR # CLUSTERS TRIED FOR ON O/P
	MOVEI	T1,0
	DPB	T1,UNYBPC##	;CLEAR # BLOCKS PER CLUSTER
	PUSHJ	P,SETCHG	;FLAG THAT THIS UNIT'S "HOME" BLOCK MUST BE REWRITTEN
	HLRZ	U,T3		;GET NEXT UNIT DATA BLOCK ADR.
	JUMPN	U,DISST1	;REPEAT IF THERE IS ONE
	POPJ	P,
ASKDEF:	PUSHJ	P,ALLINS	;SKIP IF ANY UNITS NOT IN FILE STRUCTURES
	  POPJ	P,
	MOVEI	T1,[ASCIZ .TYPE STR NAME TO BE DEFINED(CR IF NONE). ]
	PUSHJ	P,CONOUT	;O/P MSG. & ADD CRLF
	PUSHJ	P,GETLIN##	;GET USER'S RESPONSE
	  JRST	DEMSTR		;JUST CR TYPED - EXIT ONLY IF AT LEAST ONE STR EXISTS
	PUSHJ	P,ALTM		;IN CASE OF $ COP OUT
	PUSHJ	P,CTEXT##	;GET SIXBIT STR NAME
	MOVE	T1,T2		;GET SIXBIT NAME INTO KOSHER AC FOR FNSTR
	PUSHJ	P,FNSTR		;SEE IF STR ALREADY EXISTS
	  JRST	DEFNEW		;IT DOESN'T
	MOVEI	T1,[ASCIZ .?STR ALREADY EXISTS.]
	PUSHJ	P,CONOUT	;ADD CRLF & O/P MSG.
	JRST	ASKDEF		;ASK QUESTION AGAIN

DEMSTR:	SKIPN	SYSSTR##	;DO ANY STR'S EXIST?
	JRST	ASKDEF		;NO - AT LEAST ONE STR MUST BE DEFINED
	POPJ	P,		;EXIT

DEFNEW:	PUSH	P,T1		;SAVE STR NAME
	PUSHJ	P,GETSTR	;CREATE STR DATA BLOCK IN UPPER CORE & ZERO IT OUT
	  SKIPA	T1,[[ASCIZ .
?TOO MANY FILE STRUCTURES
.]]
	JRST	DEFNE1
	POP	P,T2		;POP OFF STR NAME
	PJRST	CONOUT		;TYPE MSG.

DEFNE1:	POP	P,STRNAM##(P2)	;RESTORE SIXBIT STR NAME IN STR DATA BLOCK
	HLLOS	STRUNI##(P2)	;INDICATE STR MUST BE REFRESHED
	SETOM	STRSRC##(P2)	;NOT IN SYS SEARCH LIST

DEFNE2:	MOVEI	T1,[ASCIZ .TYPE NAMES OF PHYSICAL UNITS IN STR(ALL IF ALL, EXTRA CR WHEN DONE).]
	PUSHJ	P,CONOUT	;O/P MSG. & ADD CRLF
	MOVEI	P3,STRUNI##(P2)	;MAKE ADR. OF LINK TO 1ST. UNIT DATA BLOCK IN STR
				; LOOK LIKE A PREDECESSOR UNIT DATA BLOCK
	SETZ	P1,
GETNXT:	PUSHJ	P,GETUNI	;GET USER'S RESPONSE
	  JRST	NXTPST		;JUST CR TYPED - ASK FOR NEXT STR NAME
	JUMPE	U,ALLUNI	;WAS "ALL" TYPED?
	PUSHJ	P,INSUNI	;NO - JUST PUT THIS UNIT INTO THE STR
	  JRST	DEFNE2		;UNIT ALREADY IN AN STR
	PUSHJ	P,HGHSIZ	;COMPUTE STRHGH & STRSIZ FOR THIS STR
	JRST	GETNXT		;GET THE NEXT UNIT

NXTPST:	PUSHJ	P,PARSET	;SET UP DEFAULTS
	JRST	ASKDEF
ALLUNI:	HLRZ	U,SYSUNI##	;NO - USE ALL UNITS IN THE SYSTEM
ALLUN1:	PUSHJ	P,INSUNI	;PUT THIS UNIT INTO STR
	  JRST	DEFNE2		;UNIT ALREADY IN AN STR
	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT IN THE SYSTEM
	JUMPN	U,ALLUN1	;REPEAT IF THERE IS ONE
	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	PUSHJ	P,HGHSIZ	;COMPUTE STRHGH & STRSIZ FOR THIS STR
	PJRST	PARSET		;SET DEFAULTS AND EXIT

HGHSIZ:	MOVE	T1,UNIBPU##(U)	;GET # BLOCKS ON UNIT
	ADDM	T1,STRSIZ##(P2)	;ADD TO TOTAL # BLOCKS IN STR
	MOVE	T1,STRBPU##(P2)	;GET MAX. # BLOCKS PER UNIT IN STR
	ADDM	T1,STRHGH##(P2)	;ADD TO HIGHEST LOG. BLOCK # IN STR
	HLRZ	U,UNISTR##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	JUMPN	U,HGHSIZ	;REPEAT IF ANY LEFT
	SOS	STRHGH##(P2)	;MAKE STRHGH BE HIGHEST LOG. BLOCK # IN STR
	POPJ	P,		;RETURN

INSUNI:	HRRZ	T1,UNISTR##(U)	;SEE IF THIS UNIT IS ALREADY IN AN STR
	JUMPE	T1,INSUN1	;T1 = 0 IF IT ISN'T
	MOVEI	T1,[ASCIZ .
?UNIT ALREADY IN FILE STRUCTURE
.]
	PJRST	CONOUT		;TYPE MSG. & EXIT

INSUN1:	HRLM	U,(P3)		;LINK THIS UNIT DATA BLOCK TO PREVIOUS ONE
	HRRZM	P2,UNISTR##(U)	;ATTACH THIS UNIT DATA BLOCK TO THIS STR
	HRRZ	T1,STRUNM##(P2)	;GET LOGICAL UNIT # WITHIN STR
	DPB	T1,UNYLUN##	;SAVE IT IN UNIT DATA BLOCK
	PUSHJ	P,CMPLOG	;COMPUTE SIXBIT LOGICAL UNIT NUM, STORE IN UNILOG
	MOVE	T1,UNIBPU##(U)
	CAMLE	T1,STRBPU##(P2)
	MOVEM	T1,STRBPU##(P2)
	CAIE	P1,0		;SKIP IF 1ST UNIT
	CAMGE	T1,UNIBPU##(P1)	;COMPARE WITH SMALLEST SO FAR
	MOVE	P1,U		;SAVE ADDR OF SMALLEST IN P1
	AOS	STRUNM##(P2)	;INCREMENT # OF UNITS IN STR
	PUSHJ	P,SETCHG	;FLAG THAT UNIT'S "HOME" BLOCKS MUST BE REWRITTEN
	MOVEI	P3,UNISTR##(U)	;MAKE CURRENT UNIT PREDECESSOR
	JRST	CPOPJ1##	;SKIP RETURN
;SUBROUTINE TO SET DEFAULTS IN STR DATA BLOCK
;ARGS	P1=ADDR OF SMALLEST UNIT IN STR

PARSET:	MOVE	U,P1		;U=ADDR OF SMALLEST UNIT IN STR
	LDB	P1,UNYKTP##	;CONTROLLER TYPE OF SMALLEST UNIT
	MOVE	T2,GRPDEF(P1)	;UNIGRP DEFAULT
	MOVE	T1,[HRLM T2,UNIGRP##(U)]
	PUSHJ	P,STOUNI	;STORE IN ALL UNIT DATA BLOCKS
	PUSH	P,P1		;SAVE CONTROLLER TYPE
	MOVE	P1,BPCDEF(P1)	;P1 IS ARG FOR BPCSTO
	PUSHJ	P,BPCSTO	;STORE BPC AND SET UP BYTE POINTERS
	MOVE	T3,(P)		;CONTROLLER TYPE TO T3
	MOVE	P1,CNPDEF(T3)	;DEFAULT BITS PER CLUSTER COUNT FIELD
	LDB	T3,[POINT 6,STYCLP##(P2),11]	;BITS PER CLUSTER ADDR FIELD
	PUSHJ	P,CNPSTO	;STORE THAT IN BYTE POINTERS
	POP	P,P1		;RESTORE CONTROLLER TYPE
	MOVE	T1,GARDEF(P1)	;DEFAULT RESERVE
	MOVEM	T1,STRGAR##(P2)
	MOVE	T1,OVRDEF(P1)	;DEFAULT OVERDRAW
	MOVNM	T1,STROVR##(P2)	;STORED NEGATIVE
	MOVE	T1,K4CDEF(P1)
	HRRM	T1,STRK4C##(P2)	;K FOR CRASH.SAV
	PJRST	CHGALL		;SET BIT TO WRITE OUT HOME BLOCKS
;DMKSTR--SUBROUTINE TO SET UP STRS
;ACCORDING TO TABLES IN ONCMOD

;CALLING SEQUENCE:

;JSP	T2,SVOTAC	;SAVE ACS
;PUSHJ	P,DMKSTR
;ONLY RETURN

;ENTRIES IN ONC<NN>S ARE STR NAMES FOR KONTROLLER TYPE <NN>
;ENTRIES IN ONC<NN>Z ARE THE NUMBER OF UNITS TO BE PLACED IN
;CORRESPONDING STRS SPECIFIED IN ONC<NN>S



DMKSTR:	PUSHJ	P,KILSTR	;CLEAR OUT ALL STRS BEFORE YOU BEGIN
	SETZB	J,T4		;CLEAR COUNTERS
DSTR1:	HLRZ	U,SYSUNI##	;ADDR OF 1ST UNIT DATA BLOCK
DSTR2:	SKIPE	T1,KTTAB1(J)	;GET 1ST STR NAME ADDRESS
	SKIPN	T1,@T1		;GET DESIRED STR NAME, IF ANY
	JRST	DSTR6		;NO TABLE, OR ZERO ENTRY IN TABLE
	SKIPN	@KTTAB2(J)	;ANY UNITS SPECIFIED??
	AOJA	T4,DSTR2	;NO-GET NEXT STR IN TABLE.
	PUSH	P,T1		;SAVE STR NAME
	PUSHJ	P,FNSTR		;SET UP PREDECESSOR AND OTHER THINGS
	CAIA			;ALWAYS SKIP
	STOPCD	.,HALT,AHS,	;++ALREADY HAVE STRUCTURE
	SETZ	P1,		;CLEAR P1 FOR INSUNI
	PUSHJ	P,GETSTR	;CREATE SDB AND ZERO IT OUT
	STOPCD	.,HALT,CGS,	;++CAN'T GET STR DATA BLOCK
	POP	P,STRNAM##(P2)	;PUT IN NAME
	HLLOS	STRUNI##(P2)	;SET NEEDS REFRESHING 
	MOVEI	P3,STRUNI##(P2)	;MAKE 1ST UNIT PREDECESSOR
	SETZM	UNITS		;CLEAR UNITS COUNT.
DSTR3:	LDB	T1,UNYKTP##	;GET KONTROLLER TYPE
	MOVSI	T2,UNPWPO##	;OFF LINE AND WRITE PROTECT BITS
	TDNN	T2,UNIDES##(U)	;SKIP IF NOT A GOOD UNIT FOR A STR
	CAME	T1,J		;SKIP OF  CORRECT TYPE
	JRST	DSTR4		;UNIT IS NOT SUITABLE.
	PUSH	P,T4
	PUSHJ	P,INSUNI	;ADD UNIT TO STR
	STOPCD	.,HALT,UIF,	;++UNIT ALREADY IN FILE STR
	POP	P,T4
	AOS	UNITS		;BUMP UNITS IN CURRENT STR COUNT
DSTR4:	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT
	JUMPE	U,DSTR5		;NONE LEFT-GET NEXT KONTROLLER TYPE
	MOVE	T1,UNITS	;GET UNITS IN THIS STR
	CAMGE	T1,@KTTAB2(J)	;ENOUGH?
	JRST	DSTR3		;NO-GET MORE IF POSSIBLE
	PUSHJ	P,COMPDF	;YES-COMPUTE STRHGH AND STRSIZ, SET UP
				;DEFAULTS
	AOJA	T4,DSTR2	;NEXT STR WITHIN KONTROLLER TYPE
DSTR5:	PUSHJ	P,COMPDF	;CLOSE OUT STR
DSTR6:	CAIL	J,KTLEN		;FINISHED WITH KONTROLLER TYPES??
	POPJ	P,		;YES-EXIT.
	SETZ	T4,		;CLEAR UNIT NUMBER.
	AOJA	J,DSTR1		;GO BACK FOR NEXT KONTROLLER TYPE.

COMPDF:	PUSH	P,U		;SAVE U
	PUSHJ	P,HGHSIZ	;COMPUTE STRHGH AND STRSIZ
	HLRZ	P1,STRUNI##(P2)	;SET UP P1 FOR PARSET
	JUMPN	P1,COMPD1	;JUMP IF THERE IS A UNIT IN STR
	MOVE	T1,STRNAM##(P2)	;NO UNITS-GET STR NAME FOR FNSTR
	PUSHJ	P,FNSTR		;FIND STR, GET PREDECESOR, ETC
	PJRST	UPOPJ##		;STR WENT AWAY! PROCEED
	PUSHJ	P,DISSTR	;KILL THE STR WITH NO UNITS IN IT
	PJRST	UPOPJ##		;AND RETURN
COMPD1:	PUSH	P,T4
	PUSHJ	P,PARSET	;SET UP DEFAULTS
	POP	P,T4
	JRST	LPOPJ##		;RESTORE U AND RETURN.

BPCSTO:	MOVE	T1,[DPB	P1,UNYBPC##];GET INSTR. TO BE EXECUTED BY STOUNI
	PUSHJ	P,STOUNI	;STORE VALUE IN EVERY UNIT IN STR
	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	LDB	T1,UNYBPC##	;GET CURRENT # BLOCKS PER CLUSTER FOR THIS UNIT
	PUSHJ	P,TRFCHS
	PUSHJ	P,COMLCA	;COMPUTE LAST CLUSTER ADR. ON UNIT
	JFFO	T2,.+2		;FIND POSITION OF 1ST. 1 BIT
	MOVEI	T3,^D35		;NONE - BUT BYTE FIELD MUST BE AT LEAST 1 BIT WIDE
	MOVN	P1,T3		;NEGATE FOR ADDI INSTR.
	ADDI	P1,^D36		;COMPUTE FIELD WIDTH FOR CLUSTER ADR.
	LDB	T1,[POINT 6,STYCLP##(P2),11]
	PUSHJ	P,TRFCHS
	DPB	P1,[POINT 6,STYCLP##(P2),11]	;PUT IT IN BYTE POINTER
	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	LDB	T3,UNYBPC##	;GET # BLOCKS/CLUSTER
	MOVE	T1,STRHGH##(P2)	;HIGHEST BLOCK IN STR
	ADDI	T1,-1(T3)
	IDIVI	T1,(T3)
	HLRZ	P1,T1		;DIVIDE BY 2**18
	ADDI	P1,1		;AND ROUND UP
	IMUL	P1,T3		;COMPUTE # BLOCKS PER SUPER CLUSTER
	HLRZ	T1,STRBSC##(P2)	;GET CURRENT # BLOCKS PER SUPER CLUSTER
	PUSHJ	P,TRFCHS
	HRLM	P1,STRBSC##(P2)	;STORE IT
	MOVE	T2,STRBPU##(P2)	;GET # BLOCKS PER UNIT
	SUBI	T2,1
	IDIV	T2,P1		;DIVIDE BY # BLOCKS PER SUPER CLUSTER
	ADDI	T2,1
	MOVE	P1,T2		;GET NEW VALUE INTO A KOSHER AC FOR 'TRFCHG'
	HRRZ	T1,STRSCU##(P2)	;GET CURRENT # SUPER CLUSTERS PER UNIT
	PUSHJ	P,TRFCHS
	HRRM	P1,STRSCU##(P2)	;STORE # SUPER CLUSTERS PER UNIT
	POPJ	P,

CNPSTO:	DPB	P1,[POINT 6,STYCNP##(P2),11]
	PUSHJ	P,REFCHS	;UNIT NEEDS "HOME" BLOCKS REWRITING, STR REFRESHING
	ADD	P1,T3
	MOVNS	P1
	ADDI	P1,^D36
	LDB	T1,[POINT 6,STYCKP##(P2),11]
	PUSHJ	P,TRFCHS
	DPB	P1,[POINT 6,STYCKP##(P2),11]
	ADD	P1,T3
	LDB	T1,[POINT 6,STYCNP##(P2),5]
	PUSHJ	P,TRFCHS
	DPB	P1,[POINT 6,STYCNP##(P2),5]
	MOVE	P1,T3
	LDB	T1,[POINT 6,STYCKP##(P2),5]
	PUSHJ	P,TRFCHS
	DPB	P1,[POINT 6,STYCKP##(P2),5]
	POPJ	P,
;SUBROUTINE TO DETERMINE IF ANY UNITS ARE NOT IN STR'S
;SKIP RETURN IF YES, NO SKIP IF NO

ALLINS:	HLRZ	U,SYSUNI##	;U=1ST UNIT IN SYSTEM
ALLIN1:	JUMPE	U,CPOPJ##	;NO MORE UNITS, ALL MUST BE IN STRS
	SKIPN	UNILOG##(U)	;SKIP IF THIS UNIT IS IN AN STR
	JRST	CPOPJ1##
	HLRZ	U,UNISYS##(U)	;NEXT UNIT IN SYSTEM
	JRST	ALLIN1

;SUBROUTINE TO COMPUTE SIXBIT LOGICAL UNIT NUMBER WITHIN STR

CMPLOG:	PUSH	P,P3
	MOVE	P3,T1
	LSH	P3,-^D3
	ADDI	P3,20
	LSH	P3,^D6
	ANDI	T1,7
	ADDI	P3,20(T1)
	MOVE	T1,STRNAM##(P2)
	PUSHJ	P,MSKUNI##
	SETCA	T2,0
	JFFO	T2,.+2
	STOPCD	.+1,DEBUG,JDJ,	;++JFFO DIDN'T JUMP
	MOVEI	T2,^D24
	TRNE	P3,700
	JRST	INSUN2
	TRZ	P3,7700
	MOVEI	T2,^D30
INSUN2:	SUB	T2,T3
	LSH	P3,(T2)
	ADD	T1,P3
	MOVEM	T1,UNILOG##(U)
	POP	P,P3
	POPJ	P,
CHGASL:	MOVEI	T1,[ASCIZ .
DO YOU WANT TO CHANGE THE ACTIVE SWAPPING LIST?
.]
	PUSHJ	P,ASKQUE	;TYPE MSG. & GET USER'S RESPONSE
	  POPJ	P,		;OBVIOUSLY NOT
	MOVEI	U,DIFSWP##	;GET ADR. OF PTR. TO 1ST. UNIT DATA BLOCK IN ASL
	PUSHJ	P,CLRAS1
	JRST	CHGAS3		;JRST AROUND THE ROUTINE

CLRASL:	PUSHJ	P,SETCHG	;FLAG "HOME" BLOCK MUST BE REWRITTEN
	SETOM	UNISUN##(U)	;AS UNIT IS NOW NO LONGER IN ASL
CLRAS1:	HLRZ	T2,UNISWP##(U)	;GET LINK TO NEXT UNIT IN ASL
	HRRZS	UNISWP##(U)	;UNLINK CURRENT UNIT FROM ASL
	MOVE	U,T2
	JUMPN	U,CLRASL	;REPEAT IF THERE IS ONE LEFT
	MOVE	T1,PTRSWP	;GET BLT PTR. TO CLEAR SWPTAB
	SETZM	SWPTAB##	;CLEAR OUT 1ST. WORD
	BLT	T1,SWPTBE##	;CLEAR THE REST OUT
	POPJ	P,

CHGAS3:	MOVEI	T1,[ASCIZ .FOR EACH CLASS TYPE PHYSICAL UNIT NAMES(EXTRA CR WHEN DONE).]
	PUSHJ	P,SVMOUT	;O/P BUFFER & ADD CRLF
	MOVEI	P3,DIFSWP##
	SETZM	P1		;SET CLASS INITIALLY TO ZERO
	MOVSI	P4,MSWPMX##	;SETUP AOBJN PTR. FOR SWAPPING TABLE LENGTH
	SETOM	TYPONL		;SET TYPE ONLY FLAG
CHGAS1:	MOVEI	T1,[ASCIZ .CLASS .]
	PUSHJ	P,ASKDEC
	  TLOA	P3,-1		;INDICATE FIRST TIME
	STOPCD	.-4,DEBUG,AR1,	;++ASKDEC RETURNED CPOPJ1
	PUSHJ	P,ASKCHW
	  JRST	CHGAS2
	CAIG	P1,SWCLSN##
	AOJA	P1,CHGAS1
CHGAS2:	SETZM	TYPONL
	POPJ	P,

PTRSWP:	XWD	SWPTAB##,SWPTAB+1
;ROUTINE TO CLEAR OUT ENTIRE ACTIVE SWAPPING LIST...
;DOES NOT ASSUME ACTIVE SWAPPING LIST IS ALREADY SETUP.

KASL:	MOVEI	U,DIFUSY##
KASL1:	HLRZ	U,UNISYS##(U)
	JUMPE	U,KASL2
	PUSHJ	P,SETCHG	;MARK AS NEEDING HOM BLOCKS REWRITTEN
	SETOM	UNISUN##(U)	;UNIT NO LONGER IN ASL
	HRRZS	UNISWP##(U)	;CLEAR LINK
	JRST	KASL1
KASL2:	MOVE	T1,PTRSWP	;GET BLT POINTER TO CLEAR OUT
	SETZM	SWPTAB##	;SWPTAB
	BLT	T1,SWPTBE##	;CLEAR TO THE LAST DROP
	POPJ	P,		;RETURN
SAMUNI:	MOVEI	T1,[ASCIZ .?UNIT ALREADY IN ACTIVE SWAPPING LIST.]
	PUSHJ	P,SVMOUT

ASKCHW:	PUSHJ	P,GETUNI
	  POPJ	P,
	LDB	T1,UNYK4S##	;GET # K FOR SWAPPING ON THIS UNIT
	JUMPN	T1,ASKCH1	;PRINT MSG. IF NONE
	MOVEI	T1,[ASCIZ .?UNIT HAS NO SPACE ALLOCATED FOR SWAPPING
.]
	PUSHJ	P,SVMOUT	;TYPE MSG. & CRLF
	JRST	ASKCHW		;AND WAIT FOR ANOTHER UNIT NAME TO TYPED

ASKCH1:	HLRZ	T1,SWPUNI##
	JUMPE	T1,ASKCH3
ASKCH2:	CAMN	T1,U
	JRST	SAMUNI
	HLRZ	T1,UNISWP##(T1)
	JUMPN	T1,ASKCH2
ASKCH3:	TLZE	P3,-1
	AOS	(P)
	HRLM	U,UNISWP##(P3)
	HRRZS	UNISWP##(U)
	DPB	P1,UNYCFS##
	HRRZM	P4,UNISUN##(U)
	HRRM	U,SWPTAB##(P4)
	PUSHJ	P,SETCHG	;FLAG "HOME" BLOCKS MUST BE REWRITTEN
	HRRZ	P3,U
	AOBJN	P4,ASKCHW	;REPEAT IF ANY ROOM LEFT IN TABLE
	MOVEI	T1,[ASCIZ .
%ACTIVE SWAPPING LIST FULL.]
	SOS	(P)		;NON-SKIP RETURN IF LIST FULL
	PJRST	SVMOUT
DEFASL:	MOVEI	U,DIFSWP##	;GET ADDR OF PTR TO 1ST UDB IN ASL
	PUSHJ	P,KASL	;CLEAR OUT ASL
	MOVEI	P3,DIFSWP##	;POINTERTO PREDECESSOR
	MOVEI	U,DIFUSY##
	MOVSI	P4,MSWPMX##	;AOBJN POINTER
	SETZ	P1,
DFASL1:	HLRZ	U,UNISYS##(U)	;GET UNIT
	JUMPE	U,CPOPJ##	;FINISHED
	MOVSI	T1,300000	;THIS IS CASE OFF DOWN UNITS
	TDNE	T1,UNIDES##(U)
	JRST	DFASL2		;SKIP THIS UNIT...
	LDB	T1,UNYK4S##	;ANY K FOR SWAPPING??
	JUMPE	T1,DFASL1	;NO SWAPPING SPACE-GET NEXT UNIT
	LDB	T1,UNYKTP##	;GET KONTROLLER TYPE
	CAIE	P3,DIFSWP##	;FIRST TIME, IT SKIPS
	CAMN	T1,T3		;HAS UNIT TYPE CHANGED?
	JRST	.+2		;NO-BOP IN CLASS
	AOS	P1		;TYPE HAS CHANGED-BUMP IT UP
	DPB	P1,UNYCFS##	;PUT IN SWAP CLASS
	MOVE	T3,T1		;SAVE OLD UNIT TYPE FOR THE CHECK.
	HRLM	U,UNISWP##(P3)	;CREATE POINTER FROM PREDECSS. TO THS UNIT
	HRRZS	UNISWP##(U)	;CLEAR POINTER TO NEXT UNIT FOR THIS UNIT
	HRRM	U,SWPTAB##(P4)	;ENTER THIS UNIT IN SWPTAB
	HRRZM	P4,UNISUN##(U)	;ENTER LOGICAL UNIT NUMBER
	PUSHJ	P,SETCHG	;FLAG HOME BLOCKS NEED REWRITING
	MOVE	P3,U		;MAKE THIS UNIT PREDECESSOR
	AOBJN	P4,DFASL1	;LOOP FOR MORE IF ANY ROOM LEFT
	POPJ	P,		;NO ROOM LEFT IN ASL
DFASL2:	SETOM	UNISUN##(U)
	HRRZS	UNISWP##(U)
	JRST	DFASL1		;TAKE IT OUT OF ACTIVE SWAPPING LIST
				;IF ITS WRITE PROTECTED OR DOWN.
;SUBROUTINE TO CHANGE THE "SYS" SEARCH LIST

CHGSRC:	MOVEI	T1,[ASCIZ .
DO YOU WANT TO CHANGE THE "SYS" SEARCH LIST?
.]
	PUSHJ	P,ASKQUE	;TYPE QUSTION & GET USER'S RESPONSE
	  POPJ	P,		;OBVIOUSLY NOT
	HLRZ	P2,SYSSTR##	;TAKE ALL STRS OUT OF "SYS" SEARCH LIST
CHGSR1:	SETOM	STRSRC##(P2)	;INDICATE STR NOT IN "SYS" SEARCH LIST
	PUSHJ	P,CHGALL	;MAKE SURE ALL HOME BLOCKS GET REWRITTEN
	HLRZ	P2,STRSYS##(P2)	;GET ADR. OF NEXT STR DATA BLOCK IN SYSTEM
	JUMPN	P2,CHGSR1	;REPEAT IF ANY LEFT
	MOVEI	T1,[ASCIZ .TYPE STR NAMES FOR "SYS" SEARCH LIST(EXTRA CR WHEN DONE).]
	PUSHJ	P,CONOUT	;TYPE MSG. & ADD CRLF
	MOVE	P4,[-.SLMXS,,0]	;AOBJN PTR. FOR MAX. # STRS IN SEARCH LIST
CHGSR2:	PUSHJ	P,ASKST1	;TYPE MSG. & GET RESPONSE
	  POPJ	P,		;CR TYPED - EXIT
	JUMPN	P2,CHGSR3	;WAS "ALL" TYPED
	MOVEI	T1,[ASCIZ .
?"ALL" NOT ALLOWED.]
	PUSHJ	P,CONOUT	;TYPE MSG. & ADD CRLF
	JRST	CHGSR2		;TRY AGAIN

CHGSR3:	HRRZM	P4,STRSRC##(P2)	;STORE LOG. STR # IN STR DATA BLOCK
	AOBJN	P4,CHGSR2	;GET NEXT STR NAME
	POPJ	P,		;EXIT - MAX. # STRS TYPED
;ROUTINE TO SET UP SYS SEARCH LIST DEFAULT
;PUTS ALL STRS IN SYS SEARCH LIST

DEFSSL:	HLRZ	P2,SYSSTR##	;GET ADDR OF 1ST STR IN SSL
	JUMPE	P2,CPOPJ	;THROUGH IF NONE
DFSSL1:	SETOM	STRSRC##(P2)	;TAKE IT OUT
	PUSHJ	P,CHGALL	;MAKE SURE ALLHOM BLOCKS ARE REWRITTEN
	HLRZ	P2,STRSYS##(P2)	;GET NEXT STR
	JUMPN	P2,DFSSL1	;JUMP IF ANY LEFT
	MOVE	P4,[-.SLMXS,,0]	;AOBJN POINTER
	MOVEI	P2,DIFSTR##
DFSSL2:	HLRZ	P2,STRSYS##(P2)
	JUMPE	P2,CPOPJ##
	SKIPN	STRUNI##(P2)	;IF NO UNITS IN THIS STR
	JRST	DFSSL2		;GO FOR NEXT STR
	HRRZM	P4,STRSRC##(P2)	;PUT STR IN SYS SEARCH LIST
	AOBJN	P4,DFSSL2	;BUMP LOGICAL NUMBER AND CONTINUE
	POPJ	P,		;WE'RE THROUGH
;ENTER WITH P1 = 0

CANTB0:	JUMPN	P1,CPOPJ1##	;SKIP RETURN IF P1 IS NON ZERO
	MOVEI	T1,[ASCIZ .CANNOT BE .]
	PJRST	DECLOP		;TYPE MSG. & VALUE

CHKHBS:	CAMLE	P1,MAX		;IS NEW VALUE GT OR EQ MAX?
	JRST	CANTEX		;YES - TYPE CANNOT EXCEED AND VALUE
	JRST	CPOPJ1##	;IT'S NOT - SKIP RETURN


;ENTER AT CANTX1 WITH T2 = VALUE TO BE TYPED, AT CANTEX WITH MAX = VALUE

CANTEX:	MOVE	P1,MAX		;PUT VALUE INTO KOSHER AC
	MOVEI	T1,[ASCIZ .CANNOT EXCEED .]
	PJRST	DECLOP		;TYPE MSG. & VALUE

;T3 IS RESPECTED

CHGONL:	PUSHJ	P,SAVE2##
	MOVEI	P2,0
	PJRST	REFCHU

; T3 IS RESPECTED

TRFCHU:	HLLOS	WHICH
	CAME	T1,P1		;IS OLD VALUE=NEW VALUE?
REFCHU:	SKIPN	WHICH
	POPJ	P,
	SKIPE	P2		;IS UNIT IN AN STR?
	HRROS	STRREF##(P2)	;YES - INDICATE STR NEEDS REFRESHING
	PJRST	SETCHG		;FLAG "HOME" BLOCKS MUST BE REWRITTEN

TRFCHS:	HLLOS	WHICH
	CAME	T1,P1
REFCHS:	SKIPN	WHICH
	POPJ	P,
	HRROS	STRREF##(P2)	;INDICATE STR NEEDS REFRESHING
CHGSTR:	SKIPN	WHICH
	POPJ	P,
CHGALL:	MOVE	T1,[PUSHJ P,SETCHG]	;GET INSTR. TO BE EXECUTED BY STOUNI
;SUBROUTINE TO EXECUTE AN INSTRUCTION FOR ALL UNITS WITHIN AN STR
; USUALLY STORES A BYTE
;T1=INSTRUCTION TO BE EXECUTED, P1=ARG., P2=STR DATA BLOCK ADR.

STOUNI:	HLRZ	U,STRUNI##(P2)
	PUSH	P,T1
STOUN1:	XCT	(P)		;EXECUTE INSTRUCTION SUPPLIED IN AC T1
	HLRZ	U,UNISTR##(U)
	JUMPN	U,STOUN1
	JRST	TPOPJ##

;SUBROUTINE TO COMPUTE # CLUSTERS & WORDS PER SAT

CMCWPS:	PUSHJ	P,SAVE4##	;SAVE P1-P4
	PUSHJ	P,COMLC1	;NOW COMPUTE # CLUSTERS PER SAT
	SOS	T2
	LDB	P1,UNYSPU##	;GET # SATS PER UNIT IN THIS STR
	IDIV	T2,P1
	HRRM	T2,UNICPS##(U)	;STORE COMPUTED VALUE
	AOS	UNICPS##(U)	;MAKE VALUE IN UNIT DATA BLOCK RIGHT
	IDIVI	T2,^D36
	ADDI	T2,1
	DPB	T2,UNYWPS##	;STORE COMPUTED VALUE
	POPJ	P,		;EXIT

ASKDMM:	CAMGE	P1,MIN		;SEE IF BELOW MINIMUM
	MOVE	P1,MIN		;YES -- SET TO MINIMUM
	CAMLE	P1,MAX		;SEE IF ABOVE MAXIMUM
	MOVE	P1,MAX		;YES -- SET TO MAXIMUM
	SKIPGE	TYPONL		;DONT SKIP IF ONLY TYPING PARAMS
	PJRST	ASKDEC		;IN WHICH CASE FORGET ABOUT MIN AND MAX
	JSP	T2,SVOTAC
	MOVE	T2,MIN
	CAMN	T2,MAX
	JRST	SNDMIN		;IF MIN=MAX DONT ASK
	MOVEM	P1,WHICH	;SAVE ORIGINAL VALUE
	PUSHJ	P,DECLOP	;TYPE MESSAGE AND SEND VALUE
	MOVEI	T1,[ASCIZ .MIN = .]
	MOVE	P1,MIN
	PUSHJ	P,TYPDEC	;TYPE MIN
	PUSHJ	P,SOPOUT
	MOVEI	T1,[ASCIZ . MAX = .]
	MOVE	P1,MAX
	PUSHJ	P,DECLOP	;TYPE MAX, CRLF
	MOVE	P1,WHICH	;RESTORE ORIGINAL VALUE
	PJRST	ASKDC2		;GET RESPONSE
SNDMIN:	MOVE	P1,MIN		;RETURN MIN
	JRST	CPOPJ1##
ASKDEC:	JSP	T2,SVOTAC
	JRST	ASKDC1

ASKDAG:	SKIPA	T1,WHICH
ASKDC1:	MOVEM	T1,WHICH
	PUSHJ	P,DECLOP
	SKIPGE	T1,TYPONL
	POPJ	P,
ASKDC2:	PUSHJ	P,GETLIN##
	  JRST	SIXCH1
	PUSHJ	P,ALTM		;IN CASE OF $ COP OUT
	PUSHJ	P,DECIN##
	  JFCL			;SHOULD NEVER HAPPEN
	  JRST	ASKDAG
	PJRST	SIXCHK

DECLOP:	JSP	T2,SVOTAC
	PUSHJ	P,TYPDEC
	PJRST	CRLFOP


COMLCA:	HLRZ	U,STRUNI##(P2)	;GET ADR. OF 1ST. UNIT DATA BLOCK IN STR
	JRST	COMLC2		;IS UNIT IN AN STR?

COMLC1:	SKIPA	T2,UNIBPU##(U)	;NO - GET # BLOCKS ON UNIT
COMLC2:	MOVE	T2,STRBPU##(P2)	;YES - GET # BLOCKS PER UNIT
	LDB	T4,UNYBPC##	;GET # BLOCKS PER CLUSTER
	IDIV	T2,T4		;COMPUTE LAST CLUSTER ADR. ON UNIT
	POPJ	P,		;RETURN

TYPMSN:	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	PUSHJ	P,TYPDEC	;PUT MSG. IN THE BUFFER FOLLOWED BY DECIMAL #
	PJRST	OPOUT##		;O/P THE BUFFER

TYPDEC:	PUSHJ	P,ICONM##
	MOVE	T1,P1
	PJRST	RADX10##
ASKSIX:	JSP	T2,SVOTAC
	MOVEM	T1,WHICH
	PUSHJ	P,SIXLOP
	SKIPGE	T1,TYPONL
	POPJ	P,
GETSIX:	PUSHJ	P,GETLIN##
	  JRST SIXCH1
	PUSHJ	P,ALTM		;IN CASE OF $ COP OUT
GETSX1:	PUSHJ	P,CTEXT##
SIXCHK:	EXCH	P1,T2
	CAME	P1,T2
	AOSA	(P)
	SETZM	WHICH
	PUSHJ	P,OTSET##	;INITIALIZE BUFFER
	PUSHJ	P,CRLFOP
	SKIPA	T1,WHICH
SIXCH1:	SETZB	T1,WHICH
	POPJ	P,

PSXLOP:	JSP	T2,SVOTAC
	PUSHJ	P,OTSET##	;INITIALIZE CTY BUFFER
	CAIA
SIXLOP:	PUSHJ	P,ICONM##
	MOVE	T2,P1
NAMFLO:	PUSHJ	P,PRNAME##
	PJRST	CRLFOP
RWRSUB:	MOVEI	T1,[ASCIZ .
HOME BLOCKS TO BE WRITTEN ON WHICH PHYSICAL UNITS (EXTRA CR WHEN THROUGH)
(CR IF NONE, ALL IF ALL ;"ALL" IS NORMAL CASE).]
	PUSHJ	P,CONOUT	;TYPE MESSAGE
	MOVSI	P4,UNPCHG##	;BIT SET IF HOME BLOCK MUST BE REWRITTEN
	SETZM	RWRFLG		;CLEAR ANY REWRITTEN FLAGS
RWRSU1:	PUSHJ	P,GETUNI	;GET UNITS TO REWRITE
	  JRST	RWREX		;NO MORE
	AOS	RWRFLG
	JUMPE	U,RWRHUN	;JUMP IF NO UNIT SPECIFIED
	PUSHJ	P,RWRWHM	;REWRITE THE HOME BLOCK
	JRST	RWRSU1		;AND WAIT FOR NEXT
RWRHUN:	HLRZ	U,SYSUNI##	;FIRST UNIT IN SYSTEM
RWRSU2:	PUSHJ	P,RWRWHM	;REWRITE HOME BLOCK
	HLRZ	U,UNISYS##(U)	;NEXT UNIT
	JUMPN	U,RWRSU2	;LOOP FOR ALL IN SYSTEM
RWREX:	SKIPN	RWRFLG		;SKIP IF ANY SPECIFIED
	POPJ	P,		;NO, DON'T TYPE
	MOVEI	T1,[ASCIZ .
HOME BLOCKS WRITTEN.]
	PJRST	SVMOUT		;ADD CRLF, OUTPUT, AND RETURN
RWRWHM:	TDNE	P4,UNIDES##(U)	;SKIP IF DON'T NEED TO
	PUSHJ	P,UPDHOM	;REWRITE UNIT'S HOME BLOCKS
	ANDCAM	P4,UNIDES##(U)	;CLEAR NEEDS REWRITING FLAG
	POPJ	P,		;RETURN
SVOSET::PUSHJ	P,SVTPAC
	PUSHJ	P,OTSET##
	PJRST	SUPDAT

SAVP4:	0
SAVT2:	0
SAVF:	0
SAVU:	0
SAVK:	0

SPSNAM:	SKIPA	T2,STRNAM##(P2)
SPUNAM::MOVE	T2,UNINAM##(U)
SPRNAM:	PUSHJ	P,SUPDAT
	PUSHJ	P,PRNAME##
	PJRST	SUPDAT

SOPOUT::PUSHJ	P,SUPDAT
	PUSHJ	P,OPOUT##
	PJRST	SUPDAT

SRDX10:	PUSHJ	P,SUPDAT
	PUSHJ	P,RADX10##
	PJRST	SUPDAT

SCRLFO:	PUSHJ	P,SUPDAT
	PUSHJ	P,CRLF##
	PUSHJ	P,OPOUT##
	PJRST	SUPDAT

SCONMS::PUSHJ	P,SUPDAT
	PUSHJ	P,CONMES##
SUPDAT:	EXCH	P4,SAVP4
	EXCH	T3,SAVT2
	EXCH	F,SAVF
	EXCH	U,SAVU
	EXCH	J,SAVK
	POPJ	P,

SVTPAC:	MOVEM	P4,SAVP4
	MOVEM	T3,SAVT2
	MOVEM	F,SAVF
	MOVEM	U,SAVU
	MOVEM	J,SAVK
	POPJ	P,

SVMOTS:	SETOM	SERIUS
SVMOTE:	SETOM	ERRHOM
SVMOUT::JSP	T2,SVOTAC
CONOUT:	PUSHJ	P,ICONM##
CRLFOP:	PUSHJ	P,CRLF##
	PJRST	OPOUT##
ASKYCR:	MOVEI	T1,[ASCIZ .
DO YOU WANT TO CHANGE ANY DISK PARAMETERS?(CR IF NO)
.]
ASKQUE:	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	PJRST	YESNO##		;GET USER'S RESPONSE - SKIP RETURN IF 1ST. T4="Y"
				; NON SKIP RETURN IF ANYTHING ELSE TYPED

;SUBROUTINE TO TYPE A MSG. - ACCEPT A RESPONSE WHICH SHOULD BE AN STR NAME
; AND SCAN STR DATA BLOCKS FOR A MATCH WITH THE NAME TYPED

ASKSTR:	JSP	T2,SVOTAC	;SAVE P4,T3,F,U & J
	PUSHJ	P,CONOUT	;O/P MSG. & ADD CRLF
	CAIA
ASKST1:	JSP	T2,SVOTAC	;SAVE P4,T3,F,U & J
	PUSHJ	P,GETLIN##	;GET RESPONSE
	  POPJ	P,		;CR TYPED - NON SKIP RETURN
	PUSHJ	P,ALTM		;IN CASE OF $ COP OUT
	PUSHJ	P,CTEXT##	;GET RESPONSE IN SIXBIT
	SETZM	P2		;ASSUME "ALL" TYPED
	CAMN	T2,[SIXBIT .ALL.]	;WAS IT?
	JRST	CPOPJ1##	;YES - SKIP RETURN
	MOVE	T1,T2		;PUT STR NAME INTO T1 FOR FNSTR
	PUSHJ	P,FNSTR		;GET STR DATA BLOCK ADR. IF IT EXISTS
	  SKIPA	T1,[[ASCIZ .?NOT AN STR - TRY AGAIN.]]
	JRST	CPOPJ1##	;SKIP RETURN WITH ADR. IN P2
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	JRST	ASKST1		;WAIT FOR NEW NAME TO BE TYPED

;T2 & T3 ARE RESPECTED

SETCHG:	MOVSI	T1,UNPCHG##	;PREPARE TO FLAG "HOME" BLOCKS NEED REWITING
	MOVSI	T4,UNPWPO##
	TDNN	T4,UNIDES##(U)	;IS UNIT WRITE PROTECTED OR OFF-LINE?
	IORM	T1,UNIDES##(U)	;SET UNPCHG FLAG
	POPJ	P,		;RETURN

;SUBROUTINE TO SEE IF ANY UNIT IN THE SYSTEM HAS THE 'UNPCHG' BIT ON

CHKCHG:	MOVSI	P4,UNPCHG##	;SEE IF ANY UNITS NEED THEIR "HOME" BLOCKS REWRITTEN
	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
CHKCH1:	TDNE	P4,UNIDES##(U)	;IS THE BIT SET?
	JRST	CPOPJ1##	;YES - SKIP RETURN
	HLRZ	U,UNISYS##(U)	;GET ADR. OF NEXT UNIT DATA BLOCK IN SYSTEM
	JUMPN	U,CHKCH1	;REPEAT IF THERE IS ONE LEFT
	POPJ	P,		;NO "HOME" BLOCKS NEED REWRITING - NON SKIP RETURN
GETUNI::PUSHJ	P,GETLIN##	;GET USER'S RESPONSE
	  POPJ	P,		;JUST CR TYPED - NON SKIP RETURN
	PUSHJ	P,ALTM		;IN CASE OF $ COP OUT
	PUSHJ	P,CTEXT##	;GET SIXBIT UNIT NAME
	SETZM	U		;ASSUME "ALL" WAS TYPED
	HLRZ	T1,T2		;MAKE AC LOOK GOOD FOR COMPARE
	CAIN	T1,(SIXBIT .ALL.);WAS "ALL" TYPED?
	JRST	CPOPJ1##	;YES - SKIP RETURN
	PUSHJ	P,FNDUNI	;SEE IF UNIT EXISTS & RETURN WITH UNIT DATA BLOCK
	  SKIPA	T1,[[ASCIZ .?NOT A PHYSICAL UNIT-TRY AGAIN.]]
	JRST	CPOPJ1##	;UNIT EXISTS - SKIP RETURN
	PUSHJ	P,SVMOUT	;ADD CRLF & O/P MSG.
	JRST	GETUNI		;TRY AGAIN

FNDUNI:	HLRZ	U,SYSUNI##	;GET ADR. OF 1ST. UNIT DATA BLOCK IN SYSTEM
FNDUN1:	CAME	T2,UNIHID##(U)	;ACCEPT MATCH ON UNIT ID
	CAMN	T2,UNINAM##(U)	;MATCH?
	JRST	CPOPJ1##	;YES - SKIP RETURN
	HLRZ	U,UNISYS##(U)	;GET NEXT UNIT DATA BLOCK ADR. IN SYSTEM
	JUMPN	U,FNDUN1	;REPEAT IF THERE IS ONE
	POPJ	P,		;NONE FOUND - NON SKIP RETURN

;SUBROUTINE TO PRESERVE AC'S P4,F,U & J

REFSAV:	HRROS	STRREF##(P2)	;INDICATE STR NEEDS REFRESHING
SVOTAC:	PUSH	P,P4
	PUSH	P,T3
	PUSH	P,F
	PUSH	P,U
	PUSH	P,J
	PUSHJ	P,(T2)
	  CAIA
	AOS	-5(P)
	POP	P,J
	POP	P,U
	POP	P,F
	POP	P,T3
	POP	P,P4
	POPJ	P,
;ROUTINE JUST TO WRITE OUT A HOME BLOCK FOR A UNIT WITHOUT READING IT IN.
;CALLED WITH UNIT DATA BLOCK ADRESS IN U

HOMWRT:	JSP	T2,SVOTAC	;SAVE AC'S
	MOVE	F,DATADR	;FDB ADDRESS
	HRRZ	P1,DEVMBF##(F)	;ADRESS OF MBF
	ADDI	P1,1		;POINT IT PAST FIRST IOWD
	MOVSI	P2,(SIXBIT .HOM.)
	MOVE	P3,[EXP CODHOM##]
	PJRST	HOMWR1

UPDHOM:	JSP	T2,SVOTAC	;SAVE P4,F,U & J
	PUSHJ	P,GTHOM		;GET "HOME" BLOCK INTO CORE
	  JFCL			;IGNORE ERRORS
HOMWR1:	MOVEM	P2,BLKNAM##(P1)	;SAVE SIXBIT "HOME" BLOCK IDENTIFIER
	HRRZ	P2,UNISTR##(U)	;GET STR DATA BLOCK ADR.
	MOVE	T1,UNIHID##(U)	;GET SIXBIT UNIT ID
	MOVEM	T1,HOMHID##(P1)	;SAVE IN "HOME" BLOCK
	SETZM	HOMLEN##+1(P1)
	HRLZI	T1,HOMLEN##+1(P1)
	HRRI	T1,HOMLEN##+2(P1)
	BLT	T1,HOMLEN##+4(P1)
	MOVEI	T1,MFDSIZ##	;MAKE UFD'S FOR [1,1] AND [1,4]
	MOVEM	T1,HOMLEN+3(P1)	; EXTRA LONG TO MINIMISE DSK READ
	MOVEM	T1,HOMLEN+5(P1)
	HLRZ	T1,UNISTR##(U)	;GET NEXT UNIT DATA BLOCK ADR. IN STR
	SKIPE	T1		;SAVE 0 IF LAST UNIT IN STR OR NOT IN AN STR
	MOVE	T1,UNIHID##(T1)	;GET ITS ID
	MOVEM	T1,HOMNXT##(P1)	;SAVE IN "HOME" BLOCK
	SKIPE	T1,P2		;SAVE 0 STR NAME IF UNIT NOT IN AN STR
	MOVE	T1,STRNAM##(P2)	;GET SIXBIT STR NAME
	MOVEM	T1,HOMSNM##(P1)	;SAVE IN "HOME" BLOCK
	JUMPE	P2,UPDHM3	;BYPASS ALL REFERENCES TO VALUES IN STR DATA BLOCK
	HLRZ	T1,STRUNI##(P2)	;GET ADR. OF 1ST UNIT DATA BLOCK IN STR
UPDHM1:	JUMPE	T1,UPDHM2	;IF NONE LEFT SAVE 0 IN HOMPRV
	HLRZ	T2,UNISTR##(T1)	;GET ADR. OF NEXT UNIT DATA BLOCK IN STR
	MOVE	T3,UNIHID##(T1)	;GET CURRENT UNIT'S SIXBIT ID
	MOVE	T1,T2		;CURRENT UNIT_NEXT UNIT
	CAME	T2,U		;IS ADR. OF NEXT UNIT DATA BLOCK SAME AS THIS ONE?
	JRST	UPDHM1		;YES - PUT SIXBIT ID INTO THIS UNIT'S "HOME" BLOCK
UPDHM2:	MOVEM	T3,HOMPRV##(P1)	;SAVE IN "HOME" BLOCK
				; 0 OR SIXBIT UNIT ID OF PREVIOUS UNIT IN STR
	HLRZ	T1,STRBSC##(P2)	;GET # BLOCKS PER SUPER CLUSTER
	MOVEM	T1,HOMBSC##(P1)	;SAVE IN "HOME" BLOCK
	HRRZ	T1,STRSCU##(P2)	;GET # SUPER CLUSTERS PER UNIT
	MOVEM	T1,HOMSCU##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STRSRC##(P2)	;GET LOG. STR # OF STR IN "SYS" SEARCH LIST
	MOVEM	T1,HOMSRC##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STYCNP##(P2)	;GET BYTE PTR. FOR CLUSTER COUNT
	MOVEM	T1,HOMCNP##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STYCKP##(P2)	;GET BYTE PTR. FOR CHECKSUM
	MOVEM	T1,HOMCKP##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STYCLP##(P2)	;GET BYTE PTR. FOR CLUSTER ADR.
	MOVEM	T1,HOMCLP##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STRGAR##(P2)	;GET # BLOCKS GUARANTEED TO USER BY RESERVATION
	MOVEM	T1,HOMGAR##(P1)	;SAVE IN "HOME" BLOCK
	HLLZ	T1,STRREF##(P2)	;GET 'REFRESH' FLAG
	HLLM	T1,HOMREF##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,STROVR##(P2)	;GET -VE # BLOCKS USER IS ALLOWED TO OVERDRAW
	MOVEM	T1,HOMOVR##(P1)	;SAVE IN "HOME" BLOCK
	HRRZ	T1,STRK4C##(P2)	;GET # K FOR CRASH.SAV
	MOVEM	T1,HOMK4C##(P1)	;SAVE IN "HOME" BLOCK
	LSH	T1,BLKSPK##	;CONVERT TO # BLOCKS
	MOVEM	T1,HOMLEN##(P1)	;SAVE IN "HOME" BLOCK
IFN FTPSTR,<
	LDB	T1,STYPVS##	;GET PRIVATE STR BIT
	DPB	T1,HOYPVS##	;SAVE IN "HOME" BLOCK
>
UPDHM3:	MOVE	T1,UNILOG##(U)	;GET SIXBIT LOGICAL UNIT WITHIN STR
	MOVEM	T1,HOMLOG##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYLUN##	;GET LOGICAL UNIT # WITHIN STR
	MOVEM	T1,HOMLUN##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,UNIHOM##(U)	;GET LOG. BLOCK #'S OF BOTH "HOME" BLOCKS
	MOVEM	T1,HOMHOM##(P1)	;SAVE IN "HOME" BLOCK
	HLL	T1,UNIGRP##(U)	;GET # CONSECUTIVE CLUSTERS TRIED FOR ON O/P
	HLRZM	T1,HOMGRP##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYK4S##	;GET # K FOR SWAPPING ON THIS UNIT
	MOVEM	T1,HOMK4S##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYBPC##	;GET # BLOCKS PER CLUSTER
	MOVEM	T1,HOMBPC##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYSIC##	;GET # SAT BLOCKS IN CORE FOR THIS UNIT
	MOVEM	T1,HOMSIC##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,UNISUN##(U)	;GET LOG. UNIT # IN ASL
	MOVEM	T1,HOMSUN##(P1)	;SAVE IN "HOME" BLOCK
	SKIPE	T1,SWPTAB##+1(T1)	;GET UNIT DATA BLOCK ADR. OF NEXT UNIT IN ASL
	MOVE	T1,UNIHID##(T1)	;GET ITS SIXBIT ID
	MOVEM	T1,HOMSID##(P1)	;SAVE IN "HOME" BLOCK
	MOVE	T1,UNISLB##(U)	;GET 1ST. LOG. BLOCK # FOR SWAPPING
	MOVEM	T1,HOMSLB##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYCFS##	;GET CLASS FOR SWAPPING
	MOVEM	T1,HOMCFS##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYSPU##	;GET # SAT BLOCKS PER UNIT
	MOVEM	T1,HOMSPU##(P1)	;SAVE IN "HOME" BLOCK
	LDB	T1,UNYUTP##	;GET UNIT TYPE
	MOVEM	T1,HOMUTP##(P1)	;SAVE IN 'HOME' BLOCK
;HERE TO CLEAR UNUSED PORTIONS OF HOME BLOCK

	MOVEI	T1,HOMEND##+1(P1)	;FIRST WORD TO CLEAR
	CAILE	T1,HOMCOD##-1(P1)	;SKIP IF AT LEAST ONE WORD
	JRST	UPDHM4
	SETZM	(T1)		;CLEAR THE FIRST WORD
	CAIN	T1,HOMCOD##-1(P1)	;SKIP IF MORE
	JRST	UPDHM4
	HRLZI	T1,HOMEND##+1(P1)
	HRRI	T1,HOMEND##+2(P1)
	PUSH	P,HOMK4C##(P1)	;SAVE HOMK4C (IN MIDDLE)
	BLT	T1,HOMCOD##-1(P1)	;CLEAR UNUSED WORDS
	POP	P,HOMK4C##(P1)	;RESTORE HOMK4C
UPDHM4:	PUSHJ	P,WRTVID	;STORE VOLID STUFF IN HOME BLOCK
	MOVEM	P3,BLKCOD##(P1)	;SAVE CODE WORD IN "HOME" BLOCK
	MOVE	P4,UNIHOM##(U)	;GET LOG BLOCK #'S OF 1ST. & 2ND. "HOME" BLOCKS
	PUSHJ	P,WRTRUN	;WRITE OUT BOTH "HOME" BLOCKS
	  JFCL			;IGNORE ERRORS
	MOVSI	T1,UNPCHG##	;CLEAR CHANGED FLAG
	ANDCAM	T1,UNIDES##(U)	; IN UDB
	POPJ	P,		;RETURN
;SUBROUTINE TO SETUP VOLUME ID FIELDS IN HOME BLOCK
;CALL WITH:
;	P1 = ADDRESS OF HOME BLOCK
;	PUSHJ	P,WRTVID
;	RETURN HERE
;
WRTVID:	MOVEI	T1,HOMVID##	;GET OFFSET TO VOLUME ID
	LSH	T1,2		;MAKE BYTE ADDRESS
	MOVE	T2,HOMHID##(P1)	;GET PACK NAME
	PUSHJ	P,VOLIDN	;STORE IN BLOCK
	ADDI	T1,6		;SKIP AHEAD
	MOVEI	T2,0		;BLANKS
	PUSHJ	P,VOLIDN	;STORE IN BLOCK
	MOVEI	T1,HOMVSY##	;GET SYSTEM TYPE
	LSH	T1,2		;CONVERT TO BYTES
	MOVE	T2,[SIXBIT "TOPS-1"]
	PUSHJ	P,VOLIDN	;STORE IN BLOCK
	ADDI	T1,6		;BUMP 1 1/2 WORDS
	MOVSI	T2,'0  '	;ADD IN ZERO
	PUSHJ	P,VOLIDN	;STORE NAME
	MOVEI	T1,HOMOWN##
	LSH	T1,2
	MOVE	T2,[SIXBIT "SYSTEM"]
	PUSHJ	P,VOLIDN
	ADDI	T1,6
	MOVEI	T2,0
	PJRST	VOLIDN
;SUBROUTINE TO STORE 1 SIXBIT WORD IN VOLUME ID
;CALL WITH:
;	T1 = BYTE # WITHIN HOME BLOCK (PDP-11 WISE)
;	T2 = WORD
;	P1 = ADDRESS OF HOME BLOCK
;	PUSHJ	P,VOLIDN
;	RETURN HERE
;
VOLIDN:	PUSHJ	P,SAVE1##	;SAVE P1
	PUSH	P,T1
	MOVEI	P1,-1(T1)	;SETUP ADDRESS
	MOVEI	T4,6		;BYTE COUNT
VOLDN1:	MOVEI	T3,0		;CLEAR WORD
	ROTC	T2,6		;COPY BYTE
	ADDI	T3,"0"-'0'	;CONVERT TO ASCII
	AOS	T1,P1		;T1 IS BYTE ADDRESS
	PUSHJ	P,VOLIDP	;GET POINTER
	ADD	T1,-2(P)	;ADD ADDRESS OF BUFFER
	DPB	T3,T1		;STORE IN BUFFER
	SOJG	T4,VOLDN1	;LOOP OVER WHOLE WORD
	JRST	TPOPJ##		;RETURN
;SUBROUTINE TO COMPUTE BYTE POINTER TO BYTE IN VOLID PART
;CALL WITH:
;	T1 = BYTE NUMBER WITHIN HOME BLOCK
;	PUSHJ	P,VOLIDP
;	RETURN HERE WITH POINTER IN T1
;
VOLIDP:	PUSH	P,T2
	IDIVI	T1,4		;T1=WORD #, T2=BYTE #
	ADD	T1,VOLPTT(T2)	;GET CORRECT POINTER
	JRST	T2POPJ##	;RETURN

VOLPTT:	POINT	7,0,17		;BYTE 0
	POINT	7,0,9		;BYTE 1
	POINT	7,0,35		;BYTE 2
	POINT	7,0,27		;BYTE 3
;SUBROUTINE TO WRITE REDUNDANT BLOCKS(HOM,BAT & RIB)
; ENTER WITH F = FILE DATA BLOCK ADR. U = UNIT DATA BLOCK ADR.
; P1 = ADR. OF BLOCK IN CORE. P4 = XWD 1ST. LOG. BLOCK #,2ND. LOG. BLOCK #
; RETURN WITH S = 0 IF NO ERRORS. OTHERWISE IT HAS STANDARD RH ERROR BITS SET
; T2=0 IF NO ERRORS, OTHERWISE RH=-1 IF ERROR ON 2ND. BLOCK & LH=-1 IF ON 1ST.

WRTRUN::SETZM	REDERR		;CLEAR OUT ERROR SWITCH
	SETOM	WHICH		;INDICATE WRITING 1ST. BLOCK
WRTRN1:	HLRZM	P4,BLKSLF##(P1)	;SAVE THIS BLOCK # IN BLOCK
	HLRZ	T2,P4		;GET LOG. BLOCK # TO WRITE
	HRLZS	P4		;SETUP P3 FOR BLOCK #2
	PUSHJ	P,OMNWRT	;GO WRITE OUT BLOCK
	  PUSHJ	P,WRTCHK	;ERROR - GO PRINT MSG.
	SETZM	WHICH		;INDICATE WRITING 2ND. BLOCK
	JUMPN	P4,WRTRN1	;HAVE WE WRITTEN BOTH BLOCKS?
	MOVE	T2,REDERR	;PICK UP ERROR WORD FOR CHECKING BY CALLER
	JUMPE	S,CPOPJ1##	;SKIP RETURN IF NO ERRORS
	POPJ	P,		;EXIT

WRTCHK:
IFE FTKL10,<
	SKIPN	.UONCE##	;DON'T DO DATAO IN USER MODE
	DATAO	PI,UNIERR##(U)	;FLASH OP. WITH ERROR STATUS
>;END IFE FTKL10
	MOVEI	T1,[ASCIZ .%HARDWARE WRITE ERROR.]
	MOVE	T3,UNINAM##(U)	;PICK UP UNIT NAME
	PJRST	RDNMSG		; & PRINT ERROR MSG. FOR BLOCK TYPE
;SUBROUTINE TO READ OR WRITE A BLOCK FOR THE ONCE ONLY & REFRESHER
; ENTER WITH T2 = LOG. BLOCK # TO READ OR WRITE. U = UNIT DATA BLOCK ADR.
; F = FILE DATA BLOCK ADR.
; RETURN WITH S = 0 IF NO ERRORS. OTHERWISE IT HAS STANDARD RH ERROR BITS SET

OMNWRT::MOVEI	T3,MONWRT##	;GET ADR. OF WRITE RTNE. IN FILSER
	JRST	OMONIO		;GO WRITE BLOCK

OMNRED::MOVEI	T3,MONRED##	;GET ADR. OF READ RTNE. IN FILSER
OMONIO:	MOVEI	S,0		;CLEAR S FOR ERROR STATUS CHECKING
	HRRM	U,DEVUNI##(F)	;SETUP DEVUNI FOR MONRED/WRT SINCE IT DOESN'T USE U
	MOVE	T1,[JRST ONCWAT##]	;SETUP A FAKE PWAIT1
	MOVEM	T1,PWAIT1##
	MOVSI	T1,DVDSK
	IORM	T1,DEVMOD(F)
	MOVE	T1,DEVMBF##(F)	;GET IOWD FOR MONRED/WRT
	PUSHJ	P,(T3)		;GO READ OR WRITE BLOCK
	TRNN	S,IOIMPM!IODERR!IODTER!IOBKTL	;CHECK FOR ERRORS
	AOS	(P)		;NO ERRORS - SKIP RETURN
RSPWTC::HRRZ	T1,SYSINA##	;ACTUAL POSITION OF SYSINI
	SUBI	T1,SYSINI##	;MINUS PLACE IT WAS LOADED
	PJRST	RSPWT1##(T1)	;CALL RSPWT1 IN NEW POSITION OF SYSINI

;DEFAULTS FOR STR DATA BLOCKS, DETERMINED BY CONTROLLER TYPE OF SMALLEST
;UNIT IN STR.  EACH DEFAULT TYPE IS INDEXED BY CONTROLLER TYPE, TAKEN BY
;BYTE POINTER UNYKTP - 0=DR, 1=FH, 2=DP, 3=MF, 4=FS, 5=RP

;BLOCKS TO TRY FOR ON SEQUENTIAL ALLOCATION

GRPDEF:	0		;DR
	^D10		;FH
	^D30		;DP
	^D30		;MF
	^D10		;FS
	^D30		;RP

;BLOCKS PER CLUSTER

BPCDEF:	0		;DR
	1		;FH
	5		;DP
	^D10		;MF
	1		;FS
	^D10		;RP

;BLOCKS GUARANTEED TO ALL USERS

GARDEF:	0		;DR
	0		;FH
	0		;DP
	0		;MF
	0		;FS
	0		;RP

;OVERDRAW

OVRDEF:	0		;DR
	^D200		;FH
	^D500		;DP
	^D500		;MF
	^D100		;FS
	^D500		;RP

;K FOR CRASH.SAV

K4CDEF:	0		;DR
	0		;FH
	M.NKC##		;DP
	^D256		;MF
	0		;FS
	M.NKC##		;RP

;BITS FOR CLUSTER COUNT FIELD

CNPDEF:	0		;DR
	^D9		;FH
	^D9		;DP
	^D9		;MF
	^D9		;FS
	^D9		;RP

;INDIRECT TABLES FOR RETRIEVING DEFAULT PARAMETERS USED
;BY THE ONCE ONLY DESTROY OPTION.
;ALL TABLES ARE IN COMMOD, AND THEIR CONTENTS DEPEND
;ON HOW THE MONGEN QUESTIONS FOR ONCE CONFIGURATION
;ARE ANSWERED.

;KTTABN TABLES ARE POINTERS TO ACTUAL CONFIGURATION TABLES.
;ONC<NN>S TABLE CONTAINS NAMES OF DESIRED STRS TO BE CREATED
;WITH UNITS OF KONTROLLER TYPE <NN> IN THEM.

;ONC<NN>Z TABLES CONTAIN NUMBER OF UNITS OF KONTROLLER TYPE <NN>
;TO BE PLACED IN MATCHING STR.

KTTAB1:	0		;FUTURE DRUM
	ONCFHS##(T4)	;FH
	ONCDPS##(T4)	;DP
	0		;OLD MD
	ONCFSS##(T4)	;RS04 ON RH10
	ONCRPS##(T4)	;FUTURE DISK
	KTLEN==.-KTTAB1		;LENGTH OF TABLES KTTABN
KTTAB2:	0		;FUTURE DRUM
	ONCFHZ##(T4)	;FH
	ONCDPZ##(T4)	;DP
	0		;OLD MD
	ONCFSZ##(T4)	;RS04 ON RH10
	ONCRPZ##(T4)	;FUTURE DISK

;K4S TABLES ARE FOR FETCHING THE DEFAULT 
;K FOR SWAPPING PARAMETERS IN COMMOD.

K4STAB:	0		;K4 SWAPPING FOR FUTURE DRUM
	@KSFHTB(T3)	;FOR FH UNITS
	@KSDPTB(T3)	;FOR DP UNITS
	0		;OLD MD
	@KSFSTB(T3)	;FOR RS04S ON DH10S
	@KSRPTB(T3)	;FOR FUTURE DISKS.

;MACRO TO GENERATE NEXT LEVEL OF TABLES.
;SINCE ONCMOD IS NOT ASSEMBLED WITH HDWCNF AND
;WE DON'T WANT TO USE UP SPACE IN COMMOD, WE MUST
;PROVIDE AN ENTRY FOR EVERY POSSIBLE KONTROLLER THE SYSTEM
;CAN HAVE IN THESE TABLES.
;SINCE ONCMOD SPACE IS RECLAIMED AFTER THE SYSTEM IS STARTED UP,
;THIS IS NOT TOO BAD.

	DEFINE KSMAC(Y,Z),<
	IRP Y,<
	IRP Z,<
	IFIDN <Z> <A>,<

KS'Y'TB:	K4S'Y'Z##(T2)
>
	IFDIF <Z> <A>,<
	K4S'Y'Z##(T2)
>>>>
	;GENERATE THE TABLES

	KSMAC(<FH,DP,FS,RP>,<A,B,C,D,E,F,G,H,I>)


UNITS:	BLOCK	1	;COUNTER LOCATION
MIN:	BLOCK	1
MAX:	BLOCK	1

TMPMIN:	BLOCK	1		;TEMPORARY STORAGE OF MIN
DATADR:	BLOCK	1
RWRFLG:	BLOCK	1
HOMFLG:	0
DOFLOK:	BLOCK	1		;DISK OFF-LINE OK
OPTQIK::BLOCK	1		;QUICK OPTION
XLIST
LIT
VAR
LIST

ONCMND:	END