
* 
*                              *
**  INSERT AN ENTRY INTO ADT  **
*                              *
* 
*  ON ENTRY, ADTEN = POINTER TO ADT BUFFER FOR INSERTING NEW ENTRY. 
*            LTMP1 = POINTER TO LAST LOCATION+1 OF ADT IN BUFFER
*            RMLEN = LENGTH IN +BLOCKS FOR THE NEW ENTRY
*            LDISC = THE LOGICAL DISC # FOR THE ADT IN BUFFER 
*            (A) => DOUBLE WORD DISC ADDRESS FOR THE NEW ENTRY
* 
ISADT NOP 
      STA LTMP2     SAVE POINTER
      LDA RMLEN     LENGTH = 0? 
      SZA,RSS 
      JMP ISADT,I   YES. NO NEED INSERT 
      LDA ADTEN 
      CPA LTMP1     END OF ADT? 
      JMP ISAD2     YES, NO NEED MOVE            [B]
      LDB LTMP1     => DESTINATION
      ADB L.2         WORD
ISAD1 CCA           => ORIGIN                    [B]
      ADA LTMP1       WORD
      STA LTMP1 
      LDA A,I 
      STA B,I 
      CPB ADTEN     ALL MOVED?
      JMP ISAD2     YES                          [B]
      ADB LM1       NO. MOVE
      JMP ISAD1       THE ABOVE ONE              [B]
* 
ISAD2 EQU *                                      [B]
      DLD LTMP2,I   INSERT
      DST ADTEN,I     NEW ENTRY 
      LDA RMLEN         WITH NEW
      LDB ADTEN           DISC ADDR 
      ADB L.2               AND 
      STA B,I                 LENGTH
      JSB CMPLW     GET POINTER TO LENGTH WORD
      LDB A,I       BUMP ADT LENGTH BY -3 
      ADB LM3               DUE TO
      STB A,I                 NEW ENTRY 
      JMP ISADT,I   RETURN
      SKP 
*                                                            *
**  UPDATE POINTERS FOR FSDAD WHEN ADT'S ARE IN CORE BUFFER  *
*                                                            *
BUMP  NOP 
      LDA DCADT     BUMP DCADT (=> 1ST ADT ENTRY) 
      ADA B1400       BY 1400 OCT 
      STA DCADT 
      JSB CMPLW     GET LENGTH WORD TO COMPUTE LAST 
      LDA A,I         LOCATION +1 OF ADT FOR CURRENT
      CMA,INA               AND 
      ADA DCADT               SAVE
      STA LTMP1                 IN LTMP1
      JMP BUMP,I
* 
* 
*  COMPUTE POINTER TO LENGTH WORD OF ADT IN EQT  ** 
* 
*   ON ENTRY, LDISC = LOGICAL DISC #
*   ON EXIT, (A) POINTS TO THE LENGTH WORD
* 
CMPLW NOP 
      LDA LDISC 
      ALS           MULTIPLY
      ADA LDISC       BY 3
      ADA DADLA 
      JMP CMPLW,I 
      SKP 
*                                                          *
**    CLAIM DISC SPACE FOR SYSTEM LIBRARY & SWAP TRACKS.  **
*                                                          *
CDB   NOP 
      LDA MHAD      SET 
CDB1  STA TMP3A,I     FOR FNZSC 
      JSB FNZSC     FIND ACTIVE DISC
      JMP LDRWA,I   OUT OF DISC SPACE ERROR 
      LDA TMP3A,I   SAV => 1ST WORD OF NEXT SEGMENT 
      STA SVTP3       OF MHTBL
      LDA TMP1A,I   SAVE LOGICAL
      STA LDISC       DISC #
      JSB RDADT     READ ADT INTO CORE BUFFER 
      CLA           SET 
      STA LTMP1 
      STA DCBV        UP
      STA DCFLG 
      JSB CMPLW         FOR CALLING 
      LDB A 
      LDA ADTBF             FSDAD 
      STA DCADT 
      LDA DSLLN 
      JSB FSDAD     FIND DISC SPACE 
      JMP CDB2      NO ROOM ON THIS DISC
      DST DSLLC     SAVE ADDRESS ALLOCATED
      LDA LDISC     WRITE BACK
      JSB WRADT       UPDATED ADT 
* 
      JSB CLMSW     CLAIM SWAP TRACKS 
      JMP CDB,I     RETURN. 
* 
CDB2  LDA SVTP3     FINISHED
      CPA MHAD        ALL DISCS?
      JMP LDRWA,I   YES, OUT OF DISC SPACE ERROR
      JMP CDB1      NO. TRY NEXT DISC 
      SKP 
*                                                            *
**  CLAIM SWAP TRACKS AND SAVE DISC ADDRESSES IN TEMPORARY  **
**  TABLE TRKTB WHICH WILL LATER BE COPIED TO TTY TABLE     **
*                                                            *
CLMSW NOP 
      LDA LM64      ZERO OUT
      STA CONT
      LDA TRKTA       TABLE 
      CLB 
SW0   STB A,I           OF DISC ADDRESSES 
      INA 
      ISZ CONT            FOR SWAP AREAS
      JMP SW0 
* 
      LDA NPORT     INIT
      STA CONT        COUNTER 
      LDA TRKTA     INIT
      STA PPTR        PTR TO TRKTB
      LDA NUADA     => SUBROUTINE 
      STA CLMFL       FOR CLAIM 
SW1   CLA 
      STA LDISC 
      JSB RDADT     READ IN ADT FOR DISC 0
      LDA L.40      CLAIM 40 BLOCKS 
      JSB CLAIM       FOR EACH SWAP TRACK 
      DST PPTR,I    SAVE DISC ADDR
      LDA LDISC     WRITE BACK
      JSB WRADT       UPDATED ADT 
      LDA LM128     WRITE OUT 
      STA MWORD       SWAP AREA TABLE 
      LDA MLTLD         TO REFLECT ADT
      LDB TRKTA           IN CASE OF
      JSB DISCI,I           CRASH 
      ISZ PPTR      => NEXT 
      ISZ PPTR        ENTRY IN TRKTB
      ISZ CONT      ALL DONE? 
      JMP SW1       NO. 
      JMP CLMSW,I   YES.RETURN
      SPC 5 
*                                         * 
**  READ ADT INTO CORE BUFFER AT 32000B  ** 
*                                         * 
*   ENTER WITH A = LOGICAL DISC # 
* 
RDADT NOP 
      JSB PTADT     SET A & MWORD 
      SZB,RSS       ADT LENGTH = 0? 
      JMP RDADT,I   YES. DON'T READ 
      LDB ADTBK     READ
      JSB DISCI,I     FROM DISC 
      JMP RDADT,I 
*                                                  *
**  WRITE ADT FROM CORE BUFFER AT 32000B TO DISC  **
*                                                  *
*   ENTER WITH A= LOGICAL DISC #
* 
WRADT NOP 
      JSB PTADT     SET A & MWORD 
      SZB,RSS       ADT LENGTH = 0? 
      JMP WRADT,I   YES. DON'T WRITE
      LDB ADTBF     WRITE 
      JSB DISCI,I     TO DISC 
      JMP WRADT,I 
      SPC 3 
*                                                      *
**  SET A = POINTER TO DISC ADDR WORD OF ADT IN EQT,  **
***     B & MWORD = LENGTH OF ADT IN -WORDS          ***
**  ON ENTRY, A= LOGICAL DISC #                       **
*                                                      *
PTADT NOP 
      MPY L.3       => DISC 
      ADA DADLP        ADDR IN EQT
      LDB A         => LENGTH 
      ADB L.2          WORD 
      LDB B,I       GET LENGTH
      STB MWORD 
      JMP PTADT,I 
      SPC 3 
*                                                         * 
**  READ ADT TO CORE BUFFER AT 32000B & SET:             ** 
*** LTMP1 = 0                                           *** 
**  DCADT = POINTER TO FIRST LOCATION OF ADT BUFFER      ** 
*                                                         * 
*   ENTER WITH A = LOGICAL DISC # 
* 
NUADT NOP 
      JSB RDADT 
      CLA 
      STA LTMP1 
      LDA ADTBF     => BEGINNING
      STA DCADT       OF ADT BUFFER 
      JMP NUADT,I 
      SKP 
*                              *
**  RETURN DISC SPACE TO ADT  **
*                              *
* 
*  ON ENTRY:  (A) = + NUMBER OF BLOCKS TO BE RETURNED 
*             (B) => DOUBLE WORD STARTING DISC ADDRESS
* 
RTADT NOP           MOVED HERE IN VERSION B      [B]
      CLE,SZA,RSS   ANY SPACE TO BE RETURNED? 
      JMP RTADT,I   NO, WE'RE DONE ALREADY
      STA RMLEN     YES, SAVE AMOUNT
      DLD B,I       SAVE THE
      DST DSCA        DISC ADDRESS
      ADB RMLEN     COMPUTE   ( (E)=0 ) 
      SEZ             DISC ADDRESS
      INA               OF FIRST BLOCK
      DST LTMP5          NOT RETURNED 
      LDA MHAD      FIND AN 
      STA TMP3A,I     ACTIVE
RT1   JSB FNZSC         DISC
      JMP RTADT,I   DISC NOT FOUND
* 
*  CHECK IF RELINQUISHED SPACE BELONGS TO THIS DISC 
*  (START ADDR OF SPACE - START ADDR OF DISC) < (MXDAD + 4) 
* 
      DLD DSCA      GET RET. START ADDR 
      DST INTMP       AND SET FOR TWSUB CALL
      LDA TMP2A,I   => 1ST WORD OF MHTBL SEGMENT
      DLD A,I       GET STARTING SECTOR # OF THIS 
      SWP             DISC IN (B),(A) 
      ASR 1             AND CONVERT TO BLOCK ADDRESS
      JSB TWSUA,I   GET (RET. START. ADDR - START.
      SWP             ADDR OF DISC) IN (A),(B) AND
      DST INTMP         SAVE FOR NEXT TWSUB CALL
* 
      CLB,CLE       COMPUTE 
      LDA MXDAB,I     (MXDAD + 4) 
      ADA L.4           USING 
      SEZ                 DOUBLE WORD 
      INB                   ADD 
      JSB TWSUA,I   FIND THE DIFFERENCE 
      SSB,RSS       IS IT < 0 ? 
      JMP RT4       NO, SPACE NOT ON THIS DISC
      SKP 
* 
*  SEARCH DISC'S ADT FOR PLACE TO ADD ENTRY OR
*  COMBINE WITH EXISTING SPACE
* 
      LDA TMP1A,I   SAVE LOGICAL
      STA LDISC       DISC NUMBER 
      JSB CMPLW     COMPUTE POINTER TO ADT LENGTH 
      LDB A,I       CONVERT LENGTH
      CMB,INB         TO + BLOCKS 
      LDA ADTBF     SET ADT ENTRY 
      STA ADTEN       POINTER TO FIRST ENTRY
      STA LTMP3 
      ADA B         RECORD POINTER
      STA LTMP1       TO END OF ADT 
      SZB,RSS       ANY ENTRIES?
      JMP RT9       NO
      LDA LDISC     YES, READ 
      JSB RDADT       ADT TO CORE 
* 
*   COMPARE DISC ADDRESS OF RETURNING SPACE WITH DISC ADDRESS 
*   OF CURRENT ADT ENTRY AS FOLLOWS:
* 
*   1.  IF START OF RETURNING SPACE IMMEDIATELY FOLLOWS CURRENT 
*       ADT ENTRY'S SPACE, COMBINE BY INCREASING ENTRY'S LENGTH.
*        IF THIS REACHES TO NEXT ADT ENTRY, COMBINE THE ENTRIES.
*   2.  IF END OF RETURNING SPACE IMMEDIATELY PRECEDES CURRENT
*       ADT ENTRY'S SPACE, COMBINE BY INCREASING ENTRY'S LENGTH 
*       AND REPLACE ITS DISC ADDRESS WITH THAT OF RETURNED SPACE. 
*   3.  IF END OF RETURNING SPACE PRECEDES CURRENT ADT ENTRY'S
*       SPACE, CREATE NEW ADT ENTRY PRECEDING CURRENT ONE.
*   4.  IF CURRENT ADT ENTRY IS LAST ONE, CREATE NEW ADT ENTRY
*       FOLLOWING IT. 
*   5.  OTHERWISE, MOVE TO NEXT ENTRY AND REPEAT FROM STEP 1. 
* 
RT3   LDA LTMP3     SAVE POINTER TO 
      ADA L.2         CURRENT ENTRY'S 
      STA LTMP4         LENGTH WORD 
      DLD DSCA      COPY STARTING 
      DST INTMP       DISC ADDRESS
      CLE           COMPUTE 
      DLD LTMP3,I     DISC ADDRESS
      ADB LTMP4,I       IMMEDIATELY 
      SEZ                 FOLLOWING 
      INA                   ADT ENTRY'S 
      SWP                     SPACE 
      JSB TWSUA,I   MATCH WITH
      IOR B           RETURNING 
      SZA,RSS           SPACE?
      JMP RT6       YES, AUGMENT CURRENT ENTRY
      DLD LTMP3,I   NO, COPY ENTRY'S
      DST INTMP       STARTING DISC ADDRESS 
      LDA LTMP6     COMPUTE DIFFERENCE
      LDB LTMP5       FROM DISC ADDRESS 
      JSB TWSUA,I       IMMEDIATELY FOLLOWING 
      IOR B               RETURNING SPACE 
      SZA,RSS       MATCH?
      JMP RT5       YES, PREFIX SPACE TO ENTRY
      SSB,RSS       NO, DOES ENTRY FOLLOW NEW SPACE?
      JMP RT9       YES, INSERT NEW ENTRY 
      LDA LTMP3     NO, MOVE TO 
      ADA L.3         NEXT ADT ENTRY
      STA LTMP3         AND INFORM
      STA ADTEN           ISADT 
      CPA LTMP1     ADT EXHAUSTED?
      JMP RT9       YES, APPEND NEW ADT ENTRY 
      JMP RT3       NO, TRY AGAIN 
* 
RT4   LDA TMP3A,I   FINSIHED
      CPA MHAD        ALL DISCS?
      JMP RTADT,I   YES, IGNORE SPACE 
      JMP RT1       NO, TRY NEXT DISC 
* 
*  UPDATE CURRENT ADT ENTRY 
* 
RT5   DLD DSCA      COPY DISC ADDRESS 
      DST LTMP3,I     OF RETURNING SPACE
RT6   LDB LTMP4,I   AUGMENT LENGTH OF 
      ADB RMLEN       CURRENT ADT ENTRY 
      STB LTMP4,I       WITH RETURNED SPACE 
      LDA LTMP3     => NEXT 
      ADA L.3         ADT ENTRY 
      CPA LTMP1     END OF ADT? 
      JMP RT7       YES 
      DLD A,I       NO, GET STARTING DISC ADDRESS 
      DST INTMP       AND SET FOR TWSUB 
      DLD LTMP3,I   COMPUTE 
      CLE             CURRENT ENTRY'S 
      ADB LTMP4,I       NEW 
      SEZ                 ENDING
      INA                   ADDRESS 
      SWP           CHECK IF
      JSB TWSUA,I     STARTING ADDRESS OF NEXT ENTRY
      IOR B             = NEW ENDING ADDRESS OF 
      SZA                 CURRENT ENTRY?
      JMP RT7       NO
      LDA LTMP4     YES,
      LDB LTMP4,I     COMBINE 
      ADA L.3           THE 
      ADB A,I             TWO 
      STB LTMP4,I           LENGTHS 
      SKP 
      ADA LM2       => NEXT ADT ENTRY 
      STA MOVDA,I     & MAKE IT THE DESTINATION WORD
      ADA L.3       ANYTHING
      CPA LTMP1       TO MOVE?
      JMP RT11      NO, SKIP MOVE 
      STA MOVSA,I   SET SOURCE WORD 
      LDB LTMP1     COMPUTE 
      CMB,INB         # WORDS 
      ADB A             TO MOVE 
      JSB MOVEA,I   AND SHORTEN THE ADT 
RT11  JSB CMPLW     UPDATE
      LDB A,I         ADT LENGTH
      ADB L.3           IN
      STB A,I             EQT 
RT7   LDA LDISC     WRITE UPDATED ADT 
      JSB WRADT       BACK TO DISC
      DLD MLTBE     WRITE 
      STA MWORD       UPDATED 
      LDA MLTB2         EQT 
      JSB DISCI,I         TO DISC 
      JMP RTADT,I 
* 
RT9   LDA DSCAA     INSERT NEW
      JSB ISADT       ADT ENTRY 
      JMP RT7 
      SKP 
* 
**  CONVERT A POSITIVE NUMBER OF 5 DIGITS FROM DECIMAL TO ASCII  *
*                                                                *
*   ON ENTRY: (A) = NUMBER TO BE CONVERTED
*             (B) => BUFFER OF 3 WORDS FOR HOLDING THE ASCII
* 
DACV  NOP 
      STA SVAB      SAVE A
      CLA           INITIALIZE
      STA B,I         BUFFER
      INB               TO
      STA B,I             ALL 
      INB                   NULLS 
      STA B,I 
      STB SVAB+1    SAVE (B) => LAST WORD OF BUFFR
      STA DFLG      0 FOR LOW BYTE, -1 FOR HIGH BYTE
      LDA SVAB      GET NUMBER TO CONVERT 
DACV1 EQU * 
      CLB           DIVIDE NUMBER 
      DIV L.10        BY 10 
      ADB LB60      CHANGE REMAINDER INTO ASCII 
      ISZ DFLG      1ST DIGIT OF WORD?
      JMP DACV3     YES - 
      BLF,BLF       NO  PACK WITH 
      ADB SVAB+1,I    1ST DIGIT 
      STB SVAB+1,I
      LDB SVAB+1    DECREMENT 
      ADB LM1         BUFFER
      STB SVAB+1        POINTER 
DACV2 SZA,RSS       QUIT WHEN 
      JMP DACV,I      QUOTIENT 0
      JMP DACV1 
* 
DACV3 EQU * 
      STB SVAB+1,I  SAVE LOW BYTE 
      CCB           SET FLAG
      STB DFLG        FOR HIGH BYTE 
      JMP DACV2 
      HED           CONSTANTS, TEMPORARIES, ETC.
LM2K  OCT -2000 
LM128 DEC -128
LD72  OCT -72 
LM64  DEC -64 
LM32  DEC -32 
LM31  DEC -31 
LM8   DEC -8
LM4   DEC -4
LM3   DEC -3
LM2   DEC -2
LM1   DEC -1
L.2   DEC 2 
L.3   DEC 3 
L.4   DEC 4 
L.6   DEC 6 
L.10  DEC 10
LB12  EQU L.10
L.13  DEC 13
LB15  EQU L.13
L.15  DEC 15
L.17  DEC 17
L.21  DEC 21
L.24  DEC 24
L.25  DEC 25
L.40  DEC 40
LB54  OCT 54
LB60  OCT 60
B1400 OCT 1400
L.100 DEC 100 
LB377 OCT 377 
LB2KM OCT 1777
INF   OCT 77777 
DASH  OCT 55        '-' 
?N    OCT 116 
?Y    OCT 131 
ASCAZ ASC 1,@0
ASCBB ASC 1,
ASCZZ ASC 1,00
DSINP JSB DISCB,I   COMMAND CHANNEL CONTENTS
* 
MAXAD OCT 100100
SYSTA ABS 77700B-24000B 
MAXBA ABS 24000B-2000B
BPAGA ABS 2000B-EQTSE 
INRPA ABS EQTSE-30B 
INRPB ABS 26B 
* 
ADTBF DEF ADTBL     ADT BUFFER ADDRESS
ADTBK DEF ADTBL,I   READ INTO ADT BUFFER
ASRDA DEF TTY35     ADDRESS OF TTY DRIVER 
COFLA DEF COFLG 
DADLA DEF DADLN 
DADLP DEF DADLC 
DISCI DEF DISCZ     DISC DRIVER LINKAGE 
DISPT DEF ADTMP 
DKTBM DEF DKTBL     => DISC SELECT CODE TABLE 
DSCAA DEF DSCA                                   [B]
ERR7A DEF ERR7
GMQBH DEF GMQBF 
INTMA DEF INTMP 
L46A  DEF LDR46 
LBUFD DEF LBLBF     LABEL BUFFER ADDRESS
LBUFI DEF LBLBF,I 
MHEND DEF MHTBL+48  END OF DISC EQT 
MLTB2 DEF MLTBE+2   => DISC ADDRESS OF EQT       [B]
MLTLD DEF MLTLC+2   => DISC ADDRESS OF TRKTB
MOVDA DEF MOVED 
MOVEA DEF MOVEW 
MOVSA DEF MOVES 
MXDAB DEF MXDAD 
NUADA DEF NUADT 
PHBPC DEF PBPC
TMP0A DEF TEMP0 
TMP1A DEF TEMP1 
TMP2A DEF TEMP2 
TMP2I DEF TEMP2,I 
TMP3A DEF TEMP3 
TMP5A DEF TEMP5 
TMP5I DEF TEMP5,I 
TRKTA DEF TRKTB     SYSTEM TRACK TABLE ADDRESS
TWSUA DEF TWSUB 
ADTEN BSS 1 
BADDR BSS 1         POINTER TO NEXT INPUT CHARACTER 
BLANK BSS 1 
CLMFL BSS 1 
CONT  BSS 1 
DCFLG BSS 3         -1 SEZ SEARCH ONLY, OTHERWISE,
*                                   ACTUALLY REMOVE THE SPACE 
DCBV  EQU DCFLG+1   ALTERNATE ALLOCATION FLAG 
DCADT BSS 1         => ADT BUFFER 
DFLG  BSS 1 
DSCA  BSS 2 
FADT  BSS 1 
LDISC BSS 1 
LTMP0 BSS 1 
LTMP1 BSS 1 
LTMP2 BSS 1 
LTMP3 BSS 1 
LTMP4 BSS 1 
LTMP5 BSS 1 
LTMP6 BSS 1 
RMLEN BSS 1 
RQLEN BSS 1 
PPTR  BSS 1 
SBLK  BSS 1 
SCYL  BSS 1 
SLEN  BSS 1 
SVAB  BSS 2 
SVTP3 BSS 1 
* 
BADDA DEF BADD
BDADA DEF BADAD 
BDDLA DEF BDDL
COPTA DEF COPT
ILINL DEF ILIN
ILSCL DEF ILSCD 
LDRWA DEF LDRWE 
      SPC 3 
* 
*  CHECK FOR PAGE OVERFLOW
* 
      LDA 12000B                                 [B]
