         PCC      0                 DONT PRINT GARBAGE
         TITLE    'IOQ - UNMAPPED SEGMENT FOR I/O QUEUEING'
*M*      NAME:    IOQ - I/O QUEUEING MANAGER FOR CP-V SYSTEMS
*P*
*P*      THE FOLLOWING ROUTINES MAY BE FOUND IN THIS MODULE
*P*
*P*      ROUTINE        FUNCTION
*P*      -----------    -----------------------------------------------
*P*      CHKDA       ENTRY TO CHECK DISC ADDRS AND SAVE 4 THRU 6
*P*      CHKDAQ      ENTRY TO CHECK DISC ADDRS - NO REGISTER SAVE
*P*      DRIVEIO     ENTRY TO CHECK DEVICES WAITING CLEANUP/TIMEOUT.ETC.
*P*      FORCEIO     ALTERNATE ENTRY TO DRIVEIO
*P*      INTSIM      ENTRY TO SET CLEANUP PENDING-RESET BUSY...ETC
*P*      IOINT       I/O INTERUPT RECEIVER
*P*      IOSCU       RETURN FROM HANDLERS POST-PROCESSING
*P*      IOSST       RETURN FROM COMLIST FOR I/O STARTUP
*P*      MSGOUT      SEND MSG TO OPERATOR'S CONSOLE
*P*      MSG2        'ERROR' MESSAGE
*P*      MSG3        'TIMED OUT' MESSAGE
*P*      MSG4        'NOT OPERATIONAL' MESSAGE
*P*      MSG5        'WRITE PROTECTED' MESSAGE
*P*      MSG7        'CODE DISC ERR' MSG
*P*      MSG9        'REQ RETRY' MSG
*P*      MSG9A       'INCONSISTENT STATUS' MSG
*P*      NEWQ        MONITOR TYPE I/O ENTRY
*P*      NEWQNW      ENTRY TO NEWQ FOR NO-WAIT I/O
*P*      NEWQNWM     ENTRY TO NEWQ (MAPPED) FOR NO-WIAT I/O
*P*      OCINT       OPERATOR CONSOLE INTERRUPT RECEIVER
*P*      OCQUEUE     QUEUE MSG FOR OPERATOR'S CONSOLE
*P*      PL5BSR4     PLM INTO R5 AND B *R11
*P*      PVCHKDA     CHECK PRIVATE PACK DISC ADDRS
*P*      QUEUE       ENTRY FOR I/O WITH DCB AND NO END ACTION
*P*      QUEUE1      ENTRY FOR I/O WITH DCB AND END ACTION
*P*      Q15A        RETURN FROM RBQCK TO FINISH ENQUEUE OF I/O
*P*      Q51         RETURN FROM RBQCK TO THROW AWAY I/O REQUEST
*P*      RC20        ENTRY INTO REQUEST COMPLETE (REQCOM)
*P*      RC21        ENTRY INTO REQUEST COMPLETE (REQCOM)
*P*      RESCHED     RE-SCHEDULE I/O ENTRY
*P*      RTRET1      REAL-TIME USER RETURN POINT
*P*      RTRET2      REAL-TIME USER RETURN POINT
*P*
*
*        SET CONTROL SETTINGS FOR UTS PROCEDURES  AND INTERNAL
*        VERSIONS
*
OC       EQU          2
MONPROC  SET          1
DISCBPROC SET         1
BITS     SET          1
         SYSTEM       UTS
*
DEFER    SET          0          DO NOT DEFER START/CLEANUP
*
         PAGE
*
*        IOQ EXTERNAL REFERENCES
*
         REF      AVRDCT         * AVR'D DEVICE DCTX                          .
         REF      AVRTBLNE       * LAST DISC PACK AVRX+1                      .
         REF      BATAPE         * DCTX --> AVRX                              .
WABLK    EQU      BLK            *                                            .
         REF      BTDBIT         *                                            .
         REF      BUFLIMS        * LIMITS OF WA FROM MPOOL TO TOP             .
         REF      C:NOQ          * PERF. MON.. CELL FOR LACK OF A QUEUE       .
         REF      CFUBIT                                                      .
         REF      CHAINCHK
         REF      CIT1           * HEAD OF CHANNEL QUEUE #                    .
         REF      CIT2           * TAIL OF CHANNEL QUEUE #                    .
         REF      CIT3           * CHANNEL FLAGS                              .
         REF      CIT4           * INDEX OF HOLDING QUEUE #                   .
         REF      CIT5           *                                            .
         REF      CIT6           *                                            .
         REF      CJOB           * JIT POINTER AT LOC X'4F'                   .
         REF      CTACT          *                                            .
         REF      CTFLAGS        *                                            .
         SREF     CTGL           *                                            .
         SREF     CTINT          *                                            .
         REF      CTOC           *                                            .
         REF      CTRIG             TRIGGER CONTROL TASK
         SREF     CTWD           *                                            .
         REF      CURBQ          *                                            .
         REF      DCTSIZ         * LENGTH OF DCT TABLES                       .
         REF      DCT1           * DEVICE ADDRS TABLE                         .
         REF      DCT1A          * ALTERNATE DEVICE ADDRS  (DUAL-AC)          .
         REF      DCT1P          * PRIMARY DEVICE ADDRS  (DUAL-AC)            .
         REF      DCT10          * RE-ENTRANCY COUNTER                        .
         REF      DCT11          * DEVICE I/O OVERDUE TIME BUCKET             .
         REF      DCT12          * AIO STATUS BUCKET                          .
         REF      DCT13          * TDV STATUS BUCKET                          .
         REF      DCT14          * CHANNEL FLINK QUEUE INDEX                  .
         REF      DCT15          * CHANNEL BLINK QUEUE INDEX                  .
         REF      DCT16          * DEVICE NAME IN EBCDIC                      .
         REF      DCT17          * HANDLER CODES                              .
         REF      DCT18          * TIME-OUT INCREMMENTS (5 SECOND UNITS)      .
         REF      DCT19          * SIO/AIO CONDITION CODES                    .
         REF      DCT2           * CHANNEL  INFO TABLE INDEX                  .
         REF      DCT20          * TDV CONDITION CODES                        .
         REF      DCT21          * TIO STATUS                                 .
         REF      DCT22          * INDEX  INTO SEEK CONVERT TABLES            .
         REF      DCT25          * SIO COUNTER                                .
         SREF     DCT26             FEDX IN FECP SYSTEMS
         REF      DCT3           * I/O LEGALITY/DUAL ACCESS FLAGS             .
         REF      DCT4           * OH:NM INDEX                                .
         REF      DCT5           * DEVICE  FLAGS                              .
         REF      DCT6           * QUEUE HEAD INDEX                           .
         REF      DCT8           * WA OF HANDLER POST PROCESSOR               .
         REF      DCT9           * WA OF HANDLER PREE PROCESSOR               .
         REF      DEVCTCHK       *                                            .
         REF      DID            * DIAGNOSTIC INTERFACE USER # SLOT           .
         REF      DOUBLEZERO        *
         REF      DSCCVT         *                                            .
         REF      E:IC           * I/O COMPLETE EVENT CODE                    .
         REF      E:IP           * I/O IN PROGRESS EVENT CODE                 .
         SREF     ECBPOST1       * POSTS ECB GIVEN 4-WORD BLOCK               .
         REF      ENBSR4            ENABLE RETURN *R11
         REF      ERRLOG         * ERROR LOGGING RECORDER                     .
         REF      INTCNT         *                                            .
         REF      INTFLG         *                                            .
         REF      IOCLOCK        * # OF 5 SECOND INTERVALS ELAPSED
         REF      IOCTQ          *                                            .
         REF      IOPSD          * PSD FROM I/O INTERRUPT                     .
         REF      IOQ1           * BAK LINK FOR IOQ TABLES                    .
         REF      IOQ10          * # OF  RETRY REQUESTS                       .
         REF      IOQ11          * # OF RETRIES  REMAINING                    .
         REF      IOQ12          * SEEK ADDRESS                               .
         REF      IOQ13          * DBL-WORD OF END ACTION ADDRS/INFO          .
         REF      IOQ14          * REQUEST PRIORITY                           .
         REF      IOQ15          * REQUESTORS USER # (>>0 ONLY)               .
         REF      IOQ16          *  ECB WORD ADDRESS
         REF      IOQ2           * FWD LINK FOR IOQ TABLES                    .
         REF      IOQ3           * IOQ  STATUS DATA  (DUAL ACCESS.ETC)        .
         REF      IOQ4           * CALLERS FUNCTION CODE                      .
         REF      IOQ5           * CURRENT FUNCTION CODE                      .
         REF      IOQ6           * WA OF DCB  (NON-ZERO)                      .
         REF      IOQ7           * DCT INDEX OF DEVICE                        .
         REF      IOQ8           * BA OF BUF OR DBL-WORD OF CDW               .
         REF      IOQ9           * #  CDWS  `OR # OF BYTES                    .
         REF      IOSERCK        * CHECK STATUS FOR ERROR ROUTINE             .
         REF      J:JIT          * WA OF JIT                                  .
         REF      KEYINBUF       * OPERTOR KEYIN INTO THISBUFFER              .
         REF      MBGBIT         * MON BUFFER USED BIT                        .
         REF      MPOOL          * MON POOL CHAIN                             .
         REF      MPOOLIM        *                                            .
         REF      MSGOUT
         REF      MSG1
X3       EQU      M2             * DATA OF X'00000003'                        .
X7       EQU      M3             * DATA OF X'00000007'                        .
XF       EQU      M4             * DATA OF X'0000000F'                        .
X7F      EQU      M7             * DATA OF X'0000007F'                        .
XFF      EQU      M8             * DATA OF X'000000FF'                        .
         REF      NEWQ
         REF      OCDCT          * DCT INDEX OF OC DEVICE                     .
         REF      OCPSD          * PSD FROM O/C INTERRUPT                     .
         REF      OCWRITE
         REF      PFSRIO         *                                            .
         REF      QFREE          * BYTE ZERO HAS INDEX OF FIRST FREE Q        .
         REF      QUEUE
         REF      RBLIMS         * CLM PAIR OF REMOTE BATCH DCT'S             .
         SREF     RBQCK          *                                            .
         REF      RE:ENT
         SREF     RTCU           *                                            .
         SREF     RTINT          *                                            .
         SREF     RTIOSTRT       *                                            .
         SREF     RTTO           *                                            .
         SREF     SACT           * ACTIVATE SYMBIONT ROUTINES                 .
         REF      SC1900         *                                            .
         REF      SSE0           *                                            .
         REF      SYSACT         * DBL-WORD TEXTOF :SYS                       .
         REF      T:GJOB         * PASS PRIORITY/ACCNT # ROUTINE              .
         REF      T:PULLE        *                                            .
         REF      T:RUE          * REPORT UNUSUAL EVENT IN SCHED              .
         REF      T:SAVE         * SAVE STANDARD ENVIRONMENT                  .
         REF      T:SSE          *                                            .
         REF      TB:FLGS        *                                            .
         REF      TEMP           * USED FOR INT PROCESSING                    .
         REF      TP30
         REF      TP32
         REF      TYPEMSG
         REF      TYPERSP
         REF      J:TELFLGS         * ADDRESS OF TEL FLAGS
         REF      UB:US             * USER STATE TABLE
         REF      SIOW              * STATE INDICATING WAITING ON I/O
         REF      SIOMF             * STATE INDICATING MASTER FUNCTION COUNT
*                                        TOO GREAT
         REF      UH:DL             * DO LIST POINTER AND FLAGS
         REF      ERR:CHK           * ROUTINE TO CHECK FOR CONTROL Y
         REF      SQR               * STATE INDINCATING WAITING ON RESOURCE
         REF      R:NQW             * ENQUE RESOURCE WAITING ON
         REF      AVRID             * ID OF USER TAPE BELONGS TOO
         REF      OCQUEUE           * ROUTINE TO TYPE CANNED MSG
         REF      U:MISC            * FIELD CONTAINING RESOURCE TYPE
         REF      UNEXP          * COUNT OF UNEXPECTED INTERRUPTS             .
RTPRIO   EQU      X'C0'          * I/O PRIORITY FOR REAL-TIME USERS           .
         REF      XE7            * DATA OF X'000000E7'                        .
         REF      XFB            * DATA OF X'000000FB'                        .
         REF      X44            * DATA OF X'00000044'                        .
         REF      YE             * DATA OF X'E0000000'                        .
         REF      YFF            * DATA OF X'FF000000'                        .
         REF      YFFFF          * DATA OF X'FFFF0000'                        .
         REF      Y00FE          * DATA OF X'00FE0000'                        .
         REF      Y03            * DATA OF X'03000000'                        .
         REF      OLWRITE           * ONLINE WRITE ERROR MESSAGE
         PAGE
*
*        IOQ INTERNAL DEFINITIONS
*
         DEF      IOQ:              * MODULE BASE ADDRESS
*
         DEF      DPDCT             DISC PACK DCT LIMITS
         DEF      DRIVEIO        *
         DEF      FORCEIO        *
         DEF      INTSIM         *
         DEF      IOINT          * I/O INTERRUPT RECEIVER
         DEF      IOSCHED           * I/O SCHEDULING
         DEF      IOSCU          * CLEANUP RETURN ADDRESS
         DEF      IOSST          * I/O START ROUTINE
         DEF      OCINT          * O/C INTERRUPT RECEIVER
         DEF      PL5BSR4        * PLM 5 AND BRANCH *R11
         DEF      Q15A           *
         DEF      Q51            *
         DEF      RC20           *
         DEF      RC21           *
         DEF      RESCHED        * RE-SCHEDULE I/O RETURN
         DEF      RTRET1         *
         DEF      RTRET2         * RETURN FROM RTROOT
         DEF      TP33
         DEF      UNEWQ             * UNMAPPED SEG OF NEWQ
         DEF      UQUEUE            * UNMAPPED SEG OF QUEUE
         DEF      1Q2               * UNMAPPED SEG OF FRONTEND
         PAGE
         PAGE
*
*   REGISTER DEFINITIONS
*
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
         PAGE
*
*        BASIC I/O ROUTINES
*
*        NEWQ CALLING SEQUENCE;
*
*   R12       FC/PRI/NRT/DCTX                         (8,8,8,8)
*   R13       DATA CHAIN,CMND CHAIN,BA OF BUFFER      (1,1,6,24)
*   R14       BUFFER SIZE IN BYTES                    (0,16)
*   R15       GENERALIZED DISC ADDRESS                (32)
*   R0        END ACTION WORD ADDRESS                 (32)
*   R1        END ACTION INFO  TO RETURN              (32)
*
*
*          QUEUE/QUEUE1  CALLING SEQUENCE;
*
*   R8        FC/DCB ADDRESS                          (8,0,17)
*   R9        END ACTION ADDRESS                      (32)
*   R10       END ACTION INFO                         (32)
*
*          BOTH ROUTINES ENTERED  ON  BAL,11
*
         PAGE
IOQ:     EQU      %                 ORIG
         BOUND    8
KEYIN    TEXTC    'KEYIN'
*
*
DCTLIM   DATA     1,DCTSIZ          RANGE OF VALID DCT INDICES
*
DPDCT    DATA     BATAPE,BATAPE+AVRTBLNE-1
*
*
*  FRONTEND ENTERS HERE UNMAPPED
*
1Q2      PUSH     7,R5              SAVE NON VOLATILES
         LW,R6    R3                MOVE USER NUMBER FOR GETQ
*
*        GET A QUEUE ENTRY FOR THIS REQUEST
*
*        DRIVES ALL I/O IF NONE ARE AVAILABLE
*
*        R4 = PRIORITY (IN)
*        R6 = USER NUMBER (IN)
*        R12 = DCT INDEX (IN)
*
*        R3 = IOQ INDEX (OUT)
*
*
GETQ     RES      0
         LB,R3    QFREE             GET FREE ENTRY HEAD
         BEZ      GQ10              EMPTY, DRIVE ALL I/O
         STB,R4   IOQ14,R3          SAVE PRIORITY
         STB,R12  IOQ7,R3           AND DCT INDEX
         MTW,1    CURBQ             INCREMENT CURRENT BACKGROUND ENTRIES
GQ40     LB,R5    IOQ2,R3           FLINK
         STB,R5   QFREE             SET HEAD TO NEXT FREE ENTRY
         STB,R6   IOQ15,R3          PUT AWAY USER NUMBER
         ENABLE                                  ** ENABLE **
         B        2,R2              RETURN SKIPPING +2
GQ10     LI,R3    DCTSIZ            DRIVE I/O FOR ALL DEVICES
         MTW,1    C:NOQ             COUNT NUMBER OF TIMES THERE ARE NONE
GQ11     PUSH     16,R0             SAVE ALL REGS
         INT,R1   R3                GET DCT INDEX INTO REG FOR DRIVEIO
         BAL,R2   FORCEIO           FORCE
         PULL     16,R0             RESTORE REGS
         BDR,R3   GQ11              CONTINUE
         DISABLE                                    **DISABLE**
         B        GETQ              TRY AGAIN
         PAGE
*
*  NEWQ COMES HERE AFTER UNMAPPING VIA FRONTEND
*
UNEWQ    RES      0
*
*                             BUILD Q ENTRY
         LI,2     0
         STW,R2   IOQ16,R3          NO ECB FOR NEWQ I/O.
         SLS,R12  -8
         LI,R11   X'7F'
         AND,R11  R12               EXTRACT RETRY COUNT
         STB,R11  IOQ10,R3          INIT
         STB,R11  IOQ11,R3          RETRY COUNTERS...
         SLS,R12  -8
         CB,R12   IOQ14,R3          CHECK AGAINST ASSUMED
         BG       %+2               LOWER
         STB,R12  IOQ14,R3          PRIORITY
         SLS,R12  -8
         LW,R8    R15               GET DISK ADDRESS INTO REG FOR DSCCVT
         LI,R15   0                 NO MBG BIT
Q13      RES      0                 MERGE POINT FOR QUEUE AND NEWQ
         STB,R12  IOQ4,R3           FUNCTION CODE
         STB,R12  IOQ5,R3           CURRENT FUNCTION STEP
         STW,R13  IOQ8,R3           BUF ADDR
         STH,R14  IOQ9,R3           BYTE COUNT
         BAL,11   DSCCVT            CONVERT TO SEEK
         STW,8    IOQ12,R3          STORE SEEK
         STD,R0   IOQ13,R3          END-ACTION DATA
         STW,R2   IOQ6,R3           DCB AND FUNCTION
*
Q15      EQU      %
         LB,R1    IOQ7,R3           GET DCT INDEX
         CLM,R1   DCTLIM            TEST FOR VALID DCT INDEX
         BCR,9    Q151              IS VALID -> CONTINUE
SC17     SCREECH  X'17'             BAD DCT
Q151     RES      0
         CLM,R1   RBLIMS
         BCR,9    RBQCK
Q15A     EQU      %
         LB,R7    DCT3,R1           EXTRACT DCT ACCESS KEY
         AND,R7   X3                ..
         BEZ      Q15A0             DEVICE IS NOT DUAL ACCESS
         LB,R9    R13               YES> GET CALLER'S SC FLAGS
         AND,R9   X3                EXTRACT THEM
         BEZ      Q15A0             DEALER'S CHOICE IF ZERO
         LW,R7    R9                ELSE USE WHAT CALLER SAID TO USE
Q15A0    EQU      %
         AH,R15   IOQINIT,R7        SET IOQ ACCESS KEY
         BAL,R9   ERR:CHK           SEE IF CONTROL Y PROCESSING REQUIRED
         STB,R15  IOQ3,R3           SAVE REQUEST SWITCHES
         LB,9     IOQ15,3           GET USER NUMBER
         BEZ      Q15AA             ZERO, UNMAPPED I/O
         INT,R7   IOQ8,R3           IS THIS A USER COMMAND LIST
         BCS,15   Q15AA             YES, SKIP CHAINCHK
         BAL,9    CHAINCHK          NO, USER, CONVERT BUF ADR
Q15AA    EQU      %
         LB,R4    DCT2,R1           GET CHANNEL INDEX
*                             LINK ENTRY INTO Q
         LB,R8    IOQ14,R3          GET PRIORITY OF ENTRY
*
         LI,R11   X'F0000'          MASK FOR COMPARE SELECTIVE(YFFFF)
*
         LB,R2    DCT22,R1          GET SUBTYPE
         BEZ      Q20               NOT A DISC
         LI,R2    1                 SET INDEX
         LW,R10   IOQ12,R3          GET SEEK ADDRESS
Q20      DISABLE                                *** DISABLE ***
         LB,R7    CIT2,R4           GET TAIL OF QUEUE
         BNE      Q28               NOT EMPTY
         STB,R3   CIT1,R4           Q WAS EMPTY
         STB,R3   CIT2,R4
         STB,R7   IOQ1,R3
         B        Q27
Q29      B        Q30               DEVICE, AT THE RIGHT SPOT
         CS,R10   IOQ12,R7          CHECK CYLINDER
         BL       Q26A              LOWEST NUMBERED FIRST
         CB,R8    IOQ14,R7          CHECK PRIO AGAIN
         BE       Q30               SAME
         CW,R10   IOQ12,R7          CHECK DISK ADDR
         BE       Q30               SAME, CANT INVERT; PUT KINK IN Q
         B        Q26A              KEEP GOING
Q26      CB,R1    IOQ7,R7           SAME DEVICE
         BE       Q29,R2            YES, SWITCH ON DEVICE/DISK
Q26A     LB,R6    IOQ1,R7           BLINK
         BNE      Q28A              GOT ANOTHER
         STB,R3   CIT1,R4           SET NEW HEAD
         STB,R6   IOQ1,R3           SET NEW BLINK
         STB,R3   IOQ1,R7           MAKE PREVIOS BLINK TO CURRENT
Q27      STB,R7   IOQ2,R3           SET CURRENT FLINK
         B        Q40               DONE
Q28A     LB,R7    IOQ1,R7           GET NEXT
Q28      CB,R8    IOQ14,R7          CHECK PRIO
         BLE      Q26               TRY TO INVERT
Q30      LB,R6    IOQ2,R7           INSERT
         BNEZ     %+2               CHECK FOR TAIL
         STB,R3   CIT2,R4           SET NEW TAIL
         STB,R6   IOQ2,R3           SET CURRENT FLINK
         STB,R7   IOQ1,R3           SET CURRENT BLINK
         STB,R3   IOQ2,R7           SET PREV BLINK TO CURRENT
         BEZ      %+2               CHECK FOR TAIL
         STB,R3   IOQ1,R6           NO, SET NEXT BLINK TO CURRENT
*
Q40      ENABLE                                             **ENABLE**
*
*                             CALL SERVICE DEVICE
Q50      STB,R1   *TSTACK           SAVE DCT INDEX IN RETURN
         BAL,R2   DRIVEIO           CALL I/O SCHEDULER WITH CJOB PRI
         LB,R2    *TSTACK           RESTORE DCT INDEX
*                             RETURN TO CALLER
Q51      EQU      %
         LCI      7                 RESTORE NON-VOLATILE REGS
PL5BSR4  PLM,5    TSTACK
         B       *11
IOQINIT  DATA,2   0,1,2,4           INITIAL IOQ KEYS FOR DUAL-ACCESS
         PAGE
*
*  QUEUE COMES HERE AFTER UNMAPPING VIA FRONTEND
*
UQUEUE   RES      0
         LW,R2    R13               RESTORE PHYSICAL DCB ADDRESS
         AND,R8   YFF               EXTRACT OLD FUNCTION CODE
         OR,R2    R8                MERGE WITH PHYS DCB ADDRESS
*
*                                   BUILD Q ENTRY
*
*
         AND,R14  M17               GET ECB ADDRESS ONLY.
         BEZ      %+2               ---> NO ECB.
         MTB,+1   *R14                ECB. BUMP I/O COUNT IN 4-WD BLK.
         STW,R14  IOQ16,R3          PUT ECB ADDRESS INTO Q ENTRY.
         LW,R13   QBUF,R2           GET WORD ADDRESS OF BUFFER
         AND,R13  M22               SCRUB OFF FCN
         SLS,R13  2                 CONVERT TO BYTE ADDRESS
         LI,R7    X'C0'             MASK FOR HBTD
         AND,R7   0,R2              EXTRACT FROM DCB
         BEZ      QD51A             NONE, SHORT CUT
         SLS,R7   BTDBIT-31         ALIGN
         OR,R13   R7                MERGE
QD51A    LW,R14   WABLK,R2          GET RECORD SIZE
         SCS,R14  15                RIGHT ALIGN
         AND,R14  M15               SCRUB
         BNE      %+2
         LI,R14   X'8000'           0 => 32K BYTES
*
         LI,R7    BANRA             INDEX TO NRA (NRT)
         LB,R10   *R2,R7            GET NRT FROM DCB
         AND,R10  X7F               SCREEN THAT X80 BIT OUT
         STB,R10  IOQ10,R3          NUMBER OF TRIES
         STB,R10  IOQ11,R3          TRY COUNT
*
*
*                             CONVERT FUNCTION CODE
         LB,R5    R2                GET FUNCTION CODE
         LB,R7    IOQ7,R3           GET DCT
         AI,R15   -1                CHECK FOR FILE ASSIGNMENT
         BEZ      OLDTNEWFC         YES, NO MBG BIT
         LW,R15   0,R2              EXTRACT MBG BIT
         SCS,R15  MBGBIT+6          FROM DCB
         AND,R15  X20               SCRUB AND PASS TO Q13
*
*        AT THIS POINT, MOST DCB INFORMATION HAS BEEN MOVED
*        INTO REGISTERS IN ESSENTIALLY THE SAME FORMAT AS A
*        NEWQ CALL.
*
*        R0 = END ACTION ADDRESS
*        R1 = END ACTION INFORMATION
*        R13 = BUFFER (BYTE ADDRESS)
*        R14 = BYTE COUNT
*        R8 = DISC ADDRESS
*        R15 = MBG BIT (IF APPROPRIATE)
*        R12 = FUNCTION CODE FOR HANDLER
*        R2 = OLD FUNCTION CODE, DCB PHYSICAL ADDRESS (8,24)
*
*
OLDTNEWFC RES     0                 5=OLD,7=DCT,6NG
*                                   9=RA,5=NEW FC
         LB,R7    DCT4,R7           GET TYPE
         CI,R7    X'10'             TEST FOR RESOURCE TYPE
         BLE      QD49              NO
         LB,R6    TB:FLGS,R7        GET TYPE FLAGS FOR ADDED DEVICE
         SLD,R6   -6                6= BITS 0,1 OF TB:FLGS
         SLS,R7   3                 LEFT ALIGN REV BIT
         SLD,R6   1                 MERGE TO FORM INDEX ON GENERIC TYPES
         LB,R7    GENERIC,R6        TRANSLATE
QD49     EQU      %
         LB,R6    TYPCOR,R7         TABLE OFFSET
         CI,R6    BA(MTCOR)-BA(TYPCOR) CHECK FOR TAPE
         BE       QD50              YES
         AND,R5   X7                USE 3 BITS FOR OTHERS
         B        QD60
QD50     CI,R5    8                 IS IT POSITION OP
         BAZ      QD52              NO
         AND,R5   XF                YES, MASK
         AI,R6    22                INDEX TO POS OPS
         B        QD60
QD52     CI,R7    8                 IS IT 9T
         BNE      QD56              NO
         AND,R5   X44               YES, MASK DIRECTION, R/W BITS
         AI,R5    X'22'             ADD PACKED, BINARY BITS
QD56     LI,R7    X'60'
         AND,R7   R5                MASK DIREC, PACK BITS
         SLS,R7   -2
         AND,R5   X7                READ/WRITE BITS
         OR,R5    R7                COMBINE
*
QD60     AW,R6    R5                SET INDEX IN COR TABLE
         LB,R12   TYPCOR,R6         CONVERT TO HANDLER FUNCTION CODE
         LW,R8    CDA,R2            GET SEEK ADDRESS
         B        Q13               MERGE WITH NEWQ PATH
*
*        TABLE TO CONVERT TB:FLGS CONTENT TO GENERIC TYPE INDEX
*
GENERIC  DATA,1   1,1,6,6,9,8,11,11
*
*
*
*    FUNCTION CODE CONVERSION TABLES
*
:COR     CNAME
         PROC
LF       GEN,8    BA(AF(1))-BA(TYPCOR)
         PEND
*
TYPCOR   EQU      %
         :COR     TYCOR             NULL
         :COR     TYCOR             TY
         :COR     PTCOR             PR
         :COR     PTCOR             PP
         :COR     CRCOR             CR
         :COR     CPCOR             CP
         :COR     CRCOR             LP
         :COR     DCCOR             DC
         :COR     MTCOR             9T
         :COR     MTCOR             7T
         :COR     MTCOR             MT
         :COR     TYCOR             DP
         :COR     MOCOR             MOC TYPE DEVICES
         :COR     TYCOR
         :COR     TYCOR
         :COR     TYCOR
*
         BOUND    4
*
TYCOR    DATA,1   0,0,0,0,1,1,1,1   TY
*
PTCOR    DATA,1   8,4,0,4,1,5,3,5   PR,PP
*
CRCOR    DATA,1   2,2,0,0,1,1,3,3   CR,LP
*
CPCOR    DATA,1   0,0,1,1,0,0,1,1   CP
*
DCCOR    DATA,1   0,0,0,0,4,4,4,4   DC
*
MTCOR    DATA,1   13,13,10,10,14,14,11,11      7 TRACK
         DATA,1   13,13,00,00,14,14,01,01
         DATA,1   15,15,12,12,14,14,11,11
         DATA,1   15,15,02,02,14,14,01,01
*
         DATA,1   5,4,7,6,8,3,0,0   MT POSITION
*
MOCOR    DATA,1   0,X'80',0,X'80',0,X'80',0,X'80'  MO
         PAGE
         SPACE
*        9/1/71 J PODOLSKY .. DUAL-ACCESS INPUT/OUTPUT SCHEDULER.
*
*        DRIVEIO .. TO DRIVE I/O WITH CURRENT JOB PRIORITY.
*        DRIVEIO1 . TO DRIVE I/O WITH PRIORITY IN R0.
*        FORCEIO .. TO DRIVE I/O WITH PRIORITY X'FF' (LOWEST PRI).
*        CALLING SEQUENCE ..
*
*                 ...      ...         PRIORITY IN R0 (FOR DRIVEIO1)
*                 ...      ...         DCT INDEX IN R1
*                 BAL,R2   <NAME>      CALL DRIVEIO OR FORCEIO
*
         SPACE
DRIVEIO  LB,R0    CJOB              NORMAL ENTRY - SET CURRENT JOB PRI
DRIVEIO1 CI,R0    RTPRIO            CHECK FOR BACKGROUND CALL
         BL       %+2               IF SO, TREAT THIS CALL AS I/O FORCE
FORCEIO  LI,R0    X'FF'             SINCE BKGD PRI IS BELOW CONTROL TASK
         PUSH     2
         LB,2     DCT2,1
DSERV    DISABLE                    DEVICE SERVICE CHECK, INHIBIT
         LB,R8    DCT5,R1           GET DEVICE STATUS SWITCHES(2)
         CI,R8    X'88'             IS DEVICE BUSY OR KEY-IN PENDING.
         BANZ     CLOCKIO           YES, SERVICE CLOCK & CHECK TIMEOUT
         CI,R8    X'40'             NO, IS CLEANUP OPERATION PENDING.
         BANZ     CLEANUP           YES, DO IT, PRIORITY PERMITTING
         PAGE
*F*
*F*      NAME:        IOSCHED
*F*
*F*      PURPOSE:     TO SELECT CHANNEL/DEVICE FOR I/O ACTIVITY
*F*
*F*      DESCRIPTION: CALL HERE WITH;
*F*
*F*      R1           DCT INDEX
*F*      R2           CHANNEL INDEX
*F*
*F*
IOSCHED  ENABLE                     MAIN I/O SCHEDULING ALGORITHM
IOSCHED1 DISABLE                    RELEASE ANY PENDING INTERRUPTS
         LB,R3    CIT1,R2           GET HEAD OF CHANNEL QUEUE
         BEZ      SCHEDXIT          ARE THERE ANY PENDING REQUESTS.
         LB,R5    CIT3,R2           YES, GET SUBCHANNEL STATUS BYTE
         SLS,R5   -4                FORM INDEX FROM BUSY/HOLD FLAGS
IOSCHED2 INT,R8   SELECTAB,R5       GET SCHEDULING KEY & COMPARE MASK
         BCS,8    SCHEDHLD          CHECK CHANNEL HOLD IF SPECIFIED
IOSCHED3 CB,R8    IOQ3,R3           ELSE SCAN QUEUE FOR FREE REQUEST
         BANZ     NEXTQUE           THAT IS STARTABLE ON AVAILABLE S.C.
         DO       DEFER
         CB,R0    IOQ14,R3          COMPARE REQUEST/SCHEDULER PRIORITIES
         BL       DEFER2            SCHEDULER HIGHER, MUST DEFER SERVICE
         FIN
REQSTRT  LW,R10   R3                PRIORITY OK, SAVE CURRENT IOQ INDEX
         LB,R1    IOQ7,R3           GET INDEX OF DEVICE FOR THIS REQUEST
         LB,R4    DCT5,R1           CHECK DEVICE STATE FOR AVAILABILITY
         SCS,R4   -5                ISOLATE BUSY/CLEANUP/INTEROP FLAGS
         CW,R4    Y4                AND CHECK FOR DEVICE KEYIN PENDING
         EXU      REQSERV,R4        GO IF CLEANUP, NO GO IF BUSY/KEYIN
         LB,R4    IOQ3,R3           START OR INTEROP, R3 HAS REQUEST
         AND,R4   X7                EXTRACT 3-BIT IOQ ACCESS KEY
         CH,R5    ACCHECK,R4        ARE REQUIRED SUBCHANNELS AVAILABLE.
         BAZ      STARTIO           YES, START I/O ACTIVITY FOR REQUEST
         BL       SCHEDXIT          NO, ARE BOTH SUBCHANNELS REQUIRED.
REQNSTRT INT,R3   R10               NO, RESTORE CURRENT IOQ INDEX
         BCS,8    CHANBLK           IF SUBCHANNEL HELD, BLOCK IT OUT.
NEXTQUE  LB,R3    IOQ2,R3           OTHERWISE, CONTINUE QUEUE SCAN
         BNEZ     IOSCHED3          ARE THERE ANY MORE REQUESTS.
SCHEDXIT ENABLE                     NO, REMOVE INTERRUPT INHIBITS
         PULL     2
         B        0,2
*
*        DCT5 CONTENTS
*
* 0      1       2       3       4       5       6       7
*--------------------------------------------------------------*
*      *       *       *       *       *       *       *       *
* DEV  * CLEAN *INTER  * DATA  * KEYIN * CONT. * SIO   * BIN   *
* BUSY * UP    * OP    * XFER  * REQRD * TASK  * WHILE * MODE  *
* NOW  * REQRD *       * NOW   * TO    *       * MANUAL* 1=YES *
*      *       *       *       * CLEAR * DEFER *       * 0=BCD *
*      *       *       *       *       *       *       *       *
*--------------------------------------------------------------*
*
*      DCT3 CONTENTS
*
* 0     1       2       3       4       5       6       7
*--------------------------------------------------------------*
*      *       *       *       *       *       *       *       *
*OUTPUT* INPUT *1=PART *TIMED  * SIO   *       * SC2   * SC1   *
*LEGAL *LEGAL  *0=USE  * OUT   *REJECT *       * AVAIL * AVAIL *
*      *       *  OK   * I/O   *       *       * TO USE* TO USE*
*      *       *       *       *       *       *       *       *
*--------------------------------------------------------------*
*
         PAGE
         SPACE
SCHEDHLD AI,R8    SCCHECK           SUBCHANNEL HELD OR BOTH BUSY, CHECK
         EXU     *R8                IF BOTH BUSY (FCN=0), EXIT SCHEDULER
         OR,R3    Y8                HELD - REQUEST INDEX IN R3 - FLAG
         B        REQSTRT           ATTEMPT SERVICE OF HOLDING REQUEST
CHANBLK  LB,R4    IOQ3,R3           HELD SUBCHANNEL BLOCKED, EXTRACT KEY
         AND,R4   X3                ..
         AH,R5    ACCHECK,R4        SET REQUIRED SUBCHANNELS UNAVAILABLE
         B        IOSCHED2          RE-SCHEDULE WITH NEW CHANNEL STATUS
         SPACE
SCCHECK  B        SCHEDXIT          FUNCTION 0 .. BOTH SUBCHANNELS BUSY
         LB,R3    CIT5,R2           FUNCTION 1 .. SUBCHANNEL 1 HELD
         LB,R3    CIT6,R2           FUNCTION 2 .. SUBCHANNEL 2 HELD
         SPACE
REQSERV  BANZ     REQNSTRT          0 .. NO START IF KEY-IN PENDING
         LB,R3    DCT6,R1           1 .. INTER-OP, GET WAITING REQUEST
         B        CLEANUP1          2 .. CLEANUP PENDING, PROCESS
INVAL    DATA     0                 3 .. NO SUCH ANIMAL .. S.C. 40
         B        REQNSTRT          4 .. DEVICE BUSY, NO GO
         B        REQNSTRT          5 .. DEVICE BUSY
         B        REQNSTRT          6 .. CLEANUP RUNNING NOW
         B        REQNSTRT          7 .. DEVICE BUSY
*
         SPACE
ACCHECK  GEN,16   X'C'              000 .. BOTH SUBCHANNELS REQUIRED
         GEN,16   X'8'              001 .. SUBCHANNEL 1 REQUIRED
         GEN,16   X'4'              010 .. SUBCHANNEL 2 REQUIRED
         GEN,16   X'0'              011 .. UNDEFINED ACCESS KEY
         GEN,16   X'0'              100 .. UNASSIGNED DUAL-ACCESS DEVICE
         BOUND    4
         PAGE
         SPACE
*        SELECTAB .. CENTRAL SCHEDULING DECISION TABLE.  AN ENTRY IN
*        THIS TABLE IS SELECTED ACCORDING TO THE VALUE OF CIT3 BITS
*        0 THRU 3 (SUBCHANNEL 'BUSY' & 'HOLD' FLAGS).  TABLE FORMAT:
*
*             BIT  0         AT LEASE ONE SUBCHANNEL IDLE-HELD OR
*                            BOTH SUBCHANNELS BUSY
*             BITS 4-15      IF BIT 0 IS 1, THIS IS A SPECIAL FUNCTION
*                            CODE, WITH 0 = BOTH SC'S BUSY, 1 = SC1
*                            HELD, & 2 = SC2 HELD.  IF BIT 0 IS 0,
*                            THIS IS A COMPARE MASK FOR THE IOQ ACCESS
*                            KEY.  BIT 8 WILL ALWAYS BE 1, WITH BIT 14
*                            1 IF SC2 BUSY & BIT 15 1 IF SC1 BUSY.
*             BITS 16-19     USED BY 'ASSIGNSC' TO SELECT SUBCHANNEL
*             BITS 24-31     CIT CHECK MASK (INVERSE OF CIT3(0-3))
         SPACE
SELECT   COM,1,3,12,3,1,12 AF(1),0,AF(2),AF(3),AF(4),(%-SELECTAB||15)**4
         SPACE
SELECTAB SELECT   0,X'80',-3,1      0 .. I-F/I-F .. UNRESTRICTED CHANNEL
         SELECT   1,2,-3,0          1 .. I-F/I-H .. SCHEDULE HELD SC2
         SELECT   1,1,-2,0          2 .. I-H/I-F .. SCHEDULE HELD SC1
         SELECT   1,1,0,0           3 .. I-H/I-H .. BOTH HELD, SC1 FIRST
         SELECT   0,X'82',-3,0      4 .. I-F/B-F .. SCHEDULE SC1 ONLY
         SELECT   0,X'82',-3,0      5 .. I-F/B-H .. LIKEWISE - SC1 ONLY
         SELECT   1,1,0,0           6 .. I-H/B-F .. SCHEDULE HELD SC1
         SELECT   1,1,0,0           7 .. I-H/B-H .. SAME AS ABOVE - SC1
         SELECT   0,X'81',-2,0      8 .. B-F/I-F .. SCHEDULE IF DUAL-ACC
         SELECT   1,2,0,0           9 .. B-F/I-H .. SCHEDULE HELD SC2
         SELECT   0,X'81',-2,0      A .. B-H/I-F .. SC2 AVAIL IF DUAL-AC
         SELECT   1,2,0,0           B .. B-H/I-H .. SUBCHANNEL 2 HELD
         SELECT   1,0,0,0           C .. B-F/B-F .. BOTH BUSY, NOTHING
         SELECT   1,0,0,0           D .. B-F/B-H .. CAN BE SCHEDULED.
         SELECT   1,0,0,0           E .. B-H/B-F .. NOTE: I=IDLE, B=BUSY
         SELECT   1,0,0,0           F .. B-H/B-H .. AND F=FREE, H=HELD
         PAGE
         SPACE
*        CLOCKIO .. PERFORM I/O TIMEOUT CHECK FOR SCHEDULER.  IF TIME
*        EXCEEDED AND TIME-OUT INCREMENT IS NON-ZERO, FOLLOWING WILL
*        HAPPEN, DEPENDING ON DCT STATUS INFORMATION:
*
*        1.  DEVICE BUSY-MANUAL.  IF STILL IN MANUAL STATE, OPERATOR
*            WILL BE NOTIFIED.  IF NOW IN AUTOMATIC STATE, TIMEOUT
*            WILL BE SET FOR I/O NOW IN PROGRESS.
*        2.  DEVICE BUSY, NOT MANUAL.  I/O WILL BE HALTED AND CLEANUP
*            REQUEST SET.
*        3.  DEVICE KEY-IN PENDING.  OPERATOR WILL BE NOTIFIED WITH
*            'PLEASE RESPOND' MESSAGE.
*
*        R1 HAS DCT INDEX UPON ENTRY TO CLOCKIO.
         SPACE
CLOCKIO  LW,R10   DCT11,R1          GET EXPECTED COMPLETION TIME
         CW,R10   IOCLOCK           HAVE WE EXCEEDED TIME LIMIT.
         BGE      IOSCHED           NO, RETURN TO SERVICE CHANNEL
         LB,R9    DCT18,R1          YES, IS TIME-OUT INCREMENT ZERO.
         BEZ      IOSCHED           YES, NO LIMIT, IGNORE TIMEOUT
         BAL,R11  GETDEVAD          GET DEV ADRS INTO R6
         CI,R8    2                 WAS DEVICE MANUAL LAST TIME.
         BAZ      CLOCKOUT          NO, TIMED OUT I/O OR EXPECTED KEY-IN
         LI,R13   MSG1              YES, SET UP 'MANUAL' MESSAGE
         TIO,R11  0,R6              CHECK STATUS OF DEVICE NOW
         CW,R11   Y1                IS DEVICE AUTOMATIC
         BAZ      CHK:CNTRLY        CHECK FOR CONTROL Y ON TAPE
         AW,R9    IOCLOCK           DEVICE NOW AUTO OR INDETERMINATE
         STW,R9   DCT11,R1          SET TIMEOUT FOR I/O NOW IN PROGRESS
         EOR,R8   X2                CLEAR MANUAL BIT
         STB,R8   DCT5,R1           AND REPLACE DEVICE FLAGS
         B        IOSCHED           RETURN TO SERVICE CHANNEL QUEUE
         PAGE
*
*        CALL HERE VIA R11 TO GET DEVICE ADDRESS INTO R6
*
*        R1 MUST CONTAIN DCTX
*
         DEF      GETDEVAD          USED BY HANDLERS IN BASHANDL
*
GETDEVAD EQU      %
         LB,R6    DCT6,R1           GET IOQX
         LB,R6    IOQ3,R6           GET IO SWITCHES
         AND,R6   X3                MASK TO EXTRACT SUB-CHAN ASN.
         EXU      IOALOAD,R6        LOAD R6 W/DEVICE ADDRESS USED
         B        *R11              AND RETURN
         PAGE
         PAGE
*
*        DEVICE HAS NOT INTERRUPTED IN THE ALLOWED TIME AND IS
*        NOW CONSIDERED TO BE OVER-DUE -> MUST TELL OPERATOR.
*
CLOCKOUT EQU      %
         LC       DCT5,R1           IS DEVICE BUSY, OR IS KEYIN PENDING.
         BCR,8    CHK:CNTRLY        NOT BUSY, KEYIN; 'PLEASE RESPOND'
CLOCKOUT10 EQU    %
         TDV,R8   0,R6
         STCF     DCT20,R1          STORE CC'S
         STD,R8   DCT13,R1          STORE STATUS
         HIO,R11  0,R6
         STCF     DCT19,R1          STORE HIO CC'S
         AND,R11  YFFFF             SAVE STAT CLEAR CDW ADDRS
         OR,R11   R6                INSERT DEVICE ADDRESS
         STW,R11  DCT12,R1          SAVE HIO IN AIO SLOT
         TIO,R11  0,R6
         LH,R11   R11               MOVE STATUS OVER
         STH,R11  DCT21,R1          AND SAVE IT
         LB,R9    DCT3,R1           GET DEVICE SWITCHES(1)
         OR,R9    X10               SET I/O TIMEOUT FLAG
         STB,R9   DCT3,R1           ..
CLOCKXIT LI,R5    DSERV             SET RETURN FROM 'INTSIM'
         SPACE    5
*                 .
*                 .                 ENTER 'INTSIM' TO CLEAN UP 'BUSY'
*                 .                 DEVICE AND SET CLEANUP PENDING.
*                 .                 SET CHANNEL NOT BUSY.  RETURN TO
*               . . .               'CLEANUP' TO TYPE 'TIMED OUT'
*                ...                MESSAGE (PRIORITY PERMITTING,
*                 .                 OF COURSE).
         PAGE
         SPACE
*        INTSIM .. ROUTINE TO SET DEVICE IN CLEANUP-PENDING STATE
*        FOLLOWING AN I/O HALT.  CALLING SEQUENCE ..
*
*                 BAL,R5   INTSIM      DCT INDEX PASSED IN R1
*                 ...      ...         USES REGISTERS 6 THRU 9
*
*        THE FOLLOWING ACTIONS WILL BE TAKEN:
*
*        1.  DEVICE STATE SWITCHED FROM 'BUSY' TO 'CLEANUP-PENDING'
*        2.  IF DATA TRANSFER WAS SET, 'SUBCHANNEL-BUSY' IS RESET.
*
*        NOTE: NO INDICATORS FOR RECOVERY -- SUCH AS 'TIMED-OUT' -- ARE
*        SET BY INTSIM.  THERE MAY BE FUTURE ENHANCEMENTS TO ALLOW
*        FOR SOME KIND OF RECOVERY ATTEMPT AFTER I/O HALT, BUT CUR-
*        RENTLY THE ONLY MODULES USING INTSIM, OUTSIDE OF 'SERDEV',
*        ARE THE PFSR AND RTROOT ROUTINES.
         SPACE
INTSIM   LB,R8    DCT5,R1           GET DCT SWITCHES(2)
         AND,R8   X7F               RESET DEVICE BUSY FLAG
         OR,R8    X40               SET CLEANUP PENDING FLAG
         CI,R8    X'10'             WAS THERE DATA TRANSFER.
         BAZ      INTSEXIT          NO, SKIP CHANNEL STATUS RESET
         LB,R6    DCT2,R1           YES, GET CIT INDEX (DON'T USE R2)
         LB,R9    CIT3,R6           GET CHANNEL STATUS FLAGS
         LB,R7    DCT6,R1           GET INDEX OF REQUEST USING DEVICE
         LB,R7    IOQ3,R7           EXTRACT 3-BIT IOQ ACCESS KEY
         AND,R7   X3                ..
         EOR,R9   CBFLAGS,R7        RESET SUBCHANNEL BUSY INDICATOR
         STB,R9   CIT3,R6           RESTORE CHANNEL STATUS
INTSEXIT STB,R8   DCT5,R1           RESTORE DEVICE SWITCHES(2)
         LW,R5    R5                IS THIS A REAL-TIME IOEX CALL?
         BLZ      0,R5              YES, RETURN
         DISABLE
         LB,6     DCT14,1           GET FORWARD LINK
         LB,7     DCT15,1           GET BACK LINK
         STB,7    DCT15,6           AND CROSS LINK THEM
         STB,6    DCT14,7
         LI,7     0                 ZAP
         STB,7    DCT14,1           ANY
         STB,7    DCT15,1           GARBAGE
         B        0,R5              RETURN TO CALLING PROGRAM
*
         PAGE
*
*        CHK:CNTRLY .. ROUTINE TO SEE IF CONTROL Y HAS OCCURED
*                      DURING ERROR REQUEST AND USER WANTS TO BE
*                      ERRORED IF HE IS WAITING ON THE IO REQUEST.
*
CHK:CNTRLY EQU    %
         LB,R3    DCT6,R1           GET IOQ INDEX
         LB,R5    IOQ3,R3           GET IOQ3 (STATUS)
         CI,R5    8                 DO WE HAVE CONTROL Y PROCESSING
         BAZ      CNTRLY90          NO-->BRANCH
         LW,R5    R1                GET DCT INDEX
         AI,R5    -BATAPE           CONVERT TO AVR INDEX
         LH,R5    AVRID,R5          GET THE USER #
         LH,R3    UH:DL,R5          GET HIS DO-LIST ENTRY
         CI,R3    X'2000'           HAS A CONTROL Y OCCURED
         BAZ      CNTRLY90          NO-->BRANCH
         LB,R3    UB:US,R5          GET THE USERS STATE
         CI,R3    SQR               CHECK FOR QUEUED FOR RESOURCE
         BNE      CNTRLY2           NO-->BRANCH
         LW,R3    U:MISC,R5         GET THE TYPE OF RESOURCE
         LB,R3    R3                INTO R3
         CI,R3    R:NQW             IS IT THE ENQUE STATE (TAPE SPACING?)
         BE       CNTRLY5           SPACING-->BRANCH
         B        CNTRLY90          NOT SPACING-->BRANCH
CNTRLY2  EQU      %
         CI,R3    SIOW              IS THE GUY WAITING ON I/O
         BE       CNTRLY5           WAITING ON I/O-->BRANCH
         CI,R3    SIOMF             IS HE BLOCKED FOR MASTER FUNCTION CNT
         BNE      CNTRLY90          NOT SIOMF-->BRANCH
CNTRLY5  EQU      %
         CI,R8    2                 WAS DEVICE MANUAL
         BAZ      CNTRLY10          NOT MANUAL-->BRANCH
         EOR,R8   X2                TURN OF MANUAL BIT
         STB,R8   DCT5,R1           SAVE THE NEW STATUS BITS
         B        CLOCKOUT10        GO TIME OUT THE DEVICE
CNTRLY10 EQU      %
         PUSH     2,R1              SAVE R1 AND R2
         LI,R4    0                 SET UP PHONEY 'E' KEYIN
         BAL,R11  TP33              GO ERROR THE DEVICE
         PULL     2,R1              RESTORE R1 AND R2
         B        IOSCHED           GO SCHEDULE SOME MORE I/O
CNTRLY90 EQU      %
         CI,R8    2                 WAS DEVICE MANUAL LAST TIME
         BAZ      TYPERSP           NOT MANUAL-->BRANCH
         B        TYPEMSG           MANUAL-->BRANCH
*
*
         PAGE
         SPACE
*        I/O SCHEDULER CONTROL TASK DEFER ROUTINES.
*
*        DEFER1 .. DEFER TO CONTROL TASK, RETURN TO IOSCHED.
*        DEFER2 .. DEFER TO CONTROL TASK, RETURN TO SCHEDXIT.
         SPACE
         DO       DEFER
DEFER1   LI,R11   IOSCHED           ENTRY FROM CLEANUP, SET RETURN
         B        DEFER3            GO SET CONTROL TASK FUNCTION
DEFER2   LI,R11   SCHEDXIT          ENTRY FROM I/O SCHEDULER, SET RETURN
DEFER3   LB,R7    IOQ7,R3           GET DEVICE ASSOCIATED WITH REQUEST
         LB,R8    DCT5,R7           GET DEVICE SWITCH BYTE 2
         CI,R8    4                 IS CONTROL TASK ALREADY SET.
         BANZ    *R11               YES, TAKE DEFER EXIT NOW
         MTB,4    DCT5,R7           NO, SIGNAL CONTROL TASK FUNCTION
         LW,R8    R7                SET CONTROL WORD EQUAL TO DCT INDEX
         B        CTRIG1            GO SET CONTROL TASK FUNCTION
         FIN
         SPACE
         PAGE
         SPACE
*        STARTIO .. INITIATE I/O ACTIVITY FOR A REQUEST.
*        AT THIS POINT, THERE IS A STARTABLE REQUEST IN R3.  THE DEVICE
*        ACTIVITY COUNTER IS SET IN R14 AND INTERRUPTS ARE ENABLED.
*        THE I/O HANDLER PRE-PROCESSOR IS CALLED UNLESS USER COMMAND
*        LIST IS SPECIFIED.  HANDLER RETURN IS TO 'IOSST'.
*        REGISTER SETUP FOR I/O HANDLER:
*
*        R0  ..  DOUBLEWORD ADDRESS OF COMMAND LIST
*        R1  ..  PRIORITY, CIT CHECK MASK, DCT INDEX (8,4,20)
*        R2  ..  FLAGS, SERDEV EXIT, CIT INDEX (3,10,19)
*        R3  ..  REQUEST IOQ INDEX
*        R4  ..  HANDLER FLAGS, SUBCHANNEL ALLOCATION CODE (8,24)
*        R10 ..  DEVICE OPERATION TABLE ('DOT') FOR 'IOSST'
*        R14 ..  DEVICE ACTIVITY COUNT FOR RE-ENTRANCY CHECK
*        R15 ..  NOT USED - SAVED FOR FUTURE EXPANSION
*
         SPACE
STARTIO  LH,R14   DCT10,R1          START, SET DEVICE ACTIVITY COUNTER
         ENABLE                     RUN HANDLER & INITIAL START ENABLED
         STB,9    2
         STB,R0   R1                SAVE PRIORITY & MASK IN R1(0-11)
         LW,R6    DCT8,R1           GET HANDLER PRE-PROCESSOR ADDRESS
         INT,R7   IOQ8,R3           IS USER COMMAND LIST SPECIFIED.
         BCR,4    0,R6              NO, CALL I/O HANDLER, RETURN 'IOSST'
         LW,0     IOQ8,3
         LH,R8    IOQ9,R3           GET I/O TIMEOUT INCREMENT
         LI,R9    0                 SET NULL RE-TRY & FOLLOW-ON CODES
         B        IOSTRT            GO TO ENTRY DISABLE POINT
         PAGE
*
*        HANDLER'S RETURN HERE TO START I/O
*        R0 CONTAINS DA OF CLIST
*
IOSST    EQU      %
         LB,R7    IOQ5,R3           GET CURRENT FUNCTION STEP INDEX
         INT,R8  *R10,R7            GET 'DOT' INFORMATION FROM HANDLER
         AND,R8   XFF               MASK TIMEOUT INCREMENT IN BYTE 2
*
*        INSURE HANDLER FRONT-END DID NOT GET RE-ENTERED AND START
*        I/O EVENT
*
IOSTRT   DISABLE                    DISABLE POINT, START CRITICAL CODE
         CH,R14   DCT10,R1          HAS START/CLEANUP BEEN SCHEDULED.
         BNE      RESCHED           YES, RE-ENTERED, ABORT I/O START
         AND,R0   M21               SCREEN CLIST DA TO 21 BITS WORTH
         LI,R14   0                 SET FOR NO MESSAGE
         LB,R5    CIT3,R2           NO PRE-EMPT, GET CHANNEL STATUS
         LB,R10   IOQ3,R3           AND GET REQUEST SWITCH BYTE
         EXU      CHANTEST,R4       SELECT RELEVANT STATUS IF ASSIGNED
         CB,5     2
         BANZ     RESCHED           YES, ABORT START, BACK TO IOSCHED
IOSTRT1  STB,R8   DCT18,R1          NO, SAVE I/O TIMEOUT INTERVAL COUNT
         STH,R9   DCT17,R1          SAVE RE-TRY & FOLLOW-ON CODES
         LB,R9    DCT5,R1           GET DEVICE SWITCH BYTE 2
         AND,R9   X7                RESET STATE FLAGS & DATA XFER BIT
         STB,R3   DCT6,R1           PUT AWAY IOQ INDEX IN DCT'S
         OR,R9    X80               SET BUSY BIT
         STB,R9   DCT5,R1           INTO DCT TABLES
         EXU      IOALOAD,R4        GET DEVICE I/O ADDRESS IN R6
         MTW,1    DCT25,R1          BUMP THE NUMBER OF SIO'S ATTEMPTED
         LCI      0
         SIO,R12  0,R6              ATTEMPT I/O START ON THIS ADR.
         STCF     DCT19,R1          SAVE SIO CONDITION CODES
         BCS,12   IOREJECT          IF IT FAILED, EXIT TO ANALYZE FAULT
         LB,R7    DCT15,R1          IS THIS A REAL-TIME IOEX REQUEST?
         BEZ      IOSTRT5           NO, CONTINUE
         LI,R7    IOSTRT6           YES, SET RETURN FROM RTROOT
         B        RTIOSTRT          SPECIAL PROCESSING IN RTROOT
IOSTRT5  EQU      %
         STH,R6   DCT1,R1           ACCEPTED, SET 'ACTIVE' I/O ADDRESS
         LB,7     DCT14             GET HEAD
         STB,1    DCT14             MAKE CURRENT REQUEST NEW HEAD
         STB,7    DCT14,1           LINK TO REST OF CHAIN
         STB,1    DCT15,7           AND BACK LINK
IOSTRT6  ;
         LC       R13               CHECK FOR DEVICE 'MANUAL' OR 'AUTO'
         BCS,1    IOSTRT3           AUTOMATIC, CONTINUE PROCESSING
         LB,R7    DCT4,R1           MANUAL, SPECIAL TEST FOR PAPER TAPE
         EOR,R7   X3                IS DEVICE PAPER READER/PUNCH (2/3).
         BDR,R7   IOSTRT2           NO, DEVICE IS DEFINITELY MANUAL.
         LCI      0
         TDV,R13  0,R6              GET TDV STATUS
         SLS,R13  3,R7              CHECK BIT 2 = PUNCH, BIT 3 = READER
         CI,R13   0                 IS SPECIFIED SUB-UNIT MANUAL.
         BGE      IOSTRT3           NO, OTHER ONE MUST BE - IGNORE IT
IOSTRT2  EQU      %
         OR,R9    X2                SET SIO WHILE MANUAL BIT
         LI,R14   MSG1              SET UP TO OUTPUT 'MANUAL' MESSAGE
         LI,R8    3                 AND SET 15-SECOND TIME-OUT INCREMENT
IOSTRT3  AW,R8    IOCLOCK           ADD CURRENT I/O CLOCK TO TIMEOUT
         STW,R8   DCT11,R1          SAVE I/O DEADLINE VALUE IN DCT
         LC       R4                GET I/O HANDLER PRE-PROCESSOR FLAGS
         BCS,8    RELEASSC          IS SUBCHANNEL RELEASE SPECIFIED.
         BCR,2    IOSTRT4           NO, IS SUBCHANNEL TO BE HELD.
         OR,R5    CHFLAGS,R4        YES, SET APPROPRIATE HOLD FLAGS.
         EXU      CHSAVE,R4         SAVE REQUEST INDEX IN CIT5 OR CIT6
IOSTRT4  OR,R5    CBFLAGS,R4        SET APPROPRIATE SUBCHANNEL(S) BUSY
         OR,R9    X10               SET DATA XFER BIT
IOSTEX   LW,R6    IOQ6,R3           IS THIS A DCB I/O REQUEST.
         BEZ      IOSTEX2           NO, SKIP DCB INITIALIZATION
IOSTEX1  LI,R12   3                 YES, GET 2-BIT ASSIGNMENT MASK
         AND,R12  0,R6              EXTRACT ASN FROM DCB WORD ZERO
         CI,R12   CFUBIT            IS I/O BEING DONE FOR FILE.
         BE       IOSTEX2           YES, DO NOT RESET 'TYC' FIELD
         LW,R13   Y00FE             NO, SET 7-BIT 'TYC' FIELD TO ZERO
         STS,R12  2,R6              ..
IOSTEX2  EQU      %
         STB,R5   CIT3,R2           SAVE CHANNEL STATUS FLAGS
         STB,R9   DCT5,R1           AND DEVICE STATUS BYTE 2
         OR,R10   X80               SET THIS REQ BUSY BIT
IOSTEX3  STB,R10  IOQ3,R3           RESTORE UPDATE IOQ3 SWITCH BYTE
         MTH,1    DCT10,R1          UPDATE DEVICE ACTIVITY COUNTER
         LC       4                 GET FLAGS
         BCR,8    IOSTEX35          IS SUBCHANNEL RELEASE SPECIFIED
         BCR,4    IOSTEX35          WAS FCN DECREMENTED
         LI,R4    IOSCHED           RETURN LINK
         PUSH     4,R1              SAVE R1 THRU R4
         LI,R13   0
         XW,R14   R13               MSG INTO R13 AND CLEAR R14
         BEZ      %+2               NO MSG
         BAL,R5   MSGOUT            ELSE PRINT IT NOW
         LW,R4    IOQ6,R3           DCB INTO R4 (IF ANY)
         LB,R5    IOQ15,R3          USER # TO R5 (MAYBE NEWQ IF FF)
         STW,R14  IOQ6,R3           ZERO DCB ADDRESS
         STB,R14  IOQ15,R3          ZERO USR NUMBER (FOR REPORT ONCE)
         XW,R14   IOQ16,R3          GET ECB/EA ADDRESS
         LW,R3    R14               PUT INTO RC28'S REGISTER
*
*        GO REPORT I/O COMPLETE FOR THIS USER
*
         B        RC28              WADE INTO END OF REQCOM
         PAGE
*
*        I/O START COMPLETE - PRINT MSG IF NECESSARY AND START
*        SOME MORE I/O IF ANY TO DO.
*
IOSTEX35 EQU      %
         ENABLE                     REMOVE INTERRUPT INHIBITS
         LB,R0    R1                RESTORE PRIORITY CODE INTO R0
         LW,R13   R14               IS THERE ANY MESSAGE TO BE OUTPUT.
         BEZ      %+2               NO, DON'T ASK FOR ANY TYPEOUT
         BAL,R5   MSGOUT            YES, PASS MESSAGE INDEX IN R13
         LC       DCT5,R1           WAS CLEANUP SET BY I/O START.
         BCR,4    IOSCHED1          NO, RE-ENTER SCHEDULER FOR MORE I/O
         B        DSERV             YES, CHECK DEVICE PRIOR TO SCHEDULER
         PAGE
*
*        IF R4 = X'C0000000' IT INDICATES A NON-DATA TRANSFER IS
*        TAKING PLACE (EG; REWINDS,SPACE RECORDS,SPACE FILES..ETC)
*
*        SO WE WILL REPLEASE THE USER FROM I/O WAIT BY DECREASING
*        HIS DCB FCN COUNTER HERE AND AT 'IOSTEX3' WE WILL GO TO
*        'RC28' TO REPORT I/O COMPLETE ON HIM.
*
RELEASSC BCR,4    IOSTEX            SUBCHANNEL RELEASE, DECR FCN COUNT.
         LW,R6    IOQ6,R3           YES, REQUEST COMPLETE (E.G., REWIND)
         BEZ      IOSTEX2           IS THERE A DCB FOR THIS REQUEST.
         LB,R7    IOQ10,R3          YES, GET MAX RECOVERY TRIES
         CB,R7    IOQ11,R3          HAVE WE ALREADY DONE A RE-TRY.
         BNE      IOSTEX1           YES, DON'T DECREMENT FCN COUNT
         LI,R7    BAFCN             NO, SET POINTER TO FUNCTION COUNT
         MTB,-1  *R6,R7             DECREMENT ACTIVE FUNCTION COUNT
         B        IOSTEX1           RETURN TO FINISH UP I/O START
         PAGE
         SPACE
CHANTEST NOP                        SUBCHANNEL ASSIGNMENT CHECK LIST
         AND,2    =X'A0FFFFFF'
         AND,2    =X'50FFFFFF'
         B        FORCESC           011 .. DUAL-ACCESS RESTRICTED TO SC1
         B        ASSIGNSC          100 .. UNASSIGNED DUAL-ACCESS
         SPACE
IOALOAD  LH,R6    DCT1P,R1          LOAD I/O ADDRESS: 00 = BOTH SC'S
         LH,R6    DCT1P,R1          01 .. ON SC1 .. PRIMARY I/O ADDRESS
         LH,R6    DCT1A,R1          10 .. ON SC2 .. SECONDARY ADDRESS
         SPACE
CHSAVE   STB,R3   CIT5,R2           SAVE HOLDING REQUEST - BOTH SC'S
         STB,R3   CIT5,R2           01 .. HOLD ON SUBCHANNEL 1
         STB,R3   CIT6,R2           10 .. HOLD ON SUBCHANNEL 2
         SPACE
CBFLAGS  DATA     X'C0'             SUBCHANNEL BUSY FLAGS: 00 = BOTH
         DATA     X'80'             01 .. SUBCHANNEL 1 ONLY
         DATA     X'40'             10 .. SUBCHANNEL 2 ONLY
         SPACE
CHFLAGS  DATA     X'30'             SUBCHANNEL HOLD FLAGS: 00 = BOTH
         DATA     X'20'             01 .. SUBCHANNEL 1 HELD
         DATA     X'10'             10 .. SUBCHANNEL 2 HELD
*
         PAGE
         SPACE
*        FORCESC .. FORCE DUAL-ACCESS TO SUBCHANNEL 1 OPERATION.
*        ASSIGNSC .. ROUTINE TO DETERMINE SUBCHANNEL ASSIGNMENT FOR
*        A NEW OPERATION ON A DUAL-ACCESS DEVICE.  ASSIGNMENT HAS
*        BEEN DELAYED TO 'IOSTRT' TIME IN ORDER TO AVOID RE-SCHEDULING
*        DUE TO PRE-EMPTION OF THE SUBCHANNEL BY A HIGHER-PRIORITY
*        TASK.  ALGORITHM WORKS AS FOLLOWS:
*
*        1.  IF NEITHER SUBCHANNEL IS AVAILABLE (NOT BUSY, NOT HELD),
*            THE I/O SCHEDULER IS RE-ENTERED.
*        2.  IF ONE AND ONLY ONE SUBCHANNEL IS AVAILABLE, THAT SUB-
*            CHANNEL IS TAKEN BY DEFAULT.
*        3.  IF BOTH SUBCHANNELS ARE AVAILABLE, THE 'PREFERRED' BIT
*            IS EXTRACTED FROM THE CIT STATUS AND IS USED TO SELECT
*            THE SUBCHANNEL TO BE USED.  THE BIT IS THEN INVERTED.
         SPACE
FORCESC  LI,R4    1                 DUAL-ACCESS DEVICE FORCED TO SC1
         AI,R10   -3                FORCE IOQ ACCESS KEY TO 001
         CI,R5    X'A0'             IS SUBCHANNEL 1 IDLE AND FREE.
         BAZ      IOSTRT1           YES, RETURN TO START I/O ON SC1
         B        IOSTEX3           NO, RE-SCHEDULE WITH NEW ACCESS KEY
         SPACE
ASSIGNSC SCS,R5   -3                R4 KEY = 100: UNASSIGNED DUAL-ACCESS
         LH,R6    SELECTAB,R5       GET RIGHT HALFWORD OF SELECTAB ENTRY
         BGEZ     SCHEDXIT          IS ANY SUBCHANNEL IDLE & FREE.
         SAD,R6   -13               YES, SET UP SUBCHANNEL SELECT DATA:
         AND,R7   Y8                SC1|-3/0, SC2|-2/0, EITHER|-3/1**31
         AD,R4    R6                SELECT, INVERT 'PREFERRED' IF EITHER
         SCS,R5   3                 RESTORE (POSSIBLY NEW) CIT STATUS
         LI,R11   7                 MOVE SUBCHANNEL INDEX TO IOQ3
         LS,R10   R4                TO FORM NEW IOQ ACCESS KEY
         B        IOSTRT1           AND RETURN TO CONTINUE I/O START
         PAGE
         SPACE
*        IOREJECT .. PROCESS REJECTED 'SIO' INSTRUCTION.  ACTION TO
*        BE TAKEN IS A FUNCTION OF CONDITION CODE STATUS AS FOLLOWS:
*
*        01 .. SIMPLE SIO REJECTION.  REVERSE IOQ ACCESS KEY IF DEVICE
*              IS DUAL-ACCESS AND DEVICE IS 'RESERVED' -- A CONDITION
*              NORMALLY UNEXPECTED BUT MAY OCCUR AFTER SPECIAL I/O,
*              SUCH AS SYSTEM START-UP OR RECOVERY.
*        10 .. SELECTOR IOP BUSY WITH ANOTHER CONTROLLER OR CON-
*              TROLLER BUSY WITH ANOTHER DEVICE.  SET 'SIO-FAIL'
*              BIT IN DCT3 AND CLEANUP PENDING.
*        11 .. DEVICE ADDRESS NOT RECOGNIZED.  SET 'SIO-FAIL' AND
*              CLEANUP PENDING.
         SPACE
IOREJECT EQU      %                 SIO FAILED
         LW,R12   R0                NON-OP DEVICE LEAVES GARBAGE
         STD,R12  DCT13,R1          SAVE SIO STATUS IN DCT
         LB,R7    DCT3,R1           GET DEVICE SWITCHES
         EOR,R13  Y4                AND CHECK FOR DEVICE STATUS '10'
         CW,R13   YE                IS DEVICE STATUS 'RESERVED' (10)
         CS,R7    X3                TEST FOR DUAL ACCESS PATH
         BCS,15   SIOFAIL           AND IS SIO CC1 ZERO (STATUS AVAIL).
         EOR,R10  X3                RESCHED ON OTHER CONTROLLER
         B        IOSTEX3           BY INVERTING IOQ ACCESS KEY.
         PAGE
*
*        DEVICE STATUS INDICATES THAT IT CANNOT BE STARTED - SET
*        SIO FAILED BIT IN DCT3
*
SIOFAIL  EQU      %
         OR,R7    X8                SET SIO FAIL BIT IN DEV SWITCHES
         STB,R7   DCT3,R1           AND REMEMBER CURRENT STATE OF DEV.
         HIO,R7   0,R6              HALT THE DEVICE
         AND,R7   YFFFF             HOLD STATUS BITS
         OR,R7    R6                INSERT DEVICE ADDRESS
         STW,R7   DCT12,R1          AND PUT HIO STATUS IN AIO SLOT
         TIO,R7   0,R6              TEST DEVICE
         LH,R7    R7
         STH,R7   DCT21,R1          AND STORE TIO STATUS AWAY
         AND,R9   X7                SAVE MODES
         OR,R9    X40               SET CLEANUP REQUIRED BIT
         AND,R4   M24               **NO ASYNC I/O IF SIO FAILED**
         B        IOSTRT4           MERGE W/COMMON EXIT
         PAGE
*F*
*F*      NAME:        IOINT
*F*
*F*      PURPOSE:     I/O INTERRUPT RECEIVER
*F*
*F*      DESCRIPTION: WHENEVER THERE IS AN I/O INTERUPT
*F*                   THE XPSD AT LOCATION X'5C' WILL BRING US HERE.
*F*
IOINT    EQU          %
*
         STW,1    TEMP              SAVE FOR LATER PUSH
         LI,1     19                OPEN
         MSP,1    TSTACK             STACK
         LI,1     -15               REG 0
         AW,1     TSTACK             STACK LOC
         XW,1     TEMP              RESTORE REGS
         LCI      0                 STACK
         STM,0    *TEMP              'EM
         LI,3     -1
         LD,0     IOPSD             STACK
         STD,0    *TEMP,3            CONTROL INFO
         ENABLE                     LET 'EM COME
         LCI      0
         AIO,1    0                 ACKNOWLEDGE
         STCF     R3                SAVE AIO CC STATUS
         BCR,8    IO7               BRANCH IF OK
         MTW,1    UNEXP             ELSE, COUNT UNEXP INTS
         B        IO70              DON'T LOG UNRECOGNIZED
IO62     EQU      %
         LW,R15   R1                MOVE AIO WORD TO MSG  ORD ZERO
         STH,R7   R15               STORE CODE/COUNT FIELDS
         LW,R2    R3                RECORD
         SLS,R2   -8
         LI,R6    R15               ADDRESS OF ERROR RECORD
         AW,R6    Y8                TELL ERROR LOGGER WE'RE ON AN INT.
         BAL,5    ERRLOG            LOG THE GLITCH
RTRET2   EQU      %                 EXTERNAL RETURN FROM RTROOT(IOEX)
         MTW,-1   INTCNT            COUNT 'EM DOWN
IO70     LI,2     X'20'             CLEAR IO LEVEL
         DISABLE
         WD,2     X'1200'           CLEAR I/O LEVEL
         B        T:PULLE           AND PULLEXIT
IO7      MTW,1    INTCNT            COUNT 'EM UP
         LI,2     X'FFFF'
         AND,2    1                 DEVICE ADDR
         DISABLE                    DISABLE WHILE HANDLING CHAIN
         LB,7     DCT14             GET HEAD
IO75     CH,2     DCT1,7            CHECK DEVICE ADDRESS
         BNE      IO76              NO
         LB,6     DCT14,7           YES, DEQUEUE IT
         LB,5     DCT15,7           BACK LINK
         LI,8     0
         STB,8    DCT14,7           ZAP ANY GARBAGE
         STB,8    DCT15,7           IN FLINK AN BLINK
         STB,5    DCT15,6           CROSS LINK
         STB,6    DCT14,5           REMAINING ENTRIES
         B        IO10
IO76     LB,7     DCT14,7           FLINK TO NEXT DEVICE
         BNE      IO75              WITH I/O IN PROGRESS
         LI,7     DCTSIZ            TOLOOK IT UP
IO71     CH,2     DCT1,7
         BNE      IO8               NOT YET FOUND
IO10     EQU      %
         LC       DCT5,R7           TEST DEVICE BUSY BIT
         BCS,8    IO14              DEVICE WAS BUSY
*
*        NOTE:    IF DEVICE WAS NOT BUSY GO DIRECTLY TO THE
*                 HANDLER'S BREAK ADDRESS WHICH IS POST-PROCESSING
*                 ADDRESS-1. YOU MUST HAVE A BIT IN DCT9 TO INDICATE
*                 THAT AN UN-BUSY INT IS OKAY.
*
         LI,R11   RTRET2          LOAD RETURN ADDRESS FOR HANDLER
         INT,R5   DCT9,R7         TEST IF DEVICE CAN HAVE THIS
         BCS,4    *M24,R5         GO TO HANDLER'S BREAK ADDRESS
         MTB,0    DCT15,R7          CHECK FOR PRE- EMPTED
         BEZ      IO12              NO, MIGHT BE AVR
         LW,R6    DCT12,R7          GET ENTRY ADDRESS
         BLZ      RTINT             IF A REAL-TIME IOEX INTERRUPT
         LI,R5    J:JIT
         B        0,R6              GO TO DEVICE INTERRUPT HANDLER
IO12     CW,1     Y4                CHK DEVICE END
         BAZ      IO8               NO
         CLM,R7   DPDCT             IS REALLY A DP
         BCS,9    IO50              NO-> JUMP
         LW,8     Y02               ASSUME AVR
         OR,8     7                 COMBINE DCT
         LI,11    IO22              SET RETURN
         B        CTRIG             TRIGGER CONTROL TASK
IO8      BDR,7    IO71              TRY NEXT ENTRY
*
*        CAN'T FIND THE DEVICE OR IT WASNT BUSY, LOG
*        AN ERROR RECORD.
*
IO50     LI,7     X'1304'           CODE/COUNT
         B        IO62              LOG ERROR
IO14     EQU      %
         STW,1    DCT12,7           SAVE AIO INFO
RTRET1   EQU      %                 EXTERNAL RETURN FROM RTROOT(IOEX)
         LB,R6    DCT5,R7           GET DEVICE FLAGS
         AND,R6   M5                CLEAR BUSY/CLNUP/INTROP
         OR,R6    X40               SET CLEANUP PENDING
         STB,R6   DCT5,R7           STORE DEVICE CONTROL BYTE
         LB,R3    R3                POSITION AIO CONDITION CODES
         STB,3    DCT19,7           SAVE
         LCI      0
         TIO,3    0,2               STATUS OF I/O
         LH,3     3
         STH,3    DCT21,7           SAVE IN DCT
         LCI      0
         TDV,R8   0,R2
         STCF     DCT20,7           SAVE STATUS & CC
         STD,R8   DCT13,R7
         LB,5     DCT2,7            CIT INDEX
         LB,4     CIT3,5            CIT SWITCHES
         LB,R3    DCT6,R7           GET IOQ INDEX
         LB,R3    IOQ3,R3           GET IOQ SWITCHES
         CI,R6    X'10'             YES  IS DATA XFER SET
         BAZ      IO20              NO-> GO DRIVE I/O
         AND,R3   X3                EXTRACT ACCESS KEY
         EOR,R4   CBFLAGS,R3        SET SUBCHANNEL(S) NOT BUSY
         STB,4    CIT3,5
IO20     EQU      %                 READY TO EXIT INTERRUPT HANDLER
         MTB,0    DCT22,R7          IS THIS A DISC ?
         BEZ      IO22              B/ NO, GET OUT
         HIO,0    0,R2              AND RELEASE THE CONTROLLER
IO22     LI,6     X'20'             CLEAR
         WD,6     X'1200'            IO LEVEL
         LW,R1    R7                GET DCT FOR SCHEDULER
         BAL,R2   DRIVEIO           CALL I/O SCHEDULER
IO30     MTW,-1   INTCNT            COUNT 'EM DOWN
         BNEZ     T:PULLE
         BAL,11   SACT
         LI,11    0
         XW,11    INTFLG            SEE RC28 IN REQCOM
         BEZ      SSE0
         B        T:SSE
         PAGE
         SPACE
*        CLEANUP  - DO POST-PROCESSING, PRIORITY PERMITTING.
*        CLEANUP1 - DO POST-PROCESSING, REGARDLESS OF PRIORITY.
*
*        IF PRIORITY PERMITS, THE DEVICE ACTIVITY COUNT IS SET IN R14,
*        INTERRUPTS ARE ENABLED, AND THE REQUEST CURRENTLY BEING SER-
*        VICED BY THE DEVICE IS PROCESSED BY THE I/O HANDLER, WITH
*        THE DEVICE RETURNED TO THE 'FREE', 'INTER-OP', OR 'KEYIN-
*        PENDING' STATE, AS APPLICABLE.  REGISTER SETUP:
*
*        R1  ..  PRIORITY, DCT INDEX (8,24)
*        R2  ..  FLAGS, SERDEV EXIT, CIT INDEX (3,10,19)
*        R3  ..  SCRATCH, IOQ INDEX (8,24)
*        R12 ..  FLAGS RETURNED FROM HANDLER:
*                BIT 16 .. RE-TRY SEQUENCE
*                BIT 17 .. FOLLOW-ON SEQUENCE
*                BIT 18 .. INTER-OPERATIVE REQUEST
*                BIT 19 .. KEY-IN PENDING (NORMAL)
*                BIT 20 .. KEY-IN PENDING (SPECIAL)
*                BIT 21 .. CONTINUE CHANNEL HOLD
*                BYTE 3 .. TYPE OF COMPLETION
*        R13 ..  MESSAGE TO BE TYPED (0 IF NONE)
*        R14 ..  DEVICE ACTIVITY COUNT
*        R15 ..  NOT USED - RESERVED FOR FUTURE SYSTEMS
         SPACE
         DO       DEFER
CLEANUP  LB,R3    DCT6,R1           SERVICE CLEANUP-PENDING, GET REQUEST
         CB,R0    IOQ14,R3          IS REQUEST PRIORITY BELOW SCHEDULER.
         BL       DEFER1            YES, DEFER CLEANUP, RETURN IOSCHED
         ELSE
CLEANUP  RES      0
         FIN
CLEANUP1 LH,R14   DCT10,R1          NO, SET DEVICE ACTIVITY COUNTER
         LB,R3    DCT6,R1           PRE-EMPT REQUEST INDEX
         STB,R0   R1                SAVE PRIORITY OF SCHEDULER CALL
         LB,R5    DCT15,R1          IS THIS A REAL-TIME IOEX CLEANUP?
         BNEZ     RTCU              YES, BY-PASS HANDLER POST-PROCESSOR
         LB,8     DCT5,R1           GET DEVICE SWITCHES
         OR,8     X80               PREVENT FURTHER SCHEDULING
         STB,8    DCT5,R1           UNTIL CLEANUP COMPLETE
         ENABLE                     AND RUN HANDLERS ENABLED
         INT,R5   DCT9,R1           GET HANDLER ADDRS-CHK FOR DIAG USE
         BCR,2    0,R5              DEVICE NOT IN DIAGNOSTIC MODE
         LB,R15   IOQ15,R3          DIAG MODE--GET USER #
         CW,R15   DID               IS THIS USER ALLOWED
         BNE      0,R5              NOPE--> CALL HANDLER
         BAL,9    IOSERCK
         NOP
         PAGE
*F*
*F*      NAME:        IOSCU
*F*
*F*      PURPOSE:     RETURN POINT FROM HANDLERS POST-PROCESSING
*F*                   ROUTINES.
*F*
*F*      DESCRIPTION: HANDLERS RETURN HERE WITH THE STANDARD I/O
*F*                   REGISTER SETUP PLUS THEIR FLAGS IN R12/R13.
*F*
*F*                   IOSCU WILL DECODE THE FLAGS AND TAKE APPROPRIATE
*F*                   AACTION.
*F*
IOSCU    EQU      %
         DISABLE
         MTH,1    DCT10,R1          UPDATE ACTIVITY COUNTER
         LB,R0    DCT5,R1           GET DEVICE SWITCHES
         AND,R0   =X'15'            SAVE DATAXFER/CTASK/BIN MODE
         CI,R12   X'D800'           HANDLER SAY TO DO FURTHER THINGS
         BAZ      REQCOM            NOPE--> WE'RE DONE
         CI,R12   X'1800'           NEED OPERATOR KEYIN
         BANZ     SETKEYIN          YES--> STORE CODES/SETUP KEYIN
         LH,R10   DCT17,R1          GET RETRY/FOLLOW-ON CODES
         CI,R12   X'8000'           IS RE-TRY FLAG SET BY HANDLER.
         BAZ      IOFOLLOW          NO, FOLLOW-ON, PRESUMABLY NO ERROR
         MTB,-1   IOQ11,R3          YES, RE-TRY, DECREMENT RE-TRY COUNT
         BNC      REQERR            NO MORE ATTEMPTS - ERROR COMPLETIOM
         SLS,R10  -8                RE-TRY OK, GET HANDLER FUNCTION CODE
IOFOLLOW STB,R10  IOQ5,R3           SAVE CODE AS NEXT FUNCTION STEP
         CI,R12   X'2000'           IS INTER-OPERATION REQUESTED.
         BAZ      %+2               NO, SEQUENCE IS 'INTERRUPTABLE'
         OR,R0    X20               SET DEV INTER-OP SWITCH
         STB,R0   DCT5,R1           STORE UPDATED SWITCHES
         LI,R11   IOSCHED           RETURN LINK
         B        FREESC            RELEASE SOFTWARE IF SUPPOSED TO
*
RESCHED  EQU      IOSCHED
*
         SPACE
         DO       0
IOKEYIN  LI,R9    CTINT             KEY-IN, DOES CONTROL TASK EXIST.
         B        SETKEYIN          NOT FOR U.T.S. -- BRANCH
*        THIS BRANCH WILL BE REMOVED WHEN CTINT IS DEF'ED AS 0 OR
*        AS THE CONTROL TASK INTERRUPT
         BEZ      SETKEYIN          NO, FOREGROUND NO PROBLEM
         LB,R9    IOQ14,R3          YES, GET REQUEST PRIORITY
         CI,R9    CTINT-X'50'       IS IT ABOVE CONTROL TASK PRIORITY.
         BL       REQERR            YES, COMPLETE REQUEST IN ERROR
         ELSE
IOKEYIN  RES      0
         FIN
         PAGE
*
*        SETUP FOR OPERATOR INTERVENTION
*
SETKEYIN EQU      %
         OR,R0    X8                SET KEYIN PENDING BIT IN DEV SWITCH
         STB,R0   DCT5,R1           SAVE CONTROL BYTE
         LD,R10   DCT13,R1          GET TDV STATUS INFORMATION
         STH,R12  R11               SAVE FLAGS, TYC WITH TDV INFO
         STD,R10  DCT13,R1          ..
         LI,R10   6                 SET 30 SECOND TIME-OUT INTERVAL
         AW,R10   IOCLOCK           ..
         STW,R10  DCT11,R1          ..
         BAL,R5   MSGOUT            PRINT DER MSG
         B        IOSCHED           AND SCHEDULE AGAIN
         PAGE
*
*        POST I/O REQUEST COMPLETE
*
*        R0       CONTAINS DCT5 BYTE
*        R1       CONTAINS DCT INDEX
*        R2       CONTAINS CHANNEL INFO TABLE INDEX
*        R3       CONTAINS IOQ INDEX
*        R5       RETURN LINK
*        R12      TYPE COMPLETION CODE IN BYTE 3
*
*        R1 THRU R4 ARE PRESERVED - ALL OTHERS ARE VOLATILE
*
REQERR   LI,R12   8                 ERROR-FORCE ENTRY FROM 'IOSCU'
         BAL,R5   MSGOUT            PRINT ERROR MSG NOW
REQCOM   EQU      %                 REQUEST COMPLETE NORMALLY ENTRY POINT
         LI,R4    IOSCHED           LOAD RETURN ADDRESS
REQCOM1  EQU      %
         PUSH     4,R1              SAVE R1 THRU R4
         AND,R12  XFF               CLEAR HANDLER FLAGS
         BAL,R11  FREESC            RELEASE SOFTWARE CHANNEL
         LW,R4    IOQ6,R3           DCB
         BEZ      RC20              NO DCB
         CI,R12   8                 IS IT ERROR
         BNE      RC3               NO
         CW,R4    Y04               READ OR WRITE
         BAZ      %+2               READ
         LI,R12   9                 WRITE
RC3      RES      0
         LI,R6    0                 CLEAR REG FOR RESETTING EGV
         LI,R15   X'F'              EXTRACT ASN
         AND,R15  0,R4              FROM DCB
         CI,R15   3                 CHECK FOR DEVICE
         BNE      RC4               NO DONT CLOBBER
         LI,R5    4                 DISP TO NRT
         LB,R7    IOQ11,R3          GET REAL NUMBER REMAINING
         STB,R7   *R4,R5            TRANSFER TO DCB
         CW,R4    Y04               READ OR WRITE
         BANZ     RC4               WRITE--DONT CHANGE
         LB,R7    DCT4,R1           GET TYPE INDEX
         LC       TB:FLGS,R7        GET DEV INDICATOR
         BCS,8    RC4               ITS A TAPE-> JUMP
         LI,R7    X'20000'        * ELSE SET BIN BIT IN DCB ACCORDING
         CI,R0    1                 TO THE BIN BIT IN DCT5
         BAZ      %+2
         LI,R6    X'20000'
         STS,R6   0,R4
RC4      EQU      %
         LI,R13   X'3F'             MASK FOR TYC
         SLD,R12  17                ALIGN MASK AND TYC
         CS,R12   TYC,R4            TEST FOR NEW PEAK VALUE
         BLE      RC5               DONT CHANGE, PREVIOUS PEAK
         STS,R12  TYC,R4            SAVE NEW VALUE
RC5      LCW,R13  Y01               DECREMENT FUNCTION COUNT
         AWM,R13  FCN,R4            IN DCB.
         LW,R7    IOQ16,R3          IF AN ECB IS ASSOCIATED
         BEZ      RC6               WITH THIS REQUEST,
         SLS,R12  +7                UPDATE THE TYC IN
         CS,R12   2,R7              THE 4-WORD BLOCK
         BLE      RC6               IF NEW TYC IS BIGGER.
         STS,R12  2,R7
RC6      EQU      %
         LI,R7    X'1000'
         STS,R6   0,R4              CLEAR EGV
         CI,R15   2
         BL       RC10              DO NOT STORE ARS FOR DISC, BLOCKED LBL
         BG       RC8
         LI,R5    3
         CS,R5    ACS,R4
         BNE      RC10
*
RC8      EQU      %
         BAL,R13  IOARS             GET ARS INTO R8 / RBC INTO R11
         LI,R9    X'7FFF'             15 BIT MASK.
         SLD,R8   17                POSITION ARS AND MASK.
         STS,R8   ARS,R4            STORE ARS IN DCB.
         LW,R6    IOQ16,R3          IF AN ECB IS ASSOCIATED
         BEZ      RC10              WITH THIS REQUEST,
         SLD,R8   -17               UPDATE THE RECORD SIZE IN
         STS,R8   2,R6              THE 4-WORD BLOCK.
*                             TEST TO RELEASE BUFFER
RC10     CI,R15   CFUBIT            DOES ASN = FILE
         BE       RC15              YES
         CW,R4    Y08               IS IT POSITION OPERATION
         BANZ     RC14              YES, DO NOT RELEASE
         CW,R4    Y04               IS IT READ OP
         BAZ      RC14              YES, DO NOT RELEASE
         LC       IOQ3,R3           IS MON BUF USED
         BCR,2    RC14              NO
         LW,R14   M24               GET BUFFER ADDR MASK
         AND,R14  IOQ8,R3           GET BUFF ADDR
         SLS,R14  -2                MAKE WORD ADDR
         LW,R8    MPOOL             NEXT AVAIL BUF
         CLM,14   BUFLIMS+MPOOLIM+MPOOLIM   CHECK MPOOL WITHIN LIMITS
         BCS,9    SC1900            SOFTWARE CHECK 19-00
         STW,R14  MPOOL             RELEASED BUF TO HEAD
         STW,R8   *R14              NEXT AVAIL TO RELEASED BUF
*
RC14     EQU      %
         CI,R15   3                 IS IT DEVICE
         BNE      RC15              NO - STILL NOT DIAG CAL
         INT,R11  5,R4              TEST FOR DIAG BIT
         BCR,2    RC15              NO
*  DIAG RETURN -
         LW,R7    DCT12,R1          AIO STATUS
         SLS,7    -16               SAVE ONLY STATUS
         LD,R8    DCT13,R1          TDV STATUS
         LH,R10   DCT21,R1          GET LAST TIO STATUS
         SLS,R10  16                SHIFT INTO PLACE
         LCI      4
         STM,7    15,4              SAVE IN DCB
RC15     EQU      %
         LD,R10   IOQ13,R3
         XW,R10   R11               EAI IN R10, E-A ADDR IN R11
         LW,R8    IOQ6,R3           DCB ADDR
         B        RC21
         PAGE
*
*        NON-DCB I/O COMPLETION RETURN POINT
*
RC20     EQU      %
         BAL,R13  IOARS             GET RBC INTO R11 / ARS INTO R8
         STB,R12  R11               STORE TYC W/RBC
         LW,R12   R11               TYC, RBC
         LD,R13   DCT13,R1          CCA
         LD,R10   IOQ13,R3          END-ACTION INFO
         LW,R14   R11               EAI IN R14
         XW,R11   R10               MIGHT AS WELL GETEA REGS COMP.
RC21     RES      0
         LW,R15   IOQ8,R3           BUF ADDR
         CI,R0    1                 CHECK FOR BIN BIT IN DCT5
         BAZ      RC22
         OR,R15   Y02               SET BIN FOR NEWQ
*                             RELEASE Q ENTRY
RC22     EQU      %
         LW,R6    IOQ8,R3           DATA CHAIN
         BGEZ     RC23              NO
         SLS,R6   1                 TO BUILD DATA CHAIN
         LW,R7    MPOOL             RELEASE BUFFER
         CLM,6    BUFLIMS+MPOOLIM+MPOOLIM   CHECK MPOOL WITHIN LIMITS
         BCS,9    SC1900            SOFTWARE CHECK 19-00
         STW,R6   MPOOL
         STW,R7   0,R6
*
RC23     EQU      %
         LB,6     IOQ2,3            FLINK
         LB,R7    IOQ1,R3           BLINK
         BEZ      RC24              FIRST ENTRY
         STB,R6   IOQ2,R7           CUR FLINK TO PREV FLINK
         B        %+2
RC24     STB,R6   CIT1,R2           CUR FLINK TO HEAD
         AI,R6    0                 TEST FLINK
         BEZ      RC26              LAST ENTRY
         STB,R7   IOQ1,R6           CUR BLINK TO NEXT BLINK
         B        %+2
RC26     STB,R7   CIT2,R2           CUR BLINK TO TAIL
*
         LB,R7    QFREE             HEAD OF FREE ENTRIES
         STB,R7   IOQ2,R3           TO FLINK
         STB,R3   QFREE             CUR IS NEW HEAD
*
         MTW,-1   CURBQ             YES, DEC NO. B'GRND ENTRIES
         LB,5     IOQ15,3
         LB,R7    IOQ7,R3           GET DCT INDEX FOR POSSIBLE E A
         LW,R3    IOQ16,R3          GET USER ECB/EA POINTER.
*
         STB,R0   DCT5,R1           ALLOW DEVICE TO BE SCHEDULED NOW.
*
*
         ENABLE                     RUN EA PEOPLE ENABLED
*
         AND,R11  M22               IS THERE END ACTION
*
         BEZ      RC28
         PUSH     3,R3              SAVE ECB,DCB,USER#.
         LW,R6    R15               BUF ADDR
         BLEZ     %+2
         AND,R6   M22
         SLS,R6   -2                MAKE WORD ADDR
         BAL,R11  *R11              GO TO END-ACTION RECEIVER
         PULL     3,R3              RESTORE ECB,DCB,USER#.
RC28     CI,5     X'FF'
         BAZ      RC30
         BE       RC30              NEWQNW
         LW,R7    R3                DID USER SPECIFY ECB OR EA?
         BEZ      RC29              --> NO.
         MTB,-1   *R7               ARE ALL PHYSICAL I/O'S DONE?
         BNEZ     RC29              --> NO.
         LW,R8    3,R7              IS CAL COMPLETED YET?
         BGEZ     RC29              --> NO.
         LW,R8    R5                R8= USER#.
         LW,R9    2,R7              R9= TYC/RBC FOR ECB INFO WORD.
         LW,R10   1,R7              R10=ECB ADDRESS.
         BAL,R11  ECBPOST1           POST THE ECB. (USING BLK IN R7)
RC29     RES      0
         LW,R1    R4                GET DCB ADDRESS
         LI,6     E:IC              REPORT I/O COMPLETE
         STW,6    INTFLG
         BAL,11   T:RUE
RC30     EQU      %
         PULL     4,R1              RESTORE R1 THRU R4
         B        0,R4              EXIT TO CALLER
         PAGE
*
*        GET ARS
*
*        R1       DCTX
*        R3       IOQX
*        R13      LINK
*
*        RETURNS:
*
*        R8       CONTAINS ARS (REQUEST CNT - RBC = ARS)
*        R10      LAST USED CDW DBL-WORD ADDRESS
*        R11      RBC
*
         DEF      IOARS
*
IOARS    EQU      %
         LH,R8    IOQ9,R3           GET REQUEST BYTE COUNT
         LI,R5    0                 CLEAR ACCUMULATOR
         LD,R10   DCT13,R1          GET TDV STATUS
         BEZ      IOARS3            OPERATION ENDED BY OPERATOR
         AND,R10  M21               SCREEN TDV DA PTR TO LAST CDW
         AND,R11  M16               EXTRACT RBC
         LW,R6    IOQ8,R3           GET DA OF CDW / OR BA OF BUFFER
         BGEZ     IOARS4            OPERATION NOT DATA CHAINED
         LW,R7    R10               MOVE TDV DA OF LAST CDW
         SLS,R7   1                 TDV DA INTO WORD ADDRESS
IOARS0   EQU      %
         SLS,R6   1                 CDW DA INTO WORD ADDRESS
IOARS1   EQU      %
         LB,R14   *R6               GET THIS ORDER CODE
         INT,R9   1,R6              GET BYTE COUNT FROM THIS CDW
         AW,R5    R9                ADD EM UP
         CW,R6    R7                IS THIS THE LAST CDW
         BE       IOARS3            YES-> STOP HERE
         CI,R14   X'08'             THIS CDW A TIC CDW
         BNE      IOARS2            NOPE-> LOOP ON
         LW,R6    0,R6              GET TIC CDW WORD ZERO
         AND,R6   M21               SCREEN OUT ORDER CODE
         B        IOARS0            REJOIN
IOARS2   EQU      %
         AI,R6    2                 POINT TO NEXT CDW IN SEQUENCE
         BDR,R8   IOARS1            AND FINISH UP
IOARS3   EQU      %
         LW,R8    R5                MOVE CALCULATED COUNT TO R8
IOARS4   EQU      %
         SW,R8    R11               REQ CNT-RBC = ARS
         B        *R13              RETURN TO CALLER
         PAGE
*
*F*      NAME:    TDV760X
*F*
*F*      PURPOSE: PERFORM OR SIMULATE TDV FOR HANDLERS WHOSE DEVICE
*F*               MAY BE ON AN FECP
*F*
*F*      DESCRIPTION: IF DEVICE IS NOT ON AN FECP PERFORMS TDV NORMALLY.
*F*               OTHERWISE CALLS FECPIO AT FETDV TO GET UPDATED TDV
*F*               STATUS FROM TABLES
*F*
*
*
TDV760X  EQU      %
*
*
         DEF      TDV760X           FOR REMOTE BATCH GOODIES
*
         LH,R8    DCT1P,R1
         TDV,R8   *R8
         B        0,R6
*
         PAGE
*
*F*
*F*      NAME:        OCINT
*F*
*F*      PURPOSE:     OPERATORS CONSOLE INTERRUPT RECEIVER.
*F*
*F*      DESCRIPTION: WHENEVER THERE IS AN INTERRUPT FROM LOCATION
*F*                   X'5D' WE WILL WIND UP HERE WITH CONDITION CODES
*F*                   EQUAL TO 6.
*F*
OCINT    EQU          %
         PSM,R13  TSTACK            SAVE 13,14,15,0,1,2
         LD,R0    OCPSD             GET PSD
         BAL,R2   T:SAVE            SAVE STANDARD ENV
OCT10    LCW,R8   CTOC              WAS TASK TRIGGERED
         BNEZ     OCT20             YES
         LW,R8    Y01               CODE FOR KEYIN
         BAL,R11  CTRIG             TRIGGER CONTROL TASK
         B        OCT10
OCT20    AWM,R8   CTOC              CLEAR TRIGGER FLAG
         MTW,0    CTACT             IS CONTROL TASK ACTIVE
         BEZ      OCT40             NO
OCT30    LI,R2    X'10'
OCT35    WD,R2    X'1200'           ARM AND ENABLE (CLEAR)
         B        T:SSE             TO SSE TO POINT OF INTERRUPT
OCT40    MTW,1    CTACT             SET CONTROL TASK ACTIVE
         LI,R2    X'10'
         WD,R2    X'1200'           CLEAR OC LEVEL
         PAGE
*
CTIOP    EQU      %                 CONTROL TASK I/O PROCESSOR
*
*    CALLED BY CONTROL TASK OR CONTROL TASK SIMULATOR
*    EXECUTES FUNCTIONS FOUND IN CONTROL TASK I/O STACK
*
*        BAL,R11  CTIOP
*
*    USES ALL REGS
*
*
TP5      DISABLE                                            **DISABLE**
*
         PLW,R8   IOCTQ             GET NEXT FUNCTION
         BCS,2    TP90              STACK EMPTY
*
         ENABLE                                             **ENABLE**
*
         LB,R7    R8                GET CODE
         LB,R7    TPBASE,R7         GET DISP TO ENTRY POINT
         B        TPBASE,R7         SWITCH TO IT
*
:TP      CNAME    0
         PROC
LF       GEN,8    AF(1)-TPBASE
         PEND
*
*
TPBASE   :TP      TP10              0 => DEVICE FUNCTION
         :TP      TP20              1 => CONSOLE INTERRUPT
         :TP      TP40              2 => AVR
         :TP      TP50              3 => KEYIN MSG IN BUF
         :TP      TP60              4 => CHECK ALL DEVICES
         :TP      TP70              5 => PFSR I/O RESTART
         BOUND    4
*
         DO       DEFER             CONTROL TASK DEFERRED CLEANUP
TP10     LW,R1    R8                SET DCT INDEX
*
         DISABLE                                            **DISABLE**
*
         LB,R9    DCT5,R1           GET DCT SWITCHES
         AND,R9   XFB               RESET CONTROL TASK BIT
         STB,R9   DCT5,R1           RESTORE SWITCHES
*
         ENABLE                                             **ENABLE**
*
         BAL,R2   FORCEIO           SERVICE DEVICE WITH PRI X'FF'
         B        TP5
         ELSE
TP10     RES      0
         FIN
*
TP20     LI,R1    TP25              MESSAGE ADDRESS
         BAL,R11  OCWRITE           OUTPUT NL-BANG
         LI,R13   BA(KEYINBUF)      BUFFER ADDRESS
         LI,R0    TP30              END ACTION ROUTINE
         LI,R14   72                SIZE
         LW,R12   TP26              SET FUN AND PRIO
         BAL,R11  NEWQ
         NOP
         B        TP5
*
*
TP25     DATA     X'02155A00'       TEXTC NL-BANG
TP26     GEN,8,8,8,8 0,X'F0',15,OCDCT
*
TP40     EQU      %
         LI,R15   X'FF'
         AND,R15  R8                DCTX
         STW,15   AVRDCT            SET DCTX FOR KEYIN
*
TP50     EQU      %
         LD,0     KEYIN
         LD,8     SYSACT            SET UP KEYIN'S ACCOUNT
         LI,15    X'F0'             SET UP KEYIN'S PRIORITY
         BAL,10   T:GJOB            SEE IF WE CAN START UP KEYIN
         BCR,8    TP5
         LI,R1    3                 LATER MESSAGE
         BAL,R11  OCWRITE
         B        TP5
*
*                             TIME-OUT TEST, ALL BUSY DEVICES
TP60     LI,R1    DCTSIZ
TP62     EQU      %
         LB,R8    DCT5,R1           DCT SWITCHES
         CI,R8    X'88'             DEV BUSY OR KEYIN PENDING
         BAZ      TP63
TP625    EQU      %
         PUSH     R1
         BAL,R2   FORCEIO           YES, FORCE I/O WITH PRIORITY X'FF'
         PULL     R1
         B        TP64
TP63     EQU      %
         LI,R10   DCT26
         BEZ      TP635
         LB,R10   DCT26,R1
         BNEZ     TPFE
TP635    EQU      %
         LB,R8    DCT15,R1          PRE-EMPTED DEVICE?
         BNEZ     TP65              YES, GO CHECK IT
TP64     EQU      %
         BDR,R1   TP62              DO NEXT
         STW,R1   DEVCTCHK          CLEAR FLAG
         B        TP5
TPFE     EQU      %
         CI,R8    X'40'             CLEANUP PENDING
         BAZ      TP635
         LC       DCT3,R1
         BCS,1    TP625             TIMED OUT
         B        TP635
*
*
TP65     EQU      %                 CHECK FOR POSSIBLE IOEX TIMEOUT
         LW,R6    DCT12,R1          INTERRUPT EXPECTED?
         BGEZ     TP64              NO
         LB,R8    DCT18,R1          TIME-OUT REQUESTED?
         BEZ      TP64              NO
         LW,R8    DCT11,R1          OVERDUE TIME VALUE
         CW,R8    IOCLOCK           ARE WE OVERDUE?
         BGE      TP64              NO
         BAL,R11  RTTO              REAL-TIME (IOEX) TIME-OUT PROCESSING
         B        TP64
*
*
TP70     EQU      %
         LI,R1    PFSRMES
         BAL,R11  OCWRITE           WRITE 'POWER FAIL-SAFE' ON OC
         BAL,R11  PFSRIO            RESTART I/O AFTER PFSR
         B        TP5
*
NL       EQU      '
'               NEW LINE X'15'
ZER      EQU      ' '
ZEROS    EQU      ZER,ZER
PFSRMES  TEXTC    ZEROS,NL,'POWER FAIL-SAFE',NL
TP90     LI,R2    0
         LI,3     X'100'            IS SYMFLAG SET
         CW,3     CTFLAGS
         BAZ      TP91              NO
         STS,2    CTFLAGS           YES-SET FLAG OFF
         ENABLE                     AND START SYMBIONTS
         BAL,11   SACT
         B        TP5
TP91     EQU      %
         LI,R3    1
         STS,R2   CTFLAGS           RESET FLAG
*
         LI,R1    X'1001'
         CW,R1    CTFLAGS
         BAZ      OCT60
         ENABLE
         B        CTIOP
OCT60    LI,R1    0
         STW,R1   CTACT
         ENABLE
         B        T:SSE
         PAGE
*
*        FREE ASSIGNED SUB-CHANNEL
*
FREESC   EQU      %
         LB,R4    IOQ3,R3           GET IO SWITCHES
         AND,R4   X7F               THIS REQUEST NOT BUSY OUT
         STB,R4   IOQ3,R3           AND SAVE EM
         LB,R9    CIT3,R2           GET CHANNEL FLAGS
         AND,R4   X3                EXTRACT SUB-CHAN FLAGS
         CW,R9    CHFLAGS,R4        TEST FOR SUB-CHAN BUSY
         BAZ      *R11              NOPE
         ANLZ,R6  CHSAVE,R4         GET CIT SLOT BYTE ADDRESS
         LB,R7    0,R6              GET IOQX OF HOLDING REQUEST
         EOR,R7   R3                IS THIS THE REQUEST THAT IS HOLDING
         BNEZ     *R11              NOPE--> RETURN TO CALLER
         CI,R12   X'400'            BUT DID HANDLER SAY TO CONT HOLD
         BANZ     *R11              YES--> RETURN
         EOR,R9   CHFLAGS,R4        NO---> CLEAR SUB-CHAN BUSY FLAGS
         STB,R9   CIT3,R2           REPLACE CHANNEL FLAGS
         STB,R7   0,R6               CLEAR CHANNEL HOLDING INDEX
         B        *R11              RETURN TO CALLER
         PAGE
*
*        INTERFACE WITH THE KEYIN PROCESSOR FOR DEVICE KEYINS
*
TP33     DISABLE                            ***** DISABLE *****
         LB,R8    DCT5,R1           GET DEV SWITCH BYTE
         CI,R8    8                 IS KEYIN PENDING FOR DEV
         BAZ      TP32              NOPE-> SAY EH
         AND,R8   =X'15'            SAVE XFER/CTASK/BIN MODE
         STB,R8   DCT5,R1           REPLACE
         LB,R3    DCT3,R1           GET SECOND DEVICE FLAGS BYTE
         AND,R3   XE7               SCREEN TIMED OUT/SIO REJECT
         STB,R3   DCT3,R1           AND REPLACE
         LB,R3    DCT6,R1           GET IOQ INDEX
         BEZ      TP32              NONE--> SAY EH
         PUSH     R11               OK--> SAVE RETURN LINK
         LB,R2    IOQ3,R3           CHECK FOR CONTROL Y PROCESSING
         CI,R2    8                 SEE IF WE HAVE IT
         BAZ      TP33:20           NO-->BRANCH
         PUSH     4,R1              SAVE R1-R2-R3-R4
         LW,R15   R1                MOVE DCT INDEX
         LW,R13   R4                GET TYPE OF ERROR INDEX
         BAL,R11  OLWRITE           WRITE THE MESSAGE
         CI,R13   0                 WHAT KIND OF ERROR
         BNEZ     TP33:10           NO USER-->BRANCH
         LW,R7    R15               MOVE DCT INDEX
         LI,R1    14                'YYNDD ERROR BY USER ' MSG INDEX
         BAL,R11  OCQUEUE           GO WRITE THE MESSAGE
TP33:10  EQU      %
         PULL     4,R1              RESTORE R1-R2-R3-R4
TP33:20  EQU      %
         LD,R10   DCT13,R1          GET TDV STATUS
         LH,R12   R11               GET HANDLER FLAGS AS SAVED
         LB,R2    DCT2,R1           GET CIT INDEX
KEYDV    EQU      %
         LB,R7    KEYTV,R4          GET INDEX TO ROUTINE
         B        KEYDV,R7          DISPATCH ROUTINE
KEYTV    DATA,1   ESIMKEYN-KEYDV,CKEYN-KEYDV,RKEYN-KEYDV,EKEYN-KEYDV
         BOUND    4
         PAGE
*
*        CONTINUE KEYIN RETURNS TO ORIGINAL CALLER WITH TYC=1
*
CKEYN    CI,R12   X'800'            CHECK FOR CONTINUE ALLOWED
         BANZ     RKEYN             NO, TREAT AS R
         LI,R12   1                 NORMAL TYC
CKEYN1   EQU      %
         LD,R10   DOUBLEZERO
         STD,R10  DCT13,R1          ZAP TDV STATUS
         BAL,R4   REQCOM1           POST I/O COMPLETED
         B        CKEYN2            MERGE
*
*        RETRY KEYINS CAUSE ANOTHER ATTEMPT AT PERFORMING THE
*        I/O REQUEST
*
*        NOTE THE DIFFICULTY IN ESTABLISHING THE REMAINING RETRY
*        COUNT - THE SIGN BIT IS RESTORED TO INSURE WE DO NOT
*        PASS UP THE # OF RETRIES AUTHORIZED BY THE I/O
*        REQUESTOR.
*
RKEYN    EQU      %
         LB,R11   IOQ11,R3
         STB,R11  R11
         SAS,R11  -24               RESTORE SIGN BIT
         AI,R11   -1                ADJUST BY ONE
         BLEZ     EKEYN             TOO MANY--FORCE AN ERROR EXIT
         STB,R11  IOQ11,R3          RESTORE THE RETRY REMAINING COUNT
         BAL,R11  FREESC            FREE THE SUB-CHANNEL FOR RESTART
CKEYN2   EQU      %
         BAL,R2   FORCEIO
         PULL     11                RESTORE EA RETURN
         B        ENBSR4            RETURN
*
*        ERROR KEYIN FORCES IOQ TO GIVE UP AND RETURN TO CALLER
*        WITH TYC=8 (ERROR)
*
ESIMKEYN EQU      %
EKEYN    LI,R12   8                 ERROR
         B        CKEYN1
*
         END

