      HED PURGE OVERLAY 
* PURFX IS CALLED WHENEVER THE PATCH TABLE HAS REACHED ITS LIMIT. 
* THIS ROUTINE FIRST UPDATES IDT BY DECREASING THE "DISC USED" ENTRY
* IN EACH IDT ENTRY REFERENCED BY A PATCH. IT THEN BUILDS A NEW ADT 
* BASED ON THE RELEASED DISC SPACE. 
      SPC 2 
      ORG LIBRA 
      LDA MOVED 
      LDB MOVES 
      DST PURM
      LDA IDTTA     INPUT FIRST 
      ADA .+3         ID TRACK
      STA IDTRA 
      LDB IDTRL 
      ADB .+3 
      STB IDTLA 
      LDB 1,I 
      STB WORD
      LDB LIBDI 
      LDA 0,I 
      JSB DISCL 
      LDB LIBD     SET FIRST ENTRY
      LDA PURP     COPY PURP
PURX1 STA PURPP    DONE WITH
      CPA USEND           IDT?
      JMP PURX2       YES 
      LDA PURPP,I 
      CPA 1,I      FOUND IDT ENTRY? 
      JMP PURX5    YES
      CPB LIBD     END OF ID TRACK? 
      JMP PUR.4    YES
      ADB .-8      NO - GO BACK 
      JMP *-5 5W
PUR.4 LDA IDTRL,I 
      STA WORD     OUTPUT ID TRACK
      LDA IDTRA,I 
      LDB LIBD
      JSB DISCL 
      LDA PURPP,I  RELOAD ID
      STA ID
      JSB FIDT     SEARCH ID TRACKS FOR ID ENTRY
PURX5 EQU * 
* 
      ADB .+7       UPDATE IDT ENTRY. 
      ISZ PURPP 
      ISZ PURPP 
      LDA PURPP,I   GET LENGTH. 
      CMA,INA       SUBTRACT FROM IDT ENTRY.
      ADA 1,I 
      STA 1,I 
      ADB .-7       RESTORE IDT POINTER.
      LDA PURPP     BUMP PATCH POINTER. 
      INA 
      JMP PURX1 
* 
PURX2 LDA IDTRA,I  WRITE BACK IDT 
      LDB LIBD
      JSB DISCL 
* 
      LDA ADLEN     READ IN ADT.
      STA WORD
      LDA ADLOC 
      LDB LIBDI 
      JSB DISCL 
* 
PURX3 LDA PURP      IS PATCH TABLE EMPTY? 
      CPA USEND 
      JMP PURX4     YES--GO WRITE ADT.
      ISZ PURP      PURP=>DISC ADR OF PATCH.
      LDB LIBD      SEARCH ADT FOR AN ENTRY BEYOND
PUR.1 EQU * 
      LDA 1,I     STANDARD ADT TABLE SEARCH     [X] 
      AND DHMSK                                  X] 
      STA LTEMP+14                               X] 
      LDA PURP,I
      AND DHMSK                                   X]
      CPA LTEMP+14                                X]
      JMP PUR.2                                   X]
      ADB .+2                                     X]
      JMP PUR.1                                  X] 
PUR.2 LDA 1,I                                    X] 
      CMA,CLE,INA                                X] 
      ADA PURP,I                                 X] 
      ADB .+2 
      SEZ,RSS                                    X] 
      JMP PUR.3                                  X] 
      LDA 1,I                                    X] 
      AND DHMSK                                  X] 
      CPA LTEMP+14                               X] 
      JMP PUR.2                                  X] 
      ADB .+2                             (L) 
PUR.3 EQU *                                      X] 
* 
* TRY  TO  MERGE WITH NEXT ENTRY
* 
      ISZ PURP
      ADA PURP,I
      SZA 
      JMP PURX6     CAN'T DO IT.
      ADB .-1       COMBINE 
      LDA 1,I        LENGTHS
      ADA PURP,I
      STA 1,I 
      ADB .-1 
      CCA 
      ADA PURP
      STA PURP
      LDA PURP,I,1
      STA 1,I 
      CMA,INA       TRY TO COMINE 2 ADJACENT
      ADB .-2        ENTRIES. 
      ADA 1,I I&
      INB 
      ADA 1,I 
      SZA 
      JMP PURX9     CAN'T COMBINE ENTRIES 
      ADB .+2 
      LDA 1,I       GET LENGTH OF 2ND ENTRY.
      ADB .-2 
      ADA 1,I       ADD TO
      STA 1,I        LENGTH OF 1ST. 
      INB           SMDE  
      STB MOVED      TOGETHER.
      ADB .+2 
      STB MOVES 
      ADB MLIBD 
      ADB ADLEN 
      JSB MOVEW 
PRX10 ISZ ADLEN     ADJUST
      ISZ ADLEN      ADLEN. .z
      JMP PURX9 
PURX6 CCA           CAN WE MERGE WITH PREVIOUS ENTRY
      ADA PURPRW
      STA PURP
      ADB .-4 zz
      LDA 1,I 
      INB 
      ADA 1,I 
      CPA PURP,Iyy
      JMP PURX8     YES--GO DO IT.
* 
* HAVE TO CREATE A NEW ENTRY. FIRST TEST TO SEE IF
* THERE IS ROOM TO EXPAND THE ADT.
* qq
      LDA ADLEN 
      ADA .-2 2
      STA ADLEN 
      ADA P3072                                  X] 
      SSA 
      JMP PRX10     NOT ENOUGH--FORGET IT.
      LDA ADLEN     SLIDE 
      CMA            DOWN.
      ADA LIBD
      STA MOVED 
      ADA .-2 
      STA MOVES 
      CMA,INA 
      ADB 0 
      JSB MOVEB 
      ISZ MOVES     INSERT NEW ENTRY
      DLD PURP,I
      DST MOVES,I 
PURX9 ISZ PURP      ADJUST PURP & 
      ISZ PURP       LOOP/
      JMP PURX3 
* qq
PURX8 ISZ PURP      MERGE NEW ENTRY WITH PREVIOUS 
      LDA PURP,I
      ADA 1,I 
      STA 1,I 
      JMP PURX9+1 
* qq
* 
PURX4 DLD PURM      RESTORE MOVES AND MOVED.
      STA MOVED D_
      STB MOVES 
      LDA ADLEN     W[TE ADT BACK.  
      STA WORD
      LDA ADLOC 
      LDB LIBD
      JSB DISCL 
      LDA M3072     COMPUTE NEW VALUE 
      LDB M3072       FOR PURID 
      CMB,INB BQ
      ADB ADLEN 
      SSB 
      LDA ADLEN 
      ADA MLIBD 
      ADA .-4 
      STA PURID 
      JMP PURXF 
$$PUR EQU *         (MUST BE <= PURXF)
* 
      ORG LTEMP 
PURDT BSS 1 
PURN  BSS 1 1@
PURP  BSS 1 
PURI  BSS 1 
PURDD BSS 1 
PURD  BSS 1 
PURT  BSS 3 
PURID BSS 1 
PURW  BSS 1 1)
PURPP BSS 1 
PURM  BSS 2 
      HED PHONES
* *q
*     THE PHONES COMMAND INFORMS THE SYSTEM 
*     OF THE PRESENCE OF A PHONES CONTROL 
*     BOARD.  IT ALSO SETS THE TIME ALLOWED FOR LOGGING ON. 
* qq
      SPC 2 26
      ORG LIBRA 
      CLA           SET INITIAL 
PHO1  STA LTEMP       TIME TO ZERO
      ADA M256      TOO BIG?
      SSA,RSS 
      JMP LFRER     YES 
      JSB T35CQ     GET CHARACTER 
      JMP PHO2      NO MORE 
      ADA M72B      DIGIT?
      SSA,RSS 
     JMP LFRER     NO 
      ADA .+10
      SSA 
      JMP LFRER 
      LDB LTEMP     YES - MULTIPLY
      BLS,BLS       OLD VALUE 
      ADB LTEMP         BY 10 
      BLS 
      ADA 1         ADD IN NEW
      JMP PHO1        DIGIT 
* 
PHO2  LDA LTEMP     CHECK VALUE 
      SZA,RSS 
      JMP LFRER     INVALID 
      CLB 
      CMA,INA       SET COUNTER FOR 
      STA PHR         TENTHS OF SECONDS 
      JMP LEND      TERMINATE 
* 
$PHO  EQU * 
      HED ***  DISC COMMAND **  DISC-UP,#  OR DISC-DN,#  ***
      ORG LIBRA                                  X] 
*                                                X] 
*                                                X] 
      JSB T35CH,I  GET A CHAR                    X] 
      JMP LFRER    NONE LEFT                     X] 
      ALF,ALF      MOVE UP                       X] 
      STA SDIS1     AND SAVE                       [X]
      JSB T35CH,I  GET NEXT CHAR                 X] 
      JMP LFRER    NONE LEFT                     X] 
      IOR SDIS1     FORM WORD                      [X]
      CPA ASCDN    DOWN?                         X] 
      JMP DIS11     YES.
      CPA ASCUP    UP?                           X] 
      RSS 
      JMP LFRER    NO - ILLEGAL                  X] 
*                                                X] 
*     DISC,DN,#                                  X] 
*                                                X] 
*                                                X] 
DIS11 STA UPDN      SAVE "UP" OR "DN".
* 
*  GET SUBCHANNEL AND FORM DISC ADDRESS 
* *q
      JSB T35CH,I    GET NEXT CHAR. 
      JMP SUBER     CR. 
      CPA .+54B     COMMA?
      RSS 
      JMP SUBER     NO. 
      JSB T35CH,I   YES. NEXT CHAR. 
      JMP SUBER     CR. 
      ADA M72B      TEST FOR DIGIT. 
      SSA,RSS S
      JMP SUBER     NOT A DIGIT.
      ADA .+10
      SSA 
      JMP SUBER     NOT A DIGIT.
      LDB A 
      ADB .-4       TEST FOR TOO BIG. 
      SSB 
      SZA,RSS 
      JMP SUBER     IT IS TOO BIG OR =0.
      LDB A         COMPUTE DISC
      CLE,ERB         ADDRESS FOR THIS
      RBR               SUBCHANNEL. 
      SEZ,RSS 
      ADB B100
      STA SCHAN    SAVE SUBCHANNEL               X] 
      STB SDISC    SAVE DISC ADDRESS             X] 
      LDA UPDN
      CPA ASCUP     UP? 
      JMP UP        YES.
      LDA SCHAN     NO. DOWN! 
      MPY .+14     MULTIPLY IT BY 14             X] 
      ADA DIRD0    ADD DIRECTORY ADR TO IT        X 
      LDB A,I       IF TRACK 1 LENGTH=0, THEN 
      SZB,RSS 
      JMP DIS10       ALREADY DOWN. 
      STA LTEMP     SAVE POINTER. 
      LDA .-5       READ
      STA WORD
      LDA SDISC 
      LDB LIBDI 
      JSB DISCL       LABEL.
      LDB LIBD,I    GET USER DISC FLAG. 
      SSB,RSS       IF=0, OUTPUT ERROR MESSAGE. 
      JMP DIS12 
      LDA LTEMP     IF=1, RESTORE POINTER.
      LDB .-14     SET COUNTER TO 14              X 
      STB DCNT     SAVE COUNTER                   X 
      LDB 0,I      LOAD TRACK 1 LENGTH            X 
      STB DT1L     SAVE TRACK 1 LENGTH            X 
      ADA .+7      ADD 7 TO ADDRESS               X 
      LDB 0,I      LOAD TRACK 2 LENGTH            X 
      STB DT2L     SAVE IT                        X 
      ADA .-7      RESTORE TRACK 1 ADDRESS        X 
      STA LTEMP     SAVE ADDRESS
      LDA M128      INPUT 
      STA WORD        FUSS
      LDA FUSS,I        TABLE 
      LDB LIBDI 
      JSB DISCL 
      LDB LIBD      SEE IF ANY
DIS.9 EQU * 
      LDA 1,I         BUSY FILES
      SZA,RSS      IF NO FILE THEN SKIP 
      JMP DIS.8 
      AND DHMSK         ON THIS 
      CPA SDISC           DISC
      JMP DIS.7     YES 
DIS.8 EQU * 
      ADB .+2       NEXT ONE
      CPB L128
      RSS 
      JMP DIS.9 
      LDA LTEMP 
      CLB          SET 14 WORDS TO 0              X 
      STB A,I      THIS CLEARS THE DIRECTORY      X 
      INA          FOR THIS DISC                  X 
      ISZ DCNT                                    X 
      JMP *-3                                     X 
*                                                 X 
*     THE DIRECTORY HAS BEEN CLEARED.             X 
*     NOW GET THE SYSTEM ADT TABLE AND DELETE THOSE PORTIONS WHICH
*     REFER TO THE DOWNED DISC.  SAVE THOSE PROTIONS A ON THE 
*     DOWNED DISC                                X] 
*                                                X] 
*                                                X] 
      LDA ADLEN    READ THE SYSTEM ADT           X] 
      STA WORD     SYSTEM ADT LENGTH             X] 
      LDA ADLOC    DISC ADDRESS                  X] 
      LDB LIBDI    CORE ADDRESS FOR INPUT        X] 
      JSB DISCL    LOAD THE ADT                  X] 
*                                                X] 
*                                                X] 
      LDB LIBD     LOAD POINTER TO ADT CORE ADDRESS 
DIS.2 LDA B,I      LOAD ADT ENTRY                X] 
      AND DHMSK    GET DISC AND HEAD             X] 
      CPA SDISC    RIGHT DISC?                   X] 
      JMP DIS.1    YES                           X] 
      ADB .+2      NO  GET NEXT ENTRY            X] 
      JMP DIS.2                                  X] 
DIS.1 STB DADT     SAVE POINTER TO ADT BLACK FOR TH RIGHT DISC
      LDA .-2      SET WORD COUNT=-2             X] 
DIS.4 STA DCNT                                   X] 
      ADB .+2      GO TO NEXT ENTRY              X] 
      LDA 1,I      LOAD IT                       X] 
      CPA .-1       IF IT SI PSEUDO ENTRY,
      JMP DIS.3       WE FOUND THE END. 
      AND DHMSK    IS IT THE                     X] 
      CPA SDISC    RIGHT SUBCHAN?                X] 
      RSS          YES                           X] 
      JMP DIS.3    NO - WE HAVE FOUND THE END    X] 
      LDA DCNT     UPDATE WORD COUNT             X] 
      ADA .-2      FOR THE ADT BLOCK             X] 
      JMP DIS.4                                  X] 
*                                                X] 
*     WE KNOW HOW LONG THE ADT FOR THIS DISC IS, X] 
*     SO SAVE IT, AND OUTPUT IT TO TRACK 0 SECTOR 1 
*     ALSO OUTPUT THE DIRECTORY TRACK LENGTHS TO THAT SECTOR
*                                                X] 
*                                                X] 
DIS.3 LDA .-3                                    X] 
      STA WORD     WORD COUNT IS -3              X] 
      LDB DTAB     DEF DCNT                      X] 
      LDA SDISC    FORM DISC ADDRESS             X] 
      INA          SECTOR IS 1                   X] 
      JSB DISCL    OUTPUT IT                     X] 
*                                                X] 
*                                                X] 
      LDB DADT     LOAD ADT CORE ADDRESS         X] 
      LDA DCNT     LOAD WORD COUNT FOR THE BLOCK X] 
      STA WORD                                   X] 
      LDA SDISC    FORM DISC ADDRESS             X] 
      ADA .+2      START IN SECOTR 2             X] 
      JSB DISCL    OUTPUT ADT BLOCK TO DISC      X] 
*                                                X] 
*     THE DISC HAS BEEN SAVED.  NOW UPDATE SYSTEM ADT 
*                                                X] 
      LDA LIBD     COMPUTE THE LENGTH            X] 
      CMA,INA      OF THE LAST SECTION           X] 
      ADA ADLEN    OF THE ADT TABLE              X] 
      ADA DADT     THIS SECTION MUST             X] 
      LDB DCNT     LOAD COUNT                    X] 
      CMB,INB      MAKE IT +                     X] 
      ADB 0        COMPUTE LENGTH                X] 
*                                                X] 
      SZB,RSS      TEST IF ANY TO MOVE           X] 
      JMP DIS.5    NO                            X] 
      LDA DADT     SET DEST. ADDRESS             X] 
      STA MOVED    FOR MOVE WORD SUBOUTINE       X] 
      LDA DCNT     COMPUT START ADDRESS          X] 
      CMA,INA      FROM POSITIVE BLACK COUNT     X] 
      ADA DADT     AND BLOCK ADDRESS             X] 
      STA MOVES                                  X] 
      JSB MOVEW    MOVE WORDS DOWN               X] 
      LDA DCNT     COMPUT THE NEW                X] 
      CMA,INA      ADT LENGTH                    X] 
      ADA ADLEN                                  X] 
      STA ADLEN                                  X] 
DIS.6 STA WORD                                   X] 
      LDA ADLOC    TO THE SYSTEM                 X] 
      LDB LIBD     DISC                          X] 
      JSB DISCL                                  X] 
* 
      LDA .-5       READ
      STA WORD
      LDA SDISC 
      LDB LIBDI 
      JSB DISCL       LABEL.
      LDB LIBD      SET USER DISC 
      LDA B,I         FLAG TO 0.
      ELA,CLE,ERA 
      STA B,I 
      LDA SDISC     WRITE 
      JSB DISCL       LABEL BACK OUT. 
* 
*                                                X] 
*     EVERYTHING HAS BEEN UPDATED                X] 
      JMP LEND      ALL DONE
* 
UP    LDA UPLEN     LOAD "DISC-UP" ROUTINE. 
      STA WORD
      LDA LIB B*
      INA 
      LDA A,I 
      LDB #LIBI 
      JMP DIS13 3+
* qq
*                                                X] 
DIS.5 LDA ADLEN                                  X] 
      JMP DIS.6                                  X] 
*                                                X] 
DIS10 LDA DISAD     OUTPUT
      LDB .-6         "ALREADY DOWN"
      JMP DMES          MESSAGE.
* 
DIS.7 LDA DISFB     OUTPUT
      LDB .-6       BUSY FILES
      JMP DMES          MESSAGE 
* 
DISAD DEF *+1 
      OCT 5101      LF-A
      ASC 5,LREADY DN!
DISFB DEF *+1 
      OCT 5102
      ASC 5,USY FILES 
ASCDN ASC 1,DN
ASCUP ASC 1,UP
UPDN  BSS 1 
UPLEN ABS LIBRA-$UP 
      SKP                                        X] 
      SPC 2 
      ORG 37637B
      SPC 2 
*                                                X] 
*     SUBCHANNEL IS TOO BIG                      X] 
*                                                X] 
SUBER LDA DISR                                   X] 
      LDB .-6       OUTPUT ERROR MESSAGE. 
*                                                X] 
DMES  STA MOVES    SET SOURCE                    X] 
      LDA T35B1    SET DESTINATION               X] 
      STA MOVED                                  X] 
      STB DMESL    SAVE LENGTH                   X] 
      JSB MOVEW    MOVE TO TTY35 BUF             X] 
      LDA DMESL                                  X] 
      ALS                                        X] 
      CMA,INA                                    X] 
      CLF 0 
      CLB 
      STB LIB 
      LDB T35B1 
      STF 0 
      JMP LEND2     OUTPUT THE MESSAGE. 
* qq
DIS12 LDA ILL       OUTPUT "ILL. DISC"
      LDB .-5         MESSAGE.
      JMP DMES
* 
DMESL NOP                                        X] 
DISR  DEF *+1                                    X] 
      OCT 5123      LF-S
      ASC 5,UBCH ERROR
DCNT  NOP                        [X]
DT1L  NOP                        [X]
DT2L  NOP                        [X]
DTAB DEF DCNT                    [X]
SCHAN EQU LTEMP+4                [X]
SDISC EQU LTEMP+5                [X]
SDIS1 EQU LTEMP+6                [X]
DADT EQU LTEMP+7                 [X]
* qq
      ORG LIBRA+254 
DIS13 JSB DISCL     LOAD OVERLAY. 
      JMP LIBRA     START UP OVERLAY. 
* 
$DN    EQU *                                   [X]
