
      HED *** PREPARE TIME-SHARE BASIC SYSTEM***
      ORG 22000B
      SUP
* 
      SPC 10
* 
*              TIME-SHARE BASIC DRIVERS AND MONITOR
* 
*                         KILE B. BAKER
*                         JOHN S. SHEMA
* 
*                      DATA RECORDING CENTER
* 
*                    MONTANA STATE UNIVERSITY
* 
*                           16K SYSTEM
* 
* 
      SKP
* 
*     REVISION - A     JSS  CSL/MSU DEC. 21, 1971
*     ALL CORRECTIONS HAVE BEEN NOTED BY THE MARKING - [A]
*     THE FOLLOWING CORRECTIONS HAVE BEEN MADE:
* (1) CARD READER DRIVER  CANNOT INTERRUPT ITSELF DURING HEAVY
*     USAGE OF I/O BY OTHER CHANNELS.
* 
* (2) SYSTEM IGNORES CALL FOR CARD READER OR PHOTOREADER
*     TO BE USED WITH INACTIVE OR NONEXISTANT CHANNEL.
* 
* 
***   LISTS OF INSTRUCTIONS TO BE MODIFIED
* 
ZDLS1 DEF ZX1
      DEF ZX2
      DEF ZX2+1
      DEF ZX2+2
      DEF ZX2+7
      DEF ZX2+8
      DEF ZX2+9
      DEF ZX2+11
      DEF SRITB-1
* 
***   LOG-TTY I/O INSTRUCTIONS
* 
ZDLS2 DEF LTTY1    (OTA)
      DEF LTTY2    (OTA)
      DEF LTTY4
      DEF LTTY5
      DEF CHINL+1  (LIA)
      DEF CHINL+5  (OTB)
      DEF CHINL+6  (STC,C)
      DEF LTTY3    (OTA)
      DEF CHOTL+1  (OTB)
      DEF CHOTL+2  (OTA)
      DEF CHOTL+3  (STC,C)
      DEF CLCL+1   (CLC)
* 
***   CLOCK I/O INSTRUCTIONS
* 
ZDLS3 DEF CL1
      DEF CL2
      DEF CL3
      DEF CL4
      DEF STM
* 
***   HIGH SPEED TAPE READER I/O INSTRUCTIONS
* 
ZDLS4 DEF .RDR1
      DEF RDINT+3  (LIA)
      DEF ?OMIT    (STC,C)
      DEF ?LDR+3   (CLC)
      DEF .HSPR+5  (STC,C)
      DEF CRIN     (CLC)
* 
***   CHANNEL 1 TTY I/O INSTRUCTIONS
* 
ZDLS5 DEF CHIN1+1  (LIA)
      DEF CHIN1+5  (OTB)
      DEF CHIN1+6  (STC,C)
      DEF CHOT1+1  (OTB)
      DEF CHOT1+2  (OTA)
      DEF CHOT1+3  (STC,C)
      DEF CLC1+1   (CLC)
* 
***   CHANNEL 2 TTY I/O INSTRUCTIONS
* 
ZDLS6 DEF CHIN2+1  (LIA)
      DEF CHIN2+5  (OTB)
      DEF CHIN2+6  (STC,C)
      DEF CHOT2+1  (OTB)
      DEF CHOT2+2  (OTA)
      DEF CHOT2+3  (STC,C)
      DEF CLC2+1   (CLC)
* 
***    CHANNEL 3 TTY I/O INSTRUCTIONS
* 
ZDLS7 DEF CHIN3+1  (LIA)
      DEF CHIN3+5  (OTB)
      DEF CHIN3+6  (STC,C)
      DEF CHOT3+1  (OTB)
      DEF CHOT3+2  (OTA)
      DEF CHOT3+3  (STC,C)
      DEF CLC3+1   (CLC)
* 
***   CHANNEL 4 TTY I/O INSTRUCTIONS
* 
ZDLS8 DEF CHIN4+1  (LIA)
      DEF CHIN4+5  (OTB)
      DEF CHIN4+6  (STC,C)
      DEF CHOT4+1  (OTB)
      DEF CHOT4+2  (OTA)
      DEF CHOT4+3  (STC,C)
      DEF CLC4+1   (CLC)
ZDLS9 DEF TOUT3
      DEF PNCH&+1
      DEF PNCH&+2
      DEF PNCH&+3
      DEF &T1
* 
* 
***   CARD READER I/O INSTRUCTIONS
* 
ZDL10 DEF SETM2+2  (CLC)
      DEF RCOL+2   (STC,C)
      DEF RCOL+4   (OTA)
      DEF CRDR1    (LIA,C)
* 
***   MESSAGE PRINT TABLE
* 
ZZG1  ASC 11,LOG TTY I/O ADDRESS?
ZZG2  ASC 10,INVALID I/O ADDRESS
ZZG3  ASC 10,NUMBER OF CHANNELS?
ZZG4  ASC 7,INVALID INPUT
ZZG5  ASC 14,CHANNEL   TTY I/O ADDRESS?
ZZG7  ASC 10,CLOCK I/O ADDRESS?
ZZG8  ASC 12,PHOTO READER IN SYSTEM?
ZZG9  ASC 6,YES OR NO:
ZAG10 DEF *+1
      ASC 8,ACCOUNT NUMBER?
ZAG11 DEF *+1
      ASC 11,INVALID ACCOUNT NUMBER
ZAG12 DEF *+1
      ASC 6,CODE WORD?
ZZ12  ASC 13,PHOTOREADER I/O ADDRESS?
ZAG14 DEF *+1
      ASC 11,ENTER CODE-WORD TABLE
ZZG15 ASC 17,DECIMAL FREE CORE AVAILABLE:
ZZG16 ASC 17,STANDARD FREE CORE IS DECIMAL
ZZG17 ASC 11,ACCEPT STANDARD CORE?
ZAG18 DEF *+1
      ASC 10,USER:   FREE CORE?
ZAG19 DEF ZAG18+4
ZZG20 ASC 12,ENTER INFORMATION TABLE
ZZG21 ASC 9,# LINES EXCEED 10
ZAG22 DEF *+1
      ASC 20,MEMORY REQUEST EXCEEDS AVAILABLE MEMORY
ZAG23 DEF *+1
      ASC 8,DUPLICATE ENTRY
ZAG25 DEF *+1
      ASC 18,CODE-WORD GIVEN SPECIFIES ACCOUNT:
      BSS 1
ZAG24 DEF *-1
ZAG26 DEF *+1
      ASC 7,ILLEGAL FORMAT
ZZG27 ASC 17,SYSTEM PUNCH DEVICE I/O ADDRESS?
ZZG28 ASC 2,*END
ZZG29 ASC 17,TURN ON TTY TAPE PUNCH, PRESS RUN
ZZG30 ASC 10,PUNCH ABSOLUTE TAPE?
ZZG31 ASC 11,CARD READER IN SYSTEM?
ZZG32 ASC 13,CARD READER I/O ADDRESS?
* 
***     SUBROUTINE TO DIVIDE FREE CORE
* 
ZFRC  NOP          FREE CORE SUBR.
      LDA ZRPLY
      STA ZANS     SET ZANS ADR
      JSB CRLF,I
      LDA FWFC,I   LOAD 1ST WD FR CORE
      CMA,INA
      INA
      ADA LWFC,I   FIND AMT FR CORE
      STA ZX       TEMP STORAGE
      LDA Z30      OUTPUT
      STA CCNT
      LDB ZG.15    TOTAL
      STB BADDR
      LDA ZX           AMT
      JSB OUTIN,I
      LDA CCNT           MESSAGE
      LDB ZAG15
      JSB ZCLOT,I
      LDA ZX       SUB ZLOT DESTR A
      CLB,INB
      STB ZONE     SETUP CNTR OF # OF USERS
      LDB &#USR,I  LOAD - NUMBER OF USERS
      CMB,INB      +NUM OF USERS
      CPB ZONE     ONE USER?
* 
***   1 USER - STANDARD CORE = TOTAL CORE
* 
      JMP ZWRT     YES
      ISZ ZONE     NO:TRY 2
      CPB ZONE     TWO USERS?
      RSS
      JMP *+3
* 
***   2 USERS - DIVIDE BY 2
* 
      ARS          YES:DIV BY 2
      JMP ZWRT
      ISZ ZONE     NO: TRY 3
      CPB ZONE     THREE USERS?
      RSS
      JMP ZWRT-1
* 
***   3 USERS - DIVIDE BY 3
* 
      LDB ZX       GET TOTAL CORE
      CLA          SET /3 COUNT = 0
      INA
      ADB M3       SUBTRACT 3 FROM TOTAL CORE
      SSB,RSS      FINISHED DIVISION?
      JMP *-3      NO - CONTINUE
      ADA M1       YES - TOO MANY SUBTRACT 1
      RSS          SET STND CORE
* 
***   4 USERS - DIVIDE BY 4
* 
      ARS,ARS      4 USERS-DIV BY 4
* 
ZWRT  STA ZX       STND CORE
      LDA Z30      OUTPUT
      STA CCNT
      LDB ZG.16    STND
      STB BADDR
      LDA ZX           AMT
      JSB OUTIN,I
      LDA CCNT           MESG
      LDB ZAG16
      JSB ZCLOT,I
      JSB CRLF,I
      LDA X22      OUTPUT
      LDB ZAG17      OK
      JSB ZCLOT,I
      LDA M11
      LDB ZX9
      JSB ZCLOT,I
      LDA .2
      LDB ZRPLY
      JSB ZCLIN,I
      LDA ZRPLY,I
      CPA XYES       ANSWER
      JMP XSTND
* 
ZRERE LDA FWFC,I   SET FIRST WORD
      STA XFWC     AVAILABLE CORE
      LDB LWFC,I   SET LAST WORD
      STB XLWC     AVAILABLE CORE
      CMA,INA      COMPUTE AMT
      INA
      ADA B        OF FREE CORE
      STA XFCR     REMAINING
* 
      LDA &#USR,I  LOAD -# USERS
      STA ZCCT     AND SAVE AS COUNTER
      CLA,INA      SET TO CHANNEL
      STA ZCHNX    NUMBER ONE
* 
ZRERD JSB CRLF,I   OUTPUT CR-LF
      LDA ZCHNX    LOAD CHANNEL NUMBER
      IOR .48      ADD ON ASCII BITS
      ALF,ALF      POSITION TO UPPER WORD
      IOR .32      ADD ON BLANK
      STA ZAG19,I  STORE IN MESSAGE
* 
      LDA M19
      LDB ZAG18    "USER (N) FREE CORE"
      JSB ZCLOT,I
      LDA .6       ASK FOR
      LDB ZRPLY    TTY
      JSB ZCLIN,I  INPUT
      LDB ZRPLY    CONVERT TO
      JSB DVRT,I   BINARY
      JMP ZRERD    NOT-VALID INPUT
      SZA,RSS      REQUEST FOR ZERO CORE?
      JMP ZRERD    YES - REJECT
      STA XFCR     SAVE FREE CORE REQUESTED
      ADA MSK1     TOO SMALL REQUEST?
      SSA
      JMP ZRERD    NO-TRY AGAIN
* 
***   SET USER FIRST WORD AVAILABLE MEMORY
* 
      LDA XFWC     LOAD FIRST WORD FREE CORE
      LDB ZFWTB    LOAD FWFC TABLE BASE ADR
      ADB ZCHNX    INDEX BY CHANNEL #
      LDB B,I      LOAD STORE ADDRESS
      STA B,I      SET FIRST WORD AVAIL MEM.
* 
***   SET USER LAST WORD AVAILABLE MEMORY
* 
      ADA XFCR     INDEX F.W. BY AMT REQUESTED.
      ADA M1
      LDB ZLWTB    LOAD LWFC TABLE BASE ADR
      ADB ZCHNX    INDEX BY CHANNEL #
      LDB B,I      LOAD STORE ADDRESS
      STA B,I      SET LAST WORD AVAIL MEM.
      INA          INDEX TO NEXT WORD
      STA XFWC     SET NEW FIRST WORD CORE
* 
      CMA,INA      SET A=NEG(A-1)
      INA
      ADA XLWC     ADD LW FREE CORE
      SSA
      JMP *+5      YES-ERROR MESSAGE
      ISZ ZCHNX    INDEX TO NEXT USER
      ISZ ZCCT     FINISHED?
      JMP ZRERD    NO-GET NEXT USER
      JMP ZFRC,I   YES-RETURN
* 
*** ERROR ** FREE CORE SPACE EXCEEDED **
* 
      JSB CRLF,I   OUTPUT CR-LF
      LDA Z39       OUTPUT MESSAGE:
      LDB ZAG22    "MEMORY REQUESTED EXCEEDS
      JSB ZCLOT,I  MEMORY AVAILABLE"
      JMP ZRERE    TRY AGAIN
* 
*** SET   STANDARD CORE
* 
XSTND LDA &#USR,I  GET -# USERS
      STA ZCCT     SET AS COUNTER
      LDA FWFC,I   LOAD FIRST WORD FREE CORE
      STA XFWC     SAVE AS POINTER
* 
      CLA,INA      SET TO USER # 1
      STA ZCHNX
* 
      LDA XFWC     LOAD FIRST WORD F CORE
      LDB ZFWTB    LOAD FWAM TABLE BASE ADR
      ADB ZCHNX    INDEX BY CHANNEL #
      LDB B,I      LOAD STORE ADR IN (B)
      STA B,I      SET USER FIRST WORD MEM
      ADA ZX       COMPUTE LAST WORD MEM
      ADA M1
      LDB ZLWTB    LOAD LWAM TABLE BASE ADR
      ADB ZCHNX    INDEX BY USER #
      LDB B,I      LOAD STORE ADDRESS
      STA B,I      SET USER LWAM
      INA          INDEX BY 1
      STA XFWC     SET NEW FWAM
* 
      ISZ ZCHNX    INDEX TO NEXT USER
      ISZ ZCCT     FINISHED?
      JMP *-15     NO
      JMP ZFRC,I   YES-RETURN
* 
***    LOAD AND CONSTRUCT CODE-WORD TABLE
* 
CDTBL NOP
      LDB FWFC,I   GET FIRST WORD AVAIL FREE CODE
      STB ?ACCT,I  SET START OF ACCOUNT TABLE
      STB XCODE    STORE FOR CODE WORD STORAGE
      CLB          SET CODE TABLE
      STB XLNTH    LENGTH = 0
      STB XNTRY    # ENTRIES = 0
      JSB CRLF,I
      JSB CRLF,I
      LDA X21
      LDB ZAG14    OUTPUT MESSAGE" ENTER CODE
      JSB ZCLOT,I  -WORD TABLE"
ZLOP3 JSB CRLF,I   OUTPUT CR-LF
      JSB CRLF,I
      LDA M16      OUTPUT MESSAGE:
      LDB ZAG10    "ACCOUNT NUMBER?"
      JSB ZCLOT,I
* 
      LDA X20      INPUT
      LDB XBUF     RESPONSE
      JSB ZCLIN,I  FROM TTY
      SZA,RSS      NULL INPUT?
      JMP ZLOP3    YES-TRY AGAIN
      LDB XBUF,I   LOAD FIRST CHARS
      CPB X/E      IS IT "/E"?
      JMP ZEND     YES-EXIT FROM ACCOUNT LOOP
* 
      JMP ZOK1     NO - VALID INPUT
ZER3  JSB CRLF,I   OUTPUT CR-LF
      LDA X22      OUTPUT MESSAGE:
      LDB ZAG11    "INVALID ACCOUNT NUMBER"
      JSB ZCLOT,I
      JMP ZLOP3    TRY AGAIN
ZOK1  LDB XBUF     CONVERT TO BINARY
      JSB XVERT,I
      JMP ZER3     NOT VALID INPUT
      STA B        SAVE ACCOUNT # IN (B)
      ALF,RAR      POSITION
      ALF,RAR      ACCOUNT
      ALF,RAR      NUMBER
      STA ZACNT    AND STORE
      ADB ZM64     DOES ACCOUNT
      SSB,RSS      NUMBER EXCEED MAXIMUM
      JMP ZER3     OF 63?
* 
ZLOP4 JSB CRLF,I   OUTPUT CR-LF
      LDA M11      OUTPUT MESSAGE:
      LDB ZAG12    "CODE WORD?"
      JSB ZCLOT,I
* 
      LDA .72      INPUT RESPONSE
      LDB XBUF     RESPONSE
      JSB ZCLIN,I
* 
      SZA,RSS      NULL INPUT?
      JMP ZLOP4    YES - TRY AGAIN
      STA ZSVA     SAVE CHARS INPUT LENGTH
* 
***   CHECK FOR ILLEGAL FORMAT
* 
      CPA .1
      JMP ZERR
      ADA M7       INPUT TOO LONG?
      SSA,RSS
      JMP ZERR     YES-ILLEGAL FORMAT
      LDA ZSVA     RELOAD INPUT COUNT
      INA          INDEX BY 1
      ARS          SHIFT RIGHT FOR WORDS
      CMA,INA      MAKE COUNT NEG
      STA XA1      SAVE AS WORD COUNTER
      LDB XBUF     SET BUFFER ADDRESS
      STB ZBF      POINTER
* 
ZLOP6 LDA ZBF,I    LOAD WORD
      ALF,ALF      POSITION TO UPPER CHAR
      AND M177     MASK OFF UPPER CHAR
      CPA BLANK    SPACE?
      JMP ZERR     YES-ERROR
      LDA ZBF,I    RELOAD INPUT
      AND M177     MASK TO LOW CHAR
      CPA BLANK    SPACE?
      JMP *+5      YES-PROCESS MORE
      ISZ ZBF      NO-INDEX BUFFER POINTER
      ISZ XA1      FINISHED?
      JMP ZLOP6    NO-CONTINUE
      JMP ZCFDE    YES - INPUT O.K.
      LDB XA1      LAST WORD?
      CPB M1
      JMP ZCFDE    YES - INPUT O.K.
ZERR  JSB CRLF,I   OUTPUT CR-LF
      LDA Z14      OUTPUT MESSAGE:
      LDB ZAG26    "ILLEGAL FORMAT"
      JSB ZCLOT,I
      JMP ZLOP4    GET NEXT INPUT
* 
***   CHECK FOR DUPLICATE ENTRY
* 
ZCFDE LDA ZSVA     RELOAD # CHARS INPUT
      CMA,SSA,RSS  MAKE -1-# CHARS
      JMP ZLOP4    NOT VALID INPUT
      STA CCNT     SAVE LENGTH
      LDB XBUF     RELOAD BUFFER START ADR
      BLS          GET ADR*2
      STB BADDR    SAVE AS BUFFER POINTER
      JSB GETCR,I  GET A CHAR
      JMP ZLOP4    NOT VALID INPUT
      LDB LWFC,I   SET SYMBOL BUFFER
      ADB D100     START ADDRESS
      STB SBPTR    * INITIALIZE FOR
      STA SBPTR,I  * TABLE SEARCH
      LDA ?ACCT,I  TABLE ADR IN (A)
      LDB XNTRY    GET # ENTRIES
      CMB,INB,SZB,RSS  CONVERT TO NEG
      JMP ZPEIT
      JSB TSRCH,I  CHECK FOR DUPLICATE ENTRY
      JMP ZPEIT    PUT ENTRY IN TABLE
* 
***   DUPLICATE ENTRY IN TABLE
* 
      ALF,ALF      ROTATE ACCOUNT #
      RAR          TO CORRECT POSITION
      STA XCHN%    SAVE ACCOUNT NUMBER
      JSB CRLF,I   OUTPUT CR-LF
      LDA .15      OUTPUT MESSZGE:
      LDB ZAG23    "DUPLICATE ENTRY"
      JSB ZCLOT,I
      LDA .36      PUT
      STA CCNT     ACCOUNT
      LDB ZAG24    NUMBER
      STB BADDR    INTO
      LDA XCHN%    MESSAGE
      JSB OUTIN,I
      LDA CCNT     OUTPUT MESSAGE:
      LDB ZAG25    "CODE-WORD PREVIOUSLY
      JSB ZCLOT,I  SPECIFIED FOR ACCOUNT:(N)"
      JMP ZLOP4    TRY AGAIN
* 
ZPEIT LDA ZSVA
      ADA ZACNT    INDEX BY ACCOUNT #
22255-80001 D         
