         DEF      ALLYCAT
DISCBPROC SET 1
         SYSTEM   UTS
         SPACE    3
ALLYCAT  CSECT    1                 ALLYCAT PROCEDURE
         SPACE    3
         DEF      ALLOINIT,ALLOCAT
         SPACE
         REF    HGPTYPE,LOLEVEL,HILEVEL
         REF      CATBUF,BUFMASK
         REF      M6,M8,M15,M24,MN9,Y8
         REF      BUFLAGS,WORDCNT,ADJSTCNT
         REF      TOP,BOTTOM,TEMPBOT
         REF      GRAVAIL,AGRAVAIL
         REF      J:BASE,ALLYHD,ALLYEND
         REF      CBAHD,CBFHD,CBRHD
         REF      HGP
         REF      ACNFDA
         REF      SYSACTL
         REF      DCTGG
         REF      CMNGG,CMNGNG
         REF      CMNRG,CMNRNG
         REF      FNDHGP
         REF      DCT2
         REF      Y4
         REF      GBG,GCYL
         REF      GSG
         REF      ALLODIRA
         REF      ACNCFU
         REF      COMBUF
         REF      SGB
         REF      JBUPVP,Y2         * BEGINNING USER PAGE #
         REF      UH:JIT,UH:AJIT
         REF      M:GASLIM,M:ADRINCR
         REF      T:RVPI,T:SGR
         REF      T:REG,T:GJOBSTRT
         REF      UB:PRIOB
         REF      UB:PCT,UB:SWAPI
         REF      JH:DA
         REF      JB:LMAP
         REF      GRANMIN,GRANRESET
         REF      SAMSJIT
         REF      U:MISC
         REF      ALLOOUT
         REF      E:SL
         REF      PURGEFLAG
         REF      MB:GAM6
         REF      YFF
         REF      STARTHGP
         REF      JXBUFVP,T:RBUF
         REF      TIME,ERRLOG
         REF      ALLYON
         PAGE
*  SYMBOLIC REGISTERS
         SPACE
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
*  ALLYCAT INITIALIZATION ROUTINE...  ONLY ENTERED WHEN
*  THE ALLOCAT GHOST IS STARTED UP AT BOOT TIME AND AT
*  CRASH RECOVERY.
         SPACE    3
ALLOINIT CAL1,8   FPTRAP            SET TRAP CONTROL TO MASK DECIMAL OVERFLOW
         CAL1,6   SYS               GET MASTER MODE
         SPACE
         LI,R7    JBUPVP            *FREE ANY UNNEDED PAGES BELOW
1A1      LB,R10   JB:LMAP,R7        *(FLINK) ALLY START
         LW,R7    R10               BEFORE TRYING TO SWAP
         BEZ      1A2               BACK TO ORIGINAL SIZE
         SPACE
         LB,R10   JB:LMAP,R7
         LW,14    7
         AI,14    -JXBUFVP          SPARE BUFFER INDEX.
         LI,5     0
         BAL,2    T:RBUF       RELEASE IT..
         B        1A1
1A2      EQU      %
         SPACE
         LI,R4    2                 ALLOCAT'S NUMBER
         LB,R7    UB:PCT,R4
         LI,R14   2                 SECT 2 RESVD FOR AJIT
         LH,R15   UH:AJIT,R4        IF THERE IS ONE
         BEZ      NOAJ
         STH,R14  UH:AJIT,R4
         AI,R7    -1                DECR CT FOR AJIT PAGE
         B        RELIT
NOAJ     LH,R15   UH:JIT,R4         GET JIT SECT NUM TO REL
RELIT    AI,R7    -1                DECR CT FOR JIT PAGE
         LI,R14   4                 SECT 4 RESERVED FOR JIT
         STH,R14  UH:JIT,R4
         BAL,R11  T:SGR             REL A GROUP OF GRANS
         AI,R7    3
         SLS,R7   -2                GET # DISC ADDRESSES
         LI,R14   8                 CAT STARTS ON SECTOR 8
         LI,R6    0
         LH,R15   JH:DA,R6          PICK UP DAS
         BAL,R11  T:SGR
         STH,R14  JH:DA,R6          PUT BACK OLD ONES
         SPACE
         BAL,R13  INCR              NEXT DA
         AI,R6    1
         BDR,R7   %-5
         STB,R7   UB:SWAPI,R4
         MTB,-8   UB:PRIOB,R4       UPP OUR COMPUTE PRIO A BIT
         SPACE
         LCI      5
         LM,0     ACNFDA            GET FILE SYSTEM POINTERS
         STW,0    ACNCFU+1          FDA
         STW,1    ACNCFU+8          DFDA
         STD,2    ALLODIRA          NGAVAL/GAVAL
         STW,4    SYSACTL           :SYS FDA
         LI,R2    0
         STW,R2   SGB               RESET SGB ONLY AT STARTUP
         PAGE
         BAL,11   WAIT              GIVE UP FOR RECON
         LI,11    KRD2
*
*        COUNT UP FREE BITS IN ALL HGP'S
*
HGPCNT   EQU      %
         LW,13    Y8                EMPTY BIT
         LI,12    0                 FOR ZAPPING
         LI,R4    4                 THE GRANULES AVAILABLE
         STW,12   HGPTYPE-1,4       ZAP FAST PATH POINTERS TOO
         STW,12   HGPTYPE+2,4
         STW,12   AGRAVAIL-1,4      TABLES
         BDR,4    %-3
         LI,R7    HGP               START OFF LOOP
NEXTHGP  LW,R3    1,R7              GET MAP FLAGS
         STS,13   5,7               SET EMPTY BITS
         STS,13   6,7               FOR PFA AND PER
         STW,12   3,7               ZAP FAST PATH DISP
         CI,R3    X'4000'           IS THIS MAP A PUBLIC HGP
         BANZ     HGPLINK           NOPE...;PRIVATE
         LH,4     3                 IF DEVICE IS DOWN, SKIP IT
         REF      DCT24
         LC       DCT24,4
         BCS,8    HGPLINK
         LI,9     1                 ONE GRANULE PER BIT UNLESS CYL
         CI,R3    X'8000'           IS CYLINDER ALLOCATED
         BAZ      NOTCYL            NOPE
         LI,14    3                 CYL SPOT
         LI,9     X'FF'             GET GRANULES/CYLINDER
         AND,9    1,7
         BEZ      HGPSBLOWN         NO GOOD
         B        COUNTEM           GET INTO LOOP
NOTCYL   SLS,R3   -8                POSITION DEVICE TYPE
         REF      M4
         AND,R3   M4                STRIP DOWN TO DEVICE TYPE
         CI,R3    X'07'             IS THIS A RAD HGP
         BNE      NOTRAD            NOPE
         LI,14    0                 RAD SPOT
         B        COUNTEM           DO IT
NOTRAD   CI,R3    X'0B'             IS IT A DISC PACK THEN
         BNE      HGPSBLOWN         HGPS ARE BLOWN AWAY
         LI,14    1                 POINT TO PACK SPOT
COUNTEM  INT,2    4,7               GET WORD COUNTS  (MAX FFF)
         AI,2     0                 ANY PER ON THIS ONE
         BEZ      COUNTEM3          NO...CHECK PFA
         LW,4     5,7               GET PER MAP DETAILS
         LI,1     2
COUNTEM1 INT,4    4                 SHIFT MAP WORD DISP INTO PLACE
         LW,0     AGRAVAIL,1        GET CURRENT VALUE FOR EMPTY CHECK
COUNTEM2 LW,15    *R7,R4            GET A WORD
         BEZ      %+6               NON HERE
         LI,R6    32                WIDTH
         SLS,15   1
         BEV      %+2
         AWM,9    AGRAVAIL,1        COUNT GRANULES
         BDR,R6   %-3               NEXT BIT LOOP
         AI,R4    1
         BDR,2    COUNTEM2          NEXT WORD LOOP
         CW,0     AGRAVAIL,1        DID WE GET ANY GRANULES
         BE       COUNTEM3          NO
         LI,4     6                 ASSUME PFA
         CI,1     2
         BNE      %+2
         LI,4     5                 NO, WAS PER
         STS,12   *4,7              RESET EMPTY BIT IF WE GOT SOME
COUNTEM3 XW,2     3                 ANY PFA ON THIS DEVICE, OR WERE DONE
         BLEZ     HGPCHAIN          DONE, PUT IN A CHAIN, MAYBE
         LW,1     14                GET SAVED PFA TYPE
         LW,4     6,7               GET PFA MAP DETAILS
         B        COUNTEM1
*
HGPCHAIN LW,3     4,7               IF SWAPPER ONLY, DONT CHAIN
         BEZ      HGPLINK
         CI,1     2                 CYL => ONLY PFA SO LINK IT
         BG       HGPCH2
         BDR,5    %+2               OTHERWISE, CHECK FOR DUAL PURPOSE
         AI,1     -4                STARTS AT 0, PUT IN O,1,OR 2
         AI,1     4                 DOESNT, PUT IN 4,5,OR 6
HGPCH2   LW,2     7                 ADD 7 TO CIRCULAR CHAIN HGPTYPE
         XW,7     HGPTYPE,1
         XW,2     2,7               OLD HEAD'S NEW FLINK IS NEW HEAD
         LW,7     HGPTYPE,1         NEW HEAD'S FLINK IS OLD HEAD'S OLD FLINK
         STW,2    2,7               (BOTH THE SAME IF OLD HEAD WAS 0)
*
HGPLINK  LW,R7    0,R7              STEP UP TO NEXT HGP
         REF      HGPSIZE           LENGTH OF HGPS
         BEZ      HGPDONE           HIT LAST ONE
         LI,R9    NEXTHGP           SET RETURN, FALL THRU CHK LINK
*
*
         DEF      HGPTEST
HGPTEST  CLM,R7   HGP:LIMS          IS ADDRESS WITHIN RANGE
         BCR,9    *9                YES,EXIT
HGPSBLOWN  SCREECH   X'89'          NOPE
*
*
         BOUND    8
         DEF      HGP:LIMS          FOR GRANSUB
HGP:LIMS DATA     HGP
         DATA     HGP+HGPSIZE+2
HGPDONE  LCI      4
         LM,R0    AGRAVAIL          SET UP GRAVAIL FOR KEYIN
         STM,R0   GRAVAIL
         LI,3     7
         LW,2     HGPTYPE-1,3       ALLOCATE FROM FIRST TO LAST
         LW,2     2,2
         STW,2    HGPTYPE-1,3
         BDR,3    %-3
         B        *R11              RETURN TO INITIALIZATION
         SPACE    3
INCR     LI,R5    4
         AI,R14   2
         LB,15    MB:GAM6
         CS,14    M:GASLIM
         BLE      INCR1
         AW,R14   M:ADRINCR
         REF      MB:GAM7
         MTB,0    MB:GAM7
         BEZ      INCR1
         AI,14    1
INCR1    EQU      %
         BDR,R5   INCR+1
         B        *R13
         PAGE
ALLOCAT  EQU      %
         LI,R5    0
         XW,R5    J:BASE            SET CHECKSUM TO ZERO
         BEZ      KRD2              NO CHECKSUM TO COMPARE WITH
         BAL,R6   CHKSUM            CHECKSUM ALL OF ALLOCAT DATA
         CW,R5    J:BASE            CHECKSUM CHECK
         BE       KRD2              YES
         SCREECH  X'89',X'10'       NO-CRASH .89-.10
KRD2     EQU      %
         MTW,1    ALLYON            SET 'ON' FLAG
         LW,0     ACNCFU+1          SAVE FILE SYSTEM POINTERS
         LW,1     ACNCFU+8
         LD,2     ALLODIRA
         LW,4     SYSACTL
         LCI      5
         STM,0    ACNFDA
         PAGE
*
*        GET MESSAGE FROM COMBUF
*
ENDYET   BAL,R7   GBUF              GO GET ENTRY - NON-RETURN AT ZERO
         INT,R4   COMBUF,R1
         AND,R4   M8
         LW,R15   COMBUF+1,R1
         BAL,R10  COMVEC,R4
         B        ENDYET
         SPACE    3
         PAGE
*  NEW CODE FOR AUTOMATIC BUFFER LEVEL ADJUSTMENT.
         SPACE    3
*  EXCEPT FOR THE BUFFER ADDRESSES THEMSELVES, RADBUF,
*  PACKBUF, PERBUF AND CYLBUF, EACH DATA ITEM PERTAINING
*  TO THE ALLOCATION BUFFERS IS A HALF-WORD IN LENGTH.
*  THESE INCLUDE FOUR DATA ITEMS EACH, UNDER THE FOLLOWING
*  NAMES:      FIXED DATA...
*              BUFSIZE, LOLEVEL, HILEVEL, LOTHRSH, HITHRSH
*              DYNAMIC DATA...
*              WORDCNT, TOP, BOTTOM, TEMPBOT, ADJSTCNT
         SPACE
*  REGISTER  0   CONTAINS THE WORD COUNT FOR THE ALLOCATION
*                BUFFER BEING PROCESSED
*  REGISTER  1   CONTAINS THE INDEX FOR DATA RELATED TO THE
*                BUFFER BEING PROCESSED
*                0=RAD
*                1=PACK
*                2=PER
*                3=CYL
*  REGISTER  2   CONTAINS THE NUMBER OF DISK ADDRESSES TO ADD
*                OR REMOVE FROM THE BUFFER BEING PROCESSED
*  REGISTER  3   CONTAINS THE DISPLACEMENT OF THE NEXT
*                BUFFER WORD TO BE FILLED OR EMPTIED
*  REGISTER  8   IS THE PARAMETER REGISTER FOR GGVEC AND
*                RGVEC
*  REGISTER  9   CONTAINS THE ADDRESS OF THE BUFFER BEING
*                PROCESSED
*  REGISTER 11   IS THE SUBROUTINE LINK REGISTER
         SPACE    3
QUIESCE  BAL,R11  FCB               FREE COMM BUFFER
         LI,1     -4                EMPTY ALL BUFFERS
QE1      DISABLE
         MTH,0    WORDCNT+2,1       ANY LEFT HERE
         BEZ      QE2               NO, TO THE NEXT ONE
         PUSH     1                 SAVE INDEX
         LB,0     GT,1              GET DEVICE TYPE
         BAL,11   GG,1              GET ONE HERE
         BAL,11   CMNRG             RELEASE IT
         PULL     1
         B        QE1               TRY FOR MORE HERE
QE2      BIR,1    QE1               TO NEXT STACK
         B        ENDYET            TO NEXT REQUEST
         B        GBG
         B        GBG
         B        GSG
         B        GCYL
GG       DATA,1   7,11,0,0
GT       EQU      %
         SPACE
ADJBUFS  EQU      %
SETINDEX LI,R1    4                 SET INDEX FOR # OF BUFS
         SPACE
NEXTBUF  ENABLE
         AI,R1    -1                DECREMENT INDEX
         BLZ      NOMORE            AND EXIT IF NO MORE BUFS
         SPACE
         DISABLE
         LH,R0    BUFLAGS,R1        GET OLD FLAGS
         CI,R0    X'6001'           HAS SSS RUN/OR IN PROGRESS FLAG SET
         BANZ     NEXTBUF           NOT FOR THIS ONE YET
         AI,R0    1                 SET IN PROGRESS FLAG
         STH,R0   BUFLAGS,R1        AND SAVE IT
         LI,R0    0                 YES
         STH,R0   ADJSTCNT,R1       RESET COUNTER
         LH,R2    WORDCNT,R1        GET COUNT IN BUFFER
         BLZ      ALLYERROR         SOMEONE BLEW IT
         CH,2     LOLEVEL,1
         BLE      FILL              FILL IF LOW
         CH,2     HILEVEL,1
         BLE      AVG:ADJ           BUFFER IS OPTIMUM
         SH,2     LOLEVEL,1         CALCULATE # TO REMOVE
         LH,R3    BOTTOM,R1         GET BOTTOM DISP
         AW,R3    R2                MAKE TEMPBOT DISP
         AND,R3   BUFMASK,R1        LOOK FOR WRAPAROUND
         STH,R3   BOTTOM,R1         SET BOTTOM
         LH,R3    TEMPBOT,R1        START AT LOW END
         LW,R4    CATBUF,R1         GET LOC OF BUFFER
         ENABLE
EMPTY1   MTH,-1   ADJSTCNT,R1       DECREMENT WORD COUNT 1ST FOR TSTHGP
         LI,R8    0
         XW,R8    *R4,R3            RESET OLD / GET ONE OUT
         LW,R5    R8                REMEMBER IT IN R5
*
*  UPDATE POINTER AND WORD COUNT FIRST. THEN IF A CRASH
*  OCCURS BETWEEN RELEASING THE GRANULE AND UPDATING THE
*  POINTER... WE LOSE ONE GRANULE INSTEAD OF TRYING TO
*  RELEASE A RELEASED GRANULE LATER.
         SPACE
         AI,R3    1                 INCREMENT DISPLACEMENT
         AND,R3   BUFMASK,R1        LOOK FOR WRAPAROUND
         PUSH     5,1
         BAL,11   CMNRG             RELEASE A GRANULE/CYL ETC.
         PULL     5,1
         AI,R8    0                 RESET THE CC
         BNEZ     EMP3              CONTINUE IF WE GOT ONE
         BAL,R11  LOGERR            LOG AN ERROR
EMP3     EQU      %
         BDR,R2   EMPTY1            CONTINUE EMPTYING
         LI,R5    X'4000'           FLAG TO SHOW
SETFLAG  LH,R11   BUFLAGS,R1        GET OLD FLAGS
         OR,R11   R5                SET NEW FLAG
         STH,R11  BUFLAGS,R1        STORE IT BACK
AVG:ADJ  EQU      NEXTBUF
         B        NEXTBUF           CONTINUE ALONG
         PAGE
*
*        FILL BUFFER TO OPTIMUM LEVEL
*
FILL     LH,R11   BUFLAGS,R1        GET OLD FLAGS
         BLZ      NEXTBUF           HGP IS EMPTY..GO TO NEXT ONE
         SH,2     HILEVEL,1         CALCULATE HOW MANY TO ADD
         LH,R3    BOTTOM,R1         MOVE TEMPBOT DOWN
         AW,3     2                 2 IS NEGATIVE
         AND,R3   BUFMASK,R1        LOOK FOR WRAPAROUND
         STH,R3   TEMPBOT,R1        NOW WE CAN ENABLE
         LW,R4    CATBUF,R1         GET LOC OF BUFFER
         ENABLE
         LH,3     BOTTOM,1          FILL DOWN FROM THE BOTTOM
FILL1    PUSH     4,1               SAVE REQUIRED REGS
         BAL,11   CMNGG
         PULL     4,1
         AI,R8    0                 RESET THE CC
         BNEZ     FILL2             GOT ONE
         LI,R5    X'A000'           EMPTY/JUST FILLED
         STH,R3   TEMPBOT,R1        TELL SWAPPER WHERE WE STOPPED
         B        SETFLAG           AND GIVE UP ON THIS ONE
FILL2    AI,R3    -1                BACK UP ONE FOR NEXT SPOT TO FILL
         AND,R3   BUFMASK,R1
         STW,R8   *R4,R3            PUT IT IN PLACE
*
*        NOTE:    ALLYCAT SETS THE 'EMPTY' HGP FLAG
*                 FOR ALL TO LOOK AT, BUT GRANSUB IS
*                 THE ONLY ONE WHO RESETS THE EMPTY BIT
*                 CAUSE HE IS THE ONLY ONE WHO KNOWS
*                 THE RIGHT ONE TO TURN OFF.
*
         MTH,1    ADJSTCNT,R1       INCREMENT WORD COUNT
         BIR,2    FILL1             ADD ANOTHER ONE
         LI,R5    X'2000'           JUST FILLED FLAG
         B        SETFLAG           PUT IT IN AND CONTINUE
         PAGE
*
*  GET AND RELEASE N GRANULES OR CYLINDERS.
         SPACE    3
GETN     EQU      %
         LB,R0    R15               DEV TYPE INTO REG 0
         AND,R15  M24               REMOVE GARBAGE FROM #
         PSW,R1   TSTACK            SAVE COMM BUF NUMBER
         BAL,11   CMNGNG            GET THE GRANS OR CYLS
         BNE      %+3
         AI,0     X'80'             TRY CYLINDER TOO
         BAL,11   CMNGNG
         PLW,R1   TSTACK            RESTORE BUFFER NUMBER
         STW,R8   COMBUF+1,R1       PUT THE DA AWAY
         STW,15   COMBUF,1          SET # ALLOCATED
         B        ENDYET            LEAVE MSG SITTING WHERE IT IS
         PAGE
*
*        RELEASE N GRANS OR CYLS
*
*
RELN     EQU      %
         LW,R8    R15               PUT # TO REL IN R 8
         AND,R8   M24               MASK OFF THE GARBAGE
         PUSH     R8                REMEMBER DISK ADDRS IN STACK
         REF      M16
         LW,R15   COMBUF,R1         GET # TO RELEASE
         AND,R15  M16               REMOVE GARBAGE
         BAL,R11  FCB               RELEASE COMBUF ENTRY NOW
         BAL,11   CMNRNG
         PULL     R5                RESTORE D/A TO REG#5
         AI,R8    0                 RELEASE GO OK
         BNEZ     ENDYET            YES, GO ON
         BAL,R11  LOGERR            WAS NOT OK
         B        ENDYET            ALL DONE
         PAGE
*
*        GET SEPARATED PAIR FOR DIRECTORIES
*
*
GSBP     EQU      %
         PUSH     1                 SAVE COMBUF ADDRESS
         BAL,11   HGPCNT            MAKE SURE EMPTY BITS ARE ACCURATE
         LW,1     *TSTACK           RESTORE COMBUF DISP
         LW,1     COMBUF+1,1        GET DEVICE TYPE FOR FIRST
         SLS,1    -24-3             AS STACK INDEX
         LW,9     GSBP3,1           GET PROPER DEV TYPE SEQUENCE
GSBP1    LI,11    GSBP2             SET RETURN FROM GET GRAN
         DISABLE                    DONT LET ANYBODY STEAL THE LAST STACK GRAN
         LH,0     WORDCNT,1         GET FROM STACK IF THERE'S ANY THERE
         BEZ      CMNGG             NONE, GET FROM BITMAP
         LB,0     GSBP4,1           SET DEVICE TYPE FOR GBG
         BDR,1    GCYL              GET CYL IF 1 WAS 3
         B        GBG
GSBP2    BNEZ     GSBP5             GOT ONE
         LB,1     9,1               GET NEXT STACK TYPE TO TRY
         AI,1     -1
         BGEZ     GSBP1
         B        GSBP5             NONE ANYWHERE..EXIT UNHAPPY
GSBP3    DATA,1   1+1,3+1,0,0       RAD -> PACK -> CYL -> GIVE UP
         DATA,1   3+1,0+1,0,0       PACK -> RAD -> CYL -> GIVE UP
GSBP4    DATA,1   7,11,0,X'8B'      DEVICE TYPES BY STACK #
GSBP5    LW,1     *TSTACK           GET COMBUF INDEX
         STW,8    COMBUF,1          SAVE FIRST ADDRESS
         BAL,3    FNDHGP            GET HGP ADDRESS IN 7, DCTX IN 5
         BEZ      GSBP14            NONE ANYWHERE, GIVE UP
         LB,3     DCT2,5            CHANNEL #
         LI,8     0                 NOW SEARCH FOR A DEVICE FOR SECOND GRAN
*        ON PACK -> RAD -> OR CYL TYPE,
*        BUT DIFFERENT CHANNEL OR AT LEAST DIFFERENT DEVICE
         LW,0     =X'8B070B'
         LI,1     -1                INITIALIZE BEST HGP ADDRESS
GSBP6    LI,6     6                 DISP TO DEVICE TYPE
         LI,7     HGP               START OF HGPS
GSBP7    CB,0     *7,6              IS THIS THE RIGHT TYPE
         BNE      GSBP9             NO, TRY THE NEXT ONE
         MTW,0    6,7               IS THERE ANY PFA LEFT HERE
         BLEZ     GSBP9             NO...
         LW,4     1,7               GET DCT INDEX
         SLS,4    -16
         CB,3     DCT2,4            IS THIS THE SAME CHANNEL
         BNE      GSBP8             GOT A GOOD ONE
         OR,7     Y4                SET SAME CHANNEL FLAG
         LC       1                 AND CHECK PREVIOUS FLAGS
         BCR,4    GSBP9             THEY WERE BETTER
         CW,4     5                 IS THIS THE SAME DEVICE
         BNE      GSBP8             NO...TAKE IT
         BCR,8    GSBP9             YES.. BUT WEVE GOT A DIFFERENT ONE ALREADY
         OR,7     Y8                SET SAME DEVICE FLAG
GSBP8    STW,7    1                 UPDATE CURRENT BEST TRY
GSBP9    LW,7     0,7               HAVE WE SEARCHED THE WHOLE CHAIN
         BNEZ     GSBP7             NO, TRY THIS ONE
         CI,1     -1                DID WE GET ANYTHING
         BNE      GSBP10            YES...GET A GRANULE THERE
         SLS,0    -8                NO, TRY NEXT DEVICE TYPE
         AI,0     0                 IF THERE ARE ANYMORE
         BNEZ     GSBP6
         B        GSBP11            NONE..TRY STACKS
GSBP10   LB,0     *1,6              GET DEVICE TYPE OF WHAT WE WANT
         LW,8     1,1               SET DCTX FOR GET
         BAL,11   DCTGG             GET A GRAN BY DCT
GSBP11   BNEZ     GSBP14            GOT ONE
         LI,1     1                 NOPE...TRY STACKS
GSBP12   LI,11    GSBP13
         DISABLE
         MTH,0    WORDCNT,1
         BEZ      GSBP13
         BDR,1    GCYL
         B        GBG
GSBP13   BNEZ     GSBP14            GOT ONE, FINALLY
         LB,1     GSBP3+1,1
         AI,1     -1
         BGEZ     GSBP12
GSBP14   PLW,1    TSTACK            SAVE RESULTS IN COMBUF
         STW,8    COMBUF+1,1
         B        *10
         PAGE
*
*        THE STACK COUNT IS INVALID
*
ALLYERROR   SCREECH    X'87'
         PAGE
*
*        RELEASE BUFFER BACK TO FREE CHAIN
*
*
*
*
FCB      DISABLE
         LW,R3    R1                BUFFER INDEX IN R1
         AI,R3    COMBUF            CORE ADDRESS
         LB,R5    CBFHD             CURRENT FREE HEAD
         STB,R5   *R3               LINKED INTO FREE CHAIN
         STB,R1   CBFHD             LEAVE CURRENT AS NEW FREE HEAD
         ENABLE
         B        *R11
         PAGE
*
*        RELEASE A PAGE FULL OF DISK ADDRESSES
*
RELBUF   BAL,R11  FCB               FREE UP COMBUF
         STH,15   6                 GENERATE CVMCAL
         SLS,6    -7                WA PHYS PAGE
         MTB,7    6
         LI,7     CVMPAGE
         CAL1,8   6                 MAP INTO IT
         LW,7     CVMPAGE+1         # OF DISC ADDRESSES
RELBUF1  LI,8     0
         XW,8     CVMPAGE+3,7       GET/ZAP ADDRESS
         PUSH     7                 SAVE COUNTER
         BAL,11   CMNRG
         PULL     7
         BDR,7    RELBUF1
         STD,7    CVMPAGE
CVMPAGE  EQU      X'1FE00'          USE LAST VIRTUAL PAGE
         B        ENDYET
         PAGE
*  MAKE ALL THE SYMBIONT SPACE AVAILABLE AGAIN BY
*  TURNING ON ALL THE PER BITS IN THE HGP BIT MAPS
*  RESETTING THE SYMBIONT ALLOCATION BUFFER TO EMPTY.
         SPACE    3
FILLPER  EQU      %
         BAL,R11  FCB               GO AHEAD AND RELEASE BUFFER
         LI,R1    2                 SYMBIONT STACK POINTER
         DISABLE
         LI,R8    -1                RESET EM ALL
         LI,R7    HGP
FP1      LW,R6    4,R7              # OF PER WORDS
         LH,R6    R6
         BEZ      FP2               BRANCH IF NONE
         AI,R6    -1                DONT SET LAST WORD
*                                   MAY NOT BE
*                                   COMPLETELY FULL
         INT,4    5,7               START OF PER
         AW,4     7
         AI,4     -1
         STW,8    *4,6
         BDR,R6   %-1
FP2      LW,R7    0,R7
         BNEZ     FP1
         LI,R0    0                 RESET PER WORD
         LW,7     CATBUF,R1         ZAP THE BUFFER
         LH,6     BUFMASK,R1
         STW,R0   *7,6
         BDR,6    %-1
         STW,R0   0,7
         STH,R0   WORDCNT,R1
         STH,R0   TEMPBOT,R1
         STH,R0   ADJSTCNT,R1
         STH,R0   BUFLAGS,R1
         STH,R0   BOTTOM,R1
         STW,R0   SGB               #SYMB GRANS BUSY RESET
         STH,R0   TOP,R1            'TOP' TO 'BOTTOM'
         ENABLE
         BAL,R11  HGPCNT            RESTORE GRANULES AVAILABLE TABLES
         B        ENDYET            DO NEXT COMBUF
         PAGE
*  BRANCH VECTOR TABLES
         SPACE    3
COMVEC   B        GETN
         B        RELN
         B        GSBP
         B        ENDYET
         B        RELBUF
         B        QUIESCE
         B        FILLPER
         B        AVR
         B        COUNTBITS
         PAGE
AVR      EQU      %
         BAL,R11  FCB               GO AHEAD AND RELEASE BUFFER
         LW,R7    R15               DCTX
         OVERLAY  MISOVSEG,AVR#
         B        ENDYET            DO NEXT BUFFER
         REF      MISOVSEG,AVR#
         PAGE
*
*        IF A COMBUF ENTRY CODE OF '08' IS PASSED, ALLYCAT
*        WILL COUNT UP THE BITS IN ALL OF THE HGPS AND SET
*        AGRAVAIL AND GRAVAIL UP. THE KEYIN 'DISP DISC'
*        SHOULD TRIGGER THIS FUNCTION.
*
COUNTBITS BAL,R11 FCB               GO AHEAD AND RELEASE BUFFER
          BAL,R11 HGPCNT            COUNT UP BITS
          B       ENDYET            DO NEXT BUFFER
         PAGE
*
*        GET NEXT ENTRY ON ALLYCAT'S CHAIN, TAKE ITS
*        FLINK AND LEAVE IT AS NEXT ON CHAIN
*
GBUF     DISABLE                    LEAVE US INTERACTIVE W/SYMBIONTS
         LB,R4    CBAHD             GET HEAD
         BEZ      ADJBUFS           NONE, START LOOKING AT D/A TABLES
         LW,R1    R4                RETURN IT IN R1
         AI,R4    COMBUF
         LB,R4    *R4               GET ITS FLINK
         STB,R4   CBAHD             LEAVE IT AS NEXT ONE
         ENABLE
         B        0,R7              AND EXIT
         PAGE
         SPACE    3
LOGERR   PUSH     7,R5              SAVE THE REGISTERS
         LI,R6    8                 ADDRESS OF ERR MSG
         AW,R6    Y2                SET FLAG FOR ERHNDLR
         LW,R8    =X'24040000'      ERR MSG CODE/COUNT
         LW,R9    TIME              GET CURRENT TIME
         LW,R10   R5                GET DISC ADDRESS IN ERROR
         LW,R11   ='ACAT'           FLAG FOR ERROR RECORD
         BAL,R5   ERRLOG            WRITE THE ENTRY
         PULL     7,R5              RESTORE THE REGISTERS
         B        *R11              AND RETURN
         PAGE
*  ALL BUFFERS HAVE BEEN ADJUSTED... THIS IS THE EXIT.
         SPACE    3
NOMORE   MTW,0    GRANMIN           CHECK FOR STARTING UP
         BL       PURGE             PURGE (BACKUP-FILL)
         MTW,0    GRANRESET
         BG       PURGE
         SPACE
NOPURGE  LW,0     UB:SWAPI          GET SWAPI OF RBBAT
         LW,2     UH:JIT+1          AND JITDA
         STH,0    2
         INT,3    UH:AJIT+1         ALSO AJIT
         STD,2    SAMSJIT
         LI,11    ALLOCAT           RETURN FROM REG
WAIT     EQU      %
         LI,R0    X'7FFFF'
         STW,R0   U:MISC+2          AND RESTORE VALUE
         LI,R0    2
         STW,R0   ALLOOUT
         LI,R1    0
         STW,R1   J:BASE            CLEAR OLD CHECKSUM
         BAL,R6   CHKSUM            COMPUTE NEW CHECKSUM
         LI,R6    E:SL
         B        T:REG             EXIT TO SLEEP
         SPACE    3
CHKSUM   EQU      %
         LI,R1    ALLYHD            START OF ALLOCAT DATA
         LI,R3    -1                MASK TO ADD ALL 32 WORDS
         LI,R4    ALLYEND-ALLYHD+X'3F'
         SLS,R4   -7                NUMBER OF 128 WORD BLOCKS TO CHECKSUM
KRD4     CVA,R2   0,R1              ADD UP 32 WORDS
         AWM,R2   J:BASE
         CVA,R2   32,R1
         AWM,R2   J:BASE
         CVA,R2   64,R1
         AWM,R2   J:BASE
         CVA,R2   96,R1
         AWM,R2   J:BASE
         AI,R1    128               POINT TO NEXT 128 WORD BLOCK
         BDR,R4   KRD4
         B        *R6
FPTRAP   GEN,8,24 X'14',0
         DATA     1                 MASK DECIMAL OVERFLOW TRAP
         SPACE    3
PURGE    MTW,0    PURGEFLAG         SEE IF WE CAN RUN
         BEZ      NOPURGE           BACKUP
         LD,R0    BACKUP
         LI,R10   NOPURGE
         B        T:GJOBSTRT
         PAGE
*  DATA
         SPACE    3
SYS      GEN,8,24      8,0
         BOUND    8
BACKUP   TEXTC    'FILL'
         SPACE    3
         END      ALLYCAT

