*G*      'GETMAIN'           MEMORY MANAGEMENT SUBROUTINES
*
*P*      TYPE:     NON-CONTROL MODULE.  TWO SUBROUTINES.
*P*
*P*      PURPOSE:  THIS IS A PAIR OF MEMORY MANAGEMENT
*P*                ROUTINES.  THE FIRST FINDS WORDS FOR THE
*P*                USER.  THE SECOND RETURNS WORDS TO THE
*P*                'POOL' OF FREE SPACE.
*P*
*P*                THE UNIT OF ALLOCATION IS THE DOUBLEWORD.
*P*
*P*      CALLS:    MODULE CONTAINS TWO ENTRY POINTS.  THE
*P*                FIRST IS CALLED TO OBTAIN DOUBLEWORDS
*P*                FROM A 'POOL' OF SPACE; THE SECOND
*P*                RETURNS WORDS TO THAT POOL.
*P*
*P*      METHOD:   THESE MEMORY MANAGEMENT ROUTINES ARE BASED
*P*                ON KNUTH VOLUME ONE.
*P*
*P*                THE ROUTINES ONLY KEEP TRACK OF THE FREE SPACE.
*P*                FREE SPACE IS CHAINED TOGETHER, USING THE FIRST
*P*                DOUBLEWORD IN EACH PIECE.  FORMAT OF THIS
*P*                DOUBLEWORD IS JUST:
*P*                          FORWARD LINK WA
*P*                          NUMBER OF DW IN BLOCK
*P*                THIS CHAIN IS HEADED WITHIN THIS MODULE.
*P*
*P*                TO START WITH, THE CHAIN IS EMPTY ... THAT IS
*P*                THERE IS NO FREE SPACE.
*P*
*P*                WHEN FREE SPACE IS REQUESTED, AND THERE IS
*P*                NONE, OR IS NO BLOCK BIG ENOUGH, THE MODULE
*P*                GETS A PAGE VIA A M:GVP CAL AND ADDS THE
*P*                256 DW THUS OBTAINED TO THE SPACE POOL AND
*P*                RE-TRYS THE REQUEST.  THIS CONTINUES UNTIL
*P*                THE REQUEST CAN BE SATISFIED OR UNTIL A
*P*                M:GVP FAILS OWING TO THE JOB'S LIMIT
*P*                BEING REACHED.
*P*
*P*      REFERENCE: THE METHODOLOGY OF THIS ROUTINE IS
*P*                COMPLETELY DESCRIBED IN KNUTH VOLUME ONE.
*P*                IN PARTICULAR, THE USAGE OF A TEMP POINTER
*P*                WHICH IS KEPT POINTING 'SOMEWHERE' IN THE
*P*                FREE SPACE CHAIN IN ORDER TO SAVE CPU TIME,
*P*                IS DESCRIBED IN KNUTH.
*P*
*P*                COMMENTS ON THE USE OF THE ROUTINES MAY BE
*P*                FOUND IN THE INTERNAL SPEC OF THE TIC,
*P*                DRAWING 703231 ... THESE ROUTINES WERE
*P*                DEVELOPPED FOR THE USE OF THE TIC.
         PAGE
         SYSTEM    SIG7                                                 TIM00010
         DEF       #FIND#DWS,#HIDE#DWS                                  TIM00020
         DEF       FINDDWS,HIDEDWS                                      TIM00030
         PAGE                                                           TIM00380
*                                                                       TIM00390
*        THE #FIND#DWS ROUTINE GIVES SPACE FROM THE FREE SPACE          TIM00400
*        POOL TO THE CALLER.  IT IS ENTERED WITH REGISTER               TIM00410
*                  REG #DWS = NUMBER OF DW DESIRED                      TIM00420
*                                                                       TIM00430
*        ON RETURN:                                                     TIM00440
*                  REG #DWS = NUMBER OF DW DESIRED                      TIM00450
*                  REG #DWA = DA OF BLOCK OR = 0                        TIM00460
*                  CC REFLECT C(#DWA)                                   TIM00470
*                                                                       TIM00480
*                                                                       TIM00490
*                                                                       TIM00500
*        DEFINE THE REGISTERS:                                          TIM00510
*                                                                       TIM00520
#DWA     EQU       4                                                    TIM00530
#DWS     EQU       5                                                    TIM00540
#XDW     EQU       6                                                    TIM00550
#TRR     EQU       8                                                    TIM00560
#BAL     EQU       3                                                    TIM00570
*                                                                       TIM00580
DO#FINDFROMBOTTOM SET 1                ON IF WE SHOULD ALLOCATE, AS
*                                      STRICTLY AS POSSIBLE, FROM LOW
*                                      CORE LOCATIONS UPWARD.
*                                                                       TIM00590
#FIND#DWS RES      0                                                    TIM00600
FINDDWS  RES       0                                                    TIM00610
*                                                                       TIM00620
         AI,#DWS   0                   IF WE ASKS FOR ZERO OR LESS      TIM00630
         BLEZ      *#BAL                 DW'S THEN JUST RETURN.         TIM00640
*                                                                       TIM00650
         DO        DO#FINDFROMBOTTOM
         ELSE
         LI,#TRR   2                   COUNTS TIMES WE MUST SCAN CHAIN  TIM00660
*                                                                       TIM00670
         LW,#XDW+1 #FREE#DWS#CHAIN#POINTER GET PTR TO CHAIN MIDDLE      TIM00680
         BEZ       FINDDWSHEAD         HEAD THE CHAIN IF NO POINTER.    TIM00690
         LW,#XDW   0,#XDW+1            ESTABLISH US AT NEXT BLOCK       TIM00700
*                                       OF THE FREE CHAIN.              TIM00710
         BNEZ      FINDDWSCOMPARE      OVER IF THERE IS A NEXT BLOCK.   TIM00720
*                                                                       TIM00730
FINDDWSHEAD RES    0                                                    TIM00740
         LI,#TRR   1                   START AT HEAD, SO NEED ONLY      TIM00750
         FIN
*
FINDDWSCOMPAAA RES 0                                                    TIM00760
         LW,#XDW   #FREE#DWS#CHAIN#HEAD ONE SCAN THROUGH.               TIM00770
         BEZ       FINDDWSNONE         OUT IF NO FREE SPACE.            TIM00780
         LI,#XDW+1 #FREE#DWS#CHAIN#HEAD (POINTER TO FLINK OF FIRST)     TIM00790
*                                                                       TIM00800
FINDDWSCOMPARE RES 0                                                    TIM00810
         CW,#DWS   1,#XDW              IS SPACE BIG ENOUGH?             TIM00820
         BLE       FINDDWSFOUND76      OUT IF SO.                       TIM00830
*                                                                       TIM00840
         LW,#XDW+1 0,#XDW              LINK UP TO NEXT ENTRY.           TIM00850
         BEZ       FINDDWSCOMPARETIX   END-OF-LOOP IF FLINK=0.          TIM00860
*                                                                       TIM00870
         CW,#DWS   1,#XDW+1            IS SPACE BIG ENOUGH?             TIM00880
         BLE       FINDDWSFOUND67      OUT IF SO.                       TIM00890
*                                                                       TIM00900
         LW,#XDW   0,#XDW+1            LINK UP TO NEXT ENTRY.           TIM00910
         BNEZ      FINDDWSCOMPARE      NOT END-OF-LOOP IF NON-ZERO.     TIM00920
*                                                                       TIM00930
FINDDWSCOMPARETIX RES 0                                                 TIM00940
         DO        DO#FINDFROMBOTTOM
         ELSE
         BDR,#TRR  FINDDWSCOMPAAA      IF WE ORIGINALLY BEGAN IN        TIM00950
         FIN
*                                      THE MIDDLE OF THE CHAIN.         TIM00960
*                                                                       TIM00970
FINDDWSNONE RES    0                                                    TIM00980
*                                      HERE WHEN NONE OF THE            TIM00990
*                                      BLOCKS IN THE CHAIN WAS          TIM01000
*                                      LARGE ENOUGH TO SATISFY          TIM01010
*                                      THE REQUEST.  SO WE MUST         TIM01020
*                                      GET SOME MORE SPACE FROM         TIM01030
*                                      UTS AND PUT IT IN THE            TIM01040
*                                      CHAIN AND TRY AGAIN.             TIM01050
*                                                                       TIM01060
         DO        DO#FINDFROMBOTTOM
         LI,#DWA   X'C000'             START AT LOWEST LEGAL
*                                      PAGE OF VIRTUAL MEMORY OR
         ELSE
         LI,#DWA   X'1FE00'            START AT HIGHEST LEGAL           TIM01070
*                                      PAGE OF VIRTUAL MEMORY.          TIM01080
         FIN
*                                                                       TIM01090
         LI,#XDW   #DWA                HERE WE CREATE AN FPT IN         TIM01100
         OR,#XDW   =X'84000000'         A REGISTER TO AVOID A           TIM01110
*                                        FPT CS IN THIS ROUTINE.        TIM01120
*                                                                       TIM01130
*        (WHY WE USED THE DA RETURN REGISTER WILL BECOME                TIM01140
*        CLEAR A FEW LINES DOWN.)                                       TIM01150
*                                                                       TIM01160
FINDDWSGVP CAL1,8  #XDW                M:GVP *#DWA                      TIM01170
         BCR,8     FINDDWSGVPGOT       OVER IF GOT A PAGE.              TIM01180
*                                                                       TIM01190
         DO        DO#FINDFROMBOTTOM
         AI,#DWA   512                 BUMP TO NEXT
         CI,#DWA   X'1FE00'             PAGE AND BACK
         BLE       FINDDWSGVP            IF NOT OFF END.
         LI,#DWA   0                   IF NONE, RETURN A ZERO.
         ELSE
         AI,#DWA   -512                DECREMENT TO NEXT PAGE           TIM01200
         BGZ       FINDDWSGVP          AND BACK TO TRY AGAIN.           TIM01210
*                                                                       TIM01220
*        FALL THROUGH IF THERE JUST ISN'T ANY SPACE.                    TIM01230
*        (NOTE THAT THE ABOVE LOOP BOTH ZEROED #DWA AND                 TIM01240
*        SET THE CONDITION CODES JUST RIGHT!)                           TIM01250
         FIN
*                                                                       TIM01260
         B         *#BAL                                                TIM01270
*                                                                       TIM01280
*                                                                       TIM01290
*                                                                       TIM01300
         PAGE                                                           TIM01310
*                                                                       TIM01320
*                                                                       TIM01330
*                                                                       TIM01340
FINDDWSGVPGOT RES  0                   HERE AFTER GETTING A VIRTUAL PAGETIM01350
*                                                                       TIM01360
*        TO ADD THE NEW VIRTUAL PAGE TO OUR LIST OF FREE                TIM01370
*        PAGES, WE SIMPLY USE OUR OWN #HIDE#DWS ROUTINE.                TIM01380
*                                                                       TIM01390
*        WE AVOID REGISTER PROBLEMS BY STORING ALL OF THE               TIM01400
*        REGISTERS INTO THE BLOCK OF 512 WORDS THAT WE                  TIM01410
*        ARE MANIPULATING!                                              TIM01420
*                                                                       TIM01430
         LCI       0                                                    TIM01440
         STM,0     512-16,#DWA                                          TIM01450
*                                                                       TIM01460
         SLS,#DWA  -1                  CONVERT VIRTUAL WA TO DA         TIM01470
         LI,#DWS   256                 256 DOUBLEWORDS IN THE PAGE.     TIM01480
*                                                                       TIM01490
         BAL,#BAL  #HIDE#DWS                                            TIM01500
*                                                                       TIM01510
         SLS,#DWA  1                   DA BACK TO WA                    TIM01520
*                                                                       TIM01530
         LCI       0                                                    TIM01540
         LM,0      512-16,#DWA         RESTORE OUR REGISTERS            TIM01550
*                                                                       TIM01560
         B         FINDDWS             AND TRY THE WHOLE THING AGAIN    TIM01570
         PAGE                                                           TIM01580
*                                                                       TIM01590
*                                                                       TIM01600
*                                                                       TIM01610
FINDDWSFOUND67 RES 0                                                    TIM01620
         XW,#XDW   #XDW+1              SWAP OUR TWO SCAN REGS           TIM01630
FINDDWSFOUND76 RES 0                   OR NOT.                          TIM01640
*                                                                       TIM01650
*        THE ABOVE ENTRIES MAKE IT SO THAT HERE WE HAVE                 TIM01660
*        THE WA OF THE BLOCK THAT SATISFIES THE CALLERS                 TIM01670
*        NEEDS IN REGISTER #XDW AND WE HAVE THE WA OF THE               TIM01680
*        FLINK THAT POINTS TO IT IN REGISTER #XDW+1.                    TIM01690
*                                                                       TIM01700
         CW,#DWS   1,#XDW              RE-COMPARE                       TIM01710
         BE        FINDDWSEXACT        OVER IF EXACT FIT.               TIM01720
*                                                                       TIM01730
*        HERE ON MORE DOUBLEWORDS IN THE FREE BLOCK THAN THE            TIM01740
*        CALLER WANTS, SO WE LAVE THE BLOCK IN EXISTANCE.               TIM01750
*        WE JUST SHORTEN IT BY THE NUMBER OF DW THE CALLER WANTS.       TIM01760
*                                                                       TIM01770
         DO        DO#FINDFROMBOTTOM
*        IF WE ARE ALLOCATING MEMORY UP FROM THE BOTTOM,
*        WE RETURN TO THE CALLER THE BEGINNING OF THE BLOCK,
*        EVEN THOUGH IT IS EASIER TO RETURN THE END.
*
         LW,#TRR   0,#XDW+1            BUMP FLINK TO
         AW,#TRR   #DWS                 POINT TO WHERE
         AW,#TRR   #DWS                  REMAINDER OF
         STW,#TRR  0,#XDW+1               BLOCK WILL BE.
*
         LW,#XDW+1 #TRR                NOW #XDW POINTS TO START OF
*                                       OLD BLOCK AND #XDW+1 POINTS
*                                        TO START OF NEW BLOCK.
*
         LW,#TRR   0,#XDW              COPY THE FLINK THAT POINTS
         STW,#TRR  0,#XDW+1             TO THE NEXT BLOCK.
*
         LW,#TRR   1,#XDW              DW IN OLD BLOCK.
         SW,#TRR   #DWS                LESS AMOUNT WE ARE GIVING.
         STW,#TRR  1,#XDW+1            IS DW IN NEW BLOCK.
*
         LW,#DWA   #XDW                DA TO RETURN IS JUST
         SLS,#DWA  -1                   DA OF THE OLD BLOCK.
*
         STW,#XDW+1 #FREE#DWS#CHAIN#POINTER POINT US AT NEW BLOCK.
         B         *#BAL               AND RETURN.
*
         ELSE
         LW,#TRR   1,#XDW              GET CURRENT SIZE OF FREE BLOVK   TIM01780
         SW,#TRR   #DWS                DECREMENT BY CALLER'S REQUEST.   TIM01790
         STW,#TRR  1,#XDW              AND REPLACE IT.                  TIM01800
*                                                                       TIM01810
         LW,#DWA   #XDW                CREATE DA TO RETURN              TIM01820
         SLS,#DWA  -1                  (DA INTO A WA)                   TIM01830
         AW,#DWA   #TRR                AS LOB(BLOCK) + NEW SIZE.        TIM01840
*                                                                       TIM01850
         STW,#XDW  #FREE#DWS#CHAIN#POINTER POINT US AT THIS BLOCK.      TIM01860
         B         *#BAL               AND RETURN.                      TIM01870
         FIN
*                                                                       TIM01880
*                                                                       TIM01890
*                                                                       TIM01900
FINDDWSEXACT RES   0                                                    TIM01910
*                                                                       TIM01920
*        HERE ON AN EXACT FIT.  SO WE GIVE THE CALLER                   TIM01930
*        THE WHOLE BLOCK AND REMOVE THE BLOCK FROM THE CHAIN.           TIM01940
*                                                                       TIM01950
         LW,#TRR   0,#XDW              GET FORWARD POINTER.             TIM01960
         STW,#TRR  0,#XDW+1            STORE INTO THE PREVIOUS          TIM01970
*                                      BLOCK'S FLINK IN ORDER TO        TIM01980
*                                      POINT AROUND THIS BLOCK.         TIM01990
*                                                                       TIM02000
         LI,#TRR   0                   LOAD A ZERO AND KILL
         STW,#TRR  #FREE#DWS#CHAIN#POINTER ANY KNUTH POINTER.
*
         LW,#DWA   #XDW                RETURN DA OF THE BLOCK.          TIM02010
         SLS,#DWA  -1                  (WA TO DA)                       TIM02020
*                                                                       TIM02030
         B         *#BAL               AND RETURN WITH CORRECT CC.
         PAGE                                                           TIM02080
*                                                                       TIM02090
*                                                                       TIM02100
*                                                                       TIM02110
#HIDE#DWS RES      0                                                    TIM02120
HIDEDWS  RES       0                                                    TIM02130
*                                                                       TIM02140
*        HERE TO PUT WORDS INTO THE FREE SPACE CHAIN.                   TIM02150
*                                                                       TIM02160
*        NOTE THAT IT DOESN'T HAVE TO BE SPACE THAT WAS                 TIM02170
*        ORIGINALLY IN THE CHAIN - COMPLETELY NEW SPACE MAY             TIM02180
*        BE FREED OR SPACE THAT WAS OBTAINED MAY BE FREED               TIM02190
*        IN SEVERAL PIECES.                                             TIM02200
*                                                                       TIM02210
*        ON ENTRY:                                                      TIM02220
*                  REG #DWA = DA OF THE SPACE                           TIM02230
*                  REG #DWS = NUMBER OF DOUBLEWORDS AT THAT DA          TIM02240
*                                                                       TIM02250
*                                                                       TIM02260
*                                                                       TIM02270
*        WE SCAN UP THE FREE CHAIN (WHICH IS IN ADDRESS                 TIM02280
*        ORDER) UNTIL WE FIND WHERE TO INSERT THIS BLOCK.               TIM02290
*                                                                       TIM02300
*        FIRST SEE THAT CALLER ISN'T TRYING TO RETURN                   TIM02310
*        LESS THAN ONE DOUBLEWORD:                                      TIM02320
*                                                                       TIM02330
         AI,#DWS   0                   SET CC AND                       TIM02340
         BLEZ      *#BAL                OUT IF NO DWS.                  TIM02350
*                                                                       TIM02360
*        SINCE WE USUALLY HAVE A POINTER TO SOMEWHERE IN THE MIDDLE     TIM02370
*        OF THE FREE CHAIN REMEMBERED IN #FREE#DWS#CHAIN#POINTER,       TIM02380
*        WE FIRST TEST TO SEE IF WE CAN BEGIN THE SEARCH AT             TIM02390
*        THAT POINT:                                                    TIM02400
*                                                                       TIM02410
         LW,#TRR   #DWA                CREATE IN TEMP REGISTER THE      TIM02420
         SLS,#TRR  1                    WORD ADDRESS OF THE CALLER'S.   TIM02430
*                                                                       TIM02440
         LW,#XDW+1 #FREE#DWS#CHAIN#POINTER RETRIEVE POINTER TO MIDDLE.  TIM02450
         BEZ       HIDEDWSBEGIN        OVER IF NO REMEMBERED POS.       TIM02460
         LW,#XDW   0,#XDW+1            GET A BLOCK IN THE CHAIN.        TIM02470
         BEZ       HIDEDWSBEGIN        OVER IF AT CHAIN END.            TIM02480
*                                                                       TIM02490
         CW,#TRR   #XDW                COMPARE ADDRESSES.               TIM02500
         BG        HIDEDWSSCANSEVEN    OVER IF CALLER'S BLOCK IS        TIM02510
*                                      PAST THE POINTER; THAT           TIM02520
*                                      MEANS WE CAN USE THE             TIM02530
*                                      POINTER'S POSITION TO            TIM02540
*                                      START OUR SEARCH.                TIM02550
         BE        HIDEDWSERROR        EQUAL IS ERROR.                  TIM02560
*                                                                       TIM02570
HIDEDWSBEGIN RES   0                                                    TIM02580
         LW,#XDW   #FREE#DWS#CHAIN#HEAD POINTER WASN'T USEFUL -         TIM02590
         BEZ       HIDEDWSEMPTY        (SPECIAL FOR NO CHAIN)           TIM02600
         LI,#XDW+1 #FREE#DWS#CHAIN#HEAD SO USE CHAIN HEAD.              TIM02610
*                                                                       TIM02620
HIDEDWSSCAN RES    0                                                    TIM02630
         CW,#TRR   #XDW                COMPARE ADDRESSES.               TIM02640
         BLE       HIDEDWSBLED76       OUT IF THE RIGHT PLACE.          TIM02650
*                                                                       TIM02660
HIDEDWSSCANSEVEN RES 0                                                  TIM02670
         LW,#XDW+1 0,#XDW              CHAIN DOWN THE CHAIN.            TIM02680
         BEZ       HIDEDWSSCANEND76    OUT IF END-OF-CHAIN.             TIM02690
*                                                                       TIM02700
         CW,#TRR   #XDW+1              COMPARE ADDRESSES.               TIM02710
         BLE       HIDEDWSBLED67       OUT IF AT THE RIGHT PLACE.       TIM02720
*                                                                       TIM02730
         LW,#XDW   0,#XDW+1            CHAIN DOWN THE CHAIN.            TIM02740
         BNEZ      HIDEDWSSCAN         LOOP IF NOT AT THE END.          TIM02750
         B         HIDEDWSSCANEND67    OUT IF END-OF-CHAIN.             TIM02752
*                                                                       TIM02760
HIDEDWSSCANEND76 RES 0                                                  TIM02770
         XW,#XDW   #XDW+1                                               TIM02780
HIDEDWSSCANEND67 RES 0                                                  TIM02790
*                                                                       TIM02800
*        WHEN HERE, REGISTER #XDW+1 CONTAINS THE WA OF THE              TIM02810
*        LAST BLOCK IN THE FREE CHAIN, AND REGISTER #XDW                TIM02820
*        CONTAINS C(0,#XDW+1), WHICH IS ZERO.                           TIM02830
*                                                                       TIM02840
*        SEE IF THE END OF THE LAST BLOCK OF THE FREE CHAIN             TIM02850
*        ABUTS THE START OF THE BLOCK THE CALLER'S FREEING:             TIM02860
*                                                                       TIM02870
         LW,#TRR   #XDW+1              ADDRESS OF THE FREE BLOCK        TIM02880
         SLS,#TRR  -1                  CONVERTED TO A DA                TIM02890
         AW,#TRR   1,#XDW+1            PLUS ITS LENGTH:                 TIM02900
         CW,#DWA   #TRR                COMPARE CALLER'S DA WITH END-OF-BTIM02910
         BE        HIDEDWSADDTOLAST    OUT IF EQUAL= ABUTTING.          TIM02920
         BL        HIDEDWSERROR        ERROR IF OVERLAPPING.            TIM02930
*                                                                       TIM02940
*        WHEN HERE, CALLER'S BLOCK DOESN'T ABUT OUR                     TIM02950
*        LAST BLOCK, SO WE CAN'T MERGE THEM.  THEREFORE                 TIM02960
*        WE MAKE A NEW CHAIN ENTRY WITH THE CALLER'S BLOCK.             TIM02970
*                                                                       TIM02980
         SLS,#DWA  1                   CALLER'S DA TO A WA.             TIM02990
         STW,#DWS  1,#DWA              STORE DW COUNT INTO BLOCK.       TIM03000
         LI,#TRR   0                   A ZERO FLINK                     TIM03010
         STW,#TRR  0,#DWA              INTO THE BLOCK.                  TIM03020
         STW,#DWA  0,#XDW+1            ADD BLOCK TO CHAIN.              TIM03030
*                                                                       TIM03040
         STW,#DWA  #FREE#DWS#CHAIN#POINTER ESTABLISH NEW KNUTH PTR.     TIM03050
*                                                                       TIM03060
         SLS,#DWA  -1                  RE-CREATE CALLER'S DA.           TIM03070
         B         *#BAL               AND RETURN.                      TIM03080
         PAGE                                                           TIM03090
*                                                                       TIM03100
*                                                                       TIM03110
*                                                                       TIM03120
HIDEDWSEMPTY RES   0                                                    TIM03130
*                                      HERE WHEN THE CHAIN              TIM03140
*                                      IS TOTALLY EMPTY.                TIM03150
         SLS,#DWA  1                   CALLER'S DA TO A WA.             TIM03160
         STW,#DWS  1,#DWA              STORE DW COUNT INTO BLOCK.       TIM03170
         STW,#XDW  0,#DWA              ZERO FLINK (#XDW=0 FROM ABOVE)   TIM03180
         STW,#DWA  #FREE#DWS#CHAIN#HEAD HEAD THE NEW CHAIN.             TIM03190
         SLS,#DWA  -1                  CALLER'S REGISTER BACK TO DA.    TIM03200
*                                                                       TIM03210
         B         *#BAL               AND RETURN.                      TIM03220
         PAGE                                                           TIM03230
*                                                                       TIM03240
*                                                                       TIM03250
*                                                                       TIM03260
HIDEDWSADDTOLAST RES 0                                                  TIM03270
*                                                                       TIM03280
*        HERE WHEN THE CALLER'S BLOCK ABUTS THE LAST                    TIM03290
*        BLOCK IN THE CHAIN.  SO JUST INCREMENT THE                     TIM03300
*        CHAIN BLOCK'S SIZE.                                            TIM03310
*                                                                       TIM03320
         AWM,#DWS  1,#XDW+1            INCREMENT BLOCK'S SIZE.          TIM03330
*                                                                       TIM03340
         B         *#BAL               AND RETURN.                      TIM03350
         PAGE                                                           TIM03360
*                                                                       TIM03370
*                                                                       TIM03380
*                                                                       TIM03390
HIDEDWSBLED67 RES  0                                                    TIM03400
         XW,#XDW   #XDW+1              SWAP THE TWO POINTERS            TIM03410
HIDEDWSBLED76 RES  0                   OR DON'T.                        TIM03420
*                                                                       TIM03430
*        HERE WHEN THE NEW BLOCK FROM THE CALLER IS                     TIM03440
*        BETWEEN TWO BLOCKS IN THE CHAIN.  THIS IS                      TIM03450
*        MEANT TO INCLUDE THE CASE OF WHEN IT IS                        TIM03460
*        'BETWEEN' THE HEAD POINTER AND THE FIRST BLOCK.                TIM03470
*                                                                       TIM03480
*        NOW REGISTER #XDW CONTAINS THE WA OF THE BLOCK                 TIM03490
*        WHOSE ADDRESS IS HIGHER THAN THE CALLER'S BLOCK AND            TIM03500
*        REGISTER #XDW+1 CONTAINS THE WA OF THE BLOCK WHOSE             TIM03510
*        ADDRESS IS LOWER.                                              TIM03520
*        AND THEREFORE C(0,#XDW+1) = C(#XDW)                            TIM03530
*                                                                       TIM03540
*        SEE IF THE LOWER BLOCK ABUTS THE CALLER'S:                     TIM03550
         LW,#TRR   #XDW+1              ADDRESS OF LOWER BLOCK           TIM03560
         SLS,#TRR  -1                  CONVERT TO A DA.                 TIM03570
         AW,#TRR   1,#XDW+1            ADD IN THE DW COUNT.             TIM03580
         CW,#DWA   #TRR                COMPARE WITH DA OF CALLER'S.     TIM03590
         BNE       HIDEDWSBLEDNOTLOWER OVER IF NOT ABUTTING.            TIM03600
*        IMPORTANT NOTE HERE:  NORMALLY ONE WOULD EXPECT                TIM03610
*        THAT THE ABOVE 'BNE' WOULD BE REPLACED BY A 'BG'               TIM03620
*        AND THEN THERE WOULD BE A 'BL HIDEDWSERROR' WHICH              TIM03630
*        WOULD CATCH OVERLAPPING BLOCKS.  THIS CANNOT BE                TIM03640
*        DONE HERE BECAUSE THE LOWER 'BLOCK' - THE ONE                  TIM03650
*        POINTER TO BY #XDW+1 - MAY ACTUALLY BE THE FAKE                TIM03660
*        BLOCK AT '#FREE#DWS#CHAIN#HEAD'.  WE COULD HAVE                TIM03670
*        PUT IN A SPECIAL TEST FOR THAT, BUT IT'S EASIER                TIM03680
*        TO JUST NOT MAKE THE OVERLAP TEST.                             TIM03690
*                                                                       TIM03700
*                                                                       TIM03710
*        HERE FOR MERGE OF THE CALLER'S BLOCK WITH                      TIM03720
*        THE BLOCK POINTER TO BY REGISTER #XDW+1.                       TIM03730
*                                                                       TIM03740
         AWM,#DWS  1,#XDW+1            JUST ADD IN THE DW COUNT.        TIM03750
         B         HIDEDWSMERGEABOVE AND FORWARD TO NEXT MERGE.         TIM03760
*                                                                       TIM03770
*                                                                       TIM03780
*                                                                       TIM03790
HIDEDWSBLEDNOTLOWER RES 0                                               TIM03800
*                                                                       TIM03810
*        HERE IF THE CALLER'S BLOCK DOESN'T ABUT                        TIM03820
*        THE LOWER ONE.  FIRST MAKE IT INTO A FREE                      TIM03830
*        BLOCK (BY PUTTING IN APPROPRIATE VALUESINTO                    TIM03840
*        THE FIRST DW OF THE BLOCK) AND THEN CHAIN                      TIM03850
*        IT INTO THE CHAIN.                                             TIM03860
*                                                                       TIM03870
         LW,#TRR   #DWA                ADDRESS OF CALLER'S BLOCK.       TIM03880
         SLS,#TRR  1                   CONVERT TO A WA.                 TIM03890
         STW,#TRR  0,#XDW+1            POINT LOWER BLOCK T US.          TIM03900
         STW,#TRR  #XDW+1              MAKE US THE LOWER BLOCK          TIM03910
*                                       FROM THE POINT OF VIEW          TIM03920
*                                        OF THIS ROUTINE'S CODE.        TIM03930
         STW,#XDW  0,#XDW+1            FLINK INTO NEW BLOCK.            TIM03940
         STW,#DWS  1,#XDW+1            COUNT INTO NEW BLOCK.            TIM03950
*                                                                       TIM03960
*                                                                       TIM03970
*                                                                       TIM03980
HIDEDWSMERGEABOVE RES 0                                                 TIM03990
*                                                                       TIM04000
*        SEE IF THE END OF THE BLOCK AT C(#XDW+1) IS THE                TIM04010
*        ABUTS THE BLOCK AT C(#XDW).                                    TIM04020
*                                                                       TIM04030
         LW,#TRR   #XDW+1              ADDRESS OF LOWER BLOCK.          TIM04040
         AW,#TRR   1,#XDW+1            ADD IN THE DW COUNT.             TIM04050
         AW,#TRR   1,#XDW+1            (ADD DW COUNT IN TWICE FOR W COUNTIM04060
         CW,#TRR   #XDW                COMPARE WITH WA OF HIGHER.       TIM04070
         BL        *#BAL               DONE IF NO ABUT.                 TIM04080
*                                                                       TIM04090
         BG        HIDEDWSERROR        ERROR IF OVERLAPPING.            TIM04100
*                                                                       TIM04110
*        FALL THROUGH TO MERGE THESE TWO BLOCKS.                        TIM04120
*                                                                       TIM04130
         LW,#TRR   0,#XDW              GET FORWARD LINK POINTER.        TIM04140
         STW,#TRR  0,#XDW+1            AND COPY IT BACK.                TIM04150
         LW,#TRR   1,#XDW              GET COUNT OF BLOCK TO BE MERGED. TIM04160
         AWM,#TRR  1,#XDW+1            AND ADD IT IN TO LOWER BLOCK.    TIM04170
*                                                                       TIM04180
         STW,#XDW+1 #FREE#DWS#CHAIN#POINTER ESTABLISH NEW KNUTH PTR.    TIM04190
         B         *#BAL               AND RETURN.                      TIM04200
*                                                                       TIM04210
*                                                                       TIM04220
*                                                                       TIM04230
HIDEDWSERROR DATA 0                                                     TIM04240
*                                                                       TIM04250
*                                                                       TIM04260
*                                                                       TIM04270
*        DEFINE 'LOCAL' STORAGE:                                        TIM04280
*                                                                       TIM04290
         BOUND     8                                                    TIM04300
#FREE#DWS#CHAIN#HEAD RES 0                                              TIM04310
         DATA      0                                                    TIM04320
         DATA      0                                                    TIM04330
*                                                                       TIM04340
#FREE#DWS#CHAIN#POINTER RES 0                                           TIM04350
         DATA      0                                                    TIM04360
*                                                                       TIM04370
*                                                                       TIM04380
*                                                                       TIM04390
         END                                                            TIM04400

