* 
**
***   PORT ACTIVITY CHECKER 
**
* 
*  CONTROL COMES HERE TO CHECK THE PORT COMMUNICATIONS BIT FLAG FOR 
*  ANY PENDING PORT ACTIVITY.  AFTER ALL PENDING REQUESTS HAVE BEEN 
*  SERVICED, THE SYSTEM CONSOLE IS CHECKED FOR PENDING ACTIVITY.  IF
*  THERE IS NOTHING TO DO, THIS SECTION SERVES AS THE IDLE LOOP.  IF
*  A PORT IS AWAITING PROCESSING, ITS TELETYPE TABLE ?MASK BIT WILL 
*  BE SET IN THE PORT COMMUNICATIONS BIT FLAG.  THE ?STAT ENTRY WILL
*  THEN INDICATE THE PENDING ACTIVITY AS FOLLOWS: 
* 
%DISC EQU .-2 
* 
*                  DISCONNECT - THE USER IS DEQUEUED; HIS RESTART 
*                  ADDRESS IS SET TO THE LIBRARY ROUTINE ORIGIN,
*                  LIBRA (OCTAL 37300); HIS STATUS IS SET FOR THE 
*                  BYE ROUTINE; AND HE IS REINSERTED ON THE QUEUE 
*                  WITH A PRIORITY OF 2.
* qq
* 
%ABRT EQU .-1 
* 
*                  ABORT - THE USER IS DEQUEUED AND THE "STOP"
*                  MESSAGE IS SENT TO HIS TERMINAL.  IF HE IS 
*                  CURRENTLY RUNNING THE $HELLO PROGRAM, HIS
*                  USER AREA IS SCRATCHED.
* qqq{
* 
%IDLE EQU .+0 
* qq
*                  COMMAND - THE USER IS CURRENTLY IN IDLE MODE 
*                  AND HE HAS ENTERED A COMMAND OR A LINE OF SYNTAX.
*                  THESE CAN BE DISTINGUISHED BY THE FIRST NON-BLANK
*                  CHARACTER WHICH, IF IT IS A DIGIT, SIGNIFIES A 
*                  LINE OF SYNTAX HAS BEEN ENTERED.  IN EITHER CASE 
*                  CONTROL IS PASSED TO THE COMMAND HANDLER.
* 
* *q
%INPT EQU .+2 
* 
*                  INPUT WAIT - THIS INDICATES THAT A USER PROGRAM
*                  WHICH HAD REQUESTED INPUT HAS RECEIVED IT.  THE
*                  USER IS INSERTED ON THE QUEUE WITH A PRIORITY
*                  OF 0.
* 
* 
%OUTW EQU .+3 
* 
*                  OUTPUT WAIT - THE USER WAS SUSPENDED FOR LACK
*                  OF OUTPUT BUFFER SPACE.  THE BUFFER NOW HAS
*                  SPACE AVAILABLE SO THE USER IS PLACED ON THE 
*                  QUEUE WITH A PRIORITY OF 0.
* 
* 
*    IF THE USER IS SCHEDULED TO RUN, HE WILL BE ON THE QUEUE.  THE 
*    QUEUE CONSISTS OF THE QUEUE HEAD, MLINK, AND THE TELETYPE TABLE
*    ?LINK ENTRIES OF EACH USER WHO IS SCHEDULED TO RUN.  EACH ?LINK
*    ENTRY, STARTING WITH MLINK+1, POINTS TO THE NEXT USER ON THE 
*    QUEUE.  THE LAST ENTRY ON THE QUEUE WILL POINT BACK TO MLINK+1,
*    THUS IF MLINK+1 POINTS TO ITSELF, NO ONE IS ON THE QUEUE.
*    SCHEDULED USERS HAVE ONE OF THE FOLLOWING STATUS:
* qq
%SYNT EQU .+4 
* *q
*                  SYNTAX - THE USER HAS ENTERED A LINE OF SYNTAX 
*                  AND IS WAITING FOR INTERPRETATION. 
* qq
* 
%RUN  EQU .+5 
* 
*                  RUN - THIS IS THE STATUS OF THE FIRST COMMAND
*                  IN THE COMMAND TABLE.  ALL OTHER COMMANDS ARE
*                  SCHEDULED AS AN INCREMENTAL VALUE OF THE RUN 
*                  COMMAND, SOLELY DEPENDENT ON THEIR PHYSICAL
*                  LOCATION IN THE COMMAND TABLE.  THUS THE LIST
*                  COMMAND, WHICH RESIDES IN THE TABLE JUST AFTER 
*                  RUN, HAS THE STATUS OF %RUN+1. 
      SPC 2 
SCH54 STF 0 
      LDA MPCOM     ANY PENDING 
      SZA,RSS         ACTIVITY? 
      JMP SCH5      NO, CHECK SYSTEM CONSOLE
      LDB DTTY0     YES, COMPUTE ADDRESS OF TABLE 
      SLA,RAR       ENTRY FOR SIGNALLING TELETYPE.
      JMP *+3       FOUND.
      ADB .+TTY01-TTY00 
      JMP *-3 
      STB TTQ       SAVE ADDRESS IN TTQ 
      ADB .+?ID     STORE ID ADDRESS IN 
      STB SCHID      SCHID. 
      CLF 0         INHIBIT MULTIPLEXOR.
      ADB .+?MASK-?ID 
      LDA 1,I       CLEAR MPCOM BIT.
      XOR MPCOM 
      STA MPCOM 
      ADB .+?STAT-?MASK  B=>STATUS. 
      LDA B,I       A = STATUS
      ADA .+.-%SYNT MAKE SURE STATUS
      SSA,RSS         IS LESS THAN %SYNT
      JMP SCH54     IGNORE OTHERWISE
      ADA *+2       BRANCH TO SECTION 
      JMP A,I         TO HANDLE REQUEST 
      DEF *+7 
      JMP SCH8      DISCONNECT
      JMP SCH7      ABORT 
      JMP SCH6      COMMAND 
      JMP SCH54     NOT USED
      NOP           INPUT WAIT
*                     NOP           OUTPUT WAIT 
      SPC 1 
* 
**    INPUT WAIT AND OUTPUT WAIT HANDLER
* 
      ADB .+?PLEV-?STAT 
      LDA B,I       GET ACTUAL STATUS 
      ADB .+?STAT-?PLEV 
      STA B,I       SET ACTUAL STATUS 
      STF 0 
      ADB .+?PLEV-?STAT 
      CLA           SET PRIORITY TO 0 
      STA B,I 
      ADB .+?LINK-?PLEV 
      JMP SCH3      GO INSERT USER IN QUEUE 
      SPC 1 
* qq
**    ABORT HANDLER 
* 
SCH7  STF 0 
      INB           B=>LINK 
      JSB DEQUE     REMOVE USER FROM QUEUE. 
      LDB TTQ       CHANGE STATUS 
      ADB .+?STAT 
      LDA %IDLE 
      STA B,I 
      LDB TTQ       SCATCH IF $HELLO
      JSB HTEST       IS RUNNING
      LDA .-8       PRINT ABORT 
      JSB TYPE        MESSAGE 
      OCT 6412
      ASC 2,STOP
      OCT 6412
      SPC 1 
* qq
**    DISCONNECT HANDLER
* 
SCH8  LDA %RUN-COM2+BYE  SET USER'S STATUS
      STA B,I              TO BYE ROUTINE 
      ADB .+?LINK-?STAT 
      JSB DEQUE     REMOVE USER FROM QUEUE
      LDB TTQ 
      ADB .+?RSTR 
      STF 0 
      JMP SCH61     GO SET UP STARTING INFO 
      SPC 2 
* 
**
***   COMMAND HANDLER 
**
* 
SCH6  ADB .+?BHED-?STAT 
      LDA B,I       GET BUFFER HEAD 
      STA SBHED     INITIALIZE BUFFER POINTER 
      ADB .+?BEND-?BHED 
      STB SCHL      SAVE POINTER TO BUFFER END
SCH24 STF 0 
      CLA 
      STA SCHP      INITIALIZE TO HOLD CHARACTERS 
      JSB SCOM      INTERPRET COMMAND 
      JMP SCH30     EMPTY LINE
      JMP SCH9      FIRST CHARACTER A DIGIT 
      JMP EHERR     INVALID COMMAND 
*                     NOP           VALID COMMAND 
      SPC 1 
* 
**    VALID COMMAND 
* 
      LDA SCHID,I   PROCESS COMMAND ONLY
      SZA,RSS         IF USER'S ID NOT EQUAL
      CPB HI            TO 0 OR IF HELLO COMMAND
      JMP SCH22 
SCH25 LDA .-16      PRINT "LF PLEASE LOG IN 
      JSB TYPE        CRLF" AND THEN TERMINATE
      OCT 5120
      ASC 6,LEASE LOG IN
      OCT 6412
* 
SCH22 LDB TTQ 
      ADB .+?MASK   REMOVE USER 
      LDA B,I         FROM TAPE MODE
      CMA AE
      AND TAPEF 
      STA TAPEF 
      LDA SCHP,I    IF HELLO, BYE,
      CPA HELLO 
      JMP SCH27       OR SCRATCH NO 
      CPA SCR 
      JMP SCH27         NEED TO CHECK 
      CPA BYE 
      JMP SCH27           FOR TAPE ERRORS 
      LDA B,I       CHECK FOR 
      AND TERR        TAPE ERRORS 
      SZA,RSS 
      JMP SCH26     NONE
      LDA DTAPR     ERRORS - SET UP FOR 
      STA SCHP        EXECUTION OF TAPE 
      JMP SCH26         ERROR PRINTOUT ROUTINE
* 
SCH27 LDA B,I       HELLO, BYE, OR SCRATCH
      CMA             SO CLEAR BIT IN TAPE
      AND TERR          ERROR FLAG AND CONTINUE 
      STA TERR
* 
**    RUN-ONLY SECURITY CHECKER 
* 
SCH26 ADB .+?NAME-?MASK 
      LDA B,I       IF 'PROTECTED PROGRAM'
      SSA,RSS         BIT NOT SET, CONTINUE 
      JMP SCH28 8&
      LDA SCHP,I    IF PROTECTED, DISALLOW
      CPA SAVE        SAVE
      JMP SCH29 
      CPA LIS         LIST
      JMP SCH29 
      CPA PUN         PUNCH 
      JMP SCH29 
      CPA XPUN        XPUNCH
      JMP SCH29 9x
* 
**    CHECK FOR COMMAND TYPE
* 
SCH28 ADB .+?BHED-?NAME 
      LDA SBHED     SET BUFFER POINTER
      STA B,I 
      LDA SCHP
      ADA MCOM2 
      SSA           TYPE I COMMAND? 
      JMP SCH14     YES 
      ADA %RUN           COMPUTE
      ADB .+?STAT-?BHED    PROGRAM'S
      STA B,I                STATUS 
      ADB .+?RSTR-?STAT 
      ADA .+.-%RUN+COM2-COM3
      SSA                TEST FOR TYPE II COMMAND 
      JMP SCH13          YES
* 
*     TYPE III COMMANDN\
* 
SCH61 LDA #LIB# 
      STA B,I           TYPE III PROGRAMS 
      LDA .+2             HAVE A STANDARD 
SCH12 ADB .+?PLEV-?RSTR     STARTING ADDRESS
      STA B,I                 AND A PRIORITY OF 2 
      ADB .+?LINK-?PLEV 
      JMP SCH3          INSERT USER ON QUEUE
* 
*     TYPE II COMMAND 
* 
SCH13 ADA TP2SA     COMPUTE STARTING
      LDA A,I         ADDRESS FOR TYPE II 
      STA B,I           PROGRAMS AND STORE IT 
      CLA,INA       SET PRIORITY TO 1 
      JMP SCH12 II
* 
*     TYPE I COMMAND
* 
SCH14 ADA *+2       COMPUTE STARTING ADDRESS
      JMP A,I         FOR COMMAND AND GO THERE
      DEF COM5-COM1+COM2,I
      SPC 2 
SCH29 LDA .-11
      JSB TYPE
      OCT 12
      ASC 4,RUN ONLY
      OCT 6412
      SPC 2 
* qq
**    INVALID COMMAND 
* qq
EHERR LDA .-6 
      JSB TYPE
EH    OCT 5077,37477,6412    (???)
      SPC 1 
* 
**    SYNTAX
* qq
SCH9  CLA 
      CPA SCHID,I   IF NO ID GO TO PLEASE 
      JMP SCH25       LOG IN MESSAGE HANDLER
      LDB TTQ 
      ADB .+?PLEV 
      STA B,I       SET PRIORITY TO 0 
      ADB .+?RSTR-?PLEV 
      LDA SYNTA 
      STA B,I       SET RESTART ADDRESS TO SYNTAX 
      ADB .+?STAT-?RSTR 
      LDA %SYNT 
      STA B,I       SET STAUS  TO %SYNT 
      ADB .+?LINK-?STAT 
      JMP SCH3      GO INSERT USER ON QUEUE 
      SPC 1 
* 
**    EMPTY LINE
* 
SCH30 LDB TTQ 
      ADB .+?MASK 
      LDA TAPEF 
      AND B,I 
      SZA,RSS       TAPE MODE?
      JMP SCH20     NO - GO EMIT LINE FEED
      CLF 0         YES 
      LDB SBHED 
      INB           SET SBHED TO POINT
      CPB SCHL,I      TO FIRST CHARACTER
      ADB MBLEN         OF NEXT BUFFER
      STB SBHED 
      LDA SCHL
      ADA .+?BHED-?BEND 
      STB A,I       RESET BUFFER HEAD 
      ADA .+?BSTR-?BHED 
      CPB A,I       TEST FOR CONTINUATION 
      JMP SCH54     NO
      JMP SCH24     YES, GO SCAN NEXT BUFFER
      SKP 
* 
**
***   SYSTEM CONSOLE ACTIVITY CHECKER 
**
* qq
SCH5  CCA           TEST FOR DRIVER BUSY
      CPA T35F1 
      JMP SCH15     DRIVER IS BUSY. 
      CPA T35F3 
      JMP SCH16     COMMAND ENTERED BUT NOT STARTED 
* *q
* WHEN T35F1=0, THE CONSOLE IS QUIET SO WE CAN DO LOGGING.
* 
* 
      ADA MSQCT     ANY MESSAGES
      CPA .-1 
      JMP SCH55     NO
* 
      STA MSQCT 
      SZA,RSS 
      JMP SCH55-1 
      LDB MSQP1     LOAD MESSAGE LENGTH 
      LDA 1,I 
      INB           COMPUTE MESSAGE BUFFER
      JMP SCH21     OUTPUT MESSAGE
* qq
      CCA 
SCH55 EQU *         NO MESSAGES - LOGGING?
      ADA LOGCT     TEST FOR ANY ENTRIES IN LOGTABLE. 
      CPA .-1 
      JMP SCH16     LOG TABLE IS EMPTY. 
* qqq{
* SET UP LOG BUFFER 
* *q
      STA LOGCT     DECREMENT LOG COUNTER.
      LDA LOGP1     BUMP LOG POINTER
      INA 
      CPA LOGND     IF AT END,
      LDA LOGBG       WRAP AROUND.
      STA LOGP1 
      LDA LOGP1,I   TEST FOR LOGON
      LDB ASCIN       OR LOGOUT.
      SSA 
      LDB ASCFF 
      STB LOGBF+3 
      LSR 10        SHIFT LOG CHAR TO LEAST 5 BITS. 
      AND .+37B     MASK OFF OTHER STUFF. 
      ADA ASCBA     CONVERT TO ASCII. 
      STA LOGBF+4 
      LDA LOGP1,I   GET ACCOUNT NUMBER AGAIN. 
      AND B1777     KEEP ONLY # PART. 
      CLB 
      DIV .+10      GET 1ST 2 DIGITS IN A, LAST IN B
      BLF,BLF       SET UP LAST DIGIT AS
      ADB ASC0B      ASCII LEFT HALF. 
      STB LOGBF+6 
      JSB #LTEN     CONVERT FIRST 2 TO ASCCII ALSO. 
      STA LOGBF+5 
      ISZ LOGP1 ))
      LDA LOGP1,I   NOW GET THE TIME. 
      AND .+17B     GET TERMINAL NUMBER.
      JSB #LTEN     CONVERT AND STORE IN BUFFER.
      STA LOGBF+10
      LDA LOGP1,I 
      CLB 
      ASR 4 
      DIV D60 
      STB LOGP1,I   SAVE SECOND HALF
      JSB #LTEN     CONVERT FIRST HALF TO ASCII.
      STA LOGBF+7 
      LDA LOGP1,I 
      JSB #LTEN     CONVERT 2ND HALF TO ASCII.
      STA LOGBF+8 KK
      LDA .+22
      LDB LOGR2      TO PPRINT THE
SCH21 JSB TTY35,I    STUFF. 
      JMP SCH15 5*
LOGR2 DEF *+1,I     BUFFER ADDRESS (I=>PUNCH) 
LOGBF ASC 11,**LOGOFF A123 0930 #01 
* 
*  TTY35 IO COMPLETE
* *q
SCH16 CPA T35F2     TEST DRIVER COMMUNICATE FLAG. 
      RSS 
      JMP SCH15 
      LDA T35ST     GET CONSOLE STATUS. 
      LDB T35PR 
      CPA %OUTW     IF OUTPUT WAIT, 
      JMP SCH23     GO SET HIM UP.
      SZA           IF NOT IDLE WEVE ALREADY
      JMP SCH15       QUEUED HIM. 
* TTY35 INPUT COMMAND 
* 
      LDA T35B2     POINTER TO FIRST CHARACTER
      STA SBHED      OF CONSOLE BUFFER. 
      LDA T35ND     POINTER TO END OF 
      STA SCHL       CONSOLE BUFFER.
      LDA .+40B     INITIALIZE COMMAND
      STA SCHP       HOLDER.
      JSB SCOM      GET COMMAND.
      JMP SCH17     BLANK LINE
      JMP SCH18     ERROR 
      JMP SCH18     ERROR 
* 
* SET UP QUEUE ENTRY FOR CONSOLE. 
* 
      LDA SBHED     SET POINTER FOR 
      STA T35CP      T35CR. 
      LDA .+40B     SET UP LA2T CHAR
      STA T35LC      AS BLANK 
* qq
      LDA #LIB#     SET RESTART ADDRESS.
      STA T35RS S
      ADB SCH19     SET PROGRAM STATUS
SCH23 STB T35ST      TYPE.
      LDA .+2       SET PRIORITY. 
      STA T35PR 
      LDB T35LN     GO INSERT IN QUEUE
      JMP SCH3
      SPC 1 
SCH17 LDA ONEI      OUTPUT LINE FEED
      RSS 
SCH18 LDA .+4       OUTPUT ERROR MESSAGR
      CLB 
      STB T35F2 
      LDB DEH 
      JMP SCH21 ::
      SPC 2 
* *q
**    SCRATCH COMMAND PROCESSOR 
* 
#SCR  LDB TTQ 
      JSB SCRAT     PERFORM SCRATCH 
SCH20 LDA .+12B 
      LDB TTQ       OUTPUT A
      JSB POCR,I      LINE FEED 
      JMP SCH54 
* 
SCRAT NOP           SCRATCH A PROGRAM (B=>USERS TTY)
      LDA PBUFF     IF MAIN=B, SET PBPTR. 
      CPB MAIN
      STA PBPTR 
      ADB .+?PROG   B=>PROGEND
      STA 1,I       RESET TABLE(PROG) 
      ADB .+?NAME-?PROG   CLEAR 
      CLA 
      STA 1,I 
      JMP SCRAT,I 
* qq
* "TAPE" COMMAND
* 
#TAP  LDB TTQ       B=>TTY TABLE. 
      ADB .+?MASK   B=>MASK 
      LDA TAPEF     SET TAPE BIT. 
      IOR 1,I 
      STA TAPEF 
      JMP SCH20     TERMINATE.
* *q
* qq
#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.
* qq
* 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 2 
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 CHAR TO TELETYPE.
      JSB POCR,I
      ISZ TYPET     ANY MORE? 
      JMP TYPEL     YES.
      JMP SCH54     NO, RETURN TO SCHEDULER HEAD
TYPET NOP 
* 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>
* qq
* 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           IF <=ASC9,RETURN TO P+2 IF A
      JMP SCOM,I     DIGIT, P+3 IF NOT. 
      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 
* 
* qq
SCH15 JSB SWAPR     CHECK FOR ANYTHING TO DO. IF NOT
*                                   SWAPR WILL GO TO SCH1 AGAIN.
*                                   IT WILL RETURN HERE IF THERE IS 
*                                   AN EXECUTABLE PROGRAM IN CORE.
      SPC 3 
*     THE PROGRAM TO RUN IS AT THE HEAD OF THE QUEUE, AND SWAPR HAS 
*     GUARANTEED THAT IT IS IN CORE. THE FOLLOWING SECTION OF CODE
*     SETS IT UP TO RUN, AND ALSO SETS UP THE CLOCK DRIVER SO THAT
*     FUTURE INTERRUPTS WILL GO BACK INTO THE SCHEDULER.
      SPC 1 
      CLF 0         INHIBIT INTERRUPT.
      LDA CLC2      RESTORE A <JMP SCHED> IN THE
      STA CLC1        CLOCK INTERRUPT ROUTINE.
      LDA MLINK+1 
      INA           GET PRIORITY OF PROGRAM.
      LDB 0,I 
      CPB .+2       IF PRIORITY IS 2, CHANGE IT TO
      CLB           ZERO SO IT DOESNT GET INTERRUPTED.
      STB 0,I 
      ADA .+?RSTR-?PLEV   GET RESTART ADDRESS 
      LDB 0,I         IF NOT 0, PUT IT IN PREG
      SZB            TO START UP PROPERLY.
      STB PREG
      CLB           PUT 0 INTO TABLE IN ANY CASE
      STB 0,I 
      STB TIMEF     SET TO SAY NO TIMING. 
      INA           GET PROGRAM STATUS. 
      LDB 0,I IU
      ADA .+?CLOC-?STAT   SET TIMER POINTER.
      STA TIMER 
      CPB %SYNT+1   IF STATUS IS RUN, SET 
      ISZ TIMEF      TIMEFLAG FOR CLOCKING. 
      LDA EREG      RESTORE E 
      CLO            AND OVERFLOW 
      SLA,ELA         REGISTERS.
      STO 
      LDA AREG      RESTORE A AND 
      LDB BREG        B REG.
      STF 0         ENABLE INTERRUPT AND
      JMP PREG,I     TRANSFER TO PROGRAM. 
      SKP ll
* 
**
***   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 PRO- 
*  GRAM IS NOT READY, SWAPR INITIATES THE NECESSARY DISC TRANSFERS
*  AS FOLLOWS:
* 
*     TYPE II  - IF USER IN CORE IS NOT THE ONE AT THE HEAD OF THE
*                QUEUE (MLINK+1 NOT EQUAL TO MAIN), THE USER IS 
*                SWAPPED OUT AND MAIN IS SET TO 0.
* 
*                IF NO USER IS IN CORE (MAIN EQUALS 0), THE USER AT 
*                THE HEAD OF THE QUEUE IS READ INTO CORE. 
* 
* 
*     TYPE III - IF ANY USER PROGRAM IS IN CORE (MAIN NOT EQUAL TO
*      AND IV    0), THE USER IS SWAPPED TO DISC AND MAIN IS SET
*                TO 0.
* 
*                IF THE LIBRARY OVERLAY IN CORE (INDICATED BY LIB)
*                IS NOT THE ONE INDICATED BY THE ?STAT TELETYPE 
*                TABLE ENTRY OF THE USER AT THE HEAD OF THE QUEUE,
*                THEN THE PROPER ONE IS READ IN AND LIB IS UPDATED. 
* qq
      SPC 1 1
SWAPR NOP 
      LDA ENDSK     WAIT FOR DISC 
      SZA             TRANSFER TO 
      JMP SCH1          COMPLETE
      LDB MLINK+1   GET ENTRY ON TOP OF 
      CPB MLINK       QUEUE AND TEST FOR EMPTY
      JMP SCH1      EMPTY - NOTHING TO DO 
      LDA T35F3     HAS A SYSTEM CONSOLE COMMAND
      CPA .-1         BEEN ENTERED BUT NOT STARTED? 
      JMP SWAP4     YES, LET IT START 
      LDA LOGCT     NO
      IOR T35F1     IS THERE CURRENT
      CPB T35LN       OR IMMINENT OUTPUT
      SZA,RSS           TO SYSTEM CONSOLE?
      JMP SWAP4     NO
      LDA T35ST     YES, CAN IT 
      CMA,INA         BE DEQUEUED?
      ADA %RUN-COM2+ROS 
      SSA 
      JMP SWAP4     NO
      JSB DEQUE     YES, SO SUSPEND 
      LDA T35ST       UNTIL OUTPUT IS 
      STA T35PR         COMPLETED 
      LDA %OUTW 
      STA T35ST 
      JMP SWAPR+1 
* qq
**    CHECK COMMAND TYPEPO
* 
SWAP4 ADB .+?STAT-?LINK 
      LDA B,I       GET STATUS OF FIRST QUEUE ENTRY 
      ADA .+.-%RUN+COM2-COM3
      SSA,RSS       TEST FOR TYPE II PROGRAM
      JMP SWAP9     NO, TYPE III OR IV
      SPC 1 
* 
**    TYPE II PROGRAM 
* 
      ADB .-?STAT   IS CORRECT USER 
      CPB MAIN        IN CORE?
      JMP SWAPR,I   YES - DONE
      LDA MAIN      NO, IS ANY USER 
      SZA             IN CORE?
      JMP SWAP6     YES 
* qq
*     SWAP IN USER
* 
      STB MAIN      NO, SET MAIN FOR NEW USER 
      ADB .+?PROG 
      LDA B,I       GET PROGRAM LIMIT 
      STA PBPTR     SAVE FOR LANGUAGE PROCESSOR 
      CMA           CALCULATE 
      ADA USE         LENGTH OF 
      STA WORD          TRANSFER
      ADB .+?DISC-?PROG 
      LDA B,I       = DISC ADDRESS
      LDB USEI      => CORE ADDRESS FOR READ
SWAP5 JSB DISC,I    CALL DISC DRIVER
      JMP SCH1      RETURN BUSY 
* 
*     SWAP OUT USER 
* 
SWAP6 STA B         => TTY TABLE
SWAP7 CLA           SET MAIN TO SAY 
      STA MAIN        NO USER IN CORE 
      ADB .+?PROG 
      LDA PBPTR     SAVE PROGRAM
      STA B,I         END LOCATION
      CMA           CALCULATE 
      ADA USE         LENGTH OF 
      STA WORD          TRANSFER
      ADB .+?DISC-?PROG 
      LDA B,I       = DISC ADDRESS
      LDB USE       => CORE ADDRESS FOR WRITE 
      JMP SWAP5 
      SPC 1 1
* 
**    TYPE III AND IV PROGRAMS
* 
SWAP9 ADB .+?RSTR-?STAT 
      LDB B,I       GET RESTART ADDRESS 
      CPB #LIB#     IF FRESH CALL,
      STB LCHCR       ZAP LCHCR FLAG
      LDB MAIN      ANY USER
      SZB             IN CORE?
      JMP SWAP7     YES - GET RID OF HIM
      ADA DCOM6     NO, => LIB PROGRAM DISC ADDRESS 
      CPA LIB       IS IT IN CORE?
      JMP SWAPR,I   YES - DONE
      STA LIB       NO, SET LIB 
      LDB M256
      STB WORD      SAVE TRANSFER LENGTH
      LDB #LIBI     => CORE ADDRESS 
      LDA A,I       = DISC ADDRESS
      JMP SWAP5 
      SKP 
* *q
* ENTRY POINT FOR INPUT REQUEST 
* 
SCHIQ NOP 
      CLF 0         INTERRUPT INHIBIT.
      LDB MLINK+1   SET RESTART ADDRESS 
      ADB .+?RSTR-?LINK  INTO TABLE.
      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.
      ADB .+?TSTA-?STAT 
      LDA B,I       A = USER'S I/O STATUS 
      IOR IOBT      SET 'INPUT MODE' BIT
      CPA B,I       BRANCH IF USER IS 
      JMP SCHIW       NOT IN OUTPUT MODE
      LDA B,I       A = STATUS
      IOR ICBT      SET 'INPUT CONFIGURATION' BIT 
      STA B,I       STORE NEW STATUS
      JMP SUSP
* 
SCHIW AND NINBT     REMOVE 'NO INPUT ALLOWED' BIT 
      STA B,I       STORE NEW STATUS
      ADB .+?RPRM-?TSTA 
      LDA B,I       A = RECEIVE PARAMETER 
      ADB .+?TNUM-?RPRM 
      LDB B,I       B = UNIT NUMBER 
      JSB MUXR,I    OUTPUT TO MULTIPLEXER 
      JMP SUSP       GO REMOVE FROM QUEUE.
* q{
**  ENTRY POINT FOR TERMINATION 
* 
SCHEQ CLF 0 
      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 %ABRT     QUIT IF ABORT REQUEST 
      JMP SUSP
      CLA                TO IDLE
      STA 1,I 
      JMP SUSP
* SCHAR FETCHES THE NEXT CHARACTER FROM A BUFFER. BUFFER
* POINTERS FOR SCHAR ARE INITIALIZED AS FOLLOWS:
*     SBHED=>FIRST CHARACTER IN BUFFER
*     SCHL,I=>BUFFER END
* *q
* SCHAR CALLING SEQUENCE: 
* 
*     JSB SCHAR 
*     RETURN HERE IF CR 
*     RETURN HERE IF ANY OTHER CHARACTER
      SPC 1 
SCHAR NOP 
      LDB SBHED     GET POINTER.
      CLE,ERB       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. 
      CPB SCHL,I    TEST FOR END OF BUFFER. 
      ADB MBLEN     IF END, CHANGE TO BEGINNING.
      STB SBHED 
      CPA .+40B     SKIP BLANKS 
      JMP SCHAR+2 
      ISZ SCHAR 
      JMP SCHAR,I 
* 
* DEQUE REMOVES A USER FROM THE QUEUE. IT IS CALLED WITH THE USER'S 
* LINK ADDRESS IN B.
* q{
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 
* 
**   SUSPEND USER 
* 
SUSP  LDA MLINK+1,I 
      STA MLINK+1 
      CLA           BLOCK 
      STA CLC1        CLOCK 
      JMP SCH1
      SPC 1 
* qq
**   OUTPUT SUSPEND REQUEST ENTRY 
* 
SCHOQ NOP           OUTPUT SUSPEND REQUEST ENTRY. 
      CLF 0         TURN OFF INTERRUPT. 
      LDA SCHOQ     SET UP RETURN ADDRESS.
      STA POC       FOOL POC INTO 
      LDB MLINK+1     DOING THE WORK
      ADB .+?STAT-?LINK 
      JMP OBF+1 
      SPC 1 
* HTEST SCRATCHES A PROGRAM IF THE ASSOCIATED HFLAG BIT IS SET. 
* B POINTS TO THE USER'S TTY ADDRESS. 
* 
HTEST NOP 
      ADB .+?MASK   GET USER'S MASK.
      LDA 1,I 
      AND HFLAG     GET HFLAG BIT.
      SZA,RSS 
      JMP HTEST,I   RETURN IF HFLAG BIT =0. 
      XOR HFLAG     CLEAR HFLAG BIT.
      STA HFLAG 
      ADB .-?MASK   SCRATCH IT. 
      JSB SCRAT 
      JMP HTEST,I   RETURN. 
