         DEF      NSTAP:
NSTAP:   EQU      %
         SYSTEM   UTS
*
*
         DEF      NSTAP,NSTAPCU,NSLOG
*
*
         REF      MAGTAPE,VECT1,9TDOT,NEWERCK,MT64
         REF      FCSNSL1,FCSNSL2,FCSNSL3,FCSNSL4,FCEWR8
         REF      EXITEOT,EXITBOT,EXITTM,EXITBOTT,EXITDECT
         REF      EXITTMT,EXITEOTT,EXITTMCK,EXITTEST,EXITGOOD
         REF      EXITFOL,EXITNOT,EXITIS,EXTERASE,EXTSTORE
         REF      DCT1,DCT7,DCT17,DCT20
         REF      IOQ4,IOQ5,IOQ8,IOQ11
         REF      COMLIST,IOSCU,RE:ENT,CC3FAIL
         REF      MSG5,MSG9A,ERRLOG,TIME
         REF      Y2,XFF
*
         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
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
*
*
*        TYC CODES
*
TYCOK    EQU      1                 SUCCESS
TYCBOT   EQU      3                 LOAD POINT
TYCEOT   EQU      5                 END OF TAPE
TYCTM    EQU      6                 TAPE MARK (END OF FILE)
TYCERR   EQU      8                 ERROR
*
*        FLAGS
*
FLGRETRY EQU      X'8000'
FLGFOLOW EQU      X'4000'
FLGINTER EQU      X'2000'
FLGKEYNC EQU      X'800'
FLGHOLD  EQU      X'400'
*
*        ORDER CODES
*
RDBCODE  EQU      12                READ BACKWARD
SRBCODE  EQU      75                SPACE RECORD BACKWARD
SFBCODE  EQU      91                SPACE FILE BACKWARD
SECODE   EQU      99                SET ERASE
RWONCODE EQU      19
*
*        SPECIAL CLIST AREA WORDS
*
SENSEBUF EQU      2                 SENSE DATA BUFFER, WDS 2-5
FUNCSAVE EQU      6                 CURRENT FUNCTION SAVE AREA
BYTESKIP EQU      7                 WT RECOVERY REV READ BYTE COUNTER
ERASEBUF EQU      7                 WT RECOVERY ERASE COUNT
*
*
MAXERASE EQU      10                MAX # OF 3 1/2 INCH ERASURES,WT RCV
*
         PAGE
************************************
*   NS TAPE PRE-PROCESSOR          *
************************************
NSTAP    EQU      %
         LI,R10   9TDOT
         OR,R4    Y2                HOLD CHAN FOR POSSIBLE SENSE
         B        COMLIST
*
*
************************************
*   CLIST AREA USAGE               *
*   WORD 0/1   CDW BUILDING        *
*   WORD 2/3/4/5   SENSE DATA      *
*   WORD 6   CURRENT FUNC SAVE     *
*   WORD 7   ERASEBUF.BYTESKIP     *
************************************
         PAGE
************************************
*   NS TAPE POST-PROCESSOR         *
************************************
NSTAPCU  EQU      %
         LB,R4    IOQ5,R3           GET CURRENT FUNCTION
         BAL,R0   RE:ENT
         ENABLE
         BAL,R7   NEWERCK           GENERAL ERROR TESTS
         B        NSTAP05           POSSIBLE ERRORS FOUND
         LB,R7    VECT1,R4          NO ERRORS; GET INDEX FOR
*                                    NO ERROR CLEANUP
         B        MAGTAPE,R7        GO TO N0-ERROR-CLEANUP
NSTAP05  EQU      %
         BAL,R15  TDVCCNOT          CHK FOR ERRORS, NOT
*                                    DEPENDENT ON FUNCTION
*        IF WE RETURN HERE, NO INDEPENDENT ERRORS WERE FOUND.
*        ANALYZE THE FUNCTION DEPENDENT ERRORS.
*
         LB,R7    VECT2,R4          GET INDEX FOR FUNCTION
*                                    DEPENDENT ERROR ANALYSIS
         LW,R4    IOQ8,R3           IS IT A DATA CHAINED CLIST
         BLZ      %+2               YES, IOCD'S ARE IN MPOOL
         LH,R4    DCT7,R1           GET CLIST AREA ADR
         SLS,R4   1                 MAKE IT A WORD ADR
         LB,R4    *R4               GET I/O ORDER FROM IOCD
         B        NSTAPCU,R7        GO TO ERROR ANALYSIS
         PAGE
*
*        ERROR CHECK FOR 'WRITE' AND 'WRITE TAPE MARK'
*
NSTAP10  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP14           TAPE MOVED
*                                   NO TAPE MOTION
         CI,R5    X'4000'           TDV1, WRITE RING INSTALLED
         BANZ     EXITSL4           YES, RETRY WITHOUT POSITIONING
         LI,R12   FLGKEYNC          NO, REQUEST KEYIN (NO C)
         LI,R13   MSG5              SEND 'WRITE PROTECTED' MESSAGE
         B        IOSCU             GO TO GENERAL I/O CLEANUP
*                                   TAPE MOVED, STOPPED IN GAP
NSTAP14  EQU      %
         CI,R5    X'7C'             TDV9,10,11,12,13; TDE OR IOP HALT
         BAZ      NSTAP17           NO
         LB,R5    IOQ5,R3           YES, GET CURRENT FUNCTION
         CB,R5    IOQ4,R3           IS IT REQUESTED FUNCTION
         BE       NSTAP16           YES, RECOVERY WITH POSITIONING
         B        EXITSL3           NO, ABORT RECOVERY SEQUENCE
NSTAP16  EQU      %
         LH,R6    DCT7,R1           CLEAR 'ERASEBUF' AND 'BYTESKIP'
         SLS,R6   1
         LI,R7    0
         BAL,R0   RE:ENT
         STW,R7   BYTESKIP,R6
         LB,R7    IOQ11,R3          GET REMAINING RETRIES
         CI,R7    MAXERASE          WILL THEY ERASE TOO MUCH TAPE
         BLE      %+2               NO
         LI,R7    MAXERASE          YES, FORCE TO MAX
         SLS,R6   1
         STH,R7   ERASEBUF,R6       SAVE ERASE COUNT
         B        EXITSL1
NSTAP17  EQU      %
         CI,R5    X'200'            TDV6, EOT
         BAZ      EXITSL3           UNKNOWN ERROR, INCONSISTENT STATUS
         LB,R5    IOQ5,R3           GET CURRENT FUNCTION
         CB,R5    IOQ4,R3           IS IT REQUESTED FUNCTION
         BE       EXITEOT           YES, REPORT EOT
         LB,R7    IOQ11,R3          GET RETRIES REMAINING
         BGZ      NSTAP18           SOME LEFT
         LI,R12   X'13'             NONE LEFT; REPORT WT ERROR AT EOT
         B        IOSCU
NSTAP18  EQU      %
         LI,R7    1                 ALLOW ONE RETRY AT EOT
         BAL,R0   RE:ENT
         STB,R7   IOQ11,R3
         LB,R7    VECT1,R5          CONTINUE RECOVERY SEQUENCE
         B        MAGTAPE,R7
         PAGE
*
*        ERROR CHECK FOR 'READ FOREWARD' AND 'READ BACKWARD'
*
NSTAP20  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP24           TAPE MOVED
*                                   NO TAPE MOTION
         CI,R4    RDBCODE           IS IT 'READ BACKWARD'
         BNE      EXITSL4           NO, RTY WITHOUT POSITIONING (RWP)
NSTAP22  EQU      %
         CI,R5    X'400'            TDV5, BOT
         BANZ     EXITBOT           LOAD POINT ENCOUNTERED
         B        EXITSL4           RWP
*                                   TAPE MOVED, STOPPED IN GAP
NSTAP24  EQU      %
         CI,R5    X'3C'             TDV10,11,12,13; IOP HALT
         BANZ     EXITSL1           NON-CORRECTABLE READ RECOVERY
         CI,R5    X'40'             TDV9, TDE
         BAZ      NSTAP26           IT ISN'T A TRANSMISSION DATA ERROR
         CI,R5    X'800'            TDV4, NONCORRECTABLE READ ERROR
         BAZ      EXITSL2           CORRECTABLE READ RECOVERY
         B        EXITSL1           NONCORRECTABLE READ RECOVERY
NSTAP26  EQU      %
         CI,R5    X'1000'           TDV3, TAPE MARK (TM)
         BANZ     EXITTM            END OF FILE ENCOUNTERED
         CI,R4    RDBCODE           IS IT 'READ BACKWARD'
         BE       NSTAP28           YES
         CI,R5    X'200'            TDV6, EOT
         BANZ     EXITEOT           END OF TAPE
         B        EXITSL3           INCONSISTENT STATUS
NSTAP28  EQU      %
         CI,R5    X'400'            TDV5, BOT
         BANZ     EXITBOT           LOAD POINT
         B        EXITSL3           INCONSISTENT STATUS
         PAGE
*
*        ERROR CHECK FOR 'SPACE RECORD' FOREWARD OR BACKWARD
*
NSTAP30  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP34           TAPE MOVED
*                                   NO TAPE MOTION
         CI,R4    SRBCODE           IS IT 'SPACE RECORD BACK'
         BNE      EXITSL4           NO, RWP
         CI,R5    X'400'            TDV5, BOT
         BANZ     EXITBOTT          YES, TEST FOR PRECORD
         B        EXITSL4           NO, RWP
*                                   TAPE MOVED, STOPPED IN GAP
NSTAP34  EQU      %
         CI,R5    X'7C'             TDV9,10,11,12,13; TDE OR IOP HALT
         BANZ     EXITDECT          TEST FOR M:PRECORD
         CI,R5    X'1000'           TDV3, TM
         BANZ     EXITTMT           TEST FOR PRECORD
         CI,R4    SRBCODE           SPACE RECORD BACK
         BE       NSTAP38           YES, CHK FOR LOAD POINT
NSTAP36  EQU      %
         CI,R5    X'200'            TDV6, EOT
         BANZ     EXITEOTT          TEST FOR SPACE FUNC REQUEST
         B        EXITSL3           INCONSISTENT STATUS
NSTAP38  EQU      %
         CI,R5    X'400'            TDV5, BOT
         BANZ     EXITBOTT          YES, TEST FOR PRECORD
         B        EXITSL3           NO, INCONSISTENT STATUS
         PAGE
*
*        ERROR CHECK FOR 'SPACE FILE' FOREWARD OR BACKWARD
*
NSTAP40  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP44           TAPE MOVED
*                                   NO TAPE MOTION
         CI,R4    SFBCODE           IS IT 'SPACE FILE BACK'
         BNE      EXITSL4           NO, RWP
         B        NSTAP22           NO MOTION, REVERSE FUNCTION
*                                   TAPE MOVED, STOPPED IN GAP
NSTAP44  EQU      %
         CI,R5    X'7C'             TDV9,10,11,12,13; TDE OR IOP HALT
         BAZ      NSTAP46           NO
*                                   IF TDE OR IOP HALT,CHK FOR BOT OR TM
         CI,R5    X'400'            TDV5, BOT
         BANZ     EXITBOTT
         LI,R6    EXITTMCK
         B        EXITTEST          TEST FOR M:PFIL
NSTAP46  EQU      %
         CI,R4    SFBCODE           IS IT 'SPACE FILE BACK'
         BE       NSTAP28           YES, CHK FOR LOAD POINT
         B        NSTAP36           LOOK FOR EOT
         PAGE
*
*        ERROR CHK FOR 'REWIND', 'MODE CONTROL' OR 'SET CORRECTION'
*
NSTAP50  EQU      %
         CI,R4    RWONCODE          IS IT ON-LINE REWIND
         BNE      NSTAP54           NO
         CI,R5    X'400'            YES, TDV5, BOT
         BANZ     EXITGOOD          YES, SUCCESSFUL REWIND
         B        EXITSL4           NO, NOT AT LOAD PT, TRY AGAIN
NSTAP54  EQU      %
         CI,R8    X'800'            TIO4, UNUSUAL END
         BAZ      EXITTEST          NO,  SUCCESSFUL NO MOTION ORDER
         B        EXITSL4           YES, TRY AGAIN
         PAGE
*
*        PHONEY GAP TEST FOR WRITE RECOVERY
*        FUNCTION WAS A 'READ BACKWARD WITH SKIP'
*
NSTAP60  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP64           TAPE MOVED
*                                   NO TAPE MOTION
         CI,R5    X'400'            TDV5, BOT
         BAZ      EXITSL4           RETRY WITHOUT POSITIONING
         LI,R5    FCEWR8            NEXT STEP AFTER BOT, WRITE TM
         B        EXTSTORE
*                                   TAPE MOVED, STOPPED IN GAP
NSTAP64  EQU      %
         CI,R5    X'7C'             TDV9-13, TDE OR IOP HALT
         B        MT64
         PAGE
*
*        ERASE TAPE DECISION FOR WRITE RECOVERY
*        FUNCTION WAS A 'SPACE RECORD BACKWARD'
*
NSTAP70  EQU      %
         BAL,R15  MOVTST            TEST FOR TAPE MOTION
         B        NSTAP74           TAPE MOVED
*                                   NO TAPE MOTION
         B        EXITSL4           RETRY WITHOUT POSITIONING
*                                   TAPE MOVED , STOPPED IN GAP
NSTAP74  EQU      %
         CI,R5    X'147C'           TDV3,5,9-13; TM,BOT,TDE OR IOP HALT
         BAZ      EXITSL3           INCONSISTENT STATUS
         B        EXTERASE
         PAGE
*
*        LOG SENSE DATA
*
NSLOG    EQU      %
         LH,R5    DCT7,R1           GET CLIST AREA ADR
         SLS,R5   1                 CONVERT TO WORD ADR
         LH,R7    DCT1,R1           GET CURRENT I/O ADR
         OR,R7    =X'16060000'      SET CODE/COUNT
         LW,R8    TIME              GET HHMM
         LCI      4                 NUMBER OF SENSE WORDS
         LM,R9    SENSEBUF,R5       SENSE DATA INTO REGS 9-12
         LW,R6    =X'40000007'      SET NO I/O AND MSG ADR
         BAL,R0   RE:ENT
         BAL,R5   ERRLOG            LOG MSG
         PAGE
*
*        RETRY, FOLLOW-ON, ABORT, OR RWP
*
AFTERLOG EQU      %
         LH,R5    DCT7,R1           GET CLIST AREA ADR
         SLS,R5   1                 MAKE IT A WORD ADR
         LW,R4    FUNCSAVE,R5       GET FUNCTION PERFORMED BEFORE SENSE
         LW,R5    9TDOT,R4          GET DOT ENTRY OF FUNCTION
         LB,R7    IOQ5,R3           GET DOT INDEX OF SENSE FUNC
         AI,R7    -FCSNSL1          GET RELATIVE INDEX OF SENSE
         LB,R7    AFTERSEN,R7       GET CONTINUATION INDEX
         B        AFTERLOG,R7
:SEN     COM,8    AF(1)-AFTERLOG
AFTERSEN EQU      %
         :SEN     NEXT1             RETRY WITH RETRY CODE
         :SEN     NEXT2             RTY WITH FOLLOW-0N CODE
         :SEN     NEXT3             ABORT OPERATION
         :SEN     NEXT4             RWP, RTY THE SAVED FUNC
NEXT2    EQU      %
         AND,R5   XFF               DON'T SENSE AFTER SENSE
         LW,R5    9TDOT,R5
         B        NEXT4A
NEXT3    EQU      %
         B        EXITIS
NEXT4    EQU      %
         LW,R5    R4
NEXT4A   EQU      %
         SLS,R5   8
NEXT1    EQU      %
         LI,R12   FLGRETRY+FLGINTER+TYCERR
NEXTOUT  EQU      %
         BAL,R0   RE:ENT
         STH,R5   DCT17,R1
         B        IOSCU
         PAGE
*
*        SENSE FOR ERROR LOGGING EXITS
*
EXITSL1  EQU      %
         LI,R5    FCSNSL1           SENSE,LOG,RETRY W/ RETRY CODE
         B        EXITSEN
EXITSL2  EQU      %
         LI,R5    FCSNSL2           SENSE,LOG,RETRY W/ FOLLOW-ON CODE
         B        EXITSEN
EXITSL3  EQU      %
         LH,R7    DCT1,R1           HIO,SENSE,LOG,ABORT OPERATION
         BAL,R0   RE:ENT
         LCI      0
         HIO,R0   0,R7
         BCS,2    CC3FAIL
         LI,R5    FCSNSL3
         B        EXITSEN
EXITSL4  EQU      %
         LI,R5    FCSNSL4           SENSE,LOG, RETRY W/O POSITIONING
EXITSEN  EQU      %
         BAL,R0   RE:ENT
         STH,R5   DCT17,R1
         LB,R4    IOQ5,R3           SAVE CURRENT FUNC IN CLIST AREA
         LH,R5    DCT7,R1
         SLS,R5   1
         STW,R4   FUNCSAVE,R5
         LI,R12   FLGFOLOW+FLGINTER+FLGHOLD
         B        IOSCU
*
*
EXITFOLL EQU      %
         B        EXITFOL
         PAGE
*
*        FUNCTION INDEPENDENT ERROR CHECK
*
TDVCCNOT EQU      %
         LC       DCT20,R1          TDV CC'S
         BCS,8+4  EXITSL3           INCONSISTENT STATUS
         CI,R8    X'6600'           TIO OPERATIONAL STATUS
         BANZ     EXITNOT           NOT OPERATIONAL
         B        *R15
*
*        TAPE MOTION DETERMINATION
*
MOVTST   EQU      %
         CI,R5    X'2100'           TDV2,7 TAPE MOTION TESTS
         BAZ      *R15              TDV2,7=00; TAPE MOVED,STOPPED IN GAP
         CI,R5    X'2000'
         BAZ      EXITSL3           TDV2,7=01 TAPE MOVED, POSITION LOST
         CI,R5    X'100'
         BAZ      EXITSL3           TDV2,7=10 TAPE MOVED, POSITION LOST
         AI,R15   1                 TDV2,7=11 NO TAPE MOTION
         B        *R15
         PAGE
*
*        NS 9-TRACK TAPE
*        ERROR BRANCH TABLE
*
:BCH2    COM,8    AF(1)-NSTAPCU
         BOUND    4
*
VECT2    EQU      %
         :BCH2    NSTAP20            0 RDF
         :BCH2    NSTAP10            1 WT
         :BCH2    NSTAP20            2 RDB
         :BCH2    NSTAP10            3 TM
         :BCH2    NSTAP30            4 SRB
         :BCH2    NSTAP30            5 SRF
         :BCH2    NSTAP40            6 SFB
         :BCH2    NSTAP40            7 SFF
         :BCH2    EXITFOLL           8 SRB-REW-ON
         :BCH2    EXITFOLL           9 SRB-REW-OFF
         :BCH2    NSTAP50           10 REW-ON
         :BCH2    NSTAP50           11 REW-OFF
         :BCH2    NSTAP50           12 MC
         :BCH2    NSTAP50           13 SENSE
         :BCH2    NSTAP30           14 SRB,NRZI RDF CORR RECOV
         :BCH2    NSTAP50           15 SC
         :BCH2    NSTAP50           16 SENSE
         :BCH2    NSTAP30           17 SRF,NRZI RDB CORR RECOV
         :BCH2    NSTAP50           18 SC
         :BCH2    NSTAP30           19 SRB,RDF NON-CORR RECOV
         :BCH2    NSTAP30           20 SRF,RDB NON-CORR RECOV
         :BCH2    NSTAP30           21 SRB,TM RECOVERY
         :BCH2    NSTAP50           22 SC,NS-NRZI WT RECOV
         :BCH2    NSTAP30           23 SRB OVER BAD WRITE
         :BCH2    NSTAP10           24 TM
         :BCH2    NSTAP30           25 SRB OVER TM
         :BCH2    NSTAP60           26 RDB WITH SKIP
         :BCH2    NSTAP40           27 SFF
         :BCH2    NSTAP28           30 SRF OVER GOOD RECORD
         :BCH2    NSTAP10           29 TM
         :BCH2    NSTAP70           30 SRB OVER TM
         :BCH2    NSLOG             31 SENSE
         :BCH2    NSLOG             32 SENSE
         :BCH2    NSLOG             33 SENSE
         :BCH2    NSLOG             34 SENSE
*
         END

