
      HED MAIN SEQUENCE 
* 
* 
KDSC  EQU * 
      CCA           INITIALIZE
      STA SYSLF       SYSTEM LIBRARY             [B]
      STA SYSLF+1       FLAGS                    [B]
      STA LIBRI,I   AVOID TROUBLE ON FIRST COMPARE
      LDA MTFLA,I   LOADING FROM
      CMA,SSA,INA,SZA      MAG TAPE?
      JMP LDR50     YES 
*                                 * 
**  LOAD SYSTEM FROM PAPER TAPE  ** 
*                                 * 
* 
*  READS THE TSB SYSTEM TAPE, OR TAPES IF MORE THAN ONE (EXECUTING
*  A HLT 77 ON RECOGNIZING AN END-OF-TAPE CONDITION).  THE LAST 
*  RECORD IS IDENTIFIED BY AN ORIGIN OF 0.  CHECKSUM'S ARE
*  COMPUTED FOR EACH RECORD: A FAILURE MAY BE RETRIED BY BACKING UP 
*  TO THE START OF THE RECORD.  THE CORE TO BE OCCUPIED BY EACH 
*  RECORD IS CHECKED AGAINST A TABLE OF ADMISSABLE AREAS TO HELP
*  CATCH ORIGIN MIS-READS BEFORE LOADING A RECORD.  RECOVERY
*  MAY BE ATTEMPTED BY BACKING UP TO THE BEGINNING OF THE RECORD. 
* 
LDR46 CLA,RSS       SET FOR START OF TAPE 
      LDA CM10      SET FOR END-OF-TAPE CHECK 
      CCE           GET RECORD'S
LDR47 JSB READA,I     WORD COUNT
      CMB,CCE,INB,SZB   AS NEGATIVE 
      JMP LDR48 
      INA,SZA       FEED FRAME, END-OF-TAPE?
      JMP LDR47     NO
      LDA C.13      YES 
      LDB EOTMA     PRINT 
      JSB ASRDI,I     'END OF TAPE' 
      HLT 77B       WAIT FOR NEXT TAPE
      JMP LDR46 
LDR48 STB COUNT     SAVE WORD COUNT 
      CMB           SAVE TRUE 
      STB CTMP1       WORD COUNT - 1
      JSB READA,I   SKIP FEED FRAME 
      JSB READA,I   READ LOAD ORIGIN
      SZB,RSS       ZERO ORIGIN?
      JMP LDR54     YES 
      LDA 1         NO, INITIALIZE CHECKSUM COUNTER 
      STB CTMP0     SAVE
      STB CTMP3       ORIGIN
      CPB LNKAD     SYSTEM LINKAGE ADDRESSES? 
      JMP LDR49     YES 
      JSB ADVLA,I   NO, VALIDATE ORIGIN 
      LDB 0         COMPUTE LAST ADDRESS
      ADB CTMP1       TO BE LOADED
      JSB ADVLA,I   VALIDATE IT 
LDR49 EQU * 
      STB TPADR     SAVE LOAD ORIGIN
      CPA LIBRI,I   SYSTEM LIBRARY PROGRAM? 
      JSB SYSLB     YES 
LDRFA EQU * 
      CLE           READ A
      JSB READA,I     WORD
      ADA 1         ADD TO CHECKSUM COUNTER 
      STB CTMP0,I   STORE WORD
      ISZ CTMP0     ADVANCE ADDRESS 
      ISZ COUNT     RECORD ALL READ?
      JMP LDRFA     NO
      CLE           YES 
      JSB READA,I   READ CHECKSUM 
      CPB 0         DO CHECKSUMS AGREE? 
      JMP LDR46+1   YES. READ NEXT RECORD 
      STA CTMP1     NO, SAVE
      STB CTMP2       REGISTERS 
      CCB 
      LDA CTMP3     FIRST RECORD OF 
      CPA LIBRI,I     SYSTEM LIBRARY PROGRAM? 
      STB SYSLF+1   YES, PREVENT SPURIOUS        [B]
      LDA C.17        CALL TO SYSLB 
      LDB CHKSA     PRINT 
      JSB ASRDI,I     'CHECKSUM ERROR'
      LDA CTMP1     LOAD REGISTERS
      LDB CTMP2       FOR DISPLAY 
      HLT 66B       WAIT FOR REREAD ATTEMPT 
      JMP LDR46 
* 
*                               * 
**  LOAD SYSTEM FROM MAG TAPE  ** 
*                               * 
* 
*  READ THE TABLE OF SYSTEM RECORDS, THEN READ IN THE RECORDS 
*  THEMSELVES (COMPRISING THE CORE-RESIDENT TSB SYSTEM).  NEXT
*  READ THE SYSTEM LIBRARY PROGRAMS ONE BY ONE, TERMINATING WITH
*  AN END-OF-FILE.
* 
LDR50 CLA           TURN OFF
      STA SYSLF+1     PAPER TAPE FLAG            [B]
      LDA CM512 
      LDB MTRLC 
      JSB MTAPA,I   LOAD
      OCT 0           RECORD
      JMP EOFER 
      JMP TPERR 
      LDB MTRLC     LOAD POINTER TO SST BUFFER
      INB           SKIP OVER THE LENGTH WORD 
LDR51 EQU * 
      STB CTMP4     SAVE THE POINTER
      DLD CTMP4,I   A=-LENGTH, B=CORE ADDRESS 
      JSB MTAPA,I   CALL FOR READ 
      OCT 0 
      JMP EOFER 
      JMP TPERR 
      LDB CTMP4     GET BACK POINTER
      ADB C.4       ADVANCE TO NEXT ENTRY 
      ISZ MTRLC,I   ALL SEGMENTS READ?
      JMP LDR51     NO
      JSB JDSEI,I   RESTORE DISC INTERRUPT LOCS 
LDR52 EQU * 
      LDA CM512     YES 
      LDB LIBRI,I   READ
      JSB MTAPA,I     SYSTEM LIBRARY
      OCT 0             PROGRAM 
      JMP LDR53     END-OF-FILE/END-OF-TAPE 
      JMP TPERR 
      JSB SYSLB     WRITE TO DISC 
      JMP LDR52 
LDR53 EQU * 
      BLF,BLF       END OF FILE BIT TO SIGN 
      SSB,RSS       SKIP IF BIT PRESENT 
      JMP EOFER     NO
      RSS 
LDR54 JSB SYSLB     TRANSFER LAST PAPER TAPE PROGRAM
* 
*                          *
**  WRITE SYSTEM TO DISC  **
*                          *
* 
*  DUMP THE CORE-RESIDENT TSB SYSTEM TO THE DISC FOR POTENTIAL
*  BOOTSTRAP LOADING. 
*  SYSTEM SEGMENT 1 & 2 ARE NOT DUMPED SINCE THEY HAVE ALREADY
*  BEEN DUMPED IN SYSLB.
* 
      LDA MLTBC,I   GET # OF SYSTEM ENTRIES IN SST
      ADA ELDSG     ADD #SEG FOR EQT, LOADER & DIREC
      STA CTMP0     SET COUNTER 
      LDA MLTBD     GET A POINTER TO THE
LDRWF EQU * 
      STA CTMP1       GUTS OF THE TABLE 
      CPA SSEG1     DON'T DUMP
      RSS             SEGMENT 1 
      CPA SSEG2         & SEGMENT 2 
      RSS 
      JSB WRSGA,I 
      LDA CTMP1     => NEXT 
      ADA C.4         SEGMENT 
      ISZ CTMP0     TEST FOR COMPLETION 
      JMP LDRWF 
      JSB WDLTB,I   WRITE BOOTSTRAP TO DISC 
* 
      LDA MTFLA,I   SYSTEM
      SZA,RSS         UPDATE? 
      JMP SPFRB,I   YES 
      INA,SZA       NO, MAG TAPE RELOAD?
      JMP FLRVA,I   YES 
      JMP SPFUA,I   NO, SYSTEM GENERATION 
      SKP 
* 
*  FATAL ERRORS 
* 
RNT   CLA,INA,RSS   EMIT LINE FEED               [B]
* 
AAER  LDA C.22      ALTERNATE ALLOCATION
      LDB AASMA       REQUESTED WITH
      JMP ERRIN         A MISSING DISC           [B]
* 
ITSER EQU * 
      LDA CD37      MAG TAPE TABLES 
      LDB ITSMA       ARE BIGGER THAN 
      JMP ERRIN         THE NEW ALLOCATION       [B]
* 
EOFER EQU * 
      LDA CD25      NO RECORD 
      LDB EOFMA       WHERE 
      JMP ERRIN         EXPECTED                 [B]
* 
LDRWE LDA C.20      OUT OF
      LDB WEOOD       DISC SPACE
      JMP ERRIN                                  [B]
* 
ILSI  LDA C.22      PRINT 
      LDB ILSLA       "ILLEGAL
      JMP ERRIN         SYSTEM CODE"             [B]
* 
SLIBO LDA C.26      OUTPUT
      LDB SYSLA       "SYSTEM LIBRARY 
      JMP ERRIN         OVERFLOW"                [B]
* 
TPERR LDA C.22      TIMING OR 
      LDB TAPEA       PARITY ERROR
* 
ERRIN JSB ASRDI,I   PRINT ERROR                  [B]
* 
      LDA C.20      OUTPUT
      LDB LABOA       TERMINATION 
      JSB ASRDI,I       MESSAGE 
      HLT 1         IRRECOVERABLE 
      JMP *-1         HALT
      SKP 
*                                   * 
**  RECORD SYSTEM LIBRARY PROGRAM  ** 
*                                   * 
* 
*  UPON FIRST ENTRY:
*     SYSLF = -1, 
*     SYSLF+1 = -1 IF LOADING FROM PAPER TAPE OR
*               0 FOR A MAG TAPE RELOAD 
*    MAG TAPE LOADS CALL SYSLB AFTER LOADING A SYSTEM LIBRARY 
*  PROGRAM TO STORE IT ONTO THE DISC; 
*  PAPER TAPE LOADS CALL SYSLB BEFORE LOADING A SYSTEM LIBRARY
*  PROGRAM TO STORE THE PRECEDING ONE ONTO THE DISC, HENCE THE
*  FIRST CALL MUST BE IGNORED.
*    A TABLE OF DOUBLE WORD LENGTHS IN +#BLOCKS OF THE SYSTEM 
*  LIBRARY PROGRAMS IS BUILT FROM THE FIRST SYSTEM LIBRARY PROGRAM
*  (WHICH IS A TABLE OF LENGTHS IN -WORDS OF THE SYSTEM LIBRARY 
*  PROGRAMS). THIS TABLE RESIDES IN CORE; AS EACH PROGRAM IS STORED 
*  ONTO THE DISC, ITS DISC ADDRESS REPLACES ITS LENGTH IN THIS
*  TABLE, WHICH BECOMES THE LINKAGE BETWEEN TSB AND THE SYSTEM
*  LIBRARY.  WHILE SWR(15) IS 'UP', THE LOADER HALTS TO ALLOW 
*  PATCHING JUST BEFORE WRITING EACH PROGRAM ONTO THE DISC. 
* 
SYSLB NOP 
      ISZ SYSLF+1   1ST CALL FOR PAPER TAPE LOAD?[B]
      RSS           NO
      JMP SYSLB,I   YES 
* 
      LIB 1         DEBUGGING AID:
      SSB             HLT 15B BEFORE SYSLIB GOES
      HLT 15B           TO DISC IF SWR(15) = 1
      CLA           FIRST PROGRAM OF
      CPA SYSLF       SYSTEM LIBRARY?            [B]
      JMP SYSL3     NO                           [B]
* 
      LDA MTFLA,I   MAG TAPE                     [B]
      CMA,SSA,INA,SZA    RELOAD?                 [B]
      JMP SYSL0     YES                          [B]
      DLD SWPAA,I   NO, SAVE LEVEL CODES         [B]
      DST TLRT+TLSL   IN TAPE BUFFER             [B]
      DST STMP0         AND STMP0 & STMP1        [B]
      CPA SYSCA,I   OUR SYSTEM?                  [B]
      RSS           YES                          [B]
      JMP ILSI      NO, ABORT LOAD               [B]
      LDA MTFLA,I   SYSTEM                       [B]
      SZA             UPDATE?                    [B]
      JMP SYSL0     NO                           [B]
* 
      LDA CM32      READ                         [B]
      STA MWORD                                  [B]
      LDA TS0B        DISC 0'S                   [B]
      LDB LBTBI                                  [B]
      JSB DISCL,I       LABEL                    [B]
      DLD MTRLT+8   LOAD DISC'S LEVEL CODES      [B]
      CPA SYSCA,I   OUR SYSTEM?                  [B]
      RSS           YES                          [B]
      JMP ILSI      NO, ABORT LOAD               [B]
      LDA B         DISC'S FEATURE LEVEL CODE    [B]
      JSB CKFCB,I   COMPARE WITH                 [B]
      DEF SDISC       SYSTEM'S CODE              [B]
      JMP RNT       RESPONSIBILITY NOT TAKEN     [B]
*                                                             * 
*** WRITE OUT SYSTEM SEGMENT 1 & 2 (LOC DIREU TO 52000B)    *** 
**  IN ORDER TO MAKE CORE AVAILABLE FOR ADT BUFFER.          ** 
*                                                             * 
SYSL0 LDA SSEG1     WRITE OUT                    [B]
      JSB WRSGA,I     SYSTEM SEGMENT 1
      LDA SSEG2     WRITE OUT 
      JSB WRSGA,I     SYSTEM SEGMENT 2
*                                                            *
**  RETURN OLD SYSLIB & SWAP TRACK SPACES IF SYSTEM UPDATE  **
*                                                            *
      LDA MTFLA,I   SYSTEM
      SZA             UPDATE? 
      JMP SYSL1     NO - CONTINUE                [B]
* 
      LDA DSLLN     YES - 
      LDB DSLCA      RETURN SYS LIBRARY SPACE 
      JSB RTADC,I      TO ADT 
      JSB RTSWA,I   RETURN OLD SWAP AREAS TO ADT
*                                                            *
**  CLAIM DISC SPACE FOR NEW SYS LIBRARY & USER SWAP AREAS  **
*                                                            *
SYSL1 EQU *                                      [B]
      CLA 
      STA DSLLN     INIT. #BLOCKS FOR SYS LIB 
      STA SYSLR     INIT. #BLKS FOR CHECKING OVFLO
      LDA LIBRJ,I 
      STA SYSLF     SET MOVE COUNTER             [B]
      LDB COM6I,I   SET 
      STB SLDIR       POINTER TO LENGTH TABLE 
      LDA LIBRI,I   SET POINTER TO
      STA CTMP4       BEGINNING OF LENGTH TABLE 
SYSL2 EQU *                                      [B]
      CCB 
      LDA CTMP4,I   GET LENGTH IN -WORDS
      DIV CM256 
      SZB           EXACT # BLOCKS? 
      INA           NO.ROUND TO #BLOCKS 
      STA SLDIR,I   SAVE LENGTH IN +#BLOCKS 
      ADA DSLLN     ACCUMULATE TOTAL
      STA DSLLN       #BLOCKS FOR SYS LIB 
      ISZ SLDIR     BUMP PTR
      ISZ SLDIR       TO COM6 TABLE 
      ISZ CTMP4     BUMP PTR TO LENGTH TABLE
      ISZ SYSLF     DONE?                        [B]
      JMP SYSL2     NO                           [B]
* 
      JSB CDBA,I    CLAIM DISC SPACE FOR SYSTEM LIB 
*                                     AND USER SWAP AREAS 
      DLD DSLLC     INIT. STARTING
      DST SLDAD       DISC ADDR 
      LDA COM6I,I   INIT PTR
      STA SLDIR       TO COM6 TABLE 
* 
SYSL3 EQU *                                      [B]
      LDA SYSLR     ACCUMULATE
      ADA SLDIR,I     # BLOCKS USED 
      STA SYSLR         FOR SYS LIBRARY 
      CMA,INA       CHECK 
      ADA DSLLN       IF
      SSA               OVERFLOW
      JMP SLIBO     YES 
      LDA SLDIR,I   NO, CONVERT 
      ALF,ALF         TO WORDS
      CMA,INA           AND SET FOR 
      STA MWORD           DISC DRIVER 
      LDA DLBDA     WRITE LIBRARY 
      LDB LIBRI,I     PROGRAM 
      JSB DISCL,I       TO DISK 
      LDA SLDIR,I   SAVE LENGTH 
      STA CTMP5       TEMPORARILY 
      DLD SLDAD     REPLACE LENGTH WITH 
      DST SLDIR,I     STARTING DISC ADDR
      CLE           COMPUTE 
      LDA SLDAD+1     STARTING
      ADA CTMP5          DISC ADDR
      STA SLDAD+1         FOR NEXT
      SEZ                   LIB ROUTINE 
      ISZ SLDAD               USING DOUBLE ADD
      ISZ SLDIR     => NEXT ENTRY 
      ISZ SLDIR       IN COM6 TABLE 
      LDA LIBRI,I   RETURN WITH (A) => ORIGIN 
      JMP SYSLB,I   RETURN
      HED MLOCK/MUNLOCK EXECUTION 
*                       * 
**  INTERPRET REQUEST  ** 
*                       * 
* 
*  SEARCH THE INPUT RECORD FOR: 
*    -<STARTING BLOCK #> [,<ENDING BLOCK #>]
*  INSURE THAT STARTING BLOCK <= ENDING BLOCK AND THAT BOTH 
*  BLOCKS ARE ON THE SAME DISC WHICH MUST BE PRESENT. 
* 
MLKUN EQU * 
      STB LUFLG     SAVE MODE 
MLKU1 EQU * 
      JSB GETCI,I   SEARCH
      JMP MLKU2 
      CPA CDASH       FOR 
      RSS 
      JMP MLKU1         DASH
      JSB LGINT     GET STARTING BLOCK
      JMP MLKU7     NOT FOUND 
      CPA CB54      COMMA FOLLOWING?
      JMP MLKU3     YES 
      CPA CB15      NO, CR? 
      JMP MLKU4     YES 
MLKU2 EQU * 
      LDA C.15      NO, OUTPUT
      LDB ILINC       ERROR 
      JSB ASRDI,I       MESSAGE 
      JMP LD22C,I   ASK AGAIN 
MLKU3 EQU * 
      DLD INTMP     SAVE STARTING 
      DST SBLCK       BLOCK NUMBER
      JSB LGINT     GET ENDING BLOCK NUMBER 
      JMP MLKU7     ERROR 
      CPA CB15      CR FOLLOWS? 
      RSS           YES 
      JMP MLKU2     NO, ERROR 
      LDB SBLCK     COMPUTE 
      LDA SBLCK+1     END BLOCK - 
      JSB TWSUB         START BLOCK 
      SZB,RSS       DIFFERENCE VALID? 
      JMP MLKU5     YES 
MLKU7 EQU * 
      LDA C.22      NO, OUTPUT
      LDB IVBNA       ERROR 
      JSB ASRDI,I       MESSAGE 
      JMP LD22C,I   ASK AGAIN 
MLKU4 EQU * 
      DLD INTMP     SAVE STARTING 
      DST SBLCK       BLOCK NUMBER
      CLA           SET FOR ONE BLOCK 
      SKP 
MLKU5 EQU * 
      INA           SAVE NUMBER 
      STA CTMP0       OF BLOCKS 
      LDA CMHND     CHECK FOR 
      STA CTMP3       BLOCK NUMBER
      JSB CFTD          TOO LARGE 
      SSB,RSS 
      JMP MLKU7     ERROR 
MLKU6 EQU * 
      LDA CTMP3     POINT TO
      ADA CM6         NEXT DISC 
      STA CTMP3         TABLE ENTRY 
      JSB CFTD      ON THIS 
      SSB             DISC? 
      JMP MLKU6     NO
      INA           YES, SAVE FIRST 
      STA CTMP2       UNUSED BLOCK
      DLD SBLCK     CHECK FOR 
      DST INTMP       STARTING BLOCK ALSO 
      JSB CFTD          ON THIS DISC
      CLE,SSB 
      JMP MLKU7     ERROR 
      STA CTMP1     SAVE STARTING BLOCK 
      ADA CM4       GREATER 
      SEZ,RSS         THAN 3? 
      JMP MLKU7     NO, ERROR 
      LDA CTMP3     YES, CHECK
      ADA C.2         FOR 
      LDB A,I           DISC
      LDB B,I 
      SZB,RSS             PRESENT 
      JMP MLKU7     ERROR 
      LDA CTMP3     => ADDRESS WORD 
      STA TMP2C,I     IN DISC TABLE 
      LDA CM256     READ BLOCK
      LDB C.3         THREE 
      JSB DAIRC,I   READ IN 
      LDB LBTBI       LOCKED BLOCKS 
      JSB DISCL,I       TABLE 
      LDA LUFLG 
      SSA           MUNLOCK?
      JMP MLK20     YES 
      SKP 
*                   * 
**  EXECUTE MLOCK  ** 
*                   * 
* 
*  THE LOCKED BLOCKS TABLE, WHICH RESIDES ON BLOCK 3 OF EACH
*  DISC, CONSISTS OF UP TO 128 TWO-WORD ENTRIES.  THE FIRST WORD
*  CONTAINS THE DISC-RELATIVE ADDRESS OF THE LOCKED BLOCKS AND
*  THE SECOND THE NUMBER OF BLOCKS LOCKED.  THE TABLE IS ARRANGED 
*  IN ORDER OF INCREASING DISC ADDRESS.  LOCKING CONSISTS OF
*  ADDING A NEW ENTRY TO THE TABLE, UNLESS IT CAN BE COMBINED 
*  WITH AN ENTRY OR ENTRIES ALREADY IN THE TABLE. 
* 
      JSB LBSRH     SEARCH LOCKED BLOCKS TABLE
      JMP MLK11     SAME STARTING BLOCK 
      JMP MLK14     BETWEEN TWO BLOCKS
      JMP MLK18     INSERT AT END 
      JSB CPB       TABLE FULL, CHECK PRECEEDING
*                                     BLOCK 
      JMP MLK99     ENTRIES MERGED
MLK10 EQU * 
      LDA C.26      OUTPUT
      LDB LBTFA       'TABLE FULL'
      JSB ASRDI,I       MESSAGE 
      JMP LD22C,I 
* 
*  SAME STARTING BLOCK
* 
MLK11 EQU * 
      INB           BUMP TO LENGTH
      LDA CTMP0     IS THE
      CMA,CLE,INA     NEW 
      ADA B,I           BLOCK 
      SEZ                 LONGER? 
      JMP LD22C,I   NO
      LDA CTMP0     YES, RESET
      STA B,I         LENGTH
      INB 
MLK12 EQU * 
      CPB LBND      END OF TABLE? 
      JMP MLK99     YES 
      LDA B,I       ALL ENTRIES 
      SZA,RSS         FINISHED? 
      JMP MLK99     YES 
      ADB CM2 
      LDA B,I       DOES THIS 
      INB 
      ADA B,I         ENTRY 
      CMA,CLE 
      INB               OVERLAP THE 
      ADA B,I 
      SEZ,INB             NEXT ONE
      JMP MLK99     NO
      ADA B,I       YES, ENCLOSE
      SEZ,RSS         THE ENTRY?
      JMP MLK13     YES 
      INA           NO, COMPUTE 
      ADB CM2         NEW LENGTH
      ADA B,I           AND 
      STA B,I             SAVE
      INB,RSS 
MLK13 EQU * 
      ADB CM1       REMOVE OVERLAPPED 
      JSB ELBEN       ENTRY 
      JMP MLK12     LOOP
* 
*  BLOCK BETWEEN TWO ENTRIES
* 
MLK14 EQU * 
      JSB CPB       CHECK PRECEEDING BLOCK
      JMP MLK12     GO CHECK FOR OVERLAP
      JSB MRLBE     INSERT
      LDA CTMP1 
      STA B,I         NEW 
      INB 
      LDA CTMP0         ENTRY 
      STA B,I 
      JMP MLK12-1   GO CHECK FOR OVERLAP
* 
*  INSERT ENTRY AT END
* 
MLK18 EQU * 
      JSB CPB       CHECK PRECEEDING BLOCK
      JMP MLK99     ENTRIES MERGED
      LDA CTMP1     INSERT
      STA B,I 
      INB             NEW ENTRY 
      LDA CTMP0 
      STA B,I           AT TABLE END
      JMP MLK99 
      SKP 
