
      HED SYSTEM DEATH EMERGENCY TRACK GRABBER
* 
*    THE SALVG ROUTINE IS CALLED WHEN A SYSTEM TRACK WITH VITAL 
*    INFORMATION, SUCH AS A DIRECTORY OR IDT TRACK, CANNOT BE 
*    WRITTEN BACK TO ITS ASSIGNED DISC ADDRESS, BUT WHEN RECOVERY 
*    MIGHT BE POSSIBLE IF THE INFORMATION CAN BE SAVED.  SALVG
*    ASSUMES THE FOLLOWING POINTERS HAVE BEEN SET:
* 
*         LIBUS = STARTING CORE ADDRESS OF THE TRACK
*         MWORD = NEGATIVE LENGTH OF THE TRACK IN CORE
*         STDAP = ADDRESS OF A DOUBLE WORD CONTAINING 
*                 THE TRACK'S DISC ADDRESS
* 
*    SALVG READS THE ADT IN PIECES INTO THE UPPER 2K OF THE USER
*    AREA AND SEARCHES FOR AN ENTRY LARGE ENOUGH TO HOLD THE TRACK. 
*    IF AN ENTRY IS FOUND, THE TRACK IS WRITTEN TO DISC AND ITS NEW 
*    ADDRESS IS STORED INTO THE DOUBLE WORD LOCATION POINTED TO BY
*    STDAP (SYSTEM TABLE DISC ADDRESS POINTER.)  THE ADT IS THEN
*    UPDATED BY RETURNING SPACE FOR THE OLD TRACK AND CLAIMING SPACE
*    FOR THE NEW ONE. 
* 
*    SALVG CALLS CLNOT TO PRINT ANY REMAINING SYSTEM MESSAGES AND 
*    AN INDICATION OF SALVG'S SUCCESS OR FAILURE, AND THEN HALTS. 
*    THE THREE POSSIBLE HALTS HAVE THE FOLLOWING MEANINGS:
* 
*        32B - RECOVERY POSSIBLE BY BOOTING UP FROM DISC
*        33B - RECOVERY POSSIBLE BY LOADING FROM MAG TAPE 
*        34B - RECOVERY IS OUT OF THE QUESTION
* 
      SPC 1 
SALVG NOP 
      CLA           BLOCK 
      STA DCLC1,I     CLOCK 
      LDA STDAP     SAVE ADDRESS
      STA SALAD       POINTER AND 
      LDA MWORD         DISC LENGTH OF
      STA SALLN           TRACK TO BE SALVAGED
      DLD STDAP,I   SAVE DISC ADDRESS 
      DST SDADR       FOR FADT ROUTINE
      LDA .-8       INITIALIZE ADT
      STA SCNT1       TRACK COUNTER 
      LDA SADTP     INITIALIZE ADT
SAL01 STA SADTA       ADDRESS POINTER 
      ADA .+2       INITIALIZE ADT
      STA SADTL       LENGTH POINTER
      DLD SADTA,I   INITIALIZE
      DST SADA,I      CURRENT DISC
      LDA SADTL,I       ADDRESS AND 
      STA SADL            LENGTH
SAL02 LDB SADL      B = -# OF WORDS LEFT
      SZB,RSS       ANY MORE ON THIS TRACK? 
      JMP SAL05     NO
      ADB D1536     REDUCE COUNT BY 6 BLOCKS
      SSB           ANY LEFT? 
      JMP SAL03     YES 
      LDA SADL      NO, GET ORIGINAL LENGTH 
      CLB,RSS       SET ADJUSTED LENGTH TO ZERO 
SAL03 LDA M1536     MAXIMUM LENGTH FOR READ 
      STA MWORD     SET DISC LENGTH WORD
      STB SADL      SAVE ADJUSTED TRACK LENGTH
      CCB           COMPUTE ADT 
      DIV .+3         ENTRY COUNT 
      STA SCNT2         AND SAVE IT 
      LDA SADA      => DISC ADDRESS 
      LDB L8192     = CORE ADDRESS
      ADB BIT15     ADD READ BIT
      JSB DISCZ,I   READ ADT CHUNK
      JMP DOOM      DISC FAILURE - FLUSH SYSTEM 
* 
**    CHECK ADT FOR A LARGE ENOUGH ENTRY
* 
      LDB L8192     => START OF TABLE 
SAL04 ADB .+2       => LENGTH WORD
      LDA B,I       = LENGTH
      ADA M32       IS THIS ENTRY LARGE ENOUGH
      SSA,RSS         FOR THE SYSTEM TRACK? 
      JMP SAL06     YES 
      INB 
      ISZ SCNT2     NO, ANY ENTRIES LEFT? 
      JMP SAL04     YES 
      DLD SADA,I    ADJUST
      CLE             DISC
      ADB .+6           ADDRESS 
      SEZ                 FOR NEXT
      INA                   6 BLOCK 
      DST SADA,I              CHUNK 
      JMP SAL02     CHECK NEXT CHUNK
* 
**    ADJUST POINTERS FOR CHECKING NEXT ADT TRACK 
* 
SAL05 LDA SADTA 
      ADA .+3 
      ISZ SCNT1     ANY TRACKS LEFT?
      JMP SAL01     YES 
* 
**    THIS SYSTEM IS BEYOND HELP
* 
DOOM CLF 0
      LDB SALFA     GET ADDRESS OF FAILURE MESSAGE
      JSB CLNOT     PRINT MESSAGES
      LDA SALVG     GET THE CALLING ADDRESS 
      HLT DEATH+34B EXPIRE
      JMP *-1       NO CHANCE!
      SPC 2 
* 
**    A NEW TRACK HAS BEEN FOUND
* 
SAL06 STA B,I       UPDATE ENTRY'S LENGTH WORD
      ADB .-2       => DISC ADDRESS 
      STB SADTA     SAVE POINTER
      DLD B,I       PUT NEW DISC ADDRESS IN SALVAGED
      DST SALAD,I     TRACK'S CORE RESIDENT TABLE 
      CLE           UPDATE
      ADB .+32        ENTRY'S 
      SEZ               DISC
      INA                 ADDRESS 
      DST SADTA,I           WORDS 
      LDA MWORD     SAVE LENGTH OF ADT CHUNK
      STA SADL        THAT ENTRY WAS FOUND ON 
      LDA SALLN     SET TRANSFER LENGTH OF
      STA MWORD       TRACK TO BE SALVAGED
      LDA SALAD     => NEW DISC ADDRESS FOR TRACK 
      LDB LIBD      => CORE LOCATION
      JSB DISCZ,I   SALVAGE THE TRACK 
      JMP DOOM      DANG IT! TUBE THIS SYSTEM 
      SPC 1 
* 
**    TRACK HAS BEEN SALVAGED - NOW UPDATE ADT
* 
      LDA SADL      SET TRANSFER LENGTH 
      STA MWORD       OF UPDATED ADT CHUNK
      LDA SADA      => DISC ADDRESS OF ADT CHUNK
      LDB L8192     = CORE ADDRESS
      JSB DISCZ,I   WRITE TO DISC 
      JMP SPSUC     BLEW IT 
      JSB SFADT,I   FIND ADT OF SALVAGED TRACK
      LDA SDLPR,I   SET TRANSFER
      STA MWORD       LENGTH WORD 
      LDA SDAPR     => ADT DISC ADDRESS 
      LDB LIBDI     READ IN 
      JSB DISCZ,I     ADT TRACK 
      JMP SPSUC     MORE PROBLEMS 
      LDA .+32      SET AMOUNT TO 
      STA SDALN       BE RETURNED 
      JSB SRBAT,I   RETURN THE BLOCKS 
      LDA SDAPR     WRITE THE 
      LDB LIBD        UPDATED TRACK 
      JSB DISCZ,I       TO THE DISC 
      JMP SPSUC     FOUR OUT OF FIVE AIN'T
*                                     BAD FOR A SICK DISC 
* 
**    THE ADT HAS BEEN UPDATED
* 
      CLF 0 
      LDB SALSU     LOAD ADDRESS OF COMPLETE SUCCESS
      JSB CLNOT     OUTPUT MESSAGES 
      LDA SALVG     LOAD CALLING ADDRESS
      HLT DEATH+32B KICK OFF
      JMP *-1 
      SPC 2 
* 
**    THE ADT COULD NOT BE UPDATED
* 
SPSUC CLF 0 
      LDB SALPS     LOAD ADDRESS OF PARTIAL SUCCESS 
      JSB CLNOT     PRINT MESSAGES
      LDA SALVG     LOAD CALLING ADDRESS
      HLT DEATH+33B DIE 
      JMP *-1 
      SPC 2 
SALSU DEF *+1 
      DEC 72
      OCT 6412
      ASC 17,MOVED SYSTEM TRACK.  EMERGENCY DIS 
      OCT 41415     C-CR
      OCT 5123      LF-S
      ASC 16,LEEP AND THEN BOOT UP FROM DISC. 
      SPC 1 
SALPS DEF *+1 
      DEC 70
      OCT 6412
      ASC 15,MOVED SYSTEM TRACK.  EMERGENCY 
      OCT 6412
      ASC 18,MAG TAPE SLEEP AND RELOAD FROM TAPE. 
      SPC 1 
SALFA DEF *+1 
      DEC 58
      OCT 6412
      ASC 12,CAN'T WRITE SYSTEM TRACK 
      OCT 27015     .-CR
      OCT 5122      LF-R
      ASC 14,ECOVERY OUT OF THE QUESTION. 
      SPC 2 
SALAD BSS 1         => ADDR. OF TRACK TO BE SALVAGED
SALLN BSS 1         = LENGTH OF TRACK TO BE SALVAGED
SCNT1 OCT 0 
SCNT2 OCT 0 
SADTP DEF ADTAT     => ADT TABLE
SADTA BSS 1         ADT DISC ADDRESS POINTER
SADTL BSS 1         ADT TRACK LENGTH POINTER
SADA  DEF *+1       => ADDRESS OF CURRENT ADT CHUNK 
      BSS 2 
SADL  BSS 1         = ADT TRACK REMAINDER'S LENGTH
M1536 DEC -1536 
D1536 DEC 1536
SDLPR EQU LTEMP+11  =DLPTR
SDAPR EQU LTEMP+12  = DAPTR 
SDALN EQU LTEMP+13  = DALEN 
SDADR EQU LTEMP+14  = DADDR 
SFADT DEF FADT      => FIND ADT ROUTINE 
SRBAT DEF RBADT     => RETURN BLOCK TO ADT ROUTINE
      SKP 
*     THIS ROUTINE IS CALLED WHEN THE SYSTEM CANNOT CONTINUE
*     OPERATING BUT MAY BE ABLE TO BE RESUSCITATED. 
      SPC 1 
SICK  NOP 
      CLF 0         DISABLE INTERRUPTS
      LDB SICKM     GET ADDRESS OF OPTIMISTIC MESSAG
      JSB CLNOT     GO PRINT MESSAGES 
      LDA SICK      A GETS CALLING ADDRESS
      HLT DEATH+33B CROAK 
      JMP *-1 
* 
SICKM DEF *+1 
      DEC 59
      OCT 6412
      ASC 19,CAN'T ACCESS SYSTEM SEGMENT OR TABLE.
      ASC 10, RECOVERY POSSIBLE.
      SPC 2 
*     THIS ROUTINE IS CALLED WHEN THE SYSTEM CANNOT CONTINUE
*     OPERATING AND HAS ALTERED ITS TABLES IN SUCH A WAY THAT 
*     THEY CONTAIN CONFLICTING INFORMATION AND RESUSCITATION IS 
*     IMPOSSIBLE. 
      SPC 1 
DEAD  NOP 
      CLF 0         DISABLE INTERRUPTS
      LDB DEADM     GET ADDRESS OF PESSIMISTIC MESAG
      JSB CLNOT     GO PRINT MESSAGES 
      LDA DEAD      A GETS CALLING ADDRESS
      HLT DEATH+34B PASS AWAY 
      JMP *-1 
* 
DEADM DEF *+1 
      DEC 51
      OCT 6412
      ASC 19,SYSTEM TABLES INCOMPATIBLE.  RECOVERY
      ASC 6,IMPOSSIBLE. 
      SPC 2 
*     THIS ROUTINE IS CALLED WHEN THE SYSTEM HAS BLOWN IT WRITING 
*     ON THE LOCKED BLOCKS TABLE OF ONE OF THE DISCS.  THE SITUATION
*     IS SIMILAR TO THOSE WHICH CALL "DEAD", BUT SINCE LOCKED BLOCKS
*     TABLES ARE IMMORTAL, THE OPERATOR MUST BE INFORMED THAT ONE 
*     HAS BEEN DAMAGED. 
      SPC 1 
MDEAD NOP 
      CLF 0         DISABLE INTERRUPTS
      LDB MDEDM     GET ADDRESS OF WARNING MESSAGE
      JSB CLNOT     GO PRINT MESSAGES 
      LDA MDEAD     A GETS CALLING ADDDRESS 
      HLT DEATH+34B MUERTO
      JMP *-1 
* 
MDEDM DEF *+1 
      DEC 54
      OCT 6412
      ASC 16,LOCKED BLOCKS TABLE DESTROYED. 
      ASC 10,RECOVERY IMPOSSIBLE. 
      HED SYSTEM DEATH MESSAGE PRINTER
*     THIS ROUTINE SENDS A SYSTEM DEATH MESSAGE TO THE USERS. 
*     NEXT, IT COMPLETES ANY OUTPUT WHICH HAS BEEN STARTED
*     BY THE SYSTEM CONSOLE DRIVER.  IT THEN PRINTS ANY MESSAGES
*     REMAINING IN THE MESSAGE BUFFER.  IF IT IS ENTERED WITH (B) 
*     NONZERO, IT WILL LAST PRINT THE ASCII STRING WHOSE LENGTH 
*     IS POINTED TO BY (B) AND WHICH STARTS IN THE WORD FOLLOWING 
*     THIS LENGTH.
      SPC 2 
CLNOT NOP 
      CLA           BLOCK 
      STA DCLC1,I     CLOCK 
      STB CLNB      SAVE SPECIAL MESSAGE POINTER
      CCA           INFORM USERS OF 
      JSB TCRIR       SYSTEM DEATH
      CLF 0 
      LDA T35F1     WAS SYSTEM CONSOLE DRIVER 
      SSA,RSS         DOING INPUT OR OUTPUT?
      JMP CLN1      INPUT, GO CHECK FOR MESSAGES
      SFS ?SC       OUTPUT, WAIT FOR CURRENT
      JMP *-1         CHARACTER TO BE OUTPUT
      LDA CLADR,I   GET CHARACTER POINTER 
      CLE,ELA       DOUBLE FOR SYCON AND LOSE BIT 15
      LDB CLTOG,I   GET LEFT-RIGHT WORD 
      SLB           WHERE IS NEXT CHARACTER?
      INA           ON THE RIGHT: BUMP POINTRE
      STA SYCBA     SAVE POINTER FOR SYCON
      LDB TCNT      GET REMAINING CHARACTER COUNT 
      STB SYCCC       AND STORE FOR SYCON 
      LDB CLN1P     GET RETURN ADDRESS
      STB SYCON       AND STORE IN SYCON
      LDA SYBIT,I   GET CURRENT OUTPUT CONTROL BITS 
      JMP SYC3      JUMP INTO MIDDLE OF ROUTINE 
* 
*     COME HERE TO CHECK FOR MORE MESSAGES IN QUEUE 
* 
CLN1  CCA           ARE THERE MESSAGES
      ADA MSQCT       IN THE
      CPA .-1           QUEUE?
      JMP CLN2      NO
      STA MSQCT     YES, DECREMENT THE COUNT
      LDB MSQP1     BUMP POINTER
      ADB .+MESLN     TO NEXT MESSAGE BUFFER
      CPB MSQND     WRAP AROUND?
      LDB MSQBG     YES 
      STB MSQP1     SAVE NEW CURRENT MESSAGE POINTER
      LDA B,I       GET CHARACTER COUNT INTO A
      INB           POINTER TO FIRST WORD INTO B
      JSB SYCON     GO OUTPUT IT
      JMP CLN1      CHECK FOR MORE
* 
*     COME HERE TO PRINT FINAL SPECIAL MESSAGE
* 
CLN2  LDB CLNB      GET SPECIAL BUFFER POINTER
      SZB,RSS       IS THERE A MESSAGE? 
      JMP CLN3      NO
      LDA B,I       YES, GET CHARACTER COUNT
      INB           BUMP POINTER TO FIRST MES. WORD 
      JSB SYCON     GO OUTPUT IT
CLN3  CLA           FINALLY,
      JSB SYCON       OUTPUT 3
      JSB SYCON         "AGONIZING DEATH" 
      JSB SYCON           CRLF'S AND
      JMP CLNOT,I      RETURN 
* 
* 
CLNB  BSS 1         B REG. SAVE WORD
CLADR DEF TADR      POINTER TO ?TT35'S CHAR POINTER 
CLTOG DEF TOG       POINTER TO ?TT35'S LEFT-RIGHT WD
CLN1P DEF CLN1      RETURN ADDRESS FOR FAKE SYCON CL
      HED SYSTEM DEATH OR SWAP TRACK ERROR TOWN CRIER 
*     THIS ROUTINE IS CALLED TO INFORM ALL USERS THAT THE SYSTEM
*     IS GOING DOWN BECAUSE OF A HARDWARE FAILURE OR TO INFORM A
*     SINGLE USER THAT HIS PORT IS BEING MADE UNAVAILABLE (BECAUSE
*     OF A SWAP TRACK ERROR).  IT MUST BE ENTERED WITH THE AFFECTED 
*     PORT NUMBER IN A IN THE LATTER CASE OR WITH A=-1 TO INFORM
*     ALL USERS OF SYSTEM DEATH.
      SPC 2 
TCRIR NOP 
      STA TCRPT     SAVE PORT NUMBER
      CMA,SZA       IS THIS A SYSTEM DEATH? 
      JMP TCR1      NO, GO SET UP FOR 1 PORT NEWS 
      STA TCRPT     YES, SET FIRST PORT TO ZERO 
      LDB NPORT     GET COUNT OF PORTS TO GET NEWS
      STB TCRPC       AND SET IT INTO TCRPC 
      LDA .+32      GET LENGTH OF MESSAGE (CHARS) 
      LDB TCRSD       AND POINTER TO MESSAGE
      JMP TCR2
* 
TCR1  CCA           SINGLE PORT BEING ZAPPED
      STA TCRPC     SET PORT COUNT TO -1
      LDA .+37      GET LENGTH OF MESSAGE 
      LDB TCRPU       AND POINTER TO IT 
* 
TCR2  CMA           SAVE -MESSAGE 
      STA TCRCC       LENGTH-1
      CLE,ELB       SAVE MESSAGE
      STB TCRBA       BUFFER CHARACTER POINTER
* 
      LDA .+15B     PRECEDE 
      JSB TCROT      MESSAGE
      LDA .+12B       WITH
      JSB TCROT        CR 
      LDA .+12B         LF
      JSB TCROT          LF 
* 
TCR3  ISZ TCRCC     ARE THERE MORE CHARACTERS?
      RSS           YES 
      JMP TCR4      NO, GO FINISH UP
      LDB TCRBA     GET BUFFER POINTER
      ISZ TCRBA     BUMP IT 
      CLE,ERB       CALCULATE WORD ADDRESS
      LDA B,I       GET 2 CHARACTERS
      SEZ,RSS       WHICH ONE?
      ALF,ALF       LEFT ONE: MOVE IT 
      AND B177      ISOLATE CHARACTER 
      JSB TCROT     GO SEND IT
      JMP TCR3      CHECK FOR MORE
* 
TCR4  LDA .+15B     SEND
      JSB TCROT      USER(S)
      LDA .+12B       FINAL 
      JSB TCROT        GASP 
      LDA .+12B         FORM
      JSB TCROT          FEEDS
      JMP TCRIR,I 
* 
TCROT NOP           COME HERE TO OUTPUT CHAR IN A 
      STA TCR02     SAVE CHARACTER
      LDA TCRPC     SAVE NUMBER 
      STA TCR03       OF PORTS
      LDA TCRPT         AND FIRST 
      STA TCR04           PORT
TCR5  LDA TCR04     ASK 2114 IF 
      ALF,ALF         THIS USER'S BUFFER
      IOR IBF           IS FULL 
      JSB S14SC,I 
      SFS CH2 
      JMP *-1 
      LIA CH2       GET RESPONSE
      SZA 
      JMP TCR5      YES, GO ASK AGAIN 
      LDA TCR04     NO, GET PORT #
      ALF,ALF 
      IOR OCR         OUTPUT CODE 
      IOR TCR02         AND CHARACTER 
      JSB S14SC,I   GO SEND IT
      ISZ TCR04     BUMP PORT NUMBER
      ISZ TCR03     OUTPUT TO ANOTHER?
      JMP TCR5      YES 
      JMP TCROT,I   NO, RETURN
* 
* 
TCRPU DEF *+1 
      ASC 19,HARDWARE FAILURE -- PORT UNAVAILABLE.
TCRSD DEF *+1 
      ASC 16,HARDWARE FAILURE -- SYSTEM DOWN. 
* 
TCRPT BSS 1         NUMBER OF FIRST PORT TO GET NEWS
TCRPC BSS 1         TOTAL # OF PORTS TO RECEIVE NEWS
TCRCC BSS 1         LENGTH OF MESSAGE 
TCRBA BSS 1         MESSAGE CHARACTER POINTER 
TCR02 BSS 1         OUTPUT CHARACTER
TCR03 BSS 1           ROUTINE 
TCR04 BSS 1             TEMPS 
      HED SYSTEM DEATH TELETYPE DRIVER
*     UPON ENTRY (A) HOLDS THE NUMBER OF CHARACTERS TO BE OUTPUT. 
*     BIT 15 OF A = 0 FOR X-OFF CR LF AFTER OUTPUT. 
*     (B) POINTS TO THE FIRST WORD OF THE BUFFER TO BE OUTPUT.
      SPC 2 
SYCON NOP 
      STA SYCCC     SET CHARACTER COUNT 
      CLE,ELB       INITIALIZE
      STB SYCBA       CHARACTER POINTER 
      LDA SBP       BITS FOR "PRINT ONLY" 
      STA SYBIT,I     SAVE THEM 
SYC3  OTA ?SC         SEND THEM 
SYC1  LDA SYCCC     HAVE ALL CHARACTERS 
      RAL,CLE,ERA    (COPY CRLF BIT INTO E) 
      SZA,RSS         BEEN OUTPUT?
      JMP SYC2      YES, GO SEE ABOUT CRLF
      CCA           NO, DECREMENT 
      ADA SYCCC 
      STA SYCCC       CHARACTER COUNT 
      LDB SYCBA     COMPUTE 
      ISZ SYCBA       WORD-CHARACTER
      CLE,ERB           ADDRESS 
      LDA B,I       LOAD WORD 
      SEZ,RSS       POSITION
      ALF,ALF         CHARACTER 
      AND B177      EXTRACT CHARACTER 
      IOR B200      ADD IN BIT 7
      OTA ?SC       OUTPUT IT 
      STC ?SC,C     REQUEST CHARACTER TRANSFER
      SFS ?SC       WAIT FOR
      JMP *-1         COMPLETION FLAG 
      JMP SYC1      GO DO NEXT CHARACTER
* 
* 
SYC2  SEZ           WANT CRLF?
      JMP SYCON,I   NO, RETURN
      LDA .+3       YES, 3 CHARACTERS 
      IOR BIT15       WITH NO CRLF
      STA SYCCC         FOLLOWING 
      LDB SYCCL     ADDRESS OF
      CLE,ELB         X-OFF CR LF 
      STB SYCBA 
      JMP SYC1      GO OUTPUT THESE 
* 
* 
SYCCC BSS 1         COUNT OF CHARACTERS TO BE OUTPUT
SYCBA BSS 1         CURRENT CHARACTER POINTER 
SYBIT DEF TBITS     POINTER TO CURRENT CONTROL BITS 
SYCCL DEF *+1 
      OCT 011415    X-OFF CR
      OCT 005000    LF
      UNS 
      HED COMMUNICATIONS DRIVERS
* 
*  THESE ROUTINES ARE USED FOR COMMUNICATION BETWEEN THE 2114 
*  AND 2116 
* 
* 2116 TO 2114 SEND DRIVER
* 
      ORG 62000B
S14SH NOP 
      CLF 0 
      STA SVCH2     SAVE COMMUNICATION
      STB SVBC2 
      LDB DCLC1,I   GET CLOCK WORD
      BLF,ELB       IF IT IS A JMP, BIT 12
      CLB             WILL BE SET 
      STB DCLC1,I   BLOCK CLOCK 
      STF 0 
      SFS CH2       WAIT FOR ACKNOWLEDGMENT 
      JMP *-1         OF PREVIOUS TRANSMISSION
      OTA CH2       OUTPUT WORD 
      STC CH2,C     INTERRUPT OTHER MACHINE 
      CLC CH2 
      LDB DCLC2,I 
      CLF 0 
      SEZ           UNBLOCK CLOCK UNLESS IT WAS 
      STB DCLC1,I     BLOCKED WHEN WE ENTERED 
      LDB SVBC2 
      STF 0 
      JMP S14SH,I   EXIT
* 
* 2114 TO 2116 RECEIVE DRIVER 
* 
R14CM NOP 
      STA CMA       SAVE
      STB CMB 
      ERA,ALS         A,B,E 
      SOC 
      INA               AND OVERFLOW
      STA CME 
      LIA CH1       LOAD REQUEST WORD 
      ALF,RAR       OPCODE IN BITS 2-0. 
      AND .+7       MASK TO THREE BITS
      ADA CMTBL     ADD ON DECODE TABLE POINTER 
      JMP 0,I       BRANCH TO APPROPRIATE ROUTINE 
* 
CMTBL DEF *+1,I 
      DEF HVL       HAVE LINE 
      DEF ABR       USER ABORTED
      DEF BFL       BUFFER FULL 
      DEF BFE       BUFFER EMPTY
      DEF ETO       ENTER STATEMENT TIMED OUT 
      DEF UHU       USER HUNG UP
      DEF R14RT 
      DEF R14RT 
      SKP 
* 
* ALWAYS RETURNS HERE 
* 
R14RT LDA CME       RESTORE 
      CLO 
      SLA,ELA         A,B,E 
      STO 
      LDA CMA           AND OVERFLOW
      LDB CMB 
      STC CH1,C     ACKNOWLEDGE RECEIPT 
      JMP R14CM,I   EXIT
* 
* 2114 HAS A LINE 
* 
HVL   JSB FDTTY     B=> FIRST WORD OF TTY TABLE 
      SZA           SKIP IF STATUS IS IDLE. 
      CPA %INPT     NO SKIP IF INPUT WAIT 
      RSS           IDLE OR WAITING FOR INPUT 
      JMP R14RT     IGNORE
      LDA 1,I       SET 2114
      IOR COM14       COMMUNICATION 
      STA 1,I           BIT 
      LIA CH1       STORE RESPONSE
      AND B377        TIME IN TTY 
      ADB .+?RTIM       TABLE (=0 IF NO 
      STA 1,I             ENTER TIMING) 
      JMP R14RT     RETURN TO 2114 DRIVER 
* 
*  USER'S ABORT REQUEST 
* 
ABR   JSB FDTTY     B=> FIRST WORD OF TTY TABLE 
      LDA 1,I 
      AND B30M
      CPA PBFLG     CBFLG=0 AND PBFLG=1?
      JMP R14RT     YES. ABORT NOT ALLOWED^ 
      LDA B,I       NO. ABORT POSIBLE^
      AND UNABT     UNABLE TO 
      SZA,RSS         ABORT?
      JMP ABR1      NO
      LDA 1,I 
      IOR ABTRY     DELAY ABORT 
      STA 1,I           ATTEMPT 
      JMP R14RT     RETURN TO 2114 DRIVER 
ABR1  EQU * 
      ADB .+?STAT   B => STATUS 
      LDA 1,I       A = STATUS
      CPA %SYNT     CHECK FOR SYNTAX. 
      JMP R14RT     CAN'T ABORT OUT OF SYNTAX.
      ADA .+.-%SYNT-1-COM3+COM2 
      SSA           SKIP IF LIBRARY PROGRAM.
      JMP ABR2      OTHERWISE ABORT ALWAYS ALLOWED. 
      LDA .+%SYNT-.+1+CAT-COM2
      CMA,INA       ABORTABLE 
      ADA B,I         LIBRARY 
      SSA               PROGRAM?
      JMP R14RT     NO
      LDA B,I       MAYBE 
      CMA,INA 
      ADA .+%SYNT-.+1+STA-COM2
      SSA 
      JMP R14RT     NO
ABR2  EQU * 
      ADB .-?STAT   B => FLAGS
      LDA 1,I       SET 2114
      IOR COM14       COMMUNICATIONS
      STA 1,I           BIT 
      ADB .+?STAT   SET 
      CCA             STATUS TO 
      STA 1,I           ABORTING
      JMP R14RT     RETRUN TO 2114 DRIVER 
* 
* BUFFER IS FULL
* 
BFL   JSB FDTTY     B =>FIRST WORD OF TTY TABLE 
      CPA %OUTW     IGNORE IF 
      JMP R14RT       ALREADY OUTPUT WAIT 
      LDA 1,I       SET 
      IOR OUTWT       OUTPUT
      STA 1,I           WAIT BIT
      JMP R14RT     RETURN TO 2114 DRIVER 
* 
* 
* BUFFER IS EMPTY AGAIN 
* 
BFE   JSB FDTTY     B=> FIRST WORD OF TTY TABLE 
      CPA %OUTW     CHECK FOR STATUS OUTPUT WAIT
      CCA,CCE,RSS   A _ -1, E _ 1 
      CCA,CLE       A _ -1, E _ 0 
      XOR OUTWT     CLEAR OUTPUT
      AND 1,I           WAIT BIT
      SEZ           IF STATUS # %OUTW, THEN DON'T 
      IOR COM14     SET 2114
      STA 1,I       COMMUNICATIONS BIT
      JMP R14RT     RETURN TO 2114 DRIVER 
* ENTER STATEMENT TIMED OUT 
* 
ETO   JSB FDTTY     B=> FIRST WORD OF TTY TABLE 
      ADB .+?RSTR   B => RESTART ADDRESS
      LDA 1,I       A = RESTART ADDRESS 
      CPA DENRT     WAITING FOR ENTER?
      RSS           YES, SET COM BIT. 
      JMP R14RT     NO, MUST BE MISTAKE.
      ADB .-?RSTR 
      LDA 1,I       SET 2114
      IOR COM14       COMMUNICATIONS
      STA 1,I       BIT 
      ADB .+?STAT   SET 
      LDA %ENTO       STATUS TO 
      STA 1,I           ENTER TIMEOUT 
      JMP R14RT     RETURN TO 2114 DRIVER 
      SKP 
* 
**    USER HUNG UP
* 
UHU   JSB FDTTY     A = USER'S STATUS 
      ADB .+?LINK 
      CPA %SYNT     CAN'T DISCONNECT
      JMP UHU1        OUT OF SYNTAX 
      ADA .+.-%SYNT-1-COM3+COM2 
      SSA           LIBRARY PROGRAM RUNNING?
      JMP UHU2      NO
UHU1  CPB MLINK+1   YES, IS USER HEAD OF QUEUE? 
      JMP UHU3      YES 
UHU2  ADB .+?STAT-?LINK  NO 
      LDA %DISC     SET STATUS
      STA B,I         TO DISCONNECT 
      ADB .+?FLAG-?STAT 
      LDA B,I       SET I/O 
      IOR COM14       COMMUNICATIONS
      STA B,I           BIT 
      JMP R14RT     RETURN
* 
UHU3  STB HQDIS     SET DISCONNECT FLAG 
      JMP R14RT 
**                            **
* FIND FIRST WORD OF TTY TABLE *
**                            **
* EXIT WITH (B) => FIRST WORD OF TELETYPE TABLE 
*           (A) = USERS STATUS
* 
FDTTY NOP 
      LIA CH1       LOAD REQUEST WORD 
      ALF,ALF       TTY# IN 4-0 
      AND .+37B     MASK TO 5 BITS
      MPY .+TTY01-TTY00 
      LDB 0         COMPUT LOCATION 
      ADB DTTY0       OF FLAG WORD
      LDA 1         A => FLAGS
      ADA .+?STAT   A => STATUS 
      LDA 0,I       A = STATUS
      CPA %PUN      CHECK FOR PORT UNAVAILABLE
      JMP R14RT     IGNORE IF SO
      JMP FDTTY,I 
R14ED EQU * 
SVBC2 BSS 1 
DENRT DEF ENTRT     WHERE ENTER WAITS.
* 
*  ROUTINE TO CLEAR PBFLG & CBFLG BITS AND TO TELL
*  THE OTHER MACHINE ABOUT THE ABORT. 
* 
TRNOF NOP 
      ADB .-?STAT   B=> ?FLAG 
      CLF 0 
      LDA B30M      CLEAR PBFLG & CBFLG 
      CMA                BITS.
      AND B,I 
      STA B,I 
      INB           B=> ?TNUM 
      LDA B,I       A= ?TNUM
      IOR ABT       TELL OTHER MACHINE. 
      JSB S14SC,I 
      JMP TRNOF,I 
