
      HED NEWID 
* NEWID CREATES NEW ENTRIES IN THE SYSTEM ID TABLE. THE INPUT 
* FORMAT IS AS FOLLOWS: 
* 
*     NEWID IDCODE,PASSWORD,TIME,DISC 
* 
* THESE PROVIDE, RESPECTIVELY, WORDS 0,1-3,4, AND 6 OF THE ID ENTRY.
* WORDS 5 AND 7 ARE INTIALIZED TO ZERO. 
      SPC 2 
      ORG LIBRA 
* 
* NOW INTERPRET PARAMETERS
* 
      JSB GETID     GET ID & READ IN TRACK
      RSS 
      JMP LFRER 
      CPA .+54B     TEST FOR COMMA. 
      CLA,RSS       OK
      JMP LFRER     ILLEGAL FORMAT
* 
* MOVE IDT TRACK TO LIBUS+8 
* 
      LDA IDTLN,I 
      CMA 
      ADA LIBD
      STA MOVES 
      ADA .+8 
      STA MOVED 
      LDB IDTLN,I 
      JSB MOVEB 
      LDB ID
      STB LTEMP 
* 
* NOW SCAN PASSWORD 
* 
      CLA 
      STA T35LC 
      JSB NEWIP 
      STA LTEMP+1 
      JSB NEWIP 
      STA LTEMP+2 
      JSB NEWIP 
      STA LTEMP+3 
* 
* GET THE ALLOWED TIME
* 
      LDA T35LC     CHECK FOR 
      CPA .+54B      COMMA
      JMP NEWI4 
      JSB T35CH,I   GET NEXT CHAR.
      JMP LFRER 
      CPA .+54B     MUST BE A COMMA.
      RSS 
      JMP LFRER 
* 
NEWI4 JSB NEWI#     GET THE ALLOTTED TIME 
      STA LTEMP+4     IN MINUTES. 
      LDA T35LC 
      CPA .+54B 
      RSS 
      JMP LFRER 
* 
      JSB NEWI#     GET THE DISC ALLOWED. 
      STA LTEMP+6 
      CLB           CLEAR 
      STB LTEMP+5     TIME &
      STB LTEMP+7       DISC USED 
      LDA T35LC     MUST BE END OF
      CPA .+15B      LINE.
      RSS 
      JMP LFRER 
* 
* SEARCH FOR ID ... TERMINATE IF FOUND
* 
      LDB IDTLN,I   SET B TO POINT TO LAST ID ENTRY 
      CMB,INB 
      ADB LIBD
      RSS 
NEWI7 EQU * 
      ADB .-8       POINT TO NEXT ENTRY 
      CPB LIBD      DONE WITH ID TABLE? 
      JMP NEWI5     YES.
      LDA 1,I       GET TABLE ID. 
      ADA MID       SUBTRACT TEST ID. 
      SZA,RSS       TEST FOR EQUAL
      JMP NEWI6     GO PRINT MESSAGE. 
      SSA,RSS       IF LESS WE FOUND A HOLE.
      JMP NEWI7     ELSE LOOP.
NEWI5 EQU * 
      LDA IDTLN,I   GET LENGTH
      CPA N8192     CHECK FOR TRACK FULL
      JMP NWSU        AND SUPERNEW IF SO
* 
* SLIDE ID TABLE UP 
* 
      LDA LIBD      MOVE THE
      STA MOVED      FIRST PART 
      ADA .+8         OF THE ID 
      STA MOVES        TABLE
      CMB,INB       COMPUTE LENGTH OF MOVE. 
      ADB LIBD
      JSB MOVEW 
      LDA DLTEM     MOVE THE
      STA MOVES     NEW PART
      LDB .-8         IN. 
      JSB MOVEW 
      LDA LIBUS     SET UP
      CCB            NEW
      ADB IDTAD     FIRST ID
      STA B,I          ON TRACK 
* 
      LDA IDTLN,I   MODIFY ID LENGTH
      ADA .-8 
      STA IDTLN,I 
      STA MWORD 
      LDA IDTAD     OUTPUT
      LDB LIBD        TO
      JSB DISCZ,I       DISC
      JSB SLVAG,I 
      JMP LEND
* 
* PRINT AN ERROR MESSAGE & TERMINATE
* 
NEWI2 LDA NEWIA     OUTPUT TABLE FULL MESSAGE 
      LDB NEWIB 
      JMP NEWI8 
NEWI6 LDA NEWIE     OUTPUT DUPLICATE ENTRY MESSAGE. 
      LDB NEWIF 
* 
NEWI8 STA MOVES     SET UP FOR MOVE 
      LDA T35B1      ROUTINE
      STA MOVED     MOVE STRING 
      STB LTEMP      INTO BUFFER. 
      JSB MOVEW 
      LDA LTEMP 
      ALS 
      CMA,INA       CALL
      LDB T35B1      DRIVER.
      JMP LEND2 
* 
* OUTPUT MESSAGES 
* 
NEWIA DEF *+1 
      OCT 5111
      ASC 6,D TABLE FULL
NEWIB EQU .-*+NEWIA+1 
NEWIE DEF *+1 
      OCT 5104
      ASC 7,UPLICATE ENTRY
NEWIF EQU .-*+NEWIE+1 
NEWI# NOP           SCAN FOR A NUMBER.
      CLA           INITIALIZE
      STA NEWIT      TO ZERO. 
      JSB T35CH,I   GET NEXT CHARACTER
      JMP NEWIZ     DONE
      ADA M72B      TEST FOR DIGIT
      SSA,RSS 
      JMP NEWIZ     NOT A DIGIT 
      ADA .+10
      CLE,SSA 
      JMP NEWIZ 
      LDB NEWIT 
      ELB,ELB 
      SEZ,SLB,RSS 
      RSS 
      JMP LFRER 
      ADB NEWIT 
      ELB 
      SEZ,SLB,RSS 
      RSS 
      JMP LFRER 
      ADA 1 
      SEZ 
      JMP LFRER 
      JMP NEWI#+2 
NEWIZ LDA NEWIT 
      JMP NEWI#,I 
NEWIP NOP           GET NEXT 2 PASSWORD LETTERS.
      CLA 
      LDB T35LC     IF LAST CHARACTER A 
      CPB .+54B       COMMA, RETURN ZERO. 
      JMP NEWIP,I 
      JSB T35CH,I   GET NEXT CHAR.
      JMP LFRER 
      CPA .+54B     IF A COMMA
      JMP NEWIP+1 
      ALF,ALF       SAVE 1ST
      STA NEWIT      CHAR.
      JSB T35CH,I 
      JMP LFRER 
      CPA .+54B     IF COMMA TAKE AS
      CLA            ZERO.
      ADA NEWIT 
      JMP NEWIP,I 
* 
*         THIS SECTION IS CALLED TO REDISTRIBUTE
*     THE ID TABLE ACROSS ALL AVAILABLE ID TRACKS.
* 
NWSU  EQU * 
      STB NWSV      SAVE POINTER TO ENTRY 
*                                   PRECEEDING NEW ONE
      LDA .-8       FIND THE
      ADA IDEC+3      TOTAL LENGTH
      ADA IDEC+7        OF THE TABLE
      ADA IDEC+11 
      LDB NIDT      CHECK NUMBER OF ID TRACKS 
      CPB .+1       CHECK FOR SINGLE TRACK
      JMP NEWI2     NO MORE ROOM
      CPB .+2       ONLY TWO ID TRACKS? 
      JMP NWSW      YES, DEAL WITH TWO
      LDB .-3       SET COUNT OF ID TRACKS
      STB NWST
      CCB           FIND NUMBER OF
      ASR 3           ENTRIES IN TABLE
      DIV .+3       SPREAD OVER THREE TRACKS
      CPA N1024 
      SZB,RSS 
      CPA N1025 
      JMP NEWI2     FULL, OUTPUT ERROR
      JMP NWTA
* 
* ONLY 2 ID TRACKS ARE AVAILABLE
* 
NWSW  EQU * 
      LDB .-2 
      STB NWST      SET COUNT OF ID TRACKS
      CCB           FIND NUMBER OF ENTRIES
      ASR 3           IN TABLE
      DIV .+2 
      CPA N1024 
      SZB,RSS 
      CPA N1025 
      JMP NEWI2     FULL, OUTPUT ERROR
NWTA  EQU * 
      ADA .-1       INCREASE # OF ENTRIES/TRACK BY
      STA NWSS        ONE AND SAVE
      ADB .-1       LET B COUNT HOW MANY TRACKS WILL
      STB NWSB        BE THIS LARGER SIZE 
* 
      LDA NWSNN     SET TABLE POINTER 
      STA NWSP
      LDB NWSID 
NWTB  EQU * 
      LDA B,I       CHECK 
      CLE,INB         FOR 
      ADA B,I           ZERO
      SEZ                 DISC
      INA                   ADDRESS 
      SZA,RSS       SKIP IF TRACK NOT ALLOCATED 
      JMP NWS5
      ISZ NWSB      TEST FOR BIG TRACK
      RSS           YES 
      ISZ NWSS      NO, SWITCH TO SMALLER SIZE
      LDA NWSS      GET TRACK SIZE
      ALS,ALS         AND CONVERT TO WORDS
      ALS 
NWS5  EQU * 
      STA NWSP,I    STORE TRACK SIZE IN TABLE 
      ADB .+3 
      ISZ NWSP      ADVANCE SIZE TABLE POINTER
      ISZ NWST        AND ID TRACK COUNT
      JMP NWTB
* 
*         TABLE NN NOW CONTAINS THE NEW LENGTHS OF
*     THE THREE ID TRACKS.
* 
      LDA NWSNN     SET UP POINTER
      STA NWSP        TO LENGTH WORD
* 
*         THE MAIN PART OF THIS ALGORITHM CONSISTS OF TWO 
*     SECTIONS.  IN THE FIRST SECTION WE READ AS MUCH AS
*     POSSIBLE INTO THE SWAP AREA.  IN THE SECOND SECTION 
*     WE WRITE AS MUCH AS POSSIBLE.  THE ENTIRE PROCEDURE 
*     IS THEN REPEATED UNTIL WE ARE FINISHED. 
*         THE FOLLOWING MEANINGS ARE ASSOCIATED 
*      WITH THESE VARIABLES:
* 
*     NWSK1 => ID TABLE ENTRY FOR TRACK BEING READ
*     NWSL1 => ID TABLE ENTRY FOR TRACK BEING WRITTEN 
*     NWSK2 =  # OF WORDS READ SO FAR FROM K1 
*     NWSL2 =  # OF WORDS WRITTEN SO FAR ON L1
*     NWS   =  # OF WORDS IN CORE 
*      NWSP  => - # OF WORDS TO BE WRITTEN ON L1
* 
NWS7  EQU * 
      LDA NWSL2     IS # OF WORDS WRITTEN SO FAR TO 
      CMA,INA         L1 = # OF WORDS TO BE WRITTEN 
      CPA NWSP,I
      JMP NWS10     YES GO
* 
NWS8  EQU * 
      LDA NWS       IS THE SWAP AREA FULL?
      ADA NT232 
      SSA,RSS 
      JMP NWS11     YES, GO TO WRITE SECTION
      STA MWORD     NO, SAVE AVAILABLE WORD COUNT 
      LDB NWSK1     HAVE WE READ ALL THREE TRACKS?
      CPB NIDC3 
      JMP NWS11     YES, GO TO WRITE SECTION
      LDA NWSK1,I   A = - # ON THIS TRACK 
      ADA NWSK2     A = - # NOT READ YET
      SZA           ENTIRE TRACK READ YET?
      JMP NWS9      NO
      ADB .+4       YES, TRY NEXT TRACK 
      STB NWSK1 
      STA NWSK2     SET # OF WORDS READ TO ZERO 
      JMP NWS8      TEST THIS TRACK 
* 
NWS9  EQU * 
      LDB A         B = # OF WORDS NOT YET READ 
      CMB,INB       MAKE POSITIVE 
      ADB MWORD     IS # ON TRACK > # WE HAVE 
      SSB             ROOM FOR? 
      JMP NWS9A     NO, READ ENTIRE TRACK 
      LDA MWORD     GET # WE CAN FIT IN 
      ADA B377      REDUCE TO NEXT SMALLER
      AND M256        BLOCK SIZE
NWS9A EQU * 
      SZA,RSS       IF WE CAN'T READ ANY, 
      JMP NWS11       THEN GO TO THE WRITE SECTION
* 
      STA MWORD     SET WORD COUNT FOR READ 
      LDA NWSK2     GET # READ SO FAR 
      CLB           DIVIDE BY 256 TO GET
      ASR 8           BLOCK ADDRESS 
      CCB 
      ADB NWSK1     GET ID TRACK ADDRESS
      ADA B,I       COMPUTE READ ADDRESS
      STA NWTP1+1 
      ADB .-1 
      LDB B,I 
      STB NWTP1 
      LDA NWTP2 
      LDB LIBDI 
      ADB NWS       GENERATE READ ADDRESS AND 
      JSB DISCZ,I   READ IT IN
      JSB DEADP,I   BLEW IT 
* 
      LDB MWORD     UPDATE COUNT OF WORDS 
      CMB,INB         IN CORE 
      ADB NWS 
      STB NWS 
      LDB MWORD     UPDATE COUNT OF WORDS READ
      CMB,INB         FROM THIS TRACK 
      ADB NWSK2 
      STB NWSK2 
* 
      LDA NWSTG     HAVE WE INSERTED THE NEW
      SZA             ENTRY YET?
      JMP NWS8      YES, TRY TO READ SOME MORE
      LDA NWSK1     ARE WE READING THE TRACK
      CPA IDTLN       IT WAS TO GO ON?
      RSS           YES 
      JMP NWS8      NO, TRY TO READ SOME MORE 
      ADB LIBD      DETERMINE IF WE HAVE READ THE 
      CMB             ENTRY PRECEEDING THE NEW ONE
      ADB NWSV
      SSB,RSS 
      JMP NWS8
      INB 
* 
      ISZ NWSTG     INDICATE ENTRY HAS BEEN INSERTED
      LDA LIBD      COMPUTE 
      ADA NWS         MOVE
      ADA .+7           DESTINATION 
      STA MOVED 
      ADA .-8       COMPUTE MOVE SOURCE 
      STA MOVES 
      JSB MOVEB     CALL THE REVERSE MOVER
* 
      LDA MOVES     NOW SET DESTINATION 
      INA             TO POINT AT FIRST 
      STA MOVED         WORD OF HOLE
      LDA DLTEM     SET SOURCE AT LTEMP 
      STA MOVES 
      LDB .-8       MOVE IN ENTRY 
      JSB MOVEW 
* 
      LDA NWS       EIGHT MORE
      ADA .+8         WORDS ARE NOW 
      STA NWS           IN CORE 
      JMP NWS8      CONTINUE READING
* 
*     COME HERE WHEN THE CURRENT OUTPUT TRACK HAS BEEN FILLED 
* 
NWS10 EQU * 
      LDA NWSL1     TEST FOR LAST TRACK 
      CPA NIDC2 
      JMP NWS16     ALL DONE, CLEAN UP IDEC 
      ADA .+4       ADVANCE TO NEXT TRACK 
      STA NWSL1 
      CLA           SET NUMBER OF WORDS WRITTEN 
      STA NWSL2       SO FAR TO ZERO
      ISZ NWSP      ADVANCE POINTER TO WORDS
      JMP NWS7        TO BE WRITTEN 
* 
*         THIS SECTION IS THE OUTPUT SECTION.  THIS SECTION 
*      IS ONLY CALLED WHEN NO MORE CAN BE READ.  THIS SECTION 
*     WRITES OUT AS MUCH AS POSSIBLE UNTIL WE HAVE EXHAUSTED
*     ALL WE HAVE IN CORE OR UNTIL FURTHER OUTPUT WOULD 
*     OVERLAY INFORMATION THAT HAS NOT BEEN READ. 
*         THE FOLLOWING ADDITIONAL VARIABLES
*      ARE USED IN THIS SECTION:
* 
*         NWSS  =  COUNT OF WORDS THAT HAVE BEEN
*                   WRITTEN FROM THE CURRENT CORE LOAD. 
* 
NWS11 EQU * 
      CLA 
NWS15 EQU * 
      STA NWSS      SET # OF WORDS WRITTEN OUT
      LDA NWSL2     SET WORD = -# OF WORDS LEFT TO
      ADA NWSP,I      BE WRITTEN ON L1
      LDB NWSL1     TEST FOR WRITING ON A TRACK 
      CPB NWSK1       NOT YET READ
      JMP NWS12     WE ARE, CHECK FOR OVERLAY 
NWS13 EQU * 
      LDB NWSS      SET B = # LEFT IN CORE
      CMB,INB 
      ADB NWS 
      STB NWSB      SAVE
      ADB A         COMPARE WITH # WE WANT TO WRITE 
      SSB,RSS 
      JMP NWS14     HAVE ENOUGH.  - COUNT IN A
      LDA NWSB      ONLY WRITE WHAT WE HAVE 
      AND M256      MAKE FULL BLOCK 
      CMA,INA       MAKE NEGATIVE 
      JMP NWS14 
NWS12 EQU * 
      LDB NWSL2     IF WRITING ON UNREAD TRACK, MAKE
      CMB,INB        -SURE WE DON'T GO INTO UNREAD
      ADB NWSK2         AREA
      ADB A 
      CMB,SSB,INB,RSS 
      ADA B         CHANGE COUNT TO AVOID OVERLAYING
      JMP NWS13       UNREAD DATA 
* 
*         A NOW CONTAINS THE NEGATIVE COUNT OF WORDS
*     THAT ARE TO BE WRITTEN
* 
NWS14 EQU * 
      STA MWORD     IF NO WORDS ARE TO BE WRITTEN,
      SZA,RSS         GO MOVE CORE FOR NEW INPUT
      JMP NWS17 
      CMA,INA 
      STA NWSB
      LDA NWSL2     TEST FOR FIRST WRITE ON 
      SZA             THIS TRACK
      JMP NWS18 
* 
      LDA NWSL1     IF THIS IS
      ADA .-3         THE FIRST 
      LDB LIBD          WRITE ON THIS 
      ADB NWSS            TRACK, THEN 
      LDB B,I               UPDATE THE
      STB A,I                 IDEC TABLE
      CLA 
* 
NWS18 EQU * 
      CLB           CONVERT WORD COUNT
      ASR 8           TO BLOCK ADDRESS
      CCB 
      ADB NWSL1 
      ADA B,I       ADD IN TRACK ADDRESS
      STA NWTP1+1 
      ADB .-1 
      LDB B,I 
      STB NWTP1 
      LDA NWTP2 
      LDB LIBD      GENERATE
      ADB NWSS        CORE ADDRESS
      JSB DISCZ,I       AND OUTPUT CURRENT PIECE
      JSB DEADP,I   BLEW IT 
      LDA NWSB      ADJUST NUMBER OF WORDS
      ADA NWSL2       OUTPUT TO TRACK 
      STA NWSL2 
      LDB NWSB      ADJUST NUMBER OF CORE WORDS 
      ADA NWSS        WRITTEN OUT SO FAR
      JMP NWS15     LOOP FOR ANY MORE WRITING 
* 
*     COME HERE WHEN WE CAN'T WRITE ANYMORE 
* 
NWS17 EQU * 
      CPA NWSS      IF NOTHING WRITTEN AT ALL, GO 
      JMP NWS7        TRY TO READ AGAIN 
      LDB NWSS      ADJUST NUMBER OF WORDS
      CMB,INB         IN CORE 
      ADB NWS 
      STB NWS 
      CMB,INB       MAKE NEGATIVE FOR MOVE ROUTINE
      LDA LIBD      SET 
      STA MOVED     . DESTINATION 
      ADA NWSS
      STA MOVES         AND SOURCE
      JSB MOVEW 
      JMP NWS7
* 
*         ALL OF THE ID TRACKS HAVE NOW BEEN WRITTEN
*     BACK TO THE DISC.  UPDATE THE WORD COUNTS IN
*     THE IDEC TABLE
* 
NWS16 EQU * 
      LDA NWSNN+1 
      STA IDEC+3
      LDA NWSNN+2 
      STA IDEC+7
      LDA NWSNN+3 
      STA IDEC+11 
      CLA           INDICATE TO SWAPR THAT
      STA LIB         NO LIBRARY PROGRAM IS IN CORE 
      JMP LEND
* 
N1024 DEC -1024 
N1025 DEC -1025 
N8192 DEC -8192 
NT232 ABS 8-ULEN
NWSNN DEF *+1 
      OCT 0,0,0 
NWSV  EQU LTEMP+9 
NWSS  EQU LTEMP+10
NWSB  EQU LTEMP+11
NWSP  EQU LTEMP+12
NWST  EQU LTEMP+13
NWSID DEF IDEC+1    => FIRST DISC ADDRESS 
NWSK1 DEF IDEC+3    => ID TABLE ENTRY FOR READ TRACK
NWSL1 DEF IDEC+3    => ID TABLE ENTRY FOR WRITE TRACK 
NIDC2 DEF IDEC+11 
NIDC3 DEF IDEC+15 
NWSL2 OCT 0         = LENGHT FOR WRITE TRACK
NWSK2 OCT 0         = LENGTH FOR READ TRACK 
NWS   OCT 0         = # OF WORDS IN CORE
NWSTG OCT 0 
NEWIT BSS 1 
NWTP2 DEF *+1 
NWTP1 BSS 2 
$NEW  EQU * 
