*M*      OPNL     CONTAINS ROUTINES TO OPEN AN INPUT OR UPDATE ANS OR
*,*               LABEL TAPE.
*P*      NAME:    OPNL
*,*      PURPOSE  OPENS AN INPUT OR UPDATE ANS OR LABEL TAPE.
*,*      DESCRIPTION FINDS THE REQUESTED TAPE IN THE AVR TABLES OR
*,*               REQUESTS THE OPERATOR 'MOUNT' THE TAPE. VERIFIES THE
*,*               VOLUME AND FILE LABELS, INCLUDING WHETHER THIS USER IS
*,*               PERMITTED ACCESS, AND SETS THE DCB OPEN.
MONPROC  SET      1
BITS     SET      1
ANSPROC  SET      1
         SYSTEM   UTS
         DEF      OPNL:             PATCHING DEF
OPNL:    RES
         TITLE    '**** OPNL ****'
         BOUND    8
K2       EQU      2
K7       EQU      X'7'
K0       EQU      X'0'
K1       EQU      X'1'
K3       EQU      X'3'
K40      EQU      X'40'
KFFFF    EQU      X'FFFF'
K1FFFF   EQU      X'1FFFF'
KN1      EQU      -X'1'
KN2      EQU      -X'2'
         PAGE
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE     OPL DEFS
*******************  DEF  ************************
*
***********CONSTANTS***********
         DEF      CBOF              C':BOF'
         DEF      CEOF              C':EOF'
         DEF      CEOR              C':EOR'
         DEF      CEOV              C':EOV'
         DEF      TEOF1             C'EOF1'
         DEF      TEOV1             C'EOV1'
         SPACE    2
************ROUTINES***********
         DEF      GETAVR            GET AVRX AND AVR ENTRY
         DEF      MODSET            DO MODE CONTROL TAPE COMMAND
         DEF      OFFREW            DO OFF-LINE REW OF TAPE
         DEF      OPNLA             OPEN ANS/XEROX LABEL TAPE
         DEF      OPNLBL            OPEN ANS/XEROX LABEL TAPE IN CVOL
         DEF      OPNT2             INITIALIZE DCB:CIS IF ZERO
         DEF      OPNT9             INITIALIZE DCB ON M:OPEN
         DEF      REWTP             DO ON-LINE REW OF TAPE
         DEF      RLSBF             RELEASE BUFFER USED FOR LABELS
         DEF      SKFILE            SKIP FORWARD PAST TAPE MARK
         DEF      SKFILER           SKIP BACK OVER TAPE MARK
         DEF      SKRECR            SKIP BACK OVER PRECEEDING RECORD
         DEF      SKRECR1           DO TAPE OPERATION
         DEF      TAPECHK           FIND/GET TAPE AND DRIVE
         DEF      IOWT               WAIT FOR TAPE IO, GET TYC
         DEF      WRTEOF            WRITE TAPE MARK
         DEF      ABN1403           BREAK OUT OF MMONT
         SPACE    5
****************  REF  *********************
*
*****************CONSTANTS********
         REF      NB31TO0
         REF      AVRTBLNE
         REF      BATAPE
         REF      DOUBLEZERO
         REF      FCMC
         REF      FORMAT
         REF      HDR1
         REF      MISOVSEG
         REF      NBATAPE
         REF      VOL1
         REF      YFF
         REF      YFFFE
         REF      Y00FF
         REF      Y03
         REF      Y06
         REF      :ACN
         REF      :LBL
         REF      #FORMATS
         SPACE    2
**************VARIABLES*************
         REF      ANSFLGS           INPUT;X'0C' OUTPUT;X'04'
         REF      AVRFLGS           INPUT;X'80'
         REF      AVRFNMT           INPUT;
         REF      AVRID             INPUT; OUTPUT;
         REF      AVRNOU            INPUT; OUTPUT;
         REF      AVRTBL            INPUT; OUTPUT;
         REF      DCT3              INPUT;
         REF      DCT4              INPUT;
         REF      DCT5              OUTPUT;X'01'
         REF      DID               INPUT;
         REF      J:JIT             INPUT;BITS0-1
         REF      JB:PMTS           OUTPUT; TOTAL PACK MOUNTS
         REF      JB:TMTS           OUTPUT; TOTAL TAPE MOUNTS
         REF      S:CUN             INPUT;
         REF      TB:FLGS           INPUT;BITS0-1
         REF      UH:DL             INPUT;X'F000'
         SPACE    2
***************ROUTINES**********
         REF      ABN3005           GIVE 30 05 ABNORMAL RETURN
         REF      ANSLINIT          GET MON BUFFER & SET BLK/BUF
         REF      CCCHK             CHECK LEGALITY OF NS TAPE OPTIONS
         REF      CCCHK2            CONSISTENCY CHECK NS TAPE OPTIONS
         REF      CHKADR            LEGALITY CHECK TLABEL ADDRESS
         REF      CHKANS0           SKIP IF DCB NOT ANS
         REF      CHKFLACN          CHECK DCB VLPS
         REF      CHKREW            WAIT FOR ASYNCH TAPE OP
         REF      CKLIMIT           VERIFY USER TRAILER LABEL ADDRESS
         REF      CLEARHI           CLEAR DRIVE ACCOUNTING DONE FLAG
         REF      CNVBIN            CONVERT ANS LABEL INFO TO BINARY
         REF      CNVJULIAN         :ACN EXPIRATION DATE TO JULIAN FORMAT
         REF      COMKEYC           COMPARE FILENAME..LABEL:DCB
         REF      COMPARE           CHECK ACCOUNT..LABEL:DCB
         REF      DERES             DEALLOCATE TAPE DRIVE
         REF      DHHIT1            CHK IF USER ALREADY HAS DRIVE
         REF      DISMNT            REMOVE TAPE WITH 'DISMNT' MSG
         REF      DOCCMS1           SET DENSITY ON NS DRIVE
         REF      DOCCSET           HANDLE CODE CONV. OPTION FOR NS DRIVE
         REF      DONEWQ            MAKE CALL ON NEWQNW FOR TAPE SPACING
         REF      DONEWQM           DO MODE CONTROL COMMAND-NS DRIVE
         REF      GETACNADR         GET DCB:ACN VLP ADDRESS
         REF      GETFILADR         GET DCB:FILENAME VLP ADDRESS
         REF      GETFLG1           GET NS OPTIONS FROM TB:FLGS1
         REF      GETFUN            GET DCB:FUN
         REF      GETTYC            GET DCB:TYC
         REF      GETTYP            GET RESOURCE TYPE
         REF      GSBUF             GET BUFFER FOR READING TAPE LABELS
         REF      IOCHEK1           DO POST PROCESSING OF ANS DATA I/O
         REF      IOSPIN            WAIT FOR I/O COMPLETE
         REF      JULIAN            GET CURRENT DATE IN JULIAN FORMAT
         REF      LOCCODE           FIND VLP'S IN LABELS
         REF      LOCCODEA          FIND SN'S IN DCB
         REF      MOUNT             REQUEST MOUNTING OF TAPE
         REF      MSRMOVE           MOVE FILENAME TO DCB ON OPEN NEXT
         REF      MSR01EXIT         ABN/ERR EXIT
         REF      OERX              ABN/ERR EXIT
         REF      OPENER01          ABN 14 00 EXIT
         REF      OPENER03          ABN 03 00 EXIT
         REF      OPNT3             SET AVRTBL ENTRY BUSY
         REF      OPNXTP            NORMAL EXIT FOR TAPE OPEN
         REF      PROTCHK           DO LABEL AND WRITE RING CHECKS
         REF      PULLEXIT          EXIT *TSTACK
         REF      PUTSZBF           SET DCB:SIZE AND DCB:BUFFER
         REF      READTP            READ TAPE LABEL
         REF      REEL              GIVE 'REEL NO ERROR' MSG
         REF      RMB               RELEASE MON BUFFER
         REF      S:OFFRF           FLAG TO DO OFFLINE REMOVES
         REF      SAVRL             REMOVE TAPE WITH 'SAVE' MSG
         REF      SECCHK            DO ACCESS CHECKS FOR XEROX LABEL TAPE
         REF      SETACOG           SET DCB:ACS AND DCB:ORG
         REF      SETASCII          SET DRIVE TO ASCII, IF AVAILABLE
         REF      SETBTDQ1          SET DCB:HBTD TO 1 FOR TLABEL
         REF      SETBTDZ           INITIALIZE DCB:HBTD TO ZERO
         REF      SETEBCD           INITIALIZE DRIVE TO EBCDIC
         REF      SETOPN            SET DCB OPEN
         REF      SETOPN1           CLEAR SELECTED DCB FIELDS
         REF      SETOPN2           CLEAR SELECTED DCB FIELDS
         REF      SETSPIN           SET GLOBAL BIT FOR PACKS
         REF      SETTYC            SET DCB:TYC
         REF      SIXPACK           HASH ANS SN TO 4 BYTES
         REF      T:RBUF            RELEASE BUFFER USED FOR LABEL READS
         REF      TRNABRT           GIVE ERROR FOR BAD USER LABEL ADDR
         REF      TRNINFO           VALIDATE ADDR AND MOVE FPARAMS
         REF      USECHK2           LIMIT CHECK AND ACCOUNT FOR TAPE DRIV
         PAGE
CACN     EQU      :ACN
CBOF     TEXT     ':BOF'
CEOF     TEXT     ':EOF'
CEOR     TEXT     ':EOR'
CEOV     TEXT     ':EOV'
THDR1    EQU      HDR1
DPT      EQU      AVRTBLNE
TEOF1    TEXT     'EOF1'
TEOV1    TEXT     'EOV1'
         PAGE
*
GETCIS   EQU      %
GETCISA  LI,SR3   0
         LI,R2    BACOS
         LB,R2    *R6,R2
         AI,R2    KN1
         AW,R3    R2
         B        *SR1
CHKANS   EQU      %
         LI,SR1   X'F'
         AND,SR1  ASN,R6
         CI,SR1   X'A'
         B        *SR4
YFBFF    EQU      NB31TO0+27
*
OPNT9    BAL,2    OPNT2
*D*      NAME:    OPNT9
*,*      REGISTERS R0-R5 VOLATILE
*,*      INPUT    R5=BACVI
*,*      SCRATCH  R2=1
*,*      DESCRIPTION INITIALIZES DCB:CIS, DCB:SNFN IF ANS, AND SETS DCB:CVI
*,*               TO 1 AND CLEARS DCB WORD 16.
         BAL,R0   CHKANS0
         BAL,R2   SETFNA            CLRSNFN//// SNFN FOR ANS AND BUMP FSN
         LI,2     1
         STB,2    *6,5
         B        0,4
*,*       CALL      BAL,R2     OPNT2
         SPACE    2
OPNT2    LI,R1    BACIS
*D*      NAME:    OPNT2
*,*      REGISTERS R0-R1 VOLATILE
*,*      SCRATCH  R1=BACIS
*,*      DESCRIPTION SETS DCB:CIS TO 1 IF ZERO
         LB,R0    *R6,R1
         BNEZ     %+2
         MTB,1    *R6,R1
         B        0,R2
         PAGE     OPNLBL
*
OPNLA    EQU      %
*F*      NAME:    OPNLA
*,*      PURPOSE  PROCESS THE OPEN OF AN INPUT OR UPDATE ANS OR LABEL TAPE.
*,*      DESCRIPTION INITIALIZES THE DCB FOR AN OPEN, OBTAINS THE TAPE,
*,*               VERIFIES THE USER IS PERMITTED ACCESS, AND SETS THE
*,*               DCB OPEN.
         SPACE    2
*D*      NAME:    OPNLA
*,*      ENTRY    OPNLBL
*,*      CALL     OVERTO OPENTPSEG,OPNLA#
*,*               OVERTO OPENTPSEG,OPNLBL#
*,*      INTERFACE OPNT9, CHKANS0, IOCHEK1, CHKFLACN, TAPECHK, SETBTDZ,
*,*               GSBUF, PUTSZBF, GETAVR, GETTDEV, AVR, GETFILADR,
*,*               COMKEYC, REEL, READTP, IOSPIN, GETACNADR, COMPARE,
*,*               SKFILE, SECCHK, SETACOG, TRNINFO, VOLHED9, RLSBF,
*,*               LOCCODE, MSRMOVE, INITAVR7, OERX, SKFILER, OPENER03, OSAVE
*,*      DESCRIPTION ENTRY AT OPNLA INITIALIZES FOR AN OPEN CAL, WHILE
*,*               ENTRY AT OPNLBL INITIALIZES FOR THE OPEN PHASE OF A CVOL.
*,*               THE TAPE IS THEN FOUND/MOUNTED VIA TAPECHK. IF NOT
*,*               PREVIOUSLY DONE, AVR IS CALLED TO PROCESS THE VOLUME
*,*               LABEL, FOLLOWING WHICH REEL NUMBER AND ACCOUNT CHECKS
*,*               ARE MADE. THE NEXT LABEL IS THEN READ. IF END VOLUME,
*,*               THE NEXT VOLUME IS OBTAINED AND THE NEXT LABEL READ.
*,*               IF END OF FILE, THE NEXT LABEL IS READ. IF END OF SET,
*,*               AND NOT A NEXT FILE OPERATION, A SWITCH TO THE
*,*               FIRST VOLUME IS MADE AND THE NEXT LABEL READ. IF
*,*               NEXT FILE, THE TAPE IS LEFT POSITIONED IF INOUT,
*,*               OR IS REWOUND OR REMOVED IF IN, DEPENDING ON WHETHER
*,*               SINGLE VOLUME OR MULTI-VOLUME SET. IF A BOF(:BOF OR
*,*               HDR1) AND NEXT FILE, ACCESS CHECKS ARE MADE AND THE FILE
*,*               NAME IS MOVED INTO THE DCB. IF NOT NEXT FILE, IF THE
*,*               NAME DOES NOT MATCH THAT IN THE DCB, THE NEXT LABEL IS
*,*               READ. IF NEXT FILE OR THE CORRECT SPECIFIED FILE,
*,*               ACCESS CHECKS ARE MADE, AND IF APPROPRIATE THE FPARAMS
*,*               ARE TRANSFERRED. THE DCB IS SET OPEN AND THE ROUTINE
*,*               EXITS.
         LI,5     BACVI
         BAL,4    OPNT9
         B        OPNLBLA
*
OPNLBL   EQU      %
*F*      NAME:    OPNLBL
*,*      PURPOSE  PROCESSES THE OPEN VOLUME AND FILE PHASES OF A CVOL FOR
*,*               AN INPUT OR UPDATE ANS OR LABEL TAPE.
*,*      DESCRIPTION INITIALIZES THE DCB FOR NEXT VOLUME OF SAME FILE,
*,*               OBTAINS THE TAPE, AND SETS THE DCB OPEN FOR ANS AND
*,*               LABEL TAPE.
*
         BAL,R0   CHKANS0
         BAL,SR4  IOCHEK1           IF ANS, CHK FOR POSTING
         LI,R2    X'F0001'          CVOL FLAG FOR PMD-CMD
OPNLBLA  EQU      %
         STW,2    PBD,6
         BAL,R0   CHKFLACN
*
OPNLBLII EQU      %
         BAL,D4   SETBTDZ
         BAL,5    TAPECHK
OPNLLII  EQU      %
         BAL,R3   GETAVR            RESTORE R0-R1
         BAL,SR4  CCCHK2            CHECK FOR CHANGE IN CC SETTING
         BAL,SR4  GSBUF
         LI,R2    XBUFSIZ
         BAL,SR4  PUTSZBF
         BAL,R3   GETAVR
*
*                                   CLEAR PSL
         AND,R1   YFBFF
         STD,R0   AVRTBL,R2
*
*
         CW,R1    Y4                IS TAPE AT LOGICAL BEG
         BANZ     OPNLBLI3          NO
*
         CW,R1    Y2                DID AVR RECOGNIZE
         BANZ     OPNLBLI9          YES
*
         LW,R1    Y02
         STD,0    AVRTBL,R2         FLAG DRIVE AS IN USE
         PUSH     1,R0              NO
         LI,R1    CHKSN2
         BAL,R0   CHKANS0
         B        TVR               ANS-DO SHORT VR
         B        XTVR              XEROX LABEL-DO EXTENDED VR
CHKSN2   EQU      %
         BAL,R3   GETAVR
         PULL     1,R3
         CI,SR2   0                 IS LABEL GOOD
         BG       OPNREEL           NO..
         BAL,SR4  CHKANS
         BNE      CHKSN
         LW,D4    R2
         MI,D4    6
         AI,D4    AVRFNMT
         LW,SR2   PBD,R6
         BGEZ     CHKSN1            NOT CVOL, SO SKIP CVI CHK
         LI,R4    18                CHECK VOL SEQ NO.
         LB,SR2   *D4,R4            GET VSN GROM AVRFNMT
         LI,R4    BACVI
         CB,SR2   *R6,R4
         BNE      OPNREEL
CHKSN1   EQU      %
         LI,SR2   X'20000'          IS IT BY FILENAME
         CW,SR2   0,R6
         BAZ      CHKSN
         BAL,R0   GETFILADR         YES,CHECK FILENAME
         LW,D2    R7                ANS VOL SEQ NO.
         LI,R3    0                 D2,R3 = DCB F.N.
         BAL,R1   COMKEYC
         BNE      OPNREEL
         BAL,R3   GETAVR
         B        OPNLBLI9
CHKSN    EQU      %
         CW,R0    R3
         BE       OPNLBLI9
OPNREEL  EQU      %
         BAL,R3   GETAVR
         LW,15    2                 SET AVR INDEX FOR TYPR
         BAL,SR4  REEL
*                                   TYPE MESSAGE
         BAL,11   RLSBF
         B        OPNLBLII
OPNLBLI9  EQU     %
         BAL,SR4  CHKANS            BYPASS ACCOUNT CHECK IF ANS.
         BE       OPNLBLI3
         OR,R1    Y4                SET POS TO MIDDLE OF REEL
         STD,R0   AVRTBL,R2
*                                   GET SECTOR BUFFER FOR RECORDS
*
         BAL,SR2  READTP
         BAL,SR4  IOSPIN
         BAL,R0   GETACNADR
         LW,D3    QBUF,R6
         LW,D1    CACN
         CW,D1    *D3
         BNE      OPENERIN
         LI,R3    0
         LI,R2    1
         BAL,SR4  COMPARE
         B        OPENERIN
OPNLBLI3 EQU      %
         LW,R2    S:CUN
         LH,R2    UH:DL,R2
         CI,R2    X'F000'           CHECK FOR BRK,ABRT,ERR,EC
         BANZ     ERSEC1
*
         INT,SR2  PBD,R6            GET PBD. BITS 0-15 = 0
         CI,SR2   KFFFF             IS PBD = -1
         BNE      OPNLLI3           NO. THIS IS NOT LAST TAPE TO BE SRCHD
         CW,SR2   PBD,R6            IS CMD = 0
         BE       OPNLLI3
         BAL,R3   GETAVR            GET TPOS
         STH,R1   SR2               SR2=TPOS,PBD
         CW,SR2   PBD,R6            IS TPOS="MD
         BE       OPNLBI3
OPNLLI3  EQU      %
*
         BAL,SR4  CHKANS
         BNE      OPNLLI31
         BAL,R3   GETAVR
         CW,R1    Y4                DO NOT SKIP TAPE
         BANZ     OPNLLI31          MARK IF THIS IS
         OR,R1    Y4                BEGINNING OF ANS
         STD,R0   AVRTBL,R2         TAPE.
         B        OPNLLI31+1
OPNLLI31 EQU      %
         BAL,SR2  SKFILE            SKIP TO END-OF-FILE
         STW,SR2  BUFF2             CLOBBER THE BUFFER IN CASE ERROR
         BAL,SR2  READTP            READ NEXT RECORD
         BAL,SR4  IOSPIN
         LW,D3    QBUF,R6
         LW,D1    *D3
         AI,D3    K1                INCR TO FILE PARAM
         BAL,R4   GETTYC
         CI,R3    X'6'
         BNE      OPNLLI32
         BAL,SR4  CHKANS            IF AN ANS TAPE MARK
         BE       OPNL5CA           WAS FOUND, SEE IF A
*                                   VOLUME SWITCH CAN BE PERFORMED.
OPNLLI32 EQU      %
         CW,D1    THDR1
         BE       OPNLLI33
         CW,D1    CBOF
         BNE      OPNLBLI5
*                                   BOF SENTINAL--DECIDE WHAT TO DO
*                                   ABOUT NEXT FILE
OPNLLI33 EQU      %
         LW,R4    TSTACK            SAVE LAST FPL CODE FOUND
         STW,D1   -2,R4
         LW,D2    Y01
         AND,D2   NXTF,R6
         BNEZ     OPNLBLI6          YES
*                                   NO--IS THIS CORRECT FILE
         LW,R7    D3
         LI,1     BACIS             DONT REQUIRE 1ST VOL IF
         LB,1     *6,1                 CVOL OR IF VOL>1
         CI,1     1
         BG       NTCVOL
         BAL,SR4  CHKANS
         BNE      FILCHK1
         LW,R1    QBUF,R6           FIND VOL. SEQ. NO. IN
         LW,R0    7,R1              VOL SEQ IN BYTE 27-31
         AND,R0   L(X'0F0F0F00')
         CI,R0    X'100'            CHECK FOR VOL 1
         BE       NTCVOL            IF PBD =-1 & VOL SEQ > 1.
         B        FILX
*
OPNLBLI8 EQU      %
         BAL,SR4  CHKANS            BYPASS SECURITY CHECK, FPARAM
         BE       OPNLBLI81         IF ANS.
         LW,R7    D3
         BAL,R0   SECCHK
         B        ERSEC
*
*                                   CHECK HEADER OPTION
         BAL,SR4  SETACOG
         BAL,SR1  TRNINFO
OPNLBLI81 EQU     %
         BAL,SR4  CHKANS
         BNE      VOLHED9
         BAL,SR4  VOLHEDANS
1AR      RES      0
         BAL,11   RLSBF
         BAL,SR2  SKFILE            NOT WANTED--SKIP TO FIRST RECORD
         BAL,SR3  IOWT              WAIT FOR FINISH
*                                   SET REEL IN USE
         BAL,D2   OPNT3
         B        SETOPN1A
OPNLBLI6 EQU      %
         BAL,SR4  CHKANS
         BE       OPNLBLI6A
         LW,R7    D3
         LI,D1    K1
         BAL,R4   LOCCODE
         B        OPENERIN
         BAL,0    GETFILADR
         LI,R0    (FNEMAX+3)/4
         XW,R7    D3
         LI,R2    K0
         BAL,SR1  MSRMOVE
         XW,R7    D3
OPNLBLI6C LI,R0   (FNEMAX+3)/4
         LI,R2    KN2
         STB,R0   *R7,R2
*                                   TRANSFER FILE NAME TO DCB
         B        OPNLBLI8
OPNLBLI6A EQU     %                 OPEN NXTF-ANS
         BAL,0    GETFILADR         MOVE NAME INTO DCB
         LW,2     D3
         AND,R7   M17
         LW,3     7
         SLD,2    2
         AW,3     L(17**24+1)
         MBS,2    0
*                    NOW FIND END OF NAME AND SET COUNT
         LI,2     17
OPNLBLI6B LB,0    *7,2
         CI,0     C' '
         BNE      %+2
         BDR,2    OPNLBLI6B
         STB,2    *7
         B        OPNLBLI6C         FIX R7 AND GO FIX VLP
OPNLBLI51 EQU     %
         LI,R5    BACIS
         MTB,1    *R6,R5            INCR CIS
         LI,R7    0                 FORCE R7 NOT= CIS
OPNLBLI2 EQU      %
         BAL,R0   INITAVR7          REW OR REMOVE TAPE
         LI,R1    HAPBD
         MTH,1    *R6,R1
         BNEZ     OPNLBLII
OPNLBI3  EQU      %
         BAL,11   RLSBF
         LI,SR3   K3                COULDNT FIND FILE
         B        OERX
OPNLBLI5 EQU      %                 RECORD WASNT BOF--MAKE FURTHER
*                                   CHECKS
         CW,D1    CEOF              EOF
         BE       OPNLBLI3          YES--CONTINUE SEARCH
         CW,D1    CEOV
         BE       OPNLBLI51
         CW,D1    CEOR
         BE       OPNL5C
         CW,D1    TEOF1
         BE       OPNLBLI3
         CW,D1    TEOV1
         BE       OPNLBLI51
         BAL,11   RLSBF
         LI,10    11
         B        OERX
OPNL5CA  EQU      %
         LI,D1    0
         BAL,R0   SETTYC
         LI,D1    X'20000'
         CW,D1    SNFN,R6
         BAZ      OPNL5C
         LI,R1    1                 OPEN BY ANS FILENAME
         LI,R5    BACVI             REQUIRES A VOLUME
         STB,R1   *R6,R5            SWITCH BACK TO THE
         LI,R7    X'FFFE'           FIRST VOLUME.
         STW,R7   PBD,R6
         B        OPNL5D1
OPNL5C   EQU      %
         LI,D1    K7
         LW,R7    FLP,R6
         BAL,R5   LOCCODEA          TOTAL SN'S TO R1
         B        OPENER03
OPNL5D1  EQU      %
         LI,R5    BACIS
         LB,R7    *R6,R5
         SW,R1    R7
         BLZ      OPNL5D
         AWM,R1   PBD,R6
OPNL5D   EQU      %
         LI,R1    1
         STB,R1   *R6,R5
         LW,D1    Y01
         AND,D1   NXTF,R6
         BEZ      OPNLBLI2          NO--CONTINUE SEARCH
        BAL,D2   GETFUN            DONT REWIND IF UPDATE
         CI,D1    K1
        BNE      OLBLI5A
         BAL,R0   INITAVR7
OPNL5B1  LI,SR3   K2
         B        OERX
OLBLI5A EQU      %
         BAL,SR2  SKFILER
         BAL,SR2  SKFILER
         BAL,0    CHKANS0
         BAL,SR2  SKFILER
         BAL,11   RLSBF
         B        OPNL5B1
*
         PAGE
ERSEC    EQU      %
         BAL,SR2  SKFILE
         BAL,SR3  IOWT
ERSEC1   EQU      %
         BAL,11   RLSBF
         B        OPENER03
OPENERIN EQU      %
         BAL,R0   OSAVE             REMOVE OLD VOLUME
        B        OPENER03
INITAVR7 EQU      %
*D*      NAME:    INITAVR7
*,*      ENTRY    OSAVE
*,*      REGISTERS ALL VOLATILE EXCEPT R6
*,*      CALL     BAL,R0 INITAVR7
*,*               BAL,R0 OSAVE
*,*      INTERFACE RLSBF, GETAVR, SAVRL, OFFREW, REWTP, IOSPIN
*,*      INPUT    R7=INPUT VOLUME NUMBER
*,*      DESCRIPTION IF CURRENT VOLUME IS SAME AS NEXT VOLUME, VOLUME
*,*               IS REWOUND. OTHERWISE, VOLUME IS DISMOUNTED.  OSAVE
*,*               ENTRY IS FOR UNCONDITIONAL DISMOUNT.
         LI,R5    BACIS             DO REMOVE IF OLD VOLUME NOT
         CB,R7    *R6,R5             SAME AS NEW VOLUME
         BE       INITAVR           IS SAME, SO JUST REW
OSAVE    EQU      %
         PUSH     R0                RELEASE VOLUME
         BAL,11   RLSBF
         BAL,R3   GETAVR
         LW,R3    R0                GET SN
         BAL,SR4  SAVRL
         BAL,SR2  OFFREW
         B        PULLEXIT
*D*      NAME:    TAPECHK
*,*      REGISTERS ALL VOLATILE EXCEPT R6
*,*      CALL     BAL,R5 TAPECHK
*,*      INTERFACE GETFUN, GETTYP, LOCCODE, OPENER01, OERX,MOUNT, DISMNT,
*,*               PROTCHK, CLEARHI, DHHIT1, DOCCMS1, DOCCSET, OPENER03,
*,*               DETAPE, GETAVR
*,*      OUTPUT   R0-1=AVRTBL ENTRY
*,*      DESCRIPTION THE DCB IS EXAMINED FOR ASN, FUN, AND SN'S, GIVING
*,*               AN ERROR FOR ANY WRONG COMBINATIONS. IF FIRST PASS,
*,*               THE COUNTERS ARE INITIALIZED SO THAT THE CORRECT
*,*               MAXIMUM NUMBER OF VOLUMES AND FILES ARE SEARCHED FOR
*,*               THE FUNCTION BEING PERFORMED. THE INTERNAL ROUTINE,
*,*               USECHK, IS THEN CALLED TO FIND OR GET THE TAPE OF THE
*,*               APPROPRIATE LABEL TYPE AND EITHER WITH SN OR  SCRATCH.
*,*               USECHK SEARCHES THE AVRTBL FOR A MATCH ON SN OR SCRATCH
*,*               OR FILE NAME, AS APPROPRIATE. IF NOT FOUND, MOUNT IS
*,*               CALLED TO OBTAIN THE NEEDED VOLUME, AND THE SEARCH IS
*,*               REPEATED. WHEN A MATCH IS FOUND, THE ENTRY IS THEN CHECKED
*,*               TO ASSURE THAT ANOTHER USER DOES NOT ALREADY HAVE THE
*,*               VOLUME AND THAT THIS USER MAY HAVE IT IF HE DOES NOT
*,*               ALREADY. IF NOT PREVIOUSLY ALLOCATED, IT IS ASSIGNED
*,*               TO THE CURRENT USER. IF NOT INPUT, PROTCHK IS CALLED
*,*               TO ASSURE PROPER USE OF THE VOLUME. IF REJECTED, THE
*,*               VOLUME IS DISMOUNTED AND THE SEARCH IS REPEATED.
*,*               IF AN IN DCB, THE AVRTBL IS FLAGGED FOR READ ONLY.
*,*               IF THE VOLUME WAS PREVIOUSLY ASSIGNED TO THE CURRENT
*,*               USER, AND THE USE IS CHANGING FROM IN TO SOME OTHER,
*,*               PROTCHK IS CALLED. IF ALL CHECKS ARE PASSED, THE ROUTINE
*,*               EXITS WITH THE AVRTBL ENTRY IN REGS 0,1.
INITAVR  EQU      %
         PUSH     1,R0
         BAL,11   RLSBF
INITAVR1 EQU      %
         BAL,SR2  REWTP
         BAL,SR3  IOWT
         BAL,R3   GETAVR
         LI,R3    1
         STB,R3   R1
         STD,R0   AVRTBL,R2
         B        PULLEXIT
*
RLSBF    EQU      %
         LW,D3    YFFFE
         AND,D3   QBUF,R6
         XW,D3    QBUF,R6
         AND,D3   M17
         BEZ      *SR4
         LW,R2    SR4               SET RETURN
         LI,R5    0                 REL VIRT & PHYS
         B        T:RBUF
GETAVR   EQU      %
         LI,R2    BADSI             IS TAPE BUSY
         LB,R2    *R6,R2
         AI,R2    NBATAPE
         LD,R0    AVRTBL,R2
         B        0,R3
         TITLE    '**** TAPECHK ****'
DP:TY    EQU      X'10000'          DP TYPE
WDP      EQU      Y0001
FN:OUT   EQU      X'8000'
FN       EQU      X'4000'
ANSI     EQU      X'2000'
DEVICE   EQU      X'1000'
IN       EQU      X'100'
OUT      EQU      X'200'
INOUT    EQU      X'400'
OUTIN    EQU      X'800'
*
*
TAPECHK  EQU      %
         BAL,13   GETFUN
         SLS,12   8                 IN BYTE 2
         AI,12    8                 TRY OUTSNS FIRST
         LI,13    X'F'
         AND,13   0,6               CHK FULL ASN FOR ANS
         CI,13    X'A'
         BNE      %+2
         AI,12    ANSI              FLAG ANS
         CI,13    3
         BNE      %+2
         AI,12    DEVICE            YES
         CI,12    IN+INOUT          NO OUTSNS FOR INS
         BAZ      %+2
         AI,12    -1
         BAL,11   GETTYP
         LI,SR4   TAPCHK1
         LC       TB:FLGS,4         TYPE OF DEV
         BCR,4    CCCHK             TAPE, NOT DISK...DO CC CHK
         OR,12    WDP               SET BIT
TAPCHK1  EQU      %
         LW,7     FLP,6             SET UP 7
SNCHK    EQU      %
         BAL,4    LOCCODE           DOES CODE EXIST
         B        SNCHK2            NO, MEBBE SCRATCH OR INSN
         CI,13    X'FF00'           ANY USEFUL ENTRIES
         BANZ     SNCHK3            YES
         CI,12    DEVICE
         BANZ     SNCHK2A           USE EMPTY VLP FOR DEVICE
         CI,12    ANSI+OUT+OUTIN    ANS MAY BE FILENAME OPEN
         BAZ      OPENER01          MUST BE ANS OR OUT FOR NO SN'S
         CI,12    ANSI
SNCHK2C  EQU      %
         BANZ     SNCHK2B
SNCHK2A  EQU      %
         LI,2     BACIS             GET CURRENT INDEX
         CB,13    *6,2              IS THERE ROOM FOR A SCRATCH
         BGE      GETSCR            YES
SNCHK2   AI,12    -1
         CB,12    Y06               MORE SN'S TO CHECK
         BG       SNCHK             YES
         BL       GETSCRD           NO...AND ALREADY HANDLED ANS
         LI,13    0                 NO VLP TO POST SN'S IN
         CI,12    ANSI              IF ANS,SET FNAME
         BAZ      SNCHK1
SNCHK2B  EQU      %
         LI,0     X'20000'
         BAL,2    SETFN             SET SNFN
         AI,12    FN
         CI,12    OUT+OUTIN
         BAZ      GETSCRD
         AI,12    FN:OUT            FILENAME OUTPUT FLAG
         B        SNCHK2A           OUT, MAY BE PLACE TO PUT SN'S
SNCHK1   EQU      %
         CI,12    DEVICE
         BAZ      OPENER01          MUST BE DVC IF NONE
         CI,12    IN                MUST ALSO NOT BE INPUT
         BANZ     OPENER01
GETSCRD  LI,13    0                 OK, TRY A SCRATCH
GETSCR   BAL,8    GETCISA           SET 2,3 BUT NOT SND
         LW,4     13                SAVE SN CODE
GETSCR1  PUSH     4,2
         LI,3     -1                SCRATCH SER # FLAG
         CI,12    FN
         BAZ      GETSCR2
         CI,12    IN+INOUT
         BAZ      GETSCR2
         LI,R5    HAPBD             PBD TO LAST VOL
         STH,R3   *R6,R5
         LI,3     0                 DO MOUNT IF ANS,FNAME,IN
GETSCR2  EQU      %
         BAL,5    USECHK0           CHECK IT OUT
         PULL     4,2
         CI,4     X'FF'             ANY SLOTS FOR SNS
         BAZ      0,5
         STW,0    *7,3              PUT IN SN
         SW,3     2
         AI,3     -1
         AI,4     X'100'            INCR # USEFUL ENTRIES
         STW,4    *7,3              PUT CODE AWAY
         B        0,5
*
SETFNA   EQU      %
         MTW,1    FSN,R6            BUMP 'FILE OF SET' COUNT
*
SETFN    EQU      %                 SETS DCB:SNFN F/R0
         LI,1     X'20000'
         STS,0    0,6
         B        0,2
*
SNCHK3   CI,12    DEVICE+OUT+OUTIN
         BAZ      SNCHK4            LBLD IN OR INOUT, SPECIAL CHECKS
         BAL,8    GETCISA           SET 2,3-NOT SND
         LI,1     2                 CHECK CIS VS USEFUL ENTRIES
         CB,2     13,1
         BL       USECHK            OK, CHECK IT OUT
         CI,12    IN
         BANZ     ERR56
         SW,3     2                 UNWIND FOR GETCIS
         CI,12    DEVICE
         BANZ     GETSCRD           MUST BE SCRATCH IF DEVICE
         CI,12    ANSI
         BAZ      SNCHK31
         LI,0     X'20000'          IF SNFN IS SET, TREAT AS FN
         CW,0     0,6
         B        SNCHK2C           ELSE AS EXTENDED W/SN'S
SNCHK31  EQU      %
         LI,1     3                 IS THERE ROOM FOR ANOTHER
         CB,2     13,1
         BGE      OPENER01
         B        GETSCR
*
*
*E*      ERROR:   56 - 00  CANNOT CVOL BECAUSE RAN OUT OF ENTRYS
*,*                        IN THE SN LIST
ERR56    EQU      %
         LI,SR3   X'56'
         B        OERX
*
*
SNCHK4   BAL,8    GETCIS
         LI,1     HAPBD
         LH,4     *6,1              GET PBD
         BEZ      OPENER01
         LI,1     2                 CIS VS CURRENT SIZE
         CB,2     13,1
         BL       SNCHK5            INIT REQUIRED, MEBBE
         CI,4     0
         BG       OPENER01
         SW,3     2                 GO TO FIRST SN
         LI,2     1
         LI,1     BACIS
         STB,2    *6,1
         B        USECHK
*
*
SNCHK5   CI,4     0
         BL       USECHK            PBD NEG
         LB,4     13,1              CURRENT SIZE
         LCW,4    4                 SET PBD TO -# SNS
         LI,1     HAPBD
         STH,4    *6,1              AND INSNINIT
         BAL,R5   USECHK
         LI,R2    HACMD
         MTH,1    *R6,R2            IS CVOL FLAG ON
         STH,R1   *R6,R2            TPOS TO CMD
         BNEZ     INSNIN1           CVOL FLAG OFF
         LI,R0    INSNIN2
         PUSH     1,R0
         BAL,R0   INITAVR1          CVOL FLAG ON.REWIND
INSNIN2  EQU      %
         LI,R0    -1                SEARCH ONLY THIS VOLUME
         STW,R0   PBD,R6            -1 TO CMD AND PBD
         B        OPNLLII           CONTINUE OPEN
INSNIN1  EQU      %
         LH,R1    *R6,R2            WAS TPOS 0 OR 1
         BDR,R1   INSNIN1A          GO IF 2 OR MORE
         CI,D1    ANSI              IF ANS,CHK TPOS 0
         BAZ      OPNLLII
         AI,R1    0
         BL       OPNLLII           ANS BEFORE FIRST FILE
INSNIN1A EQU      %
         MTW,-1   PBD,R6            NO.  THIS VOLUME MUST BE RE-SEARCHED
         B        OPNLLII
         TITLE    '**** USECHK ****'
USECHK   LW,3     *7,3              GET SN
         BEZ      OPENER01
USECHK0 RES 0
         LI,2     DPT
USECHK11 EQU      %                 DO SN OR FN SEARCH OF AVR
         CI,12    FN                DO FN SEARCH IF FN SET
         BAZ      USECHK12
*                    SEARCH FOR FILENAME MATCH
         INT,9    FLD,6             FETCH FNAME ADDRESS
         AW,9     FLP,6
         AND,9    M17
         LB,8     *9
         AI,8     1                 INCLUDE COUNT IN COMPARE
         SLS,9    2                 R9 NOW SET FOR CBS
         STB,8    9
         LW,8     9
         LW,9     2
         MI,9     24                AVRFNMT IS 6 WDS/ENTRY
         XW,8     9
         AI,8     BA(AVRFNMT)-24
         CBS,8    0
         BE       USECHK3
         B        USECHK13
USECHK12 EQU      %
         LD,0     AVRTBL-2,2
         CW,0     3
         BE       USECHK3
         CI,3     -1
         BNE      USECHK13
         CW,1     Y1
         BANZ     USECHK3
         BAL,SR4  CHKANS
         BNE      USECHK13
         AI,R2    -1
         LB,8     ANSFLGS,2
         AI,R2    1
         CI,8     8                 ANS KEYIN BIT
         BANZ     USECHK3
USECHK13 EQU      %
         BDR,2    USECHK11
         BAL,9    USECHK2
         B        NOTPE2            49-02
         B        GOVER
*                 BAL,11            MOUNT 3=REEL,4=TYPE
         PUSH     12
         BAL,SR4  MOUNT
         PULL     12
USECHK24 EQU      %
         BDR,0    USECHK0           BR IF NOT YC, BRK, ETC
USECHK25 EQU      %
ABN1403  RES
*
*E*      ERROR:   14 - 03  CONTROL Y, BREAK, OR SOMEHOW
*,*                        INTERRUPTED WHILE MOUNT IN PROGRESS
*
         LI,10    X'14'**7-X'49'**7+NOTPE1+3 ABN1403
         B        NOTPE
*
USECHK26 EQU      %                 TAPE NG-DISMNT & TRY AGAIN
         BIR,0    USECHK0           ALREADY CLEARED THE ENTRY
         PUSH     10,12
         BAL,SR4  DISMNT
         PULL     10,12
         B        USECHK24
*
USECHK3  AI,2     -1
         BL       USECHK13
         LD,R0    AVRTBL,R2
         CW,R1    Y00FF             NOU
         BAZ      OKDP1
         CI,12    DP:TY             DP TYPE ALLOW MULTIPLE OPENS
         BAZ      USECHK11
OKDP1    RES      0
         AI,R2    BATAPE            GET DCT INDEX
         BAL,11   GETTYP
         CB,4     DCT4,2
         BE       USECHK52          OK-TYPES MATCH
*
         AI,2     -BATAPE           NOT SAME TYPE, RESUME SEARCH
         B        USECHK11
*
USECHK52 EQU    %
         LB,R1    DCT3,R2
         AI,R2    NBATAPE
         CI,R1    X'20'             DEVICE PARTITIONED FLAG
         BAZ      USECHKDG    NO--- DEVICE PARTITIONED
         LW,R1    S:CUN       YES-- GET USER #
         CW,R1    DID
         BNE      USECHK11    NO--- USER ALLOWED PARTITIONED DEVICE
USECHKDG EQU      %           YES-- CONTINUE
         LI,1     BADSI
         LI,4     BATAPE
         AW,4     2
         STB,R4   *6,1
         BAL,11   DHHIT1
         BANZ   USECHK45
         LH,9     AVRID,2
         BEZ      USECHK33
         INT,0    J:JIT             IF BATCH, MIGHT BE REAL ID
         CW,1     9                 IS THIS PREMOUNT BY ID
         BE       USECHK33          YES, PUT USER # IN
USECHK32 CW,9     S:CUN
         BNE      USECHK11
USECHK33 EQU      %
         CI,12    DP:TY
         BCS,4    USECHK34          NOT FOR DEVICE PACK
         LB,11    ANSFLGS,2
         AND,11   NB31TO0+3         CLR READ ONLY FLAG
         CI,12    X'2000'           SET ANS DCB FLG FOR KEYIN
         BAZ      %+2
         OR,11    X40
         STB,11   ANSFLGS,2
USECHK34 AI,2     BATAPE
         BAL,9    USECHK2           CHECK RESOURCE LIMITS
         B        NOTPE2            49-02
         B        GOVER
         LI,4     BA(JB:PMTS)       COUNT MOUNTS
         CI,12    DP:TY
         BCS,4    USECHK35
*                    IF NOT 1ST VOL, RESET FSN
         LI,4     BACIS
         LB,0     *6,4
         LI,4     BA(JB:TMTS)       COUNT MOUNTS
         CI,0     1
         BG       USECHK35
         STW,0    FSN,R6
USECHK35 EQU      %
         MTB,1    0,4               BUMP COUNT OF MOUNTS
         BAL,11   CLEARHI           AND CLEAR-X'80'
         AI,2     -BATAPE
         LW,1     S:CUN
         STH,1    AVRID,R2          SET ID HERE
         CI,12    DP:TY
         BANZ     USECHK44          DEVICE PK/DP
         BAL,15   PROTCHK           DO  PROTECTION CHECK
         BIR,8    USECHK26          NO  GOOD, TRY ANOTHER
USECHK4  BAL,3    GETAVR            RESTORE SN TO R0
         B        0,5               RETURN
USECHK45 EQU      %
         BAL,3    GETAVR            REFRESH AVR INDEX
         CI,12    IN+DP:TY
         BANZ     USECHK43          CHK   DP
*                    MUST DO PROTCHK IF NOW AT LOAD POINT...
*                     PROTCHK DOES LP CHECK
         BAL,15   PROTCHK
         BDR,8    USECHK4           CHECKS OUT OK
         BDR,0    OPENER03          PROTECT VIOLATION 14 00
         B        USECHK25          BREAK, ABORT, ETC  14 03
*
USECHK43 CI,12    DP:TY
         BAZ      USECHK4
USECHK44 RES      0
         MTH,1    AVRNOU,2          COUNT FOR DCB
         LH,3     AVRNOU,2          CHECK IF FIRST TIME
         BDR,3    USECHK4           NOPE
         MTH,1    AVRNOU,2          FIRST TIME ONLY
         AI,2     BATAPE            YES, SET GLOBAL SPIN BIT
         BAL,11   SETSPIN           AND COUNT FOR USER
         B        USECHK4
*        ERRORS
*
NOTPE0   BAL,10   NOTPE
GOVER    RES      0
NOTPE1   BAL,10   NOTPE
NOTPE2   BAL,10   NOTPE
NOTPE    AI,10    X'49'**7-NOTPE1
         SCS,10   -7
         BAL,5    DERES
         B        OERX
*
         PAGE
TVR      EQU      %
*
*
*
*
         PUSH     R1
         BAL,SR4  SETEBCD
         SPACE    2
TVR1     EQU      %
         BAL,SR2  REWTP
         B        XTVR1
         SPACE    2
XTVR     EQU      %
         PUSH     R1
         BAL,SR4  SETEBCD
         BAL,SR2  REWTP
         BAL,SR2  SKFILE
         BAL,SR2  SKFILER
         BAL,SR2  SKRECR
         BAL,SR2  SKRECR
XTVR1    EQU      %
         LI,D1    0
         BAL,R0   SETTYC
         LW,14    QBUF,6            RESTORE BUFFER TO R14
         STW,R0   *D3               HSKP BUFFER
         BAL,SR2  READTP
TVR2A    EQU      %                 COMMON ENTRY AFTER 1ST LABEL READ
         BAL,10   IOWT
         LW,D3    QBUF,R6           RESTORE BUF ADR
         LI,SR2   3                 I/O ERROR FLAG
         BDR,3    TVRX              ERROR OCCURRED
         LI,SR2   0                 FLAG XEROX LABEL
         LCI      3
         LM,SR4   *D3               FETCH ALL NEEDED PARTS OF LABEL
         CW,SR4   :LBL
         BE       LBLVOL
         CW,SR4   VOL1
         BE       ANSVOL1           ANS
BADLABEL LI,SR2   1                 SET NOT LABEL
         CW,SR4   ASCVOL1           CHECK ANS WRITTEN IN ASCII
         BNE      TVRX              NOPE-UNRECOGNIZABLE LABEL
*                    ASCII ANS
         BAL,SR4  SETASCII
         BAL,SR2  GETFLG1
         BCS,4    TVR1              ASCII POSSIBLE ON DRIVE, REREAD
*                    ASCII TAPE ON NON-ASCII DRIVE
         LI,SR2   2                 FLAG ASCII ERROR
         B        TVRXX
         SPACE    3
ANSVOL1  EQU      %                 ANS LABEL
         LI,R1    12**2             BYTE ADDR OF 1R FOR SIXPACK
         BAL,SR4  SIXPACK
         LW,D1    R2                PACKED SN
         LI,SR2   X'80'             ANS FLAG FOR ANSFLGS
LBLVOL   EQU      %                 COMMON TO ANS AND XEROX LABEL
*                    SET SN ETC. INTO AVR TABLES
         BAL,R3   GETAVR
         LW,R0    D1
         STD,R0   AVRTBL,R2
         LB,R0    ANSFLGS,R2
         AND,R0   M7
         OR,R0    SR2               SET ANS/XEROX
         STB,R0   ANSFLGS,R2
*                    READ NEXT RECORD TO SET-UP AVRFNMT
         BAL,SR2  READTP            :ACN OR HDR1
         BAL,SR2  SKRECR            THEN SKIP BACK OVER IT
         BAL,SR3  IOWT
         LW,D3    QBUF,R6           RESTORE BUF ADR
         LI,SR2   3                 I/O ERROR FLAG, IN CASE
         BDR,3    TVRX
         BAL,R3   GETAVR
         LW,SR2   *D3
         CW,SR2   :ACN
         BE       DOACN             XEROX :ACN RECORD
         CW,SR2   HDR1
         BNE      BADLABEL          LABEL NG
*                 ANS
         LW,R1    R2
         MI,R1    6*4
         LI,SR4   ANSFNMAX
         ANLZ,R2  BABUFFER
         AI,R2    ANSFNMAX-1
FNDFN    EQU      %
         LB,R0    1,R2
         CI,R0    ' '
         BNE      BAAVRFNMT
         AI,R2    -1
         BDR,SR4  FNDFN
BAAVRFNMT STB,SR4 AVRFNMT,R1        DO NOT CHANGE THIS LABEL
         ANLZ,R2  BABUFFER
         ANLZ,R3  BAAVRFNMT
         STB,SR4  R3
         AI,R3    1
         MBS,R2   4
         ANLZ,2   BABUFFER          ADDRESS OF BUFFER
         LW,3     Y03               MOVE THREE BBYTES INTO R0
         LI,0     0                 SET LAST BYTE 0 TO TERMINATE CNVBIN
         MBS,R2   28                START AT BYTE 28
         LW,8     1                 SAVE R1
         BAL,SR4  CNVBIN            CONVERT TO BINARY
         XW,8     1
         ANLZ,R3  BAAVRFNMT
         AI,R3    18
         STB,8    0,R3              AVRFNMT (BYTE 18)
         ANLZ,R2  BABUFFER
         ANLZ,R3  BAAVRFNMT
         AW,R3    MVJXPR
         MBS,R2   48                MOVE JULIAN EXPIRATION DATE
         B        TVROK
         SPACE    2
DOACN    EQU      %
         LW,R3    R2
         MI,R3    6
         LW,R4    D3
*                    SAVE ACCOUNT IN AVRFNMT+0 & +1
         LW,SR2   1,R4
         STW,SR2  AVRFNMT,R3
         LW,SR2   2,R4
         STW,SR2  AVRFNMT+1,R3
*                    SET EXPIRATION DATE
         LI,SR4   DOACN1
         LW,R5    D3
         AI,R5    3
         LW,SR2   L(X'F0F0F0F0')
         CS,SR2   3,R4
         BNE      JULIAN            NO EXPIRATION, USE DEFAULT
         B        CNVJULIAN
DOACN1   EQU      %
         AI,SR1   X'100'            VOL SEQ NO=1
         STW,SR1  AVRFNMT+4,R3
         STW,SR2  AVRFNMT+5,R3
*
TVROK    LI,SR2   0
         BAL,R3   GETAVR
         OR,R1    Y2                SET AVR'D
         STD,R0   AVRTBL,R2
*
TVRX     EQU      %
*
TVRXX    B        PULLEXIT
BABUFFER MTB,0    *D3
MVJXPR   GEN,8,24 5,19
ASCVOL1  DATA     X'564F4C31'       ASCII 'VOL1'
         PAGE
FILCHK1  EQU      %
         LI,D1    9                 CHECK IF FIRST VOL. 9 IS FIXED CODE
         BAL,R4   LOCCODE           FIND (D1) CODE IN R7 LIST.DISP TOR3
         B        FILX              CANT BE BOF
         SLS,R3   2                 BTD OF DISPL
         AI,R3    2                 BTD OF VOL
         LB,R4    *R7,R3            VOL NO.
         CI,R4    1                 IS IT FIRST VOL
         BG       FILX              NO
NTCVOL   EQU      %
         BAL,SR4  CHKANS
         BNE      NTCVOL1
         BAL,R0   GETFILADR         DCB FILE NAME ADDRESS TO R7.
         LW,D2    QBUF,R6
         LI,R3    3
         LI,R4    21
NTCVA2   EQU      %
         AI,R4    -1                NOW FIND TERMINATING BLANK
         LB,D4    *D2,R4
         CI,D4    C' '
         BE       NTCVA2
         SW,R4    R3
         BGZ      %+2
         LI,R4    17
         STB,R4   *D2,R3
         LW,D4    R7                REGISTER SET-UP FOR COMPARISON
*                                   D4    = DCB FILENAME
*                                   D2,R3 = SENTINEL FILENAME
         B        NTCVOL2
NTCVOL1  EQU      %
         LI,D1    K1
         BAL,R4   LOCCODE
         B        FILX
         BAL,R0   GETFILADR
         LW,D4    R7
         LW,D2    D3
         SLS,R3   K2
*                                   SET UP FOR FILE COMPARISON--HAVE
*                                   SET UP D3,R3,D4,R4
NTCVOL2  EQU      %
         BAL,R1   COMKEYC
         BE       OPNLBLI8
FILX     EQU      %
         BAL,SR2  SKFILE
        B        OPNLBLI3
         PAGE
*
*
*
VOLHED9  EQU      %
*D*      NAME:    VOLHED9
*,*      INTERFACE LOCCODE, CHKADR, TRNABRT, PUTSZBF, SETBTDQ1, READTP
*,*      DESCRIPTION TRANSFERS INFORMATION FROM :LBL RECORD INTO DCB.
*,*               READS USER LABEL INTO USER AREA IF REQUESTED AND PRESENT.
         LI,D1    9
         LW,R7    QBUF,R6
         AI,R7    1
         BAL,R4   LOCCODE           GET TO FILE INFO.
         B        1AR
         SLS,R3   2
         AI,R3    K2
         LI,R1    BACVI
         LB,R2    *R7,R3
         STB,R2   *R6,R1
         LI,D3    K1FFFF                TLABEL OPTION
         AND,D3   TLB,R6
         BEZ      1AR
         LB,R4    *D3
         BEZ      1AR
         AI,R3    K2
         LB,R2    *R7,R3
         STB,R2   *D3
         BEZ      1AR
         CW,R2    R4
         BLE      PSH1
         STB,R4   *D3
PSH1     EQU      %
         LB,D2    *D3
         SLS,D2   -2
         BAL,R2   CHKADR            VALIDATE ADDRESSES
         BNE      TRNABRT           BAD ADDRESR
         LB,R2    *D3
         LW,R7    QBUF,R6
         BAL,SR4  PUTSZBF           PUT USER HEADER SZ AND ADR IN DCB
         LI,R0    K40
         BAL,D4   SETBTDQ1
         BAL,SR2  READTP            READ IN HEADER
         LW,D3    R7
         LI,D4    K1FFFF
         STS,D3   QBUF,R6
         B        1AR
*
*
         PAGE
SETOPN1A EQU      %
*                                   CLEAR PARTS OF DCB FOR FILES
         LI,2     SETOPNA           SET RETURN
         LD,R0    DOUBLEZERO
         BAL,SR4  CHKANS
         BNE      SETOPN1
         STW,R0   BCDA,R6           DO NOT CLEAR FSN, LRCSZ OR SETID
         LW,R1    YFFFE             IN ANS DCB.
         STS,R0   FSN,R6
         LI,R1    K1FFFF
         STS,R0   LRCSZ,R6
         STW,R0   BLKCNT,R6
         B        SETOPN2
SETOPNA  BAL,0    SETOPN
         LW,D2    Y03
         STS,D1   TRN,R6            CLR NXT & TRN
         B        OPNXTP
         PAGE
SKRECR   EQU      %
         LI,SR3   4
SKRECR1  EQU      %
*D*      NAME:    SKRECR1
*,*      ENTRY    SKRECR, SKFILER, SKFILE, OFFREW, REWTP, WRTEOF, MODSET
*,*      REGISTERS ALL VOLATILE
*,*      CALL     BAL,SR2 NAME
*,*      INTERFACE GETAVR, DONEWQ, DONEWQM
*,*      DESCRIPTION ENTRY AT SKRECR1 PERFORMS THE OPERATION SPECIFIED
*,*               IN SR3. OTHERWISE THE ENTRY POINT DETERMINES THE OP
*,*               AND AVRTBL:TPOS IS MODIFIED WHERE NEEDED. ENTRY AND
*,*               FUNCTIONS ARE AS FOLLOWS:
*,*               SKRECR            SKIP RECORD REVERSE
*,*               SKFILER           BACKSPACE FILE
*,*               SKFILE            FORESPACE FILE
*,*               OFFREW            OFF-LINE REWIND
*,*               REWTP             ON-LINE REWIND
*,*               WRTEOF            WRITE TAPE MARK
*,*               MODSET            NS TAPE MODE CONTROL
         BAL,R3   GETAVR
         B        TAPEOP
SKFILER  EQU      %
         LI,SR3   6
         BAL,R3   GETAVR
         CI,1     X'FFFF'           IF NO TPOS, DONT MAKE NEGATIVE
         BAZ      TAPEOP
         AI,R1    KN1
         B        TAPEOP
SKFILE   EQU      %                 SKIP FILE FORWARD
         LI,SR3   7
SKFILE2  EQU      %
         BAL,R3   GETAVR
         AI,R1    K1
         B        TAPEOP
OFFREW   EQU      %                 OFF-LINE REWIND
         LI,SR3   9
         MTW,0    S:OFFRF           DO ONLINE OR OFFLINE
         BEZ      REWTP1            AS REQUIRED
REWTP    EQU      %                 REWIND TAPE
         LI,SR3   8
REWTP1   EQU      %
         BAL,R3   GETAVR
         AND,R1   L(X'9FFF0000')
TAPEOP   EQU      %
         STD,R0   AVRTBL,R2
         B        DONEWQ
WRTEOF   LI,SR3   3
         B        SKFILE2
MODSET   LI,SR3   FCMC              DO MODE SET COMMAND FOR NS TAPE
         B        DONEWQM
*D*      NAME:    IOWT
*D*      REGISTERS: CLOBBERS 0-4,9,11,12
*D*      CALL:    BAL,10 IOWT
*D*               6=DCB ADDRESS
*D*      OUTPUT:  0-1: AVR ENTRY
*D*               2:   AVR INDEX
*D*               3:   TYC
*D*      INTERFACE: CHKREW,IOSPIN,GETTYC
*D*      DESCRIPTION: WAITS FOR ALL TAPE IO TO FINISH
IOWT     RES
         BAL,11   IOSPIN
         BAL,12   CHKREW
         NOP
         BAL,4    GETTYC
         B        *10
         PAGE
VOLHEDANS  EQU    %
*D*      NAME:    VOLHEDANS
*,*      INTERFACE SIXPACK, CNVBIN, READTP, IOSPIN, GETTYC, SKFILER,
*,*               MSR01EXIT
*,*      DESCRIPTION TRANSFERS THE INFORMATION IN THE PREVIOUSLY READ
*,*               HDR1 ANS LABEL TO THE DCB, THEN READS THE HDR2 AND
*,*               DOES SIMILARLY WITH IT, IF PRESENT.
*,*               THEN READS USER LABEL IF REQUESTED AND PRESENT.
         PUSH     SR4
         LW,R1    QBUF,R6
         SLS,R1   2
         AI,R1    21
         BAL,SR4  SIXPACK           CONVERT HDR1:SETID
         STW,2    VSETID,R6         SET IN DCB FOREVER!!!
         LW,R1    QBUF,R6
         LCI      2
         LM,R0    6,R1              FILE SECTION NUMBER TO...
         SLD,R0   24
         LI,R1    0
         BAL,SR4  CNVBIN
         LI,R2    BACVI
         STB,R1   *6,R2              ..CVI
         LW,R1    QBUF,R6           GET FILE SEQUENCE NUMBER FROM
         LCI      2                 SENTINEL AND CONVERT TO BINARY.
         LM,R0    7,R1
         SLD,R0   24
         LI,R1    0
         BAL,SR4  CNVBIN
         LW,R2    R1
         LI,R3    K1FFFF
         STS,R2   FSN,R6            STORE FSN
         AND,R3   TLB,R6
         BEZ      %+3
         LI,R2    0                 SET 0 IN USER'S HEADER BUFFER
         STB,R2   *R3
         PUSH     1,R5
GETSENT  EQU      %
         BAL,SR2  READTP            READ SENTINEL
         BAL,10   IOWT
         CI,R3    6                 WAS IT A TAPE MARK
         BNE      GETSENT1
         BAL,SR2  SKFILER           YES, BACKSPACE FILE.
         BAL,10   IOWT
         PULL     1,R5
         B        PULLEXIT
X50000001 DATA    X'50000001'
THDR2    TEXT     'HDR2'
TUHL1    TEXT     'UHL1'
GETSENT1 EQU      %
         LW,D3    QBUF,R6
         LW,R2    *D3
         CW,R2    THDR2
         BNE      GETSENT2
         AI,D3    1                 ITS HDR2. GET TO FORMAT
         LB,R3    *D3               GET RECFM
         LI,R2    #FORMATS
         CB,R3    FORMAT,R2         LEGAL FORMAT
         BE       %+3
         BDR,R2   %-2
*
*E*      ERROR:   30 - 05  UNRECOGNIZED FORMAT SPECIFIED IN HDR2
*,*                        LABEL
*
         B        ABN3005           UNRECOGNIZED FORMAT
         SLS,R2   4
         LI,R3    X'70'
         STS,R2   FMT,R6            SET FORMAT
         LCI      2
         LM,R0    *D3               BLKSIZE
         SLD,R0   8
         AND,R1   YFF
         BAL,SR4  CNVBIN
         SCD,R0   -15
         LW,R1    YFFFE
         STS,R0   BLKSZ,R6          BLOCK SIZE
         AI,D3    1                 POINT TO LOG REC SIZE
         LCI      2
         LM,R0    *D3               GET LOG REC SIZE
         SLD,R0   16
         AND,R1   YFF
         BAL,SR4  CNVBIN            CONVERT TO BINARY
         SCD,R0   -15
         LW,R1    YFFFE
         STS,R0   LRCSZ,R6          LOGICAL RECORD LENGTH
         B        GETSENT
GETSENT2 EQU      %
         CW,R2    TUHL1
         BNE      GETSENT
         LI,R3    K1FFFF            ITS A USER HEADER
         AND,R3   TLB,R6            DOES USER WANT IT
         BEZ      GETSENT
         LW,R7    R3
         LI,D4    80
         BAL,R0   CKLIMIT
         BCS,3    BADUSLBL
         SLS,R3   2                 YES, TRANSFER IT TO HIS BUFFER
         LI,R2    80
         STB,R2   0,R3
         AW,R3    X50000001         COUNT+DISPLACEMENT
         LW,R2    QBUF,R6
         SLS,R2   2
         MBS,R2   0                 R2=SENTINEL BUFFER
*                                   R3=COUNT,USER BUFFER
         B        GETSENT
BADUSLBL LW,SR3   ULBLBAD
         SPACE    4
*
*E*      ERROR:   30 - 01  USER LABEL IS BAD ON TAPE
*
         B        MSR01EXIT
ULBLBAD  DATA     1**25+X'30'
*
         END

