	.TITLE MTA.F
/
/ .... EDIT #7 .... 17 MAR 70
/
/MTA.F IS THE SHAREABLE VERSION (MTA.) OF THE MTF. HANDLER.
/
/MTF. FORTRAN-CALLED NON-FILE ORIENTED MAG TAPE HANDLER.
/	 BACKGROUND/FOREGROUND --- J. J. MURPHY
/*****	TIMES OUT TO DETERMINE AVAILABILITY OF TRANSPORT	*****
/*****	ALLOWS SEQUENTIAL USE BY BACKGROUND AND FOREGROUND JOBS  *****
/
/	MAGTAPE	.SCOMS
/.SCOM+22	MAGTAPE CONTINUE AFTER DELAY.
/.SCOM+116	FGRD MAGTAPE STATUS.
/.SCOM+117	BGRD MAGTAPE STATUS.
/
  
  
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.
.SCOM=100		/START OF SYSTEM COMMUNICATION TABLE.
.MED=3		/MONITOR ERROR DIAGNOSTIC.
	.GLOBL MTA.	/BACKGROUND/FOREGROUND REQUIRES THAT SHARED
MTA.=.			/HANDLERS MUST BE THE "A" VERSION.
MTF.	JMS SWAP		/WD0 --- PROVIDES FOR SEQUENTIAL USE BY BGRD AND FGRD.
	0		/WD1-FGRD BUSY REG.
	0		/WD2-BGRD BUSY REG.
	0		/WD3-FGRD .CLOSE REG.
	0		/WD4-BGRD .CLOSE REG.
MTSWCH	XX		/WD5-ION OR IOF (STATE OF PIC ON INTERRUPT OR CAL ENTRIES.)
MTWRD6	XX		/WD6-C(WD5) ON CAL ENTRIES, DBR ON INTERRUPT ENTRIES.
MTOUT	XX		/WD7-RETURN POINTER
/START OF BACKUP DATA REGISTERS.  THESE ARE
/ALSO THE LIVE DATA REGISTERS FOR THIS
/DEVICE HANDLER.
MTWD10	XX		/WD10-JMP FUNCTION
	XX		/WD11-CAL OWNER(0=F,1=B)
MTIOAC	XX		/WD12-DAT SLOT # --- MAGTAPE COMMAND.
MTUNIT	XX		/WD13-UNIT#(0-2) CAL ADRR.(3-11)
MTWD14	XX		/WD14 --- THE CONTENTS OF
MTLBH	XX		/WD15 --- THESE FOUR REGISTERS
MTWD16	XX		/WD16 --- VARY ACCORDING TO
MTWD17	XX		/WD17 --- THE FUNCTION IN PROGRESS.
/END OF BACKUP (LIVE) DATA REGISTERS
/BEGINNING OF FUNCTION DISPATCH TABLE
	JMP MTINIT	/ 1 -- INIT
	JMP MTIGN		/ 2 -- OPER (FSTAT, DLETE, RENAM)---IGNORED
	JMP MTIGN		/ 3 -- SEEK --- IGNORED
	JMP MTIGN		/ 4 -- ENTER --- IGNORED
	JMP MTCLER	/ 5 -- CLEAR 
	JMP MTCLOS	/ 6 -- CLOSE
	JMP MTMTAP	/ 7 -- MTAPE
MTLRD	JMP MTREAD	/10 -- READ (.REALR)
MTLWR	JMP MTWRIT	/11 -- WRITE (.REALW)
MT.MED	.MED		/12 -- WAIT, WAITR NEVER GET TO I/O HANDLER.
	JMP MTTRAN	/13 -- TRAN
SCOM35	XX		/STORAGE FOR .SCOM+35
	MTSTPF		/STOP FGRD I/O SUBROUTINE.
	MTSTPB		/STOP BGRD I/O SUBROUTINE.
	0		/HANDLER ID
/INITIALIZE MAG TAPE UNIT.
/CALLING SEQUENCE:
/	CAL+DIRECTION(8)+DAT(9-17)
/	1
/	RESTART
/	BUFSIZ
/WHERE DIRECTION IS 0 FOR INPUT, 1 FOR OUTPUT.
MTINIT	LAC (70		/56(10) IS STANDARD
	DAC* MTWD16	/BUFFER SIZE.
MTSETP	LAC* (.SCOM+55	/ONCE ONLY CODE.
MTTMP1	DAC MTSETP	/CALL .SETUP TO
MTWCRS	JMS* MTSETP	/TIE HANDLER TO
MTEMP1	MTSF		/SKIP CHAIN OR
MTAC	MTINT		/API CHANNEL REGISTER.
MTSTAT	LAC MTCARS	/MTTMP1 THRU MTCARS
MTSAVE	DAC MTSETP	/ARE NOW USED FOR
MTCARS	JMP MTARND	/OTHER THINGS.
MTARND	LAC* (.SCOM+4	/7 OR 9 CHANNEL
	RAR		/DEFAULT IN BIT 6
	RTR		/OF .SCOM+4
	RTR
	AND MTL100	/MOVE TO BIT 11 AND
	DAC MTEMP1	/SAVE FOR LATER.
	JMS MTDRVE	/DRIVE STATUS TABLE ENTRY.
	AND MTSPEC	/737474
	XOR MTDFLT	/ODD PARITY, 800 BPI
	XOR MTEMP1	/0=7 CHAN,1=9 CHAN (BIT 11)
MTDBR0	DAC* MTTPTR	/TABLE ENTRY COMPLETE.
	JMP MTIGN
	.EJECT
/EXECUTE CLEAR ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	5
MTCLER	JMS MTDRVE	/GET DRIVE STATUS TABLE ENTRY.
/PREPARE TO REWIND
/AND WRITE TWO EOF'S.
	LAC MTRWDC	/GET REWIND COMMAND.
	TAD* MTTPTR	/PLUS UNIT.
	JMS MTRDWR	/NOW TRY TO PERFORM REWIND.
	SKP!RTL
	JMP .+3
	SMA		/SKIP IF BOT.
	JMP MTIOP4	/RETURN ON ILLEGAL.---DEVICE (UNIT) NOT READY.
	JMS MTEOF		/WRITE EOF.
	JMS MTEOF		/WRITE 2ND EOF
/2 EOF'S WRITTEN, REWIND AGAIN.
	JMP MTRWDF
	.EJECT
  
  
/EXECUTE CLOSE ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DAT(9-17)
/	6
MTCLOS	JMS MTDRVE	/GET DRIVE STATUS TABLE ENTRY.
	RAR
	SNL
	JMP MTIGN		/INPUT FILE.
	JMS MTEOF		/ONE EOF.
	JMS MTEOF		/2ND EOF.
/COME HERE TO BACKSPACE ONE.
MTCLS2	JMS MTBACK	/ONE RECORD TO BACKSPACE.
	JMP MTEMPT
/SUBROUTINE TO WRITE ONE
/EOF IN EVEN PARITY.
MTEOF	0
	LAC MTWEFC	/EOF COMMAND.
	XOR* MTTPTR	/PLUS UNIT.
	AND (737777	/FORCE EVEN PARITY.
	JMS MTRDWR	/WRITE EOF.
	JMP MTIOP4	/RETURN ON ILLEGAL.
	JMP* MTEOF
	.EJECT
  
  
/EXECUTE MTAPE COMMAND.
/CALLING SEQUENCE:
/	CAL+SUBFUNCTION(5-8)+DAT(9-17)
/	7
/WHERE SUBFUNCTION IS:
/0-7:	MANIPULATIVE REQUEST.
/10-17:	PARITY/DENSITY/TRACK-COUNT SETTING.
MTMTAP	JMS MTDRVE	/GET DRIVE STATUS TABLE ENTRY.
	LAC MTWD14	/SUBFUNCTION CODE
	TAD (MTAPDS	/START OF SUBFUNCTION DISPATCH TABLE.
	DAC MTMODE	/SAVE DISPATCH ADDRESS.
	LAC* MTMODE	/PICK UP MTAPE FUNCTION.
	SPA		/SKIP IF FUNCTION 10-17.
	XCT* MTMODE	/JMP TO FUNCTIONS 0-7.
	LAC* MTTPTR	/10-17, PICK UP CURRENT ENTRY IN MTDSTB.
	AND MTFORM	/CLEAR OUT PREVIOUS FORMAT BITS.
	XOR* MTTPTR	/..
	XOR* MTMODE	/INSERT NEW VALUES.
	JMP MTDBR0	/UPDATE TABLE AND RETURN
/MTAPE FUNCTION DISPATCH TABLE.
/GROUP I -- MANIPULATIVE REQUESTS.
MTAPDS	JMP MTRWDF	/00 -- REWIND
	JMP MTERR6	/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.
MTL100	100		/EVEN, 556 BPI, 7-CHANNEL.
MTL200	200		/EVEN, 800 BPI, 7-CHANNEL.
MTL300	300		/EVEN, 800 BPI, 9-CHANNEL.
MTPAR	40000		/ODD,  200 BPI, 7-CHANNEL.
MTSTND	40100		/ODD,  556 BPI, 7-CHANNEL.
	40200		/ODD,  800 BPI, 7-CHANNEL.
MTFORM	40300		/ODD,  800 BPI, 9-CHANNEL.
/DEFAULT VALUES SETUP.
MTDFLT=MTFORM-1		/DEFINE DEFAULT AS 7-CHANNEL.
	.IFDEF MT9CHN
MTDFLT=MTFORM		/BUT REDEFINE IMMEDIATELY IF 9-CHANNEL P.T.
	.ENDC
	.EJECT
  
  
  
  
/COME HERE TO PERFORM MTAPE BACKSPACE (MTAPE 02).
MTBSPF	LAW 17776		/ALLOW INPUT.
	AND* MTTPTR
	DAC* MTTPTR
	JMP MTCLS2
/SUBROUTINE TO BACKSPACE ONE RECORD.
MTBACK	0
MTMIN1	LAW -1
	DAC* MTWCR	/ONE RECORD TO BACKSPACE.
	LAC MTBSPC	/BACKSPACE COMMAND.
	TAD* MTTPTR	/PLUS THIS UNIT.
	JMS MTRDWR	/GO DO IT.
	SKP!RTL		/ILLEGAL
	JMP* MTBACK	/ALL DONE.
	SPA		/SKIP IF NOT BOT.
	JMP* MTBACK	/BOT, RETURN.
	JMP MTIOP4	/NOT BOT, PUBLISH IOPS 4.
	.EJECT
/COME HERE TO REWIND (MTAPE 00)
MTRWDF	LAC MTSETP
	SMA
	JMP MTER60	/.INIT NOT DONE.
	JMS MTSTAL	/ALLOW FOR DRIVE SETTLING DOWN.
	LAW 17776		/ALLOW INPUT.
	AND* MTTPTR
	DAC* MTTPTR	/UNIT
	MTCR
	JMP MTNOT
	TAD MTRWDC	/REWIND COMMAND
	XOR MTENI		/DISABLE INTERRUPT
	MTLC		/LOAD COMMAND REG.
	MTTR
	JMP MTNOT
	MTGO		/SET GO.
	JMP MTIGN		/EVERYTHING OK --- CLEAR FLAGS, EXIT.
MTNOT	LAW -1
	DAC MTTRSW	/FORCE ILLEGAL.
	LAC MTRWDC	/ILLEGAL--RETRY
	TAD* MTTPTR	/IN NORMAL MANNER(ON INTERRUPT)
	JMS MTRDWR
	JMP MTIOP4	/ILLEGAL
	JMP MTEMPT
	.EJECT
/COME HERE TO SPACE FORWARD ONE RECORD (MTAPE 05).
MTFSPF	LAC* MTTPTR	/GET STATUS FOR THIS UNIT.
	RAR		/MAKE SURE UNIT IS INPUT.
	SZL!CLA!CMA	/SKIP IF SO.
	JMP MTERR6	/ERROR OTHERWISE.
	DAC* MTWCR	/SET UP WORD COUNT (-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 MTEMPT	/NO ERROR, RETURN.
	AND MTWRTC	/EXTRACT EOT BIT.
	SNA		/SKIP IF EOT.
	JMP MTEMPT	/IGNORE OTHER ERRORS.
	JMP MTER12
/COME HERE TO WRITE A TAPE MARK (MTAPE 04).
MTWEOF	JMS MTEOF
MT776=.
	LAW 17776		/DON'T ALLOW
	AND* MTTPTR	/INPUT.
	XOR (1
	DAC* MTTPTR
	JMP MTEMPT
	.EJECT
  
  
/READ MAG TAPE.
/CALLING SEQUENCE:
/	CAL+MODE(6-8)+DAT(9-17)
/	10
/	LINE BUFFER ADDRESS
/	WORD COUNT MAX
MTREAD	LAW -10
	DAC MTRTRY	/RETRY COUNT.
	LAC MTWD14	/DATA MODE
	TAD (MTMODE+1
	DAC MTMODE
	LAC* MTMODE
	SPA
	JMP MTERR7	/ILLEGAL DATA MODE
	DAC MTMODE
	JMS MTDRVE	/GET DRIVE STATUS TABLE ENTRY.
	RAR
	SZL		/SKIP IF INPUT
	JMP MTERR6	/OUTPUT
MTCAWC	LAW -1
	TAD MTLBH		/LINE BUFFER ADDRESS -1.
	DAC* MTCAR	/GIVE TO CURRENT ADDRESS REGISTER.
	LAC MTWD16	/AND GET WORD COUNT.
	DAC* MTWCR	/PUT IT IN WORD COUNT.
	LAC* MTTPTR
	AND MTL300
	XOR MTL300
	JMP* MTMODE	/THEN GO START UP IO IN DESIRED MODE.
	.EJECT
/READ LEIDEN-TYPE ALPHA (MODE 5).
MTRDA5	SZA		/THIS IS A 9-CHANNEL DRIVE.
	JMP MTERR7	/ILLEGAL DATA MODE IF 7-CHANNEL.
	DZM MTMODE	/INDICATE LEIDEN TRANSFER FOR ERROR PROCESSOR.
	JMP MTRDBN	/THEN GO ISSUE READ ORDER.
/READ IOPS ASCII (MODE 2).
MTRDA2=.
/READ IOPS BINARY (MODE 0).
MTRDB0	SNA!CLA		/SKIP IF 7-CHANNEL.
	LAC MTCORD	/9-CHANNEL, GET CORE-DUMP BIT.
MTRDBN	TAD MTREDC	/GET READ COMMAND.
	TAD* MTTPTR	/PLUS UNIT NUMBER, ETC.
	JMS MTRDWR	/GO READ A RECORD.
	JMP MTIOP4	/ILLEGAL.
/RETURN HERE FROM READ (IF NOT ILLEGAL) WITH MAG TAPE STATUS IN AC.
	SMA		/SKIP IF ERROR FLAG IS SET.
	JMP MTEMPT	/NO ERROR, RETURN.
	AND MTXIRG	/EXTRACT EOF BIT.
	SZA		/SKIP IF NOT EOF.
	JMP MTREOF	/EOF, SET IT UP.
	LAC MTSTAT	/RETRIEVE STATUS.
	AND (020600	/EXTRACT PARITY, BAD TAPE, DATA LATE.
	SZA		/SKIP IF NOT PAR, BT, DL.
	JMP MTRAGN	/REAL READ ERROR, TRY TO READ AGAIN.
	LAC MTSTAT	/PICK UP STATUS.
	AND MTWRTC	/END OF TAPE?
	SZA		/SKIP IF NOT.
	JMP MTREOT	/YES, GO SERVICE.
	LAC MTSTAT	/GET STATUS ONCE MORE.
	AND MTRWDC	/EXTRACT RECORD-LENGTH-INCORRECT.
	SNA		/SKIP IF RECORD-LENGTH-INCORRECT.
	JMP MTEMPT
	LAC* MTWCR	/SHORT OR LONG RECORD?
	SZA		/SKIP IF LONG RECORD.
	JMP MTEMPT	/SHORT RECORD, IGNORE.
	LAC MTMODE	/LONG RECORD. WAS THIS A LEIDEN TRANSFER?
	SNA		/SKIP IF IOPS TRANSFER.
	JMP MTEMPT	/LEIDEN, TOO BAD.
	LAW 17717		/LONG RECORD, GET HEADER.
	AND* MTLBH
	XOR (60		/SHORT BUFFER ERROR INDICATION.
MTWRD0	DAC* MTLBH	/RESTORE HEADER WORD.
	JMP MTEMPT	/THEN EXIT
MTREOF	LAC MTMODE
	SNA
	JMP MTEMPT	/MODE 5 - NO HEADER.
	LAC (2005		/END OF FILE, GET HEADER WORD 0.
MTEOT1	DAC* MTLBH	/INSERT IN LINE BUFFER.
	ISZ MTLBH		/POINT TO SECOND HEADER WORD.
	CMA		/FORM ONE'S COMPLEMENT CHECKSUM FOR THIS LINE.
	DAC* MTLBH	/PUT CHECKSUM IN LINE BUFFER.
	ISZ* MTLBH	/MAKE TWO'S COMPLEMENT.
	ISZ MTLBH		/POINT TO FIRST DATA WORD.
	DZM* MTLBH	/ZERO FIRST DATA WORD FOR FORTRAN IV.
	JMP MTEMPT	/THEN EXIT.
MTREOT	LAC MTMODE
	SNA
	JMP MTEMPT	/MODE 5 - NO HEADER.
	LAC (2006		/GET EOT INDICATOR.
	JMP MTEOT1	/THEN TREAT JUST LIKE EOF.
MTRAGN	ISZ MTRTRY	/RETRY COUNT.
	JMP MTMORE	/READ AGAIN.
MTBAD	LAC MTMODE	/FAILED 8 TIMES.
	SNA
	JMP MTEMPT	/MODE 5 - NO HEADER.
	LAW 17717
	AND* MTLBH
	XOR (20		/DATA ERROR INDICATION.
	JMP MTWRD0
MTMORE	JMS MTBACK	/BACKSPACE.
	JMP MTREAD+2	/RE-READ.
/LEGAL MODES ARE 0, 2, AND 5.
MTMODE	XX
	MTRDB0		/IOPS BINARY -- MODE 0
MTEXIT	JMP* MTF.+7	/IMAGE BINARY -- MODE 1
	MTRDA2		/IOPS ASCII -- MODE 2
MTER15	LAW 5015		/IMAGE ASCII -- MODE 3
	JMP MTERR		/DUMP -- MODE 4
	MTRDA5		/LEIDEN ALPHA -- MODE 5
L6LRD	JMP MTLRD		/ILLEGAL -- MODE 6
L6LWR	JMP MTLWR		/ILLEGAL -- MODE 7
	.EJECT
  
  
/WRITE MAG TAPE.
/CALLING SEQUENCE:
/	CAL+MODE(6-8)+DAT(9-17)
/	11
/	LINE BUFFER ADDRESS
/	WORD COUNT -- IGNORED EXCEPT FOR LEIDEN-TYPE TRANSFERS.
MTWRIT	LAW -10
	DAC MTRTRY	/RETRY COUNT.
	LAC MTWD14	/DATA MODE
	TAD (MTMOD1
	DAC MTMODE
	LAC* MTMODE
	SPA
	JMP MTERR7	/ILLEGAL DATA MODE
	DAC MTMODE
	JMS MTDRVE	/GET DRIVE STATUS TABLE ENTRY.
	AND MT776		/777776
	XOR (1		/DON'T ALLOW
	DAC* MTTPTR	/INPUT.
	JMP MTCAWC
/WRITE SPECIAL LEIDEN ALPHA
MTWRA5	SZA
	JMP MTERR7	/NOT 9-CHANNEL DRIVE.
	DZM MTMODE
	JMP MTWRBN
/WRITE IOPS BINARY
MTWRB0	SNA!CLA
MTWRA2=.-1
	LAC MTCORD
MTWRBN	TAD MTWRTC
	TAD* MTTPTR
MTWRBB	JMS MTRDWR
	JMP MTIOP4
/COME HERE ON WRITE COMPLETION. STATUS COMES BACK IN AC.
	SMA		/SKIP IF ERROR FLAG.
	JMP MTEMPT	/RETURN IF NO ERRORS.
	AND MTWRTC	/EOT BIT.
	SZA
	JMP MTER15	/MAGTAPE FULL.
MTWER1	ISZ MTRTRY	/RETRY COUNT
	JMP MTWAGN
	JMP MTBAD		/FAILED 8 TIMES.
MTWAGN	JMS MTBACK	/BACKSPACE.
	JMP MTWRIT+2	/RE-WRITE.
/LEGAL WRITE MODES ARE 0, 2, AND 5.
MTMOD1	MTWRB0
MTXCT	XCT MTEXIT
	MTWRA2
MTIOTC	700000
MTDBR	DBR
	MTWRA5
MTSPEC	737474
MTLV0	400200
  
  
  
  
/EXECUTE TRAN ON MAG TAPE.
/CALLING SEQUENCE:
/	CAL+DIRECTION(7-8)+DAT(9-17)
/	13
/	DEVICE ADDRESS (IGNORED)
/	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 MAPPED TO 0 AND 1 RESPECTIVELY.
MTTRAN	LAW -10
	DAC MTRTRY
	CLA!CMA		/SET UP CURRENT ADDRESS REGISTER.
	TAD MTLBH
	DAC* MTCAR	/..
	LAC MTWD16	/SET UP WORD COUNT REGISTER.
	DAC* MTWCR	/..
	LAC MTWD14	/TRANSFER DIRECTION.
	AND (1
	DAC MTWD14
	JMS MTDRVE	/GET DRIVE STATUS
	RAR		/L=0 IF INPUT ALLOWED.
	SNL!CLA
	JMP .+3		/INPUT OR OUTPUT ALLOWED.
	SAD MTWD14
	JMP MTERR6	/INPUT REQUEST TO OUTPUT DRIVE.
	LAC* MTTPTR	/SET DIRECTION BIT
	AND MT776		/AS A FUNCTION OF
	XOR MTWD14	/THIS REQUEST.
	DAC* MTTPTR
	AND MTL300	/IS IT 9-CHANNEL?
	XOR MTL300	/CHECK BITS 10-11 TO FIND OUT.
	SNA!CLA		/7-CHANNEL, SKIP. TURN OFF CORE DUMP.
	LAC MTCORD	/9-CHANNEL, TURN ON CORE DUMP.
	DAC MTEMP1	/AND SAVE CORE-DUMP BIT FOR LATER.
	LAC MTWD14	/PICK UP TRANSFER DIRECTION.
	SAD (1		/0=INPUT, 1=OUTPUT.
	LAC MTREDC	/MANUFACTURE WRITE COMMAND.
	TAD MTREDC	/READ COMMAND.
MTRANO	TAD* MTTPTR	/PICK UP UNIT.
	TAD MTEMP1	/AND CORE-DUMP INDICATOR.
	JMS MTRDWR	/THEN GO START UP IO.
	JMP MTIOP4	/RETURN HERE IF ILLEGAL.
	SMA
	JMP MTEMPT	/NO ERROR
	AND MTWRTC	/EOT BIT
	SZA
	JMP MTER15	/MAGTAPE FULL.
	LAC MTSTAT
	AND (020600
	SNA
	JMP MTEMPT
	ISZ MTRTRY	/READ/WRITE ERROR.
	SKP
	JMP MTEMPT	/FAILED 8 TIMES
	JMS MTBACK	/BACKSPACE.
	JMP MTTRAN+2	/RE-TRY.
	.EJECT
/DRIVE STATUS TABLE.
/BITS 0-2:   UNIT NUMBER (0-7).
/BIT 3:      PARITY FOR THIS UNIT (1=ODD, 0=EVEN).
/BIT 4:      CORE DUMP; MUST ALWAYS BE ZERO.
/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.
/BITS 12-16: UNUSED.
/BIT 17:     0=INPUT ALLOWED NOW.
MTDSTB=.
	.REPT 10,100000
	040400
/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.
MTENI	400		/INTERRUPT ENABLED.
MTWCR	32		/WORD COUNT.
MTCAR	33		/CURRENT ADDRESS.
MTXIRG	10000		/EXTENDED IRG.
MTCORD	20000		/CORE DUMP.
	.EJECT
/MAG TAPE INTERRUPT SERVICE.
MTINT	SKP			/SKIP IF PIC ENTRY.
	JMP MTAPI			/API ENTRY
	DAC MTAC			/SAVE AC
	LAC* MTZERO		/SAVE PC,L,EM,MP
	DAC MTOUT
	LAC MTIONL		/GET ION CODE
	JMP MTSETI
MTAPI	DAC MTAC			/SAVE AC
	LAC MTINT			/SAVE PC,L,EM,MP
	DAC MTOUT
	DZM MTINT			/0=API ENTRY
	IORS
	SMA!CLA
	LAW 17740			/PIC OFF - BUILD IOF
	TAD MTIONL		/PIC ON - ION
MTSETI	DAC MTSWCH
	LAC* (.SCOM+35		/SAVE STATUS OF
	DAC SCOM35		/.SCOM+35 AND
	CLA!CMA			/SET IT TO
	DAC* (.SCOM+35		/NON-0.
	LAC MTINT
	SZA
	DZM* MTZERO		/PIC ENTRY.
	LAC MTF.+11		/1=BGRD; 0=FGRD.
	TAD (.SCOM+116
	DAC MTSTAT
	MTRS
	DAC* MTSTAT		/SAVE STATUS FOR USER.
	DAC MTSTAT		/SAVE STATUS.
	MTAF			/CLEAR FLAG.
MTIONL	ION			/ENABLE PIC.
	LAC MTDBR
	DAC MTWRD6
	DZM MTSTPS		/CLEAR STOP I/O SWITCH.
	LAC MTF.+1
	SNA			/DO NOT CONTINUE I/O
	JMP MTEMPT		/IF FLAG=0
	LAC MTSTAT		/CHECK STATUS
	SMA			/SKIP IF ERROR.
	JMP MTISVC		/NO ERROR.
	AND MTPAR			/EXTRACT ILLEGAL BIT.
	SNA			/SKIP IF ILLEGAL.
MTISVC	ISZ MTRDWR
	LAC MTSTAT		/PICK UP STATUS.
	JMP* MTRDWR
	.EJECT
/SET UP SWITCHES IN PROTECTED EXIT ROUTINE
/TO CLEAR FOREGROUND AND BACKGROUND BUSY FLAGS
/AND PLACE IOF IN MAGTAPE IOT REGISTER
/SO THAT NO NEW I/O WILL BE STARTED.
/
MTEMPT	JMS CLFLAG
/IS THIS DEVICE INVOLVED IN I/O BUSY SITUATION.
MT31	JMS MTHUNG		/I/O BUSY TEST.
/
/WAS THIS I/O A REAL TIME REQUEST.
	LAC MTWD17		/NON-0 IF
	SNA			/REAL TIME
	JMP MTNOR
	LAC MTWD10		/JMP FUNCTION
	SAD L6LRD
	SKP			/.REALR
	SAD L6LWR
	SKP			/.REALW
	JMP MTNOR			/NOT REAL TIME.
	LAC* (.SCOM+51		/REAL TIME
	DAC MTTMP1		/PROCESSOR.
	JMS MTRAIS		/RAISE TO LV0, IOF
	LAC MTWD17		/LEV, ADDR
	JMS* MTTMP1
MTDOWN	JMS MTLOWR		/DBK, ION
/COMMON EXIT SEQUENCE FOR CAL LEVEL
/AND INTERRUPT LEVEL ENTRIES.
/
MTNOR	LAC* (.SCOM+54		/ADDRESS OF
	DAC MTTMP1		/CALL4.
	JMS MTRAIS		/RAISE TO LV0, IOF
	LAC MTWRD6
	SAD MTDBR
	SKP			/INTERRUPT
	JMP MT.6			/CAL
	JMS* MTTMP1
	MTF.+7
	SCOM35
MT.6	LAC SCOM35		/RESTORE IN INTERRUPT
	DAC* (.SCOM+35		/HANDLER FLAG
MTFCLR	NOP			/NOP'S IF BUSY
MTBCLR	NOP			/FLAGS NOT TO BE CLEARED.
	LAC MTNOP			/RESET SWITCHES.
	DAC MTFCLR
	DAC MTBCLR
	LAC MTIOF
	SAD MTIOT
	JMP MTIOT
	LAC MTIOAC		/AC TO
	MTLC			/COMMAND REGISTER.
MTIOT	XX			/MTGO OR IOF
	LAC MTAC			/RESTORE AC.
	DBK			/FROM LV0
	XCT MTF.+5		/ION OR IOF
	XCT MTF.+6		/ION OR IOF OR DBR
	XCT MTXCT			/RETURN POINTER.
	.EJECT
/COME HERE TO SET UP ALL ACTUAL
/MAGTAPE OPERATIONS VIA
/JMS MTRDWR
/
MTRDWR	0
	DAC MTIOAC		/COMMAND.
	JMS MTSTAL		/ALLOW FOR SETTLING DOWN TIME.
	LAC MTRDWR		/IN CASE
	DAC MTSAVE		/NOT READY
	LAC* MTWCR		/AND OPERATION
	DAC MTWCRS		/TO BE PERFORMED
	LAC* MTCAR		/AFTER ^R.
	DAC MTCARS
	LAC MTGOL			/SET UP TO
	DAC MTIOT			/TURN ON GO.
	JMP MTNOR
/
/SUBROUTINE TO RAISE TO API LEVEL 0
/AND TURN OFF PIC.
MTRAIS	0
	LAC MTLV0			/400200
	ISA
MTIOF	IOF
	JMP* MTRAIS
/
/SUBROUTINE TO DEBREAK FROM API LEVEL 0
/AND TURN ON PIC.
MTLOWR	0
	DBK
	ION
	JMP* MTLOWR
	.EJECT
/TERMINAL ERROR PROCESSOR.
/
MTER60	LAW 5060			/.INIT NOT EXECUTED.
	SKP
MTER12	LAW 5012			/EOT DURING SPACE FORWARD OPERATION.
	SKP
MTERR7	LAW	5007		/ILLEGAL DATA MODE.
	SKP
MTERR6	LAW	5006		/ILLEGAL FUNCTION
MTERR	DAC MTLAW
	LAC MTUNIT		/CAL ADDRESS AND UNIT.
	DAC MTAUX
	LAC MTF.+11
	SZA
	LAC MTRCMC		/BGRD JOB
	XOR MTLAW
	DAC MTLAW
	LAC* (.SCOM+66		/ERROR PROCESSOR
	DAC MTTMP1
	JMS MTRAIS		/LV0, IOF
MTRTRY=.				/RETRY COUNTER.
MTLAW	XX
	JMS* MTTMP1
MTTPTR=.				/DRIVE STATUS TABLE ENTRY POINTER.
MTAUX	XX			/AUXILLARY INFO.
	JMS	MTLOWR		/DBK, ION
/
MTIGN	JMS CLFLAG		/CLEAR BUSY FLAGS.
	JMP MTNOR
	.EJECT
/COME HERE WHEN DEVICE (UNIT) NOT READY.
/
MTIOP4	LAC MTIOF			/DEFER IOT
	DAC MTIOT			/WITH IOF.
	LAC MTCTLR
	SZA!CMA
	JMP MTNOR			/AVOID DUPLICATE CALL.
	DAC MTCTLR		/SET ^R FLAG.
	LAC MTF.+11		/0=FGRD, 1=BGRD.
	DAC MTARG1
	LAC MTUNIT		/UNIT # (BITS 0-2)
	DAC MTARG3
	LAC* (.SCOM+64		/POINTER TO ^R QUEUER
	DAC MTTMP1
	JMS MTRAIS		/LV0, IOF
	JMS* MTTMP1
MTARG1	XX			/0=FGRD, 1=BGRD
	.ASCII /MT/
	.LOC .-1
MTARG3	XX			/UNIT # (BITS 0-2)
	MTFRA+100000
	MTFRA+100000
	DZM MTCTLR		/TERMINAL ERROR.
	JMP MTDOWN
/
/SUBROUTINE ENTERED AT MAGTAPE API LEVEL,
/PIC OFF, WHEN ^R FROM KEYBOARD
/IS ASSOCIATED WITH MAGTAPE.
/
MTFRA	0
	LAC MTSAVE		/RESTORE
	DAC MTRDWR		/CONTINUE ADDRESS.
	DZM MTCTLR		/CLEAR ^R FLAG
	LAC MTWCRS		/RESTORE WC
	DAC* MTWCR		/AND CA DATA
	LAC MTCARS		/CHANNEL REGS.
	DAC* MTCAR		/
	LAC MTIOAC		/COMMAND TO
	MTLC			/COMMAND REG.
MTGOL	MTGO			/TURN ON GO
	DBR
	ION
	JMP* MTFRA
	.EJECT
/SUBROUTINE TO SET UP CLEARING OF THE
/FGRD AND BGRD BUSY FLAGS (AT PROTECTED
/EXIT TIME) AND NULL (IOF) THE MTGO
/IOT REGISTER.
CLFLAG	0
	LAC MTFBSY		/DZM MTF.+1
	DAC MTFCLR
	LAC MTBBSY		/DZM MTF.+2
	DAC MTBCLR
	LAC MTIOF			/IOF
	DAC MTIOT
	JMP* CLFLAG
/SUBROUTINE TO CALCULATE ENTRY ADDRESS
/IN DRIVE (UNIT) STATUS TABLE.
MTDRVE	0
	LAC MTSETP
	SMA
	JMP MTER60		/.INIT FOR .SETUP NOT DONE.
	LAC MTUNIT		/UNIT# BITS 0-2
	RTL
	RTL			/MOVE TO BITS 15-17
	AND (7			/MASK
	TAD (MTDSTB		/ADD BASE ADDRESS
	DAC MTTPTR		/OF DRIVE STATUS TABLE.
	LAC* MTTPTR		/RETURN WITH ENTRY IN AC.
	JMP* MTDRVE
/THIS SUBROUTINE IS EXECUTED BY THE CAL HANDLER
/VIA WORD 0 OF THIS I/O HANDLER JUST PRIOR
/TO GIVING CONTROL TO THE HANDLER AT THE
/APPROPRIATE ENTRY IN THE FUNCTION DISPATCH TABLE.
SWAP	0
	LAC MTLV0			/SET BOTH BUSY FLAGS
	DAC MTF.+1		/TO LOCK OUT
	DAC MTF.+2		/FOREGROUND WHEN BACKGROUND IS USING MAGTAPE.
	XCT MTF.+5		/RESTORE P.I. STATE.
	DBK			/FROM LEVEL 0
	JMP* SWAP
	.EJECT
/STOP FOREGROUND I/O SUBROUTINE.
MTSTPF	0
	LAC MTF.+11		/0=FGRD
	SZA
	JMP* MTSTPF
	JMS MTSTP			/STOP FGRD I/O
	LAC MTSTPS		/WAIT FOR
	SZA			/I/O TO
	JMP .-2			/INTERRUPT.
	JMP* MTSTPF
/STOP BACKGROUND I/O SUBROUTINE.
MTSTPB	0
	LAC MTF.+11		/1=BGRD
	SNA
	JMP* MTSTPB
	JMS MTSTP			/STOP BGRD I/O
	LAC MTSTPS		/WAIT FOR
	SZA			/I/O TO
	JMP .-2			/INTERRUPT.
	JMS MTHUNG
	JMP* MTSTPB
/SUBROUTINE CALLED TO EFFECT TERMINATION
/OF I/O IN PROGRESS.
MTSTP	0
/ABORT	.TIMER --- CANCEL ANY SETTLING DOWN CLOCK INTERVAL.
	CAL+1000
	14
	ELAPSC+300000
MTSTPS	0			/STOP I/O SWITCH.
/ABORT	.TIMER
	CAL+1000
	14
	ELAPSI+300000
MTCTLR	0			/^R IN PROGRESS IF NON 0
	JMS MTRAIS		/LV0, IOF
	LAC MTCTLR		/WATCH FOR ^R IN PROGRESS.
	SNA!CLA
	LAC MTF.+1
	DAC MTSTPS		/NON-0 IF I/O UNDERWAY.
MTFBSY	DZM MTF.+1		/CLEAR I/O BUSY
MTBBSY	DZM MTF.+2		/FLAGS.
	DZM MTF.+3		/CLEAR .CLOSE
	DZM MTF.+4		/SWITCHES.
	DZM MTCTLR		/CLEAR ^R FLAG.
	DZM MTTRSW		/NOT READY FLAG.
	DZM* (.SCOM+22		/CONTINUE POINTER.
	DBK
	ION
	JMP* MTSTP
MTTRSW	0			/NOT READY FLAG.
	.EJECT
/SUBROUTINE MTSTAL, CHECK FOR CONTROL AND
/TRANSPORT READY.
/CALLING SEQUENCE:
/	JMS MTSTAL
/	(RETURN IF CONTROL AND UNIT READY).
MTSTAL	0
	MTCR			/CONTROL READY?
	JMP NOTRDY		/NO.
	LAC* MTTPTR		/YES. GET UNIT.
	XOR MTENI			/DISABLE INTERRUPT.
	MTLC			/LOAD COMMAND REG.
	MTTR			/TRANSPORT READY?
	JMP .+3			/NO.
MTCONT	DZM MTTRSW		/YES. CLEAR NOT-
	JMP* MTSTAL		/READY COUNTER; EXIT.
	MTRS
	RAL
	SPA
	JMP NOTSET		/REWINDING
NOTRDY	LAC MTTRSW
	SZA!CLA!CMA
/DO I/O --- IOPS 4 WILL RESULT.
	JMP MTCONT
	DAC MTTRSW
NOTSET	LAC MTWRD6
	SAD MTDBR
	JMP MTRUPT		/INTERRUPT.
	LAC* MT.MED		/L,XM,MP
	AND MTIOTC		/700000
	DAC MTTMP2
	LAC (MTTIME+200000		/SET UP
	DAC* MT.MED		/EXIT FROM CALXIT.
	LAC MTF.+13		/CAL ADDRESS
	AND (77777
	XOR MTTMP2
	DAC MTTMP2		/SAVE FOR RETURN TO CAL.
MTNOIO	LAC MTIOF			/PROHIBIT I/O.
	DAC MTIOT
	JMP MTNOR
/ROUTINE ENTERED TO SET UP TIME DELAY.
MTTIME	.TIMER 2,ELAPSC,3
	LAC MTLV0
	ISA			/RAISE/DBR TO RESTORE.
	DBR			/STATE OF MEMORY PROTECT.
	JMP* MTTMP2		/RETURN TO CAL.
	.EJECT
/SUBROUTINE ENTERED FROM CLOCK INTERRUPT
/SERVICE ROUTINE. (MAGTAPE CAL)
MTTMP2=.
ELAPSC	0
	JMS MTHUNG		/CHECK I/O BUSY.
	DZM MTF.+1		/CLEAR BUSY
	DZM MTF.+2		/FLAGS.
	DZM MTF.+3		/CLEAR .CLOSE
	DZM MTF.+4		/FLAGS.
	JMP* ELAPSC
/SUBROUTINE TO RELIEVE FGRD JOB FROM
/I/O BUSY SITUATION ON THIS DEVICE.
MTHUNG	0
	LAC* (.SCOM+52		/ADDRESS OF I/O
	DAC MTTMP1		/BUSY TESTER.
	JMS MTRAIS		/LV0,IOF.
	LAC (MTF.
	JMS* MTTMP1
	JMS MTLOWR		/DBK, ION
	JMP* MTHUNG
/CONTROL COMES HERE WHEN CONTROL (UNIT) IS
/NOT READY TO BEGIN I/O AT
/INTERRUPT LEVEL.
MTRUPT	LAC (MTTIMI+200000
	DAC* (.SCOM+22		/TESTED BY LV4 HANDLER.
	JMP MTNOIO
MTTIMI	0
	DZM* (.SCOM+22
	LAC (400020		/RAISE TO
	ISA			/LEVEL 3 TO
	.TIMER 2,ELAPSI,3		/COMPENSATE FOR DBR IN CALXIT.
	JMP* MTTIMI
/SUBROUTINE ENTERED FROM CLOCK INTERRUPT
/SERVICE ROUTINE (MAGTAPE INTERRUPT).
ELAPSI	0
	LAC	MTRDWR		/SAVE EXIT ADDRESS.
	DAC	MTTMP2
	LAC (MTNOP		/PRIME INTERRUPT SERVICE
	DAC MTRDWR		/TO EXIT MTSTAL.
	LAC* MTTPTR		/NO-OP
	MTLC			/TO COMMAND REG.
	MTGO
	JMP* ELAPSI
MTNOP	NOP
	LAC	MTTMP2		/RESTORE EXIT ADDRESS
	DAC	MTRDWR		/FROM MTRDWR SUBROUTINE.
	JMP	MTCONT
	.END
