
      HED COPY
* THE COPY COMMAND IS USED TO COPY A PROGRAM OR FILE FROM ONE USER'S
* LIBRARY TO ANOTHER USER'S LIBRARY. THE FORMAT IS: 
* 
*     COPY-OLDID, OLDNAME, NEWID, NEWNAME 
* 
      ORG LIBRA 
      LDA DLTEM 
      JSB COPIN     GET OLD ID AND NAME 
      CPB .+54B     COMMA FOLLOWS?
      RSS           YES 
      JMP LFRER     NO, ERROR 
      LDA COPPT 
      JSB COPIN     GET NEW ID AND NAME 
      CPB .+15B     CR FOLLOWS? 
      RSS           YES 
      JMP LFRER     NO, ERROR 
      JSB DLOKP,I   FIND PROGRAM/FILE 
      JMP COP00 
      LDA COPEG     "NO SUCH ENTRY" 
      LDB COPFG 
      JMP COPIL 
* 
* SAVE INFORMATION FROM THE DIRECTORY ENTRY 
* 
COP00 EQU * 
      LDB COPS
      ADB .+2 
      LDA COPPT 
      ADA .+2 
      STA COPP
      LDA B,I       MOVE
      AND BIT15       FILE
      IOR COPP,I        FLAG
      STA COPP,I
      INB 
      ISZ COPP
      LDA B,I       MOVE
      AND BIT15       SEMI- 
      IOR COPP,I        COMPILED
      STA COPP,I          FLAG
      INB 
      LDA B,I       GET WORD FOUR 
      SSA,RSS       CHECK FOR ILL-STORED PROGRAM
      JMP COP0
      LDA COPEF     "ILL-STORED PROGRAM"
      LDB COPFF 
      JMP COPIL 
COP0  EQU * 
      STA COPP      SAVE WORD 4 
      ADB .+4 
      LDA B,I       FIRST WORD ON DISC ADDRESS
      STA COPDI 
      INB 
      LDA B,I       SECOND WORD OF DISC ADDRESS 
      STA COPDI+1 
      ADB .+2 
      LDA B,I 
      STA COPWD     SAVE LENGTH 
* 
      SSA,RSS 
      JMP *+4 
      ALF,ALF       CONVERT 
      IOR HIMSK       LENGTH
      CMA,INA           TO
      STA COPLN           BLOCKS
* 
* SEARCH FOR NEW ID...FAIL IF NOT FOUND 
* 
      LDA COPPT,I   FIND WHAT 
      STA ID          TRACK NEW 
      JSB FIDTP,I       ID IS ON
      LDB IDTLN,I   GET ADT TRACK LENGTH
      CMB,INB       SET POINTER 
      ADB LIBD        TO LAST 
      STB LTEMP+1       WORD +1 
* 
      LDB LIBD
COP1  EQU * 
      CPB LTEMP+1   END OF TABLE? 
      JMP COP2      YES 
      LDA B,I       NO, GET CURRENT ID
      CMA,INA 
      ADA ID
      SZA,RSS       EQUAL?
      JMP COP3      YES, FOUND THE ONE WE WANT
      SSA           NO, GREATER?
      JMP COP2      YES, ERROR
      ADB .+8       NO, MOVE TO NEXT ONE
      JMP COP1
COP2  EQU * 
      LDA COPEB     "NO SUCH ID"
      LDB COPFB 
      JMP COPIL 
* 
* CHECK FOR ENOUGH SPACE IN USERS LIBRARY 
* 
COP3  EQU * 
      ADB .+7 
      STB COPF      SAVE POINTER TO ENTRY 
      LDA B,I       GET TOTAL 
      ADA COPLN       SPACE USED
      CMA,INA 
      ADB .-1 
      CLE 
      ADA B,I 
      SEZ           COMPARE WITH ALLOTMENT
      JMP COP4      OK
      LDA COPEC     "LIBRARY SPACE FULL"
      LDB COPFC 
      JMP COPIL 
* 
* CHECK FOR ENOUGH SPACE IN SYSTEM
* 
COP4  EQU * 
      LDA .-8       8 POSSIBLE DISC ADTS
      STA COPDF 
COP5  EQU * 
      LDA RKCYP     GET CYCLIC POINTER
      ADA .+3         AND ADVANCE 
      CPA CPLNA         IT TO THE 
      LDA CPLCA           NEXT ENTRY
      STA RKCYP             IN THE TABLE
      ADA .+2 
      STA COPD
      LDA COPD,I
      SZA,RSS       IS THIS DISC AVAILABLE? 
      JMP COP7      NO
      STA MWORD     YES, SAVE LENGTH
      LDA RKCYP     => DISC ADDRESS 
      LDB LIBDI 
      JSB DISCZ,I   READ IT 
      JMP COP7
      CCB           COMPUTE 
      LDA COPD,I      ENTRY 
      DIV .+3           COUNT 
      STA COPC
      LDB LIBD
      ADB .+2       => LENGTH WORD
COP6  EQU * 
      LDA B,I 
      CMA,CLE 
      ADA COPLN 
      SEZ,RSS       ENTRY LARGE ENOUGH? 
      JMP COP10     YES 
      ADB .+3       NO
      ISZ COPC      ANY LEFT? 
      JMP COP6      YES 
COP7  EQU * 
      ISZ COPDF     NO, ANY ADTS LEFT?
      JMP COP5      YES 
* 
COP8  EQU * 
      LDA COPED     "SYSTEM OVERLOAD" 
      LDB COPFD 
      JMP COPIL 
* 
COP9  EQU * 
      LDA COPEE     "DUPLICATE ENTRY" 
      LDB COPFE 
      JMP COPIL 
* 
* DETERMINE IF THE PROGRAM/FILE ALREADY EXISTS IN THE NEWID LIBRARY 
* 
COP10 EQU * 
      LDA COPLN     SAVE
      CMA,INA         NEGATIVE NUMBER 
      ADA B,I           OF BLOCKS LEFT
      STA COPDF 
      ADB .-2       SAVE LOCATION OF
      STB COPC        DISC ADT ENTRY
      DLD B,I       GET DISC ADDRESS
      DST COPDS       AND SAVE
* 
      LDA DLTEM     MOVE ID/NAME
      STA MOVED       TO LTEMP[0:3] 
      LDA COPPT 
      STA MOVES 
      LDB .-4 
      JSB MOVEW 
      JSB DLOKP,I   SEARCH FOR ENTRY
      JMP COP9      FOUND, ERROR
* 
* SEE IF THE DIRECTORY TRACK IS FULL
* 
      LDB COPI,I    IF TRACK IS FULL, GO
      CPB M8184       DO OVERLAY SECTION
      JMP COP98 
* 
* APPARENTLY NOT - ADD THE ENTRY
* 
      CMB           MAKE
      ADB LIBD
      STB MOVES       ROOM
      ADB .+12
      STB MOVED         FOR NEW 
      CMB 
      ADB .+24            DIRECTORY 
      ADB COPS
      JSB MOVEB             ENTRY 
* 
      LDA DLTEM     MOVE
      STA MOVES 
      LDA COPS        ID/NAME 
      ADA .+12
      STA MOVED         INTO
      LDB .-4 
      JSB MOVEW           DIRECTORY 
      LDA COPP      WORD 4
      STA MOVED,I 
      JSB DATE      LAST REFERENCE DATE 
      ISZ MOVED 
      STA MOVED,I 
      ISZ MOVED 
      LDA DATIM     LAST CHANGE DATE
      STA MOVED,I 
      ISZ MOVED 
      CLA           DRUM ADDRESS
      STA MOVED,I 
      ISZ MOVED 
      DLD COPDS     DISC ADDRESS
      DST MOVED,I 
      LDB MOVED 
      ADB .+3 
      LDA COPWD     LENGTH
      STA B,I 
* 
      LDA COPI,I    ADJUST
      ADA .-12        DIRECTORY 
      STA COPI,I        LENGTH
      STA MWORD 
      LDA COPI
      INA 
      STA MOVED 
      ADA .+4 
      LDB LIBD
      STB MOVES 
      JSB DISCZ,I   WRITE DIRECTORY BACK
      JSB DEADP,I 
* 
      LDB .-4       RESET 
      JSB MOVEW       DIREC 
* 
* NOW UPDATE THE IDT
* 
COP11 EQU * 
      LDA IDTLN 
      LDB A,I 
      STB MWORD 
      LDA IDTAD     => ADT DISC ADDRESS 
      LDB LIBDI 
      JSB DISCZ,I   READ IDT AGAIN
      JSB DEADP,I 
* 
      LDA COPF,I    UPDATE
      ADA COPLN       DISC
      STA COPF,I        USED
* 
      LDA IDTAD 
      LDB LIBD
      JSB DISCZ,I   WRITE OUT IDT 
      JSB DEADP,I 
* 
* CLAIM SPACE FROM ADT
* 
      LDA COPD,I
      STA MWORD 
      LDA RKCYP 
      LDB LIBDI 
      JSB DISCZ,I   READ DISC ADT BACK
      JMP COP17     IT'S STUCK ON THE DISC
* 
      LDA COPDF 
      SZA           ADT ENTRY COMPLETELY USED?
      JMP COP15     NO
* 
      LDB COPC      YES, REMOVE IT
      STB MOVED 
      ADB .+3 
      STB MOVES 
      ADB MLIBD 
      ADB MWORD 
      JSB MOVEW 
* 
      LDA .+3 
      LDB COPD,I
      ADB A 
      STB COPD,I    SHORTEN TABLE LENGTH
      ADA MWORD 
      STA MWORD     SHORTEN WORD COUNT
      JMP COP16 
* 
COP15 EQU * 
      LDB COPC
      ADB .+2 
      STA B,I       UPDATE THE LENGTH 
      DLD COPC,I    MOVE THE DISC ADDRESS 
      CLE 
      ADB COPLN       BY LOPLN BLOCKS 
      SEZ 
      INA               AND SAVE IT 
      DST COPC,I
* 
COP16 EQU * 
      LDA RKCYP 
      LDB LIBD
      JSB DISCZ,I   WRITE ADT BACK OUT
      RSS           CAN'T WRITE IT
      JMP COP18 
* 
COP17 CLA 
      CLB 
      STA COPD,I    MAKE ADT
      DST RKCYP,I     DISAPPEAR 
* 
* FINALLY, COPY THE PROGRAM/FILE TO THE NEW SPACE 40 BLOCKS AT A TIME 
* 
COP18 CLB 
      LDA COPLN 
      DIV .+40
      CMA 
      STA COPC      # OF 40 BLOCK READS + WRITES
      STB COPP      # OF BLOCKS IN LAST WRITE 
COP21 EQU * 
      ISZ COPC      ANY 40 BLOCKERS LEFT? 
      JMP COP22     YES 
      LDA COPP      NO, READ AND
      JSB COPRW       WRITE LAST ONE
      JMP LEND      DONE
COP22 EQU * 
      LDA .+40      READ AND WRITE
      JSB COPRW       40 BLOCKS 
      DLD COPDS     UPDATE
      CLE 
      ADB .+40        WRITE 
      SEZ 
      INA               ADDRESS 
      DST COPDS     UPDATE
      DLD COPDI     UPDATE
      CLE 
      ADB .+40        READ
      SEZ 
      INA               ADDRESS 
      DST COPDI 
      JMP COP21     LOOP
* 
* COPRW READS AND WRITES
* 
COPRW NOP 
      ALF,ALF       COMPUTE 
      CMA,INA         # OF
      STA MWORD         WORDS 
      LDA COPIP 
      LDB LIBDI 
      JSB DISCZ,I   READ IT 
      JMP COPDE     FAILURE 
      LDA COPAP 
      LDB LIBD
      JSB DISCZ,I   WRITE IT
      JMP COPDE     FAILURE 
      JMP COPRW,I 
* 
* COPIN GETS AN ID AND NAME 
* 
COPIN NOP 
      STA COPP      => WHERE TO PUT IT
      JSB GETID     GET THE ID
      RSS           YES 
      JMP LFRER     CR CNN'T FOLLOW 
      CPA .+54B     COMMA FOLLOWS?
      CLA,RSS 
      JMP LFRER     NO
      STA COPF        SAY 1ST CHAR
      LDA ID
      STA COPP,I    SAVE ID 
      LDA .-3       6 CHAR
      STA COPC        MAXIMUM 
COPI1 EQU * 
      JSB COPR      GET LEFT CHAR 
      ALF,ALF 
      ISZ COPP
      STA COPP,I    SAVE IT 
      JSB COPR      GET RIGHT CHAR
      IOR COPP,I
      STA COPP,I    SAVE IT 
      ISZ COPC      FINISHED 6 CHARS? 
      JMP COPI1     NO
      JSB COPR      YES, NEXT MUST
      CPA .+40B       BE A BLANK
      JMP COPIN,I   OK
COPI2 EQU * 
      LDA COPEA     "INVALID NAME"
      LDB COPFA 
      JMP COPIL 
* 
* COPR FETCHES CHARACTERS FOR THE NAME
* 
COPR  NOP 
      LDA COPF      TEST TO RETURN BLANK
      CPA .+40B 
      JMP COPR,I
COPR1 EQU * 
      JSB T35CH,I   GET A CHAR
      JMP COPR5 
      LDB A 
      AND .140      SKIP CONTROL CHARACTERS 
      SZA 
      CPA .140
      JMP COPR1 
COPR6 EQU * 
      LDA COPF
      SZA           FIRST CHAR? 
      JMP COPR2     NO
      CPB .+54B     YES, COMMA? 
      JMP LFRER     YES 
      CPB .+44B     NO, '$'?
      JMP COPI2     YES 
      CPB .+52B     NO, '*'?
      JMP COPI2     YES 
      CPB .+15B     NO, CR? 
      JMP LFRER 
COPR3 EQU * 
      LDA B         NO, RESTORE A 
      ISZ COPF
      JMP COPR,I
COPR2 EQU * 
      CPB .+54B     COMMA?
      JMP COPR4     YES 
      CPB .+15B     CR? 
      RSS           YES 
      JMP COPR3     NO
COPR4 EQU * 
      LDA .+40B     RETURN A BLANK
      STA COPF
      JMP COPR,I
COPR5 EQU * 
      LDB A 
      JMP COPR6 
COPDE EQU * 
      LDA COPEH     "UNSUCCESSFUL; KILL AND REPEAT" 
      LDB COPFH 
COPIL EQU * 
      STA MOVES     MOVE ERROR
      LDA T35B1 
      STA MOVED       MESSAGE TO
      STB LTEMP 
      JSB MOVEW         TTY BUFFER
      LDA LTEMP 
      ALS 
      CMA,INA 
      LDB T35B1 
      JMP LEND2 
COPEA DEF *+1 
      OCT 5111
      ASC 6,NVALID NAME 
COPFA EQU .-*+COPEA+1 
COPEB DEF *+1 
      OCT 5116
      ASC 5,O SUCH ID 
COPFB EQU .-*+COPEB+1 
COPEC DEF *+1 
      OCT 5114
      ASC 9,IBRARY SPACE FULL 
COPFC EQU .-*+COPEC+1 
COPED DEF *+1 
      OCT 5123
      ASC 7,YSTEM OVERLOAD
COPFD EQU .-*+COPED+1 
COPEE DEF *+1 
      OCT 5104
      ASC 7,UPLICATE ENTRY
COPFE EQU .-*+COPEE+1 
COPEF DEF *+1 
      OCT 5111
      ASC 9,LL-STORED PROGRAM 
COPFF EQU .-*+COPEF+1 
COPEG DEF *+1 
      OCT 5116
      ASC 7,O SUCH ENTRY
COPFG EQU .-*+COPEG+1 
COPEH DEF *+1 
      OCT 5125
      ASC 6,NSUCCESSFUL 
COPFH EQU .-*+COPEH+1 
COP98 EQU * 
      LDA CM507     SET UP
      STA MWORD       OVERLAY 
      LDA COPOV 
      LDB #LIBI 
      JMP COP99 
* 
COPPT DEF *+1 
      BSS 4 
COPIP DEF COPDI 
COPAP DEF COPDS 
COPOV DEF COM6+SAVO-COM3+SAVO-COM3
CPLNA DEF DKTBL     END OF ADT TABLE
CPLCA DEF ADTAT 
CM507 DEC -507
COPI  EQU LTEMP+4 
COPS  EQU LTEMP+5 
COPDS EQU LTEMP+6   7 ALSO USED 
COPWD EQU LTEMP+8   LENGTH IN WORDS 
COPC  EQU LTEMP+9 
COPP  EQU LTEMP+10
COPDI EQU LTEMP+11  DISC
*                         LTEMP+12    ADDRESS 
COPF  EQU LOUT
COPLN EQU GETID     LENGTH IN BLOCKS
COPD  EQU LCHAR 
COPDF EQU SCHLQ 
* 
      ORG LIBRA+507 
COP99 EQU * 
      JSB DISCZ,I   CALL OVERLAY
      JSB SICKP,I 
      JMP LIBRA 
      JMP COP11     NORMAL RETURN 
      JMP COP8      ERROR RETURN
$COP  EQU * 
