*M*      NSTAP    MAG TAPE HANDLER FOR MODELS 3345, 3347
         DEF      NSTAP:
NSTAP:   EQU      %
 TITLE '*** 3345 (NS TAPES) I/O HANDLER FOR E00 CP-V ***'
         SYSTEM   UTS
*
*
         DEF      NSTAP,NSTAPCU,NSLOG
*
*
         REF      9TDOT,NEWERCK,MT64
         REF      MT65
         REF      FCSNSL1,FCSNSL2,FCSNSL3,FCSNSL4,FCEWR8
         REF      FCSNSL5
         REF      TYC:TST
         REF      EXITRTY           START RETRY ROUTINE
         REF      WRITERR           WRITE ERROR BAILOUT IN MAGTAPE
         REF      MTAPCU1           COMMON NO ERROR CLEANUP PATH
         REF      EXITIS1           FORCE NO-MORE-RETRY ERROR EXIT
         REF      EXITOK            NORMAL COMPLETION EXIT POINT
         REF      MTAP30            SPACING ORDERS CHECKER
         REF      FCEWR6
         REF      CUSETUP           INIT CLEANUP REGISTERS ROUTINE
         REF      MTAP11            SEND 'WRITE PROTECTED' MSG ROUTINE
         REF      EXITFOL           START A FOLLOW-ON ENTRY
         REF      EXITIS            'INCONSISTENT STATUS' ERROR MSG ENTRY
         REF      EXTERASE          EXIT TO START ERASING ENTRY
         REF      EXTSTORE          EXIT REPLACING NEXT FC ENTRY
         REF      SPC:TST           CHECK IF USER ORIGINATED SPACE ORDER
         REF      EXITERR
         REF      DCT1,DCT7,DCT17
         REF      DCT3              TO TEST WHETHER TIMEOUT OCCURRED
         REF      IOQ5
         REF      COMLIST,IOSCU
         REF      ERRLOG
         REF      Y2,XFF
         REF      IOSEREC
         REF      MTAP16            ROUTINE TO BUILD WRITE ERR TABLES
*
         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
              PAGE
*
*
*
*        CLIST AREA WORD USAGE
*
*                                                          *
*0            7              15             23             31
*----------------------------------------------------------*
*                                                          *
*             COMMAND DBL-WORD WORD ZERO                   *
*                                                          *
*----------------------------------------------------------*
*                                                          *
*             COMMAND DBL-WORD WORD ONE                    *
*                                                          *
*----------------------------------------------------------*
*                                                          *
*             SENSE BUFFER WORD ZERO                       *
*                                                          *
*----------------------------------------------------------*
*                                                          *
*             SENSE BUFFER WORD ONE                        *
*                                                          *
*----------------------------------------------------------*
*                                                          *
*             SENSE BUFFER WORD TWO                        *
*                                                          *
*----------------------------------------------------------*
*                                                          *
*             SENSE BUFFER WORD THREE                      *
*                                                          *
*----------------------------------------------------------*
*             *                                            *
*CURRENT FUNC *  BYTE COUNT OF WRITE ERROR RECORD ON TAPE  *
*  CODE       *  (USING REQUESTED COUNT - R.B.C.)          *
*----------------------------------------------------------*
*                            *                             *
* # OF ERASURES NEEDED       * # OF BYTES SKIPPED ON TAPE  *
* TO COVER UP WRITE ERROR    * (IN TRYING TO RE-POSITION)  *
*----------------------------------------------------------*
         PAGE
************************************
*   NS TAPE POST-PROCESSOR         *
************************************
NSTAPCU  EQU      %
         BAL,R7   NEWERCK           GENERAL ERROR TESTS
         B        NSTAP05           ERROR PATH...
         B        MTAPCU1           NO ERROR CLEANUP JOIN-UP POINT
*
*        ERROR CLEANUP PATH FOR NS DRIVES
*
NSTAP05  EQU      %
         LC       DCT3,R1           DID DEVICE TIMEOUT?
         BCR,1    %+5               N, CONTINUE
         LI,R15   X'2100'           Y, DID TAPE MOVE?
         CS,R15   R5                 (I.E., ARE TDV 2,7 NE 11?)
         BNE      MT65              Y, REPORT LOST POSITION
         B        IOSCU             N, REPORT TIMEOUT
         CI,R8    X'6600'           MAKE TIO OPERATIONAL TEST
         BANZ     EXITSL5           DEVICE NOT OPERATIONAL
*
*        GETTING HERE INDICATES THAT THE DEVICE IS OPERATIONAL AND
*        SOME OPERATION DEPENDENT ERROR HAS OCCURED
*
         BAL,R7   CUSETUP           SET UP CLEANUP REGISTERS
         LB,R7    VECT2,R4          GET VECTOR VALUE
         B        NSTAP,R7          DISPATCH ERROR ANALYSIS ROUTINE
*
         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
         B        MTAP11            SEND WRITE PROTECTED MSG TO OPER/RTY
*
*        TAPE MOVED-HAS WRITE RING
*
NSTAP14  EQU      %
         CI,R5    X'7C'             TDV9,10,11,12,13; TDE OR IOP HALT
         BAZ      NSTAP17           NO
         BAL,R12  MTAP16            GO INIT WRITE ERROR TABLES
         B        EXITSL1
         PAGE
*
*        NOT TDE/IOP HALT ERROR - TAPE HAS MOVED
*
NSTAP17  EQU      %
         CI,R5    X'200'            TDV6, EOT
         BAZ      EXITSL3           UNKNOWN ERROR, INCONSISTENT STATUS
         B        MTAPCU1           JOIN UP NO ERROR PATH
         PAGE
*
*        ERROR CHECK FOR 'READ FOREWARD' AND 'READ BACKWARD'
*
NSTAP20  EQU      %
         CI,R5    X'1600'           DID WE HIT TM/EOOT/BOT
         BANZ     TYC:TST           YES-> TELL DER USER
         BAL,R15  MOVTST            NONE OF THOOSE-> SEE IF TAPE MOVED
         B        NSTAP24           MOOVED OK
         B        EXITSL4           RETRY IF NO MOTION
*
*        TAPE MOOVED - STOPPED IN RECORD 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      EXITSL3           INCONSISTENT STATUS IF NOT
         CI,R5    X'800'            TDV4, NONCORRECTABLE READ ERROR
         BAZ      EXITSL2           CORRECTABLE READ RECOVERY
         B        EXITSL1           NONCORRECTABLE READ RECOVERY
         PAGE
*
*        ERROR CHECKING ON ALL 'SPACING' ORDERS
*
NSTAP30  EQU      %
         BAL,R15  MOVTST            CHECK FOR TAPE MOVEMENT
         B        MTAP30            MOVED OK-> MERGE
*
*        NO TAPE MOVEMENT ON LAST ORDER
*
         CI,R5    X'1600'           TM/BOT/EOT ONLY LEGAL STOPS
         BAZ      EXITSL3           INCONSISTENT STATUS IF NOT
         B        SPC:TST           SEE IF USER ORIGINATED OR HANDLER
         PAGE
*
*        ERROR CHECK FOR ALL TYPES OF REWINDS
*
NSTAP50  EQU      %
         CI,R5    X'400'            YES, TDV5, BOT
         BANZ     EXITOK            POST NORMAL TYC AND EXIT
         B        EXITFOL           DO ANOTHER REWIND THEN
*
*        ERROR CHECK FOR            'MODE CONTROL',;
*                                   'SET CORRECTION',;
*                                   'SET ERASE',;
*                                   'SENSE'
*
NSTAP54  EQU      %
         CI,R8    X'800'            TIO4, UNUSUAL END
         BANZ     EXITSL4           YUP--RETRY AGAIN
         B        EXITOK            NOPE- SUCCESSFUL NO MOTION ORDER
         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
*
         CI,R5    X'1600'           HIT TM / BOT / EOT
         BAZ      EXITSL4           NO-> RETRY WITHOUT RE-POSITION
         CI,R5    X'1000'           A TAPE MARK SEEN
         BANZ     NSTAP61           YES
         LI,R5    FCEWR8            NO-> EOT/BOT
         B        EXTSTORE          STORE NEW FC
*
NSTAP61  EQU      %
         LI,R5    FCEWR6            NEXT FC AT TAPE MARK
         B        EXTSTORE          STORE NEW FC AND CONTINUE
*
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
         LCI      4                 NUMBER OF SENSE WORDS
         LM,R9    SENSEBUF,R5       SENSE DATA INTO REGS 9-12
         LI,R6    7               POINT TO MSG  LOC
         BAL,R5   ERRLOG          AND RECORD ERROR MSG...
*
*        RETRY, FOLLOW-ON, ABORT, OR RWP
*
AFTERLOG EQU      %
         LH,R5    DCT7,R1           GET CLIST AREA ADR
         LD,R8    FUNCSAVE,R5       GET THE DOUBLEWORD THAT
         LB,R4    R8                CONTAIINS THE SAVED FUNCTION CODE
         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 OPER, 'INCONSISTENT STATUS'
         :SEN     NEXT4             RWP, RTY THE SAVED FUNC
         :SEN     NEXT5             ABORT OPERATION, 'ERROR'
*
*
         BOUND    4
*
NEXT2    EQU      %
         AND,R5   XFF               DON'T SENSE AFTER SENSE
         LW,R5    9TDOT,R5
         B        NEXT4A
NEXT5    EQU      %
         B        EXITERR
NEXT3    EQU      %
         B        EXITIS
NEXT4    EQU      %
         LW,R5    R4
NEXT4A   EQU      %
         SLS,R5   8
NEXT1    EQU      %
         STH,R5   DCT17,R1          STORE NEW CODE FOR RETRY EFFORT
         B        EXITRTY           START A RETRY SEQUENCE
         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      %
         LI,R5    FCSNSL3           PREPARE 'INCONSISTENT STATUS' SEQ
         B        %+2
EXITSL5  EQU      %
         LI,R5    FCSNSL5           PREPARE 'ERROR' ABORT SEQ
         CI,R12   X'C008'           DID WE LOG A PRIMARY ENTRY
         BE       %+2               YES
         BAL,R9   IOSEREC           NO, GO DO IT NOW
         LH,R7    DCT1,R1           HIO,SENSE,LOG,ABORT OPERATION
         HIO,R0   0,R7
         B        EXITSEN
EXITSL4  EQU      %
         LI,R5    FCSNSL4           SENSE,LOG, RETRY W/O POSITIONING
EXITSEN  EQU      %
         STH,R5   DCT17,R1
         LB,R4    IOQ5,R3           SAVE CURRENT FUNC IN CLIST AREA
         LH,R5    DCT7,R1
         LD,R8    FUNCSAVE,R5       PICK UP THE DOUBLEWORD
         STB,R4   R8                SAVE CURRENT FUNCTION CODE
         STD,R8   FUNCSAVE,R5       AND REPLACE IT FOR LATER
EXITFOLL EQU      %
         LI,R12   FLGFOLOW+FLGINTER+FLGHOLD
         B        IOSCU             BACK TO IOQ
         PAGE
*
*        TAPE MOTION DETERMINATION
*
MOVTST   EQU      %
         CI,R6    4                 CHECK AIO STATUS FOR WRITE VIOLATION
         BANZ     WLKVIOL           **ERROR
         CI,R5    X'2100'           TDV2,7 TAPE MOTION TESTS
         BAZ      *R15              TDV2,7=00; TAPE MOVED,STOPPED IN GAP
         CI,R5    X'2000'
         BAZ      MOVTST1           TDV2,7=01 TAPE MOVED; LOST OR BOT
         CI,R5    X'100'
         BAZ      EXITSL5           TDV2,7=10 TAPE MOVED, POSITION LOST
         AI,R15   1                 TDV2,7=11 NO TAPE MOTION
         B        *R15
MOVTST1  EQU      %
         CI,R5    X'1600'           TAPE MARK / BOT / EOT
         BANZ     *R15              YUP--> REPORT THOSE
         B        EXITSL5           NO, ABORT OPERATION
*
WLKVIOL  EQU      %
         LI,R13   WLKMSG
         B        EXITIS1
*
WLKMSG   TEXTC    ' WRITE LOCK VIOLATION '
         PAGE
*
*        WRITE ERROR RECOVERY FAILED
*
NSWRC    EQU      %
         B        WRITERR           MERGE W/COMMON ERROR PATH
         PAGE
*
*        NS 9-TRACK TAPE
*        ERROR BRANCH TABLE
*
:BCH2    COM,8    AF(1)-NSTAP
         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    NSTAP30           S.F.B.
         :BCH2    NSTAP30           S.F.F
         :BCH2    EXITFOLL           8 SRB-REW-ON
         :BCH2    EXITFOLL           9 SRB-REW-OFF
         :BCH2    NSTAP50           10 REW-ON
         :BCH2    NSTAP50           11 REWIND OFF-LINE
         :BCH2    NSTAP54           12 MODE CONTROL
         :BCH2    NSTAP54           13 SENSE
         :BCH2    NSTAP30           14 SRB,NRZI RDF CORR RECOV
         :BCH2    NSTAP54           15 SET CORRECTION
         :BCH2    NSTAP54           16 SENSE
         :BCH2    NSTAP30           17 SRF,NRZI RDB CORR RECOV
         :BCH2    NSTAP54           18 SET CORRECTION
         :BCH2    NSTAP30           19 SRB,RDF NON-CORR RECOV
         :BCH2    NSTAP30           20 SRF,RDB NON-CORR RECOV
         :BCH2    NSTAP30           21 SRB,TM RECOVERY
         :BCH2    NSTAP54           22 SET ERASE-NS PE WT TM RCVRY
         :BCH2    NSTAP54           23 SET CORR -NS NRZI WRIT RCVRY
         :BCH2    NSTAP30           24 SRB OVER BAD WRITE
         :BCH2    NSTAP10           25 TM
         :BCH2    NSTAP30           26 SRB OVER TM
         :BCH2    NSTAP60           27 RDB WITH SKIP
         :BCH2    NSTAP30           28 S.F.F.
         :BCH2    NSTAP30           29 S.R.B.
         :BCH2    NSTAP54           30 SET ERASE
         :BCH2    NSTAP10           31 TM
         :BCH2    NSTAP70           32 SRB OVER TM
         :BCH2    NSLOG             33 SENSE
         :BCH2    NSLOG             34 SENSE
         :BCH2    NSLOG             35 SENSE
         :BCH2    NSLOG             36 SENSE
         :BCH2    NSLOG             37 SENSE
         :BCH2    NSWRC             38 REWRITE USERS RECORD
         :BCH2    NSTAP30           39 SRB
         :BCH2    NSTAP30           40 SRB
         :BCH2    NSTAP30           41 READ FORWARD W/SKIP
         :BCH2    NSWRC             42 READ FOREWARD W/SKIP
*
         END

