MONPROC  SET      1
ANSPROC  SET      1
         SYSTEM   UTS
         REF      CHKANS0,CHKANS1
         REF      CLSSEG
         DEF      POS
POS      EQU      %
         PAGE
         BOUND    8
K2       EQU      2
K400     EQU      X'400'
K7FFF    EQU      X'7FFF'
K7       EQU      X'7'
KD       EQU      X'D'
K0F      EQU      X'F'
K0C      EQU      X'0C'
K0E      EQU      X'0E'
K0       EQU      X'0'
K1       EQU      X'1'
K4       EQU      X'4'
KA       EQU      X'A'
K10      EQU      X'10'
K1F      EQU      X'1F'
K50      EQU      X'50'
K1000    EQU      X'1000'
K1FFFF   EQU      X'1FFFF'
         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     POS DEFS
         DEF      PFIL
         DEF      PRECORD
         DEF      REW
         DEF      WEOF
         DEF      PEOF
         DEF      PLEOFRM
         SPACE    4
W14      EQU      14                CURRENT REC #
W19      EQU      19                # OF RECS TO BE SKIPPED
         PAGE     POS REFS
         REF      CLRMBG
         REF      ESTABBUF
         REF      FNDKYT
         REF      GETTYC
          REF     MSREXIT
         REF      PULLALLEXIT
         REF      PULLEXIT
         REF      PUTSZBF
         REF      REDSEC
         REF      SETBTDZ
         REF      SETCMD1
         REF      SETLKEYUB
         REF      SETTYC
         REF      TAPEOP
         REF      Y000C,Y0008,CHKBIT1,CHKBIT,Y001
         REF      ABO
         REF      GETFUN
         REF      DEOD
         REF      CBB5
         REF      MSRWRTX
         REF      TB:FLGS,GETASN
         REF     XFF,M6
         REF      IOSPIN
         REF      NBATAPE
         REF      AVRTBL
         REF      DOUBLEZERO
         REF      PRDCRD11
         REF      PUSHALL
         REF      OPNSEG
         REF      Y002
         REF      Y8
         REF      GETSEC
         REF      LBLTSEG
*
*        VARIOUS LITERAL CONSTANTS
*
         BOUND    8
NO%OR%ME EQU      %
         DATA     X'10'             METYPE SPCL CASE FOR COC
         DATA     0                 NOTYPE OUTPUT NOP
         BOUND    8
PTL      EQU      %
         GEN,8,16,8 X'80',0,X'10'
         DATA     2
PTV      GEN,8,16,8  X'80',0,X'80'
         DATA     2
REWMSK   DATA     X'9FFFFFFF'
         REF      ERO
         PAGE
SKFILE   EQU      %                 SKIP FILE FORWARD
         LI,SR3   K0C
SKFILE1  EQU      %
         BAL,SR4  GETAVR
         AI,R1    1                 INCR TM COUNT
PREOP    STD,R0   AVRTBL,R3
RESEIVC  EQU      %
         INT,R0   RNR,R6  CLR R0 BYTE 0, RNR TO CC2
         LW,R1    Y2                EIC. LW DOES NOT DISTURB CC2
         BCR,4    %+2              TEST CC29 IS RNR ON
         AW,R1    Y1                YES. MERGE EVC
         REF      Y1,Y2
         STS,R0   ORG,R6            CLEAR EIC & IF RNR ON, EVC TOO
         B        TAPEOP
SKFILER  EQU      %
         LI,SR3   KD
         BAL,SR4  GETAVR
         CI,R1    X'FFFF'
         BAZ      %+2               NEVER GO NEG
         AI,R1    -1                DECR TM COUNT
         B        PREOP
REWTP    EQU      %                 REWIND TAPE
         LI,SR3   K0E
         BAL,SR4  GETAVR
         AND,R1   YFFFF             CLEAR TM COUNT
         REF      YFFFF
         B        PREOP
SKREC    EQU      %
         LI,SR3   K400
         AND,SR3  DIR,R6
         SLS,SR3  -10
         LCW,SR3  SR3               FSR=5,BSR=4
         AI,SR3   5
         LW,15    NVA,6             # RECORDS
         LI,0     PRECEA
         REF      PRECEA,DONEWQP
         B        DONEWQP
*
SETEOPZ  EQU      %
         LI,D1    K0
SETEOP   EQU      %
         LW,D2    Y000C
         STS,D1   EOP,R6
         B        *R0
*
*
*
TESTOPN  EQU      %
         BAL,R1   PUSHALL           SEE IF DCB IS OPEN
         LW,D2    Y002
         CW,D2    FCD,R6
         BANZ     TSTOPX
         PUSH     R7
         REF      J:BASE
         LW,R7    J:BASE
         PUSH     R7
         LI,R7    DOUBLEZERO+1
         OVERLAY  OPNSEG,0
         PULL     R7
         STW,R7   J:BASE
         PULL     R7
         AI,SR3   0
         BNEZ     PXX
         LW,R1    TSTACK
         LCI      7
         LM,R5    -7,R1
TSTOPX   BAL,1    JASN              D2=ASN
*
         B        CHKRAND
         CI,SR1   WEOF+1
         BE       WEOF+1
         BAL,1    TCHK
         B        MSRWRTXX          NOT TAPE
         B        *SR1              TAPE
CHKRAND  CI,D2    2                 LTAPE ?
         BE     SETLESS             MUST SET CC
         BG       PXX
         LI,R1    X'30'
         AND,R1   ORG,R6
         CI,R1    X'30'
         BE       MSRWRTX           RAND FOR DISK
         B        *SR1
SETLESS  CI,D2   20
         B   *SR1
*
*
WRTEOF   LI,SR3   K0F
         LI,SR4   SKFILE1
*
GETAVR   EQU      %
         LW,3     DSI,6
         AND,3    XFF               DCTX
         AI,R3    NBATAPE
         LD,R0    AVRTBL,R3
         B        *SR4
         PAGE     PFIL
*                                   POSITION TO BEGINNING OR END OF FILE
*
*
PFIL     EQU      %
         BAL,SR1  TESTOPN
         CI,D2    3                 * IS DEVICE
         BNE      PFIL1             *NO, FILE OR LABEL TAPE
         LI,SR2   PRECORDX          RETURN ADDRESS
         LI,D2    K10
         STW,D2   NVA,R6
         AND,D2   0,R7
         BEZ      SKFILE            SKIP FILE FORWARD
         B        SKFILER           SKIP FILE REVERSE
PFIL1    EQU      %
         CI,D2    K2
         BE       PFIL4
*                                   POSITION TO BEGINNING OR END OF FILE
*                                   ON DISK OR LABELED TAPE
         LI,R3    K10
         AND,R3   0,R7
         BNEZ     PFILB             BOF DESIRED
*                                   EOF DESIRED
PEOF     RES      0
         BAL,SR1  TSTOPX            CHK FOR RANDOM FILE
         LI,SR1   X'20'
         CW,SR1   ORG,6
         BANZ     PEOF1
         LW,1     CFU,6
         LW,R3    TDA,1             GET LAST REC #
SEQ3     SW,R3    W14,6             CURRENT REC #
         STW,R3   W19,6             SET # RECS TO BE SKIPPED
         B        PFILB2            GET OUT
PEOF1    RES      0
*
         BAL,R0   GETSEC            MI BUFFER
         LW,D1    LDA,R1            LAST LVL 0
         BEZ      PEOFZ             NO LAST
         BAL,R0   REDSEC            READ LAST GRANULE
         LW,D1    BUFF2+FLINK       GET FLINK
         BEZ      PFILD2             LAST
PEOFZ    BAL,SR4  TRUNC             CLR & REL BFR
         REF      TRUNC
         BAL,R0   ESTABBUF          GET SECTOR BUFFER
         B        PFILE2
PFILD1   EQU      %
         LW,D1    BUFF2+FLINK       GET FLINK
         BEZ      PFILD2            YES
         BAL,R0   REDSEC            NO--READ IN NEXT GRANULE
         B        PFILD1
PFILD2   EQU      %
         LH,R3    BUFF2+NAVX        GET NAV
         BAL,R0   FNDKYT
         B        PRECORDX
         BAL,R0  SETLKEYUB
PFILE2   EQU      %
         B        PFILB2
*
PFILB    EQU      %
         LI,R3    X'20'
         AND,R3   ORG,6
         BEZ      SEQ3              CONSECUTIVE
*
         LI,R3    K0                SET CMD = 0
         BAL,R0   SETCMD1
PFILB2   EQU      %
         LI,D1    K0
         BAL,R0   SETTYC
         B        PRECORDX
*
*
PFIL4    EQU      %
*                                   POSITION LABELED TAPE
         BAL,SR4  IOSPIN
         LI,R3    K10
         AND,R3   0,R7
         BEZ      PLEOF
*                                   BOF
         BAL,R0   CHKANS0           NO PFIL FOR ANS BOF
         B        MSREXIT
         LW,R0    SCR,R6           SAVE IMPT DCB ENTRIES
         LW,R1    ACD,R6
         PUSH     2,R0
         LD,R0    PTL
         PUSH     2,R0
         LW,R7    TSTACK
         AI,R7    -1
         LI,SR4   PLBOF
         REMEMBER
         BAL,R1   PUSHALL
         OVERTO   OPNTPSEG,CLSLBL#
         REF      OPNTPSEG,CLSLBL#
PLBOF    EQU      %
         PULL     2,R0
         PULL     2,R0
         AI,SR3   0
         BEZ      %+3
PXX      EQU      %
         DESTRUCT PULLALLEXIT
         STW,R0   SCR,R6
         STW,R1   ACD,R6
         BAL,SR2  SKFILE
         BAL,SR2  SKFILE
         BAL,SR4  GETAVR
         AND,R1   L(X'FBFFFFFF')
         AI,R1    X'10000'
         STD,R0   AVRTBL,R3
*
         LW,R1    Y002
         STS,R1   FCD,R6
         LI,R0    K0
         LW,R1    KBUF,R6
         STW,R0   0,R1
         B        PRECORDX
*
PLEOF    EQU      %
*                                   GO TO EOF
         LW,R1    Y0008
         CW,R1    EOP,R6
         BANZ     PRECORDX1
         LI,R0    0                 TELL CHKEOF THAT FROM PFIL
         LI,R1    K1FFFF
         STS,R0   BUF,R6
         LW,R1    Y08               AVOID POSSIBLE PROBLEM
ULBL    EQU  5
         STS,R0   ULBL,R6
PLEOF1   EQU      %
PLEOFRM  RES      0
         BAL,SR2  SKFILE
         OVERLAY  LBLTSEG,5
         CI,9     -1
         BNE      PLEOF2
         LW,SR2   Y002              CHECK DCB OPEN
         CW,SR2   FCD,R6
         BANZ     PLEOF1            YES-CVOL WAS OK
         LI,SR3   X'56'
         B        MSR01EXIT         CVOL BLEW IT
         REF      MSR01EXIT
PLEOF2   EQU      %
         BAL,R0   CLRBBUFL
         LI,R0    K0
         LI,R1    X'E0000'
         STS,R0   BFL,R6
         B        PRECORDX
CLRBBUFL EQU      %
         PUSH     8,D1
         B        CBB5
         PAGE     REW
*                                   REWIND DISK,LABELED TAPE FILES AND
*                                   UNLABELED TAPES
*
*
REW      EQU      %
         CLEAR
         LW,R1    Y002
         CW,R1    FCD,R6
         BAZ      REW3
REW4     EQU      %
         BAL,SR1  TESTOPN
         BAL,R0   CHKANS1
         B        REW5              NOT ANS
         LD,R0    PTV               POSITION TO VOLUME
         PUSH     2,R0
         LW,R7    TSTACK
         AI,R7    -1
         LI,SR4   PULLALLEXIT
         OVERTO   CLSSEG,0          CLOSE AT MSRCLS
REW5     LI,R7    PTL
         BAL,1    JASN
         B        PFIL1
*                                   BOF
         LW,SR2   Y8
         XW,SR2   NVA,R6
         BGEZ     %+4               LAST NOT REW
         LW,SR2   Y000C
         CW,SR2   EOP,R6
         BAZ      %+2               SKIP MULT REWS
         BAL,SR2  REWTP             MT DEVICE--REWIND
         BAL,SR4  GETAVR
         AND,R1   REWMSK                                                720
         STD,R0   AVRTBL,R3
         B        PRECORDX
REW3     EQU      %
         BAL,1    JASN
         DESTRUCT
         B        REW4
         PAGE     WEOF
*                                   WRITE END OF FILE ON UNLABELED TAPES
*                                   R5 =JIT ADR
*                                   R7 =PLIST ADR
*                                   SR1 = OPCODE
*                                   BAL,SR4 WEOF
WEOF     EQU      %
         BAL,SR1  TESTOPN
         BAL,R0   CHKANS0
         B        MSRWRTX
         BAL,D2   GETFUN
         CI,D1    K1
         BE       MSRWRTXX
         BAL,1    JASN
         B        MSRWRTXX
         BAL,1    TCHK
         B        %+2               NOT TAPE
         B        TAPEJ
         BCR,1    MSRWRTXX          NOT OUT
         BCS,12   WFDL              * 11,01:  DISC OR LIST
         CLM,3    NO%OR%ME          * 00: IS IT 'NO' OR 'ME'
         BE       MSRWRTXX          *   'ME' IS SPCL CASED FOR COC
         BCR,12   MSRWRTXX          *   'NO' IS A NOP WEOF
         B        PUNWEOF           *   'XX' 00X1 => DEV GETS AN EOD
*
WFDL     EQU      %                 * WEOF DISC OR LIST
         BCR,8    TOFM              01X1
         B        MSRWRTXX          11X1
TAPEJ    RES      0
         BAL,SR2  WRTEOF
         STW,SR2  NVA,R6            SET NVA POSITIVE
         B        PRECORDX
PUNWEOF  EQU      %                 PUNCH !EOF
         LI,R2    KNEOD
         LI,D3    DEOD
         BAL,R0   RWPUNCC
WEOF1    EQU      %
         LW,D1    Y0008
         BAL,R0   SETEOP
         B        PRECORDX1
*
*
TOFM     EQU      %
         LI,SR1   K4
         BAL,SR4  IOSDEV
         REF      IOSDEV
         B        WEOF1
         PAGE
JASN     BAL,0    GETASN            D2
         CI,D2    3                 DEVICE
         BNE      0,1
         B        1,1
TCHK     EQU      %
         REF      J:USCDX
         LI,3     X'F'
         AND,3    CLK,6
         BEZ      TCHK1
         LW,3     *J:USCDX,3
         BEZ      TCHK1
         STW,3    J:BASE+3
         LW,3     1,3
         SLS,3    16
         LC       3
         B        TCHK2
TCHK1    EQU      %
         LI,3     BADEVTP
         LB,3     *6,3
         AND,3    M6
         LC       TB:FLGS,3
TCHK2    EQU      %
         BCR,8    0,1
         BCS,4    0,1
         B        1,1               TAPE
         PAGE     PRECORD
*                                   THIS ROUTINE SKIPS THE SPECIFIED
*                                   NUMBER OF RECORDS FORWARD OR BACKWRD
*                                   ON TAPE AND DISK FILES
*                                   R5 = JIT
*                                   R6 = DCB
*                                   R7 = PLIST
*                                   SR1 = OPCODE
*                                   CALLING SEQ--BAL,SR4   PRECORD
PRECORD  EQU      %
         BAL,SR1  TESTOPN
         BAL,R0   CHKANS0
         B        MSRWRTX
         LI,D1    K1
         BAL,R2   CHKBIT1
         B        %+1
         BAL,R0   SETPOS
         LI,D2    K1FFFF
         BAL,R2   CHKBIT
         STS,D1   ABO,R5
         BAL,1    JASN
         B        PRECORD2
         BAL,SR4  GETAVR            SET R2 FOR EA
         LW,2     3
         LI,0     0                 INHTIALIZE
         STW,0    AVRSID,R3
         BAL,SR2           SKREC
         BAL,SR4           GETAVR
         DISABLE
PREC1    LI,7     0
         XW,7     AVRSID,R3         GET TYC,RRC
         BNEZ     PRECX
         PUSH     R6
         LI,R6    E:NQW
         BAL,SR4  T:REG
         PULL     R6
         B        PREC1             CHECK IF DONE YET
PRECX    ENABLE
         LB,D1    7                 TYC
         AND,7    M24
         BAL,R0   SETTYC
         B        PRECL4
         REF      AVRSID
         REF      E:NQW
         REF      T:REG
*                                   DOES USER WANT TO WAIT
PRECORDX EQU      %
         BAL,R0   SETEOPZ
PRECORDX1  EQU    %
         LI,D1    K0
         LW,D2    Y001
         STS,D1   WAT,R6
         DESTRUCT MSREXIT
SETPOS   EQU      %
         STW,D1   NVA,R6
         LW,D1    0,R7              SAVE DIRECTION
         SLS,D1   6
         LI,D2    K400
         STS,D1   DIR,R6
         B        *R0
*
PRECORD2 EQU      %
         CI,D2    K2
         BE       PRECL3
         PAGE
         LI,0     X'20'
         CW,0     ORG,6
         BANZ     SEQ7              KEYED
         LW,0     CDA,6             # TO BE SKIPPED
         LI,2     K400
         CW,2     DIR,6             CHK DIRECTION
         BAZ      %+2               FORWARD
         LCW,0    CDA,6             BACKWARD
         AWM,0    W19,6             SET # TO BE SKIPPED
         LCW,0    W19,6
         SW,0     W14,6             NEW POSN
         BLEZ     SEQ8              OK SO FAR
SEQ2     RES      0                 ERROR AMOUNT
         AWM,0    W19,6             RESET SKIP COUNT
         B        SEQ9              SET TYC & OUT
SEQ8     LW,1     CFU,6
         AW,0     TDA,1             LAST REC #
         BLZ      SEQ2              BAD NEWS
         LI,0     0                 NO MORE TO SKIP
SEQ9     AI,0     0
         BGEZ     %+2
         LCW,0    0                 MAKE IT +
         STW,0    CDA,6
         LI,1     K7FFF
         SLD,0    17
         STS,0    ARS,6
         B        SETBOFEOF
SEQ7     RES      0
         LI,R0    X'8000'           SHARED BIT
         LW,R1    CFU,R6
         CW,R0    0,R1
         BAZ      SEQ71             NOT SHARED
         LI,R0    X'100'            CHK IN
         CW,R0    0,R1
         BANZ     %+2
         LW,R1    SCFU,R1
         LW,D1    COUNTS,R1
COUNTS   EQU      GAVAL
         LW,D2    YFF
         REF      YFF,M24
         LW,R2    TSTACK
         STS,D1   -2,R2             SAVE IN R10 IN PUSHALL
         LW,D2    M24
         CS,D1    CLK,R6
         BE       SEQ71
         STS,D1   CLK,R6
         BAL,SR4  TRUNC             FRESH BUFFERS
SEQ71    RES      0
         BAL,SR4  PRDCRD11
         LW,D1    CDA,R6            NO REMAINING TO SKIP
         LW,R1    CFU,R6
         BAL,R4   GETTYC
         BNEZ     1A1               EOF OR BOF
         LW,D2    FDA,R1
         BLEZ     1A2
         LI,D1    0                 FOR ARS
         B        1A2
1A1      LI,D2    X'400'
         CW,D2    DIR,R6
         BAZ      1A2
         AI,D1    K1
1A2      RES      0
         LI,D2    K7FFF
         SLD,D1   17
         STS,D1   ARS,R6
         LW,D1    FDA,R1
         BLEZ     SETBOFEOF         SET TYC 4 NULL FILES
*
         CI,R3    K7
*
         BNE      PRECORDX
         BAL,R0   SETLKEYUB         SET UP FOR EOF
         LW,D1    CDA,R6
         BNEZ     PRECORDX
*
SETBOFEOF  EQU    %
         LW,D1    CDA,R6
         BEZ      BOFEOF1
         LI,D1    K7
         LI,R1    K400
         CW,R1    DIR,R6
         BAZ      BOFEOF1           READ FORWARD
         LI,D1    K4
BOFEOF1  EQU      %
         BAL,R0   SETTYC
         B        PRECORDX
         PAGE
PRECL3   EQU      %
*                                   POSITION RECORD ON BLOCKED
*                                   LABELED TAPE
         LI,R0    K0
         STW,R0   RWS,R6
         LW,R1    Y08               RESET ULBL
         STS,R0   ORG,R6
         REF      Y08
         LW,R1    Y001
         STS,R1   WAT,R6
         LI,SR4   PRECL
         LW,R7    NVA,R6            READ ZERO RECORD LENGTH N TIMES
        BEZ        PRECL4
PRECL1   EQU      %
         LCI      K2                SAVE  ERO,ABO
         LM,R0    ERO,R5
         PSM,R0   TSTACK
         LI,R0    0
         LI,R1    K1FFFF
         STS,R0   KAD,R6
         REMEMBER
         BAL,R1   PUSHALL
         OVERTO   LBLTSEG,0
PRECL    EQU      %
         PULL     1,D3              RESTORE OVERRIDES
         LI,D4    K1FFFF
         STS,D3   ABO,R5
         PULL     1,D3
         STS,D3   ERO,R5
         LB,D3    SR3
         BEZ      PRECL5
         CI,D3    7                 CHK LOST DATA
         BNE      PRECL2
         LI,D1    0
         BAL,R0   SETTYC            RESET LOST DATA
PRECL5   RES      0
         BDR,R7   PRECL1
         B         PRECL4
PRECL2   EQU      %
         BDR,7     %+1
PRECL4   EQU       %
         LW,D3    R7                SET UP ARS
         LI,D4    K7FFF
         SLD,D3   17
         STS,D3   ARS,R6
         LI,D4    K1000
         STS,D3   EGV,R6
         B        PRECORDX
         PAGE
RWPUNCC  EQU      %                 R2 =SIZE
         PUSH     1,R0              D3 = ADDRESS
         PUSH    1,SR1
         BAL,SR4  PUTSZBF
         BAL,D4   SETBTDZ
         BAL,D4   CLRMBG
         REF      WRBCDCC
         BAL,SR4  WRBCDCC
         PULL     1,SR1
         B        PULLEXIT
MSRWRTXX EQU      %
         DESTRUCT MSRWRTX
         END

