/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/ EDIT # 25
/
/ COPYRIGHT 1971, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ MAGTAPE I/O HANDLER TASK	5 JUN 74	R.MCLEAN
/						M. HEBENSTREIT
/
/
/
/ THE REQUESTOR'S EVENT VARIABLE IS SET AS FOLLOWS:
/	+1 -- FUNCTION PERFORMED
/	-6 -- UNIMPLIMENTED FUNCTION
/	-7 -- ILLEGAL DATA MODE
/	-12 -- UNRECOVERABLE MAGTAPE ERROR
/	-16 -- ILLEGAL BUFFER SIZE
/	-17 -- READ - COMPARE ERROR
/	-20 -- BEGINNING OF TAPE ON BACKSPACE
/	-21 -- END OF TAPE
/	-23 -- ILLEGAL WORD PAIR COUNT
/	-24 -- LUN ASSIGNMENT CHANGED [ATTACH,DETACH]
/	-30 -- PARAMETER PROTECT VIOLATION
/	-777 -- EMPTY POOL
/	-N -- TAPE ERROR STATUS (USER RECOVERY)
/
/ THE CPB FORMATS ARE AS FOLLOWS:
/
/	CPB	FUNCTION CODE
/		EVENT VARIABLE ADDRESS
/		LOGICAL UNIT NUMBER
/		FDW-1
/		FDW-2
/		FDW-3
/
/	FDW = ADDITIONAL FUNCTIONAL DEPENDENT WORD REQUIRED BY ATTACH,
/		DETACH,INPUT,OUTPUT,READ-COMPARE,BACKSPACE,SPACE
/
/	ATTACH -- CODE 2400
/
/	DETACH -- CODE 2500
/
/	INPUT -- CODE 2600
/		FDW1 - MODE INDICATOR
/		FDW2 - CORE BUFFER ADDRESS
/		FDW3 - BUFFER SIZE (MAX WORDS TO BE TRANSFERRED)
/
/	OUTPUT -- CODE 2700
/		FDW1 - MODE INDICATOR
/		FDW2 - CORE BUFFER ADDRESS
/
/	GET -- CODE 3000
/		FDW 1 - CONTROL TABLE ADDRESS
/		CONTROL TABLE
/		CORE BUFFER ADDRESS
/		WORD COUNT
/		STATUS
/
/
/	PUT -- CODE 3100
/		FDW 1 -- CONTROL TABLE ADDRESS
/		CORE BUFFER ADDRESS
/		WORD COUNT
/		STATUS
/
/	HINF -- CODE 3600
/
/	READ-COMPARE -- CODE 4000
/		FDW 1 -- CONTROL TABLE ADDRESS
/		CORE BUFFER ADDRESS
/		WORD COUNT
/		STATUS
/
/	REWIND -- CODE 4100
/
/	BACKSPACE -- CODE 4200
/		FDW1 - NUMBER OF RECORDS
/
/	BACKSPACE FILE -- CODE 4300
/		FDW1 - NUMBER OF FILES
/
/	WRITE EOF -- CODE 4400
/
/	SPACE RECORD -- CODE 4500
/		FDW1 - NUMBER OF RECORDS
/
/	SPACE FILE -- CODE 4600
/		FDW1 - NUMBER OF FILES
/
/	SPACE EOT -- CODE 4700
/
/	FORMAT  -- CODE 5000
/
/	FDW1 =
/	FORMAT  7 TRACK 200 BPI -- CODE 1
/
/	FORMAT  7 TRACK 556 BPI -- CODE 2
/
/	FORMAT  7 TRACK 800 BPI -- CODE 3
/
/	FORMAT  7 TRACK EVEN PARITY -- CODE 4
/
/	FORMAT  7 TRACK ODD PARITY -- CODE 5
/
/	FORMAT  9 TRACK EVEN PARITY -- CODE 6
/
/	FORMAT  9 TRACK ODD PARITY -- CODE 7
/
/	FORMAT  9 TRACK EVEN PARITY DUMP MODE -- CODE 10
/
/	FORMAT	9 TRACK ODD PARITY DUMP MODE -- CODE 11
/
/	FORMAT  9 TRACK DEFAULT PARITY -- CODE 12
/
/	FORMAT  RETURN TO DEFAULT (7 TRACK 800 BPI)  -- CODE 13
/
/	FORMAT  HANDLER ERROR RECOVERY (DEFAULT) -- CODE 14
/
/	FORMAT USER ERROR RECOVERY -- CODE 15
/
/	UNMOUNT -- CODE 5100
/		FDW 1 =
/		MOUNT LABELED TAPE -- CODE 1
/
/		MOUNT UNLABELED TAPE -- CODE 2
/
/		UNMOUNT TAPE -- CODE 3
/
/	READ-WRITE TAPE MARK -- CODE 5200
/		FDW1= 0-READ 1-WRITE
/		FDW2=	BUFFER ADDRESS
/		FDW3=	WORD COUNT
/
	.TITLE	PARAMETER DEFINITIONS
/
/	PARAMETER DEFINITIONS
/
R1=101
R2=102
R5=105
POOL=240	/POOL DEQUE LIST HEAD
PICK=120	/PICK A NODE
PDVL=252	/PHYSICAL DEVICE DEQUE LIST HEAD
NADD=107	/NODE ADD
SNAM=123	/SEARCH FOR A NAME
DQRQ=337	/DE-QUEUE A NODE FROM PDVL NODE
ALAD=325	/ATTACH LUN AND DEVICE
DLAD=332	/DETACH LUN AND DEVICE
IOCD=345	/DECREMENT I/O PENDING COUNT
DTMQ=361	/DEQUE ABORTED NODES
X10=10
X11=11
X12=12
TPS=140
/
.INH=705522
.ENB=705521
ECLA=641000
/
MTSF=707341	/SKIP ON ERROR FLAG OR MAGTAPE FLAG
MTCR=707321	/SKIP ON TAPE CONTROL READY
MTTR=707301	/SKIP ON TAPE TRANSPORT READY
MTAF=707322	/CLEAR THE STATUS AND COMMAND REGISTERS, EF AND MTF
		/IF TAPE CONTROL READ. IF NOT READY CLEAR EF AND MTF ONLY.
MTVM=707302	/OR COMMAND REGISTER INTO AC 0-11
MTCM=707324	/OR AC 0-5,9-11 INTO COMMAND REGISTER LOAD 6-8
		/INTO COMMAND REGISTER
MTLC=707326	/LOAD AC 0-11 INTO COMMAND REGISTER
MTVS=707342	/INCLUSIVELY OR STATUS REGISTER INTO AC 0-11
MTRS=707352	/READ THE CONTENTS OF STATUS REGISTER INTO AC 0-11
MTRC=707312	/READ THE CONTENTS OF COMMAND REGISTER INTO AC 0-11
MTGO=707304	/EXECUTE THE COMMAND REGISTER
/
EF=400000	/ERROR FLAG
RW=200000	/TAPE REWINDING
BT=100000	/BEGINNING OF TAPE
IC=040000	/ILLEGAL COMMAND
PE=020000	/PARITY ERROR
FI=010000	/EOF
ET=004000	/EOT
RE=002000	/READ-COMPARE ERROR
IL=001000	/RECORD LENGTH INCORRECT
DL=000400	/DATA REQUEST LATE
TB=000200	/BAD TAPE
EP=000000+1	/EVEN PARITY
OP=040000+1	/ODD PARITY
CD=020000+1	/CORE DUMP MODE
IG=010000	/INTER - RECORD GAP
NP=000000	/MT NOP
RI=001000	/REWIND
RD=002000	/READ
RC=003000	/READ - COMPARE
WR=004000	/WRITE
WF=005000	/WRITE END OF FILE
SF=006000	/SPACE FORWARD
SR=007000	/SPACE REVERSE
IE=000400	/INTERRUPT ENABLE
ID=000000	/INTERRUPT DISABLE
D2=000000+1	/DENSITY 200 BPI
D5=000100+1	/DENSITY 556 BPI
D8=000200+1	/DENSITY 800 BPI
D9=000300+1	/DENSITY 800 BPI 9 TRACK
/
	.GLOBL	FINREQ,FLSREQ,MTRWB,MTMOV,FMTDEN,FMTPAR,MTREA9
	.GLOBL	MTWCA,MTCAA,MTEVAM,WFMT,MTNODE,UNTTMP,MTLABL,MTREA7
	.GLOBL	MTEOTT,ERM12,USREC,MTCMND,MTPGET,MTWRA7,MTWRA9
/
WCA	32		/WORD COUNT REGISTER ADDRESS
CAA	33		/CURRENT ADDRESS REGISTER ADDRESS
/
	.TITLE	MTRQ INITILIZATION CODEAND TEMPORARY STORAGE
/
/ MTRQ -- ONCE ONLY CODE TO INITALIZE THE MAGTAPE
/	HANDLER, SET UP XADJ AND THE HANDLER IS CONNECTED TO
/	THE API TRAP ADDRESS.
/	THIS CODE IS ALSO OVERLAYED BY TEMPORARY STORAGE
/
/
MTRQ	LAC	(MTUEVA) /PICK UP THE MAGTAPE TRIGGER ADDRESS
	AND	(070000) /MASK OFF THE PAGE BITS
	DAC	MXADJ	/COMPLEMENT OF XR ADJUSTMENT
	TCA		/DETERMINE XR ADJUST
	DAC	XADJ	/SAVE FOR FUTURE XR ADJUSTMENTS
	LAC*	(TPS	/GET THE CLOCK TICKS PER SECOND
	CLQ
	CLL
	LRS	5	/DIVIDE BY 32(10)
	PAX		/SAVE RESULT IN XR
	LACQ
	SZA		/NON-ZERO REMAINDER?
	AXR	+1	/YES -- ADD 1 TO XR
	PXA		/NO -- RESTORE RESULT
	DAC	MARKTG+2	/FIX MARK TIME CPB'S
	DAC	MARTTR+2
	DAC	MARKNR+2
	CAL	CONMT	/CONNECT MAGTAPE TO API TRAP ADDRESS
	LAC	MTCON	/WAS THE CONNECT REQUEST OK?
	SPA		/YES -- GO SEARCH FOR PDBL NODES
	CAL	(10)	/NO -- EXIT ERROR CAN'T CONNECT
	LAC	(UNITAB-1) /SET UP AN ACTIVE PDVL TABLE
	DAC*	(X11)	/MAGTAPE NODES FOR UNITS MTA0-MTA7
	LAW	-10	/SET UP TO LOOK FOR A MAXIMUM OF
	DAC	UNITCN	/10 UNITS
MTPDVL	LAC*	(PDVL)	/PICK UP THE ADDRESS OF THE FIRST PDVL NODE
MTNPV	TAD	XADJ	/ADD XADJ TO PICK UP QUEUE ADDRESS
	PAX
	LAC	2,X	/LOOK AT THE NAME OF THE DIVICE
	SAD	MTASBT	/IS IT MT?
	JMP	FNDPDV	/YES -- GO ENTER IT IN THE TABLE
NDFND	LAC	0,X	/NO -- THIS IS NOT THE CORRECT ENTRY GET ANOTHER
	SAD	(PDVL)	/IS THIS THE END OF THE LIST?
	JMP	CONFIN	/YES -- INITALIZATION FINISHED
	JMP	MTNPV	/NO -- PICK UP ANOTHER ENTRY
/
FNDPDV	PXA		/SAVE NODE ADDRESS AND UNIT IN TABLE
	TAD	MXADJ
	LMQ		/PUT NODE ADDRESS IN MQ
	LAC	5,X	/PICK UP UNIT NUMBER
	ALS	17	/MOVE IT TO BITS 0-2
	AND	(700000) /MASK OFF UNIT NUMBER
	OMQ		/OR UNIT AND NODE ADDRESS
	DAC*	X11	/STORE THEM IN THE TABLE
	LAC	(MTEVAR)	/SET THE TRIGGER EVENT VARIABLE
	DAC	10,X	/IN THE PDVL NODE
	ISZ	UNITCN	/CHECK TO SEE IF 10 UNITS HAVE BEEN FOUND
	JMP	NDFND	/NOT YES -- CONTINUE SEARCH
	JMP	MTWCLR	/YES -- WAIT FOR EVENT VARIABLE
/
CONMT	11		/CONNECT MAGTAPE CPB
	MTCON		/CONNECT EVENT VARIABLE
	5		/LINE NO 5
	MTINT		/INTERRUPT ADDRESS
/
MTCON	0
/
CONFIN	LAC	UNITCN	/HAVE ANY MT NODES BEEN FOUND?
	SAD	(-10)	
	JMP	MTEXIT	/NO -- EXIT AFTER DISCONNECT
	JMP	MTWCLR	/YES-- WAIT FOR TRIGGER
/
MTASBT	.SIXBT	'MT@'
/
STORSZ	-52	/SIZE OF STORAGE TO BE CLEARED
/
/	MTWCLR -- CLEARS THE INITILIZATION CODE TO ZERO
/		SO IT CAN BE USED FOR TEMPORARY STORAGE.
/
MTWCLR	LAC	(MTRQ-1) /PICK UP THE START OF THE STORAGE
	DAC*	(X10)	/SET IT IN AN XR
	DZM*	X10	/CLEAR STORAGE
	ISZ	STORSZ	/IS IT ALL CLEAR?
	JMP	.-2	/NO TRY AGAIN
	JMP	MTWFT	/YES -- GO WAIT FOR EVENT VARIABLE'S
/
/
/TEMPORARY STORAGE EQUIVALANCES
/		ONLY THE 10 WORD TABLES MUST BE IN ZEROED CORE
TIMOUT=MTRQ	/TIME OUT FLAG FOR HUNG MAGTAPE CONTROL
UNTCNT=MTRQ+1	/COUNT FOR ABORT I/O REQEST
MTEVA=MTRQ+2	/MT EVENT VARIABLE
UNITCN=MTRQ+3	/UNIT NUMBER
NTRDYC=MTRQ+4	/NOTREADY SAVE AC
MTCMND=MTRQ+5	/MAGTAPE COMMAND SAVE AREA
ERRCNT=MTRQ+6	/ERROR RETRY COUNT
MTERCM=MTRQ+7	/ERROR RETRY SPACE DIRECTION
FMTPAR=MTRQ+10	/FORMAT PARITY -- 10 WORDS-- ZERO = DEFAULTNON ZERO +1 USER SPECIFIED PARI
FMTDEN=MTRQ+20	/FORMAT DENSITY -- 10 WORDS -- ZERO = DEFAULT
NTRTBL=MTRQ+30	/NOT READY TABLE -- 10 WORDS
		/0 = UNIT READY
		/1-30 = UNIT NOT READY MESSAGE NOT PRINTED YET
		/31 = UNIT NOT READY NOT READY MESSAGE PRINTED
NODSAV=MTRQ+40	/NODE SAVED DURING NOT READY SEQUENCE -- 10 WORDS  --ZERO = NREADY
MTUEVA=MTRQ+50	/USER'S EVENT VARIABLE ADDRESS
MTWCA=MTRQ+51	/WORD COUNT SAVED FOR RETRIES AND INCORRECT RECORD LENGTH ERROR
MTCAA=MTRQ+52	/CURRENT ADDRESS USED FOR RETRIES
XRSV=MTRQ+53	/SAVE XR DURING DECODE
UNTTMP=MTRQ+54	/UNIT NUMBER OF CURRENT REQUEST
NODFND=MTRQ+55	/NODE FOUND DURING THIS SCAN FLAG
MTNODE=MTRQ+56	/MAGTAPE NODE POINTER
UNTNTR=MTRQ+57	/UNIT NOT READY THIS SEARCH
MTSVAC=MTRQ+60	/INTERRUPT SAVED AC
UNTCNT=MTRQ+61	/COUNT FOR ABORT I/O REQUEST
MTEVAM=MTRQ+62	/MAGTAPE INTERRUPT EVENT VARIABLE
MTEVAT=MTRQ+63	/MAGETAPE MARK TIME EVENT VARIABLE
MTEVAR=MTRQ+64	/TRIGGER EVENT VARIABLE
/
/ ^^^^^^^^^^^^^^^^OVERLAYED INITALIZATION CODE ^^^^^^^^^^^^^^
/
/
	.TITLE	REQUEST DECODER
/
/	MTWFT -- WAIT FOR MAGTAPE TRIGGER EVENT VARIABLE
/		AND DECODE THE REQUEST.ALSO HANDLES UMOUNT REQUEST.
/	MTWFTM -- IF A UNIT WAS PASSED OVER BECAUSE IT IS
/		REWINDING OR IT HASN'T SETTLED DOWN YET
/		AN  MARK TIME WILL RESTART THE SCAN.  THE 
/		ASSIGN INHIBIT FLAG IS NOT CHECKED WHEN A UNIT
/		IS REWINDING.OR A UNIT IS NOT READY.
/
/	SRCHAG -- NODE FOUND LAST SEARCH -- RESEARCH UNTIL A 
/		NODE IS NOT FOUND THAT CAN BE EXECUTED.
/
MTWFTM	CAL	MARKTG	/ISSUE MARK TIME REQUEST TO SET TRIGGER
MTWFT	CAL	MTTRGW	/WAIT FOR TRIGGER EVENT VARIABLE
SRCHAG	LAC	(UNITAB-1) /SET UP UNIT TABLE ENTRY
	DAC	UNITCN	/SEARCH IS IN ROUND ROBBIN ORDER
	DZM	NODFND	/CLEAR NODE FOUND FLAG
	DZM	UNTNTR	/CLEAR THE NOT READY FOUND FLAG
MTNXT	.INH		/INHIBIT INTERRUPTS WHILE LOOKING AT EVENT VARIABLE
	LAC	MTEVAR
	.ENB		/ENABLE INTERRUPTS
	DZM	MTEVAR	/CLEAR EVENT VARIABLE
	AND	(100000) /CHECK FOR I/O RUNDOWN REQUEST
	SZA
	JMP	ABTP	/ABORT I/O RUNDOWN
	LAC	UNITCN	/SET UP TO ACCESS THE NEXT NODE
	SAD	(UNITAB+7) /IS THIS THE END OF THE TABLE?
	JMP	MTSRCH	/YES -- GO CHECK TO SEE IF A REQUEST WAS FOUND
	ISZ	UNITCN	/NO -- INCREMENT POINTER AFTER PICKING
	LAC*	UNITCN	/UP PDVL POINTER
	SNA		/IS TABLE LESS THAN 10 UNITS?
	JMP	MTSRCH	/YES -- GO CHECK TO SEE IF A REQUEST WAS FOUND
	LAC*	UNITCN	/PICK UP THE UNIT NUMBER
			/CHECK CONTROL READY BEFORE
	JMS	CONTNR	/LOADING COMMAND REGISTER     
	AND	(077777) /MASK OFF 15 BITS
	DAC*	(R1)	/NO -- SET UP TO ATTEMPT TO DEQUEUE
	LAC*	UNITCN	/PICK UP THE UNIT NUMBER
	LRS	17	/PUT IT INTO BITS 15-17
	AND	(000007) / MASK OFF THE ADDRESS
	DAC	UNTTMP	/STORE IT IN UNIT NUMBER INUSE FLAG
	PAX		/PUT IT IN XR TO FIND OUT IF
	LAC	NODSAV,X / A NODE WAS NOT USED DUE TO A BUSY
			/CONTROL UNIT.
	SZA		/BUSY?
	JMP	MTPKED	/YES -- DON'T PICK A NODE THIS TIME
			/TAKE THE ONE FROM THE SAVED NODE LIST
	JMS*	(DQRQ)	/NO NODE FOUND PICK A NODE FROM THE QUEUE
	JMP	MTNXT	/NO -- NODE FOUND IN THIS QUEUE
MTPKED	DAC	MTNODE	/SAVE NODE ADDRESS
	TAD	XADJ	/ADD XR ADJUSTMENT
	DAC	XRSV	/SAVE XR POINTER TO MTNODE
	LAC	UNTTMP	/PUT  THE UNIT NUMBER IN XR
	PAX
	LAC	MTEOTT,X	 /PICK UP THE STATUS FLAG
	SAD	(1)	/OR UNMOUNT?
	JMP	MTSPFR	/YES DON'T LOOK AT IT NOW
	SPA!SNA		/IS IT 2?
	JMP	MTRDA	/NO MUST BE -1 OR 0
	MTRS		/CHECK FOR UNIT AT BEGINNING OF TAPE
	AND	(BT)
	SNA!CLA!CMA
	JMP	NTRDYU	/NOT BOT CONTINUE TO WAIT
	DAC	MTEOTT,X /RESET STATUS FLAG TAPE LOADED
MTRDA	LAC	MTLABL,X /TAPE LOADED AND READY CHECK FOR BOT AND LABELED
	SNA
	JMP	MTNOET	/NOT A LABLELD TAPE
MTSPFM	LAW	-1	/SPACE 1 RECORD
	DAC*	WCA
	MTRS		/READ THE STATUS OF THE TAPE
	AND	(BT)	/IS IT BEGINNING OF TAPE?
	SNA
	JMP	MTNOET	/NO MUST BE OK
	LAC*	UNITCN	/YES -- SPACE FORWARD
	AND	(700000)
	TAD	FMTDEN,X /ADD IN DENSITY AND PARITY
	TAD	FMTPAR,X
	XOR	(SF!IE) /SPACE FORWARD
	JMS	CONTNR
	JMS	MTSTRT	/START TAPE
	JMP	NTRDYU	/DECLARE NOT READY THIS TIME
/
MTSPFR	MTRS		/TAPE AT BT?
	AND	(BT)
	SNA
	JMP	NTRDYU	/NO THEN IT IS NOT READY
	LAC	UNTTMP
	PAX		/SET UP TO CHANGE TO STATUS 3
	LAC	(3)
	DAC	MTEOTT,X /SET TO INDICATE TAPE UNMOUNTED
	JMP	MTSPFM	/SPACE FORWARD AND WAIT
/
MTNOET	LAC	XRSV	/RESTORE THE XR
	PAX
	LAC	5,X	/LOOK AT REQUEST TO SEE IF IT IS AN EXIT REQUEST
			/BECAUSE EXIT REQUEST'S SHOULD NOT HAVE TO WAIT
			/FOR A UNIT TO BECOME READY TO BE REMOVED FROM QUEUE
	AND	(777)	/MASK OFF THE LUN SLOT NUMBER
	SAD	(777)	/IS IT EXIT?
	JMP	UNTRDY	/YES -- HANDLE THIS REQUEST-- ONLY SENT TO UNTRDY TO SET EVENT VARIABLE -6
	MTTR		/UNIT BUSY?
	JMP	NTRDYU	/YES -- GO FIND OUT WHY
UNTRDY	LAC	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX
	DZM	NTRTBL,X /NO -- RESET FLAGS
	DZM	NODSAV,X /CLEAR THE NODE SAVED FLAGS
	LAC	XRSV	/RESTORE XR
	DAC	NODFND	/SAVE IN NODE FOUND FLAG
	PAX
	LAC	6,X	/PICK UP USER'S EVENT VARIABLE
	SNA		/IS IT ZERO?
	LAC	(MTUEVA) /YES -- SET EVENT VARIABLE TO SELF
	DAC	MTUEVA	/SAVE EVENT VARIABLE ADDRESS
	LAC	5,X	/PICK UP LUN AND FUNCTION
	AND	(000777) /MASK OFF FUNCTION
	SAD	(000017) /IS IT AN ABORT REQUEST?
	JMP	ABTQ	/YES GO HANDLE ABORT REQUEST
	SAD	(000024) /IS IT AN ATTACH?
	JMP	ATTACH	/YES -- ATTACH LUN AND DEVICE (UNIT)
	SAD	(000025) /IS IT A DETACH REQUEST?
	JMP	DETACH	/YES -- DETACH LUN AND UNIT
	SAD	(000026) /NO -- IS IT A READ?
	JMP	READ	/YES -- READ A RECORD
	SAD	(000027) /NO -- IS IT A WRITE?
	JMP	WRITE	/YES -- WRITE A RECORD
	SAD	(000030) /IS IT A GET REQUEST?
	JMS*	MTPGET	/YES -- GET A RECORD
	SAD	(000031) /NO -- IS IT A PUT REQUEST?
	JMS*	MTPGET	/YES -- WRITE A RECORD
	SAD	(000036) /NO -- IS IT A HANDLER INFORMATION?
	JMP	HINF	/YES -- RETURN HANDLER INFORMATION
	JMS*	MTMOV	/CALL MAGTAPE MOVEMENT OVERLAY FOR THE REST
/	MTSRCH -- DETERMINED IS THE LAST SEARCH FOR A NODE HAS
/		BEEN SUCCESSFUL . IF NOT THE ASSIGN INHIBIT FLAG 
/		IS CHECKED TO DETERMINE WHETHER REASSIGNMENT HAS 
/
MTSRCH	LAC	NODFND	/HAS A REQUEST BEEN
	SZA		/HONORED THIS TIME?
	JMP	SRCHAG	/YES -- GO LOOK FOR ANOTHER
	LAC	UNTNTR
	SZA		/IS THERE A UNIT NOT READY?
	JMP	UNTNCK	/YES -- DON'T LOOK AT ASSIGN INHIBIT DO A MARK TIME
	LAC	UNITAB	/LOOK AT
	AND	(077777) /MASK OFF ADDRESS
	TAD	XADJ	/ADD XR ADJUSTMENT
	PAX
	LAC	11,X	/PICK UP ASSIGN INHIBIT FLAG
	SMA		/IS IT SET?
	JMP	MTWFT	/NO -- WAIT FOR TRIGGER
	JMP	MTEXIT	/YES -- EXIT
/
/	UNTNCK -- ISSUES A MARK TIME TO TIME OUT NOT READY
/		UNITS -- A UNIT THAT IS REWINDING IS IGNORED AND
/		NOT DECLARED NOT READY.
/
UNTNCK	LAC	MARTWF	/PICK UP THE MARK TIME NOT READY FLAG
	SNA		/IS THE TIME UP?
	JMP	MTWFTM	/NO WAIT FOR ANOTHER MARK TIME
	CLX		/YES -- UPDATE NOT READY TABLE
	LAC	(10)	/TEN UNITS MAX
	PAL		/STORE IT IN XR
UNTCLP	LAC	UNITAB,X /PICK UP THE UNIT NUMBER
	MTLC		/LOAD COMMAND REGISTER TO SEE IF REWINDING
	MTRS		/READ THE STATUS
	AND	(RW)	/MASK OFF REWIND STATUS
	SZA		/REWINDING?
	JMP	NXTUPD	/YES -- DON'T COUNT FOR NOT READY
	LAC	NODSAV,X / PICK UP THE NODE SAVED FLAG
	SAD	NTRDMM	/DON'T UPDATE PAST REQUEST FOR MESSAGE FLAG
	JMP	NXTUPD	/NO UPDATE NTRTBL
	SNA		/WAS THE UNIT NOT READY?
	JMP	NXTUPD	/NO -- DON'T UPDATE THE COUNT
	LAC	NTRTBL,X /PICK UP THE NOT READY COUNT
	SAD	NTRDMX	/IS IT AT THE MAXIMUM?
	SKP
	ISZ	NTRTBL,X / NO -- UPDATE THE COUNT
NXTUPD	AXS	1	/ADD 1 TO XR AND SEE IF ANY ARE LEFT TO CHECK
	JMP	UNTCLP	/YES -- UPDATE THE NEXT ONE
	CAL	MARKNR	/NO -- DO A MARK TIME FOR THE NEXT ROUND
	JMP	MTWFTM	/DO MARK TIME ON THE TRIGGER
/
/
	.TITLE	MT EXIT
/
/	REASSIGN INHIBIT FLAG IS SET CLEAR ALL REASSIGN
/		INHIBIT FLAGS FOR THIS TASK, REMOVE ALL NODES FROM THE QUEUE'S
/		AND EXIT AFTER CLEARING THE REASSIGN INHIBIT FLAGS FOR ALL NODES.
/		DO A MARK TIME INSTEAD IF A UNIT IS BUSY.
/
MTEXIT	CAL	DETMT	/DETACH FROM MAGTAPE
	CAL	UNMARK	/CANCEL ALL PENDING MARK TIMES
	LAC	(400004) /RAISE TO LEVEL 5 TO PROTECT
	ISA		/AGAINST REASSIGNMENT CHANGING
	LAC	(UNITAB-1) /THE NODES
	DAC*	(X10)	/SET UP TO CLEAR THE ASSIGN INHIBIT FLAGS
	LAW	-10	/CLEAR A MAXIMUM OF 10 NODES
	DAC	UNITCN
EXITLP	LAC*	X10	/PICK UP A NODE POINTER
	SNA		/END OF TABLE?
	JMP	EXIT	/YES -- DBK, DISCONNECT AND EXIT
	AND	(077777) /MASK OFF NODE ADDRESS
	TAD	XADJ	/ADD XR ADJUSTMENT
	PAX
	DZM	10,X	/CLEAR TRIGGER JUST IN CASE !!!!
	DZM	11,X	/CLEAR ASSIGN INHIBIT FLAG
	TAD	MXADJ	/SUBTRACT XR ADJUSTMENT
	AAC	6	/FIND REQUEST LIST HEAD
	DAC	MTNODE
CLEARQ	LAC	MTNODE	/PICK UP THE QUEUE LIST HEAD POINTER
	DAC*	(R1)	/SET UP TO PICK UP NODES FROM THIS QUEUE
	JMS*	(PICK)	/EMPTY QUEUE SINCE MAGTAPE HANDLER IS EXITING
	JMP	NXTUNT	/EMPTY QUEUE - TRY THE NEXT NODE
	DAC*	(R2)	/SET UP TO ADD NODE TO POOL
	TAD	XADJ	/ADD XR ADJUSTMENT TO FIND
	PAX		/EVENT VARIABLE ADDRESS
	LAC	6,X	/SET USER'S EVENT VARIABLE TO -24
	SNA		/EVENT VARIABLE ADDRESS SPECIFIED?
	JMP	NOEVA	/NO -- DON'T SET IT THEN
	TAD	XADJ	/YES -- SET UP XR TO SET
	PAX		/EVENT VARIABLE
	LAW	-24	/SET EVENT VARIABLE TO -24
	DAC	0,X	/SET EVENT VARIABLE
NOEVA	LAC	(POOL)	/RETURN THE NODE TO THE POOL
	DAC*	(R1)
	JMS*	(IOCD)	/COUNT DOWN I/O PENDING COUNT
	JMS*	(NADD)
	JMP	CLEARQ	/SEARCH FOR ANOTHER NODE
NXTUNT	ISZ	UNITCN	/10 UNITS FOUND
	JMP	EXITLP	/NO -- DO ANOTHER
EXIT	DBK		/DEBREAK FROM LEVEL 5 TO LEVEL 7
	CAL	(10)	/EXIT
	.TITLE	MT NOT READY
/
/	NTRDYU -- CHECKS TO SEE IF A UNIT
/		IS BUSY REWINDING OR IF A UNIT IS
/		JUST FINISHING UP OR IF A UNIT IS
/		REALLY NOT READY.
/
NTRDYU	LAC	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX
	LAC	MTNODE	/PICK UP THE POINTER TO THE NODE
	DAC	NODSAV,X /SAVE THE NODE UNTIL THE UNIT IS READY
	DAC	UNTNTR	/SET THE UNIT NOT READY FLAG SO A MARK TIME
			/WILL BE DONE TO ENABLE THIS UNIT WHEN IT IS READY
	LAC	MTEOTT,X	/READY STATUS?
	SMA
	JMP	MTNXT	/NO DON'T PRINT MESSAGE
	MTRS		/READ THE STATUS OF THE UNIT
	AND	(RW)	/ MASK OFF REWIND STATUS
	SZA		/IS IT REWINDING?
	JMP	MTNXT	/YES -- LOOK AT THE NEXT NODE
/
/	ONORTO -- CHECKS THE COUNT AND PRINTS THE NOT
/		READY MESSAGE IF NECESSARY.
ONORTO	LAC	NREV	/IS THE TTY BUSY?
	SNA
	JMP	MTNXT	/YES DON'T PRINT A MESSAGE THIS TIME
	LAC	NTRTBL,X /PICK UP NOT READY COUNT
	SAD	NTRDMM	/IS EVENT VARIABLE COUNT READY TO PRINT NT RDYMSG
	SKP
	JMP	MTNXT	/LOOK AT NEXT REQUEST -- EVENT VARIABLE = 2
	PXA		/EVENT VARIABLE = 1 -- PRINT MESSAGE
	CLL!RAL		/PUT IT INTO BITS 14-16
	XOR	MTNAM+1	/SET UP UNIT NUMBER
	DAC	NTRDMS	/PUT IT IN NOT READY MESSAGE
	ISZ	NTRTBL,X /UPDATE THE COUNT TO PREVENT DOUBLE MESSAGE
	CAL	NTRDYM	/PRINT NOT READY MESSAGE
	JMP	MTNXT	/LOOK AT NEXT REQUEST
/
ABTQ	XOR	5,X	/LUN SHOULD BE 0
	SZA
	JMP	ERM6	/NOT 0 THEREFORE UNIMPLEMENTED FUNCTION
	LAC	MTNODE	/SET UP TO DEQUE
	DAC	ABNODE
	JMS	ABORTA	/GO ABORT ALL NODES
	JMP	FINREQ	/FINISHED RETURN
/
ABORTA	0
	.INH		/CLEAR I/O RUNDOWN FLAG
	LAC	MTEVAR
	AND	(677777
	.ENB		/ENABLE INTERRUPTS
	DAC	MTEVAR	/RESET FLAG
	LAC	(2)	/SET UP TO LOOK AT NAMES
	PAX
	LAW	-10
	DAC	ABTCNT	/IN THE NOT READY QUEUE
	LAC	(NODSAV)
	DAC	ABTNDS
ABTLPC	LAC*	ABTNDS	/LOOK AT THE FIRST ENTRY
	SNA		/IS IT 0?
	JMP	NXTABT	/YES IGNORE IT
	DAC	ABTSVS	/NO SAVE POINTER
	LAC*	ABTSVS,X	/CHECK FOR I/O RUNDOWN NMAE
	SAD*	ABNODE,X /IS IT THE ONE LOOKING FOR?
	JMP	RTTAWB
NXTABT	ISZ	ABTNDS	/NO TRY AGAIN
	ISZ	ABTCNT	/FINISHED?
	JMP	ABTLPC	/NO KEEP GOING
	LAW	-10
	DAC	ABTCNT	/SET UP TO DO 10 UNITS
	LAC	(UNITAB)
	DAC	ABTTMP	/SET UP POINTER TO PDVL'S
ABTLP	LAC	ABNODE	/SET UP TO REMOVE ALL REQUESTS FROM QUEUE
	DAC*	(R2)
	LAC*	ABTTMP	/PICK UP PDVL ADDRESS
	AND	(077777) /MASK OFF UNIT
	DAC*	(R1)
	JMS*	(DTMQ)	/DELETE NODES
	ISZ	ABTTMP	/UPDATE UNTTMP TO NEXT ADDRESS
	LAC*	ABTTMP
	SNA		/FINISHED WITH ALL QUEUE'S?
	JMP*	ABORTA	/YES EXIT
	ISZ	ABTCNT	/FINISHED WITH 10 UNITS?
	JMP	ABTLP	/NO TRY AGAIN
	JMP*	ABORTA	/YES EXIT
/
RTTAWB	DZM*	ABTNDS	/CLEAR THE NOT READY QUEUE
	LAC	ABTSVS	/PICK UP THE NODE ADDRESS
	DAC*	(R2)
	LAC	(POOL)	/AND RETURN IT TO THE POOL
	DAC*	(R1)
	JMS*	(IOCD)
	JMS*	(NADD) /AND DO I/O COUNTDOWN
	JMP	NXTABT	/TRY NEXT NODE
/
ABTP	LAC	UNITAB	/SET UP TO DEQUE A NODE
	AND	(77777)
	DAC*	(R1)
	JMS*	(DQRQ)	/PICK A NODE
	JMP	SRCHAG	/CAN'T HAPPEN
	DAC	ABNODE	/SAV THE NODE ADDRESSE
	DAC	MTNODE	/SAVE NODE IN MTNODE
	TAD	XADJ	/ADD XR ADJUSTMENT
	PAX
	LAC	6,X	/PICK UPTHE EVENT VARAIBLE ADDRESS
	DAC	MTUEVA	/SAVE IT
	JMS	ABORTA
	JMP	FINREQ	/FINISHED RETURN
/
	.TITLE	ATTACH,DETACH,HINF
/
/
/	ATTACH -- ATTACHES THE TASK TO THE UNIT AND
/		PDVL NODE FOR THE MAGTAPE
/
ATTACH	CLA!IAC		/SET XR TO +1 TO INDICATE ATTACH
	PAX		/PUT +1 IN XR
	JMP	ATDC	/ENTER COMMON ATTACH DETACH CODE
/
/
/	DETACH -- DETACHES THE TASK FROM THE UNIT AND
/		PDVL NODE FOR THE MAGTAPE
/
DETACH	CLX		/CLEAR XR TO INDICATE DETACH 
ATDC	LAC*	UNITCN	/PICK UP THE PDVL HEAD -- COMMON CODE FOR ATTACH AND DETACH
	AND	(077777) /MASK OFF ADDRESS
	DAC*	(R1)
	LAC	MTNODE	/PICK UP THE NODE POINTER
	DAC*	(R2)
	XCT	ATDT,X	/DETACH LUN AND UNIT
	JMP	FLSREQ	/ERROR -- RETURN EV -24
	JMP	FINREQ	/RETURN -- DETACH OK
/
ATDT	JMS*	(DLAD)	/DETACH DEVICE
	JMS*	(ALAD)	/ATTACH DEVICE
/
/	HINF -- HANDLER INFORMATION 300005+UNIT*100
/		INDICATES I/O-NON FILE ORIENTED MAGTAPE.
/
/
HINF	LAC*	UNITCN	/PICK UP THE UNIT NUMBER
	LRS	11	/PUT IT IN BITS 9-11
	AND	(000700) /MASK OFF UNITS NUMBER
	XOR	HINFM	/ADD MAGTAPE AND UNIT STATUS
	JMP	FLSREQ	/RETURN 300005+UNIT*100
	.TITLE	INTERRUPT SERVICE
/
/	MTINT -- MAGTAPE INTERRUPT SERVICE
/		SAVE STATUS IN EVENT VARIABLE AND
/		RETURN.
/
MTINT	0
	DBA		/DISABLE BANK ADDRESSING
	DAC	MTSVAC	/SAVE AC
	MTRS		/READ MAGTAPE STATUS
	DAC	MTEVA	/SAVE IT IN THE EVENT VARIABLE
	DAC	MTEVAM	/SET STATUS FLAG
	MTAF		/CLEAR THE STATUS AND COMMAND REGISTER
	LAC	(401000) /DECLARE A
	ISA		/SIGNIFICANT EVENT
	LAC	MTSVAC	/RESTORE AC
	DBR
	JMP*	MTINT	/RETURN
	.TITLE	READ-WRITE DECODER
/
/
/	READ -- DECODES THE READ TYPE (BINARY OR ASCII (7 OR 9 TRACK))
/
READ	PXL		/SAVE THE XR
	LAC	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX		/SAVE UNIT NUMBER IN XR
	LAC	MTEOTT,X /PIC UP THE EOT FLAGS
	SMA		/IS THE UNIT AT EOT?
	JMP	ERM21	/YES ERROR
	PLX		/RESTORE XR TO POINT TO REQUEST
	LAC	7,X	/PICK UP THE MODE OF THE REQUEST
	AAC	-1	/MAKE BINARY MODES GE 0
	SPA!SNA!STL	 /BINARY?-- SET THE LINK TO INDICATE A READ REQUEST FOR BINARY READ'S
	JMS*	MTRWB	/YES READ A BINARY RECORD
	JMS	FMTTYP	/NO -- DETERMINE IF 7 OR 9 TRACK REQUEST
	JMS*	MTREA7	/7 TRACK READ REQUEST
	JMS*	MTREA9	/9 TRACK READ REQUEST
/
/	WRITE -- DECODES THE WRITE TYPE (BINARY OR ASCII (7 OR 9 TRACK))
/
WRITE	PXL		/SAVE THE XR WITH THE NODE POINTER
	LAC	UNTTMP	/PICK UP THE UNIT NUMBER OF THE REQUEST
	PAX		/PUT IT IN XR TO
	LAC	MTEOTT,X / PICK UP THE EOT FLAGS
	SMA		/EOT?
	JMP	ERM21	/YES ERROR
	PLX		/NO RESTORE NODE POINTER
	LAC	7,X	/PICK UP THE MODE OF THE REQUEST
	AAC	-1	/MAKE BINARY MODES GE 0
	SPA!SNA!CLL	 /BINARY? -- CLEAR THE LINK TO INDICATE A WRITE REQUEST
	JMS*	MTRWB	/YES WRITE A BINARY RECORD
	JMS	FMTTYP	/NO -- DETERMINE IF 7 OR 9 TRACK REQUEST
	JMS*	MTWRA7	/7 TRACK WRITE REQUEST
	JMS*	MTWRA9	/9 TRACK WRITE REQUEST
/
/	FMTTYP -- DETERMINES IF THIS UNIT IS 7 OR 9 TRACK.
/		RETURNS +1 IF 7 TRACK AND +2 IF 9 TRACK.
/
FMTTYP	0
	LAC	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX		/PUT IT IN XR TO FIND IF 7 OR 9 TRACK
	LAC	FMTDEN,X /CHECK THE FORMAT PARITY TABLE
	SAD	(D9)	/SKIP IF NOT 9 TRACK
	ISZ	FMTTYP	/RETURN AT JMS+2
	JMP*	FMTTYP	/RETURN
	.TITLE	WFMT  -- WAIT FOR MAGTAPE REQUEST TO FINISH
/
/	WFMT -- STARTS MAGTAPE DRIVE.  ENTERED WITH AC  CONTAINING
/		COMMAND REQUEST.  MTCAA CONTAINS THE CURRENT ADDRESS
/		POINTER AND MTWCA CONTAINS THE TWO'S COMPLEMENT WORD
/		COUNT.  WFMT HANDLES ALL ERROR RECOVERY.  IF ERROR'S
/		OCCUR THE HANDLER WILL ATTEMPT 10 RETRY'S BEFORE IT RETURNS
/		A FATAL ERROR.  ON WRITE OPERATIONS EXTENDED INTER-RECORD
/		GAP WILL BE REQUESTED FOR THE LAST 4 RETRIES.  MAGTAPE
/		SERVICE WILL DEGRADE SERIOUSLY IF A BAD TAPE WITH
/		MANY ERRORS IS USED.
/
WFMT	0
	DAC	MTCMND	/SAVE THE COMMAND REQUESTED
			/CHECK FOR CONTROL READY
	JMS	CONTNR	/DO A MARK TIME TO WAIT FOR CONTROL
			/SET UP THE COMMAND REGISTER
	LAC	(SR)	/SET DEFAULT RECOVERY TO SPACE REVERSE
	DAC	MTERCM
	LAW	-10	/SET UP THE ERROR COUNT
	DAC	ERRCNT
MTWFLP	JMS	MTSTRT	/START CONTROL AND WAIT FOR INTERRUPT
	SMA		/WAS THERE AN ERROR?
	JMP*	WFMT	/NO -- RETURN
	LAC	UNTTMP	/PICK UP UNIT NUMBER
	PAX
	LAC	USREC,X	/USER RECOVERY?
	SNA
	JMP*	WFMT	/YES RETURN EV
	LAC	MTEVAM	/NO -- HANDLER RECOVERY
	AND	(PE!TB!DL) /CHECK FOR LEGAL ERRORS
	SNA		/ERROR'S LEGAL?
	JMP*	WFMT	/YES -- RETURN TO CALLER
	ISZ	ERRCNT	/UPDATE THE ERROR COUNT
	SKP		/NOT FATAL RETRY
	JMP*	WFMT	/FATAL ERROR'S RETURN WITH STATUS
	LAC	MTCMND	/NO -- TRY TO RECOVER
	AND	(007000) /LOOK AT THE REQUEST TYPE
	SAD	(SR) 	/IS IT A SPACE REVERSE?
	JMP	SPRERR	/REVERSE SPACE ERROR -- DON'T BACKSPACE TO RECOVER
	SAD	(SF)	/IS THIS A SPACE FORWARD?
	JMP	SPFERR	/YES -- PICK UP WORD COUNT BEFORE RECOVERING
	SAD	(WF)	/IS IT A WRITEEND OF FILE?
	JMS	CKCNT	/YES -- CHECK ERROR COUNT TO SEE IF EXTENDED INTER RE ORD GAP IS NECESSARY
	SAD	(WR)	/IS IT A WRITE?
	JMS	CKCNT	/YES -- CHECK ERROR COUNT
MTREC	LAC	MTCMND	/PICK UP THE COMMAND TO DETERMINE THE UNIT BUMBER
	AND	(740700) /MASK UNIT,PARITY, AND INTERRUPT ENABLE AND DENSITY
	XOR	MTERCM	/SPACE 1 FORWARD OR BACKWARD DEPENDING UPON ORIGIONAL MOTION
			/CHECK FOR CONTROL READY
	JMS	CONTNR	/DO A MARK TIME TO WAIT FOR CONTROL
			/LOAD COMMAND REGISTER
	MTTR		/TEMP WAIT FOR UNIT
	JMS	WFMTTR	/UNIT NOT READY WAIT FOR UNIT
	LAW	-1	/SET UP WORD COUNT
	DAC*	WCA	/TO BACKSPACE 1 RECORD
	JMS	MTSTRT	/START CONTROL AND WAIT FOR INTERRUPT
	LAC	MTCMND	 /CHECK FOR CONTROL READY
	JMS	CONTNR	/DO A MARK TIME TO WAIT FOR CONTROL
			/RESET IT IN THE COMMAND REGISTER
	MTTR		/IS THE UNIT READY YET?
	JMS	WFMTTR	/NO -- DO A MARK TIME TO WAIT FOR IT
WFRES	LAC	MTWCA	/RESTORE THE WORD COUNT
	DAC*	WCA
	LAC	MTCAA	/RESTORE THE CURRENT ADDRESS POINTER
	DAC*	CAA
	JMP	MTWFLP	/GO TRY THE COMMAND AGAIN
/
/	MTSTRT -- STARTS THE CONTROL AND WAITS FOR THE PENDING INTERRUPT
/
MTSTRT	0
	.INH		/INHIBIT INTERRUPTS WHILE CLEARING TRIGGERS
	DZM	TIMOUT	/CLEAR THE TIME OUT FLAG -- USED TO DETERMINE
			/IF THE UNIT IS HUNG DUE TO USER ERROR
	LAC	MARERF	/PICK UP THE MARK TIME FLAG FOR THIS WAIT
	SNA		/IS IT SET?
	JMP	MFWLP	/NO DON'T DO A MARK TIME
	.ENB		/ENABLE INTERRUPTS TO DO A MARK TIME
	CAL	MARERT	/ORDER OF MARK TIMES IS CRUCIAL SINCE
			/THIS MARK TIME MUST COMPLETE TO SIGNAL
			/THAT IT HAS EXPIRED BEFORE THE TRIGGER IS SET
	CAL	MARKER	/TRIGGER MARK TIME
MFWLP	DZM	MTEVAM	/CLEAR THE STATUS FLAGS
	MTGO		/START THE CONTROL
MTWFIN	DZM	MTEVA	/CLEAR THE EVENT VARIABLE
	.ENB		/ENABLE INTERRUPTS
	CAL	MTTRGA	/WAIT FOR THE TRIGGER EVENT VARIABLE
TSTAGN	.INH		/INHIBIT INTERRUPTS WHIE LOOKING AT THE FLAGS
	LAC	MTEVAR	/I/O RUNDOWN REQUESTED?
	AND	(100000
	SZA
	JMP	ABORTI	/YES HANDLE IT NOW
	LAC	MTEVAM	/PICK UP THE STATUS OF THIS OPERATION
	SZA
	JMP	MTFIN	/TRIGGER SET
	LAC	MARERF	/IS THE TIME OUT TRIGGER SET?
	SNA	
	JMP	MTWFIN	/GO WAIT FOR EVENT VARIABLE
	.ENB		/YES ENABLE INTERRUPTS TO LOOK AT TIME OUT
	LAC	TIMOUT	/IS IT SET?
	ISZ	TIMOUT	/UPDATE TIMEOUT FLAG
	SZA
	JMP	MTFATL	/YES -- FATAL ERROR
	CAL	MARERT	/RESTART MARK TIMES
	CAL	MARKER
	JMP	TSTAGN	/GO TRY AGAIN
MTFIN	.ENB			/ENABLE INTERRUPTS
	LAC	MTEVAM	/PICK UP STATUS
	JMP*	MTSTRT
/
ABORTI	.ENB		/ENABLE INTERRUPTS
	LAC	UNITAB	/SET UP TO DEQUE A NODE
	AND	(77777) /MASK OFF UNIT NUMBER
	DAC*	(R1)
	JMS*	(DQRQ)	/DEQUEUE IT
	JMP	TSTAGN	/CAN'T HAPPEN
	DAC	ABNODE	/SAVE NODE ADDRESS
	TAD	XADJ
	PAX
	LAC	6,X	/SAVE EVENT VARIABLE ADDRESS
	SNA
	LAC	(ABTEV)	/NO EVA
	DAC	ABTEV
	LAC	5,X	/IS IT A 17?
	SAD	(17)
	SKP		/YES HONOR IT
	JMP	NOTABT	/NO ERROR
	JMS	ABORTA	/ABORT REQUEST'S
	DZM	FNDNO	/CLEAR FOUND FLAG
	LAC	(2)	/SET UP TO LOOK AT STL ADDRESSES
	PAX
	LAC*	MTNODE,X	/COMPARE WITH RUNNING REQUEST
	SAD*	ABNODE,X
	JMP	SAMRQ	/SAME ABORT THIS REQUEST
SAMRTN	CLA!IAC		/SET ABORT FLAG
ABTSEV	PAL		/SAVE EVENT VARIABLE
	LAC	ABTEV	/FIND ADDRESS
	TAD	XADJ
	PAX
	PLA		/RETURN EV
	DAC	0,X
	LAC	ABNODE	/RETURN NODE TO POOL
	DAC*	(R2)
	LAC	(POOL)
	DAC*	(R1)
	JMS*	(IOCD)	/DO I/O COUNTDOWN FIRST
	JMS*	(NADD)	/ADD NDE TO POOOL
	ISZ	FNDNO	/NODE FOUND TO BE ABORTED?
	JMP	TSTAGN	/GO TRY AGAIN
	JMP	MTNXT	/YES ABORT THIS REQUEST
/
SAMRQ	LAC	MTNODE	/RETURN NODE TO POOL
	DAC*	(R2)
	LAC	(POOL)
	DAC*	(R1)
	JMS*	(IOCD)
	JMS*	(NADD)
	LAW	-1
	DAC	FNDNO	/SET NODE FOUND FLAG
	JMP	SAMRTN	/RETURN
/
NOTABT	LAW	-6	/ILLEGAL ABORT REJECT IT
	JMP	ABTSEV	/SET EVENT VARIABLE AND RETURN NODE TO POOL
/
/	CONTNR -- CHECK FOR CONTROL NOT READY SINCE A MTLC WILL
/		NOT LOAD THE COMMAND REGISTER IF THE CONTROL IS NOT READY IT WILL
/		JUST SKIP !!!!?
/
CONTNR	0
	DAC	NTRDYC	/SAVE AC
CONWAS	LAC	NTRDYC	/RESTORE AC
	MTCR		/IS THE CONTROL READY?
	JMP	CONWAT	/NO WAIT FOR IT
	MTLC		/YES LOAD COMMAND REGISTER
	JMP*	CONTNR	/RETURN TO CALLER
CONWAT	CAL	MARTTR
	CAL	WFMTTG	/WAIT FOR MARK TIME
	JMP	CONWAS	/CHECK TO SEE IF READY NOW
/
/	WFMTTR -- WAITS FOR UNIT TO BECOME READY SO 
/		COMMAND WILL BE LEGAL
/
WFMTTR	0
	DZM	TIMOUT	/SET TIMOUT FLAG SO NOT READY CAN BE PRINTED IF NECESSARY
WFMTLP	CAL	MARTTR	/DO A MARK TIME TO READY UNIT
	CAL	WFMTTG	/WAIT FOR THE MARK TIME
	MTTR		/IS THE CONTROL READY YET?
	SKP		/NO -- PRINT NOT READY MESSAGE
	JMP*	WFMTTR	/YES -- RETURN
	LAC	NREV	/PICK UP THE EVENT VARIABLE
	SNA		/HAVE WE ALREADY PRINTED A MESSAGE?
	JMP	WFMTLP	/YES -- GO WAIT SOME MORE
	LAC	TIMOUT	/PICK UP THE TIMEOUT FLAG
	ISZ	TIMOUT	/INCREMENT IT TO PREVENT DOUBLE PRINTING
	SZA		/PRINTED?
	JMP	WFMTLP	/YES DON'T PRINT THE MESSAGE AGAIN
	LAC	UNTTMP	/NO -- PICK UP THE UNIT NUMBER
	CLL!RAL
	XOR	MTNAM+1	/ADD IT TO THE NAME
	DAC	NTRDMS	/STORE IT IN THE NOT READY MESSAGE
	CAL	NTRDYM	/PRINT THE MESSAGE
	CAL	WFNTRD	/WAIT FOR THE READ
	JMP	WFMTLP	/LOOK WAITING FOR READY UNIT
/
/	CKCNT -- CKECKS THE ERROR COUNT AT -5 AND AN EXTENDED
/		INTER-RECORD GAP IS REQUESTED FROM THE CONTROL TO
/		SKIP OVER THE BAD TAPE OR OTHER ERROR CONDITION
/
/
CKCNT	0		/ROUTINE TO CHECK THE ERROR COUNT ON WRITE AND SET THE EXTENDED INTER RECORD GAP
	LAC	ERRCNT	/PICK UP THE ERROR COUNT
	SAD	(-5)	/4 ERRORS?
	SKP		/YES ADD EXTENDED INTER RECORD GAP
	JMP*	CKCNT	/NO RETURN
	LAC	MTCMND	/PICK UP THE REQUESTED COMMAND
	XOR	(IG)	/ADD INTER RECORD GAP
	DAC	MTCMND	/RESTORE IT IN THE SAVE D COMMAND
	JMP*	CKCNT	/RETURN
/
/	MTFATAL -- RETURNS -12 TO USER'S EVENT VARIABLE ON A FATAL ERROR
/
MTFATL	MTAF		/CLEAR CONTROL IF POSSIBLE
	LAW	-12	/FATAL ERROR
	JMP	FLSREQ	/RETURN EV -12 TO USER
/
/	SPRERR	SETS THE WORD COUNT TO -1 AND SPACES FORWARD OR 
/		REVERSE DEPENDING UPON ORIGIONAL DIRECTION
/
SPRERR	LAC	(SF)	/ON SPACE REVERSE ERROR SPACE FORWARD TO RECOVER
	DAC	MTERCM
SPFERR	LAC*	WCA	/ON SPACE ERRORS SAVE WORD COUNT
	AAC	-1	/LAST ONE FAILED SO SUBTRACT 1 FROM WORD COUNT
	DAC	MTWCA	/SO RECOVERY DOESN'T GO TOO FAR
	JMP	MTREC	/RETURN TO NORMAL RECOVERY SEQUENCE
	.TITLE	SET EVENT VARAIBLE
/
/	FINREQ  -- RETURNS AN EVENT VARIABLE OF +1 TO THE USER'S EVENT VARIABLE
/	FLSREQ  -- RETURN THE EVENT VARIABLE IN AC TO THE USER'S EVENT VARIABLE
/
FINREQ	CLA!IAC		/RETURN A +1 EVENT VARIABLE REQUEST HONORED
FLSREQ	PAL		/SAVE EVENT VARIABLE
	LAC	MTUEVA	/GET THE EVENT VARIABLE ADDRESS
	TAD	XADJ	/ADD THE XR ADJUSTMENT
	PAX		/PUT IT IN XR
	PLA		/RESTORE THE EVENT VARIABLE
	DAC	0,X	/SET THE USER'S EVENT VARIABLE
	LAC	(401000) /DECLARE A SIGNIFIGANT EVENT
	ISA
	LAC	MTNODE	/PICK UP THE ADDRESS OF THE NODE
	DAC*	(R2)	/SET UP TO RETURN IT TO THE POOL
	JMS*	(IOCD)	/COUNT DOWN TRANSFERS PENDING COUNT
	LAC	(POOL)	/PICK UP THE ADDRESS OF THE POOL
	DAC*	(R1)
	JMS*	(NADD)	/RETURN THE NODE TO THE POOL
	JMP	MTNXT	/WAIT FOR THE NEXT MAGTAPE REQUEST
/
ERM6	LAW	-6
	JMP	FLSREQ	/UNIMPLEMENTED FUNCTION
ERM21	LAW	-21
	JMP	FLSREQ
/
/
ERM12	LAC	UNTTMP	/PICK UP THE UNIT NUMBER
	PAX
	LAC	USREC,X	/FATAL ERROR RETURNS EV -- USER RECOVERY -12 HANDLER RECOVERY
	SZA
	JMP	MTFATL	/HANDLER RECOVERY FATAL ERROR
	LAC	MTEVAM	/PICK UP THE STATUS USER RECOVERY
	JMP	FLSREQ
	.TITLE	TEMP STORAGE AND CPB'S
/
/
/
/		TEMPORARY STORAGE
/
MXADJ	0	/MINUS XR ADJUSTMENT
XADJ	0	/XR ADJUSTMENT
ABTNDS	0	/SAVE AREA FOR ABORT
ABTSVS	0
ABTCNT	0
ABTTMP	0
ABNODE	0
ABTEV	0
FNDNO	0
MARKTG	13	/CAL FUNCTION CODE
	MTEVAR	/TRIGGER ADDRESS
	2	/2 UNITS
	1	/TICKS	20-40 MS DELAY
MTTRGW	20	/WAIT FOR TRIGGER
	MTEVAR	/EVENT VARIABLE ADDRESS
/
MTTRGA	20	/WIIT FOR MT
	MTEVA
/MTEOTT - -1 = TAPE READY
/		0 = TAPE AT EOT
/		1 = TAPE MNMOUNTED
/		2 = TAPE WAITING TO BE MOUNTED
/
	.REPT	10	/MAGTAPE END OF TAPE -- UNLOAD
MTEOTT	-1
	.REPT	10	/USER RECOVERY TABLE
USREC	LAW	-1
MTLABL	.BLOCK	10	/MAGTAPE LABELED =1 0=UNLABELED
UNMARK	23
	0
	.SIXBT	'MT....'
DETMT	12	/DETACH
	0	/EVENT VARIABLE ADDRESS	
	5	/LINE # 5
	MTINT	/INTERRUPT ADDRESS
WFMTTG	20
	MTEVAT
MARTTR	13	/MARK TIME REQUEST
	MTEVAT	/EVENT VARIABLE
	2	/2 UNITS
	1	/TICKS
MARKNR	13	/CAL FUNCTION CODE (MARK)
	MARTWF
	2	/2 UNITS
	1	/TICKS
MARERT	13	/MARK TIME
	MTEVA
	36
	2	/30 SECONDS
MARKER	13
	MARERF
	36
	2	/30 SECONDS
MARERF	1	/MUST START AT 1
NTRDMX	31
NTRDMM	30
MTNAM	.ASCII	'* MT0'
MARTWF	1	/MUST START AT 1
HINFM	300005	/HANDLER INFORMATION
NTRDYM	2700	/WRITE NOT READY ON TTY
	NREV	/EVENT VARIABLE OF NOT READY TTY REQUEST
	3
	2
	NTRDM
NTRDM	NTRDE-NTRDM/2*1000+2
	0
	.ASCII	'  **** MT0 NOT READY'<15>
NTRDMS=NTRDM+5
NTRDE=.
WFNTRD	20
	NREV
NREV	1	/MUST START AT 1
UNITAB	.BLOCK	10	/UNIT TABLE & PDVL POINTER TABLE -- UNIT IN 0-2
	.END	MTRQ
