;DSK:<FOONEX>MAGTAP.JCP;1  2-Jul-80 17:37:28, Edit by PETERS
;<134-TENEX>MAGTAP.F3A;18    14-Aug-79 16:14:15    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;17    10-Aug-79 19:04:07    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;16    10-Aug-79 18:31:50    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;15     2-Aug-79 15:33:36    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;14     2-Aug-79 15:13:41    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;13     1-Aug-79 23:26:59    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;12     1-Aug-79 23:20:12    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;11     1-Aug-79 23:12:18    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;10     1-Aug-79 21:08:45    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;9     1-Aug-79 19:36:24    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;8     2-Jul-79 16:03:33    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;7    22-Jun-79 17:40:22    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;6    20-Jun-79 13:26:07    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;5    19-Jun-79 21:31:29    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;4    19-Jun-79 21:14:34    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;3    19-Jun-79 20:31:54    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;2    19-Jun-79 15:42:40    EDIT BY PETERS
;<134-TENEX>MAGTAP.F3A;1    17-Jun-79 16:55:53    EDIT BY PETERS

;TENEX MAGTAPE MODULE FOR F3A

SEARCH STENEX,PROLOG
TITLE MAGTAP

INTERN MTAINI,MTARST,MTACHK,MTASV,MTADTB
EXTERN MTATIM,CPOPJ,SKPRET,BUGHLT,DISE,BHC,EDISMS

;PARAMETERS AND DEFINITIONS FOR F3A MAGTAPE

;BITS IN RIGHT HALF MTASTS - DO NOT CHANGE - THESE ARE DEFINED BY THE
;GDSTS AND SDSTS MAGTAPE DEVICE SPECIFIC STUFF

MTAILW==400000		;LAST OPERATION WAS A WRITE AND WRITES ARE PROHIBITED
MTADVE==200000		;TIMEOUT ON LAST OPERATION
MTAIOE==100000		;LAST OPERATION SUFFERED FROM AN IO DATA ERROR
MTASAE==040000		;SUPPRESS AUTOMATIC ERROR CORRECTION
MTAEOF==020000		;EOF WAS SEEN DURING THE LAST OPERATION
MTALNE==010000		;LAST OPERATION WAS A READ AND RECORD LENGTH WAS WRONG
MTABOT==004000		;DRIVE IS AT LOAD POINT
MTAEOT==002000		;DRIVE IS AT END OF TAPE
MTAPAR==001000		;ON IF PARITY EVEN, OFF IF ODD
MTADEN==000600		;DENSITY FIELD
MTADFD==000000		;DENSITY FIELD, SYSTEM DEFAULT (HIGH)
MTALOD==000200		;DENSITY FIELD, SET LOW DENSITY
MTAMED==000400		;DENSITY FIELD, SET MEDIUM DENSITY
MTAHID==000600		;DENSITY FIELD, SET HIGH DENSITY

;VALUES IN RIGHT HALF MTAOPR - DO NOT CHANGE - THESE ARE DEFINED BY THE
;MTOPR MAGTAPE DEVICE SPECIFIC STUFF

MTAREW==000001		;REWIND TAPE
MTAWEF==000003		;WRITE EOF
MTAFSR==000006		;FOWARD SPACE ONE RECORD
MTABSR==000007		;BACK SPACE ONE RECORD
MTAUNL==000011		;REWIND AND UNLOAD
MTAERG==000013		;ERASE GAP
MTAFSF==000016		;FOWARD SPACE ONE FILE
MTABSF==000017		;BACK SPACE ONE FILE

;READ AND WRITE RECORD ARE CONSIDERED INTERNALLY HERE AS OPERATION CODES

MTARDR==000020		;READ ONE RECORD
MTAWRR==000021		;WRITE ONE RECORD

;OPDEFS FOR MAGTAPE IOTS

OPDEF MTOP[726000,,0]	;CONTROL FUNCTION IOT
OPDEF MTRS[727000,,0]	;READ STATUS IOT
OPDEF MTWR[731000,,0]	;WRITE SPECIFIED NUMBER OF WORDS IOT
OPDEF MTRD[732000,,0]	;READ SPECIFIED NUMBER OF WORDS IOT

;MICROCODE TAPE STATUS BITS RETURNED IN LH AC AFTER MTRD AND MTWR IOTS

MICFLG==400000		;SOME FLAG IS BEING RETURNED BY THE MICROCODE
MICEOF==200000		;EOF SEEN FLAG FROM MICROCODE
MICTPE==100000		;TAPE PARITY ERROR FLAG FROM MICROCODE
MICLNE==040000		;LENGTH ERROR FLAG FROM MICROCODE

;HARDWARE STATUS BIT DEFINITIONS RETURNED IN RIGHT HALF BY MTRS

HDWNLN==000040		;UNIT IS ONLINE
HDWREW==000020		;UNIT IS REWINDING
HDWFPT==000010		;UNIT IS WRITE PROTECTED
HDWBOT==000004		;UNIT IS AT LOAD POINT
HDWRDY==000002		;UNIT IS READY
HDWEOT==000001		;UNIT IS AT END OF TAPE

;STORAGE DECLARATIONS FOR MAGTAPE MODULE

LS MTASVR,1		;MAGTAPE INTERRUPT RETURN WORD
LS MTALCK,MTAN		;LOCK WORD FOR MAGTAPE UNITS
LS MTASTS,MTAN		;ZERO ELSE LH=-1, RH=DEVICE DEPENDENT STATUS BITS
LS MTAOPR,MTAN		;ZERO ELSE LH=-1, RH=PENDING OPERATION FOR THIS UNIT
LS MTAXFR,MTAN		;ZERO ELSE LAST XFER WORD FOR THIS UNIT

;INITIALIZATION AND RESTART ROUTINE

USE RESPC

MTAINI:
MTARST:	MOVSI UNIT,-MTAN	;DO THIS FOR EACH UNIT
MTARS1:	SETOM MTALCK(UNIT)	;UNLOCK LOCK
	SETZM MTASTS(UNIT)	;SAY THIS UNIT NOT OPEN
	SETZM MTAOPR(UNIT)	;SAY NO OPERATIONS PENDING ON THIS UNIT
	SETZM MTAXFR(UNIT)	;SAY NO XFERS EVER ATTEMPTED ON THIS UNIT
	AOBJN UNIT,MTARS1	;LOOP IF MORE UNITS TO INITIALIZE
	RET

;PERIODIC CHECK OF MAGTAPE - CALLED HERE FROM SCHEDULER CLOCK ROUTINE

MTACHK:	MOVEI A,^D10000		;DO THIS EVERY TEN SECONDS
	MOVEM A,MTATIM		;LEAVE FOR CLOCK COUNTDOWN
	RET			;FOR NOW THERE IS NOTHING TO CHECK...

;INTERRUPT SERVICE ROUTINE FOR MAGTAPE

MTASV:	XWD MTASVR,.+1		;JSYS HERE FROM PISRV
	JRST @MTASVR		;MAGTAPE NOT YET RUNNING IN INTERRUPT MODE

REWTST:	MTRS A			;GET TAPE UNIT STATUS TO A
	TRNE A,HDWNLN		;UNIT OFFLINE?
	TRNE A,HDWBOT		;OR NOW AT LOAD POINT?
	JRST 1(D)		;ONE OR THE OTHER, WAKE UP PROCESS
	JRST 0(D)		;NEITHER, KEEP WAITING

USE SWAPPC

;MAGTAPE DEVICE DEPENDENT DISPATCH TABLE FOR VARIOUS LOGICAL OPERATIONS

MTADTB:	CPOPJ			;SET DIRECTORY
	CPOPJ			;NAME LOOKUP
	CPOPJ			;EXTENSION LOOKUP
	CPOPJ			;VERSION LOOKUP
	CPOPJ			;FILE PROTECTION INSERTION
	CPOPJ			;FILE ACCOUNT INSERTION
	CPOPJ			;FILE STATUS INSERTION
	MTAOPN			;FILE OPEN
	CPOPJ			;SEQUENTIAL INPUT
	CPOPJ			;SEQUENTIAL OUTPUT
	MTACLZ			;FILE CLOSE
	CPOPJ			;FILE RENAME
	CPOPJ			;FILE DELETION
	MTDMPI			;DUMP INPUT
	MTDMPO			;DUMP OUTPUT
	SKPRET			;MOUNT DEVICE
	SKPRET			;DISMOUNT DEVICE
	CPOPJ			;INITIALIZE DIRECTORY
	MMTOPR			;MTOPR HANDLER
	MTAGDS			;GET DEVICE STATUS
	MTASDS			;SET DEVICE STATUS

;FILE OPEN ROUTINE FOR MAGTAPE

MTAOPN:	TLNE STS,74000		;CHECK REQUESTED ACCESS
	JRST MTILAC		;ACCESS OTHER THAN READ OR WRITE REQUESTED
	LDB A,[POINT 4,STS,35]	;CHECK REQUESTED MODE
	CAIE A,17		;BETTER BE DUMP IO MODE
	JRST MTILMD		;BUT ITS NOT...
	HLRZ UNIT,DEV		;GET UNIT
	NOINT			;PREVENT INTERRUPTS WHILE LOCKED
	LOCK MTALCK(UNIT)	;LOCK IT
	SKIPE MTASTS(UNIT)	;THIS UNIT ALREADY OPEN?
	JRST MTBUSY		;YES, LOSE
	MOVSI IOS,-1		;NO, BUT IT IS NOW
	MOVEM IOS,MTASTS(UNIT)	;MARK IT AS SUCH AND ZERO INITIAL STATUS
	UNLOCK MTALCK(UNIT)	;UNLOCK UNIT
	OKINT			;OK TO INTERRUPT NOW
	JRST SKPRET		;SAY SUCESSFULLY OPENED!

MTILAC:	MOVEI A,OPNX15		;NON READ/WRITE ACCESS NOT ALLOWED
	RET

MTILMD:	MOVEI A,OPNX14		;ILLEGAL MODE
	RET

MTBUSY:	MOVEI A,OPNX9		;FILE BUSY
	UNLOCK MTALCK(UNIT)	;UNLOCK UNIT
	OKINT			;OK TO INTERRUPT NOW
	RET

;FILE CLOSE ROUTINE FOR MAGTAPE

MTACLZ:	HLRZ UNIT,DEV		;GET UNIT
	NOINT			;PREVENT INTERRUPTS WHILE LOCKED
	LOCK MTALCK(UNIT)	;LOCK IT
	SKIPE MTAOPR(UNIT)	;UNIT NOW ACTIVE?
	CALL DISACT		;YES, WAIT UNTIL IT ISN'T BEFORE CLOSING
	SETZM MTASTS(UNIT)	;SAY UNIT NOT OPEN ANY MORE
	SETZM MTAOPR(UNIT)	;SAY NO OPERATIONS PENDING ON THIS UNIT
	SETZM MTAXFR(UNIT)	;SAY NO TRANSFERS EVER DONE ON THIS UNIT
	UNLOCK MTALCK(UNIT)	;UNLOCK LOCK
	OKINT			;OK TO INTERRUPT NOW
	JRST SKPRET		;RETURN OK

;DUMP INPUT/OUTPUT ROUTINES FOR MAGTAPE

MTDMPI:	SKIPA B,[MTARDR]	;IF DUMPI THEN OPERATION IS READ
MTDMPO:	MOVEI B,MTAWRR		;ELSE IF DUMPO THEN OPERATION IS WRITE
	EXCH A,B		;PUT THESE IN RIGHT ORDER FOR MTDOOP
	TLC B,-1		;CONVERT IOWD FORMAT TO
	ADD B,BHC+1		;WORD-COUNT,,MEMORY-ADDRESS-FIRST FORMAT
	JRST MTDOOP		;GO PERFORM MAGTAPE OPERATION

;MTOPR ROUTINE FOR MAGTAPE

MMTOPR:	HRRZ A,B		;PUT OP-CODE IN A WHERE IT'S WANTED
	JRST MTDOOP		;GO DO IT

;GDSTS ROUTINE FOR MAGTAPE

MTAGDS:	HLRZ UNIT,DEV		;GET UNIT
	NOINT			;PREVENT INTERRUPTS WHILE LOCKED
	LOCK MTALCK(UNIT)	;LOCK IT
	SKIPE MTAOPR(UNIT)	;UNIT ACTIVE?
	CALL DISACT		;YES, WAIT UNTIL IT ISN'T
	HRRZ A,MTASTS(UNIT)	;GIVE MASTER STATUS BITS TO USER
	UNLOCK MTALCK(UNIT)	;UNLOCK UNIT
	OKINT			;OK TO INTERRUPT NOW
	RET

;SDSTS ROUTINE FOR MAGTAPE

MTASDS:	HLRZ UNIT,DEV		;GET UNIT
	NOINT			;PREVENT INTERRUPTS WHILE LOCKED
	LOCK MTALCK(UNIT)	;LOCK IT
	SKIPE MTAOPR(UNIT)	;UNIT ACTIVE?
	CALL DISACT		;YES, WAIT UNTIL IT ISN'T
	MOVEI B,MTASAE!MTAPAR!MTADEN	;PREPARE MASK OF BITS TO TWIDDLE
	MOVE IOS,MTASTS(UNIT)	;GET CURRENT STATUS
	AND A,B			;MASK OFF BITS USER SHOULDN'T CHANGE
	ANDCAM B,IOS		;ZERO CHANGABLE BITS IN CURRENT STATUS
	IORM A,IOS		;NOW UPDATE THEM WITH USER REQUEST
	HRROM IOS,MTASTS(UNIT)	;AND PUT THEM BACK IN MASTER STATUS WORD
	UNLOCK MTALCK(UNIT)	;UNLOCK UNIT
	OKINT			;OK TO INTERRUPT NOW
	RET

;ACTUAL MAGTAPE CONTROL ROUTINE
;CALLED WITH OP-CODE IN A, MTAXFR WORD IF ANY IN B
;UPDATES MTASTS AFTER OP AND SETS IO DATA ERROR AND EOF FLAGS IN AC ZERO
;IF NEEDED

MTDOOP:	HLRZ UNIT,DEV		;GET UNIT
	NOINT			;PREVENT INTERRUPTS WHILE LOCKED
	LOCK MTALCK(UNIT)	;LOCK IT
	SKIPE MTAOPR(UNIT)	;UNIT ACTIVE?
	CALL DISACT		;YES, WAIT UNTIL IT ISN'T
	MOVE IOS,MTASTS(UNIT)	;GET CURRENT STATUS
	ANDI IOS,MTASAE!MTAPAR!MTADEN	;ZERO EVERYTHING EXCEPT USER MODES
	MTRS C			;GET UNIT STATUS
	TEST(O,ERRF)		;SET ERROR FLAG IN CASE UNIT IS LOSING
	TRNE C,HDWNLN		;SKIP IF UNIT NOT ONLINE
	TRNN C,HDWRDY		;SKIP IF UNIT READY
	JRST MTDRET		;UNIT IS LOSING, DON'T TRY TO EXECUTE OP
	TEST(Z,ERRF)		;UNIT OK, TAKE BACK BAD BIT
	CAIE A,1		;REWIND?
	CAIN A,11		;OR REWIND-UNLOAD?
	JRST REWIND		;YES, SAME FOR BOTH SINCE DRIVE WON'T UNLOAD
	CAIN A,3		;WRITE END OF FILE?
	JRST WRTEOF		;YES
	CAIN A,6		;FORWARD SPACE RECORD?
	JRST FSPREC		;YES
	CAIN A,7		;BACK SPACE RECORD?
	JRST BSPREC		;YES
	CAIN A,13		;WRITE GAP?
	JRST WRTGAP		;YES
	CAIN A,16		;FORWARD SPACE FILE?
	JRST FSPFIL		;YES
	CAIN A,17		;BACK SPACE FILE?
	JRST BSPFIL		;YES
	CAIN A,20		;READ RECORD?
	JRST MTREAD		;YES
	CAIN A,21		;WRITE RECORD?
	JRST MTWRIT		;YES

;FALL THROUGH HERE FOR NOP CASE OR JUMP HERE TO RETURN

MTDRET:	MTRS A			;GET STATUS TO A
	TRNE A,HDWNLN		;SKIP IF UNIT NOT ONLINE
	TRNN A,HDWRDY		;SKIP IF UNIT READY
	TRO IOS,MTADVE		;INFORM USER OF UNIT'S UNTIMELY DEMISE
	TRNE A,HDWBOT		;AT LOAD POINT?
	TRO IOS,MTABOT		;YES, UPDATE MASTER STATUS
	TRNE A,HDWEOT		;AT EOT?
	TRO IOS,MTAEOT		;YES, UPDATE MASTER STATUS
	HRROM IOS,MTASTS(UNIT)	;PUT BACK UPDATED STATUS BITS
	SETZM MTAOPR(UNIT)	;AND SAY UNIT NO LONGER ACTIVE
	UNLOCK MTALCK(UNIT)	;UNLOCK LOCK
	OKINT			;OK TO INTERRUPT NOW
	RET			;RETURN TO CALLER OF DEVICE DEPENDENT ROUTINES

;REWIND AND REWIND-UNLOAD

REWIND:	MTRS A			;GET HARDWARE STATUS
	TRNE A,HDWNLN		;IS UNIT OFFLINE?
	TRNE A,HDWBOT		;OR NOW AT LOAD POINT?
	JRST MTDRET		;YES, RETURN AND UPDATE STATUS
	MTOP A,0		;NO, EXECUTE REWIND
	MOVEI A,REWTST		;AND PREPARE TO WAIT UNTIL IT IS
	JSYS EDISMS		;GO TO SCHEDULER WAIT
	JRST MTDRET		;DONE, RETURN AND UPDATE STATUS

;WRITE EOF

WRTEOF:	MTRS A			;FETCH HARDWARE STATUS BITS TO A
	TEST(NE,WRTF)		;IF UNIT IS NOT OPENED FOR WRITE
	TRNE A,HDWFPT		;OR NOT WRITE ENABLED IN HARDWARE
	JRST MTDRET		;THEN THIS IS A NO-OP
	MTOP A,1		;ELSE DO IT, OP CODE #1
	JRST MTDRET		;RETURN AND UPDATE STATUS

;FOWARD SPACE RECORD

FSPREC:	MTRS A			;GET STATUS TO A
	TRNE A,HDWEOT		;AT EOT?
	JRST MTDRET		;YES, DO NOTHING
	MTOP A,5		;SKIP RECORD AND GET STATUS TO A
	TLNE A,MICEOF		;EOF SEEN?
	TRO IOS,MTAEOF		;YES, REFLECT IN STATUS
	JRST MTDRET		;UPDATE STATUS AND RETURN

;BACK SPACE RECORD

BSPREC:	MTRS A			;GET STATUS TO A
	TRNE A,HDWBOT		;AT LOAD POINT?
	JRST MTDRET		;YES, DO NOTHING
	MTOP A,6		;BACK SPACE RECORD
	JRST MTDRET		;UPDATE STATUS AND RETURN

;WRITE GAP

WRTGAP:	MTRS A			;FETCH HARDWARE STATUS BITS TO A
	TEST(NE,WRTF)		;IF UNIT IS NOT OPENED FOR WRITE
	TRNE A,HDWFPT		;OR NOT WRITE ENABLED IN HARDWARE
	JRST MTDRET		;THEN THIS IS A NO-OP
	MTOP A,13		;ELSE DO IT, OP CODE #13
	JRST MTDRET		

;FORWARD SPACE FILE

FSPFIL:	MTRS A			;GET STATUS TO A
	TRNE A,HDWEOT		;AT EOT?
	JRST MTDRET		;YES, DO NOTHING
	MTOP A,5		;SKIP FILE AND GET STATUS TO A
	TLNN A,MICEOF		;EOF SEEN?
	JRST FSPFIL		;NO, KEEP LOOKING
	TRO IOS,MTAEOF		;YES, REFLECT IN STATUS
	JRST MTDRET		;UPDATE STATUS AND RETURN

;BACK SPACE FILE

BSPFIL:	MTRS A			;GET STATUS TO A
	TRNE A,HDWBOT		;AT LOAD POINT?
	JRST MTDRET		;YES, DO NOTHING
	MTOP A,6		;BACK SPACE RECORD AND GET STATUS TO A
	TLNN A,MICEOF		;EOF SEEN?
	JRST BSPFIL		;NO, KEEP LOOKING
	MTOP A,5		;YES, NOW SKIP FORWARD ONE RECORD
	JRST MTDRET		;UPDATE STATUS AND RETURN

;READ RECORD

MTREAD:	SETZM TAPBUF		;ZERO THE READ BUFFER
	MOVE A,[TAPBUF,,TAPBUF+1]
	BLT A,TAPBUF+TAPBSZ-1
	MOVEM B,MTAXFR(UNIT)	;PRESERVE XFER WORD
	HLRZ A,B		;GET WORD COUNT TO A
	CAILE A,TAPBSZ		;MAKE SURE NOT TO OVERFLOW BUFFER
	MOVEI A,TAPBSZ		;FORCE FIT IF NECESSARY
	MOVEI B,TAPBUF		;PUT RECORD IN CROCK BLT BUFFER
	MTRD B,0(A)		;NOW READ ONE RECORD
	HRRZ A,MTAXFR(UNIT)	;PREPARE TO BLT RECORD - SET "TO" OF BLT
	HLRZ C,MTAXFR(UNIT)	;RETRIEVE WORD COUNT
	CAILE C,TAPBSZ		;CHECK SIZE TO NEVER BLT MORE
	MOVEI C,TAPBSZ		;THAN BUFFER HOLDS
	ADD C,A			;CREATE "UNTIL" OF BLT
	HRLI A,TAPBUF		;SET UP "FROM" OF BLT
	BLT A,-1(C)		;MOVE BUFFER TO ULTIMATE DESTINATION
	JUMPGE B,MTDRET		;UPDATE STATUS AND RETURN IF NO FLAGS
	TLNE B,MICEOF		;EOF SEEN?
	TRO IOS,MTAEOF		;YES, SET IOS FLAG
	TLNE B,MICTPE		;TAPE ERROR LOSSAGE?
	TRO IOS,MTAIOE		;YES, SET IOS FLAG
	TLNE B,MICLNE		;LENGTH ERROR?
	TRO IOS,MTALNE		;YES, SET IOS FLAG
	TLNE B,MICEOF		;EOF SEEN?
	TEST(O,EOFF)		;YES, SET UNIVERSAL FLAG
	TLNE B,MICTPE		;TAPE ERROR LOSSAGE?
	TEST(O,ERRF)		;YES, SET UNIVERSAL FLAG
	TLNE B,MICLNE		;LENGTH ERROR?
	TEST(O,ERRF)		;YES, SET UNIVERSAL FLAG
	JRST MTDRET		;UPDATE STATUS AND RETURN

;WRITE RECORD

MTWRIT:	TRO IOS,MTAILW		;PREPARE FOR WRITE LOCK FAILURE
	MTRS A			;READ HARDWARE STATUS
	TEST(NE,WRTF)		;IF UNIT IS NOT OPENED FOR WRITE
	TRNE A,HDWFPT		;OR NOT WRITE ENABLED IN HARDWARE
	JRST MTDRET		;THEN THIS IS AN ILLEGAL WRITE
	TRZ IOS,MTAILW		;ELSE TURN OFF BAD BIT
	MOVEM B,MTAXFR(UNIT)	;PRESERVE XFER WORD
	MOVEI B,TAPBUF		;PREPARE TO BLT RECORD - SET UP "TO" OF BLT
	HRL B,MTAXFR(UNIT)	;SET "FROM" OF BLT TO LOCATION OF RECORD
	HLRZ A,MTAXFR(UNIT)	;GET WORD COUNT
	CAILE A,TAPBSZ		;MAKE SURE IT IS NOT BIGGER THAN BUFFER
	MOVEI A,TAPBSZ		;ELSE BRUTALLY FORCE FIT
	BLT B,TAPBUF-1(A)	;MOVE RECORD TO BUFFER BEFORE WRITING
	MOVEI B,TAPBUF		;WRITE RECORD FROM TAPBUF
	MTWR B,0(A)		;WRITE ONE RECORD
	JRST MTDRET		;UPDATE STATUS AND RETURN

;WAIT FOR UNIT TO BE INACTIVE

DISACT:	PUSH P,A		;BE TRANSPARANT
	MOVEI A,MTAOPR(UNIT)	;POINT TO CORRECT WORD
	CALL DISE		;WAIT UNTIL IT IS ZERO
	POP P,A			;RETURN AC A
	RET

END

