
* 
* "TAPE" COMMAND
* 
#TAP  CLF 0 
      LDB TTQ       B => ?FLAG
      INB           B=> ?TNUM 
      LDA B,I       A= ?TNUM
      IOR WTP       ASK WHAT TYPE.
      JSB S14SC,I 
      CLF 0 
      SFS CH2 
      JMP *-1 
      LIA CH2 
      SZA,RSS 
      JMP #TAP1     TYPE #1, OK 
      LDA .-10
      JSB TYPE
      OCT 5111      LF, I 
      ASC 3,LLEGAL
      OCT 6412      CR, LF
      JMP SCH1      PRINT MESSAGE & TERMINATE.
#TAP1 LDB TTQ       B => FLAG WORD
      LDA 1,I 
      IOR TAPEF     SET TAPE BIT
      STA 1,I 
      STF 0 
      INB 
      LDA 1,I       TELL
      IOR TPO 
      JSB S14SC,I     2114
      JMP SCH20     TERMINATE.
* 
* 
#LTEN NOP           CONVERT A # FROM 0-99 TO ASCII. 
      CLB           GET FIRST DIGIT IN A, 
      DIV .+10       SECOND IN B. 
      ALF,ALF       POSITION FIRST ON LEFT, 
      ADA 1         ADD IN SECOND,
      ADA ASC00       ADD IN ASCII BITS.
      JMP #LTEN,I      RETURN.
      SPC 2 
* 
**    TYPE
* 
* 
* TYPE SENDS AN ENTIRE STRING TO A TELETYPE. IT IS CALLED AS FOLLOWS: 
*     A=-#OF CHARS--MUST END ON RIGHT HALF OF WORD
*     JSB TYPE
*     <CHAR STRING> 
*     RETURN
      SPC 1 
TYPE  NOP 
      STA TYPET     SAVE COUNTER
TYPEL LDA TYPE,I    GET WORD CONTAINING CHAR. 
      LDB TYPET     GET COUNT IN B. 
      SLB,RSS       IF COUNT IS EVEN, TAKE HIGH 
      ALF,ALF        CHAR;
      SLB           IF COUNT IS ODD,
      ISZ TYPE       BUMP TYPE. 
      LDB TTQ       OUTPUT CHARACTER TO TTY 
      JSB OUTCH,I 
      ISZ TYPET     ANY MORE? 
      JMP TYPEL     YES.
      JMP TYPE,I    NO. 
TYPET NOP 
      SPC 1 
* 
**    SCOM
* 
* SCOM SCANS A COMMAND INPUT BUFFER TO DETERMINE WHAT 
* THE COMMAND IS. THE CALLING SEQUENCE TO SCOM IS:
* 
*     JSB SCOM
*     <RETURN IF BLANK LINE>
*     <RETURN IF FIRST CHARACTER A DIGIT> 
*     <RETURN IF NO LEGAL COMMAND>
*     <RETURN IF COMMAND FOUNE--B=COMMAND ADDRESS>
* 
* SCOM ASSUMES THAT BEFORE IT IS CALLED, SBHED AND
* SCHL ARE INITIALIZED AS REQUIRED BY SCHAR,, AND 
* SCHP=0 FOR NORMAL USERS AND OCT40 FOR CONSOLE.
      SPC 1 
SCOM  NOP           ENTRY POINT.
      LDB .-3       INITIALIZE CHAR. COUNT TO -3
      STB SCNT
      JSB SCHAR     GET A CHARACTER.
      JMP SCOM,I    NOT THERE-BLANK LINE. 
      ISZ SCOM      BUMP SCOM TO POINT AT DIGIT RET.
      ADA M60B      TEST FOR FIRST CHAR A DIGIT.
      SSA           AUTOMATIC FAILURE IF
      ISZ SCOM       < ASC0 
      ADA .-10
      SSA,RSS       IF <=ASC9, RETURN TO P+2 IF A 
      JMP SCOME       DIGIT, P+3 IF NOT 
      LDB SCHP
      SZB           CONSOLE?
      JMP SCOM,I    YES 
      LDB TTQ       NO
      INB 
      LDA 1,I       TELL 2114 
      IOR BKS 
      JSB S14SC,I     TO BACKSPACE
      JMP SCOM,I
SCOME ISZ SCOM
      ADA M41B      TEST FOR LETTER.
SCOMB SSA,RSS 
      JMP SCOM,I    NOT ALETTER.
      ADA .+32B 
      SSA 
      JMP SCOM,I    NOT A LETTER. 
      IOR SCHP
      ISZ SCNT      TEST FOR 3 LETTERS IN.
      ALF,SLA,RAL   NO--ROTATE FOR NEXT ONE.
      JMP SCOMA     YES--GO TO SEARCH TABLE.
      STA SCHP
      JSB SCHAR     GET NEXT CHARACTER
      JMP SCOM,I    FAIL. 
      ADA M133B 
      JMP SCOMB 
* 
**    SEARCH COMMAND TABLE
* 
SCOMA LDB SCOM1     B=>TABLE
      SSA 
      ADB .+COM4-COM1 
SCOMD CPA 1,I 
      JMP SCOMC     COMMAND FOUND 
      CPB SCOM5 
      JMP SCOM,I    ILLEGAL COMMAND 
      INB 
      JMP SCOMD 
SCOMC ISZ SCOM      RETURN O.K. 
      STB SCHP      SAVE ADDRESS OF COMMAND.
      JSB SCHAR     SCAN
      JMP *+4        FOR CR 
      CPA .+55B     OR DASH.
      RSS 
      JMP *-4 
      LDB SCHP
      JMP SCOM,I
      SKP 
* 
**
***      RELEASE LINE PRINTER 
**
* 
* 
**    SCRLP - USER BUFFER MAY BE FULL 
*             MLINK+1 = POINTER TO USER 
* 
**    SCLPR - USER BUFFER EMPTY 
*             TTQ = POINTER TO USER 
* 
      SPC 1 
SCRLP NOP 
      LDB MLINK+1   INITIALIZE
      ADB .-?LINK     POINTER TO
      STB RLPFW         USER'S FLAG WORD
      LDA .-6 
      STA RLPCT     SET COUNTER 
      LDA LPMES     INITIALIZE POINTER
      STA RLPTR       TO MESSAGE BUFFER 
RLP   LDA RLPTR,I   LOAD NEXT WORD FROM THE BUFFER
      ALF,ALF       A=LEFT CHARACTER
      LDB RLPFW     => FLAG WORD
      JSB OUTCH,I   OUTPUT CHARACTER
      LDA RLPTR,I   A=RIGHT CHARACTER 
      LDB RLPFW     =>FLAG WORD 
      JSB OUTCH,I   OUTPUT CHARACTER
      ISZ RLPTR     INCREMENT POINTER 
      ISZ RLPCT     DONE? 
      JMP RLP       NO
      LDA LPD       YES, TELL I/O PROCESSOR 
      JSB S14SC,I     TO REMOVE USER FROM LP
      CLA           REMOVE USER FROM
      STA PRIST       SYSTEM INDICATOR
      JMP SCRLP,I 
      SPC 2 
SCLPR NOP 
      LDA .-12      A = -# OF CHARACTERS
      JSB TYPE      OUTPUT MESSAGE
LPM   OCT 11423     X-OFF, X-OFF
      OCT 5114      LF, L 
      ASC 3,P FREE
      OCT 6412      CR, LF
      LDA LPD       TELL I/O PROCESSOR TO 
      JSB S14SC,I     REMOVE USER FROM LP 
      CLA           REMOVE USER FROM
      STA PRIST       SYSTEM INDICATOR
      JMP SCLPR,I 
      SPC 1 
LPMES DEF LPM 
RLPFW BSS 1 
RLPCT BSS 1 
RLPTR BSS 1 
      SKP 
* 
**
***     SWAPR 
**
* 
* THE SWAPR ROUTINE IS CALLED FROM VARIOUS POINTS IN THE SCHEDULER
* IN ORDER TO DETERMINE IF A PROGRAM IS READY TO RUN. IT IS ALSO
* CALLED WHENEVER THE QUEUE IS UPDATED. THE FUNCTION OF SWAPR IS TO 
* DETERMINE IF THERE IS A PROGRAM ON THE QUEUE, AND IF SO, IS THE 
* PROGRAM AT THE HEAD OF THE QUEUE READY TO RUN. IF SAID PROGRAM IS 
* NOT READY, SWAPR INITIATES THE NECESSARY DRUM TRANSFERS. SWAPR IN-
* DICATES WHETHER A PROGRAM CAN BE RUN OR NOT AS FOLLOWS: 
* 
*     READY    : NORMAL RETURN
*     NOT READY: TRANSFER TO SCH1 
      SPC 2 
SWAPR NOP 
      LDA MBUSY     TEST FOR
      SSA             DISC BUSY 
      JMP SCH1      WAIT FOR TRANSFER COMPLETION
      LDB SMAIN 
      SZB           WAS SWAPR DOING A TRANSFER? 
      JMP SWAP5     YES, GO CHECK SUCCESS 
      LDB FMAIN     NO, HAVE WE SAVED 
      SZB,RSS         DRIVER FLAGS FOR THIS USER? 
      JMP SWAP7     YES, DON'T SAVE CURRENT ONES
      LDA MBUST     NO, SAVE DISC 
      CMA 
      CLF 0           "NOT BUSY"
      AND FMAIN,I 
      LDB MBUSY         FLAG IN 
      SZB 
      IOR MBUST          THIS USER'S
      STA FMAIN,I 
      STF 0                FLAGS WORD 
      CLB           SAY DRIVER
      STB FMAIN       FLAGS SAVED 
SWAP7 LDB MLINK+1   GET FIRST QUEUE ENTRY 
      CPB MLINK     TEST FOR QUEUE EMPTY. 
      JMP SCH1      EMPTY--NOTHING TO DO. 
      LDA T35F3     HAS A COMMAND BEEN
      CPA .-1         ENTERED BUT NOT STARTED?
      JMP SWAP4     YES - GO START IT 
      LDA LOGCT     NO, IS THERE
      IOR T35F1       CURRENT OR
      CPB T35LN         IMMINENT
      SZA,RSS             OUTPUT TO TTY35?
      JMP SWAP4     NO
      LDA T35ST     GET THE STATUS
      CMA,INA 
      ADA .+%SYNT-.+1+ROS-COM2
      SSA           CHECK TO SEE IF THIS IS 
      JMP SWAP4      A ROUTINE THAT CAN'T BE DEQUED 
      JSB DEQUE      SUSPEND UNTIL ITS DONE.
      LDA T35ST 
      STA T35PR 
      LDA %OUTW 
      STA T35ST 
      JMP SWAPR+1 
* 
SWAP5 CLA           CLEAR "SWAPR INVOKED
      STA SMAIN       TRANSFER" FLAG
      CPA MBUSY     WAS DISC TRANSFER SUCCESSFUL? 
      JMP SWAP7     YES, CONTINUE 
      STA MBUSY     NO, CLEAR MBUSY FOR KICKS 
      SSB           WERE WE SWAPPING A USER?
      JSB SICKP,I   NO, GO FOLD CON GRACIA
      JMP PTZAP,I   YES, GO FLUSH HIM OR HER
      JMP SCH1
      SPC 2 
SWAP4 ADB .+?STAT-?LINK  => STATUS OF FIRST ENTRY 
      LDA 1,I       A=STATUS
      CPA .-2       TEST FOR SPECIAL DISCONNECT.
      LDA %SYNT+1+BYE-COM2
      ADA .-5+COM2-COM3  TEST FOR TYPE II OR III. 
      SSA,RSS 
      JMP SWAP3     PROGRAM IS OF TYPE III. 
      ADB .-?STAT   TEST FOR PROGRAM IN CORE. 
      CPB MAIN
      JMP SWAPR,I   PROGRAM PRESENT.
      LDA MAIN      FIND OUT WHAT PROGRAM IS. 
      SZA           IS ANY PROGRAM PRESENT? 
      JMP SWAP1     YES.
      STB MAIN      SET MAIN TO NEW PROGRAM.
* 
**    INITIATE DISC TO CORE TRANSFER
* 
      STB SMAIN     SAVE TABLE OF USER IN QUESTION
      ADB .+?PROG   B=>PROGRAM END LOCATION.
      LDA 1,I       COMPUTE NUMBER OF 
      STA PBPTR 
      CMA            WORDS IN PROGRAM.
      ADA USE 
      STA MWORD     SAVE -LENGTH
      ADB .+?DISC-?PROG 
      LDA B         A => DISC ADDRESS 
      LDB USEI      B=CORE ADDRESS
SWAP8 JSB DISCA,I   CALL DISC DRIVER
      HLT DEATH+30B DRIVER BUSY 
      HLT DEATH+31B DISC NOT PRESENT
      JMP SCH1      RETURN BUSY.
      SPC 1 
* 
**    INITIATE CORE TO DISC TRANSFER
* 
SWAP2 LDA MAIN
SWAP1 STA SMAIN     SAVE TABLE => OF USER 
      CLB           SET MAIN TO SAY 
      STB MAIN        NO USER IN CORE 
      ADA .+?PROG   SAVE PROGRAM
      LDB PBPTR       END LOCATION
      STB A,I 
      CMB           COMPUTE AND 
      ADB USE         SAVE -TRANSFER
      STB MWORD         LENGTH
      ADA .+?DISC-?PROG  => DISC ADDRESS
      LDB USE            = CORE ADDRESS 
      JMP SWAP8     GO START DISC WRITE 
      SPC 2 
* 
**    TYPE III PROGRAMS 
* 
      SPC 1 
SWAP3 EQU * 
      LDA B,I       GET STATUS
      CPA .+%SYNT-.+1+OPE-COM2
      CLA,RSS       SET PRIORITY TO 0 IF OPEN 
      JMP SWAP6 
      ADB .+?PLEV-?STAT 
      STA B,I 
      ADB .+?STAT-?PLEV 
SWAP6 EQU * 
      ADB .+?RSTR-?STAT  B => RESTART ADDRESS 
      LDA B,I 
      CPA #LIB#     IF THIS A FRESH CALL, 
      STA LCHCR       ZAP THE LCHCR FLAG
      ADB .+?STAT-?RSTR 
      LDA B,I 
      CPA .-2 
      LDA %SYNT+1+BYE-COM2
      ADA .-5+COM2-COM3 
      LDB MAIN      TEST FOR MAIN PROGRAM IN CORE 
      SZB 
      JMP SWAP2     GO TO WRITE OUT MAIN PROGRAM. 
      ALS           MULTIPLY BY 2 
      ADA DCOM6     A=> LIBRARY PROGRAM DISC ADDRESS
      CPA LIB       IS IT IN CORE?
      JMP SWAPR,I   YES--RETURN PRESENT.
      STA LIB       IF NOT, INITIATE READ IN. 
      LDB M512      LENGTH OF PROGRAM = 512 
      STB MWORD 
      CCB           SMAIN = -1 SEZ
      STB SMAIN       READING LIBRARY PROGRAM 
      LDB #LIBI 
      JMP SWAP8     INITIATE DISC READ
      SPC 2 
* 
**    ENTRY POINT FOR INPUT REQUEST 
* 
SCHIQ NOP 
      CLF 0         INTERRUPT INHIBIT.
      LDB MLINK+1 
      ADB .+?TNUM-?LINK 
      IOR 1,I       TELL 2114 
      JSB S14SC,I     ABOUT INPUT WAIT
      CLF 0 
      ADB .+?RSTR-?TNUM 
      LDA SCHIQ 
      STA 1,I 
      INB           GET PROGRAM TYPE
      LDA 1,I 
      SSA           QUIT IF ABORT REQUEST.
      JMP SUSP
      ADB .+?PLEV-?STAT 
      STA 1,I       SET INTO PLEV.
      ADB .+?STAT-?PLEV 
      LDA %INPT     CHANGE STATUS TO
      STA 1,I        INPUT WAIT.
      JMP SUSP       GO REMOVE FROM QUEUE.
      SPC 1 
* 
**    ENTRY POINT FOR TERMINATION 
* 
SCHEQ CLF 0 
      LDA HQDIS     DID THIS GUY TRY TO 
      SZA,RSS         DISCONNECT? 
      JMP SCHQ1     NO
      CLA           YES 
      STA HQDIS     RESET DISCONNECT FLAG 
      LDB MLINK+1 
      ADB .-?LINK 
      LDA 1,I       SET 
      IOR COM14       COMMUNICATIONS
      STA 1,I           BIT 
      ADB .+?STAT 
      LDA %DISC     SET STATUS
      STA 1,I         TO DISCONNECT 
      JMP SUSP
SCHQ1 LDA MLINK+1       DOES THIS 
      ADA .+?TNUM-?LINK   USER HAVE 
      CPA PRIST             THE LINE
      RSS                     PRINTER?
      JMP SCHQ3     NO
      LDA LFLAG     YES - IS THE LPR
      SZA             COMMAND FLAG SET? 
      JMP SCHQ2     YES 
      STA CLC1      NO, BLOCK CLOCK 
      JSB SCRLP     REMOVE USER FROM LP 
SCHQ2 CLA           CLEAR 
      STA LFLAG       FLAG
SCHQ3 LDB MLINK+1   SCRATCH IF
      CPB T35LN 
      JMP *+4 
      ADB .-?LINK    THIS IS
      JSB HTEST       $HELLO. 
      LDB MLINK+1        CHANGE 
      ADB .+?STAT-?LINK  STATUS 
      LDA 1,I 
      CPA .-1       QUIT IF ABORT REQUEST.
      JMP SUSP
      CLA                TO IDLE
      STA 1,I 
      JMP SUSP
      SKP 
* 
**    SCHAR 
* 
* SCHAR FETCHES THE NEXT CHARACTER FROM A BUFFER. BUFFER
* POINTERS FOR SCHAR ARE INITIALIZED AS FOLLOWS:
*     SBHED=> FIRST CHARACTER IF TTY35; =0 OTHERWISE
*     SCHL,I=> END OF TTY35 BUFFER
* 
* SCHAR CALLING SEQUENCE: 
* 
*     JSB SCHAR 
*     RETURN HERE IF CR 
*     RETURN HERE IF ANY OTHER CHARACTER
      SPC 1 
SCHAR NOP 
      LDB SBHED     GET POINTER.
      SZB,RSS       TTY35?
      JMP SCHR1     NO
      CLE,ERB       YES--POSITION AS WORD POINTER 
      LDA 1,I       GET WORD CONTAINING CHARACTER.
      ELB,SLB       REPOSITION POINTER AND TEST 
      RSS                FOR UPPER OR LOWER.
      ALF,ALF 
      AND B377      MASK OUT CHARACTER. 
      CPA .+15B     RETURN IMMEDIATELY IF CR
      JMP SCHAR,I 
      INB           BUMP CHARACTER POINTER. 
      STB SBHED 
      CPA .+40B     SKIP BLANKS 
      JMP SCHAR+2 
      ISZ SCHAR 
      JMP SCHAR,I 
SCHR1 LDB TTQ       FETCH 
      INB 
      LDA 1,I         CHARACTER 
      IOR GTC 
      JSB S14SC,I       FROM 2114 
      SFS CH2       WAIT FOR RESPONSE 
      JMP *-1 
      LIA CH2 
      CPA .+40B     BLANK?
      JMP SCHR1+2   YES--IGNORE IT
      CPA .+15B     NO, CARRIAGE RETURN?
      JMP SCHR2     YES 
      ADA M96       CHECK FOR CODES 
      SSA,RSS        GREATER THAN 140.
      ADA M32       CODE IS LOWER CASE, MAKE UPPER. 
      ADA B140      RESTORE ASCII CODES.
      ISZ SCHAR     NO--EXIT
      JMP SCHAR,I     TO (P+2)
SCHR2 EQU * 
      LDA 1,I       B=>TTY #
      IOR BKS       TELL 2114 
      JSB S14SC,I     TO BACKSPACE
      JMP SCHAR,I 
      SPC 2 
* 
**    DEQUE 
* 
* DEQUE REMOVES A USER FROM THE QUEUE. IT IS CALLED WITH THE USER'S 
* LINK ADDRESS IN B.
* 
DEQUE NOP 
      LDA MLINK     GET POINTER TO FIRST ENTRY. 
DEQ1  CPB 0,I       TEST FOR ENTRY FOUND. 
      JMP DEQ2
      LDA 0,I       LINK TO NEXT ENTRY. 
      CPA MLINK     TEST FOR END OF QUEUE.
      JMP DEQUE,I   NOT ON QUEUE--RETURN. 
      JMP DEQ1      LOOP. 
DEQ2  LDB 1,I       LINK AROUND THIS USER.
      STB 0,I 
      JMP DEQUE,I 
      HED OUTPUT CHARACTER ROUTINE
* THE OUTCH ROUTINE OUTPUTS A CHARACTER TO A USER'S 
* BUFFER IN THE 2114. THE CALLING SEQUENCE IS:
* 
*     JSB OUTCH,I   A=CHARACTER TO BE OUTPUT
*                   B=TTY TABLE ADDRESS.
* 
* OUTCH FIRST CHECKS TO MAKE SURE THAT THE 2114 CAN ACCEPT
* CHARACTERS. IF NOT, THE USER IS PLACED IN OUTPUT WAIT STATUS
* AND A TRANSFER IS MADE INTO THE SYSTEM TO DELETE THE USER 
* FROM THE QUEUE
* 
      SPC 3 
#OUTC NOP 
      CLF 0 
      AND B377      MASK AND
      STA OUTM1     SAVE CHARACTER
      LDA 1,I       CAN 2114
      AND OUTWT       TAKE THIS 
      SZA               CHARACTER?
      JMP OUTC1     NO
      INB           YES 
      LDA 1,I       BUILD OUTPUT WORD 
      IOR OUTM1       WITH USER'S TTY #,
      IOR OCR           CHARACTER AND OPCODE. 
      JSB S14LP,I   CALL 2114 DRIVER
      JMP #OUTC,I 
* 
* TAKE CARE OF FULL BUFFER IN 2114
* 
OUTC1 ADB .+?STAT 
      LDA 1,I 
      SSA           IF ABORTED GO DIRECTLY
      JMP SUSP       TO SUSPEND.
      ADB .+?PLEV-?STAT  MOVE STATUS TO 
      STA 1,I        PLEV AND SET 
      ADB .+?STAT-?PLEV    STATUS TO
      LDA %OUTW             OUTWAIT.
      STA 1,I 
      CCA           SET RETURN ADDRESS TO 
      ADA #OUTC      RECALL OUTC
      ADB .+?RSTR-?STAT 
      STA 1,I 
      LDA OUTM1 
      STA AREG
      ADB .-?RSTR 
      STB BREG
SUSP  LDA MLINK+1,I 
      STA MLINK+1 
      CLA           LOCK
      STA CLC1       CLOCK
      JMP SCH1      JUMP TO SCHEDULER 
* 
SCHOQ NOP           OUTPUT SUSPEND REQUEST ENTRY. 
      CLF 0         TURN OFF INTERRUPT. 
      LDA SCHOQ     SET UP RETURN ADDRESS.
      INA 
SCHSQ EQU * 
      STA #OUTC 
      LDB MLINK+1 
      ADB .-?LINK 
      LDA 1,I 
      IOR OUTWT     SET OUTPUT WAIT BIT 
      STA 1,I 
      INB 
      LDA 1,I       PUT USER
      IOR OWT 
      JSB S14LP,I     IN OUTPUT WAIT
      CLF 0         NO INTERRUPTS DURING SUSPEND
      LDB MLINK+1   FOOL OUTCR INTO DOING THE WORK. 
      ADB .+?STAT-?LINK 
      JMP OUTC1+1 
      SPC 2 
* HTEST SCRATCHES A PROGRAM IF THE ASSOCIATED HFLAG BIT IS SET. 
* B POINTS TO THE USER'S TTY ADDRESS. 
* 
HTEST NOP 
      LDA 1,I 
      AND HFLAG     GET HFLAG BIT.
      SZA,RSS 
      JMP HTEST,I   RETURN IF HFLAG BIT =0. 
      CLF 0 
      XOR 1,I 
      STA 1,I       CLEAR HFLAG BIT 
      STF 0 
      JSB SCRAT 
      JMP HTEST,I   RETURN. 
