*M*      COOP      USER/DEVICE COOPERATIVE DCB I/O,ASN=3,SYMBIONT DEVICE
*
*
*
*P*      NAME:     COOP
*,*
*,*      PURPOSE:            THIS MODULE IS THE MAIN PACKAGE CONTAINING
*,*           OPERATING SOFTWARE NEEDED IN ALL CP-V SYSTEMS TO COOPERATE
*,*           WITH THE USER SUCH THAT THE LOGICAL DEVICE FILE SEEMS LIKE
*,*           THE ORIGINAL DEVICE.  COOP IS RESIDENT IN THE MONITOR ROOT
*,*           ALLOWING USAGE BY MAPPED MONITOR FOR USER AND UNMAPPED
*,*           MONITOR FOR DEVICE.  NOTE HOWEVER NEITHER OF THESE MODES
*,*           COMMUNICATE DIRECTLY WITH THE OTHER.
*,*
*,*
*,*      METHOD:             STANDARD TECHNIQUES OF CP-V DCB I/O AND
*,*           SYMBIONT FILE HANDLING ARE USED WHERE POSSIBLE.  TECHNIQUES
*,*           PECULIAR TO THIS MODULE ARE DESCRIBED HEREIN.
*,*
*,*           SIGNIFICANT FUNCTIONS HEREIN ARE:
*,*
*,*                COOP      I/O COOPERATIVE,
*,*                T:BTSCHED 'PART' CONTROLS OR DATA CHANGED-SEE IF
*,*                          MULTI-BATCH SCHEDULE IS NEEDED
*,*                SGC       FAMILY OF SUBRRUTINES FOR MANAGEING THE
*,*                          SYMBIONT GHOST COMMUNICATION QUEUE.
*,*
*,*
*,*      REFERENCE:          MODULE IORT CONTAINS STANDARD DCB HANDLING
*,*           DESCRIPTIONS. MODULES OUTSYM AND RBBAT CONTAIN SYMBIONT
*,*           FILE HANDLING DESCRIPTIONS.
*,*
*D*
*,*           NOTE: THE READER MAY DISCOVER AT VARIOUS POINTS ONE-LINE
*,*             MINI DETAIL COMMENTS.  WHEN FOLLOWING   A LONG COMPLEX
*,*             FUNCTION THIS SHORTHAND SCRATCHING HAS SAVED MANY AN
*,*             EXTRA LISTING FETCH.  IT IS HOWEVER SCRATCH AND NOT GOSPEL.
*,*             THE KEY TO THE CODE, IF NOT OBVIOUS, IS
*,*           | L - LINK | U - USED OR VOLATILE | I - INPUT | O - OUTPUT.
*,*
*,*
         DEF      COOP:             *MODULE BASE DEFED FOR PATCHING
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              *LOGICAL DEVICE COOPERATIVE MAIN
*,*                                 * ROUTINE, CALLED BETWEEN WRTD AND
*,*                                 * MODULE IOQ.
         DEF      COOPSZ            * SIZE OF COOP MODULE
         DEF      COOPIO            * LOCATION DEFED 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      EQU      8
R8       EQU      8
SR2      EQU      9
R9       EQU      9
SR3      EQU      10
R10      EQU      10
SR4      EQU      11
R11      EQU      11
D1       EQU      12
R12      EQU      12
D2       EQU      13
R13      EQU      13
D3       EQU      14
R14      EQU      14
D4       EQU      15
R15      EQU      15
         SPACE    5
EOSB     EQU      X'40'             END-OF-SYMBIONT-BLOCK
1STDBI   EQU      4
         DEF      1STDBI            * FIRST DATA BYTE INDEX DEFED FOR OPNLD
ASNMSK   EQU      3                 MASK FOR DCB:ASN
DEVASN   EQU      3                 ASN=3 FOR STREAMS
DCBBMM   EQU      X'20000'          *DCB BIN MODE MASK
INHIB    EQU      2
CHUNK    EQU      1
OUTPUTGO EQU      X'80'
SKTOFBT  EQU      X'40'             * WRTD TOF FLAG(FOR OS).
*DO*
*D*      NAME: COOP  DETAIL
*
*        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.
         REF      J:BASE            * CAL PROCESSING TEMP AREA.
*,*                                 * SEE DETAIL FOR DESCRIPTION.
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
*FIN*
*
         SPACE    5
         REF      NB31TO0           * BASE OF (NOT BITS) TABLE
*,*                                 *(IE ~1,~2,~4,...,~1**31)./
         REF      C:CSC             * COUNTER: COUNT OF COOPERATIVE PHYSICAL
*,*                                 * IO ACCESSES (OUTPUT)
         REF      ERRLOG            * RECORDER OF SYMBIONT-COOPERATIVE
*,*                                 * INCONSISTENCIES
*
         DEF      COP08A            * COOP IO SPIN TIL DONE LOOP
         DEF      COP%RSG           * COOP RELEASE SYMBIONT GRANULE
*,*                                 * ROUTINE
         DEF      COP20B            * COOP DISC FILE IO ROUTINE
*,*                                           * USED BY OPNLD AND SUPCLS
         DEF      COPGSG            * COOP GET SYMBIONT GRANULE ROUTINE
*,*                                 * USED AT OPEN AND SUPER-CLOSE BY OPNLD
         DEF      COPOLDI           * COMMON OPNLD CALLING SUBR(INTERNAL)
*,*                                 * SAVES REGS AND CALLS OPNLD OVERLAY
        SREF      H%CMP             * HASPIO COMPRESSORROUTINE.
*,*                                    ]
         REF      Y04               * FLAGS HASP BIT(INPUT)
         REF      Y2                * =X'20000000' (INPUT) CONTEXT BLOCK
*,*                                 * OPEN FLAG.
         REF      Y0008             * =X'00080000' OCP BIT IN SCDEVTYP
         REF      M24               * =X'00FFFFFF'
*,*                                 * GENERAL ADDRESS MASK
         REF      M17               *=X'0001FFFF'
*,*                                 * VIRTUAL ONLY ADDRESS MASK
         REF      Y8                * =X'80000000'
*,*                                 * SCDEVTYP INPUT OR OUTPUT FLAG
         REF      S:MBSF            * MUL BATCH SCHEDULE FLAG
*,*                                 *(INPUT) IF SET WAKEUP MBS/RBBAT
         REF      SGT               * SYMB GRANS AT TRUNC
*,*                                 * (INPUT) USED BY COP%RSG
         REF      E:NSYMD           * EVENT : NO SYMB DISC
         REF      T:REG             * SCHED REP EVENT & GIVE UP
         REF      MULSEG            *  BACK TO MUL FOR COPOPNLD
*,*                                 * NAME OF SEG IN WHICH OPNLD RESIDES
         REF      ALLOREG           * REG ON SQFAC(AWAIT ALLOCAT STACK CLR)
*,*                                 * RESIDENT ALLOCAT SCHEDULAR
         REF      UB:MF             * USERS MASTER IO FUNCTION(MOTHERFUNN)
         REF      UB:US             * USERS CURRENT STATE
         REF      SIOW              * IO WAIT STATE
*
*
         REF      RMB               * RELEASE MONITOR BUFFER ROUTINE
         REF      RSG               * RELEASE SYMB GRANULE ROUTINE
         DEF      COPEA00           * END ACTION ADDRESS OF COOP IO
*,*                                 * ROUTINE ENTERED UNMAPPED
         DEF      COPGSB            * COOP GET SYMB BUF
         REF      NEWQNWM           * NO WAIT MAPPED,W E/A
*,*                                 * ROUTINE USED FOR ALL COOP PHYSICAL IO
         REF      J:USCDX           * JIT USED CNTXT DATA EXTERNAL
*,*                                 *(INPUT/OUTPUT) POINTS AT COOP VIRT PAGES
         REF      Y01               * =X'01000000'
*,*                                 * VALUE USED TO INC/TEST BYTE 0
         REF      Y4                * =X'40000000'
*,*                                 * SCDEVTYP 'RERUN' FLAG, DONT DEL GRANS
         REF      Y00FF             * MASK
         REF      JCO2VPA           * JIT POINTER TO 2ND WINDOW
*,*                                 * USED AS AN 'MM' ARGUMENT
         REF      T:MBUF            * MM ROUTINE: MAP A BUFFER IN WINDOW
         REF      MSRLP34           * MON SRVC LP (TAB EXPAND)
         REF      SCDBI             * SYMB CNTXT DATA BYTE INDEX
*,*                                 * (INPUT/OUTPUT) CURRENT POS IN BUFFER
         REF      SCCDA             *  SYMB CNTXT CUR D. A.
         REF      SCBLDA            *  ''   ''   BLINK D. A.
         REF      SCFBUF            *  ''   ''   FILE BUF ADDR
         REF      SCFQARGS          *  ''   ''   FILE Q ARGUMENTS
         REF      TIME              *TIME-OF-DAY
         REF      QUEUE             * (IO SYST) QUEUE (AN IO REQ)
*,*                                 * FOR ALL NON-LOGICAL STREAM IO
         REF      CHKDA             * CHECK DISC ADDR ROUTINE
         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
*,*                                 * IN JIT.
         REF      SH:LNM            TEXT STREAM ID'S
         REF      SL:COMAXG         # OF DISC BLOCKS PER COMODE FILE
         REF      UH:FLG2           X'80' BIT SET FOR OUTPUT GO KEYIN
         DEF      INHIB             SCCOMFLG BIT TO INHIBIT BANNER
         DEF      OUTPUTGO          EQU. X'80', OUTPUT GO BIT IN UH:FLG2
         REF      SCGCO             * CNTXT DISP GRAN COUNTER
*,*                                    ]
         REF      SCPCO             * CNTXT DISP  PAGE COUNTER
*,*                                    ]
         REF      SCRCO             * CNTXT DISP  RECORD COUNTER
*,*                                    ]
         REF      SCMAXR            * CNTXT DISP  MAXIMUM RECORD
*,*                                    ]
         REF      SCMINR            * CNTXT DISP  MINIMUM RECORD
*,*                                    ]
         REF      SCBSIZ            * CNTXT DISP  BLOCK SIZE
*,*                                    ]
         REF      SCMISC            * CNTXT DISP  #COPIES.
         REF      SCSVDGI           * CNTXT DISP  RBID.
         REF      SCCUN             * CNTXT DISP  USER NUMBER
*,*                                    ]
         REF      SCRPDA            * CNTXT DISP  REL PREV DA
         REF      SCCOMID           *  CNTXT. DISP COMODE ID
         REF      SCCOMFLG          *  CNTXT. DISP FLAGS FOR COMODE
         DEF      SGCQA3            * ENTRY POINT FOR LINKING COMBUF
*,*                                   ON USE CHAIN ( DISABLED )
         REF      S:QUIET           * MONITOR FLAG FOR QUIESCIENT
*,*                                   MODE ( NO FREE COM BUFFS )
*
*K*      COOP-CONTEXT-BLOCK            A CONTROL BLOCK IN THE USER'S
*,*                SWAP IMAGE USED BY COOP ROUTINES.  IT DEFINES AND
*,*                DESCRIBES TE DEVICE BEING COOPERATIVELY SIMULATED,
*,*                CONTROLS AND DIRECTS THE DATA MANIPULATION SERVICE,
*,*                AND DEFINES THE LOGICAL-STREAM-FILE.
*,*
*K*      COOP-DATA-BUFFER              A HALF PAGE BLOCK (RESIDES WITH
*,*                ANOTHER COOP-DATA-BUFFER)  ACCESSED THROUGH A
*,*                COOP-WINDOW-PAGE AND CONTAINING THE LOGICAL-STREAM-FILE
*,*                PHYSICAL RECORDS FROM/TO WHICH UNIT DATA RECORDS
*,*                ARE PROCESSED.
*,*
*K*      COOP-WINDOW-PAGE              THE VIRTUAL LOCATION THROUGH WHICH
*,*                ALL COOP-DATA-BUFFERS ARE ACCESSED USING THE WINDEX
*,*                TECHNIQUE(AH, YES, I SEE IT CLEARLY NOW).  WINDEX
*,*                ALLOWS THE USERS PHYSICAL SIZE TO EXCEED HIS VIRTUAL
*,*                SPACE BY PROVIDING THE MM,SWAPPER SERVICE WHEREIN
*,*                BUFFER PAGES ARE SWAPPED USING VIRTUAL TABLE SPACE
*,*                BELOW JIT AND MAPPED IN THE WINDOW AS NEEDED.  USAGE
*,*                OF THE 1ST TWO STREAMS (SAY CR & LP) INCURS MINIMAL
*,*                OVERHEAD BECAUSE WINDOWING IS DONE ONLY WHEN NEEDED.
*,*
*K*      LOGICAL-DEVICE-FILE  OR LOGICAL-STREAM-FILE
*,*                    THE DISC FILE CONTAINING OR TO CONTAIN THE UNIT
*,*                RECORD DATA.  THE TERM OR A VARIANT IS OFT USED TO
*,*                DESCRIBE THE ENTIRE COOPERATIVE PROCESS OR TO GIVE
*,*                IDENTITY TO THE ABSTRACTION MANIPULATED BY THE USER
*,*                THROUGH LDEV.
*,*
*
*
*F*      NAME:     COOP
*,*
*,*      PURPOSE:            TO BLOCK|DEBLOCK THE LOGICAL-STREAM-FILE AS
*,*           DIRECTED BY THE USER VIA LDEV(OR DEFAULTS) AND THE
*,*           COOP-CONTEXT-BLOCK,
*,*                ALSO, TO READ|WRITE NO-WAIT THE BLOCKS TO|FROM
*,*           SECONDARY STORAGE.
*,*
*,*
*,*      DESCRIPTION:        ALL DEVICE DCB(ASN=3) CAL1'S PASS THROUGH
*,*           COOP IF PSEUDO I/O IS REQUIRED.  E.G.
*,*      CAL1,1    M:READ         (FPT CODE =    .10  )
*,*                M:WRITE                       .11
*,*                M:DEVICE  (PAGE)              .04
*,*                M:WEOF                        .02
*,*
*,*      CAL1,2    M:TYPE                        .02
*,*                M:PRINT                       .01
*,*
*,*      CAL1,3    M:SNAP    -> M:WRITE
*,*                M:SNAPC
*,*
*,*           MAJOR SECTIONS ARE:
*,*
*,*      COP08     OPEN STREAM CHECKING
*,*      COP10     LOGICAL RECORD READ
*,*      COP09       ''      ''   WRITE
*,*                (HASP COMPRESSION IS DONE AT COOP TIME)
*,*      COP15     DCB MANIPULATION
*,*      COP16     READ FILE
*,*      COPGSB    WINDOW THE DATA BUFFER
*,*      COPOLDI   LINK TO OPNLD TO OPEN A CLOSED STREAM
*,*      COPEA00   FILE END-ACTION(UNMAPPED AND ASYNCHRONOUS)
*,*      COP%RSG   RELEASE INPUT FILE DISC GRANULES
*,*      COPERLG   TO ERRLOG FOR COOP FILE INCONSISTENCY
*,*      COPGSG    ACQUIRE OUTPUT STREAM FILE STORAGE
*,*
         PAGE
*DO*
*D*      NAME: COOP  DETAIL
*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
*FIN*
         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      %
*        DCB IS POINTING TO NONEXISTENT CNTXT AND IS OPEN
         SUA      X'2D',2           * BAD COPTAB
*S*      SCREECH: 2D-02
*,*
*,*      REPORTED BY:  COOP
*,*
*,*      TYPE:    SINGLE USER ABORT
*,*
*,*      MESSAGE: COOP CONTEXT POINTERS BAD
*,*
*,*      REGISTERS:
*,*               R3 CONTAINS THE CLOSED CONTEXT BLOCK POINTER
*,*                   (CLOSED BECAUSE Y2 ISNT SET)
*,*               R6 CONTAINS THE DCB WHICH POINTS AT THE CONTEXT
*,*               SR1(R8) CONTAINS THE DCB AND MORE IMPORTANT IN
*,*                   BYTE 0 CONTAINS THE FUNCTION CODE OF THE
*,*                   ROUTINE THAT LET THIS CONTEXT SNEAK THROUGH
*,*                   WITHOUT OPENING IT.
*,*               R11 CONTAINS THE COOP RETURN(USUALLY IOSPRTN)
*,*               R7  MAY CONTAIN THE ORIGINAL OFFENDING FPT.
*,*
*,*        ONLY THE USER WHO ISSUED THE CAL IS AFFECTED.
*,*
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
*DO*     COP08
*D*      NAME:  COOP DETAIL (COP08)
*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.
*
*FIN*
         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      %
         LI,R1    CHUNK
         CW,R1    SCCOMFLG,R3       TIME TO CHUNK THIS FILE?
         BAZ      COP09A            NOPE
         LC       J:TCBP            TOF????
         BCR,4    COP09A            NO, NOT YET. WE'LL WAIT FOR ONE.
*                                   HIT NEXT TOF, NOW FOR THE FUN PART.
         LI,R0    0
         STS,R0   SCCOMFLG,R3       RESET CHUNK FLAG
         BAL,R1   COPPSH            SAVE ALL ENTRY INFO
         LCI      4
         LM,R4    J:TDCB
         PSM,R4   TSTACK
         LW,R5    0,R3              STREAM NO.
         LH,R5    SH:LNM,R5         TEXT STREAM-ID
         LW,R4    LDEVFPT1          WD1 OF LDEV FPT
         PUSH     2,R4
         LW,7     TSTACK
         AI,7     -1                POINT TO WD1 OF FPT
         OVERLAY  MULSEG,4          GO CLOSE STREAM W/ ASAVE
         BUMP     -2,R1             CLEAR FPT FROM TSTACK
         PULL     4,R4              GET TEMP DCB INFO BACK
         LCI      4
         STM,R4   J:TDCB            ...INTO USER'S JIT
         BAL,R1   COPPLL            GET BACK REGISTERS
         PULL     SR4               PULL RETURN ADDR.
         B        COOP              TRY IT AGAIN
COP09A   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
         LW,D1    SCCOMFLG,R3
         CI,D1    X'40'             IS IT FILL?
         BAZ      COP09A1           ---> NO.
         REF      RECTRAN           * MOVE RCD FROM USER TO MON BUFF.
         STW,R4   J:TDCB              SAVE DCB ADDRESS.
         LW,D4    QBUF,R4             D4= SOURCE BUFFER.
         LW,D3    R1                  D3= DESTINATION BUFFER.
         LW,R1    BLK,R4
         SLS,R1   -17                 R1= SOURCE SIZE+BTD.
         LI,R4    0                   R4= SOURCE BTD.
         LW,R3    SCDBI,R3            R3= DESTINATION BTD.
         LI,R2    X'400'              R2= DESTINATION SIZE+BTD MAX.
         BAL,SR4  RECTRAN             * MOVE IT.
         B        COP09H            ---> DONE WITH FILL.
COP09A1  EQU      %
         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      %+2               * IS .LT. MAXREC
         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           * TABLE OF LEGAL BUFFER ADDRESSES
         REF      MPOOLIM           * INDEX TO MPOOL ENTRY IN BUFLIMS
         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              * =X'00400000' TRICKY BLANK FOR
*,*                                 * FILLING BUFFERS(BLANK PAD)
         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             * RECTRAN ENTRY 2 FOR DCB ORIENTED
*,*                                 * CORE-TO-CORE MOVE (ROUTINE IN IORT)
         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              *=X'00800000' DCB:MONITOR BUFF GIVEN
*,*                                 * BIT (SET SAYS MPOOL ALLOCATED)
         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    6                 END+1+SKSKSKSK+VFC
         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           * WRTD SUBROUTINE TO FORM AN IMAGE IN
*,*                                 * AN MPOOL OF THE USER RECORD
         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
         REF      M3                * =X'00000007' SKIP COUNT FIELD
         AND,D2   M3                * ERASE THE SKIP BYTE FLAGS
         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    D4                *     AND CHANGE IT TO BCD RCC
         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      %
         LW,D2    SCCOMFLG,R3
         CI,D2    X'20'             IS IT SPILL?
         BAZ      COP12B            ---> NO.
         AI,D1    3                   YES.
         AW,D1    D2                BUMP SYMBIONT BC AND
         LW,R2    SCDBI,R3          BACK OFF SYMB BUFFER INDEX.
COP12B   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      %
         LW,R4    SR1               CALLING DCB ADDRESS.
         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
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
         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  COPERLG           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.
*S*      SCREECH: 2D-01
*,*
*,*      REPORTED BY:    COOP
*,*
*,*      TYPE:    FULL RECOVERY
*,*
*,*      MESSAGE: COOP FILE DEVICE IS DOWN
*,*
*,*      REGISTERS:
*,*               MAINLY THOSE RETURNED BY IOQ WHEN A DOWN DEVICE
*,*               IS DETECTED. HOWEVER THE COOP IOQ ARGUMENTS SHOULD
*,*               STILL BE INTACT AS FOLLOWS:
*,*               R12: BYTE 3 SHOULD BE THE DCTX OF THE FILE DEVICE.
*,*               R15: IF NOT CLOBBERED BY RECOVERY IS THE DISC ADDR.
*,*               R11: 'COOPIO' THE COOP CALL TO NEWQNWM
*,*               R5: THE VIRTUAL ADDRESS OF THE CONTEXT BLOCK.
*,*
*,*               THERE IS NO POINT IN RUNNING THE SYSTEM IF IT
*,*               IS RUNNING USERS AND DISCARDING THEIR OUTPUT OR
*,*               WORSE IF THE DEVICE DOWN FLAGS HAVE BEEN BOMBED.
*,*
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
*DO*   COP19
*D*      NAME:  COOP DETAIL (COP19)
*
*
*        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.
*
*FIN*
         REF      SCFPC             * AN EMPTY HOLE IN THE CNTXT
         LW,D2    SCGCO,R3          * POSITION IN THE FILE OF THE BLOCK
         SLS,D2   +24               * ...MOVED TO BYTE 0
         OR,D2    SCFPC,R3          *  MERGE IN HASH STUFF
         AI,D1    -1                * BACK UP TO WORD 254
         STW,D2   *D1,R1            * STASH A HASH
* WORD 254 OF BLOCK:   BLOCK(MOD 255), HASH CODE      8,24
*                 THE HASH CODE IS COMPOSED OF THE FOLLOWING BYTES
*        ACCOUNT(8BYTES),STREAM NUMBER,SYSID(2BYTES)
*        SUMMED WITH A WEIGHT OF 2 TO THE 6TH FOR EACH POSITION,
*        THEN INTEGER DIVIDED WITH THE LARGE PRIME 16777213 TO
*        REPOSITION THE MOST SIGNIFICANT BITS INTO BYTES 1,2,3.
*
*
         B        COP17B            GO TO WRITE DISC
COP20C   LI,R0    1STDBI            RESET DATA INDEX
         STW,R0   SCDBI,R3
         MTW,0    SCCOMID,R3        CONCURRENT OUTPUT MODE
         BNEZ     CHKGRANS          YES
         LW,R1    S:CUN
         LH,R1    UH:FLG2,R1
         CI,R1    OUTPUTGO          OPERATOR 'OUTPUT GO' KEYIN?
         BAZ      COP18             NO
         LW,R1    Y00FF
         AND,R1   SCSVDGI,R3          COMODE ILLEGAL FOR REMOTE.
         BNEZ     COP18
         LI,R1    X'FF'
         AND,R1   SCMISC,R3
         CI,R1    1                 COMODE ILLEGAL FOR NOT 1 COPY.
         BNE      COP18
CHKGRANS EQU      %
         LW,R1    SL:COMAXG
         CW,R1    SCGCO,R3          BIG ENOUGH 'CHUNK' YET?
         BG       COP18             NO
         LI,R1    CHUNK+INHIB
         STS,R1   SCCOMFLG,R3         SET INHIB & CHUNK FLAGS.
         B        COP18
*
LDEVFPT1 GEN,4,24,4  8,1,0          M:LDEV (ASAVE) FPT FLAGS
         DEF      HASHPRIM          * =16777213 (RESIDES HERE BECAUSE
*,*                                 * COOP IS ONE-TO-ONE WITH EVERYONE
HASHPRIM DATA     16777213          * A LARGE PRIME FOR HASHING.
*
         PAGE
*F*      NAME:    COPGSB
*F*      PURPOSE: MAP COOP STREAM BUFFER PAGE INTO COOP WINDOW #2.
*D*      NAME:    COPGSB
*D*      REGISTERS: 3,5,6,8,9,11 PRESERVED.
*D*      CALL:    BAL,SR4 COPGSB.
*D*      INTERFACE: T:MBUF.
*D*      ENVIRONMENT: MASTER MAPPED.
*D*      INPUT:   R3=> COOP CONTEXT BLOCK.
*D*      DESCRIPTION: SCFBUF WORD IN C.B. HAS SPARE BUFFER# IN BITS
*D*               0-7. THIS BUFFER IS MAPPED INTO WINDOW #2.
COPGSB   EQU      %
         LW,SR3   SCFBUF,R3         SR3= BUFX, WABUF.  8,24
         BNEZ     COPMAP            ---> BUFFER EXISTS.
         SUA      X'2D',0           ***> NO BUFFER IS BAD BAD NEWS.
*S*      SCREECH:I2D-00.
*S*      REPORTED BY: COOP.
*S*      MESSAGE: COOP DATA BUFFERS LOST.
*S*      TYPE:    SINGLE USER ABORT.
*S*      REGISTERS: R3 ADDRESS OF CONTEXT BLOCK WITHOUT A BUFFER.
*S*               SR4(11) CALLER'S LINK REGISTER.
*S*               R6 OR R4  M A Y  CONTAIN THE DCB ADDRESS.
*S*               R7  M A Y  CONTAIN THE FPT ADDRESS.
*S*      REMARKS: WHEN THE STREAM WAS OPENED WE ALLOCATED A BUFFER,
*S*               BUT SCFBUF ADDRESS IN C.B. IS ZERO NOW.
COPMAP   EQU      %
         LB,SR3   SR3               SR3= BUFX OF PG TO BE MAPPED.
         LI,D3    JCO2VPA           D3 = VIRTUAL PG TO MAP IT TO.
         PUSH     SR4
         PUSH     R3
         BAL,R2   T:MBUF              MAP BUFFER TO COOP WINDOW #2.
         PULL     R3
         PULL     SR4
         B        *SR4              ---> RETURN TO CALLER.
         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              *
*DO*   COPOLDI
*D*      NAME:  COOP DETAIL (COPOLDI)
*
*        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***
*FIN*
*
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
*COOPERATIVE ERROR LOG ROUTINE.
*(R3)= CONTEXT-DATA BLOCK ADDRESS
*        BAL,SR4  COPERLG
COPERLG  EQU      %
         PUSH     5,R2
         LW,R2    0,R3              * STREAM NUMBER
         SLS,R2   +8                *
         OR,R2    S:CUN             * AND USER NUMBER
         LI,R4    X'1B03'
         STH,R4   R2                * W0= 1B, 03, STREAM#, USER#.
         LW,R4    SCCDA,R3          * W2= DISK ADDRESS BAD.
         LI,R6    R2                *R6= ADDR OF ERR MESSAGE.
         BAL,R5   ERRLOG
         PULL     5,R2
         B        *SR4
         PAGE
*COOPERATIVE GET DISC GRANULE ROUTINE
*(R3)=CONTEXT-DATA BLOCK ADDRESS
*        BAL,SR4  COPGSG
         REF      GSG               * GET SYMBIONT FILE GRANULE ROUTINE
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 .
*
*
*
*
*
*F*      NAME:     T:BTSCHED
*,*
*,*      PURPOSE:       CALLED TO INITIATE RBBAT TO SCHEDULE A BATCH JOB
*,*           IF
*,*                A JOB HAS BEEN ADDED,
*,*                !S KEYIN OCCURRED,
*,*                A JOB HAS EXITED,
*,*                CONTROL MODIFIED BATCH SCHEDULING PARAMETERS.
*,*
*,*      REFERENCES:         FOR ADDITIONAL INFORMATION SEE
*,*           MODULE KEYN FOR !S, MODULE SCHED FOR JOB EXIT, AND
*,*           PROCESSOR CONTROL FOR TABLE MODIFICATION. ALSO THE
*,*           SYSTEM MANAGEMENT REFERENCE MANUAL FOR CONTROL
*,*           PARAMETERS.
*,*
         DEF      T:BTSCHED         * BATCH SCHEDULE ROUTINE (CALL MBSIN RBBAT)
         REF      PL:LK             * PARTITION LIMIT LOCK CELL USED BY
*,*                                 * CONTROL TO BLOCK T:BTSCHED
         REF      S:BUAIS           * BATCH USERS ALLOWED IN SYSTEM
*,*                                 * INPUT(NOT MODIFIED)
         REF      S:BUIS            * BATCH USERS IN SYSTEM CURRENTLY (INPUT)
         REF      S:BFIS            * BATCH FILES(FED) IN SYSTEM (INPUT)
         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                                                      .
*F*      NAME:     SGC FAMILY OF SUBROUTINES
*,*                SGCQ  -  SGCQ2  -  SGCR  -  SGC:NCB
*,*
*,*      PURPOSE:       THE RBBAT GHOST MANAGES THE 'BATCH QUEUE'
*,*           OF INPUT AND OUTPUT, DATA AND JOB FILES.  THE SYMBIONT
*,*           GHOST COMMUNICATION ROUTINES MANAGE ALL MONITOR
*,*           TRANSACTIONS WITH RBBAT.  IN PARTICULAR
*,*
*,*                SGCQ      QUEUE'S UP TO 4 WORDS OF SGC ARGUMENTS
*,*
*,*                SGCQ2     QUEUE'S UP TO 8 WORDS OF SGC ARGUMENTS
*,*
*,*                SGCR      RELEASES A RBBAT CALL BUFFER
*,*
*,*                SGC:NCB   PARKS A USER WHEN RBBAT COMMUNICATION
*,*                          IS SATURATED. THIS IS DONE VIA E:NSYMF,
*,*                          LATER RBBAT OR SGCR WILL REPORT E:SYMF.
*,*
*,*
*,*      METHOD:             THE SYMBIONT GHOST COMMUNICATION BUFFER
*,*           ,SGCBUF, IN MODULE COMBAT IS A SINGLE LINK THREADED LIST
*,*           OF ENTRIES CONTAINING RBBAT INFORMATION. A WORD, SGCHD,
*,*           CONTAINS THE HEAD AND TAIL OF THE ENTRY CHAIN AND A HEAD
*,*           FOR THE FREE BUFFER CHAIN.  LINKS ARE WORD OFFSETS FROM
*,*           SGCBUF TO THE NEXT ENTRY AND ARE ALWAYS IN BYTE 0 OF AN
*,*           ENTRY.
*,*
*,*
*,*      0   7 8 15 1623 24 31
*,*      ---------------------
*,*      |FREH|Q TL|    |Q HD|     SGCHD      *  FREE HEAD , RBBAT Q TAIL & HEAD
*,*      ---------------------                *
*,*                                           *
*,*      0   7              31                *
*,*      ---------------------                * ENTRIES ARE 4 WORDS LONG
*,*      |LINK|    |    |    |    SGCBUF+1    *
*,*      ---------------------                * BYTE 0 IS RESERVED FOR THE LINK
*,*      |    |    |    |    |                *
*,*      ---------------------                *
*,*      |    |    |    |    |                * ENTRY NUMBER FORMULA IS
*,*      ---------------------                *
*,*      |    |    |    |    |                * N = ( I - 1 ) / 4
*,*      ---------------------                *
*,*      |LINK|    |    |    |    SGCBUF+5    *OBVIOUSLY INDEX FORMULA IS
*,*      ---------------------                *
*,*      |    |    |    |    |                *  I = 4 * N + 1
*,*      ---------------------                *
*,*      |    |    |    |    |                * REMAINING 15 BYTES ARE RBBAT INF
*,*      ---------------------                *
*,*      |    |    |    |    |                *
*,*      ---------------------                *
*,*           .                               *
*,*           .                               *
*,*           .                               *
*,*
*,*
*,*
*,*           BEFORE CALLING SGCQ CALLER MUST HAVE TESTED WHETHER
*,*           RBBAT REALLY HAS ANY FILE SLOTS(BL:IFS|BL:OFS).
*,*           THIS ALLOWS DUAL USAGE OF S:SYMF WHICH MEANS EITHER
*,*           RBBAT HAS NO SLOTS OR RBBAT COMMUNICATION IS MOMENT-
*,*           ARILY SATURATED.  TO ALLOW RE-ENTRANCY(INTERRUPT
*,*           ROUTINES MAY INTERRUPT USERS) THE REAL PARK FOR RBBAT
*,*           SYMFILE SLOTS GONE MUST BE REMADE UPON RE-ACTIVATION.
*,*           THUS RBBAT MAY REPORT THE EVENT FOR EITHER REASON, AND
*,*           SO MAY SGCR AND FILE SLOT POEPLE WILL REQUEUE.
*,*           ( USERS REQUEUE VIA E:NSYMF-SYMBIONTS VIA SAQNSERT).
*,*           IF SGCBUF'S ARE AVAILABLE ARGUMENTS ARE STORED AND
*,*           RBBAT IS AWAKENED.
*,*
*,*
*
*        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 SETS OF ARGUMENTS
         DEF      SGCQ         * SYM GHO CALL QUEUE AND WAKEUP RBBAT
         DEF      SGCR              * SYM GHO COMBUF RELEASE
         DEF      SGCRA             * SYM GHO COMBUF REL (ALTERNATE)
         DEF      @SGCBUF           * BUFFER POINTER(AND ADDER)
         DEF      SGC:NCB           * SYM GHO COM: NO COMM BUF ROUTINE
         REF      E:NSYMF           * EVENT: NO SYM FILES
         REF      NOPGFC            * NO-OP GHOST FUNCTION CODE
         REF      T:GJOBSTRT        * GHO JOB START ROUTINE
         REF      SGCHD             * SYM GHO CALL HEAD PTR
*,*                                 * (INPUT/OUTPUT) MANAGED BY SGC ROUTINES
         REF      SGCBUF            * SYM GHO CALL BUFFER
*,*                                 * DATA AREA FOR 4-WORD RBBAT ARGS
*
*
*,*                                    ]
         REF      E:SYMF            * EVENT: SYMBIONT FILE SLOT AVAIL
         REF      T:RUE             * REPORT USER EVENT
*,*                                 * ROUTINE IN SCHED
         REF      BOOTFLG           * FLAG SAYS WE ARE BOOTED SO RBBAT MAY
*,*                                 * BE AWAKENED NOW.
         REF      YFFFF             MASK FOR BUILDING SGC BUFFERS
         REF      XFFFF             MASK FOR BUILDING SGC BUFFERS
*        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   YFFFF             * MASK FOR MOVED ARGS
         AND,SR1  D1                * PULL OUT COMID(2) & JDE
         SLS,SR1  -8                * (AND MOVE IT SOME)
         AND,D1   XFFFF             * 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
*
         LI,R7    X'FF'
         STS,R6   SGCHD             NO TL MEANS NO HD ( SAVE FREE TL )
         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
*
         BNEZ     0,R4              * (SGCQA3 NORMALLY)
         LI,R1    2                 * TAIL BYTE
         STB,R7   SGCHD,R1          * ZERO TAIL IF HEAD ZERO
         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   *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    EQU      %
         PSW,R4   TSTACK
         LI,R4    0
         STB,R4   *D1               NEW TAIL.
         LI,R4    2                 INDEX TO TAIL OF FREE CHAIN.
         DISABLE                    -----IN HIBIT-----
         LB,R0    SGCHD,R4          FREE TAIL
         AI,R0    SGCBUF            LOC OF BUFFER
         STB,R1   *R0               FLINK REL BUF
         STB,R1   SGCHD,R4          WHICH BECOMES NEW TAIL
         ENABLE                     -----UN INHIBIT-----
         PLW,R4   TSTACK
         AI,R0    -SGCBUF           JUST RELEASED LAST BUF
         BNEZ     0,R4              NO-THERE ARE PLENTY
*                                   YES- MAYBE NSYMF
         MTW,0    S:QUIET           QUIESCIENT MODE ?
         BNEZ     0,R4              YES.
         STB,R0   SGCHD             SET UP HEAD ( DONT WANT ZERO HD )
         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             * SCHED RESOURCE QUE (INPUT)
         REF      R:SYMF            * SCHED RESOURCE STATE FOR
*,*                                 * NO SYMBIONT FILE SLOTS
         REF      SIOMF             * STATE FOR IO GREATER THAN MOTHERFUN
*,*                                 * (INPUT) USERS PARKED FOR TOO MUCH IO
         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

