*M* ECBBLK GET/FREE BLOCKS FOR USE IN ECB WAITING AND POSTING.
         DEF      ECBBLK:           XDELTA LABEL FOR ECBBLK MODULE.
ECBBLK:  EQU      %
*
*P*      NAME:    ECBBLK
*P*      PURPOSE: TO GET OR FREE A FOUR-WORD BLOCK FOR USE BY ECB
*P*               WAITING AND POSTING LOGIC.
*P*  DESCRIPTION: ECBBLK USES THE COC BUFFER POOL AS A SOURCE AND
*P*               SINK FOR FOUR-WORD BLOCKS.
*P*               THE CALLER EXPECTS OR SUPPLIES THE ADDRESS OF A
*P*               FOUR-WORD BLOCK.
*P*               ECBBLK ZEROES ALL FOUR WORDS OF BLOCKS WHICH IT
*P*               GETS.
*
         SYSTEM   UTS
         PCC      0
*
*
*
         DEF      ECBGBLK     ENTRY TO GET A FOUR-WORD ECB BLOCK.
         DEF      ECBFBLK     ENTRY TO FREE A FOUR-WORD ECB BLOCK.
*
         REF      CO:INTFL    INPUT BITS 0-15 NONZERO IF COC ACTIVE
         REF      COCBUF      BASE ADDRESS OF COC BUFFER AREA
         REF      COCHPB      INPUT & OUTPUT HEAD OF FREE COC BUFS
         REF      ECBFRCHN    INPUT & OUTPUT HEAD OF SPECIAL CHAIN
         REF      HRBA        = SIZE OF COC BUFFER AREA
         PAGE
*  REGISTER EQUATES
R1       EQU      1
R2       EQU      2
*
*        TABLE SYMBOLS FOR ECB BLOCK
*
ECBBLENG EQU      4           LENGTH OF ECB BLOCK
*
*S*      SCREECH CODE: 10-01.
*S*      REPORTED BY:  ECBBLK.
*S*      MESSAGE: BAD COC BUFFER POOL (ECB GET OR FREE).
*S*      REGISTERS:  R1 RETURN ADDRESS TO CALLER.
*S*                  R2 BAD ADDRESS.  ON GET, COCHPB WAS BAD;
*S*                                   ON FREE, R2 IS CALLER-SUPPLIED.
ECBSCREECH  SCREECH  X'10',1
         PAGE
*F*      NAME:    ECBGBLK
*F*      PURPOSE: TO GET A FOUR-WORD BLOCK FOR ECB-POSTING USE.
*F*  DESCRIPTION: ECBGBLK GETS A FOUR-WORD BLOCK FROM THE COC BUFFER
*F*               POOL HEADED BY COCHPB, CLEARS THE BLOCK TO ALL
*F*               ZERO, AND RETURNS ITS ADDRESS (OR ZERO IF NO
*F*               BUFFERS ARE AVAILABLE) TO THE CALLER.
*
*D*      NAME:    ECBGBLK
*D*
*D*      REGISTERS: R1 LINK REGISTER (PRESERVED).
*D*                 R2 RETURNS WA(BLOCK) OR ZERO.
*D*               ALL OTHER REGISTERS PRESERVED.
*D*      CALL:    BAL,R1 ECBGBLK
*D*      ENVIRONMENT: MASTER MAPPED OR UNMAPPED.
*D*               RETURNS ENABLED.
*D*      INPUT:   COCHPB => FREE BUFFER CHAIN.
*D*      OUTPUT:  COCHPB UPDATED.
*D*               R2 = WA(BUFFER GOTTEN).  = 0 IF NO BUFFERS AVAIL.
*D*               CC SET NONZERO OR ZERO ACCORDING TO R2.
*D*
ECBGBLK  EQU      %
         DISABLE                    ***   INHIBIT INTERRUPTS   ***
         LW,R2    COCHPB            GET HEAD OF FREE BLOCK CHAIN.
         BNEZ     ECBG010           ---> GOT A FREE BLOCK.
         B        ECBG020           ---> NO FREE BLOCKS.  EXIT.
*
ECBG010  AI,R2    COCBUF            CONVERT INDEX TO TRUE ADDRESS.
         CLM,R2   ECBF900           IS BLOCK ADDRESS GOOD...
         BCS,9    ECBSCREECH        ---> NO. SCREECH.
         XW,R1    0,R2              GET FLINK & SAVE RETURN REGISTER.
         STW,R1   COCHPB            UPDATE CHAIN HEAD WITH FLINK.
         LI,R1    0                 CLEAR THE BLOCK TO ZERO:
I        DO       ECBBLENG-1          FIRST CLEAR WORDS 1...N.
         STW,R1   I,R2
         FIN
         XW,R1    0,R2              THEN CLEAR W0 & RESTORE RETURN.
ECBG020  ENABLE                     ***   ALLOW INTERRUPTS   ***
         AI,R2    0                 SET CC FOR BLOCK GOTTEN OR NOT.
         B        0,R1              ---> RETURN TO CALLER.
         PAGE
*F*      NAME:    ECBFBLK
*F*      PURPOSE: TO GIVE BACK A FOUR-WORD BLOCK USED BY ECB POSTING.
*F*  DESCRIPTION: ECBFBLK IS GIVEN THE ADDRESS OF A FOUR-WORD BLOCK,
*F*               WHICH IT RETURNS TO THE FREE BLOCK POOL.
*F*               THE PRIMARY POOL IS HEADED BY COCHPB.  IF COC IS
*F*               CURRENTLY BUSY, THE BLOCK IS RETURNED TO THE
*F*               ALTERNATE POOL HEADED BY ECBFRCHN.
*
*D*      NAME:    ECBFBLK
*D*
*D*      REGISTERS: R1 LINK REGISTER (PRESERVED).
*D*                 R2 INPUT WA(BLOCK) (DESTROYED).
*D*               ALL OTHER REGISTERS PRESERVED.
*D*      CALL:    BAL,R1 ECBFBLK
*D*      ENVIRONMENT: MASTER MAPPED OR UNMAPPED.
*D*               RETURNS ENABLED.
*D*      INPUT:   COCHPB => FREE BUFFER CHAIN (COC).
*D*               ECBFRCHN => ALTERNATE FREE CHAIN IF COC NOW BUSY.
*D*               CO:INTFL NONZERO IF COC NOW BUSY.
*D*               R2 = WA(BLOK TO FREE).
*D*      OUTPUT:  COCHPB OR ECBFRCHN UPDATED.
*D*
ECBFBLK  EQU      %
         CLM,R2   ECBF900           CHECK BLOCK ADDRESS FOR VALIDITY.
         BCS,9    ECBSCREECH        ---> BAD ADDRESS. SCREECH.
         AI,R2    -COCBUF           CONVERT ADDRESS TO INDEX.
         DISABLE                    ***   INHIBIT INTERRUPTS   ***
         STW,R1   COCBUF,R2         SAVE RETURN ADDR IN BLOCK.
         LW,R1    R2
         MTH,0    CO:INTFL          DID WE INTERRUPT COC...
         BEZ      ECBF020           ---> NO.
         XW,R1    ECBFRCHN          YES. CHAIN ON ECBFRCHN; COC WILL
         B        ECBF030           UNCHAIN LATER.
ECBF020  XW,R1    COCHPB            NO. CAN CHAIN DIRECTLY ON COCHPB.
ECBF030  XW,R1    COCBUF,R2         CHAIN IT & RE-GET RETURN ADDRESS.
         ENABLE                     ***   ALLOW INTERRUPTS   ***
         B        0,R1              RETURN
         BOUND    8
ECBF900  DATA     COCBUF+ECBBLENG,COCBUF+HRBA
         END

