         DEF      ECBBLK:
ECBBLK:  EQU      %
         TITLE    'ECBBLK - GET/FREE AN ECB WAIT/DO LIST BLOCK'
         PCC      0
         REF      MASKS
         SYSTEM   UTS
         REF      CO:INTFL
         REF      ECBFRCHN
         REF      COCHPB,COCBUF,HRBA
         PAGE
COCH0    EQU      X'10'
         SPACE    2
*
*        TABLE SYMBOLS FOR WAIT LIST/DO LIST ECB BLOCK
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
ECBBLENG EQU      4
ECBBECB  EQU      1
         PAGE
***********************************************************************
*                                                                     *
*        ECBBLK                                                       *
*          -GET OR FREE A WAIT LIST OR DO LIST BLOCK FOR AN ECB       *
*                                                                     *
***********************************************************************
*                                                                     *
*        ENTRY POINT                                                  *
*          ECBGBLK - GET A BLOCK                                      *
*                                                                     *
*        INPUT                                                        *
*          R1  - RETURN ADDRESS                                       *
*                                                                     *
*        OUTPUT                                                       *
*          R2  - NON-ZERO, WORD ADDRESS OF ALLOCATED BLOCK            *
*                ZERO, NO BLOCK AVAILABLE                             *
*          CC  - INDICATE WHETHER R2 IS ZERO OR NON-ZERO              *
*                                                                     *
*        REGISTER USAGE                                               *
*          R2 ALTERED, ALL OTHERS PRESERVED                           *
*                                                                     *
***********************************************************************
*                                                                     *
*        ENTRY POINT                                                  *
*          ECBFBLK - FREE A BLOCK                                     *
*                                                                     *
*        INPUT                                                        *
*          R1  - RETURN ADDRESS                                       *
*          R2  - WORD ADDRESS OF BLOCK TO BE FREED                    *
*                                                                     *
*        OUTPUT                                                       *
*          NONE                                                       *
*                                                                     *
*        REGISTER USAGE                                               *
*          R2 DESTROYED, ALL OTHERS PRESERVED                         *
***********************************************************************
         PAGE
         DEF      ECBGBLK
ECBGBLK  EQU      %
         DISABLE                    ***   INHIBIT INTERRUPTS   ***
         LW,R2    COCHPB            GET HEAD OF FREE BLOCK CHAIN.
         BGZ      ECBG010           ---> FREE BLOCKS EXIST.
         BLZ      ECBSCREECH        ---> GARBAGED HEAD. SCREECH.
         ENABLE                     ***   ALLOW INTERRUPTS  ***
         AI,R2    0                 NO BLOCKS AVAILABLE. SET CC
         B        0,R1              --->  AND RETURN TO CALLER.
*
ECBG010  XW,R1    COCBUF,R2         SAVE RETURN IN BLOCK; GET FLINK.
         STW,R1   COCHPB            UNCHAIN OUR BLOCK FROM COCHPB.
         ENABLE                     ***   ALLOW INTERRUPTS   ***
         LI,R1    0                 CLEAR THE BLOCK.
I        DO       ECBBLENG-1
         STW,R1   COCBUF+I,R2
         FIN
         LW,R1    L(ECBBECB**16)    SET THIS-IS-AN-ECB-BLOCK CODE IN
         XW,R1    COCBUF,R2         WORD0 AND RE-GET RETURN ADDRESS.
         AI,R2    COCBUF            R2=WA(4-WORD BLOCK); CC=NONZERO.
         B        0,R1              ---> RETURN TO CALLER.
         PAGE
         DEF      ECBFBLK
ECBFBLK  EQU      %
         CLM,R2   ECBF900           CHECK BLOCK ADDRESS FOR VALIDITY
         BCR,9    ECBF010           ---> ADDRESS IS VALID.
ECBSCREECH SCREECH COCH0            BAD ADDRESS. SCREECH.
ECBF010  AI,R2    -COCBUF           CONVERT ADDR TO RELATIVE ADDRESS.
         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

