	.SYSID <	.TITLE MTA. >,< 108>
/
/COPYRIGHT (C) 1975
/DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
	.EJECT
	.TITLE	MTA. EDIT'S
/MTA., FILE-STRUCTURED MAG TAPE HANDLER,VERSION II.
/	THIS HANDLER DOES NOT SUPPORT NON-FILE-STRUCTUED READ/WRITES.
/FT:	PW	16-JUL-69
/MD:	DM	4-SEP-70
/EDIT  #001	SK	9-JUL-73
/	002	SK	15-JAN-74	GENERAL BUG FIX TO PERMIT- OPERATION
/					WITH MTDUMP V4A, DELETE NFS CODE FROM
/					WRITE, CONSOLIDATE .TRAN OPERATION
/	003	SK	21-JAN-74	CLEANUP OF E. 002. FIX SPR'S: 661+663
/	004	SK	20-FEB-74	E. 002+003 DID NOT FIX PROBLEM
/					FOR ALL CASES. THIS EDIT HOPEFULLY
/					FIXED C MT_XX PIP OPERATION
/#005	10-14-74 (RCHM)	FIX FOR 9 TRACK OPERATION AS IN MTF. 012.
/006	12-18-74 (RCHM)	FIX ERROR RECOVERY FOR .TRAN'S.
/ 106	06-JUN-75 (RCHM)	MAKE XVM CHANGES.
/ 107	31-JUL-75 (JMW)		RETURN STATUS IN .SCOM+21, AS DOCUMENTED.
/ 108	30-SEP-75 (RCHM)	FIX 9/7 CHANNEL CONFUSION.
	.TITLE	MTA. FILE STRUCTURED MAG TAPE HANDLER.
/*****	TIMES OUT TO DETERMINE AVAILABILITY OF TRANSPORT	*****
  
MTSF=IOT+7341	/SKIP ON MAG TAPE DONE OR MAG TAPE ERROR FLAG.
MTCR=IOT+7321	/SKIP ON MAG TAPE CONTROL READY.
MTTR=IOT+7301	/SKIP ON SELECTED MAG TAPE TRANSPORT READY.
MTAF=IOT+7322	/CLEAR MAG TAPE DONE AND ERROR FLAGS (ALSO STATUS
		/AND COMMAND REGISTERS, IF CONTROL IS READY).
MTCM=IOT+7324	/IOR AC 0-5,9-11 TO COMMAND REGISTER; TRANSFER
		/AC 6-8 TO COMMAND REGISTER 6-8.
MTLC=IOT+7326	/TRANSFER AC 0-11 TO COMMAND REGISTER.
MTVS=IOT+7342	/IOR STATUS REGISTER TO AC.
MTRS=MTVS+10	/READ STATUS.
MTVC=IOT+7302	/IOR COMMAND REGISTER TO AC.
MTRC=MTVC+10	/READ COMMAND.
MTGO=IOT+7304	/SET GO.
.MED=3		/MONITOR ERROR DIAGNOSTIC.
.SCOM=100		/SYSTEM COMMUNICATION.
MTREGS=6		/TEMP REGISTERS ASSOCIATED WITH EACH FILE.
	.TITLE	CAL DISPATCHER
/
	.GLOBL MTA.
MTA.	DAC MTCALP	/SAVE POINTER TO CAL.
	DAC MTARGP	/AND TO ARGUMENT LIST.
	ISZ MTARGP	/BUMP TO UNIT AND FUNCTION.
	LAC MTERRS	/PICK UP ERROR INDICATOR FROM PREVIOUS IO TRANSFER.
	SZA!CLL		/SKIP IF AN ERROR DID NOT OCCUR.
	JMP* MTERRS	/THERE WAS AN ERROR. GO TRY TO RECTIFY IT.
MTGET	LAC* MTARGP	/NO ERROR, GET FUNCTION WANTED THIS TIME.
	AND (17		/EXTRACT FUNCTION.
	TAD (MTDISP	/FORM DISPATCH ADDRESS.
	DAC MTDISP	/MTDISP POINTS TO CAL SERVICER.
	LAC* MTARGP	/GET UNIT.
	ISZ MTARGP	/POINT TO CAL+2
	RTL
	RTL		/GET UNIT # IN BITS 15-17
	AND (7		/THROW AWAY JUNK.
	RAL		/UNIT NUMBER * 2.
	TAD (MTDSTB	/FIND ENTRY IN DRIVE STATUS TABLE.
	DAC MTTPTR	/SAVE LOCATION OF TABLE ENTRY WANTED.
	DAC MTTPT1	/AND LOCATION OF BUFFER POINTER.
	ISZ MTTPT1	/..
	LAC* MTDISP	/PICK UP CAL FUNCTION POINTER.
	SMA		/SKIP IF NOT .WAIT.
	JMP MTWAIT	/.WAIT OR .WAITR, DISPATCH NOW.
	LAC MTIOSW	/NOT .WAIT, CHECK IO UNDERWAY.
	SZA		/SKIP IF IO IS COMPLETE.
	JMP MTCALR	/IO INCOMPLETE, RETURN TO CAL.
	LAW 6		/SET UP ORIGINAL ERROR NUMBER.
	DAC MTERNO	/..
	JMS MTSTPT	/SETUP POINTERS TO VARIABLES FOR THIS CALL
	JMP* MTDISP	/GO TO FUNCTION
/POINTERS ARE:
/MTDEBP	POINTER TO FIRST WORD OF DEB (WORD 1 OF BUFFER)
/MTFNAM	POINTER TO HANDLER-CREATED FILE NAME (OUTPUT FILES) OR
/	  POINTER TO SWITCH FOR EOF ENCOUNTERED (INPUT FILES) (WORD 4)
/MTRECS	POINTER TO TOTAL BLOCKS IN FILE (WORD 5)
/MTWRDS	POINTER TO DATA-WORD COUNT (WORD 6)
/MTBCP1	POINTER TO BCP WORD 1 (WORD 7)
/MTBCP2	POINTER TO BCP WORD 2 (WORD 8)
/MTDATA	POINTER TO FIRST DATA WORD (WORD 9 OF BUFFER)
MTSTPT	0	/ENTRY TO SET UP POINTERS
	LAC* MTTPT1	/MTTPT1 POINTS TO FIRST WORD OF BUFFER ONLY IF MTGTBF HAS BEEN CALLED.
	DAC MTDEBP	/SAVE AS POINTER TO DEB.
	TAD MT.MED	/PLUS THREE.
	DAC MTFNAM	/GIVES POINTER TO FILE NAME OR EOF-ENCOUNTERED SWITCH.
	TAD (1		/AND SO ON.
	DAC MTRECS
	TAD (1
	AND (077777	/MASK OFF POSSIBLE M.S. BITS.
	DAC MTWRDS	/CURRENT ADDRESS WORD.
	LAC MTRECS	/RESTORE M.S.BITS.
	AND (700000
	XOR MTWRDS
	TAD (1
	DAC MTBCP1
	TAD (1
	DAC MTBCP2
	TAD (1
	DAC MTDATA
	JMP* MTSTPT
MTDISP	XX		/POINTER TO FUNCTION.
	JMP MTINIT	/ 1 -- INIT
	JMP MTOPER	/ 2 -- OPER (FSTAT, DLETE, RENAM)
	JMP MTSEEK	/ 3 -- SEEK
	JMP MTNTER	/ 4 -- ENTER
	JMP MTCLER	/ 5 -- CLEAR
	JMP MTCLOS	/ 6 -- CLOSE
	JMP MTMTAP	/ 7 -- MTAPE
	JMP MTREAD	/10 -- READ
	JMP MTWRIT	/11 -- WRITE
MT.MED	.MED		/12 -- WAIT, WAITR
	JMP MTTRAN	/13 -- TRAN
	.TITLE	.INIT
/INITIALIZE MAG TAPE UNIT.
/CALLING SEQUENCE:
/	CAL+DIRECTION(8)+DAT(9-17)
/	UNIT(0-2)+1
/	RESTART		/MTARGP POINTS HERE NOW.
/	BUFSIZ
/WHERE DIRECTION IS 0 FOR INPUT, 1 FOR OUTPUT.
MTINIT	ISZ MTARGP	/POINT TO BUFSIZ
	LAC MTBSIZ	/56(10).
	DAC* MTARGP	/UPDATE BUFSIZ.
	ISZ MTARGP	/POINT TO RETURN.
MTSETP	CAL+45		/CALL SETUP.
	16		/..
	MTSF		/MAG TAPE DONE OR ERROR FLAG.
	MTINT		/GO HERE ON INTERRUPTS.
	LAC .+2		/DON'T CALL .SETUP AGAIN.
	DAC MTSETP	/..
	JMP .+1		/..
MTLBH=MTSETP+1		/LINE BUFFER HEADER, WORD 0.
MTCOMD=MTLBH+1
MTSTAT=MTCOMD+1
	JMS MTRLBF	/GO RELEASE ANY BUFFER PREVIOUSLY ASSIGNED.
	LAC* (.SCOM+4	/7- OR 9-CHANNEL DEFAULT WANTED?
	AND MTWRTC	/EXTRACT 9-CHANNEL INDICATOR.
 
/(RCHM-005)
/ INITIALIZE THE CURRENT ENTRY IN THE MT STATUS TABLE. THE TABLE
/ WILL BE INITIALIZED TO 7 TRACK, 800 BPI, INT ON IF .SCOM+4 INDICATES
/ THAT A 7 TRACK TAPE IS MOUNTED. OTHERWISE IT WILL BE INITIALIZED TO
/ 9 TRACK, CORE DUMP MODE, 800 BPI, INT ON. DURING THIS PROCESS, THE
/ .INIT PERFORMED AND I/O MODE (INPUT-OUTPUT) WILL BE SET UP.
 
	RAR			/(RCHM-005) SHIFT THE 7/9 TRACK INDICATOR
	JMS	MTROT8		/(RCHM-005)  TO THE LINK.
				/(RCHM-005)  MUST SHIFT RIGHT ONCE TO FIX UP FOR
				/(RCHM-005)  8 LEFT SHIFTS.
	RTL			/(RCHM-005) ARGUMENT TO ROT8.
	LAC	(40602		/(RCHM-005) FETCH NEW MT STATUS WORD,
				/(RCHM-005)  7 CHANNEL, ODD PARITY, INT ON,
				/(RCHM-005)  .INIT PERFORMED.
	SNL			/(RCHM-108) 7 CHANNEL INDICATED IN .SCOM+4?
	XOR	(20100		/(RCHM-005) NO, TURN ON DUMP MODE AND 9 CHANNEL
				/(RCHM-005)  800 BPI (DENSITY BITS = 3).
 
/(RCHM-005)
/ THIS IS A MAGIC SET. THE BITS SPECIFIED IN THE FOLLOWING AND WILL
/ BE SET TO THE VALUES CONTAINED IN THE AC AT THIS POINT.
/
/ TRUTH TABLE FOR MAGIC BIT SET.
/
/	BIT0	BIT1	XOR1	AND	XOR2	CHANGE
/	0	0	0	0	0	NO CHANGE
/	0	1	1	1	0	CLEARED
/	1	0	1	1	1	SET
/	1	1	0	0	1	NO CHANGE
 
	XOR*	MTTPTR		/(RCHM-005) BEGIN THE SET UP OF
	AND	(60717		/(RCHM-005)  THE PARITY, COREDUMP,
	XOR*	MTTPTR		/(RCHM-005)  INTERRUPT, DENSITY, .INIT
				/(RCHM-005)  PERFORMED, AND I/O MODE BITS.
				/(RCHM-005) ALSO CLEAR THE FILE STRUCTURE AND
				/(RCHM-005) DECISION BITS.
	DAC*	MTTPTR		/(RCHM-005) SAVE THE NEWLY SET UP STATUS WORD.
 
/(RCHM-005)
/ AT THIS POINT THE I/O MODE INDICATES INPUT ONLY, FETCH REAL
/ I/O MODE FROM .INIT CAL.
 
	LAC*	MTCALP		/(RCHM-005) FETCH .INIT CALL
	AND	MTRWDC		/(RCHM-005) AC NOW CONTAINS I/O BIT (1=OUTPUT,
				/(RCHM-005)  0=INPUT).
	SZA!STL!CLA		/(RCHM-005) INPUT, LEAVE INDICATOR 0.
	RAL			/(RCHM-005) OUTPUT, STORE 1 IN AC.
	XOR*	MTTPTR		/(RCHM-005) SAVE I/O STATE IN STATUS TABLE.
/(RCHM-005) DELETE 21.
MTDBR0	DAC* MTTPTR	/TABLE ENTRY IS COMPLETE.
MTDBR	DBR		/ALL DONE, DEBREAK.
	XCT .+1
	JMP* MTARGP	/AND RETURN TO CALLER.
	.TITLE	.SEEK
  
  
/SEEK FILE ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	UNIT(0-2)+3
/	ADDRESS OF DEB	/MTARGP POINTS HERE NOW.
MTSEEK	JMS MTSTAL	/WAIT FOR TRANSPORT.
	LAC MTCALP
	DAC MTPC
	LAC MTNEXT	/FIRST TIME INTO SEEK?
	SZA		/YES, SKIP.
	JMP* MTNEXT	/NO, CONTINUE WITH OPERATION.
	LAC MTBFTB	/GET COUNT OF FILES CURRENTLY OPEN.
	SNA		/SKIP IF TWO OR FEWER.
	JMP MTER17	/THREE FILES ALREADY OPEN.
	LAC* MTTPTR	/PICK UP STATUS ENTRY FOR THIS TRANSPORT.
	AND	(777767	/SET FILE STRUCTURED SW
	TAD	(10
	DAC*	MTTPTR
	RTR		/INIT-PERFORMED TO LINK.
	CML		/AND COMPLEMENT TO CHECK.
	SZL!SPA!RTR	/SKIP IF INPUT AND INIT-PERFORMED.
	JMP MTERR7	/ERROR OTHERWISE.
/COME HERE WITH FILE-STRUCTURED-DECISION MADE (1=YES, 0=NO) IN SIGN
/AND FILE-STRUCTURED STATUS (1=YES, 0=NO) IN LINK.
	SMA!RAR		/SKIP IF A DECISION HAS BEEN MADE.
	JMP MTSK01	/NO DECISION MADE YET.
	SMA		/SKIP IF FILE-STRUCTURED.
	JMP MTERR7	/NON-FILE-STRUCTURED, ERROR.
/COME HERE WITH FILE-OPEN (1=YES, 0=NO) IN LINK.
MTSK01	SZL		/SKIP IF NO FILE OPEN.
	JMP MTER10	/FILE ALREADY OPEN, IOPS 10.
	JMS MTRDIR	/GO READ DIRECTORY.
	JMS MTMVNM	/MOVE FILE NAME TO DIRECTOR AREA.
	LAC* MTARGP	/MTARGP GIVES ADDRESS OF DEB TO MOVE.
	LAC* MTTPT1	/AND MTTPT1 GIVES PLACE TO MOVE IT TO.
MTSK06	JMS MTSRCH	/GO SEARCH DIRECTORY.
	SNA		/SKIP IF FILE WAS FOUND.
	JMP MTER13	/FILE NOT FOUND, IOPS 13.
/RETURN HERE WITH POSITIVE PHYSICAL FILE NUMBER (0-373 OCT) IN
/REGISTER MTACCM. SPACE FORWARD UNTIL PROPER NUMBER OF EOF'S
/HAVE BEEN PASSED.
	LAC* MTTPT1	/TURN OFF DIRECTORY-IN-CORE
	XOR MTXCT0	/  BY SETTING BIT 0 OF WORD 2 OF
	DAC* MTTPT1	/  MTDSTB ENTRY TO ZERO.
	LAC MTACCM	/PICK UP FILE NUMBER.
	CMA		/2'S COMP TOTAL EOF'S TO SKIP OVER (INCL THAT FOLLOWING DIRECTORY).
	DAC MTSKCT	/SAVE COUNT.
	DZM MTSKEF	/TURN OFF EOF-ENCOUNTERED.
MTSK05	LAW -1		/READ ONE RECORD.
	DAC* MTWCR	/SET WORD-COUNT REGISTER.
	LAC* MTTPTR	/SPACE FORWARD.
	TAD MTSPFC	/..
	JMS MTRDWR	/GO DO IT.
	JMP MTIOP4	/DRIVE UNAVAILABLE
	JMS MTNEXT	/WAIT FOR SETTLE-DOWN.
	LAC MTSTAT	/PICK UP STATUS FROM TRANSFER JUST COMPLETED.
	AND MTXIRG	/EOF PASSED?
	SNA		/SKIP IF SO.
	JMP MTSK05-1	/IF NOT CHECK NEXT RECORD.
	SAD MTSKEF	/WAS IMMEDIATELY PRECEDING RECORD ALSO AN EOF MARKER?
	JMP MTER44	/YES. UNEXPECTED LOGICAL EOT, IOPS 44.
	DAC MTSKEF	/NO. SET MTSKEF FOR CHECK OF NEXT RECORD.
	ISZ MTSKCT	/EOF ENCOUNTERED SO COUNT A FILE.
	JMP MTSK05	/MORE RECORDS TO SKIP OVER.
/WE ARE NOW POSITIONED TO READ FILE HEADER LABEL.
	LAC MTWRDS	/SET UP CURRENT ADDRESS (MTWRDS = BUFFER-1).
	DAC* MTCAR	/READ INTO BUFFER PROPER.
	LAW -33		/READ 27(10) WORDS.
	DAC* MTWCR	/..
	LAC* MTTPTR	/MAKE A READ COMMAND.
	TAD MTREDC	/..
	JMS MTRDWR	/GO ISSUE REQUEST FOR IO.
	JMP MTIOP4	/ILLEGAL RETURN. MEANS DRIVE NOT DIALED UP.
	JMS MTNEXT	/TRANSFER COMPLETE, WAIT FOR SETTLE-DOWN.
	DZM MTNEXT	/TERMINATE IO ACTIVITY CHAIN.
/PROCESS FILE HEADER LABEL.
	LAC* MTBCP1	/GET FIRST WORD OF BLOCK CONTROL PAIR.
	XOR (7745		/BI SHOULD BE 00, WORD COUNT SHOULD BE -33(8).
	SZA!CLA!CMA	/SKIP IF BCP WORD 1 FORMAT OK.
	JMP MTER40	/LABEL FORMAT ERROR, IOPS 40.
	XOR* MTDATA	/PICK UP FILE NAME FROM LABEL.
	XOR MTACCM	/COMPARE WITH FILE NAME BEING SEARCHED FOR.
	SZA		/SKIP IF THIS NAME IS THE ONE WANTED.
	JMP MTER40	/FILE NAME MISMATCH, IOPS 40.
	LAC (2
	DAC* MTWRDS
	DAC* MTEOFS	/INDICATE EOF NOT YET ENCOUNTERED.
/ALL SET AT LAST. CLEAN UP AND RETURN TO CALLER.
MTSK10	ISZ MTARGP	/BUMP TO RETURN PAST ARGUMENT LIST.
	LAC* MTTPTR	/PICK UP TABLE ENTRY FOR THIS UNIT.
	JMS MTIOR		/INDICATE A FILE IS NOW OPEN FOR READING
	AND (36		/  BY TURNING ON BITS 13-16.
	DAC* MTTPTR	/THEN UPDATE TABLE ENTRY.
	JMP MTDBR		/AND GO TO RETURN.
MTSKCT	0		/COUNT OF FILES TO SKIP OVER.
MTSKBF	0		/POINTER TO LABEL IMAGE.
MTSKEF	0
	.TITLE	.OPER
  
  
/EXECUTE SOME .OPER FUNCTION ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+CODE(7-8)+DAT(9-17)
/	UNIT(0-2)+2
/	ADDRESS OF DIRECTORY ENTRY BLOCK(S)
/WHERE CODE IS 1 FOR .DLETE, 2 FOR .RENAM, OR 3 FOR .FSTAT.
/OTHER CODES (0, 4-7) ARE ILLEGAL (IOPS 6).
MTOPER	JMS MTSTAL	/WAIT FOR DRIVE.
	LAC MTCALP	/SET TO HANG ON CAL UNTIL OPERATION IS COMPLETE.
	DAC MTPC		/..
	LAC MTNEXT	/IS THIS FIRST TIME INTO OPER SEQUENCE?
	SZA		/SKIP IF SO.
	JMP* MTNEXT	/IF NOT, START UP NEXT ACTIVITY IN SEQUENCE.
	LAC* MTCALP	/INTERPRET SUBFUNCTION CODE, PICK UP CAL.
	AND MTBSPC	/EXTRACT BITS 6-8.
	SNA!CLL!RAR	/SKIP IF CODE IS NON-ZERO.
	JMP MTERR6	/CODE .E. 0, IOPS 6.
	JMS MTROT8	/MOVE CODE TO 16-17.
	RTR		/..
	TAD MTMIN3	/CODE-3.
	SMA!SZA		/SKIP NEGATIVE OR ZERO.
	JMP MTERR6	/CODE .G. 3, IOPS 6.
	TAD (MTOPTB	/FORM SUBFUNCTION DISPATCH ADDRESS.
	DAC MTOPDS	/AND SAVE FOR LATER.
	LAC* MTTPTR	/PICK UP STATUS FOR THIS DRIVE.
	RTR		/PUT INIT-PERFORMED IN LINK, IO DIRECTION IN SIGN.
	SNL!RTR		/SKIP IF INIT WAS PERFORMED.
	JMP MTERR7	/NO INIT EXECUTED, IOPS 7.
	SMA!RAR		/SKIP IF DECISION AS TO FILE-STRUCTURING HAS BEEN MADE.
	JMP MTOP01	/NO DECISION.
	SMA		/SKIP IF FILE-STRUCTURED.
	JMP MTERR7	/NON-FILE-STRUCTURED, IOPS 7.
MTOP01	SZL		/SKIP IF NO FILE OPEN.
	JMP MTER10	/FILE IS OPEN, COMPLAIN.
	LAC* MTTPTR	/UPDATE ENTRY.
	JMS MTIOR		/..
	AND (14		/DECISION MADE AND FILE-STRUCTURED.
	DAC* MTTPTR	/ALL SET.
	JMS MTRDIR	/GO READ THE DIRECTORY FROM THIS TAPE.
	JMS MTMVNM	/MOVE DIRECTORY ENTRY BLOCK.
	LAC* MTARGP	/MOVE IT FROM ADDRESS GIVEN IN ARGUMENT LIST.
	LAC* MTTPT1	/TO THE TOP OF THE ASSIGNED BUFFER.
MTOP05	JMS MTSRCH	/GO SEARCH THE DIRECTORY.
	DAC MTOPFF	/AND SAVE FILE-FOUND INDICATOR (ZERO IF FILE NOT FOUND).
	XCT* MTOPDS	/DISPATCH TO SUBFUNCTION.
/.FSTAT PROCESSOR.
MTFSTA	LAC* MTARGP	/PICK UP CAL+2.
	AND (77777	/EXTRACT LOW-ORDER 15 BITS.
	TAD MTXCT0	/INSERT DIRECTORY TYPE (MTXCT0 = 400000).
	DAC* MTARGP	/PUT BACK IN ARGUMENT LIST.
	LAC MTOPFF	/WAS FILE FOUND DURING SEARCH?
	SZA!CLA!CMA	/SKIP IF NOT.
	LAC MTACCM	/FILE WAS FOUND, PICK UP FILE POSITION (0-373).
	TAD (1		/ENSURE NON-ZERO IF FOUND.
MTOPRT	ISZ MTARGP
	DZM MTNEXT
	JMP MTDBR
/RENAME PROCESSOR.
MTRNAM	LAC MTOPFF	/WAS FILE FOUND DURING DIRECTORY SEARCH?
	SNA		/SKIP IF SO.
	JMP MTOPRT	/IF NOT, RETURN WITH AC = 0.
	LAC (3		/FILE IS PRESENT, FORM A POINTER TO
	TAD* MTARGP	/  SECOND DEB GROUP.
	DAC MTRNPT	/AND SAVE IT.
	JMS MTMVNM	/NOW MOVE THE NAME FROM
	LAC MTRNPT	/  USER'S AREA TO
	LAC MTDIRP	/  FILE DIRECTORY, OVERLAYING OLD NAME IN DIRECTORY.
/NEW NAME HAS BEEN ADDED TO DIRECTORY.  NOW PUT THE UPDATED
/DIRECTORY ON THE TAPE.
MTOPRD	JMS MTWDIR	/CALL A SUBROUTINE TO WRITE THE FILE DIRECTORY.
	LAC MTACCM	/PICK UP PHYSICAL POSITION OF FILE REFERENCED.
	TAD (1		/BUMP BY ONE (POSITION COULD BE ZERO).
	JMP MTOPRT	/AND GO TO RETURN.
/DELETE PROCESSOR.
MTDLET	LAC MTOPFF	/WAS FILE FOUND DURING DIRECTORY SEARCH?
	SNA		/SKIP IF SO.
	JMP MTOPRT	/IF NOT, GO TO RETURN WITH AC .E. 0.
	JMS MTDLNM	/REMOVE NAME FROM DIRECTORY.
	JMP MTOPRD	/THEN RE-RECORD IT.
/OPER DISPATCH TABLE.
	JMP MTDLET
	JMP MTRNAM
MTOPTB	JMP MTFSTA
MTOPDS	0
MTRNPT=MTOPDS
MTOPFF	0		/FILE-FOUND INDICATOR.
MTRNCT=MTOPFF
	.TITLE	.ENTER
  
  
/ENTER FILE ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	UNIT(0-2)+4
/	ADDRESS OF DEB	/MTARGP POINTS HERE NOW.
MTNTER	JMS MTSTAL	/WAIT FOR UNIT TO FREE UP.
	LAC MTCALP
	DAC MTPC
	LAC MTNEXT	/IS THIS FIRST TIME INTO .ENTER SEQUENCE?
	SZA		/SKIP IF SO.
	JMP* MTNEXT	/NOT FIRST TIME IN, GO PERFORM NEXT TASK.
	LAC MTBFTB	/FIRST TIME IN, PICK UP TOTAL OPEN FILES.
	SNA		/SKIP IF 2 OR FEWER FILES CURRENTLY OPEN.
	JMP MTER17	/THREE FILES OPEN, COMPLAIN.
	LAC* MTTPTR	/PICK UP ENTRY FROM DRIVE STATUS TABLE.
	AND	(777767	/SET FILE STRUCTURED BIT
	TAD	(10
	DAC*	MTTPTR
	RTR		/PUT INIT-PERFORMED BIT IN LINK.
	CMA!CML		/INVERT SIGN AND LINK TO CHECK INIT AND DIRECTION.
	SZL!SPA!RTR	/SKIP IF OUTPUT AND INIT PERFORMED.
	JMP MTERR7	/DRIVE IS INPUT OR NO INIT EXECUTED, COMPLAIN.
/COME HERE WITH INVERSE OF FILE-STRUCTURED-DECISION-MADE IN SIGN, AND
/INVERSE OF FILE-STRUCTURED-STATUS IN LINK.
	SPA!RAR		/SKIP IF A DECISION HAS BEEN MADE.
	JMP MTNT01	/NO DECISION MADE.
	SPA		/NOW CHECK FILE-STRUCTURE STATUS. SKIP IF SO.
	JMP MTERR7	/NON-FILE-STRUCTURED, ERROR.
/COME HERE WITH INVERSE OF FILE-OPEN IN LINK (0=YES, 1=NO).
MTNT01	SNL		/SKIP IF NO FILE IS OPEN ON THIS DRIVE.
	JMP MTER10	/FILE IS OPEN, PUBLISH ERROR.
	JMS MTRDIR
	JMS MTMVNM
	LAC* MTARGP
	LAC* MTTPT1
MTNT10	LAC* MTDATA	/PICK UP COUNTS.
	AND (777		/EXTRACT ACTIVE.
	TAD (120		/ENSURE FEWER THAN 80(10).
	SPA		/POSITIVE AND NON-ZERO, OK.
	JMP MTER14	/DIRECTORY FULL, IOPS 14.
	LAC* MTDATA	/GET ACTIVE COUNT AGAIN.
	CMA		/MAKE POSITIVE.
	AND (777		/..
	SNA		/ENSURE SOME FILES PHYSICALLY PRESENT.
	JMP MTNT08	/EMPTY TAPE.
	TAD MTMIN1
	JMS MTEXBM	/FIND PHYSICAL FILE NO. OF LAST ACTIVE FILE.
/RETURN FROM MTEXBM WITH AC = 0-373(8).
	SAD (373		/LAST ACTIVE .E. LAST PHYSICAL?
	JMP MTER42	/MAP OVERFLOW, IOPS 42.
	ADD (1
MTNT08	CMA
	DAC MTNTOT	/SAVE NEW FILE NAME.
	DAC MTOTL2	/AND COUNT OF EOF'S TO SKIP OVER.
/NOW POSITION AFTER LAST ACTIVE FILE.
MTNT05	DZM MTETSW
MTNT06	LAW -1
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTSPFC
	JMS MTRDWR
	JMP MTIOP4
	JMS MTNEXT
	LAC MTSTAT
	AND MTXIRG
	SNA
	JMP MTNT05
	SAD MTETSW
	JMP MTER44	/EOT ENCOUNTERED, IOPS 44.
	DAC MTETSW
	ISZ MTOTL2	/COUNT THIS EOF MARKER.
	JMP MTNT06	/MORE FILES TO SPACE OVER.
	DZM MTNEXT
	LAC MTNTOT
	DAC* MTFNAM
	LAC* MTTPTR
	JMS MTIOR
	AND (77
	XOR (40		/TURN OFF HEADER-LABEL-WRITTEN.
	DAC* MTTPTR
MTMIN1	LAW -1
	DAC MTOFLO
	LAC* MTTPT1
	AND MTXCT0
	XOR* MTTPT1
	DAC* MTTPT1
	ISZ MTARGP
	JMP MTDBR
MTNTPT	0
MTETSW=MTNTPT
MTNTOT	0
MTOTL2	0
	.TITLE	.CLEAR
  
  
/EXECUTE CLEAR ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	UNIT(0-2)+5
/	RETURN		/MTARGP POINTS TO RETURN ON ENTRY.
MTCLER	JMS MTSTAL	/WAIT FOR TRANSPORT.
	LAC MTCALP
	DAC MTPC
	LAC MTNEXT	/ARE WE INTO CLEAR SEQUENCE ALREADY?
	SZA		/SKIP IF NOT.
	JMP* MTNEXT	/IF SO, GO TO NEXT CLEAR OPERATION.
	LAC* MTTPTR	/PICK UP DRIVE STATUS.
	RTR		/PUT IO DIRECTION IN SIGN, INIT-PERFORMED IN LINK.
	CMA!CML		/AND INVERT TO CHECK.
	SZL!SPA!RAR	/SKIP IF OUTPUT AND INIT PERFORMED.
	JMP MTERR7	/INPUT TAPE OR NO INIT PERFORMED, IOPS 7.
	SNL!RTR		/SKIP IF NO FILE IS OPEN ON THIS DRIVE.
	JMP MTER10	/FILE ALREADY OPEN, IOPS 10.
	SPA		/SKIP IF A DECISION HAS BEEN MADE.
	JMP .+3		/NO DECISION MADE, GO MAKE ONE.
	SZL		/DECISION MADE, SKIP IF FILE-STRUCTURED.
	JMP MTDBR		/NON-FILE-STRUCTURED, IGNORE REQUEST.
	LAC* MTTPTR	/PICK UP DRIVE.
	JMS MTIOR
	AND (14
	DAC* MTTPTR
/UNIT TO BE CLEARED IS AN OUTPUT TRANSPORT WITH NO FILES OPEN.
/NOW REWIND AND WRITE EMPTY FILE DIRECTORY.
	TAD MTRWDC
	JMS MTRDWR
	SKP!RTL
	JMP MTCDIR
	SMA
	JMP MTIOP4
MTCDIR	JMS MTNEXT
	JMS MTWREF	/GO WRITE AN EOF MARKER ON THE TAPE.
	LAC (MTNDIR-1
	DAC* MTCAR
	LAW -401
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTWRTC
	JMS MTRDWR
	JMP MTIOP4
	SPA
	JMP MTIOP4
	JMS MTNEXT	/GO WAIT FOR DRIVE TO SETTLE DOWN.
	JMS MTWREF	/WRITE TWO EOF MARKERS TO
	JMS MTWREF	/  INDICATE LOGICAL END-OF-TAPE.
	JMS MTBACK	/THEN BACKSPACE ONE.
	JMS MTNEXT		/(RCHM-006) PERFORM IMPLIED WAIT FOR COMPLETION.
	DZM MTNEXT
	LAC* MTTPT1
	AND MTXCT0
	XOR* MTTPT1
	DAC* MTTPT1
	JMP MTDBR
MTNDIR	747377
	0
	777777
MTIOP4	LAC MTCALP
	DAC* MT.MED
	LAC (4		/IOPS 4 INDICATOR.
	JMP MTERXT	/GO TO IOPS ERROR EXIT.
	.TITLE	.CLOSE
  
  
/EXECUTE CLOSE ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	UNIT(0-2)+6
MTCLOS	JMS MTSTAL	/WAIT FOR IO TO COMPLETE.
	LAC MTCALP	/SETUP RETURN ADDRESS
	DAC MTPC
	LAC MTNEXT
	SZA
	JMP* MTNEXT
	LAC* MTTPTR
	RTR
	CMA!CML
	SZL!SPA!RTR	/SKIP IF OUTPUT AND INIT PERFORMED.
	JMP MTCLS3	/NO INIT OR INPUT DRIVE, IGNORE CLOSE REQUEST.
	SPA!RAR		/SKIP IF A DECISION WAS MADE.
	JMP MTCLS3	/NO DECISION, IGNORE CLOSE.
	SPA!RAR		/SKIP IF FILE-STRUCTURED.
	JMP MTCLS1	/NON-FILE-STRUCTURED, JUST WRITE SOME EOF'S.
	SZL!SPA		/SKIP IF FILE IS OPEN AND SOMETHING WRITTEN INTO IT.
	JMP MTCLS3	/NO FILE OPEN OR NOTHING WRITTEN, IGNORE.
/SOMETHING IN FILE, CHECK FOR OUTPUT BUFFER PARTLY FULL.
	LAC* MTWRDS	/PICK UP CURRENT LENGTH.
	SZA		/SKIP IF BUFFER EMPTY.
	JMS MTWRBF	/BUFFER NON-EMPTY, GO WRITE IT OUT.
MTCLS1	JMS MTWREF	/WRITE TWO EOF MARKERS TO CLOSE OUT
	JMS MTWREF	/  THE PHYSICAL DATA AREA.
	JMS MTBACK	/THEN POSITION BETWEEN THE TWO EOF'S JUST WRITTEN.
	JMS MTNEXT		/(RCHM-006) PERFORM IMPLIED WAIT FOR COMPLETION.
/THEN SEE IF THIS DRIVE IS FILE-STRUCTURED.
	LAC* MTTPTR	/PICK UP DRIVE STATUS
	AND (10		/   AND EXTRACT FILE-STRUCTURED INDICATOR.
	SNA		/SKIP IF THIS DRIVE IS FILE-STRUCTURED.
	JMP MTCLS3	/NON-FILE-STRUCTURED, ALL DONE.
/DRIVE IS FILE-STRUCTURED, READ IN THE DIRECTORY.
MTCLS4	JMS MTRDIR	/MTRDIR WILL READ IT FOR US.
	JMS MTSRCH	/SEE IF NAME OF FILE BEING CLOSED APPEARS THERE.
	SZA		/SKIP IF NAME IS NOT ALREADY PRESENT.
	JMS MTDLNM	/DUPLICATE FILE NAME FOUND, GO DELETE OLD ENTRY.
	LAC MTCACT
	DAC MTCLSX
	TAD MTMIN1
	DAC MTCACT
	LAC* MTFNAM
	CMA
	JMS MTCLRB
	XOR MTCLCT
	LAW -1
	TAD* MTFNAM
	DAC MTCTOT
	LAC MTCLSX
	CMA
	DAC MTCLSX
	CLL!RAL
	TAD MTCLSX
	TAD (MTREGS+21
	TAD* MTTPT1
	DAC MTCLSY
	JMS MTMVNM
	LAC* MTTPT1
	LAC MTCLSY
/NOW UPDATE FILE COUNTS.
	LAC MTCTOT	/PICK UP NEW TOTAL COUNT.
	JMS MTROT8	/MOVE TO BITS 0-9.
	RTL		/..
	RAL		/..
	AND MTL777	/THROW AWAY LOW-ORDER JUNK.
	DAC MTCLSX	/AND SAVE NEW TOTAL COUNT.
	LAC MTCACT
	AND (777
	TAD MTCLSX
	DAC* MTDATA
/FILE COUNTS ALL SET. RE-RECORD.
	JMS MTWDIR
	LAC MTOFLO
	SMA
	JMP MTER15
MTCLS3	LAW 17717
	AND* MTTPTR
	DAC* MTTPTR
	JMS MTRLBF	/GO RELEASE BUFFER ASSIGNED TO THIS DRIVE.
	DZM MTNEXT
	JMP MTDBR
MTCLSX	0
MTCLSY	0
MTCLSA	0
MTCLE1	JMP MTIOP4
	.TITLE	.MTAPE
  
  
/EXECUTE MTAPE COMMAND.
/CALLING SEQUENCE:
/	CAL+SUBFUNCTION(5-8)+DAT(9-17)
/	UNIT(0-2)+7
/WHERE SUBFUNCTION IS:
/0-7:	MANIPULATIVE REQUEST.
/10-17:	PARITY/DENSITY/TRACK-COUNT SETTING.
MTMTAP	JMS MTSTAL	/WAIT FOR DRIVE TO FREE UP.
	LAC* MTCALP	/PICK UP THE CAL.
	JMS MTROT8	/MOVE THE SUBFUNCTION CODE TO 14-17.
	RTR		/..
	RAR		/..
	AND (17
	TAD (MTAPDS+1	/START OF SUBFUNCTION DISPATCH TABLE.
	DAC MTAPDS	/SAVE DISPATCH ADDRESS.
	LAC MTARGP
	DAC MTPC
	LAC* MTAPDS	/PICK UP MTAPE FUNCTION.
	SPA		/SKIP IF FUNCTION 10-17.
	XCT* MTAPDS	/JMP TO FUNCTIONS 0-7.
	LAC* MTTPTR	/10-17, PICK UP CURRENT ENTRY IN MTDSTB.
	AND	(717477		/(RCHM-005) CLEAR OUT PREVIOUS FORMAT BITS, INCLUDING
				/(RCHM-005)  DUMP MODE BIT.
	TAD* MTAPDS	/INSERT NEW VALUES.
	JMP MTDBR0	/UPDATE TABLE & RETURN
  
/MTAPE FUNCTION DISPATCH TABLE.
MTAPDS	XX		/POINTER TO TABLE ENTRY.
MTDFLT=MTAPDS		/CHANNEL DEFAULT INDICATOR.
/GROUP I -- MANIPULATIVE REQUESTS.
	JMP MTRWDF	/00 -- REWIND
MTSKIP	SKP		/01 -- UNDEFINED
	JMP MTBSPF	/02 -- BACKSPACE
	JMP MTERR6	/03 -- BACKSPACE FILE
	JMP MTWEOF	/04 -- WRITE EOF
	JMP MTFSPF	/05 -- SPACE FORWARD
	JMP MTERR6	/06 -- SPACE FORWARD FILE
	JMP MTERR6	/07 -- SPACE TO EOT
/GROUP II -- FORMAT DIRECTIVES.
MTZERO	0		/EVEN, 200 BPI, 7-CHANNEL.
	100		/EVEN, 556 BPI, 7-CHANNEL.
MTL200	200		/EVEN, 800 BPI, 7-CHANNEL.
MTL300	20300		/(RCHM-005) EVEN PARITY, CORE DUMP, 9-CHANNEL DINSITY.
MTPAR	40000		/ODD,  200 BPI, 7-CHANNEL.
	40100		/ODD,  556 BPI, 7-CHANNEL.
MTSTND	40200		/ODD,  800 BPI, 7-CHANNEL.
MTFORM	60300		/(RCHM-005) ODD PARITY, DUMP MODE, 9-CHANNEL DENSITY.
  
  
  
/COME HERE TO PERFORM MTAPE BACKSPACE (MTAPE 02).
MTBSPF	LAW -1		/SET UP WORD COUNT.
	DAC* MTWCR	/ONE RECORD TO BACKSPACE.
	MTRS		/GET STATUS FOR THIS UNIT.
	DAC MTSTAT	/SAVE STATUS FOR CALLER AT NEXT .WAIT.
	RTL		/MOVE BOT TO SIGN.
	SPA		/SKIP IF NOT BOT.
	JMP MTDBR		/BOT, IGNORE REQUEST.
	LAC MTBSPC	/BACKSPACE COMMAND.
	TAD* MTTPTR	/PLUS THIS UNIT.
	JMS MTRDWR	/GO DO IT.
MTRWD1	SKP!RTL		/ILLEGAL
	JMP MTRET1	/ALL DONE.
	SPA		/SKIP IF NOT BOT.
	JMP MTRET1	/BOT, RETURN.
	JMP MTIOP4	/NOT BOT, PUBLISH IOPS 4.
/COME HERE TO REWIND (MTAPE 00).
MTRWDF	LAC (MTRWD1
	DAC MTRDWR
	LAC MTRWDC
	TAD* MTTPTR
	JMP MTRDWR+2	/DONT TURN ON MTIOSW.
/COME HERE TO SPACE FORWARD ONE RECORD (MTAPE 05).
MTFSPF	LAC* MTTPTR	/GET STATUS FOR THIS UNIT.
	RTR		/MAKE SURE UNIT IS INPUT.
	SNL!CLA!CMA
	JMP MTERR6	/ERROR OTHERWISE.
	DAC* MTWCR	/WC=1.
	LAC MTSPFC	/SPACE FORWARD COMMAND.
	TAD* MTTPTR	/PLUS UNIT.
	JMS MTRDWR	/GO DO IT.
	JMP MTIOP4	/DRIVE NOT AVAILABLE.
	SMA		/SKIP IF ERROR.
	JMP MTRET1	/NO ERROR, RETURN.
	AND MTWRTC	/EXTRACT EOT BIT.
	SNA		/SKIP IF EOT.
	JMP MTRET1	/IGNORE OTHER ERRORS.
	JMP MTER12
/COME HERE TO WRITE A TAPE MARK (MTAPE 04).
MTWEOF	LAC*	MTTPTR		/(RCHM-005) FETCH SKELETON MT COMMAND.
	AND	(40000		/(RCHM-005) MAKE SURE IT WILL BE EVEN PARITY.
	XOR*	MTTPTR		/(RCHM-005) CLEAR PARITY BIT.
	TAD MTWEFC	/INSERT WRITE EOF COMMAND.
	JMS MTRDWR	/THEN GO START UP IO.
	JMP MTIOP4	/DRIVE NOT AVAILABLE.
	JMP MTRET1	/IGNORE ERRORS FOR NOW.
	.TITLE	.READ
  
  
/READ MAG TAPE.
/CALLING SEQUENCE:
/	CAL+MODE(6-8)+DAT(9-17)
/	UNIT (0-2) +10
/	LINE BUFFER ADDRESS
/	WORD COUNT MAX
MTREAD	JMS MTSTAL
	LAC MTCALP
	DAC MTPC
	LAC MTNEXT
	SZA
	JMP* MTNEXT
MTRDZR	DZM MTFSIN
	LAC* MTTPTR
	RTR
	CML
	SPA!SZL!RTR	/INPUT AND INIT PERFORMED.
	JMP MTERR7
	CMA!CML
	SMA!SNL!RTR	/NO DECISION OR NFS
	JMP MTRD01	/FILE-STRUCTURED READ.
	LAC* MTTPTR
	JMS MTIOR
	AND (26
	DAC* MTTPTR
	JMP MTRMOC
/COME HERE WITH INVERSE OF FILE-OPEN (0=YES, 1=NO) IN SIGN.
MTRD01	SPA
	JMP MTER11	/.ENTER NOT EXECUTED, IOPS 11.
	ISZ MTFSIN
/COME HERE TO CALCULATE MODE SERVICER ADDRESS.
MTRMOC	JMS MTCALM
	TAD (MTRMOD+1
	DAC MTRMOD
	LAC* MTARGP
	DAC MTLBH
	DAC MTRDP4
	AND (700000)		/(RCHM-106) EXTRACT EXTENDED MEMORY BITS.
	SZA			/(RCHM-106) ARE ANY OF THEM ON?
	JMP MTER67		/(RCHM-106) YES, GO PRINT ERROR MESSAGE.
	ISZ MTARGP
	JMP* MTRMOD
MTRMOD	0
	JMP MTERR7	/READ IOPS NFS
	JMP MTERR7	/READ DUMP NFS
	JMP MTERR7	/READ 9-CHANNEL NFS
	JMP MTRIFS	/READ IOPS FILE-STRUCTURED
	JMP MTRDPF	/READ DUMP FILE-STRUCTURED.
	JMP MTERR7	/READ 9-CHANNEL (MODE 5) FILE-STRUCTURED (ILLEGAL).
/*****  NOTE THAT MODE 5 READ MUST TURN OFF CORE-DUMP INDICATOR
/	IN DRIVE STATUS TABLE ENTRY FOR REFERENCED DRIVE.
/FILE-STRUCTURED DUMP MODE INPUT PROCESSOR.
MTRDPF	NOP		/ENTER ONE-TIME SECTION; SAVE WORD COUNT AND BUFFER ADDRESS.
	LAC	(JMP MTRDNX
	DAC MTRDPF	/JUMP AROUND THIS SECTION NEXT TIME.
	LAC* MTARGP	/PICK UP WORD COUNT.
	DAC MTRDC1	/AND SAVE AS TOTAL WORDS TO DELIVER.
	LAC MTLBH		/PICK UP BUFFER ADDRESS.
	DAC MTRPT4	/USE THAT AS POINTER TO INPUT AREA.
	LAC MTRDC1		/(RCHM-106) FETCH WORD COUNT FOR DUMP TRANSFER.
	CMA!IAC			/(RCHM-106) CONVERT TO POSITIVE NUMBER.
	TAD MTLBH		/(RCHM-106) ADD IN BUFFER START.
	AND (700000)		/(RCHM-106) EXTRACT EXTENDED MEMORY BITS.
	SZA			/(RCHM-106) ARE ANY OF THEM ON?
	JMP MTER67		/(RCHM-106) YES, GO PRINT ERROR MESSAGE.
/LOOP TO MOVE WORDS FROM BUFFER TO LINE UNTIL COUNT IS SATISFIED;
/REFILL EMPTY BUFFER IF MORE DATA NEEDED.
MTRDNX	LAC* MTEOFS	/EOF ENCOUNTERED?
	SNA		/SKIP IF NOT.
	JMS	MTEOFP	/EOF. RETURN CODE IN BUFFER
MTRDS1	LAC* MTBCP1	/PICK UP TWO'S COMPLEMENT RECORD LENGTH.
	TAD* MTWRDS	/PLUS WORDS TRANSFERRED SO FAR.
	SMA		/SKIP IF BUFFER IS NOT YET EMPTY.
	JMP MTRFIL	/BUFFER IS EMPTY, GO REFILL IT.
	LAC* MTWRDS	/GET TOTAL WORDS ALREADY TAKEN FROM BUFFER.
	TAD MTBCP1	/FORM ADDRESS OF NEXT WORD TO PICK UP.
	DAC MTRPT2	/AND SAVE AS INPUT POINTER.
	LAC* MTRPT2	/GET NEXT WORD FROM INPUT BUFFER.
	DAC* MTRPT4	/GIVE TO CALLER.
	ISZ MTRPT4	/BUMP OUTPUT POINTER.
	ISZ* MTWRDS	/AND WORDS MOVED FROM THIS BUFFER LOAD.
	ISZ MTRDC1	/COUNT TOTAL WORDS REQUESTED; SKIP IF ALL DONE.
	JMP	MTRDS1	/MORE TO DO.
	LAC MTNOP		/ALL FINISHED, RESTORE ONE-TIME SWITCH.
	DAC MTRDPF	/..
	JMP MTOPRT	/AND RETURN TO CALLER.
/IF UNIT IS FILE-STRUCTURED, IOPS ASCII AND BINARY; IMAGE ALPHA AND
/BINARY COME HERE.
MTRIFS	LAC* MTEOFS	/PICK UP EOF INDICATOR.
	SNA		/SKIP IF END-OF-FILE DID NOT OCCUR
	JMS MTEOFP	/THERE WAS AN EOF IN LATEST PHYSICAL TRANSFER.
MTRIF1	LAC* MTBCP1	/PICK UP CURRENT COUNT OF WORDS IN RECORD.
	TAD* MTWRDS	/LESS TOTAL WORDS ALREADY READ.
	SMA		/SKIP IF SOME WORDS LEFT IN BUFFER.
	JMP MTRFIL	/BUFFER IS EMPTY, GO REFILL IT.
	LAC MTBCP1	/FIND FIRST DATA WORD.
	TAD* MTWRDS	/PLUS WORDS READ SO FAR.
	DAC MTRDP3	/GIVES POSITION OF FIRST WORD OF NEXT LINE.
	LAC* MTRDP3	/PICK UP LINE HEADER.
	JMS MTROT8	/MOVE WORD-PAIR COUNT TO LOW-ORDER.
	RTR		/  PART OF WORD.
	AND (776		/THROW AWAY JUNK.
	SNA!CMA		/ENSURE NON-ZERO LENGTH.
	JMP MTRIF2	/ILLEGAL WORD-PAIR COUNT (WPC = 0), IOPS 23./REFILL BUFFER
	DAC MTRCT1	/SAVE COUNT FROM INPUT LINE.
	ISZ MTRCT1	/MAKE A TWO'S COMPLEMENT COUNT.
	LAC* MTARGP	/PICK UP MAX COUNT FROM CALLING SEQUENCE.
	DAC MTRCT2	/AND SAVE IT.
	ISZ MTARGP	/BUMP TO RETURN AFTER CAL SEQUENCE.
MTRLP1	LAC* MTRDP3	/PICK UP NEXT WORD.
	DAC* MTRDP4	/PUT IN CALLER'S AREA.
	ISZ MTRDP3	/BUMP INPUT ADDRESS.
	ISZ MTRDP4
	ISZ* MTWRDS	/UPDATE TOTAL WORDS MOVED.
	ISZ MTRCT2	/BUMP MAX WDS
	SKP
	JMP MTROFL	/OVERFLOWED USER'S AREA.
MTRLP2	ISZ MTRCT1
	JMP MTRLP1
/ALL DONE, RETURN.
	LAC MTRDP3	/DID OVERFLOW OCCUR?
	SAD MTRDP4	/SKIP IF NOT
	JMP MTRLP3
MTRLP4	LAC* MTTPT1
	AND MTLAC0
	SNA
	JMP MTDBR
	LAC* MTLBH
	AND (60
	XOR* MTLBH
	TAD (20
	DAC* MTLBH
	JMP MTDBR
MTRLP3	LAC* MTLBH
	JMS MTIOR
	AND (60
	DAC* MTLBH
	JMP MTRLP4
MTROFL	LAW -1
	SAD MTRCT1
	JMP MTRLP2
	DAC MTRCT2
	LAC MTRDP3
	DAC MTRDP4
	JMP MTRLP2
/IF WE ARE READING A FILR WRITTEN IN DUMP MODE THEN WE MUST HAVE
/REACHED THE END OF BUFFER. SO WEMUST REFILL. ELSE PUBLISH IOPS23
MTRIF2	LAC*	MTBCP2	/BLOCK CHECKSUM=0 FOR FILES WRITTEN IN DUMP MODE
	SZA
	JMP	MTER23
/COME HERE TO REFILL INPUT BUFFER.
MTRFIL	LAW -401
	DAC* MTWCR
	LAC MTWRDS
	DAC* MTCAR
	LAC MTCALP
	DAC MTPC
	LAC* MTTPTR
	TAD MTREDC
	JMS MTRDWR
	JMP MTIOP4
	JMS MTNEXT
	LAC MTBCP1
	DAC MTRFP1
	LAC MTSTAT
	AND MTXIRG
	SZA!CLA		/SKIP IF NOT EOF.
	JMP MTPTEF	/EOF, SET UP INDICATOR (AC = 0 NOW).
	LAC MTSTAT	/PICK UP STATUS.
	AND (020600	/EXTRACT PARITY, BAD TAPE, DATA LATE.
	SZA!CLL!CML	/SKIP IF NOT PARITY, BAD TAPE, DATA LATE.
	JMP MTRAGN	/REAL READ ERROR, GO TRY TO READ AGAIN.
	LAC MTSTAT	/GET STATUS AGAIN.
	AND MTWRTC	/EXTRACT EOT.
	SZA!CLA!RAL	/NOT EOT, SKIP.
	JMP MTPTEF	/EOT, GO SET THAT UP (AC = 1 NOW).
	LAC MTSTAT	/STATUS AGAIN.
	AND MTRWDC	/GET RECORD-LENGTH-INCORRECT.
	SZA		/SKIP IF RECORD LENGTH IS OK.
	JMP MTRLI		/SHORT OR LONG RECORD.
MTCKB0	LAC* MTTPT1	/INDICATE NO READ ERRORS IN THIS BLOCK.
	AND MTLAC0	/..
	XOR* MTTPT1	/BY TURNING OFF BIT 1.
	DAC* MTTPT1	/..
MTCKBL	LAC* MTRFP1	/TRANSFER IS OK, PICK UP BCP WORD 1.
	AND (770000	/EXTRACT BI.
	XOR MTLAC0	/IS THIS A USER-FILE DATA BLOCK?
	SZA!CLA		/SKIP IF SO.
	JMP MTPTEF	/IF NOT, GO TREAT JUST LIKE EOF.
	LAC MTLAC0	/USER DATA RECORD, SET UP COUNT.
	XOR* MTRFP1	/TURN OFF BIT 1.
	TAD (770000	/SET BITS 0-5.
	DAC* MTRFP1	/UPDATE COUNT.
	LAC (2		/INDICATE TWO WORDS ALREADY TRANSFERRED
	DAC* MTWRDS	/  SO THAT BCP WILL BE SKIPPED OVER.
MTRRT	DZM MTNEXT	/TURN OFF OPERATIONS IN PROGRESS.
	LAW -24		/SET UP ERROR-REREAD COUNT.
	DAC MTERCT	/FOR NEXT TIME.
	JMP MTCALR	/THEN GO REPROCESS THIS READ.
/COME HERE ON EOF OR EOT ENCOUNTERED.
MTPTEF	ISZ MTRFP1	/POINT TO BCP WORD 2.
	ISZ MTRFP1	/THEN TO FIRST DATA WORD.
	TAD (1005		/MAKES EOF OR EOT HEADER.
	DAC* MTRFP1	/PUT IN HANDLER BUFFER.
	ISZ MTRFP1	/POINT TO LINE CHECKSUM.
	CMA		/FORM ONE'S COMPLEMENT CHECKSUM.
	DAC* MTRFP1	/SAVE CHECKSUM.
	ISZ* MTRFP1	/AND MAKE TWO'S COMPLEMENT.
	DZM* MTEOFS	/INDICATE EOF OR EOT ENCOUNTERED.
	JMP MTRRT		/AND GO BACK.
MTEOFP	0
	LAW	-4
	DAC* MTBCP1
	TAD	(2
	DAC	MTRDC1
	LAC (2
	DAC* MTWRDS
	JMP*	MTEOFP
/COME HERE ON INPUT RECORD LENGTH INCORRECT.
MTRLI	LAC* MTWCR	/PICK UP WORD COUNT.
	SZA		/SKIP IF LONG RECORD.
	JMP MTCKB0	/SHORT RECORD, OK.
	JMP MTER45	/LONG INPUT RECORD, IOPS 45.
/COME HERE TO SET UP REREAD. FIRST, BACKSPACE OVER ERROR RECORD.
MTRAGN	ISZ MTERCT	/HAVE WE ALREADY READ 20 TIMES?
	SKP		/SKIP IF MORE REREADS REQUIRED.
	JMP MTIREC	/TOO MANY READ ERRORS.
MTRAG1	LAW -1		/BACKSPACE ONE.
	DAC* MTWCR	/..
	LAC* MTTPTR	/BUILD BACKSPACE COMMAND.
	TAD MTBSPC	/..
	JMS MTRDWR	/GO ISSUE BACKSPACE.
	JMP MTRD04	/DRIVE UNAVAILABLE.
	JMS MTNEXT	/WAIT FOR TRANSPORT.
	JMP MTRFIL	/THEN REREAD ERROR RECORD.
/PERMANENT READ ERROR COMES HERE.
MTIREC	LAC* MTTPT1	/INDICATE IRRECOVERABLE ERROR.
	JMS MTIOR		/BY TURNING ON BIT 1.
	AND MTLAC0	/BIT 1 MEANS READ ERROR ON CURRENT RECORD.
	DAC* MTTPT1	/..
	JMP MTCKBL	/ACCEPT RECORD AS IS.
MTRD04	LAC (MTRAG1
	JMP MTIOP4+1
MTERCT	LAW -24		/READS 20 TIMES BEFORE GIVING UP.
MTRDP3	0	/INPUT POINTER.
MTRCT1	0	/COUNT OF WORDS TO MOVE.
MTRDP4	0	/OUTPUT POINTER.
MTRCT2	0	/MAX WORDS TO READ.
MTRFP1	0
MTRDC1	0
MTRPT2	0
MTRPT4	0
	.EJECT
MTER67	LAW 50			/(RCHM-106) PICK UP PRECURSOR OF MESSAGE.
	JMP MTERRX		/(RCHM-106) GO SET UP REAL MESSAGE NUMBER.
MTER65	LAW 46
	JMP MTERRX
MTER23	LAW 4		/ILLEGAL WORD PAIR COUNT.
	JMP MTERRX
MTER47	ISZ MTERNO
MTER46	ISZ MTERNO	/ATTEMPT TO DELETE FILE WITH EXT "SYS".
MTER45	ISZ MTERNO	/LONG INPUT RECORD.
MTER44	ISZ MTERNO	/UNEXPECTED LOGICAL EOT FOUND ON SEEK/ENTER.
MTER43	ISZ MTERNO	/DIRECTORY RECORDING ERROR.
MTER42	ISZ MTERNO	/ACCESSIBILITY MAP OVERFLOW.
MTER41	ISZ MTERNO	/DIRECTORY FORMAT ERROR.
MTER40	LAW 21		/HEADER LABEL ERROR.
MTERRX	TAD MTERNO	/IOPS 20-37 UNUSED.
	DAC MTERNO
MTER17	ISZ MTERNO	/TOO MANY FILES.
MTER16	ISZ MTERNO	/OUTPUT BUFFER OVERFLOW.
MTER15	ISZ MTERNO	/PHYSICAL EOT FOUND ON WRITE.
MTER14	ISZ MTERNO	/DIRECTORY FULL.
MTER13	ISZ MTERNO	/FILE NOT FOUND ON SEEK.
MTER12	ISZ MTERNO	/EOT ENCOUNTERED ON SPACE FORWARD.
MTER11	ISZ MTERNO	/SEEK-ENTER NOT EXECUTED.
MTER10	ISZ MTERNO	/FILE STILL ACTIVE.
MTERR7	ISZ MTERNO	/ILLEGAL DATA MODE.
MTERR6	LAC MTCALP	/ILLEGAL FUNCTION.
	DAC* MT.MED	/CAL ADDRESS TO MED.
	LAC MTERNO	/PICK UP ERROR NUMBER.
MTERXT	DZM MTIOSW	/TURN OFF IO UNDERWAY.
	DZM MTNEXT	/AND IO SEQUENCER.
	JMP* (4		/GO TO .MED + 1.
MTERNO	LAW 6		/SET UP BY CAL PROCESSOR.
	.TITLE	.WRITE
  
  
/WRITE MAG TAPE.
/CALLING SEQUENCE:
/	CAL+MODE(6-8)+DAT(9-17)
/	UNIT(0-2)+11
/	LINE BUFFER ADDRESS	/MTARGP POINTS HERE ON ENTRY.
/	WORD COUNT
MTWRIT	JMS MTSTAL	/WAIT FOR TRANSPORT.
	LAC MTCALP	/HANG ON CAL IN CASE OF
	DAC MTPC		/  OVERFLOW OR INITIAL WRITE OF FILE.
	LAC* MTARGP	/PICK UP LINE BUFFER ADDRESS.
	DAC MTLBH		/SAVE IN LINE BUFFER POINTER.
	AND (700000)		/(RCHM-106) EXTRACH EXTENDED MEMORY BITS.
	SZA			/(RCHM-106) ARE ANY OF THEM SET?
	JMP MTER67		/(RCHM-106) YES, GO PRINT ERROR.
	ISZ MTARGP	/BUMP TO WORD COUNT.
	LAC MTNEXT	/ARE WE IN THE MIDDLE OF AN OPERATION?
	SZA		/SKIP IF NOT.
	JMP* MTNEXT	/IF SO, GO TO NEXT PART OF SEQUENCE.
MTWRTZ	DZM MTFSIN	/ASSUME NON-FILE-STRUCTURED TRANSFER.
	LAC* MTTPTR	/PICK UP DRIVE STATUS.
	RTR		/OUTPUT AND INIT PERFORMED?
	CMA!CML		/INVERT TO CHECK
	SPA!SZL!RTR	/SKIP IF ALL OK.
	JMP MTERR7	/INPUT DRIVE OR NO INIT PERFORMED, IOPS 7.
	SMA!SNL!RTR
	JMP MTWRT1	/DECISION MADE AND NON-FILE-STRUCTURED.
MTWRT2	LAC* MTTPTR	/NO DECISION, MAKE ONE.
	JMS MTIOR		/INSERT SOME BITS.
	AND (27
	DAC* MTTPTR	/UPDATE TABLE.
	JMP MTWMOC	/GO CALCULATE MODE PROCESSOR ADDRESS.
/COME HERE WITH INVERSE OF FILE-OPEN (0=YES, 1=NO) IN SIGN; INVERSE
/OF HEADER-LABEL-WRITTEN (O=YES, 1=NO) IN LINK.
MTWRT1	SPA		/SKIP IF A FILE IS OPEN.
	JMP MTER11	/NO FILE OPEN, ERROR.
	ISZ MTFSIN	/TURN ON FS TRANSFER.
	SNL		/SKIP IF NO HEADER LABEL WRITTEN.
	JMP MTWMOC	/ALL SET, GO PROCESS THIS REQUEST.
/COME HERE ON FIRST OUTPUT REQUEST TO FS DRIVE. WRITE A LABEL.
/BLOCK CONTROL PAIR SETUP.
	LAC (7745		/BI AND WORD COUNT.
	DAC* MTBCP1	/TO FIRST WORD.
	LAC* MTFNAM	/GET FILE POSITION.
	DAC* MTDATA	/PUT IN LABEL.
	TAD* MTBCP1	/BCP WORD 1
	TAD MTMIN1
	CMA		/GIVES CHECKSUM
	DAC* MTBCP2	/PUT CHECKSUM IN LABEL.
/NOW ZERO OUT REMAINDER OF LABEL.
	LAW -30		/24(10) WORDS.
	DAC MTWCT1	/..
MTWRZL	ISZ MTDATA	/POINT TO NEXT WORD.
	DZM* MTDATA	/..
	ISZ MTWCT1	/COUNT WORDS ZEROED.
	JMP MTWRZL	/MORE TO DO.
/LABEL IS ALL SET. NOW WRITE IT OUT.
	LAW -33
	DAC* MTWCR
	LAC MTWRDS
	DAC* MTCAR
	LAC* MTTPTR
	TAD MTWRTC
	JMS MTRDWR
	JMP MTIOP4
	JMS MTNEXT
/RETURN HERE WITH TRANSPORT READY.
	LAC* MTTPTR
	JMS MTIOR
	AND (40		/TURN ON LABEL-WRITTEN INDICATOR.
	DAC* MTTPTR
	DZM MTNEXT
	LAC (1
	DAC* MTRECS
	DZM* MTWRDS
	JMP MTWRTZ
/CALCULATE WHRE TO GO TO SERVICE THIS WRITE REQUEST.
MTWMOC	JMS MTCALM
	TAD (MTWMOD+1
	DAC MTWMOD
	JMP* MTWMOD
MTWMOD	0
	JMP MTERR7	/NFS IOPS OR IMAGE
	JMP MTERR7	/NFS DUMP
/*****  NOTE THAT MODE 5 WRITE PROCESSOR MUST TURN OFF CORE-DUMP
/	INDICATOR IN DRIVE STATUS TABLE ENTRY FOR REFERENCED DRIVE.
	JMP MTERR7	/NFS 9-CHAN
	JMP MTWIFS	/FS IOPS, IMAGE.
	JMP MTWDPF	/FS DUMP
	JMP MTERR7	/FS 9 -CHAN
/FILE-STRUCTURED DUMP MODE OUTPUT PROCESSOR.
MTWDPF	NOP		/ONE-TIME SECTION TO SAVE ARGUMENTS.
	LAC MTWDS1	/PICK UP "JMP MTDNXT"
	DAC MTWDPF	/DISABLE ENTRY TO THIS SECTION.
	LAC* MTARGP	/PICK UP WORD COUNT.
	DAC MTWCT1	/AND SAVE IT.
	CMA!IAC			/(RCHM-106) CONVERT WC TO A POSITIVE NUMBER.
	TAD MTLBH		/(RCHM-106) ADD IN BUFFER START.
	AND (700000)		/(RCHM-106) EXTRACT EXTENDED MEMORY BITS.
	SZA			/(RCHM-106) ARE ANY OF THE ON?
	JMP MTER67		/(RCHM-106) YES, GO PRINT ERROR.
	LAC MTLBH		/PICK UP CORE AREA ADDRESS.
	DAC MTWRP4	/..
/ENTER LOOP TO MOVE WORDS TO BUFFER UNTIL COUNT IS SATISFIED; WRITE
/FULL BUFFER LOADS IN THE PROCESS.
MTDNXT	LAC MTWCT1	/GET CURRENT RECORD LENGTH
	CMA			/(RCHM-005) FORMERLY CMA!IAC THIS DOESN'T WORK ON PDP9'S.
	TAD	(1		/(RCHM-005) COMPLETE CONVERSION TO TWO'S COMPLEMENT.
	TAD* MTWRDS	/INCLUDE WORDS IN BUFFER
	TAD MTLMAX	/IS BUFFER FULL NOW?
	SMA		/SKIP IF NOT.
	JMS MTWDS2	/FULL, WRITE IT OUT.
	LAC* MTWRDS	/CALCULATE WHERE NEXT WORD SHOULD GO.
	TAD MTDATA	/..
	DAC MTWRP2	/SAVE ADDRESS OF NEXT PUT.
	LAC* MTWRP4	/GET NEXT WORD FROM USER'S AREA.
	DAC* MTWRP2	/AND PUT IN BUFFER.
	ISZ MTWRP4	/BUMP INPUT POINTER.
	ISZ* MTWRDS	/BUMP TOTAL WORDS IN BUFFER.
	ISZ MTWCT1	/AND WORDS MOVED SO FAR.
MTWDS1	JMP MTDNXT	/MORE WORDS TO MOVE.
	LAC MTNOP		/ALL DONE, RESET ONE-TIME SWITCH.
	DAC MTWDPF	/  TO ALLOW LATER ENTRY.
	JMP MTWR02	/THEN RETURN TO CALLER.
/ZERO BLOCK CHECKSUM TO INDICATE DUMP MODE WRITE
MTWDS2	0
	DZM*	MTBCP2
	JMS	MTWRBF
	JMP*	MTWDS2
/IF DRIVE IS FILE-STRUCTURED, IOPS ASCII AND BINARY, IMAGE ALPHA AND
/BINARY COME HERE
MTWIFS	LAC* MTLBH	/PICK UP LENGTH OF LINE TO WRITE.
	RAL		/SHIFT LEFT TO CHECK BIT 1.
	SPA!RAR		/BIT 1 = 0, COUNT .L. 200(8).
	JMP MTER23	/COUNT .G. 177, IOPS 23.
	JMS MTROT8	/MOVE IT RIGHT.
	RTR
	AND (776
	DAC MTROT8
	SNA		/DON'T WORK ON ZERO COUNT.
	JMP MTER23
	TAD* MTWRDS	/ADD IN LENGTH SO FAR.
	TAD MTLMAX
	SMA!SZA		/SKIP NEGATIVE OR ZERO.
	JMP	MTWRL3
MTWRL5	LAW -2
	TAD MTROT8
	CMA
	DAC MTWCT1	/SAVE 2'S COMPLEMENT COUNT FOR THIS LINE.
	LAC MTDATA
	TAD* MTWRDS	/PLUS COUNT OF WORDS ALREADY IN BUFFER.
	DAC MTWRP2	/GIVES START ADDRESS OF BUFFER FOR THIS LINE.
	DAC MTWRP3	/..
	ISZ MTWRP3	/POINT TO LINE CHECKSUM.
	LAC MTLBH		/GET A POINTER TO THE USER'S LINE.
	DAC MTWRP4	/AND SAVE FOR MOVE.
	LAC* MTWRP4	/GET HEADER WORD
	AND (777770	/APPEND DATA MODE
	XOR MTMODE
	DAC* MTWRP2	/PUT IN BUFFER
	ISZ MTWRP2	/BUMP OUTPUT POINTER
	ISZ MTWRP4	/BUMP INPUT POINTER
	JMP MTWRL2-2	/GO ENTER LOOP
MTWRL1	LAC* MTWRP4	/PICK UP NEXT WORD FROM LINN.
	DAC* MTWRP2	/INSERT IN BUFFER.
	TAD* MTWRP3	/UPDATE CHECKSUM.
	DAC* MTWRP3	/..
	ISZ MTWRP2	/BUMP OUTPUT POINTER.
MTWRL2	ISZ MTWRP4	/AND INPUT POINTER.
	ISZ MTWCT1	/BUMP COUNT.
	JMP MTWRL1	/MORE TO DO.
/LINE IS MOVED TO BUFFER. NOW FINISH OFF CHECKSUM.
	LAW -1		/2'S COMPLEMENT
	TAD* MTWRP3	/LINE CHECKSUM.
	CMA
	DAC* MTWRP3
/NOW UPDATE DATA-WORD COUNT.
	LAC* MTWRDS	/PREVIOUS COUNT.
	TAD MTROT8	/PLUS WORDS THIS LINE.
	DAC* MTWRDS	/NEW COUNT.
/ALL SET, RETURN.
MTWR02	ISZ MTARGP	/***
	JMP MTDBR
/
MTWRL3	LAC	MTBCP1
	DAC	MTEMP
	LAC*	MTWRDS
	CMA!IAC
	DAC	MTEMP2
	LAC*	MTEMP
	ISZ	MTEMP
	ISZ	MTEMP2
	ISZ	MTEMP2
MTWRL4	ISZ	MTEMP
	TAD*	MTEMP
	ISZ	MTEMP2
	JMP	MTWRL4
	CMA!IAC
	DAC*	MTBCP2
	JMS	MTWRBF
	JMP	MTWRL5
  
  
MTWRP1	0	/POINTER TO CURRENT TOTAL WDS IN BUF
MTLMAX	LAW -377		/MAX DATA WORDS IN BUF
MTWCT1	0	/COUNT OF WORDS TO MOVE.
MTWRP2	0	/POINTER TO LINE AREA IN BUFFER.
MTWRP3	0	/LINE CHECKSUM POINTER IN BUFFER.
MTWRP4	0	/POINTER TO USER'S LINE.
MTWRP5	0	/POINTER TO BLOCK CONTROL PAIR.
MTWRP6	0	/POINTER  O TOTAL BLOCKS WRITTEN.
MTWFSI	0
	.TITLE	.WAIT
  
/EXECUTE WAIT, WAITR ON MAG TAPE.
/CALLING SEQUENCE
/	CAL+CODE(8)+DAT(9-17)
/	12
/	NON-BUSY RETURN (WAIT) OR POINTER TO BUSY RETURN (WAITR)
/	NON-BUSY RETURN (WAITR)
/WHERE CODE IS 0 FOR WAIT, 1 FOR WAITR.
/FIRST, FIND OUT WHETHER WAIT OR WAITR IS WANTED.
MTWAIT	LAC* MTCALP	/WAIT OR WAITR?
	AND MTRWDC	/EXTRACT BIT 8. (MTRWDC = 001000)
	XOR MTSKIP	/FORM NOP OR SKP.
	DAC MTWTSW	/SKIP IF WAIT, NOP IF WAITR.
/SET UP PROPER LINK, EXTEND MODE, MEMORY PROTECT BITS IN .WAITR RETURN.
	LAC* MTARGP	/GET RETURN ADDRESS.
	AND (77777	/EXTRACT 15 BITS.
	DAC MTEMP1	/SAVE TEMPORARILY.
	LAC MTARGP	/NOW GET POINTER.
	AND MTIOTC	/EXTRACT L, EM, MP.
	ADD MTEMP1	/PLUS .WAITR BUSY RETURN.
	DAC MTEMP1	/AND SAVE FOR LATER.
/NOW SEE IF IO IS COMPLETE.
	LAC MTIOSW	/IO STILL UNDERWAY? (MTIOSW .NE. 0 IF SO.)
	SNA		/SKIP IF IO STILL NOT FINISHED.
	JMP MTDONE	/ALL FINISHED.
	LAC MTEMP1	/ASSUME WAITR.
MTWTSW	XX		/SKIP IF WAIT.
	DAC MTCALP	/MTCALP=C(MTARGP) IF WAITR.
MTCALR	DBR		/DEBREAK FROM CAL LEVEL.
	XCT .+1
	JMP* MTCALP	/RETURN TO CAL OR WAITR ADDRESS.
/COME HERE ON IO COMPLETE. RETURN TO CAL+2 IF WAIT, TO CAL+3 IF WAITR.
MTDONE	XCT MTWTSW	/IO FINISHED. SKIP IF WAIT, NOP IF WAITR.
	ISZ MTARGP	/WAITR, BUMP TO NON-BUSY RETURN.
	LAC MTSTAT	/PICK UP STATUS IN CASE OF .TRAN-INITIATED IO.
	JMP MTDBR		/THEN RETURN THROUGH MTARGP.
	.TITLE	.TRAN
  
  
/EXECUTE TRAN ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DIRECTION(7-8)+DAT(9-17)
/	UNIT(0-2)+13
/	DEVICE ADDRESS (IGNORED)	/MTARGP POINTS HERE ON ENTRY.
/	CORE START ADDRESS
/	WORD COUNT (2'S COMPLEMENT)
/WHERE DIRECTION MUST BE 0 (INPUT FORWARD) OR 1 (OUTPUT FORWARD).
/DIRECTION CODES 2 AND 3 ARE ILLEGAL (IOPS 6).
MTECNT	0		/RETRY COUNTER
TRANWS	0		/WORD COUNT SAVE
TRANCS	0		/CURRENT ADDRESS SAVE
MTTRAN	JMS MTSTAL	/WAIT FOR DEVICE TO FREE UP.
	LAW -31		/RESET RETRY COUNT
	DAC MTECNT
	ISZ MTARGP	/POINT TO CORE START ADDRESS.
	CLA!CMA		/SET UP CURRENT ADDRESS REGISTER
	TAD* MTARGP	/  USING LINE-BUFFER ADDRESS
	DAC* MTCAR	/  FROM CAL ARGUMENT LIST.
	DAC TRANCS	/SAVE FOR LATER
	ISZ MTARGP		/POINT TO WORD COUNT.
	LAC* MTARGP	/SET UP WORD COUNT REGISTER
	DAC* MTWCR	/  WITH WORD COUNT (MAXIMUM) SUPPLIED.
	DAC TRANWS	/SAVE FOR LATER
	ISZ MTARGP	/POINT TO RETURN.
	LAC MTARGP	/SET UP RETURN FROM CAL SERVICER.
	DAC MTPC		/SET UP FOR NORMAL RETURN.
	LAC* MTCALP	/NOW PICK UP CAL.
	AND MTRCMC	/EXTRACT BITS 7-8.
	SNA!CLL		/SKIP IF NOT READ FORWARD.
	JMP MTRANI	/INPUT FORWARD.
	SAD MTRWDC	/SKIP IF NOT WRITE FORWARD.
	SKP!RTL		/WRITE FORWARD, SET UP WRITE COMMAND.
	JMP MTERR6	/ERROR.
/OUTPUT TRAN COMES HERE. NOTE THAT IF WE ARE REFERENCING A 9-CHANNEL DRIVE,
/THE CORE-DUMP BIT WILL HAVE BEEN SET BY THE LATEST .INIT OR BY A
/SUBSEQUENT .MTAPE REQUEST IF DEFAULT IS 7-CHANNEL (SCOM+4 BIT 6 = 0).
MTRANO	TAD* MTTPTR
	DAC	MTCOMD	/SAVE FOR RETRY
MTRANA	JMS MTRDWR	/THEN GO START UP IO.
	JMP MTIOP4	/RETURN HERE IF ILLEGAL.
	SMA
	JMP MTRET1		/RETURN TO USER.
	LAC MTSTAT
	AND	(4000	/EXTRACT EOT BIT
	SZA		/SKIP IF NO
	JMP	MTER44	/YES. REPORT UNRECOVERRABLE ERROR
	ISZ MTECNT
	JMP .+2		/NOT 25 TRIES YET
	JMP	.+3	/DONE. GO ERASE BAD TAPE & RETRY
	JMS	GOBACK
	JMP	MTRANA	/ALL RESET. TRY AGAIN
	LAW	-31	/TRIED 25 TIMES. SKIP A RECORD & TRY AGAIN
	DAC	MTECNT
	JMS	GOBACK
	TAD	MTXIRG	/ADD SKIP FUNCTION
	JMP MTRANA
/INPUT TRAN COMES HERE.
MTRANI	LAC MTREDC	/READ COMMAND.
	TAD*	MTTPTR
	DAC	MTCOMD	/SAVE FOR RETRY
MTRANR	JMS	MTRDWR
	JMP	MTIOP4
	SMA		/SKIP ON ERROR
	JMP MTRET1		/RETURN TO USER.
	LAC	MTSTAT	/RECORD LENGTH ERROR
	AND	(366600
	SNA		/SKIP IF NO
	JMP	MTRET1	/YES. EXIT
	ISZ	MTECNT
	JMP	.+2	/RETRY
	JMP	MTER65	/UNRECOVERABLE ERROR
	JMS	GOBACK	/BACKSPACE & RETRY
	JMP	MTRANR
/BACKSPACE RECORD & RETRY PREVIOUS OPERATION
GOBACK	0
	JMS	MTESTL	/WAIT FOR TAPE TO SETTLE DOWN
	JMS	MTBACK	/BACKSPACE ONE RECORD
	JMS	MTESTL
	LAC TRANCS
	DAC* MTCAR	/SET UP CA
	LAC TRANWS
	DAC* MTWCR	/SET UP WC
	LAC MTCOMD
	JMP*	GOBACK
	.TITLE	GENERAL SUBROUTINES
/SUBROUTINE MTSTAL, WAIT FOR CONTROL AND TRANSPORT READY.
/CALLING SEQUENCE:
/	JMS MTSTAL
/	RETURN IF CONTROL AND UNIT READY.
MTSTAL	0		/ENTRY TO WAIT FOR MAG TAPE DEVICES.
	MTCR		/CONTROL READY?
	JMP MTCALR	/NO, RETURN TO CAL.
	LAC* MTTPTR	/CONTROL READY, GET UNIT.
	XOR MTENI		/TURN OFF INTERRUPT.
	MTLC		/LOAD COMMAND REGISTER.
	MTTR		/TRANSPORT READY?
	JMP .+4		/NO, GO FIND OUT WHY NOT.
	LAW -1750
	DAC MTTRSW	/TRANSPORT READY, RESET NOT-READY COUNTER.
	JMP* MTSTAL	/AND EXIT TO CALLER.
	MTRS		/IS UNIT REWINDING?
	RAL		/GET INDICATOR.
	SMA		/SKIP IF UNIT IS REWINDING.
	ISZ MTTRSW	/NOT REWINDING, COUNT THIS TIME THROUGH.
	JMP MTCALR	/RETURN IF COUNT UNSATISFIED.
/COME HERE ON COUNT COMPLETE. MEANS UNIT MUST NOT BE AVAILABLE.
	LAW -1750		/SET UP COUNT FOR NEXT TIME.
	DAC MTTRSW	/..
	JMP MTIOP4	/THEN GO PUBLISH IOPS 4.
MTTRSW	-1750		/COUNTER FOR 1000 TIMES THRU WAIT LOOP.
/SUBROUTINE MTROT8.
MTROT8	0
MTEMP1=MTROT8		/TEMPORARY STORAGE.
	XCT* MTROT8
	XCT* MTROT8
	XCT* MTROT8
	JMP* MTROT8
/SUBROUTINE MTIOR, PERFORM INCLUSIVE OR.
/CALLING SEQUENCE (IOR WORD1 AND WORD2):
/	LAC WORD1		/ENTER WITH FIRST WORD IN AC.
/	JMS MTIOR		/GO TO MTIOR.
/	AND WORD2		/THIS INSTRUCTION IS XCT'D.
/	DAC RESULT	/RETURN FROM MTIOR WITH RESULT IN AC.
MTIOR	0		/ENTRY TO INCLUSIVE OR.
	DAC MTEMP1	/SAVE TEMPORARILY.
	CMA		/INVERT.
	XCT* MTIOR	/EXTRACT BITS NEEDED FOR WORD2 INCLUSION.
	XOR MTEMP1	/THEN REINSERT WORD1.
	ISZ MTIOR		/BUMP TO RETURN.
	JMP* MTIOR	/THEN EXIT TO CALLER.
/
/SUBROUTINE TO WAIT FOR TAPE TO SETTLE DOWN AFTER A CHANGE IN DIRECTION OF TAPE
/MOVEMENT
MTESTL	0
	LAW	-6000	/12MS DELAY
	DAC	MTTRDS
	MTTR		/CHECK IF TRANSPORT READY
	SKP		/NOT YET
	JMP*	MTESTL	/YES. RETURN
	ISZ	MTTRDS	/COUNT DELAY
	JMP	.-4
	LAC	(JMP MTESTL+3	/TROUBLE. SETUP FOR IOPS 4 RETURN
	.IFUND DOS
	DAC*	MT.MED
	.ENDC
	JMP	MTIOP4+1
/
MTTRDS	0
/
/SUBROUTINE MTCALM
MTCALM	0
	LAC* MTCALP
	CLL!RAR
	JMS MTROT8
	RTR
	AND (17
	DAC MTMODE	/SAVE FOR OUTPUT HEADER
	TAD MTMIN3
	SPA!SNA
	CLA
	DAC MTCMOD
	TAD MTMIN3
	SMA
	JMP MTERR7
	LAC MTFSIN
	CLL!RAL
	TAD MTFSIN
	TAD MTCMOD
	JMP* MTCALM
MTCMOD	0
MTFSIN	0
MTMODE	0
/BUFFER-HANDLING SUBROUTINES.
/SUBROUTINE MTGTBF, ASSIGN A BUFFER TO A FILE AT SEEK OR ENTER
/TIME. ON ENTRY, MTARGP MUST POINT TO DEB POINTER. ADDRESS OF
/BUFFER ASSIGNED IS STORED IN C(MTTPT1), WHICH SHOULD POINT TO
/SECOND WORD OF APPROPRIATE ENTRY IN MTDSTB.
/CALLING SEQUENCE:
/	JMS MTGTBF	/JUST CALL MTGTBF.
MTGTBF	0		/ENTRY TO MTGTBF.
	LAC* MTTPT1	/PICK UP POINTER TO BUFFER CURRENTLY ASSIGNED.
	AND (77777	/EXTRACT 15-BIT BUFFER ADDRESS.
	SZA		/SKIP IF NO BUFFER IS PRESENTLY ASSIGNED.
	JMP* MTGTBF	/BUFFER HAS ALREADY BEEN ASSIGNED, RETURN TO CALLER.
	LAC MTBFPT	/ADDRESS OF 1ST ENTRY IN BUFFER TABLE.
	DAC MTBPT1	/SAVE TEMPORARILY.
MTGBL1	LAC* MTBPT1	/PICK UP NEXT BUFFER ADDRESS.
	SMA		/SKIP IF THIS BUFFER IS NOT FREE.
	JMP MTGBFD	/BUFFER IS FREE, GO ASSIGN IT.
	ISZ MTBPT1	/POINT TO NEXT BUFFER.
	JMP MTGBL1	/CHECK NEXT ENTRY.
MTGBFD	DAC* MTTPT1	/PUT IT IN STATUS TABLE.
	XOR MTXCT0
	DAC* MTBPT1
	LAW -1		/REDUCE FREE-BUFFER COUNT.
	TAD MTBFTB	/BY ONE.
	DAC MTBFTB	/..
	JMS MTSTPT	/SET UP BUFFER POINTERS.
/***  SHOULD ANYTHING MORE GO IN HERE? ***
	JMP* MTGTBF	/ALL DONE, RETURN TO CALLER.
  
/SUBROUTINE MTRLBF, RELEASE AN ASSIGNED BUFFER.
/CALLING SEQUENCE:
/	JMS MTRLBF	/JUST A JMS.
/MTTPT1 MUST POINT TO THE BUFFER BEING RELEASED.
MTRLBF	0		/ENTRY TO MTRLBF.
	LAC* MTTPT1	/BUFFER ADDRESS.
	AND (77777
	SNA
	JMP MTRBL2
	JMS MTIOR		/INSERT HIGH ORDER BIT.
	AND MTXCT0	/..
	DAC* MTTPT1	/UPDATE TABLE.
	LAW -3		/*** CHECK THREE BUFFERS.
	DAC MTGBCT	/***
	LAC MTBFPT	/TOP OF BUFFER TABLE.
	DAC MTBPT1	/SAVE IN POINTER.
MTRBL1	LAC* MTBPT1	/PICK UP ADDRESS OF NEXT BUFFER.
	SAD* MTTPT1	/IS THIS IT?
	JMP MTRBFD	/YES.
	ISZ MTBPT1	/NO, BUMP POINTER.
	ISZ MTGBCT	/*** AND COUNT.
	JMP MTRBL1	/CHECK NEXT BUFFER.
	HLT!CLA!CMA	/*** ERROR, LOST TRACK OF BUFFERS.
MTRBFD	LAC* MTBPT1	/PICK UP BUFFER TO BE RELEASED.
	XOR MTXCT0	/TURN OFF BIT 0.
	DAC* MTBPT1	/BUFFER IS NOW FREE.
	ISZ MTBFTB	/BUMP COUNT OF FREE BUFFERS.
MTRBL2	DZM* MTTPT1	/INDICATE NO BUFFER ASSIGNED TO REFERENCED DRIVE.
	JMP* MTRLBF	/ALL DONE, RETURN TO CALLER.
/TABLE OF BUFFER ADDRESSES.
MTBFPT	MTBFTB+1		/TOP OF TABLE.
MTBFTB	3			/BUFFERS CURRENTLY AVAILABLE.
	MTBUF1		/BUNCH OF POINTERS TO MAG TAPE BUFFERS.
	MTBUF2
	MTBUF3
/TEMPORARY STORAGE REGISTERS.
MTBPT1	0
MTBPT2
MTBFCT	0
MTGBCT	0
/MAG TAPE BUFFERS.
/BUFFER ORGANIZATION:
/WORDS 1-3	DIRECTORY ENTRY
/WORD 4		HANDLER-CREATED FILE NAME
/WORD 5		TOTAL BLOCKS IN FILE
/WORD 6		DATA-WORD COUNT
/WORDS 7-264	DATA
MTBUF1=.
	.BLOCK MTREGS	/RESERVE SPACE FOR FILE NAME, ETC.
	.BLOCK 401	/THEN 257(10) REGISTERS FOR BUFFER PROPER.
MTBUF2=.
	.BLOCK MTBUF2-MTBUF1
MTBUF3=.
	.BLOCK MTBUF3-MTBUF2
/SUBROUTINE MTSRCH, SCAN FILE DIRECTORY FOR FILE NAME WANTED. DEB TO
/SEARCH FOR IS POINTED TO BY MTDEBP. FIRST WORD OF DIRECTORY PROPER
/IS AT C(MTBCP1).
/FILE DIRECTORY FORMAT:
/WORDS 1-2:	BLOCK CONTROL PAIR
/WORD 3:		1'S COMPLEMENT FILE COUNTS. TOTAL 0-8, ACTIVE 9-17
/WORDS 4-17:	ACCESSIBILITY MAP; 1=ACTIVE, 0=INACTIVE
/WORDS 18-257:	3-WORD FILE NAME ENTRIES
/ON EXIT, REGISTERS OF INTEREST ARE:
/AC:	ZERO IF FILE NOT FOUND, NON-ZERO OTHERWISE
/MTCTOT:	TOTAL FILES ON THIS TAPE, 1'S COMPLEMENT
/MTCACT:	ACTIVE FILES ON THIS TAPE, 1'S COMPLEMENT
/MTACCM:	POSITION OF THIS FILE IN ACCESSIBILITY MAP (0-373 OCT)
/MTDIRP:	ADDRESS OF APPLICABLE DEB IN DIRECTORY
/MTACCD:	POSITION OF THIS DEB IN DIRECTORY (0-117 OCT)
/CALLING SEQUENCE:
/	JMS MTSRCH	/COULDN'T BE SIMPLER.
  
MTSRCH	0		/ENTRY TO MTSRCH.
MTL777	LAW 17000	/GET COUNTS.
	AND* MTDATA	/EXTRACT TOTAL COUNT.
	CLL!RAR		/MOVE TOTAL COUNT TO RIGHT.
	JMS MTROT8	/GOES INTO 9-17
	RTR
	XOR MTL777	/REST OF 1'S COMPLEMENT WORD.
	DAC MTSRTC	/SAVE IN TEMPORARY AND
	DAC MTCTOT	/IN COMMUNICATION REGISTERS.
/TOTAL FILE COUNT IN MTSRTC AND MTCTOT. NOW GET ACTIVE COUNT.
	LAC* MTDATA	/PICK UP COUNTS AGAIN.
	AND (777
	XOR MTL777
	DAC MTSRTA	/SAVE ACTIVE FILE COUNTS.
	DAC MTCACT	/..
/ACTIVE FILE COUNT (1'S COMPLEMENT) IN MTSRTA AND MTCACT. SET UP
/ADDRESS OF FIRST FILE NAME ENTRY.
	LAC MTDATA	/FIRST ENTRY IN FILE NAME SECTION
	TAD (17		/  STARTS AT WORD 18 OF DIRECTORY.
	DAC MTSRP1	/SAVE POINTER TO IT.
	DZM MTACCD	/FILE NUMBER OF FIRST ACTIVE FILE = 0.
	JMP MTSRL3	/GO START THE SEARCH.
/MAJOR LOOP TO COMPARE TWO DIRECTORY ENTRY BLOCKS. FILE NAME WANTED IS
/POINTED TO BY MTDEBP; FILE NAME CURRENTLY UNDER CONSIDERATION IN THE
/DIRECTORY IS POINTED TO BY MTSRP1.
MTSRL1	LAW -3		/COUNT 3 WORDS EACH ENTRY.
	DAC MTSRCT	/..
	LAC MTDEBP	/POINTER TO DEB WANTED.
	DAC MTSRT1	/INTERNAL POINTER.
	LAC MTSRP1	/THIS DEB IN DIRECTORY.
	DAC MTDIRP	/JUST IN CASE OF SUCCESS THIS TIME.
	DZM MTSRT2	/SUCCESSFUL-COMPARE SWITCH.
MTSRL2	LAC* MTSRT1
	XOR* MTSRP1
	ISZ MTSRT1
	ISZ MTSRP1
	SZA
	DAC MTSRT2	/FAILED COMPARE.
	ISZ MTSRCT	/COUNT THREE WORDS.
	JMP MTSRL2	/MORE WORDS IN THIS DEB.
/COMPARED THREE WORDS, CHECK FOR SUCCESS. MTSRT2=0 MEANS GOOD COMPARE.
	LAC MTSRT2
	SNA
	JMP MTSRFD	/FOUND THE FILE WANTED.
	ISZ MTACCD	/COUNT FILE JUST LOOKED AT.
MTSRL3	ISZ MTSRTA	/COUNT ACTIVE FILES PRESENT.
	JMP MTSRL1	/AND GO BACK AND SEARCH SOME MORE.
/COME HERE ON FILE NOT FOUND AFTER SEARCH OF ENTIRE DIRECTORY.
MTSRNF	CLA		/***MUST BE A BETTER WAY.
	JMP* MTSRCH	/EXIT INDICATING FILE NOT FOUND.
/COME HERE ON FILE FOUND.
MTSRFD	LAC MTACCD	/ACTIVE FILE NUMBER.
	JMS MTEXBM	/GO SCAN THE ACCESSIBILITY MAP.
	DAC MTACCM	/SAVE PHYSICAL FILE NUMBER.
	CLA!CMA		/***
	JMP* MTSRCH	/DONE, RETURN TO CALLER.
MTSRT1	0		/TEMPORARY REGISTER.
MTSRTC	0		/TOTAL FILES ON TAPE, 1'S COMPLEMENT.
MTCTOT	0		/LIKEWISE.
MTSRTA	0		/ACTIVE FILES ON TAPE, 1'S COMPLEMENT.
MTCACT	0		/SAME THING.
MTSRP1	0	/POINTER TO CURRENT ENTRY IN FILE-NAME SECTION.
MTDIRP	0	/POINTER TO GOOD ENTRY IN DIRECTORY.
MTACCD	0		/POSITION OF NAME IN ENTRY SECTION.
MTACCM	0		/PHYSICAL POSITION OF FILE ON TAPE.
MTSRCT	0		/THREE-WORD COUNTER.
MTSRT2	0		/TEMP STORAGE.
  
/SUBROUTINE MTDLNM, REMOVE A NAME FROM FILE DIRECTORY.
/ON ENTRY, REGISTERS MUST BE AS SET UP BY MTSRCH.
/CALLING SEQUENCE:
/	JMS MTDLNM
MTDLNM	0
	LAW -120
	TAD MTACCD
	DAC MTDLNC
/MOVE OTHER NAMES UP BY 3.
	LAC MTDIRP
	DAC MTMPT2
	TAD (2
	DAC MTMPT1
/NOW MAKE SURE FILE BEING DELETED IS NOT SYS FILE.
	LAC* MTMPT1
	SAD MTSNAM
	JMP MTER46	/ATTEMPT TO DELETE SYSTEM FILE (EXT = "SYS"), IOPS 46.
	ISZ MTMPT1
MTDLN1	JMS MTMVNM
	LAC MTMPT1
	LAC MTMPT2
	ISZ MTDLNC
	JMP MTDLN1
/ALL SET. CLEAR MAP BIT.
	LAC MTACCM
	JMS MTCLRB
MTNOP	NOP
/*** IS THIS NECESSARY?
MTDLN2	LAC (MTREGS+2
	TAD* MTTPT1
	DAC MTDLNP
	ISZ* MTDLNP
	ISZ MTCACT
	JMP* MTDLNM
	HLT!CLA!CMA	/LOST COUNT OF FILES.
MTDLNC	0
MTDLNP	0
MTSNAM	.SIXBT 'SYS'
  
  
/SUBROUTINE MTMVNM, MOVE DIRECTORY ENTRY BLOCK AROUND.
/CALLING SEQUENCE:
/LOC	JMS MTMVNM
/LOC+1	LAC ADRNOW	/ADDRESS OF DEB TO MOVE.
/LOC+2	LAC NEWADR	/PLACE TO PUT IT.
/INSTRUCTIONS AT LOC+1 AND LOC+2 ARE EXECUTED FROM WITHIN MTMVNM.
/RETURN IS MADE TO LOC+2.
MTMVNM	0
	XCT* MTMVNM	/PICK UP ADDRESS OF DEB.
	DAC MTMPT1	/SAVE IN INPUT POINTER.
	ISZ MTMVNM	/BUMP TO NEXT ARG.
	XCT* MTMVNM	/PICK UP OUTPUT ADDRESS.
	DAC MTMPT2	/SAVE THAT TOO.
MTMIN3	LAW -3		/MOVE THREE WORDS.
	DAC MTMVCT	/..
MTMOV1	LAC* MTMPT1	/MOVE NEXT WORD IN DEB.
	DAC* MTMPT2	/..
	ISZ MTMPT1	/BUMP INPUT
	ISZ MTMPT2	/   AND OUTPUT POINTERS.
	ISZ MTMVCT	/COUNT THREE WORDS TO MOVE.
	JMP MTMOV1	/MORE TO DO.
	JMP* MTMVNM	/ALL FINISHED, RETURN.
MTMVCT	0
MTMPT1	0
MTMPT2	0
  
/SUBROUTINE MTEXBM, ACCESSIBILITY MAP SEARCH.
MTEXBM	0
	CMA		/2'S COMPLEMENT.(0-120)
	DAC MTEXCT	/SAVE COUNT
	LAC (MTREGS+3
	TAD* MTTPT1
	DAC MTEXPT
	LAW -17		/***
	DAC MTEXWC	/***
	DZM MTEXPC
MTEXL1	LAW -22
	DAC MTEXBC
	LAC* MTEXPT
MTEXL2	RAL
	SNL		/ACTIVE FILE, SKIP.
	JMP MTEXIN	/INACTIVE FILE.
	ISZ MTEXCT	/IS IT THE ONE WE WANT?
	SKP		/NO
	JMP MTEXFD	/YES.
MTEXIN	ISZ MTEXPC	/NO, COUNT PHYSICAL FILES PRESENT.
	ISZ MTEXBC	/18 BITS CONSIDERED?
	JMP MTEXL2	/NOT YET.
	ISZ MTEXPT	/YES, BUMP MAP-WORD POINTER.
	ISZ MTEXWC	/***
	JMP MTEXL1
	HLT!CLA!CMA	/***YECH!
MTEXFD	LAC MTEXPC	/PHYSICAL FILE NUMBER. (0-373)
	JMP* MTEXBM
MTEXCT	0		/ACTIVE FILE NUMBER TO SEARCH FOR.
MTEXBC	0		/18-BIT COUNTER.
MTEXPT	0		/POINTER TO MAP.
MTEXWC	0		/***
MTEXPC	0		/PHYSICAL-FILE COUNTER.
  
/SUBROUTINE MTCLRB, CLEAR OR SET A BIT IN ACCESSIBILITY MAP.
/CALLING SEQUENCE:
/	LAC FILNO		/0-373 OCTAL.
/	JMS MTCLRB
/	XOR MTCLCT	/TO SET A BIT...
/   OR
/	NOP		/TO CLEAR A BIT.
MTCLRB	0
	CMA
	DAC MTCLCT	/SAVE FILE NUMBER.
	LAC MTDATA	/POINTER TO BIT MAP-1.
	DAC MTBMPT	/..
	SKP!CLA!CLL!CML
MTCBL1	RAR
	SNL!CLL
	JMP .+3
	ISZ MTBMPT
	LAC MTXCT0
	ISZ MTCLCT
	JMP MTCBL1
	DAC MTCLCT
	LAC* MTBMPT
	AND MTCLCT
	XOR* MTBMPT
	XCT* MTCLRB
	DAC* MTBMPT
	JMP* MTCLRB
MTBMPT	0
MTCLCT	0
/SUBROUTINE MTWRBF, WRITE OUTPUT BUFFER.
/CALLED BY WRITE AND CLOSE PROCESSORS.
MTWRBF	0
	DZM MTWXIR	/INTER-RECORD GAP.
MTWRB1	LAC* MTWRDS	/GET DATA-WORD COUNT.
	CMA		/MAKE TWO'S COMPLEMENT
	TAD MTMIN1	/  COUNT OF ENTIRE RECORD (DATA WORDS + 2).
	DAC* MTWCR
	AND (7777
	TAD MTLAC0	/INSERT BI
	DAC* MTBCP1
	LAC MTWRDS
	DAC* MTCAR
	LAC* MTTPTR
	TAD MTWRTC
	TAD MTWXIR
	JMS MTRDWR
	JMP MTIOP4
	JMS MTOCHK	/WRITE COMPLETE, GO CHECK FOR ERRORS.
	JMP MTWRBX	/RETURN HERE IF ERROR-FREE TRANSFER.
	JMP MTWRB3	/RETURN HERE IF EOT ENCOUNTERED.
	JMP MTWRB1	/AND RETURN HERE IF REWRITE NEEDED.
MTWRB3	LAC* MTTPT1
	DAC MTWBP1
	ISZ MTWBP1
	ISZ MTWBP1
	LAW 10000
	AND* MTWBP1
	TAD MTXNAM
	DAC* MTWBP1
	DZM MTOFLO
	JMP MTCLS4
MTWRBX	DZM*	MTWRDS
	ISZ* MTRECS	/BUMP RECORD COUNT.
	DZM MTNEXT
	JMP* MTWRBF
MTWBP1	0
MTXNAM	.SIXBT '@XX'
MTOFLO	-1
  
  
/SUBROUTINE MTOCHK, CHECK STATUS AFTER WRITE.
/CALLING SEQUENCE:
/LOC	JMS MTOCHK	/GO TO MTOCHK
/LOC+1	JMP NOERRS	/RETURN IF NO WRITE ERRORS.
/LOC+2	JMP EOTFND	/RETURN IF EOT ENCOUNTERED.
/LOC+3	JMP REWRIT	/RETURN IF REWRITE NEEDED.
/IF RETURN IS MADE TO LOC+3 (REWRITE RECORD), GAP-LENGTH INDICATOR
/WILL HAVE BEEN SET INTO VARIABLE MTWXIR; ANY WRITE ERROR EXCEPT DATA-
/REQUEST-LATE WILL CAUSE MTWXIR TO BE LOADED WITH EXTENDED
/INTER-RECORD GAP COMMAND REGISTER BIT. DATA LATE CAUSES MTWXIR TO BE
/SET TO ZERO. IF REWRITE IS NEEDED, THE BACKSPACE OVER THE ERROR RECORD
/WILL ALREADY HAVE BEEN PERFORMED.
MTOCHK	0		/ENTRY TO CHECK FOR WRITE ERRORS.
	JMS MTNEXT	/FIRST, WAIT FOR DRIVE TO FREE UP.
	LAC MTSTAT	/PICK UP STATUS.
	SMA		/SKIP IF AN ERROR OCCURRED.
	JMP* MTOCHK	/NO ERRORS, RETURN TO LOC+1.
	ISZ MTOCHK	/BUMP TO EOT-FOUND RETURN.
	AND MTWRTC	/NOW EXTRACT EOT STATUS.
	SZA		/SKIP IF EOT NOT ENCOUNTERED.
	JMP* MTOCHK	/EOT FOUND, RETURN TO LOC+2.
	ISZ MTOCHK	/NOW BUMP TO REWRITE-NEEDED RETURN.
	LAC MTSTAT	/PICK UP STATUS AGAIN.
	AND MTENI		/EXTRACT DATA-LATE.
	SNA!CLA		/SKIP IF DATA LATE.
	LAC MTXIRG	/NOT DATA LATE, PICK UP LONG-GAP INDICATOR.
	DAC MTWXIR	/SET UP GAP LENGTH FOR REWRITE.
/BACKSPACE OVER ERROR RECORD.
MTWRC1	LAW -1		/SET UP WORD COUNT.
	DAC* MTWCR	/CAUSES BACKSPACE OF ONE RECORD.
	LAC* MTTPTR	/PICK UP UNIT NUMBER.
	TAD MTBSPC	/FORM BACKSPACE COMMAND.
	JMS MTRDWR	/GO DO IT.
	JMP MTWR04	/DRIVE NOT AVAILABLE, IOPS 4.
	JMS MTNEXT	/BACKSPACE PERFORMED, WAIT FOR DRIVE.
	JMP* MTOCHK	/THEN RETURN TO TRY WRITING AGAIN.
MTWR04	LAC (MTWRC1	/COME HERE IF DRIVE NOT AVAILABLE FOR BACKSPACE.
	JMP MTIOP4+1	/GO PUBLISH IOPS 4.
MTWXIR	0		/INTER-RECORD GAP INDICATOR; 0 = STANDARD GAP, 010000 = LONG GAP.
/SUBROUTINE MTRDIR, READ FILE DIRECTORY. CALLED BY OPER, SEEK, ENTER,
/AND CLOSE PROCESSORS.
MTRDIR	0
	LAC* MTTPT1	/IS DIRECTORY IN CORE ALREADY?
	SPA		/SKIP IF NOT.
	JMP* MTRDIR	/IF SO, RETURN NOW.
	JMS MTGTBF	/GO ASSIGN A BUFFER.
	LAW -3		/SET BACKSPACE COUNTER.
	DAC MTRDRS	/..
MTRDR1	MTRS		/READ STATUS FOR THIS UNIT.
	RTL		/MOVE BOT TO SIGN.
	SPA		/SKIP IF NOT BOT.
	JMP MTRDR2	/BOT, GO READ DIRECTORY.
/SET UP TO BACKSPACE ONE.
	LAW -1		/ONE RECORD.
	DAC* MTWCR	/TO WORD COUNT.
	DAC MTRDIL	/UNSET ILLEGAL INDICATOR.
	LAC* MTTPTR	/FORM BACKSPACE.
	TAD MTBSPC	/..
	JMS MTRDWR	/START UP IO.
	DZM MTRDIL	/IF ILLEGAL.
	JMS MTNEXT	/WAIT FOR TRANSPORT.
	LAC MTRDIL	/ILLEGAL?
	SMA		/SKIP IF NOT.
	JMP MTRDL1	/YES, GO FIND OUT WHY.
	ISZ MTRDRS	/3 BACKSPACE COMMANDS ISSUED?
	JMP MTRDR1	/NO, ISSUE ANOTHER ONE.
/BACKSPACED THREE RECORDS AND NO BOT IN SIGHT. REWIND THE DRIVE.
	LAC* MTTPTR	/FORM REWIND COMMAND.
	TAD MTRWDC	/..
	JMS MTRDWR	/GO ISSUE REWIND.
	SKP!RTL		/ILLEGAL, SKIP.
	JMP .+3		/SUCCESSFUL REWIND.
	SMA		/SKIP IF BOT.
	JMP MTIOP4	/ILLEGAL AND NOT BOT, IOPS 4.
	JMS MTNEXT	/RELEASE LEVEL 1.
	JMP MTRDR2	/THEN GO READ DIRECTORY BLOCK.
MTRDL1	LAC MTSTAT
	RTL
	SMA
	JMP MTIOP4
/COME HERE TO READ IN THE DIRECTORY BLOCK.
MTRDR2	LAW -401
	DAC* MTWCR
	LAC MTWRDS
	DAC* MTCAR
	LAC* MTTPTR
	TAD MTREDC
	JMS MTRDWR	/GO ISSUE READ REQUEST.
	JMP MTIOP4	/ILLEGAL.
	JMS MTNEXT	/WAIT.
	LAC MTSTAT	/PICK UP STATUS.
	AND MTXIRG	/EXTRACT EOF.
	SZA		/SKIP IF NOT EOF; MEANS OLD-STYLE DIRECTORY.
	JMP MTRDR2	/NEW-STYLE DIRECTORY, READ NEXT RECORD.
	LAC* MTTPT1	/PICK UP BUFFER POINTER.
	JMS MTIOR		/TURN ON DIRECTORY-IN-CORE.
	AND MTXCT0
	DAC* MTTPT1	/AND UPDATE POINTER.
	JMP* MTRDIR	/EXIT TO CALLER.
MTRDRS	0
MTRDIL	0
/MTWDIR, WRITE FILE DIRECTORY. CALLED BY DELETE, RENAME, AND 
/OUTPUT CLOSE PROCESSORS. CLEAR PROCESSOR HAS INTERNAL DIRECTORY-WRITE PROCEDURE.
MTWDIR	0
	LAW -5
	DAC MTWDCT
	DZM MTWDXI
MTWD02	LAW -2
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTBSPC
	JMS MTRDWR
	SKP!RTL
	JMP MTWD01-1
	SPA
	JMP MTWD01-1
	LAC (MTWDIR+1
	JMP MTIOP4+1
	JMS MTNEXT
MTWD01	LAW -1
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTSPFC
	JMS MTRDWR
	SKP
	JMP .+3
	LAC (MTWD01
	JMP MTIOP4+1
	JMS MTNEXT
	LAC MTSTAT
	AND MTXIRG
	SNA
	JMP MTWD03
	LAC MTWRDS
	DAC* MTCAR
	LAW -401
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTWRTC
	JMS MTRDWR
	SKP
	JMP .+3
	LAC (MTWD01
	JMP MTIOP4+1
	JMS MTNEXT
	DZM MTNEXT
	LAC MTSTAT
	SMA
	JMP* MTWDIR
	ISZ MTWDCT
	JMP MTWD02
/COME HERE ON FIVE UNSUCCESSFUL ATTEMPTS TO RECORD DIRECTORY.
MTWD03	DZM MTWDET
MTWD04	LAW -1
	DAC* MTWCR
	LAC* MTTPTR
	TAD MTSPFC
	JMS MTRDWR
	SKP
	JMP .+3
	LAC (MTWD04
	JMP MTIOP4+1
	LAC MTSTAT
	AND MTWRTC
	SZA
	JMP MTWD04
	LAC MTSTAT
	AND MTXIRG
	SNA
	JMP MTWD03
	SAD MTWDET
	JMP .+3
	DAC MTWDET
	JMP MTWD04
/LOGICAL OR PHYSICAL EOT FOUND.
	LAC (MTER43
	DAC MTWDIR
	LAC MTXIRG
	DAC MTWDXI
	JMP MTWD02
MTWDCT	0
MTWDXI	0
MTWDET	0
  
  
/SUBROUTINE MTWREF, WRITE ONE EOF MARKER ON CURRENTLY ACTIVE UNIT.
MTWREF	0		/ENTRY TO WRITE A TAPE MARK.
	LAC* MTTPTR	/GET CURRENT DRIVE DESIGNATION.
	AND	(40000		/(RCHM-005) GAURENTEE EVEN PARITY.
	XOR*	MTTPTR		/(RCHM-005) CLEAR PARITY BIT IN COMMAND WORD.
	TAD MTWEFC	/INSERT WRITE-EOF COMMAND.
	JMS MTRDWR	/GO START UP IO.
	JMP MTIOP4	/RETURN HERE IF DRIVE UNAVAILABLE.
	JMS MTNEXT	/WAIT FOR OPERATION TO COMPLETE.
	LAC MTSTAT	/PICK UP STATUS.
	AND MTXIRG	/EXTRACT EOF STATUS BIT.
	SZA		/SKIP IF EOF DID NOT GET SET.
	JMP* MTWREF	/ALL OK, RETURN TO CALLER.
	JMS MTBACK	/ERROR, BACKSPACE.
	JMP MTWREF+1	/AND GO TRY TO WRITE AGAIN.
/SUBROUTINE MTBACK, BACKSPACE ONE RECORD ON CURRENT DRIVE.
MTBACK	0		/ENTRY TO BACKSPACE A RECORD.
	LAW -1		/SET UP WORD COUNT TO REFLECT
	DAC* MTWCR	/  SINGLE-RECORD BACKSPACE.
	LAC* MTTPTR	/PICK UP DRIVE.
	TAD MTBSPC	/INSERT BACKSPACE COMMAND.
	JMS MTRDWR	/AND GO START UP OPERATION.
	JMP MTIOP4	/COME HERE IN DRIVE NOT AVAILABLE.
	JMP* MTBACK	/THEN EXIT TO CALLER.
	.TITLE INTERRUPT SERVICE
/
/MAG TAPE INTERRUPT SECTION.
MTINT	SKP		/SKIP IF PIC ENTRY.
	JMP MTAPI		/API ENTRY.
	DAC MTAC		/SAVE AC.
	LAC* MTZERO	/GET PC.
	DAC MTPC		/SAVE IT, TOO.
	LAC (ION		/GET ION CODE.
	JMP MTSETI	/AND ENTER MAIN PROCESSOR.
MTAPI	DAC MTAC		/SAVE AC
	LAC MTINT		/GET PC.
	DAC MTPC		/SAVE IT.
	LAC MTNOP
MTSETI	DAC MTION		/SET UP EXIT INTERRUPT CONDITION.
	LAC MTSKIP	/RESTORE PIC ENTRY.
	DAC MTINT		/..
	MTRS		/READ STATUS
	DAC* (.SCOM+21	/(JMW:107)RETURN STATUS (ALL OF IT) IN .SCOM+21.
	AND	(777600	/CLEAR JUNK
	DAC MTSTAT	/SAVE STATUS
	SMA		/SKIP IF ERROR.
	JMP MTISVC	/ERROR, GO DETERMINE ERROR TYPE.
	AND MTPAR		/EXTRACT ILLEGAL BIT.
	SNA		/SKIP IF ILLEGAL.
MTISVC	ISZ MTRDWR	/BUMP MTRDWR TO SUCCESSFUL-TRANSFER RETURN.
	MTAF		/CLEAR OUT MAG TAPE FLAG.
MTION	NOP		/OR ION, IF WE GOT HERE VIA A PIC INTERRUPT.
	LAC MTSTAT	/PICK UP STATUS AGAIN.
	JMP* MTRDWR
	.TITLE MTRDWR: PERFORM ACTUAL I/O SERVICE
/
/COME HERE TO PERFORM ALL ACTUAL MAG TAPE IO OPERATIONS, VIA
/"JMS MTRDWR".
MTRDWR	MTRET1		/ENTRY TO PERFORM MAG TAPE IO.
	DAC	MTIOSW
	DZM MTERRS	/TURN OFF ERRORS *****************
	MTLC		/COMMAND FROM AC TO COMMAND REGISTER.
	LAC MTAC		/PICK UP INTERRUPT AC.
	MTGO		/TURN ON GO.
MTIRET	DBR		/DEBREAK, EITHER FROM LEVEL 4 OR LEVEL 1.
	XCT MTEXIT	/RETURN TO MAIN PROGRAM.
MTEXIT	JMP* MTPC
/EXIT FROM INTERRUPT SERVICE WHEN NO MORE IO REQUIRED.
MTERRS	0		/ENTRY TO RETURN FROM INTERRUPT INDICATING ERROR.
	SKP		/LEAVE ERROR-SERVICER ADDRESS IN MTERRS.
MTRET1	DZM MTERRS	/CLEAR OUT ERROR INDICATOR.
	DZM MTNEXT
MTRET2	DZM MTIOSW	/TURN OFF IO UNDERWAY.
	LAC MTAC		/RESTORE AC.
	JMP MTIRET	/THEN GET OUT.
	.TITLE	.IMPLIED WAIT LOOP.
 
/ THIS ENTRY POINT IS USED WHENEVER A CAL MUST STALL A TASK UNTIL A PARTICULAR
/ FUNCTION IS COMPLETE. IT PERFORMS THIS FUNCTION BY LOOPING ON THE CAL WHICH
/ HAS BEEN ISSUED TO INITIATE THE I/O. TO ABORT THIS LOOP, THE USER MUST CLEAR
/ MTNEXT UPON RETURN TO THE INLINE CODE.
 
MTNEXT	0
	JMP MTRET2
	.TITLE CONSTANTS & VARIABLES
/
/COMMAND REGISTER BITS 6-8.
MTRWDC	1000		/REWIND
MTREDC	2000		/READ
MTRCMC	3000		/READ/COMPARE
MTWRTC	4000		/WRITE
MTWEFC	5000		/WRITE EOF.
MTSPFC	6000		/SPACE FORWARD
MTBSPC	7000		/SPACE REVERSE.
/INTERRUPT
MTENI	400		/INTERRUPT ENABLED.
MTWCR	32		/WORD COUNT.
MTCAR	33		/CURRENT ADDRESS.
MTXIRG	10000		/EXTENDED IRG.
MTCORD	20000		/CORE DUMP.
MTAC	0		/AC ON INTERRUPTS.
MTARGP	0
MTCALP	0
MTBSIZ	377		/STANDARD BUFFER SIZE (255 DECIMAL).
MTCLSW=MTBSIZ		/SWITCH FOR 2 EOF'S WRITTEN ON .CLOSE -- POSITIVE IF SO.
MTPC	0		/PC ON INTERRUPTS.
MTTPTR	0		/POINTER TO ENTRY WORD 1 IN DRIVE STATUS TABLE.
MTTPT1	0		/POINTER TO ENTRY WORD 2 IN DRIVE STATUS TABLE.
MTIOSW	0		/IO CURRENTLY UNDERWAY; NON-ZERO IF SO.
MTEMP	0
MTEMP2	0
MTDEBP	0	/POINTER TO DEB FOR CURRENTLY ACTIVE DRIVE.
MTFNAM	0	/POINTER TO FILE NAME WORD (OUTPUT FILES) OR
MTEOFS=MTFNAM	/  POINTER TO END-OF-FILE ENCOUNTERED (INPUT FILES).
MTRECS	0	/POINTER TO TOTAL RECORDS WRITTEN INTO FILE SO FAR.
MTWRDS	0	/POINTER TO COUNT OF WORDS TRANSFERRED INTO/OUT OF BUFFER SO FAR.
MTBCP1	0	/POINTER TO FIRST WORD OF RECORD (BCP WORD 1).
MTBCP2	0	/POINTER TO SECOND WORD OF RECORD (BCP WORD 2).
MTDATA	0	/POINTER TO THIRD WORD OF RECORD (FIRST DATA WORD).
MTIOM	0
MTXCT0	400000
MTLAC0	200000
MTIOTC	700000
	.TITLE DRIVE STATUS TABLE/COMMAND REGISTER-FORMAT
/
  
  
/MAG TAPE COMMAND REGISTER FORMAT:
/BITS 0-2		UNIT NUMBER (0-7)
/BIT 3		PARITY (1=ODD, 0=EVEN)
/BIT 4		CORE DUMP (1=USE CORE DUMP FORMAT, 0=USE 9-CHANNEL FORMAT)
/BIT 5		EXTENDED IRG (1=WRITE 3" GAP BEFORE RECORD)
/BITS 6-8		COMMAND
/BIT 9		CONNECT TO INTERRUPT (1=YES, 0=NO)
/BITS 10-11	DENSITY
/BITS 12-17	IGNORED BY TAPE CONTROL
  
/MAG TAPE STATUS REGISTER FORMAT:
/BIT 0		ERROR FLAG
/BIT 1		TAPE REWINDING
/BIT 2		BOT
/BIT 3		ILLEGAL
/BIT 4		PARITY ERROR
/BIT 5		EOF
/BIT 6		EOT
/BIT 7		READ-COMPARE ERROR
/BIT 8		RECORD LENGTH INCORRECT
/BIT 9		DATA REQUEST LATE
/BIT 10		BAD TAPE
/BIT 11	MAGTAPE FLAG
/DRIVE STATUS TABLE, TWO-WORD ENTRY FOR EACH TRANSPORT.
/	WORD 1 --
/BITS 0-2:   UNIT NUMBER (0-7).
/BIT 3:      PARITY FOR THIS UNIT (1=ODD, 0=EVEN).
/BIT 4:      CORE DUMP; 1 IF 9-CHANNEL, 0 IF 7-CHANNEL.
/BIT 5:      WRITE EXTENDED IRG; MUST ALWAYS BE ZERO.
/BITS 6-8:   COMMAND; MUST ALWAYS BE ZERO.
/BIT 9:      INTERRUPT ON; SHOULD ALWAYS BE ONE.
/BITS 10-11: DENSITY FOR THIS UNIT. 10-11 ON MEANS 9-CHANNEL.
/BIT 12:     HEADER LABEL WRITTEN. 0=NO, 1=YES.
/BIT 13:     FILE OPEN ON THIS DRIVE. 0=NO, 1=YES.
/BIT 14:     FILE-STRUCTURED? 0=NO, 1=YES.
/BIT 15:     DECISION MADE? 0=NO, 1=YES.
/BIT 16:     0=NO INIT, 1=INIT PERFORMED.
/BIT 17:     0=INPUT, 1=OUTPUT.
/	WORD 2 --
/BIT 0:      IS FILE DIRECTORY IN CORE? 0=NO, 1=YES.
/BIT 1:      HAS CURRENT INPUT RECORD A PERMANENT READ ERROR? 0=NO, 1=YES.
/BIT 2:      UNUSED.
/BITS 3-17:  ADDRESS OF BUFFER ASSIGNED TO THIS DRIVE; ZERO IF NO BUFFER ASSIGNED.
MTDSTB=.
	040600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	140600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	240600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	340600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	440600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	540600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	640600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
	740600			/(RCHM-005) ODD PARITY, INT ON, 800 BPI, 7 TRACK.
	0
  
	.END
