
      HED SUPERSAVE 
* THE SAVE OVERLAY ROUTINE IS CALLED BY THE SAVE AND OPEN ROUTINES
* * WHENEVER THEY WANT TO MAKE A DIRECTORY ENTRY ON A TRACK THAT IS 
* ALREADY FULL. THE FOLLOWING LOCATIONS MUST BE APPROPRIATELY SET:
*     LTEMP(0:3)=1ST 4 WORDS OF ENTRY.
*     LTEMP(4)=POINTER TO DIREC ENTRY OF TRACK IN CORE
*     LTEMP(5)=CORE ADDRESS OF ENTRY TO PRECEED NEW ENTRY 
*     LTEMP(6:7)=DISC ADDRESS 
*     LTEMP(8)=LENGTH OF ENTRY IN -WORDS
*     LTEMP(10)=START OF PROGRAM POINTER OR RECORD SIZE 
* 
      ORG LIBRA 
* 
      LDA SDIR0     => 1ST DIREC ENTRY
* 
* COMPUTE TOTAL # OF WORDS IN DIRECTORIES.
* 
      ADA .+5       => DIRECTORY DISC ADDRESS 
SUP1  LDB A,I       DOES
      CLE,INA         THE 
      ADB A,I           DIRECTORY 
      SEZ 
      INB                 TRACK 
      ADA .-6 
      SZB,RSS               EXIST?
      JMP SUP2        NO
      LDB 0,I       GET DIRECTORY LENGTH. 
      CLE,SZB,RSS   LENGTH ZERO?
      JMP SUP2-1      YES 
      ADB SUPS      ADD TO
      STB SUPS       TOTAL. 
      LDB SUPS-1
      SEZ,RSS       INCREMENTING DOUBLE WORD QUANTITY 
      ADB .-1 
      STB SUPS-1
      ISZ SUPB      BUMP DIRECTORY TRACK COUNTER. 
SUP2  EQU * 
      CPA SDIRL     LAST DIRECTORY TRACK? 
      JMP *+3         YES 
      ADA .+12        NO - GO TO NEXT ONE.
      JMP SUP1
* 
* AT THIS POINT THE DOUBLEWORD SUP-1    CONTAINS 12 LESS THAN THE 
*                              SUP
*    TOTAL NUMBER OF WORDS IN ALL DIRECTORY TRACKS. 
* 
      LDA SUPS      GET TOTAL # OF DIRECTORY WORDS. 
      LDB  SUPS-1 
      DIV .+12      GET ENTRY COUNT IN A
      CCB           COUNT < 65535 
      DIV SUPB      COMPUTE # IN EACH DIRECTORY.
      CPA M682
      SZB,RSS       TEST FOR FULL UP. 
      CPA M683
      JMP SUP3        ALL TRACKS ARE FULL 
      ADA .-1       INCREASE # OF ENTRIES/TRACK BY 1
      ADB .-1       LET B COUNT HOW MANY WILL HAVE
      STB SUPB       THIS LARGER SIZE.
      MPY .+12      CONVERT TO -WORD SIZE 
      STA SUPS        AND SAVE
* 
* COMPUTE AN EVEN DISTRIBUTION OF ENTRIES OVER ALL AVAILABLE TRACKS 
* 
      LDB SDIR0     GET POINTER TO FIRST TRACK AGAIN
      ADB .+5       GET THE DISC ADDRESS
SUP4  LDA 1,I 
      INB 
      IOR B,I 
      SZA,RSS       IF TRACK DOES NOT EXIST 
      JMP SUP5        DO NOT INCLUDE IT 
      LDA SUPS      GET TRACK LENGTH
      ISZ SUPB      HAVE ALL BIG TRACKS BEEN PROCESSED? 
      JMP SUP50 
      ADA .+12        YES - DECREMENT BY 1 ENTRY
      STA SUPS          AND SAVE
SUP50 EQU * 
SUP5  STA SUPP,I    STORE IN TABLE. 
      ADB .-6       TEST FOR DONE.
      CPB SDIRL 
      JMP SUP6        FINISHED
      ADB .+12      BUMP TO NEXT TRACK
      ISZ SUPP      BUMP TABLE POINTER ALSO.
      JMP SUP4
* 
* THE TABLE POINTED TO BY DEFNN NOW CONTAINS THE NEW LENGTHS OF EACH
*    OF THE DIRECTORY TRACKS
* 
SUP6  LDA DEFNN     SET UP POINTER
      STA SUPP       TO NN AGAIN. 
* 
* SQUEEZE ALL THE DIRECTORY ENTRIES ONTO THE LASTMOST OF THE
* AVAILABLE TRACKS. 
* 
      LDA SDIRL     => 1ST TRACK
      STA SUPK1       FOR READ
      ADA .+5 
SUP20 EQU * 
      LDB A,I       GET ADDRESS 
      CLE,INA 
      ADB A,I 
      SEZ 
      INB 
      SZB           ZERO? 
      JMP SUP21       NO,THE TRACK EXISTS 
      ADA .-8 
      JMP SUP20 
SUP21 EQU * 
      ADA .-6       => 1ST TRACK
      STA SUPL1       FOR WRITE 
      CLA           # OF WORDS IN BUFFER
      STA SUPK2       INITIALIZED TO ZERO 
* 
      LDA SUPK1 
SUP22 EQU * 
      LDB A,I       GET LENGTH FOR READ 
      SZB,RSS       ZERO? 
      JMP SUP27     YES 
      ADB SUPK2     NO, ADD IN # OF WORDS IN BUFFER 
      ADB S8184     ARE THE NUMBER OF WORDS IN THE
      SSB             BUFFER > 8184?
      JMP SUP23     YES 
      LDB A,I       NO, SET 
      STB MWORD       LENGTH
      ADB SUPK2     UPDATE # OF 
      STB SUPK2       WORDS IN CORE 
      ADB LULEN 
      ADB BIT15     CORE ADDRESS
      ADA .+5       => DISC ADDRESS 
      JSB DISCZ,I 
      JSB DEADP,I 
* 
      LDA SUPK2 
      CPA M8184     EXACTLY 8184    WORDS?
      RSS           YES 
      JMP SUP27     NO
      STA MWORD 
      LDB SUPL1     SET LENGTH
      STA B,I         IN DIREC
      ADB .+5 
      LDA B         => DISC ADDRESS 
      LDB X2056     CORE ADDRESS
      JSB DISCZ,I 
      JSB DEADP,I 
      CLB           BUFFER NOW EMPTY
      STB SUPK2 
      JMP SUP24 
* 
SUP23 EQU * 
      CMB,INB       CONVERT TO POSITIVE VALUE 
      BRS,BRS       COMPUTE 
      BRS,BRS         NUMBER
      BRS,BRS           OF
      BRS,BRS             EXTRA 
      STB SUPES             BLOCKS
      BLF,BLF       COMPUTE # OF
      STB SUPEX       EXTRA WORDS 
      ADB A,I       # OF WORDS
      STB MWORD       TO READ 
      ADB SUPK2 
      ADB LULEN 
      STB MOVES 
      ADA .+5 
      DLD A,I       COMPUTE 
      CLE             ADDRESS 
      ADB SUPES         OF REMAINING
      SEZ                 WORDS 
      INA                   TO
      DST SUPET               READ
      LDA SUPEA     => DISC ADDRESS 
      LDB MOVES 
      ADB BIT15     CORE ADDRESS
      JSB DISCZ,I 
      JSB DEADP,I 
* 
      LDA M8184     # OF WORDS
      STA MWORD       TO WRITE
      LDB SUPL1 
      STA B,I       SAVE IN DIREC 
      ADB .+5 
      LDA B         => DISC ADDRESS 
      LDB X2056     CORE ADDRESS
      JSB DISCZ,I 
      JSB DEADP,I 
* 
      LDB X2056     # OF
      CMB,INB         EXTRA 
      ADB MOVES         WORDS 
      STB SUPK2           TO MOVE 
      LDA LULEN 
      ADA B 
      STA MOVED     DESTINATION POINTER 
      JSB MOVEW     MOVE THEM 
* 
      LDB SUPEX     # OF WORDS
      CMB,INB         TO READ FROM
      STB MWORD         PARTIAL TRACK 
      ADB SUPK2 
      STB SUPK2     # OF WORDS IN BUFFER
      ADB LULEN 
      ADB BIT15     CORE ADDRESS
      LDA SUPK1 
      ADA .+5       => DISC ADDRESS 
      JSB DISCZ,I 
      JSB DEADP,I 
* 
SUP24 EQU * 
      LDA .-2       BUMP TO NEXT
      ADA SUPL1       TRACK TO WRITE
SUP25 EQU * 
      LDB A,I       GET ADDRESS 
      CLE,INA 
      ADB A,I 
      SEZ 
      INB 
      SZB           ZERO? 
      JMP SUP26     NO
      ADA .-8       YES, MOVE TO NEXT ONE 
      JMP SUP25 
SUP26 EQU * 
      ADA .-6       BUMP TO LENGTH WORD 
      STA SUPL1     SAVE POINTER
* 
SUP27 EQU * 
      LDA SUPK1     => CURRENT READ TRACK 
      CPA SDIR0     LAST ONE
      JMP SUP28     YES 
      ADA .-7       NO, BUMP TO NEXT ONE
      STA SUPK1 
      JMP SUP22 
SUP28 EQU * 
* 
      LDA SUPK2     # OF WORDS IN BUFFER
      SZA,RSS       ZERO? 
      JMP SUP30     YES 
      STA MWORD     NO, MUST WRITE OUT BUFFER 
      LDB SUPL1     SET LENGTH
      STA B,I         IN DIREC
      ADB .+5 
      LDA B         => DISK ADDRESS 
      LDB MWORD 
      ADB LULEN     CORE ADDRESS
      JSB DISCZ,I 
      JSB DEADP,I 
* 
      LDA SUPL1 
SUP29 EQU * 
      CPA SDIR0     LAST WRITE TRACK? 
      JMP SUP31     YES, DONE 
      ADA .-7       NO, BUMP TO NEXT ONE
      RSS 
SUP30 EQU * 
      LDA SUPL1 
      ADA .+5 
      LDB A,I       GET ADDRESS 
      CLE,INA 
      ADB A,I 
      SEZ 
      INB 
      ADA .-6 
      SZB,RSS       ZERO? 
      JMP SUP29     YES 
      CLB           NO, SET 
      STB A,I         LENGTH =0 
      JMP SUP29 
* 
* THE MAIN PART OF THE ALGORITHM CONSISTS OF TWO SECTIONS. IN THE 
* FIRST SECTION WE READ AS POSSIBLE INTO THE SWAP AREA. IN THE 2ND
* SECTION WE WRITE OUT AS MUCH AS POSSIBLE. THE ENTIRE PROCEDURE IS 
* THEN REPEATED UNTIL WE ARE FINISHED. THE FOLLOWING MEANINGS ARE 
* ASSOCIATED WITH THESE VARIABLES:
* 
*     SUPK1=>DIREC ENTRY FOR TRACK BEING READ.
*     SUPL1=>DIREC ENTRY FOR TRACK BEING WRITTEN. 
*     SUPK2=# OF WORDS READ SO FAR FROM K1. 
*     SUPL2=# OF WORDS WRITTEN SO FAR ON L1.
*     SUP  =# OF WORDS IN CORE. 
*     SUPP => -# OF WORDS TO BE WRITTEN ON L1.
* 
SUP31 EQU * 
      CLA           INITIALIZE
      STA SUPK2       LENGTH
      STA SUPL2         WORDS 
      LDA SDIR0     INITIALIZE
      STA SUPK1       DIREC 
      STA SUPL1         POINTERS
* 
SUP7  LDA SUPL2     IS # OF WORDS WRITTEN SO FAR ON 
      CMA,INA        L1=# OF WORDS TO BE WRITTEN? 
      CPA SUPP,I
      JMP SUP10     YES--GO ADVANCE L19 
* 
SUP8  LDA SUP       IS THE SWAP AREA FULL 
      ADA STLE
      SSA,RSS 
      JMP SUP11     YES--GO TO WRITE SECTION. 
      STA MWORD       NO - SAVE -# OF CORE WORDS
*                                     AVAILABLE 
      LDB SUPK1     HAVE WE READ ALL OF THE TRACKS? 
      CPB SDIRU 
      JMP SUP11     YES--GO TO WRITE SECTION. 
      LDA SUPK1,I   A=-# OF WORDS ON THIS TRACK.
      ADA SUPK2     A=-# NOT READ YET.
      SZA           ENTIRE TRACK READ?
      JMP SUP9      NO. 
      ADB .+7       YES--BUMP K1 TO NEXT TRACK. 
      STB SUPK1 
      STA SUPK2     SET # OF WORDS READ TO 0. 
      JMP SUP8      TEST THIS TRACK.
* 
SUP9  STA 1         B=-# OF WORDS NOT YET READ ON K1
      CMB,INB       MAKE POSITIVE.
      ADB MWORD     IS # OF WORDS ON TRACK > # OF 
      SSB            WORDS WE HAVE ROOM FOR?
      JMP *+4       NO--READ IN ENTIRE TRACK. 
      LDA MWORD     GET -# WE HAVE ROOM FOR.
      ADA B377      REDUCE TO NEXT SMALLER
      AND M256        BLOCK SIZE. 
      SZA,RSS       IF WE CAN'T READ IN ANY, GO TO
      JMP SUP11      WRITE SECTION. 
* 
      STA MWORD     SET WORD = -# OF WORDS TO READ. 
      LDA SUPK2     GET # OF WORDS READ SO FAR. 
      CLB           DIVIDE BY 64 TO GET 
      ASR 8           BLOCK ADDRESS.
      STA SUPET 
      LDB SUPK1     GET DIRECTORY 
      ADB .+5         TRACK ADDRESS 
      DLD B,I 
      CLE 
      ADB SUPET 
      SEZ 
      INA 
      DST SUPET 
      LDA SUPEA     => DISC ADDRESS 
      LDB LIBDI     COMPUTE CORE LOCATION 
      ADB SUP        TO READ INTO.
      JSB DISCZ,I 
      JSB DEADP,I 
* 
      LDB MWORD     UPDATE # OF WORDS 
      CMB,INB        IN CORE. 
      ADB SUP 
      STB SUP 
      LDB MWORD     UPDATE # OF WORDS 
      CMB,INB        READ FROM K1.
      ADB SUPK2 
      STB SUPK2 
* 
      LDA SUPTG     HAVE WE INSERTED THE NEW ENTRY
      SZA            YET? 
      JMP SUP8      YES--GO TRY TO READ MORE. 
      LDA SUPL2     GET THE AMOUNT ALREADY WRITTEN
      CLB             ON THIS TRACK 
      DIV .+12      FIND EXCESS OVER EVEN ENTRY 
      LDA B 
      CMB,INB 
      STB SUPEX 
      ADA SUP       GET THE COUNT 
      CLB             OF WORDS IN CORE
      DIV .+12      CONVERT TO ENTRY COUNT
      MPY .+12        AND BACK TO WORD COUNT
      ADA LIBD          SO THAT WE LOOK AT
      ADA SUPEX           AN EVEN BOUNDARY
      SZB,RSS 
      ADA .-12
      STA SUPEX 
      LDB DLTEM     => ID/NAME OF NEW ENTRY 
      JSB DIRCS,I   GO COMPARE
      JMP SUP8      DOESN'T GO ON THIS TRACK
SUP32 EQU * 
      LDB SUPEX     GOES ON THIS
      STB SUPES       TRACK, SO 
      ADB .-12          SEARCH BACKWARDS
      STB SUPEX           TO FIND 
      ADB MLIBD 
      SSB           NO SKIP IF SEARCH DONE
      JMP SUP33 
      LDB SUPEX 
      LDA DLTEM             OUT WHERE 
      JSB DIRCS,I   COMPARE THIS ENTRY
      JMP SUP32     NOT THIS ONE
* 
SUP33 EQU * 
      ISZ SUPTG     SET TOGGLE TO SAY WE'VE INSERTED
      LDA LIBD      COMPUTE DESTINATION 
      ADA SUP        OF WORDS TO BE 
      LDB A           MOVED 
      ADA .+11
      STA MOVED 
      ADA .-12      COMPUTE SOURCE
      STA MOVES 
      CMB,INB 
      ADB SUPES 
      JSB MOVEB     CALL REVERSE MOVER. 
* 
      LDA SUPES     => HOLE 
      STA MOVED 
      LDA DLTEM     SET SOURCE AT LTEMP.
      STA MOVES 
      LDB .-4       MOVE IN FIRST 4 
      JSB MOVEW      WORDS. 
      LDA SAVP      STORE START-OF- 
      STA MOVED,I     PROGRAM POINTER 
      ISZ MOVED 
      JSB DATE      INSERT DATE IN WORD 5 
      STA MOVED,I 
      ISZ MOVED       AND 
      LDA DATIM     GET HOUR OF YEAR FOR
      STA MOVED,I       WORD 6
      ISZ MOVED 
      CLA 
      STA MOVED,I 
      ISZ MOVED 
      DLD SAVDS     GET THE DISK ADDRESS AND SET IT 
      DST MOVED,I     INTO WORDS 8 AND 9
      LDB MOVED 
      ADB .+3       => WORD 11
      LDA SAVWD     GET LENGTH
      STA B,I       AND STORE AWAY
      LDA SUP       UPDATE THE COUNT OF WORDS 
      ADA .+12        IN CORE BY TWELVE 
      STA SUP 
      JMP SUP8
* 
* COME HERE WHEN CURRENT OUTPUT TRACK HAS BEEN FILLED.
* 
SUP10 LDA SUPL1     TEST FOR LAST TRACK.
      CPA SDIRL 
      JMP SUP16     ALL DONE--GO CLEAN UP DIREC.
      ADA .+7       BUMP TO NEXT TRACK. 
      STA SUPL1 
      CLA           SET # OF WORDS WRITTEN SO FAR 
      STA SUPL2      TO 0.
      ISZ SUPP      BUMP POINTER TO WORDS TO BE 
      JMP SUP7       WRITTEN. 
      SPC 3 
* THE NEXT SECTION IS THE OUTPUT SECTION. WE ONLY COME TO THIS SEC- 
* TION WHEN WE HAVE DETERMINED THAT NO MORE CAN BE READ. IN THIS
* PART WE WRITE OUT AS MUCH AS POSSIBLE UNTIL WE HAVE EXHAUSTED ALL 
* WE HAVE IN CORE OR WE REACH THE POINT WHEN FURTHER OUTPUT WOULD 
* DESTROY INFORMATION NOT YET READ. IN THIS SECTION, THE VARIABLE 
* SUPS = # OF WORDS THAT HAVE BEEN OUTPUT FROM THE CURRENT CORE 
* LOAD. 
      SPC 2 
SUP11 CLA           SET # OF WORDS OUTPUT SO FAR TO 
SUP15 STA SUPS       ZERO.
      LDA SUPL2     SET WORD = -# OF WORDS LEFT 
      ADA SUPP,I     TO BE WRITTEN ON L1. 
      LDB SUPL1     TEST FOR WRITING ON A TRACK NOT 
      CPB SUPK1      COMPLETELY READ. 
      JMP SUP12     WE ARE. 
SUP13 LDB SUPS      SET B=# OF WORDS LEFT IN CORE.
      CMB,INB 
      ADB SUP 
      STB SUPB      SAVE IN B.
      ADB 0         COMPARE WITH # WE WANT TO WRITE.
      SSB,RSS 
      JMP SUP14     HAVE ENOUGH. -# IS IN A.
      LDA SUPB      ONLY WRITE WHAT WE HAVE.
      AND M256      USE ONLY FULL BLOCK'S WORTH 
      CMA,INA       MAKE NEGATIVE.
      JMP SUP14 
SUP12 LDB SUPL2     IF WRITING ON UNREAD TRACK, MAKE
      CMB,INB        SURE WE DON'T GO INTO UNREAD 
      ADB SUPK2       AREA. 
      ADB 0 
      CMB,SSB,INB,RSS 
      ADA 1         CHANGE A TO AVOID OVERLAY.
      JMP SUP13 
* 
* A  NOW  CONTAINS -# OF WORDS WE'RE GOING TO WRITE.
* 
SUP14 STA MWORD     IF NO WORDS TO BE 
      SZA,RSS        WRITTEN GO TO SLIDE CORE FOR 
      JMP SUP17       NEW INPUT.
      CMA,INA 
      STA SUPB
      LDA SUPL2     TEST FOR FIRST WRITE ON THIS
      SZA            TRACK. 
      JMP SUP18 
* 
      LDA SUPL1     IF FIRST WRITE, 
      INA 
      STA MOVED      ADJUST DIREC TO TELL 
      LDA LIBD        NEW FIRST ENTRY ON THAT 
      ADA SUPS         TRACK. 
      STA MOVES 
      LDB .-4 
      JSB MOVEW 
      CLA 
* 
SUP18 CLB           CONVERT WORDS TO BLOCK
      ASR 8           ADDRESS 
      LDB SUPL1     ADD IN TRACK ADDRESS. 
      ADB .+5 
      STA SUPET 
      DLD B,I 
      CLE 
      ADB SUPET 
      SEZ 
      INA 
      DST SUPET 
      LDA SUPEA     => DISC ADDRESS 
      LDB LIBD      COMPUTE CORE
      ADB SUPS       ADDRESS. 
      JSB DISCZ,I   OUTPUT TO DISC
      JSB DEADP,I 
      LDA SUPB      ADJUST # OF WORDS OUTPUT TO 
      ADA SUPL2      TRACK. 
      STA SUPL2 
      LDA SUPB      ADJUST # OF CORE WORDS WRITTEN
      ADA SUPS       OUT SO FAR.
      JMP SUP15     LOOP FOR ANY MORE WRITING.
* 
* COME   HERE WHEN WE CAN'T WRITE ANYMORE.
* 
SUP17 CPA SUPS      IF NOTHING WRITTEN AT ALL, GO TO
      JMP SUP7       TRY AND READ AGAIN.
      LDB SUPS      ADJUST # OF WORDS IN CORE.
      CMB,INB 
      ADB SUP 
      STB SUP 
      CMB,INB       MAKE NEGATIVE FOR CORE MOVE.
      LDA LIBD      SET DESTINATION AND SOURCE. 
      STA MOVED 
      ADA SUPS
      STA MOVES 
      JSB MOVEW 
      JMP SUP7
* 
* ALL TRACKS WRITTEN BACK. NOW UPDATE WORD COUNTS IN
* DIREC.
* 
SUP16 EQU * 
      LDA M80       SET COUNT 
      STA SUP         OF DIRECTORY TRAX 
      LDB SDIR0     => FIRST DIREC ENTRY
SUPLL EQU * 
      LDA DEFNN,I   COPY NEW LENGTH WORDS INTO
      STA B,I         THE DIREC TABLE ENTRIES 
      ISZ DEFNN     WIPE OUT "CONSTANT" 
      ADB .+7       ADVANCE DIREC POINTER 
      ISZ SUP 
      JMP SUPLL 
      LDA SUPR1     SET UP RETURN ADDRESS.
      STA SUPR
SUP3  EQU * 
      LDA SM504     SET WORD COUNT
      STA MWORD 
      LDA LIB       => DISC ADDRESS 
      LDB #LIBI 
      JMP SUPRR 
DEFNN DEF FILBF 
M80   DEC -80 
SM504 DEC -504
M682  DEC -682
M683  DEC -683
SUPR1 JMP LIBRA+510 JUMP FOR NORMAL RETURN
S8184 DEC 8184
X2056 DEF LIBUS+ULEN-8184 
SDIR0 DEF DIREC 
SDIRL DEF DIREL 
SDIRU DEF DIREU 
DIRCS DEF DIRCM 
STLE  ABS -ULEN+20
      OCT -1
SUPS  DEC -12 
SUP   OCT 0 
SUPB  OCT 0 
SUPP  DEF FILBF 
SUPTG OCT 0 
SUPK1 BSS 1 
SUPK2 BSS 1 
SUPL1 BSS 1 
SUPL2 BSS 1 
SUPEX BSS 1 
SUPES BSS 1 
SUPEA DEF SUPET     POINTER TO DISC ADDRESS 
SUPET BSS 2         DOUBLEWORD TO HOLD DISC ADDRESS 
      ORG LIBRA+504 
SUPRR EQU * 
      JSB DISCZ,I   OVERLAY WITH ORIGINAL ROUTINE 
      JSB DEADP,I   CAN'T GET IT BACK, ARRGH! 
SUPR  JMP LIBRA+511 SET FOR ERROR ROUTINE 
$$SAV EQU * 
