.ENABLE SUBSTITUTION
.ENABLE QUIET
.SETF TT
.SETF FLAG
.SETS UIC "LB0:[10,25]"
.IF P1 NE "" .SETT TT
.IFF TT RUN 'UIC'VT
.IFF TT .IF <EXSTAT> < 5 .GOTO ERR2
.SETS OPCON "TT0:"
.SETS DRIVE "MM0"
.SETS UIC "LB0:[10,25]"
.SETF TAPE
.SETN COUNT 30.
.SETS DELAY "120.S"
.SETF SCRAT
.SETF NEW
.SETF RO
.SETF DEN16
.SETT MOUNT
.IF P1 NE "" .SETS COMND "'P1'"
.IF P1 NE "" .GOTO PRSE1
.OPEN TI:
.READ COMND
.CLOSE
.PRSE1:
.IF COMND EQ "" .GOTO ERR1
.SETS LABEL ""
.SETS KEYWRD ""
.PARSE COMND "/" LABEL KEYWRD
.PRSE2:
.SETS KEY ""
.SETS KEY1 ""
.PARSE KEYWRD "/" KEY KEY1
.GOSUB KEYCHK
.SETS KEYWRD "'KEY1'"
.IF KEYWRD NE "" .GOTO PRSE2
.LABCHK:
.TEST LABEL
.IFT MOUNT .IF <STRLEN> > 6 .GOTO ERR4
.IFF <ALPHAN> .GOTO ERR5
.IFF <RAD50> .GOTO ERR5
.IF LABEL NE "" .GOTO 10
.IFT SCRAT .SETS LABEL "SCRATC"
.IFF SCRAT .GOTO ERR6
.10:
.IFT SCRAT .AND .IFT NEW .GOTO ERR7
.IFT SCRAT .AND .IFT RO .GOTO ERR7
.IFT NEW .AND .IFT RO .GOTO ERR7
.IFT SCRAT .AND .IFF MOUNT .GOTO ERR7
.IFT NEW .AND .IFF MOUNT .GOTO ERR7
.IFT RO .SETS RING "WITHOUT RING"
.IFF RO .SETS RING "WITH RING"
.SETS DENS "/DENS=800"
.IFT DEN16 .SETS DENS "/DENS=1600"
.GOSUB ALLOC
.IFT SCRAT .OR .IFT NEW .GOSUB INIT
.IFF TAPE .GOSUB WAIT
.IFT MOUNT MOU 'DRIVE':'LABEL''DENS'/VI
.IF <EXSTAT> NE 1 .GOTO ERR9
.DISABLE QUIET
; '<TIME>' '<DATE>' Tape now available.
.EXIT

.KEYCHK:
.IF KEY EQ "" .RETURN
.TEST KEY
.IF KEY EQ "SCRATCH" .GOTO K1
.IF KEY EQ "DENS=1600" .GOTO K2
.IF KEY EQ "NEW" .GOTO K3
.IF KEY EQ "READONLY" .GOTO K4
.IF KEY EQ "NOMOUNT" .GOTO K5
.GOTO ERR3

.K1:
.SETT SCRAT
.RETURN

.K2:
.SETT DEN16
.RETURN

.K3:
.SETT NEW
.RETURN

.K4:
.SETT RO
.RETURN

.K5:
.SETF MOUNT
.RETURN

.ERR1:
.DISABLE QUIET
; TAPE -- COMMAND INPUT ERROR
.GOTO FATAL

.ERR2:
.DISABLE QUIET
; TAPE -- ILLEGAL CONTEXT
.STOP

.ERR3:
.DISABLE QUIET
; TAPE -- INVALID KEYWORD "/'KEY'"
.GOTO FATAL

.ERR4:
.DISABLE QUIET
; TAPE -- LABEL TOO LONG "'LABEL'"
.GOTO FATAL

.ERR5:
.DISABLE QUIET
; TAPE -- INVALID CHARACTER IN TAPE LABEL "'LABEL'"
.GOTO FATAL

.ERR6:
.DISABLE QUIET
; TAPE -- TAPE LABEL MISSING
; TAPE -- COMMAND LINE "'COMND'"
.GOTO FATAL

.ERR7:
.DISABLE QUIET
; TAPE -- CONFLICTING KEYWORDS
.GOTO FATAL

.ERR8:
.DISABLE QUIET
; TAPE -- WAIT LIMIT EXPIRED
.GOTO FATAL

.ERR9:
.DISABLE QUIET
; TAPE -- MOUNT ERROR
.GOTO FATAL

.ERR10:
.DISABLE QUIET
; TAPE -- INITIALISATION FAILURE
.GOTO FATAL

.FATAL:
; TAPE -- PROCEDURE TERMINATED
.STOP

.ALLOC:
.DISABLE QUIET
;
; '<TIME>' '<DATE>' Allocating tape drive ...
.ENABLE QUIET
ALL 'DRIVE':
.IF <EXSTAT> EQ 1 .GOTO BRO
.DEC COUNT
.IF COUNT EQ 0 .GOTO ERR8
.DELAY 'DELAY'
.GOTO ALLOC
.BRO:
.DISABLE QUIET
;
; '<TIME>' '<DATE>' Requesting Operator to load tape "'LABEL'"
.ENABLE QUIET
.IFT SCRAT .GOTO GETSCR
.IFT NEW .GOTO GETNEW
BRO 'OPCON'****** LOAD TAPE "'LABEL'" ON DRIVE 'DRIVE': 'RING'
.RETURN

.GETSCR:
BRO 'OPCON'****** LOAD SCRATCH TAPE ON DRIVE 'DRIVE': 'RING'
.RETURN

.GETNEW:
BRO 'OPCON'****** LOAD NEW TAPE "'LABEL'" ON DRIVE 'DRIVE': 'RING'
.RETURN

.INIT:
.GOSUB WAIT
INI 'DRIVE':'LABEL''DENS'
.IF <EXSTAT> NE 1 .GOTO ERR10
.RETURN

.WAIT:
RUN 'UIC''DRIVE'
.IF <EXSTAT> EQ 1 .GOTO W1
.DEC COUNT
.IF COUNT EQ 0 .GOTO ERR8
.GOSUB BRO
.DELAY 'DELAY'
.GOTO WAIT
.W1:
.SETT TAPE
.RETURN
