      HED SUPERSAVE EO
* 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:5)=SAME AS LEFT BY DLODIC 
*     LTEMP(6:7)=DISC ADR AND LENGTH OF ENTRY.
      ORG LIBRA 
      SPC 1 
      JSB FDIRC     RECOMPUTE DIRECTORY 
     LDA LTEMP+4
      ADA .-7 
      STA LTEMP+4     RESET LTEMP+4 TO FIRST TRACK
      LDA LTEMP+4,I COMPUTE TOTAL DIRECTORY 
      STA WORD        LENGTH
      STA SUPL1 
      LDB LTEMP+4 
      ADB .+7 
      ADA 1,I 
      STA LTEMP+14     SAVE TOTAL 
      ADA OVFL      IS SYSTEM FULL?               (D) 
      SSA 
      JMP SUP9      YES - ALL FULL
      LDA LTEMP+14
      CCB           NO - DIVIDE BY 16 TO GET
      DIV .+16
      MPY .+8         NUMBER OF ENTRIES/2 * 8=WORDS PER TRACK 
      STA SUPLN     SAVE IT 
      LDA LTEMP+4   READ
      ADA .+6         IN
      LDA 0,I           FIRST 
      LDB LIBDI           TRACK 
      JSB DISCL Lq
      LDA SUPLN     IS NEW LENGTH 
      CMA,INA         OF TRACK LONGER 
      ADA WORD        THAN CURRENT LENGTH 
      SSA 
      JMP SUP1      NO
      CMA,INA       READ IN THAT MUCH 
      STA WORD        FROM TRACK 2
      STA SUPL2 
      LDA LTEMP+4   GET DISC
      ADA .+13        ADDRESS 
      LDA 0,I 
      LDB SUPL1     COMPUTE CORE
      CMB,INB         ADDRESS 
      ADB LIBDI 
      JSB DISCL     READ IT IN
      LDA SUPLN     OUTPUT
      STA WORD        TRACK 
      LDA LTEMP+4       TO
      ADA .+6      TRACK
      LDA 0,I             ONE 
      LDB LIBD
      JSB DISCL 
      LDA WORD      RESET 
      STA LTEMP+4,I   LENGTH
      LDB LTEMP+4   READ IN 
      ADB .+7         SECOND
      LDA 1,I           TRACK 
      STA WORD
      ADB .+6 
      LDA 1,I 
      LDB LIBDI 
      JSB DISCL 
      LDA SUPL2     COMPUTE FIRST 
      CMA,INA         WROD OF 
      ADA LIBD          TACK
      STA MOVES             2 
      LDA LIBD      MOVE
      STA MOVED       TRACK 2 
      LDB SUPL2     COMPUTE 
      CMB,INB         NEW 
      ADB WORD          LENGTH
      STB WORD
      JSB MOVEW     MOVE DOWN 
      LDB LTEMP+4   RESET 
      ADB .+7         TRACK 
      LDA WORD          LENGTH
      STA 1,I 
      LDA LIBD      UPDATE
      STA MOVES       BASE
      LDA LTEMP+4       PAGE
      ADA .+8             DIRECTORY 
      STA MOVED 
      LDB .-4 
      JSB MOVEW 
      LDA LTEMP+4   OUTPUT
      ADA .+13        TRACK 
      LDA 0,I           TO
      LDB LIBD            DISC
      JSB DISCL 
      JMP SUPR      DONE
* 
*     IFRST DIRECTORY TRACK IS THE LONG ONE 
* *q
SUP1  LDA SUPLN     WRITE 
      STA LTEMP+4,I   TRACK 1 
      STA WORD          BACK
      LDA LTEMP+4         OUT 
      ADA .+6               TO
      LDA 0,I                 DISC
      LDB LIBD
      JSB DISCL 
      LDA SUPLN     MOVE
      CMA,INA       REMAINDER 
      ADA LIBD      DOWN
      STA MOVES 
      LDA LIBD
      STA MOVED 
      LDB SUPLN     COMPUTE # 
      CMB,INB         OF WORDS
      ADB SUPL1         TO MOVE 
      STB SUPL2 
      JSB MOVEW 
      LDB LTEMP+4   READ
      ADB .+7         IN 2ND TRACK
      LDA 1,I 
      STA WORD      SET LENGTH
      ADB .+6         GET DISC
      LDA B,I 
      LDB MOVED     GET CORE
      ADB BIT15       ADDRESS 
      JSB DISCL 
      LDA WORD      COMPUTE 
      ADA SUPL2       NEW TRACK 
      STA WORD          LENGTH
      LDB LTEMP+4   RESET 
      ADB .+7         LENGTH
      STA 1,I           OF TRACK
      ADB .+6        WRITE
      LDA 1,I          TO 
      LDB LIBD           DISC 
      JSB DISCL 
      LDA LIBD      RESET 
      STA MOVES       BASE PAGE 
      LDA LTEMP+4       VALUES
      ADA .+8 
      STA MOVED 
      LDB .-4 
      JSB MOVEW 
SUPR  LDA SAVLL 
      STA WORD
      LDA LIB,I 
      LDB #LIBI 
      JMP LIBRA+248 
* 
*     SYSTEM OVERLOAD 
* 
SUP9  CLF 0 
      ISZ LIB 
      STF 0 
      LDA MFLAG     WHERE DO WE PRINT 
      SZA,RSS         THE ERROR MESSAGE?
      JMP FD.5      ON USER'S TERMINAL. 
      CLA           ON SYSTEM CONSOLE.
      STA MFLAG     FIRST CLEAR THE FLAG
      LDB FD.5+3    THEN PRINT THE MESSAGE. 
      LDA .+10
      JSB TTY35,I 
      JMP LENDR 
* 
SUPL1 NOP 
SUPL2 NOP P_
SUPLN NOP 
SAVLL DEC -248
      ORG LIBRA+248 
      JSB DISCL 
      JMP LIBRA+254 
$$SAV EQU * 
      HED GET 
* THE GET ROUTINE IS RESPONSIBLE FOR LOADING A PROGRAM FROM THE 
* USER LIBRARY. IT CAN BE USED TO LOAD FROM EITHER THE USER'S 
* PRIVATE LIBRARY OR FROM THE PUBLIC LIBRARY. IF THE PROGRAM IS TO
* BE FROM THE PUBLIC LIBRARY, THE PROGRAM NAME SHOULD BE PRECEDED 
* BY A DOLLAR SIGN ($). 
      SPC 1 
      ORG LIBRA 
      SPC 1 1
      LDA MLINK+1   GET USER'S ID.
      ADA .+?ID-?LINK 
      STA GETI
      LDA 0,I 
      STA LTEMP     STORE IN LTEMP. 
      LDA DLTEM     SET UP POINTER FOR NAME.
      INA 
      STA GETP
      LDA .-3       SET UP COUNTER. 
      STA GETC
      JSB LCHAR     GET FIRST INPUT CHAR. 
      JMP GET1      ERROR IF NONE.
      CPA .+44B     IF $ GO TO SET UP FOR 
      JMP GET2       SEARCHING PUBLIC LIBRARY.
GET3  ALF,ALF       SAVE CHARACTER IN TABLE.
      STA GETP,I
      JSB LCHAR     GET RIGHT CHARACTER.
      LDA .+40B     IF END CHANGE TO BLANK. 
      IOR GETP,I
      STA GETP,I
      ISZ GETP      BUMP POINTER. 
      JSB LCHAR     GET NEXT CHARACTER. 
      LDA .+40B 
      ISZ GETC      DO WE WANT IT?
      JMP GET3      YES.
      CPA .+40B     NO--A SHOULD NOW BE BLANK.
      JMP GET4T
* 
GET1  LDA .-13
      LDB *+2 
      JMP LIBER 
      DEF *+1 
      OCT 5111
      ASC 6,NVALID NAME E^
* 
GET2  LDA A000      SET UP FOR PUBLIC LIBRARY SEARCH
      STA LTEMP 
      JSB LCHAR     GET FIRST CHAR OF NAME. 
      JMP GET1      FAIL IF NONE. 
      JMP GET3
* q{
GET4  JSB RDPRG 
      LDA SPROG     SAVE END-OF-
      STA GETS        COMMON POINTER
      JSB DLOOK     SEARCH DIRECTORY FOR PROGRAM
      JMP GET9
* *q
      LDA .-16
      LDB *+2 2F
      JMP LIBER 
      DEF *+1 1;
      OCT 5116
      ASC 7,O SUCH PROGRAM
GET9  LDB GETPD     TEST FOR FILE RATHER
      ADB .+2        THAN PROGRAM.
      LDA 1,I 
      SSA,RSS 
      JMP GET10 
* qq
      LDA .-16
      LDB *+2 
      JMP LIBER 
      DEF *+1 
      OCT 5105      LF-E
      ASC 7,NTRY IS A FILE
* qq
* FOUND CORRECT ENTRY. FIRST CHECK TO SEE IF IT FITS
* 
GET10 ADB .+2      RETRIEVE START-               X] 
      LDA 1,I         OF-PROGRAM
      STA LIBSP         POINTER 
      ADB .+3       GET PROGRAM 
      LDA 1,I         LENGTH. 
      STA GETLN 
      CMA,INA       COMPUTE FIRST 
      ADA LIBSP       UNUSED WORD 
      STA LIBPB 
      CMA,INA       COMPUTE NEGATIVE
      ADA U4475     TOTAL LENGTH
      SSA,RSS       COMPARE WITH MAX ALLOWED. 
      JMP GET13     OKOO
      LDA .-18
      LDB *+2 
      JMP LIBER 
      DEF *+1 ;;
      OCT 5120      LF-P
      ASC 8,ROGRAM TOO LARGE
* qq
GET13 JSB DATE      SET NEW DATE
      LDB GETPD      INTO 
      ADB .+5       DIRECTORY.
      STA 1,I 
      INB           GET PROGRAM 
      LDA 1,I        DISC ADDRESS.
      STA GETD
* 
      LDA GETP,I    WRITE DIRECTORY 
      STA WORD       BACK TO
      LDA GETP        DISC. 
      ADA .+6 
      LDA 0,I 
      LDB LIBD
      JSB DISCL 
* 
      LDA GETI,I    GET USER'S ID 
      ISZ GETPD     BUMP POINTERS UP TO 
      ISZ GETI      FIRST WORD OF NAME. 
      LDB GETPD,I   GET FIRST WORD OF NAME. 
      CPA A000      IF SYSTEM MASTER, CLEAR 
      ELB,CLE,ERB    RUN ONLY BIT 
      STB GETI,I    STORE FIRST WORD OF NAME. 
      ISZ GETI      BUMP POINTER TO NEXT WORD 
      DLD LTEMP+2   GET LAST 2 WORDS OF NAME. 
      DST GETI,I    STORE IN TABLE. 
* qq
      LDB MLINK+1   SET TO NULL PROGRAM 
      ADB .+?PROG-?LINK 
      LDA GETS
      STA 1,I 
      JSB RDPRG     READ IN CURRENT PROGRAM 
      LDA GETLN      SET UP TRANSFER
      STA WORD        FOR READING IN PROGRAM. 
      LDA GETD
      LDB LIBSP     GET START OF PROGRAM POINTER
      ADB BIT15 
      JSB DISCL 
      JSB SEMIC 
      JMP LLEND     TERMINATE 
* 
GETP  EQU LTEMP+4 
GETPD EQU LTEMP+5 5(
GETI  EQU LTEMP+6 
GETC  EQU LTEMP+7 
GETLN EQU LTEMP+10
GETS  EQU LTEMP+11
GETD  EQU LTEMP+121

$GET  EQU * 
      HED APPEND
* THE APPEND COMMAND ALLOWS A USER TO APPEND A LIBRARY PROGRAM ON TO
* THE END OF HIS CURRENT PROGRAM. THE FIRST STATEMENT OF THE NEW
* PROGRAM MUST HAVE A SEQUENCE NUMBER GREATER THAN THAT OF THE LAST 
* STATEMENT OF THE ORIGINAL PROGRAM. IF THE NEW SECTION IS PROTECTED
* THE ENTIRE PROGRAM WILL BE PROTECTED.  PROGRAMS WITH COMMON MAY 
* NOT BE APPENDED.
* 
* THE CODE FOR APPEND MUST FOLLOW THE CODE FOR "GET". 
      SPC 1 
      ORG LIBRA       THE CODE IS IDENTICAL TO "GET"
      LDA MLINK+1     UP TO LOCATION GET10
      ORG GET10 
* 
      ADB .+2                           [X] 
      LDA 1,I 
      CPA PBUFF     COMMON AREA?
      JMP APP02     NO
      LDA .-23
      LDB *+2 
      JMP LIBER 
      DEF *+1 
      OCT 5116      LF-N
      ASC 11,O COMMON AREA ALLOWED
APP02 JSB DATE      SET DATE OF LAST REFERENCE
      LDB GETPD      INTO DIRECTORY ENTRY.
      ADB .+5 
      STA 1,I I
      ADB .-4       SAVE LIST BIT.
      LDA 1,I 
      STA APPLS S|
      ADB .+5       GET PROGRAM DISC ADDRESS
      DLD 1,I        AND LENGTH.
      STA GETD
      STB GETLN 
* 
      LDA GETP,I    WRITE DIRECTORY 
      STA WORD       BACK TO DISC.
      LDA GETP
      ADA .+6 
      LDA 0,I 
      LDB LIBD
      JSB DISCL 
* 
      JSB RDPRG     READ IN USER'S PROGRAM AND
      JSB DCMPL      DECOMPILE IT.
* *q
      LDA GETLN     TEST FOR PROGRAM TOO
      CMA,INA        LARGE. 
      ADA PBPTR     LAST WORD+1 OF COMBINED PROGS.
      STA LIBPB 
      CMA,INA       COMPUTE NEGATIVE
      ADA U4475     TOTA LENGTH 
      SSA,RSS       COMPARE WITH MAX ALLOWED. 
      JMP APP1      O.K.
      LDA MLINK+1   SET MAIN TO SAY PROGRAM IN
      ADA .-?LINK    CORE.
      STA MAINI^
      LDA .-18
      LDB *+2 
      JMP LIBER 
      DEF *+1 
      OCT 5120      LF-P
      ASC 8,ROGRAM TOO LARGE
* qq
APP1  LDA GETLN     READ IN APPENDED
      STA WORD       PROGRAM. 
      LDA GETD
      LDB PBPTR 
      ADB BIT15 
      JSB DISC,I
* qq
* SCAN ORIGINAL PROGRAM TO DETERMINE LAST SEQUENCE NUMBER.
* 
      LDA SPROG     SET A TO POINT AT LENGTH OF 
      INA            FIRST STATEMENT. 
      LDB PBPTR     SET B TO POINT AT LENGTH OF 
      INB            FIRST NEW PROGRAM. 
      CPA 1         IF EQUAL, PROGRAM IS NULL, SO 
      JMP APP2       IT'S OK. 
      CMA,INA                                    B] 
      ADA 1                                      B] 
      SSA,RSS       SPROG>PBPTR?                 B] 
      JMP APP5-2    NO                           B] 
      LDA PBPTR     YES, RESET                   B] 
      STA SPROG       SPROG                      B] 
      JMP APP2                                   B] 
* 
      LDA SPROG                                  B] 
      INA                                        B] 
APP5  STA APPS      SAVE LOCN OF THIS STATE. LENGTH.
      ADA 0,I       LINK TO NEXT ONE. 
      CPA 1         IF SAVE AS B, APPS=>LAST STATE. 
      RSS 
      JMP APP5      OTHERWISE, LOOP.
* 
      CCA           GET SEQUENCE # OF LAST STATE- 
      ADA APPS       MENT.
      LDA 0,I       MAKE NEGATIVE AND SUBTRACT
      CMA,RSS        ONE. 
APP2  CCA           SET TO -1 (SEQNO=0) IF NO PROG. 
* qq
      LDB ENDSK     WAIT FOR DISC TO TERMINATE. 
      SZB 
      JMP *-2 
* 
      ADA PBPTR,I   CHECK THAT FIRST SEQUENCE # IS
      SSA,RSS        GREATER THAN LAST ONE OF OLD 
      JMP APP3        PROGRAM.
* *q
      LDA MLINK+1   SET MAIN TO SAY PROGRAM IN
      ADA .-?LINK    CORE.
      STA MAIN
      LDA .-24      ERROR.
      LDB *+2 
      JMP LIBER R
      DEF *+1 
      OCT 5123      LF-S
      ASC 11,EQUENCE NUMBER OVERLAP 
* qq
APP3  LDA LIBPB     SET NEW VALUE OF
      STA PBPTR      PBPTR. 
      LDB MLINK+1   GET USER ID.
      ADB .+?ID-?LINK 
      LDA 1,I 
      INB           SET POINTER TO NAME.
      CPA A000      TEST FOR SPECIAL
      JMP APP6       USER.
      LDA APPLS     IF NOT, GET LIST BIT
      AND BIT15      AND MERGE INTO NAME. 
      IOR 1,I 
      STA 1,I 
APP6 ADB  .-?NAME   SET MAIN. 
      STB MAIN
      JMP LLEND     TERMINATE.
* 
APPLS EQU LTEMP+6 
APPS  EQU LTEMP+7 
$APP  EQU * 
