         DEF      COOP:
COOP:    EQU      %
*        CPV A00 RJR 19:05  4/18/73 'A00D'(ON SIG 7E).
*        E00  RJR  19:50  03/27/73 .
*        E00  RJR  14:00 2/19/73   'INITIAL' (STRIPPED COOP)
*        D00  RJR   19:25 10/24/72.
*  CREATED 6/22/72  KDR
*   ##            16:00  04/24/72  RJR  *
*        RJR          15:00  03/23/72  *
*
*
*        THINGS TO DO
*                 ...STREAM OREINT STUFF...
*                 ...NO WAIT AND DBL BUFF...
*                 ...ALL COMPRESS...
*
*
*                                    - SIGMA 6-9 CP-V COOP
*                 CATALOG NO. 70XXXX - SIGMA 6-9 UTS COOP
*                 CATALOG NO. 704932 - SIGMA 5/7 BPM M:COOPRES
UTSPROC  SET      1                 WE WANT UTS TYPE PROCS(OVERLAY ETC.)
MONPROC  SET      1                 WANT SYSTEM MON SYMBOLS
         SYSTEM   UTS
COOP     EQU      %
         DEF      COOP,COOPSZ
         DEF      COOPIO            *FOR SYMTAB
         SPACE    5
*                 SYMBOLIC 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
SR1,R8   EQU      8
SR2,R9   EQU      9
SR3,R10  EQU      10
SR4,R11  EQU      11
D1,R12   EQU      12
D2,R13   EQU      13
D3,R14   EQU      14
D4,R15   EQU      15
         SPACE    5
EOSB     EQU      X'40'             END-OF-SYMBIONT-BLOCK
1STDBI   EQU      4
         DEF      1STDBI            *FOR OPNLD
ASNMSK   EQU      3                 MASK FOR DCB:ASN
DEVASN   EQU      3                 ASN=3 FOR STREAMS
DCBBMM   EQU      X'20000'          *DCB BIN MODE MASK
SKTOFBT  EQU      X'40'             * WRTD TOF FLAG(FOR OS).
*
*        COOP-WRTD INTERFACE     (FOR SPEED AND EASE)
*                 THE 12 WORD FILE/DATA MANAGEMENT SPILL
*                 BUFFER DEFINED IN JIT BY J:BASE IS
*                 VOLATILE BETWEEN USER CALS, BUT NON-VOLATILE
*                 DURING A PARTICULAR SERVICE. IT IS USED
*                 IN A TEMP FASHION AS A COMMON DATA AREA BY
*                 FILE/DATA MANAGEMENT. THIS IS NOT
*                 REENTRANT ONLY IN THE SENSE THAT WE CANT
*                 PERFORM MORE THAN ONE SUCH SERVICE
*                 PER USER CAL.  AREA DEFINITION FOLLOWS.
J:TDCB   EQU      J:BASE     0      *DCB TEMP
J:TBTD   EQU      J:TDCB+1   1      *DCB BTD TEMP
J:TDBI   EQU      J:TBTD+1   2      *DATA BYTE INDEX TEMP
J:TCBP   EQU      J:TDBI+1   3      *CNTXT BUF POINT TEMP
J:TBBG   EQU      J:TCBP+1   4      *BUFFER BEGIN TEMP
J:T5%%   EQU      J:TBBG+1   5      *     TEMP
J:TMBA   EQU      J:T5%%+1   6      *MON BUF ADDRESS TEMP
J:TUBA   EQU      J:TMBA+1   7      *USER BUF ADDRESS TEMP
J:T8%%   EQU      J:TUBA+1   8      *     TEMP
J:TEUB   EQU      J:T8%%+1   9      *END USER BUFF TEMP
J:TEMB   EQU      J:TEUB+1  10      *END MON BUFF TEMP
*
         SPACE    5
         REF      C:CSC
         REF      ERRLOG
*
         DEF      COP08A            * NRES  COMMUNICATION
         DEF      COP%RSG           *  ''          ''
         DEF      COP20B            *  ''          ''
         DEF      COPGSG            *  ''          ''
         DEF      COPOLDI           * COMMON OPNLD CALLING SUBR(INTERNAL)
        SREF      H%CMP             * HASPIO COMPRESSOR
         REF      Y04               * FLAGS HASP BIT
         REF      Y2
         REF      Y0008             X'00080000'
         REF      M24               * =X'00FFFFFF'
         REF      M17               *=X'0001FFFF'
         REF      Y8                * =X'80000000'
         REF      S:MBSF            * MUL BATCH SCHEDULE FLAG
         REF      SGB               * SYMB GRANS AT BLOCK
         REF      SGT               * SYMB GRANS AT TRUNC
         REF      E:NSYMD           * EVENT : NO SYMB DISC
         REF      T:REG             * SCHED REP EVENT & GIVE UP
         REF      MULSEG            *  BACK TO MUL FOR COPOPNLD
         REF      ALLOREG           * REG ON SQFAC(AWAIT ALLOCAT STACK CLR)
         REF      UB:MF             * USERS MASTER IO FUNCTION(MOTHERFUNN)
         REF      UB:US             * USERS CURRENT STATE
         REF      SIOW              * IO WAIT STATE
*
*
         REF      RMB               * RELEASE MONITOR BUFFER
         REF      RSG               RELEASE SYMB GRANULE
         DEF      COPEA00           * END ACTION ADDRESS
         DEF      COPGSB            * COOP GET SYMB BUF
         REF      NEWQNWM           * NO WAIT MAPPED,W E/A
         DEF      COPERLG           * COOP ERRORLOG INTERFACE
         REF      J:USCDX           * JIT USED CNTXT DATA EXTERNAL
         REF      Y01               * =X'01000000'
         REF      Y4                * =X'40000000'
         REF      M5
         REF      JCO2VPA
         REF      SV:LSIZ
         REF      SBSIZE            BLK BUFF SIZE
         REF      T:MBUF
         REF      DBPOOL            WHERE THE FREE DATA BUFFERS ARE
         REF      J:JIT             * JOB INFO TABLE
         REF      J:ACCN            * JIT USER'S ACCOUNT
         REF      MSRLP34           * MON SRVC LP (TAB EXPAND)
         REF      SCDBI             * SYMB CNTXT DATA BYTE INDEX
         REF      SCCDA             *  ''   ''   CUR D. A.
         REF      SCBLDA            *  ''   ''   BLINK D. A.
         REF      SCFBUF            *  ''   ''   FILE BUF ADDR
         REF      SCFQARGS          *  ''   ''   FILE Q ARGUMENST
         REF      J:BASE            * CAL PROC'ING TEMP AREA
         REF      BCDTOEBC          * BCD TO EBCDIC TRANSLATION
         REF      TIME              *TIME-OF-DAY
         REF      QUEUE             * (IO SYST) QUEUE (AN IO REQ)
         REF      CHKDA             * CHECK DISC ADDR
         REF      IOSPIN            * IO SPIN TILL DONE
         REF      SCDEVTYP          * SYMB CNTXT DEVICE TYPE
         REF      S:CUN             * CURRENT USER NUMBER
         REF      JX:CMAP           * HIS PHYSICAL PAGE ADDR TABLE
         REF      SCGCO             * SYMB CNTXT GRAN COUNTER
         REF      SCPCO             *   ''   ''   PAGE COUNTER
         REF      SCRCO             *   ''   ''   RECORD COUNTER
         REF      SCMAXR            *   ''   ''   MAXIMUM RECORD
         REF      SCMINR            *   ''   ''   MINIMUM RECORD
         REF      SCBSIZ            *   ''   ''   BLOCK SIZE
         REF      SCCUN             *   ''   ''   USER NUMBER
         REF      SCRPDA            *   ''   ''   REL PREV DA
         PAGE
*INPUT/OUTPUT COOPERATIVE-SEMI-REENTRANT
*TO SIMULATE READING OF CARD IMAGES,PUNCHING,PRINTING AND TYPING
*VIA DISC
*RESIDENT PORTION FOR NON-SYMBIONT DEVICES
*(R5)=JIT ADDRESS(JOB INFO TABLE)
*(SR1)=FUNCTION CODE,DCB ADDRESS
*ADDR FIELD OF WORD 12 OF DCB MUST BE ZERO WHEN OPENING FILE
*        BAL,SR4  COOP
*        RETURN
         SPACE    5
*
         LI,R3    ASNMSK            *
         AND,R3   ASN,R6            * REROUTE TAPEOP,
         AI,R3    -DEVASN           * ANSTAPE ET AL.
         BNEZ     QUEUE             *
         LI,R3    X'FF'             *
         AND,R3   CLK,R6            *FILTER NON STREAM
         BEZ      QUEUE             *AND SKIM IT OFF
*
         LW,R3    *J:USCDX,R3       *CNTXT BUFFER POINTER
         CW,R3    Y2                CNTXT BLK MEANS ANYTHING?
         BANZ     COP00A            *COPTAB OK
SC2D2    EQU      %
         SCREECH  X'2D',2           * BAD COPTAB
*        DCB IS POINTING TO NONEXISTENT CNTXT AND IS OPEN
COP00A   EQU      %                 *
         BG       COP00B            * STRM OPEN
         LI,R3    COOP              * RETURN TO TOP AFTER
         B        COPOLDI           *  OPNING DCBS STREAM
*
COP00B   EQU      %                 * STREAM AND DCB OPEN.
         LW,R4    SR1               CALLING DCB ADDRESS
         LW,R1    Y2                CHECK IF DIAGNOSTIC
         CW,R1    ACS,R4            USE OF DEVICE
         BANZ     COP00C            DIRECT I/O
*
         PUSH     SR4               YES, SAVE EXIT
         B        COP08A            ENTRY FOR OPEN FILE
*
COP00C   LI,D3    X'1FFFF'          * WRTD NOT XFERED YET FLAG
         AND,D3   QBUF,R4           * REC IN AN MPOOL YET
         CI,D3    X'1FFFF'          *
         BNE      QUEUE             * YES, DO IO NOW
         LI,R2    BAFCN             * NO, THROUGH WRTD AGAIN
         MTB,-1   *R4,R2            * TO TAB XPAND.
         B        MSRLP34           NON SYMBIONT PRINTER
         PAGE
*INPUT/OUTPUT COOPERATIVE
*RESIDENT PORTION FOR SYMBIONT DEVICE
*(R3)=SYMTAB INDEX
*(R4)=CALLING DCB ADDRESS
*(TSTACK) = EXIT ADDRESS
*
*USES J:BASE TEMP AREA IN CONJ WITH WRTD/IOD
*(NO CNTXT SEARCHES,HAND-IN-HAND SERVICES)
*OPENDEV IN MUL DOES ALL THE OPEN AND LINKUP WORK.
* WE ARE ALL SET UP TO GO RECORD BY RECORD.
*
         SPACE    5
COP08    EQU      %                 *FROM BELOW
         LI,SR4   0                 * (ZAP THAT 1ST TIME
         STW,SR4  SCBLDA,R3         *  FLAG)
         BAL,SR4  COP16A            * READ 1ST BLOCK IN
COP08A   EQU      %
*        CHECK FOR NON ZERO FCN
*
         BAL,R1   COPPSH            * R3-R11 NON VOL
         LW,R6    R3                *IOSPIN USES BYTE AT BAFCN(W7B0) AS
         BAL,SR4  IOSPIN            *IO EVENT CONTROL BLOCK(WAIT TILL DOONE)
         BAL,R1   COPPLL            *RESTORE R3-R11
*
COP08B   EQU      %                 *EOSB TRY AGAIN
         LW,R2    SCDBI,R3          DATA BYTE INDEX
         BEZ      COP18             *RET FROM CCLOSE IO
         LW,D4    SCDEVTYP,R3       I/O READ FUNCTION
         BGEZ     COP10             YES
         PAGE
*MOVE OUTPUT RECORD TO CORE BUFFER
COP09    EQU      %
         MTW,+1   SCRCO,R3          COUNT OUTPUT
         BAL,SR4  COPGSB            GET DATA BUFFER
         LW,R1    SCFBUF,R3
         AND,R1   M17               MASK OFF HI BYTE
         LW,R4    SR1               NOTE:SR1 NON-VOLATILE IN T:MBUF
         LW,R2    SCDBI,R3          DATA BYTE INDEX
         AND,SR1  NB31TO0+29        AND OUT BAD BIT FOR SYMB
         LB,D4    SR1               I/O FUNCTION CODE
         AI,R2    +2                *ADVANCE TO RCC
         STB,D4   *R1,R2            TO REC CTRL CODE
         AI,R2    -2                *RETARD TO BC
         LI,D1    0                 *
         STB,D1   *R1,R2            * 255 MAX BC LIM FOR NOW
         AI,R2    +1                *
         STW,R2   J:TDBI
         LI,D1    X'1FFFF'
         AND,D1   QBUF,R4
         LW,D3    R1                DEST BFR
         CI,D1    X'1FFFF'
         BE       COP09L            SYMBIONT PRINTER
         LW,D2    BLK,R4            RECORD BYTE COUNT
         SLS,D2   -17               ALIGN
         LW,R5    SCMAXR,R3         **
         AI,R5    +1                **LIM REC SIZ TO
         CW,R5    D2                **STREAM MAX
         BGE      COP09B
         LW,D2    R5                **
         CW,D2    SCMINR,R3         * MIN REQ SATISFIED
         BGE      COP09B
         LI,R1    X'C000'
         AND,R1   SCDEVTYP,R3
         CI,R1    X'4000'
         BE       COP09B            LISTING DEVICE
         LW,R1    QBUF,R4           * IS AN MPOOL
         AND,R1   M17
         REF      BUFLIMS,MPOOLIM
         CLM,1    BUFLIMS+MPOOLIM+MPOOLIM
         BCS,9    COP09B
         SLS,R1   +2                *  BA
         AW,R1    D2                *     END
         SW,D2    SCMINR,R3         * NUM TO PAD
         LCW,D2   D2                *  POSITIVELY
         STB,D2   R1                *
         LI,D2    X'20000'
         AND,D2   0,4
         SLS,D2   1
         REF      Y004
         EOR,D2   Y004
         MBS,0    53
         LW,D2    SCMINR,R3         * MIN REQ SAT.
COP09B   EQU      %                 *
         STB,D2   *D3,R2            *RECOOD BYTE COUNT.
         AI,R2    +2                GET TO CORR BYTE DISP
         LW,R5    R2                SAVE PLACE FOR SKIP BYTE
         LW,R1    SCDEVTYP,R3       IS THIS THE OCP
         CW,R1    Y0008
         BAZ      COP09B0           NOPE
         LI,D4    1                 SKIP BYTE ALWAYS ONE
         AI,R2    1
         B        COP09B1
COP09B0  EQU      %
         LI,D4    0                 INITIALIZE SKIP COUNT
         AI,R2    +1                NEXT POSITION
         AI,D4    +1                INCREMENT SKIP COUNT
         CI,R2    3                 FORCE ZERO
         BANZ     %-3                 BTD
COP09B1  EQU      %
         LB,R1    J:TCBP            * PARTICULAR FLAGS
         AND,R1   %+2               *(ONLY TOF STUFF TO SK)
         OR,D4    R1                * TO SK FOR OS
         CI,R1    SKTOFBT           * WAS THAT TOF
         BAZ      %+2               * NO,
         MTW,+1   SCPCO,R3          * YES, COUNT PAGES IN FILE
         STB,D4   *D3,R5            *INSERT SKIP COUNT.
         STW,R4   J:TDCB            SAVE DCB
         LW,D4    QBUF,R4           SRCE BFR
         LW,R1    D2                SRCE SIZE
         LW,SR4   Y04               *HASP CNTXT BIT
         CW,SR4   SCDEVTYP,R3       * IS HE
         BAZ      COP09N            * NO, HE AINT
COP09C   EQU      %
         LW,R3    SCMAXR,R3
         AI,3     6
         XW,R3    R2
         LI,4     0
  B    COP09CM
COP09N   LW,R3    R2                * DEST BTD
         REF      RECT2
         BAL,SR4  RECT2
*                                   *   DATA BYTE INDEX.
COP09H   EQU      %                 *.CONTINUE.
         LW,R5    J:TCBP
         STW,R3   SCDBI,R5          LST USED BYTE +1
         LW,R0    Y008
         REF      Y008
         AND,R0   *J:TDCB           TEST MBG
         BEZ      COP09X            SKIP IF OFF
         LW,D3    D4                MONITOR
         BAL,SR4  RMB               RELEASE CALLING DCB MONITOR BUFFER
COP09X   LW,R3    J:TCBP            CNTXT BFR
COOPCMP  EQU      X'200'            TB:FLG FOR COMPRESS
         LI,R0    COOPCMP
         CW,R0    SCDEVTYP,R3
         BAZ      COP09XX
         LW,D3    SCFBUF,R3         STRIP TRAILING BLANKS
         LW,R5    J:TDBI            DISP OF REC B.C.
         LB,D4    *D3,R5            :
         LI,R0    ' '               :
         LW,R4    SCDBI,R3          SCDBI AND RECORD B.C. ARE
         AI,R4    -1                AJUSTED OVER ANY BLANKS
         CB,R0    *D3,R4
         BE       %-2
         AI,R4    2                 END+1 AND 1 IF ALL BLNK
         XW,R4    SCDBI,R3
         SW,R4    SCDBI,R3
         BGZ      %+3
         AWM,R4   SCDBI,R3
         B        COP09XX
         SW,D4    R4
         STB,D4   *D3,R5
COP09XX  EQU      %
         LW,R4    J:TDCB            DCB
         LI,R0    0                 SET NON-EOD CONTROL CODE
         B        COP15A            CONTINUE
*
COP09L   RES      0
         LW,R1    RWS,R4            **NO  USE HIS SIZE
         LI,R5    BADSC             FOR
         LB,R5    *R4,R5             DATA
         BEZ      %+3                 OPTION
         AI,R5    -1                   IN
         AW,R2    R5                    DCB
         AI,R2    +2                TO
         LW,R3    SCDEVTYP,R3       IS THIS THE OCP
         CW,R3    Y0008
         BAZ      COP09L0           NOPE
         LI,D4    1                 SKIP BYTE ALWAYS ONE
         AI,R2    1
         B        COP09L1
COP09L0  EQU      %
         LI,D4    0                  WORD
         LI,R3    3                   ALIGN
         AI,R2    +1                   FOR
         AI,D4    +1                    MBS
         CS,R2    J:TBTD                 IN
         BNE      %-3                     RECTRAN
COP09L1  EQU      %
         SW,R2    R5                DATA OPTION AGAIN
         LW,R5    J:TDBI
         AI,R5    +2
         LB,R3    J:TCBP            * PARTICULAR FLAGS
         OR,D4    R3                * TO SK FOR OS
         CI,R3    SKTOFBT           * WAS THAT TOF
         BAZ      %+3               * NO,
         LI,R3    SCPCO             * YES, COUNT PAGES THIS FILE
         MTW,+1   *J:TCBP,R3        *
         STB,D4   *D3,R5            INSERT SKIP COUNT
         LW,R3    R2
         AI,R3    +1                *NEXT SLOT IS 1ST DATA BYTE
         LW,D4    BUF,R4            BUF
         XW,R4    J:TDCB            SAVE DCB
         STB,R4   *D3,R2            INSERT VFC BYTE
         STW,R2   J:TBBG
         LI,R2    SCMAXR            * SIZE LIM CELL
         LW,R2    *J:TCBP,R2        * FROM CNTXT
         AW,R2    J:TBBG            * FINAL BUFF LIM
         AI,R2    +1                *(ALLOW FOR VFC BYTE)
         LW,R4    J:TBTD            SRCE BTD
         BAL,SR4  FRMIMNT           FORM IMAGE
         REF      FRMIMNT
         LW,R5    J:TCBP            CNTXT BFR
COP09V   RES      0
         STW,R3   SCDBI,R5          NEW POSITION
         SW,R3    J:TBBG            ACTUAL LENGTH
         LW,R4    J:TDBI            INSERT
         STB,R3   *D3,R4             LENGTH
*                   'SC79 DUE TO FAST OVERPRINT FORMAT ONLY NOP'
         CI,R3    1                 FORMAT CHAR ONLY
         BNE      COP09X            NO, EETS OKAY
         LI,R4    X'40'             YES, AT LEAST ONE CHARACTER
         LW,R3    SCDBI,R5          * BEYOND VFC CHARACTER
         STB,R4   *D3,R3            * MUST BE PRINTED
         AI,R3    +1                * TO SLOW DOWN LP.
         B        COP09V            *=*JOIN REG PROCESSING*=*
         PAGE
*
* PARK H%CMP HERE FOR NOW
COP09CM EQU %
         BAL,SR4  H%CMP
         B        COP09NF
         LW,R5    J:TDBI
         STB,R2   *D3,R5
         LI,D1    0
         AI,5     1
         LB,5     *14,5
         LW,4     J:TCBP
         STW,3    SCDBI,4
         LCI      0
         PSM,0    TSTACK
         LW,3     J:TCBP
         BAL,11   COP19I
         LW,6     J:TCBP
         BAL,11   IOSPIN
         LCI      0
         PLM,0    TSTACK
         LW,3     SCDBI,4
         STB,D1   *D3,R3
         AI,R3    +1
         STW,R3   J:TDBI
         AI,R3    +1
         STB,5    *14,3
         LI,D1    1
         AI,R3    +1
         STB,D1   *D3,R3
         AI,R3    +1
         STW,3    SCDBI,4
         LW,R1    J:TDCB
         LW,R1    BLK,R1
         SLS,R1   -17
         LW,2     SCDBI,4
         LW,3     4
         B        COP09C
*
COP09NF  EQU      %
         AI,R1    0
         NOP
         LW,R5    J:TDBI
         STB,R2   *D3,R5
         B        COP09H
*
COP09BF  EQU      %                 * BUFFER IS FULL
         BAL,SR4  COP19I            * WRITE IT OUT
*                        *NOTE: SCDBI MUST INDICATE BUFF FULL
         B        COP08A            * RECORD TO NEXT BUFF.
*
*
         PAGE
*MOVE INPUT RECORD FROM CORE BUFFER
COP10    EQU      %
*
*
         LW,SR4   SCBLDA,R3         * GOT 1ST BLOCK IN CORE
         BLZ      COP08             *NOPE, GO BACK TO READ
         BAL,SR4  COPGSB            MAP TH BUFFER
         LW,R2    SCDBI,R3          HAVE TO REGAIN IT
         LW,R4    SR1               RESTORE DCB ADDR(SR1 NONVLTLE IN T:MBUF)
         LW,D3    SCFBUF,R3         *DATA BUFFER ADDR
         LB,R0    *D3,R2            * BC BYTE 1
         AI,R2    +1                * TO NEXT
         LB,D1    *D3,R2            * BC BYTE 2
         SLS,R0   +8                * -ALIGN-
         OR,D1    R0                * MERGED BC
         AI,R2    +1                * ADVANCE
         LB,R0    *D3,R2            *  RCC
         AI,R2    +1                * ADVANCE
         LB,D2    *D3,R2            * FETCH UP SKIP BYTE
         AW,R2    D2                * AND SKIP AHEAD
         CI,R0    EOSB              *AT END OF STREAM
         BNE      COP12A            * NOPE, CONTINUE
         LI,R2    1STDBI            * YEP,GIVEMFIN
         STW,R2   SCDBI,R3          * AT BUFF TOP
         AND,D3   M24               SCFBUF AHS SPARE BUFFER INX IN BYTE 0
         AW,D3    COPFCT            *
         LI,D4    COPF              * MBS SOURCE(&CLR HI BYTE)
         SCD,D3   +2+32             * MBS DEST+COUNT AND SOURCE(RIT REGS)
         MBS,D3   0                 *
         LI,R2    X'FF'             * STREAM NUMBER IS 8BITS WIDE
         AND,R2   CLK,R4            * FETCH IT UP
         CI,R2    1                 * IS IT THE C1 STREAM
         BNE      COP08B            * NOPE =>A FIN IS EOF
         LI,R2    2-4*(COP11-COPF)  * BAK UP TO RCC
         AW,R2    D3                *       AND CHANGE IT TO BCD REC
         MTB,BCD-EOF   0,R2         * CAUSE A BANG THRU C1 IS A NATURAL EOF
         B        COP08B            * FROM THE TOP
BCD      EQU      0                 ***BCD RCC
EOF      EQU      5                 ***EOF RCC
COPFCT   GEN,8+2,24-2 4*(COP11-COPF),1STDBI/4
COPF     EQU      %
         GEN,16,8,8  5,EOF,1   BC=5,RCC=EOF,SK=1
         DATA     '!FIN'
         GEN,8,16,8 ' ',0,EOSB  BLANNK,BC=0,RCC
COP11    EQU      %                 *(NOT TO BE MOVED)
COP12A   EQU      %
         SLS,D1   +17               POSITION BYTE COUNT
         LI,D2    X'E0000'          RECORD BYTE COUNT MASK
         STS,D1   ARS,R4            RECORD BYTE COUNT TO CALLING DCB
         AND,D2   BLK,R4            CALLING DCB RECORD BYTE COUNT
         STH,R0   R0                RECORD CONTROL CODE BECOMES MODE
         LI,R1    DCBBMM            MODE MASK
         STS,R0   MOD,R4            SET MODE IN CALLING DCB
*                                   0=BCD,1=BINARY;BIT 14
         LI,R1    X'C0'             STARTING BYTE INDEX MASK
         AND,R1   BTD,R4            CALLING DCB RECORD START BYTE INDEX
         SLS,R1   -6                POSITION STARTING BYTE INDEX
         LW,D3    QBUF,R4           CALLING DCB RECORD BUFFER ADDRESS
         SCD,D1   +15               RIGHT JUSTIFY RECORD BYTE COUNTS
*                 D1  = USER BC  (DESTINATION)
*                 D2  = MONITOR BC (SOURCE)
         LW,R4    SCFBUF,R3         DATA BUFFER ADDRESS
         B        COP14A            *(B BEATS 2 AI-)
COP13    AI,R2    +1                INCR.DATA BYTE INDEX
         CW,R2    SCBSIZ,R3         * DATA BUFFER OVERFLOW
         BL       COP14             NO
*                                   YES
         LI,R2    1STDBI+2          * RESET TO TOP
         LI,D4    EOSB              SET END OF DATA BLK CODE
         STB,D4   *R4,R2            INTO TOP OF BUFFER
         LI,D1    0                 SET DATA LOST
         STW,D1   0,R4
         AI,R2    -2                * BACK OFF TO CORRECT
         BAL,SR4  COPERLG           * AND LOG THE BAD IN FILE
         B        COP14B            CONTINUE
COP14    BDR,D1   %+2               DATA LOST
         B        %+3               YES
COP14A   LB,D4    *R4,R2            NO,DATA RECORD BYTE
         STB,D4   *D3,R1            TO CALLING DCB RECORD BYTE
         AI,R1    1                 INCR.CALLING DCB RECORD BYTE INDEX
         BDR,D2   COP13             IF MORE DATA BYTES TO MOVE,LOOP
         AI,R2    1                 INCR.DATA BYTE INDEX
COP14B   EQU      %
         INT,D4   SR1               DATA CONVERSION REQUESTED
         BCR,1    COP14Z            NO
         PUSH     3,R1
         LW,R2    D3                CALLING DCB RECORD BUFFER ADDRESS
         SLS,R2   8                 POSITION BUFFER ADDRESS
         LI,R3    X'C0'             STARTING BYTE INDEX MASK
         LS,R2    BTD,R4            CALLING DCB RECORD START BYTE INDEX
         SLS,R2   -6                BUFFER BYTE ADDRESS
         LI,R3    X'E0000'          RECORD BYTE COUNT MASK
         AND,R3   ARS,R4            CALLING DCB RECORD BYTE COUNT
         SCS,R3   +15               RIGHT JUSTIFY RECORD BYTE COUNT
*ALL REGISTERS EXCEPT D3 SAVED
         BAL,R1   BCDTOEBC
         PULL     3,R1
         PAGE
         LOCAL    CO,TO
CO       SET      1**16+1           INPUT-TYPE CODE OFFSET.
TO       SET      +12               DCB TYPE-OF-COMP OFFSET
*
*
*INPUT/OUTPUT PROCESSING
*TO PROCESS CALLING DCB
COP14Z   LW,R4    SR1               CALLING DCB ADDRESS
*                                   * ANS NOT WORD BOUNDED
COP15    STW,R2   SCDBI,R3          DATA BYTE INDEX TO CNTXT-DATA BLOCK
COP15A   LI,D3    1**TO             NORMAL I/O COMPLETION CODE
         CI,D1    0                 DATA WAS LOST
         BG       %+2               NO
         LI,D3    2**TO             YES,LOST DATA COMPLETION CODE
         AI,R0    -CO*1             END OF DATA CONTROL CODE
         BNEZ     %+2               NO
         LI,D3    6**TO             YES,END OF DATA COMPLETION CODE
         AI,R0    -CO*(3-1)         READ ERROR CONTROL CODE             932
         BNEZ     %+2               NO                                  932
         LI,D3    8**TO             YES,READ ERROR COMPLETION CODE      932
         AI,R0    -CO*(EOF-3)       *END-OF-FILE CONTROL CODE FOUND
         BNEZ     %+2               * NOPE, MUST BE OTHER
         LI,D3    7**TO             * YEP, EOF TYC.
         LI,D4    X'7F'**TO         COMPLETION CODE MASK                932
         SLD,D3   +17-TO            POSITION COMPLETION CODE AND MASK
         STS,D3   TYC,R4            COMPLETION CODE TO CALLING DCB
         LI,D4    X'1000'           ERROR GIVEN FLAG MASK
         STS,D3   EGV,R4            RESET CALLING DCB ERROR GIVEN FLAG
         STB,D4   J:TCBP            *CLEAR PARTICULAR FLAGS
         LCW,R0   Y01               DECR.I/O REQUEST
         AWM,R0   FCN,R4            COUNT IN CALLING DCB
         LOCAL
         PAGE
*
*READ/WRITE DISC
*
         LW,D4    SCDEVTYP,R3       I/O READ FUNCTION
         BLZ      COP19             NO
*SINCE READ FUNC.,WNDW #2 SHOULD ALREADY HAVE BEEN MAPPED
         LW,D3    SCFBUF,R3         DATA BUFFER ADDRESS
         AI,R2    +2                *ADVANCE TO NEXT RCC.
         LB,R0    *D3,R2            RECORD CONTROL CODE
         CI,R0    EOSB              END OF DATA BLOCK
         BNE      COP18             NO,EXIT
         LI,SR4   COP18             SET READ DISC EXIT
*
*READ DISC
*
COP16A   EQU      %
         PUSH     4,SR1             SAVE NON-VOLATILE REGISTERS
COP16AA  EQU      %                 * QFAC RETURN
         LW,SR1   SCRPDA,R3         * OVERFLOW TO REL
         BEZ      %+3               * NOPE,SKIP IT
         BAL,SR3  COP%RSG           * YEP, TRY AGAIN
         BEZ      COP17E            * FAILURE, WAIT ON CAT
COP16B   EQU      %                                                     932
         BAL,SR4  COPGSB            GET DATA BUFFER
         LW,SR1   SCCDA,R3          IS NEXT TO BECOME CURRENT
         BGZ      COP17A            YES
COP16C   EQU      %
*                                   *=* END OF THAT FILE *=*
         B        COP17C            EXIT                                932
COP17A   EQU      %
         BAL,SR4  CHKDA             IS D.A. GOOD
         BCS,8    COP17B            YES
         BAL,SR4  COPDER1           NO
         B        COP16C
COP17B   EQU      %
         LW,R0    Y01               SET I/O
         AWM,R0   SCBSIZ,R3         REQUEST COUNT
         LW,R5    R3                CNTXT-DATA BLK ADDRESS
         MTW,+1   SCGCO,R3          *
         MTW,1    C:CSC
         LCI      5                 * NEWQ HAS 6 ARGUMENTS
         LM,R12   SCFQARGS,R3       * EXPECTED IN R12-R1.
         SLS,R13  2                 * BUF IS A BYTE ADDR
         AND,R13  M24               * 24 BITS WIDE.
         AND,R15  M24               * DA IS 24 BITS WIDE
         AH,R12   R15               * DCTX IS BYTE 1(DISC B MOD NEEDED)
*                       R1 AVAIL FOR DISC B DCTX FETCH FOR 'AH'
         LI,R2    0                 * UNMAP CONTEXT POINTER.
         AND,R3   M17               *(CLEAN UP THAT CNTXT POINT)
         SLD,R2   32-9              *(1 WORD LESS 9 BITS OF PAGE
         LOAD,R2  JX:CMAP,R2        * DISP ARE REPLACED FROM
         SLD,R2   -(32-9)           * PHYS PAGE TABLE)
         LW,R1    S:CUN             * USER NO. TO CONTEXT
         STW,R1   SCCUN,R5          * FOR EA ROUTINE.
         MTB,+1   UB:MF,R1          *LOCK IN CORE FOR IO
         LW,R1    R3                * CNTXT POINT PHY EA ARG.
COOPIO   BAL,SR4  NEWQNWM           *NO-WAIT MAPPED IOQ.
         B        COP17D            --FILE DEVICE DOWN--
         LW,R3    R5                CNTXT-DATA BLK ADDRESS
COP17C   EQU      %                                                     932
         PULL     4,SR1             RESTORE NON-VOLATILE REGISTERS
         B        *SR4              EXIT
COP17D   SCREECH  X'2D',1           THE OTHER BAD PROBLEM
*                                   *WHAT TO DO WITH DISC DOWN.
COP17E   EQU      %                 TRY AGIN AFTER CAT'S BEEN IN
         LI,R0    COP16AA           *ALLOREG LINK IS R0
         B        ALLOREG           *STATE IS SQFAC.
         SPACE    10
*
*COOPERATIVE EXIT
*
COP18    EQU      %
         PULL     SR4
         B        *SR4
         SPACE    10
COP19I   EQU      %                 * WRITE THE BLOCK INTERNAL
         PUSH     SR4               * INTERNAL LINK IS SR4
*
*WRITE DISC
*
COP19    EQU      %
         LW,D1    SCBSIZ,R3
         SW,D1    SCMAXR,R3         * ALLOW FOR A MAX RECORD
         AI,D1    -(4+3+4+4+6)      *+BC,RCC,SK+MXSK+BC,EOSB,SK,COMP
*                                   *+4 BYTES OF BLINK.
         SW,D1    SCDBI,R3          SPACE LEFT IN BFR
         BGEZ     COP18             YES,EXIT
*COOP WNDW #2 SHOULD ALREADY HAVE BEEN MAPPED
         LW,D2    SCFBUF,R3         DATA BUF ADR
         LI,R0    EOSB              EOD
         LW,R2    SCDBI,R3          DATA BYTE INDEX
         AI,R2    +2                *ADVANCE OVER BC
         STB,R0   *D2,R2            EOD BLK CONTROL CODE TO DATA BLK
         BAL,SR4  COPGSG            YES,GET DISC GRANULE
COP20A   EQU      %
         LW,R1    SCFBUF,R3         DATA BUFFER ADDR
         LI,SR4   COP20C            WRITE DISC EXIT
COP20B   EQU      %
         STW,R0   0,R1              NEXT DISC ADDR TO DATA BUFFER
         LW,R0    SCCDA,R3
         XW,R0    SCBLDA,R3         BLINK
         BGEZ     %+2               *(WATCH THAT FIRST ONE)
         LI,R0    0                 *1STBLINK=0
         LW,D1    SCBSIZ,R3         *
         AI,D1    -4*1              * BUFFEND-1
         SLS,D1   -2                *
         STW,R0   *D1,R1            * BLINK TO BUF.
         PUSH     4,SR1             SAVE NON-VOLATILE REGISTERS
*
*
*        COOP OUTPUT BLOCKS ARE MARKED SUCH THAT GIVEN A SYMBIONT
*        FILE INCONSISTENCY ONE CAN TELL IF THE BAD BLOCK BELONGS
*        WITH THE STREAM IN WHICH IT WAS FOUND, IF IT BELONGS AT
*        THIS POSITION, WHO IT REALLY BELONGS TO, AND MAYBE WHAT WENT
*        WRONG TO CAUSE THE DISC BLOCK BAD SITUATION.
*
         LW,D2    J:JIT             * L/ USER TYPE,0,SYSID  2,14,16
         SCS,D2   +8                * MOVE HOLE TO HI BYTE
         SCS,R3   -5                * PICK CNTXT ADDR BITS 19-26
         STB,R3   D2                * ... MERGE W/USERID
         SCS,R3   +5                * RESTORE CNTXT ADDR
         SCS,D2   -8                * ...........AND USER ID
         AI,D1    -1                * PICK WORD PRECEDING BLINK
         STW,D2   *D1,R1            *--PARK: TYPE,CNTXT#,SYSID 2,14,16
*
         LI,D2    20                * DUE TO UNSUBSTANTIATED RUMOR
         AW,D2    SCDBI,R3          * THAT SOMETIMES WE USE ENUF BUF
         SW,D2    SCBSIZ,R3         * TO PROHIBIT COMPLETE BUFF MARK
         BGEZ     COP17B            *..WE WONT MARK IF THAT CASE OCCURS.
*
         LW,D2    J:ACCN+1          * L/ WHO WORD 1
         AI,D1    -1                * PICK PRECEDING WORD
         STW,D2   *D1,R1            *--PARK: '....(WHO WORD 1)'
*
         LW,D2    J:ACCN            * L/ WHO WORD 0
         AI,D1    -1                * PICK PRECEDING WORD
         STW,D2   *D1,R1            *--PARK: '(WHO W0)(WHO W1)'
*
* ... LAST RECORD/BC=0/RCC=EOSB/SK=0/.../'ACCO'/'UNT '/TYPE,CNTXT,SYSID/BLINK.
*
*
         B        COP17B            GO TO WRITE DISC
COP20C   LI,R0    1STDBI            RESET DATA INDEX
         STW,R0   SCDBI,R3
         B        COP18
         PAGE
*COOP GET DATA BUFFER ROUTINE
*        BAL,SR4  COPGSB
*        INPUT : (R3)=CNTXT BLK ADDR     NON-VOLATILE
*        OUTPUT : COOP WNDW #2 MAPPED WITH DESIRED SPARE BUFFER
*          CNTXT BLK INFO (SCFBUF) UPDATED
*          FREE DATA BUFFER POOL(DBPOOL IN CB0) UPDATED
*
COPGSB   EQU      %
         LW,SR3   SCFBUF,R3         HAS BUFFER BEEN ASSOCIATED
         BNEZ     COPMAP            YES,BUT STILL HAS TO MAP SPRE BUFFER
         LW,D3    J:USCDX
         AI,D3    DBPOOL            PT TO FREE POOL
         LI,R2    1
COPGSB1  LB,R0    *D3,R2
         BNEZ     COPGSB2
         AI,R2    1
         CI,R2    SV:LSIZ
         BLE      COPGSB1           KEEP TRYING
         SCREECH  X'2D',0           NO FREE DATA BUFF PRE-ALLOATED
COPGSB2  EQU      %                 GOT ONE
         LI,D1    0
         STB,D1   *D3,R2            NOW,IT WILL BE TAKEN AWAY
         LI,SR3   JCO2VPA
         CW,R0    X20               SEE IF LOWER/UPPER HALF PAGE
         BAZ      COPGSB3
         AI,SR3   SBSIZE
         AND,R0   M5                SHAKE OFF INDICATOR
COPGSB3  STB,R0   SR3
         STW,SR3  SCFBUF,R3
COPMAP   EQU      %                 (R3) PRESERVED
         LB,SR3   SR3               GET SPARE BUFFER INDEX
         LI,D3    JCO2VPA
         LW,D1    R3
         PUSH     2,SR4
         BAL,R2   T:MBUF            SR1 NON-VOLATILE
         PULL     2,SR4
         LW,R3    D1
         B        *SR4
*SYSTEM UTS: REF  RCVPSD            * WE HAD THAT BUFFER
*                                   *BEFORE, NOW WE LOST IT.
         PAGE
*
*        COPPSH - COOP PUSH    L=R1;  R3-R11(SR4) TO TSTACK
COPPSH   EQU      %
         PUSH     9,R3              *
         B        0,R1              *
*
*        COPPLL - COOP PULL    L=R1; R3-R11(SR4) FROM TSTACK
COPPLL   EQU      %                 *
         PULL     9,R3              *
         B        0,R1              *
*
*        COPOLDI - COOP OPNLD INTERNAL (ENTRY)
*                 L=R3;  R3-R11(SR4) NON-VOLATILE
*                 CLOSED STREAM IS REOPENED FOR OPEN DCB.
*                 ***RARE: IT ONLY OCCURS AFTER EXPLICIT
*                        STREAM CLOSURES***
*
COPOLDI  EQU      %
         BAL,R1   COPPSH            * SAVE NONVOLATILE
         OVERLAY  MULSEG,6          * 6TH ENTRY IS INTERNAL
*
*                 SR3 HAS (POTNTIALLY) AN OBSCURE ERROR CODE WHICH
*                   SHOULD BE TRANSMITTED TO THE USER -- VERY HARD TO
*                   DO NOW, BBUT HE'LL GET A 4A00 BECAUSE WE IGNORE
*                   IT HERE.
         BAL,R1   COPPLL            * RESTORE NONVOLATILE
         B        0,R3              * AND BACK TO INTERNAL CALLER.
*
         PAGE
*INPUT COOP DISC READ-OUTPUT COOP DISC WRITE END ACTION-CORE RESIDENT
*NO ERROR DETECTION ON DISC WRITE
*
*R15     =  BUFFER BYTE ADDRESS
*R14     =  CONTEXT BLOCK ADDRESS (PHYSICAL)
*SR4(R11)=  EA LINK
*R6      =  BUFFER WORD ADDRESS.
*
         SPACE    5
COPEA00  EQU      %
         LW,R3    R14               CONTEXT BLK ADDR.
         LW,R4    SCBSIZ,R3         * IO ECB FOR COOP IO
         SW,R4    Y01               HI BYTE -1
         STW,R4   SCBSIZ,R3         * BACK WITH FCN DECR.
         LW,SR3   TSTACK            *
         AI,SR3   -1                *
         LW,R1    SCCUN,R3          USER NEEDING E:IC
         LW,SR1   0,R6              *BUF FLINK IS NDA
         XW,SR1   SCCDA,R3          * NDA IS NEW CDA.
         DISABLE                    * STATE LOOK AND REPORT DONE INHIBITED
         LB,R5    UB:US,R1          *CHECK IOC USER STATE
         CI,R5    SIOMF             *PARKED ON MF HIGH
         BE       COPEA01           *YEP CHECK UNPARK
         CI,R5    SIOW              *PARKED ON PARTICULAR IO
         BNE      COPEA02           * NO (MAY NOT BE PARKED)
         BDR,R4   COPEA02           *YES,BUT THIS AINT IT.
*                                   *PARKED AND THIS IS IT
COPEA01  EQU      %                 * REPORT COMPLETE.
         STW,R1   *TSTACK           -R5 IN REQCOM STACK
         STW,R14  *SR3              *-R4 IN REQCOM STACK
*                                   THAT MARKS THE DCB(CONTEXT
*                                   BLOCK THAT MAY NEED E:IC)
*   IOQ MANAGES 'MF' AND SSS   IO EVENT REPORTING
*   IOSPIN & SSS NEED ONLY FCN BYTE IN DCB.
*
         OR,R4    Y8                * SET TO REPORTING NOT RELEASING
         B        COPEA03           *LEAVE INHIBIT AND MF FOR SSS
COPEA02  EQU      %
         MTB,-1   UB:MF,1
         BNEZ     COPEA03-1         ---------------------
         MTB,1    UB:MF,1
         OR,R4    Y8                SMK -- 10/1/73 #11191
         LI,14    0
         B        COPEA01           ----------------------------
         ENABLE
COPEA03  EQU      %                 *
         LW,R0    SCDEVTYP,R3       * IN OR OUT STREAM
         BLZ      *SR4              - OUT MEANS EXIT
*                                   - IN TRY TO REL GRANS
*        WE CANT PARK AN E:IIP USER
*        ON E:QFAC UNTIL AFTER E:IC
*        SO, GRANS MUST BE RELEASED BEFORE  CONTEXT RELEASE.
*
         LI,SR3   1STDBI            *RESET CONTEXT DATA BYTE INDEX
         STW,SR3  SCDBI,R3          *
         XW,SR1   SCBLDA,R3         * OLD CDA BECOMES PDA
*
         CW,R0    Y4                * RERUN NO DELETE
         BANZ     *SR4              * YES,EXIT.
         BDR,R4   COP%RSG11         * NOT REPORTING SO RELEASE(11TO10)
         STW,SR1  SCRPDA,R3         *REPORTING SO CANT RELEASE, STASH
         B        *SR4              *DA FOR LATER AND LEAVE
*
COP%RSG11 EQU     %                 * MOVE LINK AND RELEASE(L=SR4)
         LW,SR3   SR4               * PRESERVE EA LINK.
*
COP%RSG  EQU      %   L=SR3,U=R0,R1,R2,SR4 STANDARD COOP RSG SUBR
         LI,R0    0                 * (FOR RSG)
         STW,SR1  SCRPDA,R3         * SAVE REL PDA IN CASE
         BAL,SR4  RSG               * TRY TO REL PDA
         BEZ      *SR3              *FAILURE, GIVE UP
         LI,R0    0                 * (ALSO FOR RSG)
         STW,R0   SCRPDA,R3         * CLEAR IN CASE 'NOT LAST'
         MTW,0    SCCDA,R3          * LAST INPUT DISC ACCESS
         BNEZ     *SR3              * NOPE DONE
         LW,SR1   SCBLDA,R3         *CURR=0 SO RELEASE BLINK.
         STW,R0   SCBLDA,R3         * (PREVENT INFINITE LOOP)
         B        COP%RSG           * USE COMMON CODE.
*
         PAGE
*                 CO-OP ERRLOG ROUTINE  SR3 = CNTXT BLK.
*        BAL,SR4  COPDER
COPDER   EQU      %
*        BAL,SR4  COPDER1
COPDER1  EQU      %
COPERLG  PUSH     5,R2
         LW,R2    0,R3              * STREAM NUMBER
         SLS,R2   +8                *
         OR,R2    S:CUN             * AND USER NUMBER
         LI,R3    X'1B03'
         STH,R3   R2                FIRST WD
         LW,R3    TIME
         LI,R4    SCCDA
         LW,R4    *SR3,R4           D.A.
         LI,R6    R2                ADDR OF ER MBS
         BAL,R5   ERRLOG
         PULL     5,R2
         B        *SR4
         PAGE
*COOPERATIVE GET DISC GRANULE ROUTINE
*(R3)=CONTEXT-DATA BLOCK ADDRESS
*        BAL,SR4  COPGSG
         REF      GSG
COPGSG   EQU      %
*
         LW,R0    SGT               # AT WHICH TO TRUNK
         CW,R0    SCGCO,R3          * # IN USE THIS FILE
         NOP                        *NEED OVERTO CCLOSE CODE
*        BLE      TRUNCATE          HE HAS ENUF SO TRUNC'EM
*
*
CPGSGM1  EQU      %
         PUSH     SR4               SAVE EXIT
         PUSH     SR1               SAVE I/O FUNCTION,CALLING DCB ADDR
CPGSG00  EQU      %
         LW,SR1   SCCDA,R3          CUR DA
         AI,SR1   1                 *GET SECOND HALF
         CI,SR1   1                 * ALREADY GOT
         BAZ      %+2               * NUP,USE ODD ADDR
         BNEZ     CPGSG02           * YUP,GET ANOTHER
         BAL,SR4  GSG
*        CI,SR1   0
         BNE CPGSG01 GOT ONE
*
         PUSH     R6
         LI,R6    E:NSYMD           NO GRANULE AVAILABLE FOR OPENING A
         BAL,SR4  T:REG             COOP FILE. Q HIM UP TILL A SYMB
         PULL     R6
         B        CPGSG00           GRAN GETS RELEASED.
CPGSG01  RES      0
CPGSG02  EQU      %
         LW,R0    SR1               CURRENT DISC ADDRESS
         PULL     SR1               RESTORE I/O FUNCT,CALLING DCB ADDR
         PULL     SR4               RESTORE EXIT
         B        *SR4              EXIT
*
TRUNCATE EQU      %
*        LI,11    COP18             SET EXIT FROM COOP CLOSE
*        B        CCLOSE            DO A SUPER-CLOSE ON THIS GUY
         PAGE
*
*        MONITOR SIZE REALIGNMENT CAUSED SGC ROUTINE FAMILY AND
*        T:BTSCHED TO BE MOVED TO THIS MAPPED SERVICE MODULE.
*        CLOCK4 AND SACT ARE NOW PURELY UNMAPPED INTURRUPT MODULES.
*
*                 TO ALLOW THE MONITOR TO FLOAT IN SIZE
*               ABOVE THE .8000 BOUNDARY IMPLIED BY THE
*               NEED TO HAVE MAPPED SERVICE ROUTINES EXIST
*               1-TO-1 WITH THE USER, ALL MAPPED SERVICE
*               ROUTINES NOW EXIST IN TOTALLY MAPPED SERVICE
*               MODULES,AND UNMAPPED(INTURRUPT) ROUTINES
*               EXIST IN SEPERATE MODULES THAT ARE
*               LOCCT'ED TO THE ROOT TOP AND MAY EXTEND
*               BEYOND .8000 .
*
*
*
*
         DEF      T:BTSCHED         BATCH SCHEDULE
         REF      PL:LK             PARTITION LIMIT LOCK
         REF      S:BUAIS           BATCH ALLOWED IN SYSTEM
         REF      S:BUIS            BATCH IN SYSTEM
         REF      S:BFIS            BATCH FILES(FED) IN SYSTEM
         REF      MBSGFC            MULTIBATCH SYS GHO FUN CODE
*
T:BTSCHED EQU     %
*                                   BLOCKED BY CONTROL
         LW,D4    PL:LK                (IF NOT BLOCK HIM)
         BNEZ     *11               --BLOCKED: CATCH IT LATER
*
         LW,D4    S:BUAIS           SYS LIM: BATCH USERS ALLOWED IN SYSTEM
         SW,D4    S:BUIS            SYS CNT: BAT USERS IN SYSTEM
         MW,D4    S:BFIS            SYS CNT: BAT FILS IN SYSTEM
*                 S:BUAIS-S:BUIS IS:     -     0     +
*                 S:BFIS         IS:     +  0  +  0  +  0
*                 S:BFIS*(S:BUAIS-S:BUIS)
*                                IS:     -  0  0  0  +  0
*     SO SCHEDULE IF (S:BUAIS .GT. S:BUIS).AND.(S:BFIS .NE. 0)
         BLEZ     *11               *** CANT START ANOTHER
         LI,D1    MBSGFC            SIGNAL GHOST
         BAL,R4   SGCQ                VIA COMMUNICATION QUEUE
         STW,14   S:MBSF            ERR: CUDNT SIGNAL SO REMARK AS WAS
         B        *11               EXIT
*
         PAGE                                                      .
*
*        RBBAT                      *
*                                   *
*        REMOTE BATCH / BATCH       *
*        SYMBIONT GHOST CALLER:     *
*           QUEUEING ROUTINES       *
*
*        PROGRAMMED FOR UTS C00     *
*        BY       RON RILEY         *
*                 SAM KEYS          *
*          AND    KEITH DICKEY      *
*
*        MODULES MODIFIED  (RJR)    *
*        ----------------           *
*        SACT     SUPPORT ROUTINES  *
*        COOP     IN & OUT FILE     *
*                 USER INTERFACE    *
*        INSYM    IN FILE CREATION  *
*        OUTSYM   OUT FILE DELETION *
*        CLOCK4   SCHEDULER         *
*        SUPCLS   OUT FILE CLOSE    *
*        T:JOBENT SPECIAL FILE      *
*                 MANAGEMENT        *
*        REQDC    SUPPORT SUBR      *
*        SUSPTERM SUPPORT SUBR      *
*        DSCIO    RBT HANDLER       *
*                                   *
*
*                                                                  .
*        SGC-     REGISTER USAGE IN GENERAL:                       .
*                                   LINKS=R4,R11(SR4),R0           .
*                 ARGS=R12(D1),R13(D2),R14(D3),R15(D4);RTNS=R1,ARGS.
*                                                                  .
*        GHOST CALLING  ARGUMENTS                                  .
*                                                                  .
*        AIF                                                       .
*                 1   FLNK,-,DCTX,GFC     8,8,8,8                  .
*                 2   FINFLG,SDA          1,31                     .
*                 3      -                                         .
*                                   NO RETURN                      .
*        AIFJE                                                     .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   0,SDA         1,31                           .
*                 3   0,SYSID       16,16                          .
*                               NO RETURN                          .
*        AOF                                                       .
*                 1   FLNK,0,DCTX,GFC     8,8,8,8                  .
*                 2   RBID,SDA            8,24                     .
*                 3   SYSID               32                       .
*                                   NO RETURN                      .
*        AOFNB                                                     .
*                 1   FLNK,0,DCTX,GFC  8,8,8,8                     .
*                 2   RBID,SDA      8,24                           .
*                 3   PRIO,-,SYSID  8,8,16                         .
*                               NO RETURN                          .
*        AOFP                                                      .
*                 1   FLNK,0,DCTX,GFC  8,8,8,8                     .
*                 2   TYP,SDA       8,24                           .
*                 3   PRIO,RBID,SYSID  8,8,16                      .
*                               NO RETURN                          .
*        GOF                                                       .
*                 1   FLNK,-,DCTX,GFC     8,8,8,8                  .
*                 2   LAST OF INDX        32                       .
*                 3    -                                           .
*                                   RETURN                         .
*                 1   FLNK,0,DCTX,GFC  8,8,8,8  (UNCHANGED)        .
*                 2   SDA OR 0=NOFILE                              .
*                 3   PRIO,RBID,SYSID  8,8,16                      .
*        MBS                                                       .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   -                                            .
*                 3   -                                            .
*                               NO RETURN                          .
*        KPRIO                                                     .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   TYP,-,SYSID   8,8,16                         .
*                 3   NEWPRIO       32                             .
*                               NO RETURN                          .
*        KDEL                                                      .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   TYP,-,SYSID   8,8,16                         .
*                 3   -                                            .
*                               NO RETURN                          .
*        KDISP                                                     .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   ?????                                        .
*                 3   ?????                                        .
*                               NO RETURN                          .
*        JESTAT                                                    .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   -,SYSID       16,16                          .
*                 3   USER #        32                             .
*                               RETURN                             .
*                 1    (UNCHANGED)                                 .
*                 2   CODE          32                             .
*                 3   # TO RUN      32                             .
*        JEDEL                                                     .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   -,SYSID       16,16                          .
*                 3   USER #        32                             .
*                               RETURN                             .
*                 1    (UNCHANGED)                                 .
*                 2   0 OR X'3F3A'  32                             .
*                 3   -                                            .
*        KSWIT                                                     .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   TYP,-,SYSID   8,8,16                         .
*                 3   TARGET RBID   32                             .
*                               NO RETURN                          .
*        KSEND                                                     .
*                 1   FLNK,-,DCTX,GFC  8,8,8,8                     .
*                 2   MBA           32                             .
*                 3   -                                            .
*                               NO RETURN                          .
*        KBDCST                                                    .
*                 1   FLNK,-,GFC    8,16,8                         .
*                 2   MBA OR 0      32                             .
*                 3   -                                            .
*                               NO RETURN                          .
*        DUP                                                       .
*                 1   FLNK,-,DCTX,GFC     8,8,8,8                  .
*                 2   -                                            .
*                 3   -                                            .
*                                   NO RETURN                      .
*        LORR                                                      .
*                 1   FLNK,-,DCTX,GFC     8,8,8,8                  .
*                 2   MON BUF ADDR        32                       .
*                                   NO RETURN                      .
*        HUP                                                       .
*                 1   FLNK,-,DCTX,GFC     8,8,8,8                  .
*                 2   -                                            .
*                 3   -                                            .
*                                   NO RETURN                      .
*
*
*
         DEF      SGCQ2             SYM GHO CALL: QUE 2  .
         DEF      SGCQ         SYM GHO CALL QUEUE
         DEF      SGCR              SYM GHO COM RELEASE
         DEF      SGCRA             SYM GHO COM REL (ALTERNATE)
         DEF      @SGCBUF           BUFFER POINTER(AND ADDER)
         DEF      SGC:NCB           SYM GHO COM: NO COMM BUF
         REF      E:NSYMF           EVENT: NO SYM FILES
         REF      NOPGFC            * NO-OP GHOST FUNCTION CODE
         REF      Y00FF             * =X'00FF0000'
         REF      T:GJOBSTRT        GHO JOB START ROUTINE
         REF      SGCHD             SYM GHO CALL HEAD PTR
         REF      SGCBUF            SYM GHO CALL BUFFER
*
         REF      E:SYMF            EVENT: SYMBIONT FILE SLOT AVAIL
         REF      T:RUE             REPORT USER EVENT
         REF      BOOTFLG
*
*        THREE IS A MAGIC NUMBER
*                 MOST EVERYBODY PASSES THREE ARGUMENTS TO RBBAT, THUS
*               THE ROUTINES ARE DESIGNED TO HANDLE THIS WELL.
*               FOR THOSE WITH 4 ARGS R2 IS USED VIA SGCQ. FOR
*               THOSE WITH MORE SGCQ2 USING TWO BUFFERS MUST DO.
*
*
*
*
XFF00FFFF DATA    X'FF00FFFF'       *ERASE MASK
SGCQ2    EQU      %                 QUEUE UP TWO
*        L=R4;I=D1,D2,D3,D4(THAT'S R12-R15)
*                 R2 IS UNCONDITIONALLY DROPPED INTO CB1&2 W4
*        O=R1;U=R0,R1,R12,R14
*        ACTION:  D1-D3 TO COMM BUFF 1  W1-3
*                 COMM BUFF W1 BY1 POINTS TO SECOND COMM BUFF
*                 D4-R0             TO COMM BUFF 2 W2-3
*                 (SECOND COMM BUFF IS A NOP)
*                 GHOST IS TOLD.
*        RETURN:  PLUS ONE COULDN'T GET 1 OR 2 BUFFS
*                 PLUS TWO A O K.
*
         LCI      14                *DONT CLOBBER ANYTHING
         PSM,R7   TSTACK            * R7--(D4,D0)--R4 NONVOL.
         LW,SR1   Y00FF             * MASK FOR MOVED ARG
         AND,SR1  D1                * REMEMBER MOVED ARG
         SLS,SR1  -8                * (AND MOVE IT SOME)
         AND,D1   XFF00FFFF         * AND ERASE IT
         DISABLE                    -----INHIBIT-----
         LB,R6    SGCHD             * CAN GET ONE
         BEZ      SGCQA1            * NUP, GIVE UP.
         LH,R5    SGCHD             *REMEM OLD TAIL FOR CASE2 FAIL
         BAL,R4   SGCQA             * YEP, GO GET IT.
*                                   * CAN GET ANOTHER
         BEZ      SGCQA2            * NUP, GIVE 1ST BACK
*                                   * YEP, ALL IS GO
         SLS,R7   +16               * NEXT IS WHERE THEYLL GO
         OR,D1    R7                * POINT RBBAT
         LCI      3                 * 3 AT-A-TIME
         STM,D1   0,R6              * 1ST SET OF ARGS
         STW,R2   3,R6              * --R2 IS ALWAYS THE 4TH ARG--
         STM,D4   D2                *(IT WORKS-BELIEVE ME)
         LW,D1    SR1               * MOVE THE MOVED ARG
         AI,D1    NOPGFC            * AND IDENT.
         MTW,1    *TSTACK           * BUMP USER RETURN
         BAL,R4   SGCQ              *--FINISH AND TELL RBBAT--
SGCQA2   BAL,R4   SGCR6             *(RELEASE HIDDEN IN SKIPPED
*                                   *  INSTRUCTION SLOT)
SGCQA1   EQU      %                 * USER RET
         LCI      14                * DONT CLOBBER ANYTHING
         PLM,R7   TSTACK            * R7--(15,0)--R4
         B        SGCQX             * ENABLE FOR CASE 1
*
         SPACE    5
SGCQ     EQU      %                 SYMBIONT GHOST COMMUNICATION Q
*        L=R4;I=D1,D2,D3(THAT'S R12-14);O=R1;U=R1
*                 (R2 IS ALWAYS DROPPED INTO W4)
*        GENERAL WORKHORSE FOR GHOST CALLING
*        STORES D1-D3 IN COMM BUFF AND AWAKES GHOST
*        RETURNS PLUS ONE NO BUFFERS
*                     TWO NORMAL
         DISABLE                    OH YES, WE ALSO DISABLE/ENABLE
         MTB,0    SGCHD             *SENSE ANY FREE
         BEZ      SGCQX             - NUP  EXIT
*
         MTW,0    BOOTFLG           *ARE WE BOOTED YET
         BNEZ     SGCQX             *NOE: Q'EM TILL RBBAT STARTS
*                                   *YAH: AOK
         LCI      15                14(+LINK) NON-VOL REGS
         PSM,R2   TSTACK            R2-R0(VIA D4 ) ARE SAVED
*                                   - R1 IS THE ANSWER -
*
         LI,R4    SGCQA3            * (ALTERNATE USAGE COSTS
SGCQA    EQU      %                 * A LI & B )
*
         LH,R6    SGCHD             *
         SCS,R6   -8                *     R0 = UTL
         LB,R7    R6                *     R1 = FHD
         BNEZ     SGCQ%1            - TAIL IS THERE;NORMAL CASE
*
         STW,R6   SGCHD             NO TAIL IMPLIES NO USE Q
         STH,R6   SGCHD             * SO CREATE ONE
         B        SGCQ%2            - SKIP AHEAD
*
SGCQ%1   EQU      %                 * ADD NEW TO UTL
         STH,R6   SGCHD             *   NEW UTL
         AI,R7    SGCBUF            * BUF # TO BUF ADDR
         STB,R6   *R7               * FLINK OLD TAIL TO NEW
SGCQ%2   EQU      %
         AI,R6    SGCBUF            * FREE BUF# TO ADDR
         LB,R7    *R6               * OLF FHD FLINK TO
         STB,R7   SGCHD             *     NEW FHD
*
         B        0,R4              * (%+1 NORMALLY)
SGCQA3   EQU      %                 *
*
         LCI      3
         STM,D1   *R6                 : ARG TO GHOST PASSER :
         STW,R2   3,R6              * --R2 IS ALWAYS THE 4TH ARG--
         ENABLE                     -----UN INHIBIT-----(NO MORE NEED)
*
         PSW,R6   TSTACK            - SAVE THE ANSWER -
         LD,R0    TSYMGHO           'NAME OF GHOST'
         BAL,SR3  T:GJOBSTRT        TRIGGER GHOST
*        I=R0,R1;L=SR3;U=R0-R6,SR3-D1,D4  ;  O=CC'S, GHOST GOOSED
*
         LCI      0                 REGS SAVED ABOVE
         PLM,R2   TSTACK            ARE RESTORED
*
         AI,R4    1                 * NORM EXIT
SGCQX    ENABLE                     -----UNINHIBIT-----
         B        0,R4                       RETURN
         BOUND    8                 FOR LOAD DOUBLE
TSYMGHO  TEXTC    'RBBAT'           THE RABBIT --REMOTE BATCH/BATCH
*****
*****
@SGCBUF  LW,R0    SGCBUF,R1         'HANDY-DANDY P-Q-R ADDER'
*
         SPACE    5
SGCR6    EQU      %                 * CASE2 FAILURE CUDNT GET 2 BUFS
*                    THE OLD TAIL MUST BE RESTORED AND ITS FLINK ZAPPED
         LI,R1    +1                * POINT AT BY 1
         STB,R5   SGCHD,R1          *    AND DROP IN THE OLD TAIL
         LB,R5    SGCHD,R1          *(WHILE WERE HERE CLEAN THE REG)
*        BEZ      THE MONITOR SIMPLY CANT HANDLE THIS SITUATION
*                 (NO MAUDE: NOT EVEN A CRASH WILL DO)
         LI,R1    0                 *  A ZERO FLINK FOR
         AI,R5    SGCBUF            * . .  THAT OLD
         STB,R1   0,R5              * . . .  TAIL ARGUMENT
         LW,R1    R6                * THE GOTTEN GUY TO BE GIVEN BACK
SGCR     EQU      %
*
*        L=R4; U=R0,R1,D1(R12)   RELEASE R1 BUFFER
         LW,D1    R1
         AI,R1    -SGCBUF
SGCRA    DISABLE                    -----IN HIBIT-----
         LB,R0    SGCHD             FREE HEAD
         STB,R0   *D1                FLINKS REL BUF
         STB,R1   SGCHD              WHICH BECOMES NEW HEAD
         ENABLE                     -----UN INHIBIT-----
         AI,R0    0                 JUST RELEASED LAST BUF
         BNEZ     0,R4              NO-THERE ARE PLENTY
*                                   YES- MAYBE NSYMF
         LCI      0
         PSM,0    TSTACK
         LI,R6    E:SYMF            REPORT FILE SLOTS AVAIL
         LI,R5    R:SYMF            FOR ALL IN THIS STATE
         REF      SB:RQ,R:SYMF,SIOMF
         LB,R5    SB:RQ,R5
         BEZ      %+2               NONE THERE SKIP IT
         BAL,R11  T:RUE             DOIT
         LCI      0
         PLM,0    TSTACK
         B        0,R4
*
         SPACE    5
*
*
*
*
SGC:NCB  EQU      %
         PUSH     11
         PUSH     6
         LI,6     E:NSYMF
         BAL,11   T:REG
         PULL     6
         PULL     11
         B        *M24,R4           FOR SIGMA 9 EXT. ADDR.
*
COOPSZ   EQU      %-COOP
         END

