	.SYSID <	.TITLE MTC. >,< 101>
/
/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
/+
/ 100	09-JUN-75 (RCHM)	MAKE XVM CHANGES.
/101	31-JUL-75 (JMW)		RETURN STATUS IN .SCOM+21; IN AC AFTER .WAIT.
/-
/LINKING LOADERS IN KM9 ENVIRONMENT.  1 FILE, INPUT ONLY,
/IOPS AND IMAGE MODES.
/PETE WILSON, 1-13-69
/*****	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.
	.GLOBL MTC.
MTC.	DAC MTCALP	/SAVE POINTER TO CAL.
	DAC MTARGP	/AND TO ARGUMENT LIST.
	ISZ MTARGP	/BUMP ARGUMENT POINTER TO UNIT AND FUNCTION.
	LAC (.MED+1	/SET UP IOPS ERROR NUMBER.
	DAC MTERNO	/..
/SECTION TO WAIT FOR MAG TAPE CONTROL AND UNIT READY.
	MTCR		/CONTROL READY?
	JMP MTCALR	/NO, RETURN TO CAL.
	LAC* MTARGP	/PICK UP UNIT.
	MTLC		/MOVE UNIT NUMBER TO COMMAND REGISTER.
	MTTR		/SKIP IF THE UNIT REFERENCED IS READY.
	JMP MTLOOP	/UNIT NOT READY, GO SEE WHY NOT.
	AND (17		/UNIT IS READY; EXTRACT FUNCTION CODE.
	TAD (MTDISP	/FORM ADDRESS OF APPLICABLE JMP IN DISPATCH TABLE.
	DAC MTDISP	/SAVE IT.
	LAC* MTARGP	/PICK UP UNIT AGAIN.
	RTL		/MOVE UNIT TO 15-17.
	RTL		/..
	AND (7		/THROW AWAY HIGH-ORDER JUNK.
	TAD (MTDSTB	/FIND ENTRY IN DRIVE STATUS TABLE.
	DAC MTTPTR	/SAVE POINTER TO ENTRY REFERENCED.
	LAW -1750		/RESET NOT-READY COUNTER
	DAC MTTRSW	/  FOR NEXT TIME.
	ISZ MTARGP	/MTARGP POINTS TO CAL+2 AFTER EXECUTION.
	LAC MTCALP	/SET UP MTPC IN CASE HANG ON
	DAC MTPC		/  CAL IS REQUIRED ( >1 IO OPERATION NEEDED).
	LAC* MTTPTR	/STARTING PROCESSING OF BRAND-NEW CAL, PICK UP DRIVE STATUS.
	JMP* MTDISP	/GO TO FUNCTION.
MTDISP	XX		/POINTER TO FUNCTION.
	JMP MTINIT	/ 1 -- INIT
MTSKIP	SKP		/ 2 -- OPER (FSTAT, DLETE, RENAM)
	JMP MTSEEK	/ 3 -- SEEK
MTNOP	NOP		/ 4 -- ENTER
	JMP MTERR6	/ 5 -- CLEAR
	JMP MTCLOS	/ 6 -- CLOSE
	JMP MTERR6	/ 7 -- MTAPE
	JMP MTREAD	/10 -- READ
	JMP MTERR6	/11 -- WRITE
	JMP MTWAIT	/12 -- WAIT, WAITR
	JMP MTERR6	/13 -- TRAN
MTCALR	DBR
	XCT .+1
	JMP* MTCALP
/SECTION TO WAIT FOR SETTLE-DOWN DELAY WHEN UNIT IS NOT READY.
MTLOOP	MTRS		/READ STATUS FOR SELECTED TRANSPORT.
	RAL		/MOVE REWIND INDICATOR TO SIGN.
	SMA		/THEN SKIP IF THE UNIT IS REWINDING.
	ISZ MTTRSW	/UNIT IS NOT REWINDING, COUNT THIS TIME THROUGH WAIT LOOP.
	JMP MTCALR	/THEN GO REPROCESS THE CAL.
/COME HERE ON COUNT COMPLETE. MEANS TRANSPORT MUST NOT BE AVAILABLE.
	LAW -1750		/SET UP COUNT FOR NEXT TIME.
	DAC MTTRSW	/..
	JMP MTIOP4	/THEN GO PUBLISH IOPS 4.
	.EJECT
MTBUFF	.BLOCK 401	/ROOM FOR STANDARD MAG TAPE RECORD.
MTEXBC=MTBUFF+1
MTACCM=MTBUFF+2
/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	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 MTINIT	/..
	JMP .+1		/..
MTLBH=MTINIT+1		/POINTER TO LINE BUFFER HEADER, WORD 0.
MTSTAT=MTLBH+1		/MAG TAPE STATUS ON COMPLETION OF OPERATION.
MTWRDS=MTSTAT+1		/COUNT OF WORDS TRANSFERRED FROM CURRENT BUFFER LOAD.
MTSRT2=MTWRDS		/SWITCH FOR SUCCESSFUL DEB COMPARE.
MTEOFS=MTWRDS+1		/SWITCH FOR EOF ENCOUNTERED IN THIS FILE; ZERO IF SO.
MTSRT1=MTEOFS		/POINTER TO USER'S DEB DURING .SEEK PROCESSING.
MTERSW=MTEOFS+1		/PARITY ERROR IN CURRENT INPUT RECORD; 20 IF SO, ZERO IF NOT.
MTFNAM=MTERSW+1		/FILE NAME CALCULATED DURING .SEEK PROCESSING.
MTSRCT=MTFNAM		/THREE-WORD COUNTER FOR DEB COMPARE.
MTRDP4=MTFNAM		/CURRENT-OUTPUT-WORD POINTER (IN USER'S LINE) FOR .READ'S.
	LAC* MTCALP	/CHECK IO DIRECTION, PICK UP CAL.
	AND MTRWDC	/DIRECTION IS IN BIT 8; MTRWDC = 001000.
	SZA!CLC!CCL	/SKIP IF INIT FOR INPUT.
	JMP MTERR7	/OUTPUT INIT, IOPS 7.
	TAD MTENI		/FORM BUFFER SIZE; AC = 377(8) AFTER EXECUTION.
	ISZ MTARGP	/POINT TO BUFFER SIZE LOCATION,
	DAC* MTARGP	/  AND UPDATE IT.
	ISZ MTARGP	/POINT TO RETURN.
	LAC* (.SCOM+4	/7- OR 9-CHANNEL DEFAULT?
	AND MTWRTC	/CHECK BIT 6 TO FIND OUT (MTWRTC = 004000).
	SZA!RTR		/SKIP IF 7-CHANNEL.
	TAD MTLAC0	/9-CHANNEL, INSERT CORE-DUMP BIT.
	RTR		/AND ROTATE FORMAT DIRECTIVES INTO POSITION.
	RAR		/..
/IF 9-CHANNEL, AC = 020100; IF 7-CHANNEL, AC = 000000.
	DAC MTDFLT	/SAVE DEFAULT CONDITION FOR LATER.
	LAC* MTTPTR	/CLEAR OUT PREVIOUS STATUS BITS.
	AND (60301	/..
	XOR* MTTPTR
	TAD MTSTND	/INSERT STANDARD VALUES.
	TAD MTDFLT	/THEN ADD IN 9-CHANNEL IF WANTED.
	DAC* MTTPTR	/TABLE ENTRY IS COMPLETE.
	ISZ* MTTPTR	/TURN ON INIT-PERFORMED.
MTCLOS	AND (2		/NOW EXTRACT FILE-OPEN.
	SZA		/SKIP IF NO FILE OPEN ON THIS DRIVE.
	DZM MTBFTB	/FILE IS OPEN, RELEASE ASSIGNED BUFFER.
	XOR* MTTPTR	/TURN OFF FILE-OPEN.
	DAC* MTTPTR	/AND RESTORE DRIVE STATUS.
MTDBR	DZM MTNEXT	/TURN OFF IO SEQUENCER.
	DBR		/DEBREAK,
	XCT .+1		/WAIT FOR API,
	JMP* MTARGP	/AND RETURN TO CALLER.
  
  
/SEEK FILE ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	UNIT(0-2)+3
/	ADDRESS OF DEB	/MTARGP POINTS HERE NOW.
MTSEEK	XOR MTNEXT	/ARE WE IN THE MIDDLE OF SOME I/O OPERATION?
	SAD* MTTPTR	/SKIP IF SO.
	SKP		/AND SKIP IF NOT.
	JMP* MTNEXT	/GO PERFORM NEXT TASK.
	XOR MTBFTB	/GET COUNT OF FILES CURRENTLY OPEN.
	SAD* MTTPTR	/SKIP IF A FILE IS NOW OPEN ON SOME UNIT.
	SKP!RTR		/NO FILE OPEN, SKIP.
	JMP MTER17	/FILE ALREADY OPEN, IOPS 17.
	SMA!RTL		/SKIP IF INIT PERFORMED.
	JMP MTERR7	/ERROR OTHERWISE.
/GO REWIND AND SEARCH DIRECTORY.
	TAD MTRWDC	/PLUS REWIND COMMAND.
	JMS MTRDWR	/GO ISSUE REWIND.
	SZL		/ILLEGAL RETURN; SKIP IF NOT BOT.
	JMP MTSK03	/OK, GO READ DIRECTORY.
	JMP MTIOP4	/NOT BOT, TAKE IOPS 4.
MTSK03	JMS MTNEXT	/WAIT FOR DRIVE.
/NOW READ THE FILE DIRECTORY IN.
	JMS MTINPT	/ISSUE READ REQUEST.
	AND MTXIRG	/EXTRACT EOF-ENCOUNTERED.
	SZA!CLL!CML	/SKIP IF EOF NOT ENCOUNTERED; MEANS OLD-STYLE DIRECTORY.
	JMP MTSK03+1	/NEW-STYLE DIRECTORY, GO READ DIRECTORY BLOCK PROPER.
/DIRECTORY IS IN CORE. MAKE SURE DIRECTORY FORMAT IS CORRECT (BCP WORD 1
/SHOULD EQUAL 747377; MAG TAPE WORD COUNT REGISTER SHOULD EQUAL ZERO).
	LAW 3577		/SET UP AC TO LOOK LIKE DIRECTORY BCP 1.
	RAL		/AC = 747377 AFTER EXECUTION.
	XOR MTBUFF	/COMPARE WITH BCP WORD 1.
	SZA		/SKIP IF SUCCESSFUL COMPARE.
	JMP MTER41	/BCP 1 .NE. 747377, IOPS 41.
	SAD* MTWCR	/NOW ENSURE THAT RECORD LENGTH IS 401(8).
	SKP!CLA!CMA	/RECORD LENGTH IS OK, SKIP.
	JMP MTER41	/BAD RECORD LENGTH, IOPS 41.
/SEEMS LIKE IT REALLY IS A DIRECTORY BLOCK; SEARCH DIRECTORY FOR NAME OF
/FILE BEING SOUGHT.
	XOR MTL777	/TURN OFF BITS 0-8; BITS 9-17 = 777.
	AND MTBUFF+2	/EXTRACT ACTIVE FILE COUNT.
	TAD MTL777	/FILL UP LEFT HALF.
	DAC MTCACT	/SAVE ONE'S COMPLEMENT ACTIVE COUNT.
/SET UP ADDRESS OF FIRST FILE-NAME ENTRY.
	LAC MTSRS1	/PICK UP "LAC MTBUFF+2"; IT WILL BE USED TO GET
	DAC MTEXPT	/   SUCCESSIVE WORDS IN ACCESSIBILITY MAP.
	TAD (17		/THEN MAKE IT "LAC MTBUFF+21"
	DAC MTSRL2	/  AND USE THAT TO ACCESS THE FILE-NAME SECTION.
	DZM MTACCM	/ZERO RELATIVE-FILE-POSITION COUNTER.
/NOW BEGIN THE SEARCH.
MTSRL1	LAW -3		/COUNT THREE WORDS EACH ENTRY.
	DAC MTSRCT	/..
	LAC* MTARGP	/POINTER TO DEB GOES TO
	DAC MTSRT1	/  INTERNAL POINTER.
	ISZ MTCACT	/COUNT FILE NAMES CONSIDERED.
	SKP		/MORE TO DO.
	JMP MTER13	/FILE NOT FOUND, IOPS 13.
	DZM MTSRT2	/SUCCESSFUL-COMPARE SWITCH.
/ENTER LOOP TO COMPARE THE DEB PROVIDED BY CALLER WITH THE DEB CURRENTLY
/UNDER CONSIDERATION IN THE DIRECTORY.
/THE FOLLOWING INSTRUCTION WAS SET UP AT MTSRL1-2 AND IS MODIFIED AT
/MTSRL2+3.
MTSRL2	LAC MTBUFF+21	/LAC MTBUFF+21,+22,...,+400
MTEXPC=.-1
MTSKEF=.-1		/SWITCH FOR LAST-ENCOUNTERED RECORD WAS EOF DURING SEEK; NON-ZERO IF SO.
MTDFLT=.-1
MTRDP3=.-1		/CURRENT-INPUT-WORD POINTER FOR READ.
	XOR* MTSRT1	/COMPARE CORRESPONDING WORDS IN TWO DEB'S.
	ISZ MTSRT1	/BUMP POINTER TO CALLER'S DEB.
	ISZ MTSRL2	/AND ADDRESS PORTION OF THE LAC OF DIRECTORY WORD.
	SZA		/NOW SKIP IF THE TWO WORDS MATCHED.
	DAC MTSRT2	/TWO WORDS DID NOT COMPARE; TURN OFF GOOD-COMPARE SWITCH.
	ISZ MTSRCT	/COUNT WORDS CONSIDERED IN THIS DEB.
	JMP MTSRL2	/MORE TO DO, GO BACK AND CHECK NEXT PAIR.
/COMPARED THREE WORDS, CHECK FOR SUCCESS.
	LAC MTSRT2	/MTSRT2 .E. 0 IF ALL THREE WORDS MATCHED.
	SNA!CLA!CMA	/SKIP IF BAD COMPARE.
	JMP MTSRFD	/GOOD COMPARE.
	ISZ MTACCM	/FILE NAME MISMATCH, INDEX DEB-POSITION COUNTER.
	JMP MTSRL1	/THEN GO BACK TO CHECK NEXT ENTRY IN MAG TAPE DIRECTORY.
/COME HERE ON FILE NAME FOUND IN DIRECTORY. TRANSLATE FILE-NAME POSITION
/IN DIRECTORY (IN REGISTER MTACCM) INTO PHYSICAL FILE POSITION ON TAPE.
/IDEA IS TO COUNT BITS IN THE ACCESSIBILITY MAP UNTIL THE NTH ONE-BIT
/IS FOUND.
MTSRFD	XOR MTACCM	/FORM 2'S COMPLEMENT FILE-NAME POSITION IN DIRECTORY
	DAC MTACCM	/  (AC .E. 777777 BEFORE EXECUTION OF XOR).
	DZM MTEXPC	/INITIALIZE PHYSICAL-FILE-POSITION COUNTER.
MTEXL1	ISZ MTEXPT	/INDEX LAC OF MAP WORD.
	LAW -22		/SET UP 18-BIT COUNTER FOR
	DAC MTEXBC	/  CURRENT WORD IN ACCESSIBILITY MAP.
/THE FOLLOWING INSTRUCTION WAS SET UP AT MTSRL1-4 AND IS MODIFIED AT MTEXL1.
MTEXPT	LAC MTBUFF+2	/LAC MTBUFF+3,+4,...,+20
MTSKCT=MTEXPT		/COUNT OF FILES TO SKIP OVER DURING TAPE SEARCH.
MTRCT1=MTEXPT		/COUNT OF WORDS IN CURRENT INPUT LINE DURING .READ PROCESSING.
MTEXL2	RAL		/CHECK ACCESSIBILITY STATUS OF NEXT PHYSICAL FILE.
	SZL		/SKIP IF THIS FILE IS INACTIVE.
	ISZ MTACCM	/FILE IS ACTIVE. IS IT THE ONE WANTED?
	SKP		/NO. RESUME SEARCH OF ACCESSIBILITY MAP.
	JMP MTEXFD	/YES. GO SCAN THE TAPE FOR THIS FILE.
	ISZ MTEXPC	/COUNT PHYSICAL FILES PRESENT.
	ISZ MTEXBC	/COUNT BITS IN MAP WORD.
	JMP MTEXL2	/LOOK AT NEXT BIT IN CURRENT MAP WORD.
	JMP MTEXL1	/THIS WORD IS EXHAUSTED; TRY NEXT WORD.
MTEXFD	LAC MTEXPC	/PICK UP POSITION OF FILE IN ACCESSIBILITY MAP.
	CMA		/INVERT,
	DAC MTSKCT	/  AND SAVE AS 2'S COMPLEMENT COUNT OF EOF'S TO SKIP.
	DAC MTFNAM	/SAVE ALSO AS FILE NAME APPEARING IN LABEL.
	DZM MTSKEF	/THEN TURN OFF EOF-ENCOUNTERED SWITCH.
MTSK05	JMS MTINPT	/SPACE OVER ONE RECORD.
	AND MTXIRG	/EOF PASSED?
	SNA		/SKIP IF SO.
	JMP MTSK05-1	/IF NOT, SPACE OVER ANOTHER RECORD.
	SAD MTSKEF	/HAVE WE SEEN 2 EOF'S IN SUCCESSION?
	JMP MTER44	/YES; UNEXPECTED LOGICAL EOT, IOPS 44.
	DAC MTSKEF	/NO, SET MTSKEF FOR TEST ON NEXT RECORD.
	ISZ MTSKCT	/AND COUNT THE FILE JUST PASSED.
	JMP MTSK05	/MORE RECORDS TO SKIP OVER.
/WE ARE NOW POSITIONED TO READ FILE HEADER LABEL.
	JMS MTINPT	/READ LABEL.
/RETURN HERE WITH LABEL IN CORE.
	LAW 10033		/CHECK BCP WORD 1.
	TAD MTBUFF	/IT SHOULD BE 007745.
	SZA!CLL!CML	/SKIP IF BCP WORD 1 IS OK.
	JMP MTER40	/BCP WORD 1 .NE. 007745, IOPS 40.
MTSRS1	LAC MTBUFF+2	/PICK UP FILE NAME FROM LABEL.
	XOR MTFNAM	/SHOULD BE SAME AS CALCULATED NAME.
	SZA!RTL		/SKIP IF TWO NAMES MATCH.
	JMP MTER40	/BAD FILE-NAME COMPARE, IOPS 40.
	DAC MTBFTB	/INDICATE A FILE IS OPEN (AC .E. 2 NOW).
	ISZ* MTTPTR	/TURN ON FILE-OPEN.
	ISZ* MTTPTR	/AND RESTORE INIT-PERFORMED.
/ALL SET AT LAST.
MTSK06	ISZ MTARGP	/BUMP MTARGP TO POINT TO RETURN.
	JMP MTDBR		/THEN GO BACK TO CALLER.
  
  
/READ MAG TAPE.
/CALLING SEQUENCE:
/	CAL+MODE(6-8)+DAT(9-17)
/	UNIT (0-2)+10
/	LINE BUFFER ADDRESS /MTARGP POINTS HERE ON ENTRY.
/	WORD COUNT MAX
MTREAD	XOR MTNEXT	/IS IO SEQUENCER ON?
	SAD* MTTPTR	/SKIP IF SO.
	SKP!RTR		/STARTING NEW .READ, SKIP.
	JMP* MTNEXT	/MOVING TAPE, GO TO NEXT OPERATION.
	SNL		/SKIP IF A FILE IS OPEN.
	JMP MTER11	/NO .SEEK EXECUTED, IOPS 11.
	LAW 14000		/ENSURE MODE 0,1,2, OR 3.
	TAD* MTCALP	/MODE IS IN CAL, BITS 6-8.
	SMA!CLA!CCL	/SKIP IF MODE IS 0-3 (MINUS AC).
	JMP MTERR7	/ILLEGAL DATA MODE, IOPS 7.
	SAD MTEOFS	/DID EOF OCCUR ON A PREVIOUS READ REQUEST?
	JMP MTEOFP	/THERE WAS AN EOF IF MTEOFS .E. 0.
MTRIF1	LAC MTBUFF	/PICK UP CURRENT COUNT.
	TAD MTWRDS	/LESS TOTAL WORDS ALREADY READ.
	SMA!CLA!RAL	/SKIP IF MORE WORDS TO TRANSFER.
	JMP MTRFIL	/BUFFER IS EMPTY, GO REFILL IT.
	TAD (MTBUFF-1	/FIND FIRST DATA WORD.
	TAD MTWRDS	/PLUS WORDS READ SO FAR.
	DAC MTRDP3	/GIVES NEW-LINE POSITION.
MTL777	LAW 17000		/CHECK WORD COUNT.
	AND* MTRDP3	/PICK UP LINE HEADER.
	CLL!RAL		/BIT 1 TO SIGN; AC 0-8 = WORD-PAIR-COUNT * 2.
	SNA!SPA		/SKIP IF BIT 1 .E. 0, BUT TOTAL COUNT .G. 0.
	JMP MTER23	/ILLEGAL WORD PAIR COUNT (WPC .G. 177 OR 0), IOPS 23.
	DAC MTRCT1	/SAVE POSITIVE WORD COUNT.
	LAC* MTARGP	/PICK UP ADDRESS OF USER'S LINE BUFFER.
	DAC MTRDP4	/SAVE IN OUTPUT POINTER.
	DAC MTLBH		/AND IN HEADER-WORD-0 POINTER.
	ISZ MTARGP	/THEN BUMP MTARGP TO MAXIMUM WORD COUNT.
	AND (700000)		/(RCHM-100) EXTRACT HIGH ORDER ADDRESS BITS.
	SZA			/(RCHM-100) ARE ANY ON?
	JMP MTER67		/(RCHM-100) YES, GIVE INVALID MEMORY ERROR.
	LAC* MTARGP	/PICK UP COUNT.
	DAC MTRCT2	/AND SAVE IT.
/ENTER LOOP TO MOVE REQUESTED LINE FROM MAG TAPE BUFFER TO USER'S
/LINE BUFFER AREA.
MTRLP1	LAC* MTRDP3	/PICK UP NEXT WORD.
	DAC* MTRDP4	/PUT IN CALLER'S AREA.
	ISZ MTRDP3	/BUMP INPUT ADDRESS.
	ISZ MTRDP4	/AND OUTPUT ADDRESS.
	ISZ MTWRDS	/UPDATE TOTAL WORDS MOVED FROM CURRENT BUFFER LOAD.
	LAC MTRCT1	/DECREMENT COUNT OF WORDS IN LINE.
	TAD MTL777	/COUNT IS IN BITS 0-8.
	DAC MTRCT1	/SAVE NEW COUNT.
	SNA		/SKIP IF MORE TO DO.
	JMP MTRLP2	/ALL WORDS MOVED, GO FINISH UP.
	ISZ MTRCT2	/TEST UPPER LIMIT OF WORDS TO TRANSFER.
	JMP MTRLP1	/ROOM FOR MORE WORDS IN USER'S LINE.
	LAC MTRDP3	/OVERFLOWED USER'S AREA,
	DAC MTRDP4	/  TURN OFF TRANSFERS.
	JMP MTRLP1	/THEN GO CONTINUE COUNTING.
/ALL DONE, SET UP VALIDITY BITS AND RETURN.
MTRLP2	LAW 17717		/CLEAR HEADER BITS 12-13.
	AND* MTLBH	/..
	DAC* MTLBH	/..
	XOR MTERSW	/NOW CHECK FOR PARITY ERROR ON CURRENT RECORD.
	SAD* MTLBH	/SKIP IF A PARITY ERROR DID OCCUR.
	SKP		/NO ERROR, CHECK FOR LINE BUFFER OVERFLOW.
	JMP MTRLP3	/BYPASS OVERFLOW CHECKING IF PARITY ERROR.
	LAC MTRDP3	/DID OVERFLOW OCCUR?
	XOR MTRDP4	/MTRDP3 .E. MTRDP4 IF SO.
	SNA!CLA		/SKIP IF NO OVERFLOW.
	LAC (60		/OVERLOW, TURN ON BITS 12-13.
	TAD* MTLBH	/..
MTRLP3	DAC* MTLBH	/RESTORE HEADER WITH VALIDITY BITS SET.
	JMP MTSK06	/THEN RETURN TO CALLER.
/COME HERE TO REFILL INPUT BUFFER.
MTRFIL	JMS MTINPT	/READ NEXT RECORD.
	SMA		/SKIP IF ERROR ON READ.
	JMP MTCKBL-1	/NO ERROR, GO PROCESS INPUT RECORD.
	AND MTXIRG	/EXTRACT EOF STATUS BIT.
	SZA!CLA		/SKIP IF NOT EOF.
	JMP MTPTEF	/EOF, SET UP INDICATOR (AC = 0 NOW).
	LAC MTSTAT	/RETRIEVE STATUS.
	AND (020200	/EXTRACT PARITY AND BAD TAPE.
	SZA!CLL!CML	/SKIP IF NOT PARITY OR BAD TAPE.
	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, SO INDICATE (AC = 1 NOW).
	LAC MTSTAT
	AND MTENI		/EXTRACT DATA LATE.
	SZA!CLA		/SKIP IF NOT DATA LATE.
	JMP MTRAG1	/DATA LATE, REREAD WITHOUT COUNTING.
	SAD* MTWCR	/SKIP IF WORD COUNT .NE. 0.
	JMP MTER45	/WC .E. 0 MEANS LONG RECORD; IOPS 45.
	DZM MTERSW	/INDICATE NO ERRORS IN THIS RECORD.
MTCKBL	LAW 10000		/TRANSFER OK. PICK UP BCP WORD 1.
	AND MTBUFF	/EXTRACT BLOCK IDENTIFIER.
	XOR MTLAC0	/IS THIS A USER DATA BLOCK?
	SZA!CLA!CCL	/USER DATA RECORD, SKIP.
	JMP MTPTEF	/NOT USER DATA, TREAT AS EOF.
	LAC MTBUFF	/USER DATA, SET UP COUNT.
	XOR MTLAC0	/TURN OFF BIT ONE.
	TAD MTCKBL	/..
	JMP MTRRTN
/COME HERE ON EOF ENCOUNTERED.
MTPTEF	TAD (001005	/EOF OR EOT HEADER.
	DAC MTBUFF+2	/..
	CMA!CCL		/FORM CHECKSUM.
	DAC MTBUFF+3	/..
	ISZ MTBUFF+3	/MAKE TWO'S COMPLEMENT.
	DZM MTEOFS	/INDICATE EOF OR EOT ENCOUNTERED.
MTEOFP	LAW -4
MTRRTN	DAC MTBUFF
	LAC (2
	DAC MTWRDS
	LAW -25		/SET UP ERROR REREAD COUNTER
	DAC MTERCT	/  FOR NEXT TIME.
	JMP MTRIF1
/COME HERE TO SET UP REREAD. FIRST, BACKSPACE OVER ERROR RECORD.
MTRAGN	ISZ MTERCT	/COUNT THIS TIME THROUGH ERROR LOOP.
MTRAG1	SKP!CLA!CMA	/MORE REREADS ALLOWED.
	JMP MTIREC	/TOO MANY READ ERRORS.
	DAC* MTWCR	/SET UP WORD COUNT TO BACKSPACE ONE.
	LAC* MTTPTR	/BUILD BACKSPACE COMMAND.
	TAD MTBSPC	/..
	JMS MTRDWR	/GO START UP BACKSPACE.
	JMP MTRD04	/ILLEGAL, IOPS 4.
	JMS MTNEXT	/WAIT FOR SETTLE-DOWN.
	JMP MTRFIL	/THEN GO REREAD ERROR RECORD.
MTIREC	LAC (20		/20 REREAD ATTEMPTS WITHOUT SUCCESS, TURN ON BIT 13.
	DAC MTERSW	/INDICATES PERMANENT READ ERROR.
	JMP MTCKBL
MTRD04	LAC (MTRAG1
	JMP MTIOP4+1
MTER67	LAW 50			/(RCHM-100) PICK UP PRECURSOR TO IOPS 67 ERROR
	JMP MTER23+1		/(RCHM-100) GO PRINT ERROR MESSAGE.
MTER45	ISZ MTERNO	/LONG INPUT RECORD.
MTER44	LAW 25		/UNEXPECTED LOGICAL EOT FOUND ON SEEK/ENTER.
	JMP .+3		/IGNORE IOPS 42-43.
MTER41	ISZ MTERNO	/DIRECTORY FORMAT ERROR.
MTER40	LAW 21		/HEADER LABEL ERROR.
	SKP
MTER23	LAW 4		/ILLEGAL WORD PAIR COUNT.
	TAD MTERNO
	DAC MTERNO
MTER17	ISZ MTERNO	/TOO MANY FILES.
	ISZ MTERNO	/OUTPUT BUFFER OVERFLOW.
	ISZ MTERNO	/PHYSICAL EOT FOUND ON WRITE.
	ISZ MTERNO	/DIRECTORY FULL.
MTER13	ISZ MTERNO	/FILE NOT FOUND.
	ISZ MTERNO	/EOT ENCOUNTERED ON SPACE FORWARD.
MTER11	ISZ MTERNO	/SEEK-ENTER NOT EXECUTED.
	ISZ MTERNO	/FILE STILL ACTIVE.
MTERR7	ISZ MTERNO	/ILLEGAL DATA MODE.
MTERR6	ISZ MTERNO	/ILLEGAL FUNCTION.
	ISZ MTERNO	/BYPASS IOPS 5.
MTIOP4	LAC MTCALP	/PICK UP POINTER TO CAL INSTRUCTION.
	DAC* (.MED	/GIVE TO .MED.
	DZM MTNEXT	/TURN OFF IO SEQUENCER.
	LAC MTERNO	/PICK UP ERROR NUMBER.
	JMP* (.MED+1	/THEN GO TO .MED + 1.
  
  
  
/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)
	SZA		/SKIP IF WAIT.
	ISZ MTARGP	/WAITR, BUMP TO NON-BUSY RETURN.
	LAC MTSTAT	/(JMW:101) RETURN STATUS IN AC.
	JMP MTDBR		/THEN RETURN THROUGH ARGUMENT POINTER.
  
  
/SUBROUTINE MTINPT, ISSUE READ FOR STANDARD MAG TAPE RECORD.
MTINPT	0
MTCACT=MTINPT
	LAW -401		/READ 257(10) WORDS.
	DAC* MTWCR	/SET UP WORD COUNT.
	LAC (MTBUFF-1	/READ INTO BUFFER PROPER.
	DAC* MTCAR	/SET UP CURRENT ADDRESS.
	LAC* MTTPTR	/FORM A READ COMMAND.
	TAD MTREDC	/..
	JMS MTRDWR	/AND GO START UP IO.
	JMP MTIOP4	/ILLEGAL (DRIVE NOT DIALED UP), IOPS 4.
	JMS MTNEXT	/GO WAIT FOR SETTLE-DOWN.
	LAC MTSTAT	/PICK UP STATUS.
	JMP* MTINPT	/THEN RE-ENTER MAIN LINE.
  
  
/DRIVE STATUS TABLE FOR MTC.
/BITS 0-2:   UNIT NUMBER (0-7).
/BIT 3:      PARITY FOR THIS UNIT (1=ODD, 0=EVEN).
/BIT 4:      CORE DUMP; 0 IF 7-CHANNEL, 1 IF 9-CHANNEL.
/BIT 5:      WRITE EXTENDED IRG; UNUSED IN MTC.
/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.
/BITS 12-15: UNUSED.
/BIT 16:     FILE OPEN ON THIS DRIVE? 0=NO, 1=YES.
/BIT 17:     INIT PERFORMED? 0=NO, 1=YES.
MTDSTB=.
	040400
	140400
	240400
	340400
	440400
	540400
	640400
	740400
	.EJECT
  
/MAG TAPE INTERRUPT SECTION.
MTINT	SKP		/SKIP IF PIC ENTRY.
	JMP MTAPI		/API ENTRY.
	DAC MTAC		/SAVE AC.
	LAC* MTLAC0	/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		/LEAVE PIC ALONE ON EXIT.
MTSETI	DAC MTION		/SET UP EXIT INTERRUPT CONDITION.
	LAC MTSKIP	/RESTORE PIC ENTRY.
	DAC MTINT		/..
	MTRS		/READ STATUS
	DAC MTSTAT	/SAVE STATUS
	DAC* (.SCOM+21		/(JMW:101) RETURN STATUS IN .SCOM+21.
	RTL		/SKIP IF ERROR.
	RAL		/EXTRACT ILLEGAL BIT.
	SMA		/SKIP IF ILLEGAL.
	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.
	JMP* MTRDWR
/COME HERE TO PERFORM ALL ACTUAL MAG TAPE IO OPERATIONS, VIA
/"JMS MTRDWR".
MTRDWR	0		/ENTRY TO PERFORM MAG TAPE IO.
	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 MORE IO REQUIRED.
MTNEXT	0
MTRCT2=MTNEXT
	LAC MTAC		/RESTORE AC.
	JMP MTIRET	/THEN GET OUT.
	.EJECT
/UNTOUCHABLE VARIABLES. DON'T USE THESE REGISTERS FOR ANYTHING ELSE.
MTAC	0		/AC ON INTERRUPTS.
MTPC	0		/PC ON INTERRUPTS.
MTCALP	0		/POINTER TO CAL CURRENTLY IN PROCESS.
MTARGP	0		/POINTER TO CAL ARGUMENT LIST.
MTTRSW	LAW -1750		/COUNTER FOR 1000 TIMES THROUGH WAIT LOOP.
MTERCT	LAW -25		/COUNTER FOR 20 REREADS OF ERROR RECORD.
MTBFTB	0		/IS BUFFER IN USE? ZERO = NO, NON-ZERO = YES.
MTERNO	0		/IOPS ERROR NUMBER; SET TO 4 BY CAL PROCESSOR.
MTTPTR	0		/POINTER TO CURRENT ENTRY IN DRIVE STATUS TABLE.
  
/CONSTANTS --
/COMMAND REGISTER BITS 6-8.
MTRWDC	1000		/REWIND
MTREDC	2000		/READ
MTWRTC	4000		/MASK FOR EOT STATUS.
MTBSPC	7000		/SPACE REVERSE.
MTENI	400		/MASK FOR DATA-LATE STATUS.
MTWCR	32		/WORD COUNT.
MTCAR	33		/CURRENT ADDRESS.
MTXIRG	10000		/MASK FOR EOF STATUS.
MTLAC0	200000	/BLOCK IDENTIFIER FOR USER DATA RECORDS.
MTSTND	040200	/STANDARD TAPE FORMAT (7-CHANNEL, ODD PARITY, 800 BPI).
  
  
/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 MODE, 0=USE 9-CHANNEL MODE)
/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 BIT ASSIGNMENTS --
/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		MAG TAPE FLAG
	.END
