
      HED MLOCK OVERLAY 
* THE MLOCK OVERLAY DOES ALL THE WORK FOR MLOCK. IT USES THE TABLE
* BUILT BY MLOCK AND PROCEEDS AS FOLLOWS: 
* 
*     1)  UPDATE LOCKED BLOCKS TABLE. 
*     2)  UPDATE THE DIRECTORY BY REMOVING ENTRIES WHOSE DISC 
*         ADDRESSES LIE IN THE RANGE OF THE BLOCKS TO BE LOCKED.
*     3)  UPDATE THE ADT WITH DRUM SPACE RETURNED FROM SANCTIFIED 
*         PROGRAMS AND FILES WHICH HAVE BEEN REMOVED. 
*     4)  UPDATE THE IDT WITH SPACE RETURNED FROM DELETED PROGRAMS
*         AND FILES.
*     5)  UPDATE DISC ADT BY REMOVING ENTRIES WHICH ARE IN THE RANGE
*         OF THE BLOCKS TO BE LOCKED. 
* 
*  ISN'T THIS A RIDICULOUS AMOUNT OF THRASHING? 
* 
      ORG LIBRA 
      LDA M256      LENGTH OF 
      STA MWORD       BAD BLOCKS
      DLD MLKLP,I 
      CLE,ERA 
      ERB,CLE 
      ADB .+3       RESIDES ON BLOCK 3
      SEZ 
      INA 
      DST MLKIN 
      LDA MLKIP     READ BAD
      LDB LIBDI       BLOCKS
      JSB DISCZ,I       TABLE 
      JMP DDERR 
* 
**  UPDATE LOCKED BLOCKS TABLE
* 
      LDB LIBD      => FIRST ENTRY
MLK71 EQU * 
      LDA B,I 
      SZA,RSS       FINISHED SEARCH?
      JMP MLK81     YES, GO INSERT AT END 
      CMA,CLE,INA   THIS
      ADA MLKFA       ENTRY 
      SZA,RSS           EQUAL?
      JMP MLK73     YES 
      SEZ,RSS       NO, GREATER?
      JMP MLK78     YES 
      ADB .+2       NO, TABLE 
      CPB MLKLZ       FULL? 
      RSS           YES 
      JMP MLK71     NO, LOOP
      JSB MLKPB     CHECK PRECEEDING BLOCK
      JMP MLK82     ENTRIES MERGED
MLK72 EQU * 
      CLF 0 
      CLA 
      STA LIB       NO ROUTINE IN CORE
      JMP MLFLA,I   OUTPUT TABLE FULL MESSAGE 
MLK73 EQU * 
      INB 
      LDA MLKLN     IS THE
      CMA,CLE,INA     NEW 
      ADA B,I           BLOCK 
      SEZ                 LONGER? 
      JMP MLK99     NO
      LDA MLKLN     YES, RESET
      STA B,I         LENGTH
      INB 
MLK74 EQU * 
      CPB MLKLZ     END OF TABLE? 
      JMP MLK82     YES 
      LDA B,I       ALL ENTRIES 
      SZA,RSS         FINISHED? 
      JMP MLK82     YES 
      ADB .-2       NO
      LDA B,I       DOES THIS 
      INB 
      ADA B,I         ENTRY 
      CMA,CLE 
      INB               OVERLAP THE 
      ADA B,I 
      SEZ,INB             NEXT ONE? 
      JMP MLK82     NO
      ADA B,I       YES, ENCLOSE
      SEZ,INA,RSS     THE ENTRY?
      JMP MLK75     YES 
      ADB .-2         NEW LENGTH
      ADA B,I           AND SAVE
      STA B,I 
      INB,RSS 
MLK75 EQU * 
      ADB .-1 
      STB MLKBR     SAVE (B)
      STB MLKPP     DESTINATION POINTER 
      ADB .+2       SOURCE POINTER
MLK76 EQU * 
      CPB MLKLZ 
      JMP MLK77 
      LDA B,I       MOVE
      SZA,RSS 
      JMP MLK77       TABLE,
      STA MLKPP,I 
      ISZ MLKPP         ELIMINATING 
      INB 
      JMP MLK76           ONE ENTRY 
MLK77 EQU * 
      CLA 
      STA MLKPP,I   ZERO TWO
      ISZ MLKPP       WORDS AFTER 
      STA MLKPP,I       LAST ENTRY
      LDB MLKBR     RESTORE (B) 
      JMP MLK74     GO CHECK NEXT ENTRY 
MLK78 EQU * 
      JSB MLKPB     CHECK PRECEEDING BLOCK
      JMP MLK74     GO CHECK NEXT ENTRY 
      STB MLKBR     SAVE (B)
      LDB MLKLY     TABLE 
      LDA B,I 
      SZA             FULL? 
      JMP MLK72     YES 
      STB MLKPP     DESTINATION POINTER 
      ADB .-2       SOURCE POINTER
MLK79 EQU * 
      LDA B,I       MOVE
      STA MLKPP,I 
      CPB MLKBR       TABLE,
      JMP MLK80 
      ADB .-1           MAKING
      CCA 
      ADA MLKPP           ROOM FOR
      STA MLKPP 
      JMP MLK79        NEW ENTRY
MLK80 EQU * 
      LDA MLKFA     INSERT
      STA B,I 
      INB             NEW 
      LDA MLKLN 
      STA B,I           ENTRY 
      JMP MLK74-1   GO CHECK NEXT ENTRY 
MLK81 EQU * 
      JSB MLKPB     CHECK PRECEEDING BLOCK
      JMP MLK82     ENTRIES MERGED
      LDA MLKFA     INSERT
      STA B,I 
      INB             NEW ENTRY 
      LDA MLKLN 
      STA B,I           AT TABLE END
MLK82 EQU * 
      LDA MLKIP     WRITE OUT 
      LDB LIBD        LOCKED BLOCKS 
      JSB DISCZ,I       TABLE 
      JSB MDEDP,I 
* 
*                      *
**  UPDATE DIRECTORY  **
*                      *
* 
*  USING THE TABLE BUILT PREVIOUSLY, REMOVE EACH REFERENCED ENTRY.
*  REPLACE THE FIRST TWO WORDS OF THE TABLE BY THE ID AND LENGTH IN 
*  +BLOCKS FOR USE IN UPDATING THE IDT. FOR SANCTIFIED ENTRIES, 
*  REPLACE THE THIRD AND FOURTH WORDS BY THE DRUM ADDRESS AND LENGTH
*  IN +SECTORS FOR USE IN UPDATING THE ADT. SET THE THIRD WORD TO 
*  ZERO FOR NON-SANCTIFIED ENTRIES. 
      LDA MLKTC     SKIP UPDATE 
      SZA,RSS         IF NO 
      JMP MLK59         ENTRIES 
      STA MLKCT 
      LDB L8192     POINTER TO
      STB MLKTP       FIRST ONE 
MLK40 EQU * 
      LDB MLKTP,I   SAVE DIREC
      STB MLKDI       POINTER 
      LDA B,I       WORD
      STA MWORD       COUNT 
      CMA,INA       COMPUTE END 
      ADA LIBD        OF DIRECTORY
      STA MLKND         BUFFER
      ADB .+5       READ
      LDA B 
      LDB LIBDI       DIRECTORY 
      JSB DISCZ,I 
      JSB DEADP,I   CAN'T DO IT 
      LDB LIBD      INITIALIZE
      STB MOVES       MOVE
      STB MOVED         POINTERS
MLK41 EQU * 
      LDA MLKTP 
      INA           => DIRECTORY ENTRY
      LDB A,I 
      ADB .-8       => ID WORD
      ADA .-1 
      STA MLKTP 
      LDA B,I       SAVE ID 
      STA MLKTP,I     IN TABLE
      STB MLKBR     SAVE POINTER FOR MOVE 
      ISZ MLKTP 
      ADB .+11
      LDA B,I       GET LENGTH
      SSA,RSS       CONVERT 
      JMP *+4 
      ALF,ALF         TO BLOCKS 
      IOR HIMSK 
      CMA,INA           AND SAVE
      STA MLKTP,I 
      ISZ MLKTP      IN TABLE 
      CLA 
      STA MLKTP,I 
      ISZ MLKTP 
      ISZ MLKTP 
* 
* MOVE PORTION OF DIRECTORY 
* 
      LDB MLKBR     COMPUTE 
      CMB,INB         NUMBER
      ADB MOVES         OF WORDS
      JSB MOVEW 
      LDB MLKBR     UPDATE
      ADB .+12
      STB MOVES       POINTER 
      LDA MLKDI,I   UPDATE
      ADA .+12        DIRECTORY 
      STA MLKDI,I       LENGTH
      ISZ MLKCT     FINISHED TABLE? 
      RSS           NO
      JMP MLK43     YES 
      LDB MLKTP,I   GET NEXT DIREC ENTRY FROM TABLE 
      CPB MLKDI     SAME DIRECTORY TRACK? 
      JMP MLK41     YES 
MLK43 EQU * 
      LDB MLKND     NO, MOVE END
      CMB,INB 
      ADB MOVES       OF DIRECTORY
      JSB MOVEW 
      LDB MLKDI 
      LDA B,I 
      STA MWORD 
      INB 
      STB MOVED 
      ADB .+4 
      LDA B         WRITE 
      LDB LIBD        OUT 
      STB MOVES 
      JSB DISCZ,I       DIRECTORY 
      JSB DEADP,I   MUERTO
      LDB .-4       RESET 
      JSB MOVEW       DIREC 
      LDA MLKCT     FINISHED
      SZA             TABLE?
      JMP MLK40     NO
* 
**  UPDATE DISC ADT 
* 
MLK59 EQU * 
      JSB FADTP,I   GET THIS DISC ADT 
      LDA MLKN,I
      STA MWORD 
      LDA MLKAD     READ
      LDB LIBDI       DISC
      JSB DISCZ,I       ADT 
      JSB DEADP,I 
      DLD MLKFB     COMPUTE 
      DST MLKIN       THIS ENTRY
MLK57 EQU * 
      LDB MLKRD     GET POINTER TO SPECIAL TABLE
      CPB MLKRP     END OF TABLE? 
      JMP MLK58     YES 
      ADB .-1 
      LDA B,I       GET LENGTH
      STA MLKBR 
      ADB .-1 
      LDA B,I       SECOND WORD OF DISC ADDRESS 
      STA MLKFB+1 
      ADB .-1 
      LDA B,I       FIRST WORD OF DISC ADDRESS
      STA MLKFB 
      STB MLKRD     TABLE POINTER 
      JSB RBAD,I    RETURN SPACE TO DISC ADT
      JMP MLK57 
MLK58 EQU * 
      DLD MLKIN     RESTORE 
      DST MLKFB       MLKFB 
      LDA MLKN,I    COMPUTE 
      CMA,INA         END OF
      ADA LIBD          TABLE 
      STA MLKND           BUFFER
      LDB LIBD      INITIALIZE
      STB MLKTP       TABLE POINTER 
MLK60 EQU * 
      DLD MLKTP,I       -STARTING 
      JSB MLKTW           BLOCK 
      SZA,RSS 
      SZB           EQUAL?
      RSS           NO
      JMP MLK61     YES 
      SSA           GREATER?
      JMP MLK65     YES 
      LDB MLKTP     UPDATE
      ADB .+3         TABLE 
      STB MLKTP         POINTER 
      CPB MLKND     END OF TABLE? 
      RSS           YES 
      JMP MLK60     NO
      JSB MLKPE     CHECK PRECEEDING ENTRY
      JMP MLK64     MERGED
      JMP MLK98     NO WORK DONE
MLK61 EQU * 
      LDB MLKTP 
      ADB .+2 
      LDA MLKLN     IS THIS 
      CMA,CLE         ENTRY 
      ADA B,I           COMPLETELY
      SEZ,INA,RSS         ENCLOSED? 
      JMP MLK62     YES 
      STA B,I         NEW LENGTH
      JMP MLK67 
MLK66 EQU * 
      LDB MLKTP     UPDATE
      ADB .-2         TABLE 
      STB MLKTP         POINTER 
MLK62 EQU * 
      LDB MLKTP     SET UP
      STB MOVED       POINTERS
      ADB .+3           FOR 
      STB MOVES           MOVE
      LDA MLKND     COMPUTE 
      CMA,INA         LENGTH
      ADB A             OF MOVE 
      JSB MOVEW     ELIMINATE ENTRY 
      LDB MLKN,I    UPDATE
      ADB .+3         DISC ADT
      STB MLKN,I        LENGTH
      LDB MLKND     UPDATE END- 
      ADB .-3         OF TABLE
      STB MLKND         POINTER 
MLK63 EQU * 
      LDB MLKTP     END OF
      CPB MLKND       TABLE?
      JMP MLK64     YES 
      DLD MLKTP,I   NO, 
      DST MLKIN       OVERLAP 
      DLD MLKLB         NEXT
      JSB MLKTW           ENTRY?
      SSA,RSS 
      JMP MLK64     NO
      ISZ MLKTP     YES,
      ISZ MLKTP       COMPLETELY
      CLE               ENCLOSE 
      ADB MLKTP,I         IT? 
      SZB,RSS 
      JMP MLK66     YES 
      SEZ,RSS       MAYBE 
      JMP MLK66     YES 
      STB MLKTP,I   NO, SAVE LENGTH 
      LDB MLKTP 
      ADB .-2 
      STB MLKTP       STARTING
MLK67 EQU * 
      DLD MLKLB 
      DST MLKTP,I       BLOCK 
MLK64 EQU * 
      LDA MLKN,I    WRITE 
      STA MWORD 
      LDA MLKAD       ADT 
      LDB LIBD
      JSB DISCZ,I       TO DISC 
      JSB DEADP,I 
* 
MLK98 EQU * 
      LDA MLKTC     ANY TABLE ENTRIES 
      STA LTEMP+5 
      SZA 
      JSB RTID,I    YES, UPDATE IDT 
* 
MLK99 EQU * 
      CLF 0 
      CLA 
      STA LIB 
      JMP LEND
MLK65 EQU * 
      JSB MLKPE     CHECK PRECEEDING ENTRY
      JMP MLK63     GO CHECK
      JMP MLK63       SUCCEEDING ENTRY
* 
* MLKPB CHECKS THE PRECEEDING BLOCK TO SEE IF THE NEW ENTRY IS IN 
* ITS RANGE. IF SO, IT MODIFIES THE PRECEEDING ENTRY AND RETURNS
* TO (P+1), OTHERWISE TO (P+2). 
* 
MLKPB NOP 
      CPB LIBD      BEGINNING OF TABLE? 
      JMP MLKP1     YES 
      ADB .-1       NO, NEW 
      LDA B,I 
      ADB .-1       BLOCK IN
      ADA B,I 
      CMA,CLE           RANGE OF
      ADA MLKFA 
      SEZ                 PRECEEDING ONE? 
      JMP MLKP1-1   NO
      LDA B,I       YES, COMPUTE
      CMA,INA 
      ADA MLKLA       NEW LENGTH
      INB 
      STA MLKXB 
      CMA,CLE,INA 
      ADA B,I       BIGGER THAN 
      SEZ             PREVIOUS LENGTH?
      JMP *+3        NO 
      LDA MLKXB     YES, SAVE NEW 
      STA B,I         LENGTH
      INB           RESTORE (B) 
      JMP MLKPB,I 
      ADB .+2       RESTORE (B) 
MLKP1 EQU * 
      ISZ MLKPB 
      JMP MLKPB,I   EXIT TO (P+2) 
* 
* 
MLKPE NOP 
      DLD MLKFB     FOR SUBTRACT
      DST MLKIN       ROUTINE 
      LDA MLKTP     BEGINNING 
      CPA LIBD        OF TABLE? 
      JMP MLKE1     YES 
      ADA .-1       NO
      LDB A,I       SAVE
      STB MLKXB       LENGTH
      ADA .-2       SAVE
      STA MLKTP       POINTER 
      LDA MLKTP,I   IS THE NEW
      ISZ MLKTP 
      CLE             BLOCK IN
      ADB MLKTP,I 
      SEZ               RANGE OF THE
      INA 
      JSB MLKTW           PRECEEDING ONE? 
      ISZ MLKTP 
      SSA 
      JMP MLKE2     YES 
      ISZ MLKTP 
MLKE1 EQU * 
      ISZ MLKPE 
      JMP MLKPE,I 
MLKE2 EQU * 
      LDA MLKTP     COMPUTE 
      ADA .-2 
      DLD A,I         NEW LENGTH
      JSB MLKTW 
      STB MLKTP,I       AND SAVE
      LDB MLKTP 
      ADB .-2 
      STB MLKTP 
      DLD MLKTP,I   IS THE
      CLE 
      ADB MLKXB       UNLOCKED
      SEZ 
      INA               PORTION 
      DST MLKIN           IN THE MIDDLE 
      DLD MLKLB 
      JSB MLKTW             OF THE PREVIOUS 
      SZA,RSS 
      SZB                     BLOCK?
      RSS 
      JMP MLKE3     NO
      SSA           MAYBE 
      JMP MLKE3     NO
      STB MLKXB     YES 
      LDB MLKND     TABLE 
      CPB ML819       FULL? 
      JMP MLKE3     YES 
      STB MOVES 
      ADB .+3       SET UP
      STB MOVED 
      STB MLKND       FOR 
      ADB .-5 
      CMB,INB           MOVE
      ADB MLKTP 
      JSB MOVEB     MAKE ROOM FOR NEW ENTRY 
      LDB MLKN,I    UPDATE
      ADB .-3         DISC ADT
      STB MLKN,I        LENGTH
      LDB MLKTP     UPDATE
      ADB .+3         TABLE 
      STB MLKTP         POINTER 
      DLD MLKLB     SAVE ADDRESS
      DST MLKTP,I     OF NEW ENTRY
      LDB MLKTP     SAVE
      ADB .+2 
      LDA MLKXB       LENGTH
      STA B,I 
      INB               ALSO
      STB MLKTP 
      JMP MLKPE,I 
MLKE3 EQU * 
      LDB MLKTP     RESTORE 
      ADB .+3         TABLE 
      STB MLKTP         POINTER 
      JMP MLKPE,I 
MLKLZ DEF LIBUS+256 
MLKLY DEF LIBUS+255 
ML819 DEF LIBUS+8190
$$MLO EQU * 
