Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-03 - decus/20-0081/tpmodl.mac
There is 1 other file named tpmodl.mac in the archive. Click here to see a list.
TITLE  TRANSACTION PROCESSOR  (MULTI TTY VERSION)
SUBTTL GEORGE H. NEWTON /DEC INFORMATION SERVICES/24-MAY-73/ VERSION 009A


;
;	NOTES TO THE MODIFIER OF THIS CODE
;
;	AC5 (5)  =  INDEX FOR TTYTBL
;
;	AC7 (7)  =  NUMBER OF ENTRIES BETWEEN CURRENT AC5
;		    AND END-OF-TABLE (TTYTBL)
;
;
	ENTRY	TP
;
;	SAVE THE AC'S
;

TP:	MOVEM	17,SAVE17	;SAVE AC17 (ADDRESS OF PC WORD)
	MOVE	17,[XWD 0,SAVEAC]	;SET UP FOR BLOCK TRANSFER
	BLT	17,SAVEAC+17	;SAVE THE AC'S
	MOVE	17,SAVE17	;RESTORE AC17 (PUSH-DOWN POINTER)
	SETOM	TALKED		;TELL SLEEPER THAT WE 'TALKED' TO COBOL PROGRAM
	AOS	TSTOT		;ADD 1 TO TOTAL NUMBER OF TRANSACTION SETS
	

;
;	FIRST TIME THINGS/SWITCH
;

ONCE:	JRST	ONCEA		;THIS IS ALTERED TO ALTGO: AFTER FIRST TIME


;	LOCK IN CORE ROUTINE / PERFORMED AFTER FIRST SLAVE


LOCKIT:	0			;SAVE RETURN PC HERE
	MOVE	16,[XWD 3,3]	;DO     LOCK HI-SEG (LH)
				;DO     LOCK LO-SEG
				;      IN CONTIGUOUS CORE
				;      WITH NO MAPPING
	LOCK	16,		;TRY THE LOCK - - - - - 
	JRST	.+2		;JUMP OVER GOOD RETURN
	JRST	LOCKOK		;LOCK WORKED - JUMP OVER ERROR CODE
	OUTSTR	[ASCIZ/
* * LOCK ATTEMPT FAILED * * ERROR CODE (/]
	MOVE	11,16		;MOVE ERROR CODE TO AC11
	PUSHJ	17,OCTPNT	;GO TYPE ERROR CODE
	OUTSTR	[ASCIZ/)
/]
	HRRZI	1,0		;SET AC1 TO 0
	CAME	16,1		;SKIP - ERROR CODE = 0
	JRST	LOCK1		;JUMP TO CHECK NEXT ERROR CODE
	OUTSTR	[ASCIZ/
    ( 0 = LOCK UUO NOT SUPPORTED BY THIS MONITOR )
/]
	JRST	LOCKA		;JUMP TO FINAL LOCK ERROR
	
LOCK1:	HRRZI	1,1		;SET AC1 TO 1
	CAME	16,1		;SKIP - ERROR CODE = 1
	JRST	LOCK2		;JUMP TO CKECK NEXT ERROR CODE
	OUTSTR	[ASCIZ/
    ( 1 = LOCK PRIVILEGE NOT IN ACCT.SYS FOR THIS [P,PN])
/]
	JRST	LOCKA		;JUMP TO FINAL LOCK ERROR

LOCK2:	OUTSTR [ASCIZ /
    ( 2 OR 3 = NOT ENOUGH CORE TO LOCK THIS JOB)
    ( 4,5,6 = LOCK MODE ERROR FOR THIS PROCESSOR)
/]

	
LOCKA:	OUTSTR	[ASCIZ /
    (JOB IS PROCEEDING  UNLOCKED!!!)

/]
	JRST	LOCKXX		;JUMP OVER LOCK-OK MESSAGE

LOCKOK:	OUTSTR	[ASCIZ/

* * JOB RUNNING  LOCKED  IN CORE * *

/]
LOCKXX:	OUTSTR	[ASCIZ/

/]
	HRRZI	1,1		;SET AC1 TO 1
	CALLI	1,71		;SET HPQ1
	OUTSTR	[ASCIZ/!!FAILED!! /]
	OUTSTR	[ASCIZ/HPQ 1

/]
	JRST	@LOCKIT		;RETURN


PAGE
;
;	THIS CODE IS PROCESSED ONLY ONCE, TO DETERMINE
;	THE LOCATION OF THE COBOL PROGRAM DISPATCHER, 
;	MESSAGE AREA, GO TO DEPENDING ON, MORE-TO-COME,
;	NUMBER OF LINES, CONTROL-C-DISPATCHER, AND
;	LOGICAL TTY NUMBER.
;
;	THIS CODE DETERMINES WHICH VERSION COBOL COMPILER
;	THE COBOL PROGRAM WAS COMPILED WITH, WHICH TELLS
;	IT HOW TO PROCESS THE ENTER MACRO ARGUMENTS.
;

ONCEA:	MOVE	1,[XWD 0,ALTGO]		;SET ADDRESS OF ALTGO:  IN RH AC1
	HRRM	1,ONCE			;ALTER   ONCE:   TO JRST TO ALTGO:

	HRRZ	1,SAVE17		;SET UP PC @ MOVE
	HRRZ	2,@1			;MOVE ENTRY PC+1 TO AC1
	HRRZM	2,ENTRPC		;STORE ENTRY PC+1

	MOVE	1,400005		;MOVE FILE-NAME OF HI-SEG TO AC1 (IN SIXBIT)
	CAMN	1,[SIXBIT/LIBOL5/]	;SKIP IF HI-SEG NOT LIBOL5
	JRST	LIBOL5			;GO PROCESS 'LIBOL5' ARGUMENTS
	CAMN	1,[SIXBIT/LIBOLQ/]	;SKIP IF HI-SEG NOT LIBOLQ (LIBOL5)
	JRST	LIBOL5			;GO PROCESS 'LIBOL5' ARGUMENTS
	CAMN	1,[SIXBIT/LIBOL6/]	;SKIP IF HI-SEG NOT 'LIBOL6'
	JRST	LIBOL6			;GO PROCESS 'LIBOL6' (LIBOL6 OR GREATER)
					;   TYPE ARGUMENTS

	OUTSTR	[ASCIZ"
?(ERROR FROM T/P)  YOUR COBOL PROGRAM IS CALLING FOR UNFAMILIAR 'LIBOL'
	SUGGEST YOU EXAMINE LOC.400005 IN HI-SEG FOR LIBOL NAME (SIXBIT)"]

	HALT			;SORRY BUT I MUST DIE!!!!!!!
PAGE
;
;	PROCESS  LIBOL5  ENTER MACRO   FOR THE FOLLOWING
;
;
;	TTYADR = ADDRESS OF LOGICAL TTY # IN COBOL PROGRAM (I-O-TTY)
;	GOTOAD = ADDRESS OF 1ST GO TO DEPENDING ON
;	ALTADD = ADDRESS OF (DISPATCHER) IN COBOL PROGRAM
;	CNTRLC = ADDRESS OF WHERE TO GO ON ^C (CONTROL-C)
;	TYPPTR = ADDRESS OF LINE 1 IN TTYI-O AREA (OUT-LINE)
;	LNSADR = ADDRESS OF NUMBER OF LINES TO BE TYPED (LINES-OUT)
;	MTCADR = ADDRESS OF (MORE-TO-COME) SWITCH
;

LIBOL5:	MOVE	16,ENTRPC	;MOVE ENTRPC TO AC16
	ADDI	16,2		;ADD 2 TO ENTRY PC+1
	HRRZ	15,@16		;MOVE TTY ADDRESS TO AC15
	HRRZM	15,TTYADR	;MOVE TTY ADDRESS TO TTYADR

	ADDI	16,^D11		;ADD 11 TO ENTRY PC+1+2
	HRRZM	16,GOTOAD	;SAVE ADDRESS OF 1ST GO TO DEPENDING ON - - 

	MOVE	16,ENTRPC	;MOVE ENTRY PC+1 TO AC16
	SUBI	16,5		;SUBTRACT 5 FROM AC16
OPLOOP:	HRRM	16,.+1		;JAM ADDRESS ON NEXT INSTRUCTION
	HLRZ	1,.		;LOAD OPCODE TO RH AC1
	CAMN	1,JRSTID	;SKIP - IF OPCODE IS NOT = JRST @
	JRST	OPOK		;OPCODE OK - - - - - - 
	SUBI	16,1		;BACK-UP LOOKING FOR JRST @
	JRST	OPLOOP		;TRY AGAIN

OPOK:	HRRM	16,.+1		;JAM ADDRESS ON NEXT INSTRUCTION
	HRRZ	1,.		;MOVE ALTERED ADDRESS TO AC1
	HRRZM	1,ALTADD	;SAVE ADDRESS OF ALTERED GO TO (DISPATCHER)

OPOK1:	SUBI	16,1		;SUBTRACT 1 FROM AC1
	HRRM	16,.+1		;JAM ADDRESS ON NEXT INSTRUCTION
	HLRZ	1,.		;LOAD OP-CODE ETC.  LH AC1
	CAMN	1,JRSTXX	;SKIP- IF OP-CODE NOT = 'JRST'
	JRST	OPOK2		;OP-CODE IS 'JRST'  -  JUMP TO OPOK2:
	JRST	OPOK1		;BACK-UP LOOKING FOR 'JRST'

OPOK2:	HRRM	16,.+1		;JAM ADDRESS ON NEXT INSTRUCTION
	HRRZ	1,.		;MOVE JRST ADDRESS TO RH AC1
	HRRZM	1,CNTRLC	;SAVE ADDRESS OF CONTROL-C-DISPATCHER


	MOVE	1,ENTRPC	;MOVE ENTRY PC+1 TO AC1
	ADDI	1,1		;ADD 1 TO AC1
	HRRM	1,.+1		;SET UP NEXT INSTRUCTION FOR @ MOVE
	HRRZ	2,@.		;MOVE START ADDRESS OF DISPLAY TO AC2
	HRRZM	2,TYPPTR	;SAVE ADDRESS OF TTY I-O AREA

	MOVE	1,ENTRPC	;MOVE ENTRPC TO AC1
	MOVE	2,(1)		;MOVE ADDRESS OF # LINES TO AC2
	HRRZM	2,LNSADR	;SAVE ADDRESS OF # LINES

	SUBI	2,1		;CALCULATE ADDRESS OF MORE-TO-COME
	HRRZM	2,MTCADR	;SAVE ADDRESS OF MORE-TO-COME SWITCH
	OUTSTR 	[ASCIZ/
 (LIBOL5 IS THE HI-SEG)
/]
	JRST	ITTY 		;GO SET-UP TTY TABLES
PAGE
;
;	PROCESS  'ENTER MACRO ARGUMENTS'  IN   (LIBOL6 OR LATER)  FORMAT
;

LIBOL6:	HRRZ	1,(16)		;GET ADDRESS OF # LINES OUT (LINES-OUT)
	MOVEM	1,LNSADR	;SAVE   LNSADR:

	SUBI	1,1		;BACK-UP 1 WORD FOR (MOORE-TO-COME)
	MOVEM	1,MTCADR	;SAVE   MTCADR:

	ADDI	16,1		;BUMP ARG POINTER BY 1
	HRRZ	1,(16)		;GET ADDRESS OF OUT-STRING BYTE POINTER
	HRRZ	1,(1)		;GET ADDRESS OF (OUT-STRING) FROM (RH)OF BYTE POINTER
	MOVEM	1,TYPPTR	;SAVE   TYPPTR:

	ADDI	16,1		;BUMP ARG POINTER BY 1
	HRRZ	1,(16)		;GET ADDRESS OF (I-O-TTY)
	MOVEM	1,TTYADR	;SAVE   TTYADR:

	MOVE	1,ENTRPC	;MOVE ENTRY PC+1 TO AC1
	ADDI	1,^D10		;BUMP AC1 TO POINT TO 1ST GO TO DEPENDING ON
	MOVEM	1,GOTOAD	;SAVE   GOTOAD:

	MOVE	1,ENTRPC	;MOVE ENTRY  PC+1 TO AC1
	SUBI	1,^D6		;GO BACK  LOOKING FOR  'JRST @'
BOL6LP:	HLRZ	2,(1)		;MOVE (LH) TO AC2
	CAMN	2,JRSTID	;SKIP - IF OPCODE NOT = 'JRST @'
	JRST	BOL6A		;OPCODE  OK - - - - - 
	SUBI	1,1		;BACK-UP 1 MORE - - - 
	JRST	BOL6LP		;LOOP

BOL6A:	HRRZ	2,(1)		;GET ADDRESS OF (DISPATCHER)
	MOVEM	2,ALTADD	;SAVE   ASTADD:

BOL6B:	SUBI	1,1		;BACK-UP 1 MORE
	HLRZ	2,(1)		;MOVE (LH) TO AC2
	CAMN	2,JRSTXX	;SKIP IF OPCODE NOT = 'JRST'
	JRST	BOL6C		;OPCODE IS OK - - - JUMP
	JRST	BOL6B		;LOOP

BOL6C:	HRRZ	2,(1)		;GET ADDRESS OF (CONTROL-C-DISPATCHER)
	MOVEM	2,CNTRLC	;SAVE   CNTRLC:

	OUTSTR	[ASCIZ/
 (LIBOL6 IS THE HI-SEG)
/]


	JRST	ITTY		;GO SET-UP TTY TABLES
PAGE
;
;	INITIALIZE (TTYTBL)  TTY RING TABLE
;

ITTY:	MOVE	1,TYPPTR	;MOVE TYPPTR TO AC1
	HRRM	1,POINT4	;MOVE ADDRESS OF TTY I-O AREA
				;(OUT-STRING) TO ITS BYTE POINTER

	MOVEI	7,MAXTTY	;MOVE MAXIMUM NUMBER OF TTY'S 
				;TO BE HANDLED BY TP TO AC1
	HRRZI	2,1		;MOVE 1 TO AC2 (LOGICAL TTY #)
	MOVE	3,SIXTTY	;MOVE -TTY   - TO AC3 (SIXBIT)
	SETZ	5,		;SET AC5 TO ZERO
	HRRZ	4,PTYTBL	;MOVE BYTE POINTER TO TTYTBL TO AC4
	ADDI	4,TFIXSZ	;OFFSET BYTE POINTER BY TTYTBL FIXED AREA

ITTYA:	ADDI	2,1		;ADD 1 TO (LOGICAL TTY#)
	HRLZM	2,TTYTBL(5)	;MOVE LOGICAL TTY # TO - LH
				;ZERO # OF TRANSACTIONS- RH
	MOVEM	3,TTYTBL+1(5)	;MOVE -TTY   - TO TABLE (SIXBIT)
	SETZM	TTYTBL+2(5)	;ZERO    FLAGS      - LH
				;ZERO PHYSICAL TTY# - RH
	SETZM	TTYTBL+3(5)	;ZERO TTY BEGINNING TIME (JIFFIES)
	SETZM	TTYTBL+5(5)	;ZERO BYTES LEFT TO BE TYPE FROM TP BUFFER
	HRRM	4,PTYTBL	;JAM OFFSET TTYTBL TTY BUFFER ADDRESS
				;ON BYTE POINTER
	MOVE	6,PTYTBL	;MOVE BYTE POINTER TO AC6
	MOVEM	6,TTYTBL+4(5)	;INITIALIZE TTYTBL BYTE POINTER
	MOVEM	6,TTYTBL+6(5)	;INITIALIZE TTYTBL BYTE POINTER
	ADDI	4,TABSIZ	;BUMP ADDRESS TO TP BUFFER FOR NEXT TTY IN TABLE
	ADDI	5,TABSIZ	;SET INDEX UP BY TABSIZ WORDS
	SUBI	7,1		;SUBTRACT 1 FROM NUMBER OF TTYS
	JUMPG	7,ITTYA		;LOOP - UNTIL TABLE INITALIZED - - - -

;
;	ESTABLISH THE NUMBER OF TTYS ON THE SYSTEM
;

	MOVE	1,[XWD 22,11]	;SET AC1 FOR GETTAB (INDEX 33 OF TABLE 11)
	GETTAB	1,		;GET TABLE 11  ENTRY 33
				;AC1  LH = - TOTAL NUMBER OF TTY LINES
				;     RH = BEGINNING OF LINE TABLE
	JRST	ERR1		;GETTAB DIED/ GO COMPLAIN - - 
	HLRZ	2,1
	SUBI	2,2
	MOVEM	2,SYSTTY	;SAVE NUMBER OF TTYS ON SYSTEM
	MOVE 2,SYSTTY
	SUBI 2,2
	MOVEM	2,SYSTTY

;
;	IDENTIFY SYSTEM/TP/APPLICATION ON MASTER TTY (NOT USERS TTY)
;

	OUTSTR	[ASCIZ/

/]
	MOVE	1,[XWD 0,11]	;SET FOR GETTAB
	GETTAB	1,		;GET WORD 1 OF SYSTEM ID
	JRST	ERR5		;FAILED/REPORT IT
	MOVEM	1,SYSID		;MOVE WORD 1 OF ID TO SYSID
	MOVE 	1,[XWD 1,11]	;SET FOR GETTAB
	GETTAB	1,		;GET WORD 2 OF SYSTEM ID
	JRST	ERR5		;FAILED/REPORT IT
	MOVEM	1,SYSID+1	;MOVE WORD 2 OF ID TO SYSID
	MOVE	1,[XWD 2,11]	;SET FOR GETTAB
	GETTAB	1,		;GET WORD 3 OF SYSTEM ID
	JRST	ERR5		;FAILED/REPORT IT
	MOVEM	1,SYSID+2	;MOVE WORD 3 OF ID TO SYSID
	MOVE	1,[XWD 3,11]	;SET FOR GETTAB
	GETTAB	1,		;GET WORD 4 OF SYSTEM ID
	JRST	ERR5		;FAILED/REPORT IT
	MOVEM	1,SYSID+3	;MOVE WORD 4 OF ID TO SYSID
	MOVE	1,[XWD 4,11]	;SET FOR GETTAB
	GETTAB	1,		;GET WORD 5 OF SYSTEM ID
	JRST	ERR5		;FAILED/REPORT IT
	MOVEM	1,SYSID+4	;MOVE WORD 5 OF ID TO SYSID
	OUTSTR	SYSID		;TYPE SYSTEMS ID
	OUTSTR	@CRLF		;TYPE <CR><LF>
	OUTSTR	[ASCIZ/"BEGIN TRANSACTION PROCESSOR V009A 
FOR   MIKE & NICK  @ /]
	JSR	TIMER		;GO GET THE TIME
	JSR	TYTIME		;GO TYPE TIME
	OUTSTR	[ASCIZ/
PAGE CODE - (.SET TTY PAGE /]
	MOVE	11,TPID		;MOVE PAGE ID TO AC11
	PUSHJ	17,DECPNT	;CONVERT PAGE COUNT TO DECIMAL & TYPE
	OUTSTR	[ASCIZ/)

/]



;
;	GO FIND FIRST TTY TO START FOR THE DAY
;

A1:	HRRZI	16,^D5		;SET SLEEP INTERVAL TO 5 SECONDS
A:	JSR	GETTTY		;GO TRY TO ADD TTY TO POOL
;	OUTSTR	[ASCIZ/ZZZZZ/]	;LET EM KNOW YOUR SLEEPING!!!!!!
	CALL	16,[SIXBIT/SLEEP/] ; SLEEP FOR AC1 SECONDS
	CALL	15,[SIXBIT/TIMER/] ;GET CURRENT TIME (JIFFIES)
	MOVEM	15,HLDTIM	;SAVE TIME
	TTCALL	2,1		;INPUT CHAR FROM MASTER TTY TO AC1
	JRST	.+2		;MASTER HAS NOTHING / PROCEED
	JSR	PROMST		;GOT A CHARACTER / GO PROCESS IT
	JRST	A		;GO BACK & LOOK AGAIN !!!!

;
;	NOTE: WHEN TTY IS FOUND, GETTTY GOES TO RESTAC
;	      AFTER ENTERING NEW TTY IN TTYTBL
;

;
;	ALTER COBOL 'GO TO DEPENDING ON - - - '
;

ALTGO:	HRRZ	4,@ALTADD	;SET AC4 WITH ALTERED GO TO - - - 
	HRRZ	2,@TTYADR	;MOVE TTY#(LOGICAL) TO RH AC2
	HRRZ	5,GOTOAD	;MOVE GO TO ADDRESS TO AC5
	HRRM	5,.+1		;SET UP NEXT ADDRESS
	HRRM	4,.(2)		;MOVE ALTERED ADDRESS (AC4) TO
				;GO TO DEPENDING ON (AC3)
				;INDEXED BY LOGICAL TTY # (AC2)

;
;	FIND USERS TTY IN TTYTBL
;

	MOVEI	7,MAXTTY	;MOVE TTY TABLE SIZE TO AC7
	SETZ	5,		;ZERO AC5 (INDEX)
	
DL:	HLRZ	4,TTYTBL(5)	;MOVE LOGICAL TTY# FROM TTYTBL
	CAMN	2,4		;SKIP - IF LOGICAL TTY NOT = TABLE
	JRST	DLAA		;JUMP - FOUND LOGICAL TTY IN TTYTBL
	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY(TABSIZ WORDS/ENTRY)
	SUBI	7,1		;SUBTRACT 1 FROM ENTRIES LEFT IN TABLE
	JUMPG	7,DL		;LOOP - UNTIL HIT / TABLE EXHAUSTED
				;- - - - F A T A L - - - -
				;TABLE EXHAUSTED / DID SOMEONE CHANGE
				;THE LOGICAL TTY# IN COBOL PROGRAM??
	OUTSTR	CRLF
	OUTSTR [ASCIZ/? F A T A L -- CONFUSION ON LOGICAL TTYS/]
	OUTSTR [ASCIZ/    TRANSACTION PROCESSOR/]
	OUTSTR	CRLF

	HALT			;SORRY - - I MUST DIE - -
PAGE

;	IF USER HAS SET MORE-TO-COME TO 'Y'
;	    MARK HIS NO-ACCEPT BIT IN USER FLAG HALF-WORD
;

DLAA:	HRRZ	2,MTCADR	;MOVE ADDRESS OF MORE-TO-COME
	HRRM	2,.+1		;JAM ADDRESS ON NEXT INSTRUCTION
	HLRZ	1,.		;MOVE LH SWITCH TO RH AC1
	CAIE	1,544000	;SKIP - IF  SWITCH = 'Y'
	JRST	DLA		;JUMP - SWITCH NOT SET
	HRRM	2,.+1		;CLEAR SWITCH
	SETZM	,.		;  IN COBOL PROGRAM
	HLLZ	1,TTYTBL+2(5)	;MOVE TTYTBL FLAG HALF-WORD TO AC1 LH
	TLO	1,200000	;TURN ON 'NO-ACCEPT THIS TIME' BIT
	HLLM	1,TTYTBL+2(5)	;  SWITCH IN TTYTBL 

;
;	CHECK TO SEE IF THIS IS LAST MESSAGE FOR TTY 
;	(IF SO, CLEAN HIS TTYTBL ENTRY/GIVE ENDING MESSAGE)
;	(RESET HIS PAGE CODE AND UNSLAVE HIM)
;

DLA:	MOVE	6,@TYPPTR	;MOVE FIRST WORD OF RETURNED MESSAGE TO AC6
	CAME	6,STOPIT	;SKIP - IF MESSAGE = !STOP
	JRST	DLB		;CONTINUE - 
;
;	CHECK FOR  'ECHON (ECHO ON)  & 'ECHOF' (ECHO OFF)
;

	MOVE	6,TYPPTR	;MOVE ADDRESS OF WORD 1 COBOL AREA
	ADDI	6,1		;LOOK AT WORD #2 OF RETURN MESSAGE
	MOVE	1,@6		;PUT WORD #2 IN AC1
	CAMN	1,ECHOFF	;SKIP IF  NOT  ECHOF  (ECHO OFF)
	JRST	OFECHO		;GO TO CHANGE ECHO STATUS TO 'OFF'
	CAMN	1,ECHON		;SKIP IF  NOT  ECHON  (ECHO ON)
	JRST	ONECHO		;GO TO CHANGE ECHO STATUS (ECHO ON)
	CAIN	1,[SIXBIT/!ALL!/]	;IS WORD #" =  !ALL!
	JRST	KILALL		;YES - GO KILL ALL SLAVES!!!!!
	JRST	GOODBY		;HE MUST WANT TO GO AWAY
				; - GO SAY  GOOD BYE !!!!!
PAGE
;
;	TURN  USERS SLAVED TERMINAL 'ECHO'   (ON-OFF)
;

ONECHO:	SETZM	ECHO2		;SET ECHO ON BITS (ZERO IN BIT 35)
	JRST	CHGECH		;GO ALTER ECHO STATUS
OFECHO:	SETOM	ECHO2		;SET ECHO OFF BITS (ONE IN BIT 35)
CHGECH:	HRRZ	1,TTYTBL+2(5)	;MOVE PHYSICAL TTY#
	MOVEM	1,ECHO1		;TO  ECHO+1 (FOR SET TTY ECHO)
	MOVE	1,[XWD 3,ECHO]	;SET AC1 FOR CALLI (TRMOP.)
	CALLI	1,116		;CHANGE HIS ECHO STATUS
	JFCL			;NO-OP ERROR RETURN
	JRST	NXTTY		;GO LOOK FOR NEXT TTY:


;
;	THE PROGRAM HAS REQUESTED THAT I KILL ALL SLAVES
;

KILALL:	OUTSTR	[ASCIZ/

ALL SLAVES ARE BEING KILLED PER REQUEST OF PROGRAM

Y/]
	JRST	PK2		;GO TO ROUTINE TO KILL ALL SLAVES
				;
				;WHEN DONE IT WILL RETURN TO COBOL
				;PROGRAM VIA LOGICAL TTY #1
PAGE
;
;	THIS IS WHERE WE SAY GOOD BY TO USER TERMINAL
;

GOODBY:	HRRZ	1,TTYTBL+2(5)	;MOVE PHYSICAL TTY#
	MOVEM	1,DESLAV+1	;TO DESLAVE (FOR UUO)
	HRRZI	1,1		;MOVE 1 TO AC1
	MOVEM	1,UNSLAV	;SET UNSLAVE SWITCH FOR OUTTTY:

;	WRITE ENDING TTY MESSAGES ON MASTER TERMINAL

	OUTSTR	[ASCIZ/
TTY #/]
	HRRZ	11,TTYTBL+2(5)	;MOVE PHYSICAL TTY# TO AC11
	SUBI	11,200000	;SUBTRACT 200000 FROM TTY#
	PUSHJ	17,OCTPNT	;TYPE TTY# IN OCTAL
	OUTSTR	[ASCIZ/ ENDED @ /]
	JSR	TIMER		;GO GET THE TIME
	MOVE	11,14		;PLACE HOURS IN AC11
	PUSHJ	17,DECPNT	;GO TYPE HOURS (AFTER CONVERTING TO DECIMAL)
	OUTSTR	@COLON		;TYPE COLON (:)
	MOVE	11,15		;PLACE MINUTES IN AC11
	CAMG	11,NINE		;SKIP - IF MORE THAN 9 MINUTES
	OUTSTR	@ZERO		;TYPE LEADING ZERO FOR MINUTES
	PUSHJ	17,DECPNT	;GO TYPE MINUTES (AFTER CONVERTING TO DECIMAL)
	OUTSTR	[ASCIZ/
CONNECT TIME WAS /]
	JSR	CONTIM		;GO CALCULATE & TYPE CONNECT TIME

;	CHECK IF BEEING 'FLUSHED' DUE TO PASSWORD ERRORS!!!!!

	MOVE	6,TYPPTR	;MOVE ADDRESS ON WORD 1 COBOL AREA
	ADDI	6,1		;ADD 1, SO ADDRESS POINTS TO WORD 2 (AC6)
	MOVE	1,@6		;MOVE WORD 2 OF COBOL I-O AREA TO AC1
	CAMN	1,BADPW		;SKIP - IF NOT BAD PASSWORD TERMINATION
	OUTSTR	[ASCIZ/
**** USER TERMINATED DUE TO PASSWORD ERRORS ****
/]

	OUTSTR	[ASCIZ/
USER HAD /]
	HRRZ	11,TTYTBL(5)	;MOVE # OF TRANSACTION SETS TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	OUTSTR	[ASCIZ/ TRANSACTION SETS

/]
	SOS	TTYS		;SUBTRACT 1 FROM # OF SLAVE TTYS
	JSR	STATUS		;GO TYPE T/P VOLUME STATUS ON MASTER TTY
	JSR	NAMCHG		;CHANGE NAME TO REFLECT # SLAVES
	JSR	OUTTTY		;GO TYPE HIS FINAL MESSAGE
				;AND UNSLAVE HIM - - - - 

;	CLEAN TTYTBL FOR THE TTY WE JUST REMOVED

	HRRZI	1,		;ZERO AC1
	HRRM	1,TTYTBL(5)	;ZERO NUMBER OF TRANSACTION SETS
	HRRM	1,TTYTBL+1(5)	;ZERO ### OF SIXBIT (TTY###)
	MOVEM	1,TTYTBL+2(5)	;ZERO FLAGS & PHYSICAL TTY#
	MOVEM	1,TTYTBL+3(5)	;ZERO START TIME
	SETZM	TTYTBL+5(5)	;ZERO BYTES TO BE TYPED FROM TP BUFFER
	MOVE	2,TTYTBL+4(5)	;INITIALIZE BYTE POINTER TO
	MOVEM	2,TTYTBL+6(5)	;TP BUFFER
JAMIT:	SKIPN	TTYS		;SKIP - IF WE STILL HAVE SLAVES LEFT
				;NOTE: THIS INSTRUCTION IS OVERLAYED
				;      AT WRAP-UP TIME IN PK2:

	JRST	A1		;WE HAVE NO SLAVES LEFT!!!!
				;GO BACK & FIND SOME

	JRST	NXTTY		;GO FIND NEXT TTY IN TTYTBL WITH MESSAGE
				;OR MORE TO TYPE OUT FROM TTYTBL BUFFER



;
;	WRITE RETURNED MESSAGE(S) ON USERS TERMINAL
;

DLB:	JSR	OUTTTY		;GO MOVE FROM COBOL BUFFER & WRITE
	AOS	TTYTBL(5)	;ADD 1 TO # OF MESSAGES FOR THIS TTY
				;IT WILL TAKE 262,145 MESSAGES FROM
				;A SINGLE TTY BEFORE IT WILL OVERFLOW
				;INTO THE LOGICAL TTY#
	CALL	16,[SIXBIT/TIMER/] ;PLACE CURRENT (JIFFIES) IN AC16
	MOVEM	16,LINTIM	;SAVE TIME LAST LINE TYPED TO USER
PAGE
;
;	NOW WE LOOK FOR NEXT TTY WITH INPUT / OR TTY'S WITH MORE OUTPUT
;

NXTTY:	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY(TABSIZ WORDS/ENTRY)
	SUBI	7,1		;SUBTRACT 1 FROM ENTRIES LEFT IN TABLE
	JUMPG	7,SCAN		;JUMP- IF NOT AT END OF TABLE

;	RESET TO BEGINNING OF TABLE & SLEEP IF GOING TOO FAST!!!!!
;
;		CHECK FOR 'NEW' SLAVES EVERY SLVCHK: JIFFIES
;		FOR THE FIRST INITIM: JIFFIES ,  THEN  CHECK FOR
;		NEW SLAVES EVERY SLVCK1: JIFFIES


	SETZ	5,		;ZERO INDEX
	MOVEI	7,MAXTTY	;INITIALIZE AC7 TO TTYTBL SIZE

SLAV1:	JRST	.+1		;ALTERED TO SLAV2: AFTER INITIM: JIFFIES
	CALL	16,[SIXBIT/TIMER/] ;GET CURRENT TIME (JIFFIES)
	SUB	16,HLDTIM	;SUBTRACT 'FIRST SLAVE' TIME
	CAMG	16,INITIM	;SKIP - IF MORE THAN INITIM: JIFFIES
	JRST	SLAV2		;STILL IN 'QUICK SLAVE' MODE -JUMP-
	MOVE	1,SLVCK1	;JAM SLVCK1: TIME
	MOVEM	1,SLVCHK	;ON  SLVCHK:
	MOVE	1,[XWD 0,SLAV2] ;ALTER SLAV1: TO
	HRRM	1,SLAV1		;PROCEED TO SLAV2:

SLAV2:	CALL	16,[SIXBIT/TIMER/] ;GET CURRENT TIME (JIFFIES)
	SUB	16,LSTSLV	;SUBTRACT TIME SLAVES LAST LOOKED FOR
	CAML	16,SLVCHK	;SKIP - IF LESS THAN SLVCHK: JIFFIES
				;SINCE LAST GETTTY:
	JSR	GETTTY		;TRY TO FIND 'NEW' SLAVES
	TTCALL	2,1		;INPUT CHAR FROM MASTER TTY TO AC1
	JRST	.+2		;MASTER HAS NOTHING / PROCEED
	JSR	PROMST		;GO PROCESS CHAR FROM MASTER

	SKIPN	TALKED		;SKIP - IF ACTIVITY SINCE LAST TABLE LOOP
	JRST	SLEEP1		;GO TO SLEEP
	SETZM	TALKED		;TURN OFF 'TALKED' SWITCH
	SETZM	SLEEPCT		;ZERO SLEEP COUNTER
	JRST	SCAN		;GO SCAN FOR ACTIVE TTY


SLEEP1:	AOS	SLEEPCT		;ADD 1 TO SLEEP COUNTER
	HRRZI	1,^D360		;SET AC1 TO 360  1/6 SECONDS (60 SEC)	
	CAMG	1,SLEEPCT	;SKIP - IF LESS THAN ^D60 SECONDS 
	JRST	SLEEP2		;GO TAKE LONGER SLEEPS!!!!!!!
HIBER:	HRRZI	1,^D165		;SET HIBERNATE TIME
				;FOR 165 MS  (10 JIFFIES)
	CALL	1,[SIXBIT/HIBER/]  ;HIBERNATE FOR 1/6 SECOND
	JRST	HIBNG		;GO TO HIBERNATE N/G !!!!!
	JRST	SCAN		;GO SCAN FOR ACTIVE TTY


HIBNG:	JRST	.+1		;JUMP TO NEXT INSTRUCTION
	MOVEI	1,HIBNG1	;MOVE ADDRESS OF HIBNG1: TO AC1
	HRRM	1,HIBNG		;JAM HIBNG: TO JRST HIBNG1
	OUTSTR	[ASCIZ/%HIBERNATE FAILED- - (WILL SUBSTITUTE SLEEP)
/]
	MOVEI	1,^D100		;SET HBFAIL TO  ^D100
	MOVE	1,HBFAIL	

HIBNG1:	MOVEI	1,1		;MOVE 1  SECOND TO SLEEP TIME
	CALLI	1,31		; SLEEP FOR AC1   SECONDS
	SOSE	HBFAIL		;SUBTRACT 1 FROM HBFAIL -SKIP IF ZERO
	JRST	SCAN		;GO   SCAN FOR ACTIVE TTY
	OUTSTR	[ASCIZ/% 100 HIBERNATE FAILURES
/]
	MOVEI	1,^D1000	;SET HBFAIL TO 1000 THIS TIME
	MOVE	1,HBFAIL	;
	JRST	SCAN		;GO SCAN FOR TTY ACTIVITY


SLEEP2:	HRRZI	1,^D1		;SET SLEEP FOR 1 SECONDS
	CALL	1,[SIXBIT/SLEEP/]  ;SLEEP FOR AC1 SECONDS
	JRST	SCAN		;GO SCAN FOR ACTIVE TTY

;	SCAN TABLE LOOKING FOR 'ACTIVE' TTYS - - - -

SCAN:	HRRZ	1,TTYTBL+2(5)	;MOVE PHYSICAL TTY NUMBER TO AC1
	JUMPE	1,NXTTY		;GO TRY NEXT ENTRY IN TABLE
				;(THIS ONE IS EMPTY)
	SKIPG	TTYTBL+5(5)	;SKIP - IF TP BUFFER HAS CHARACTERS TO BE TYPED
	JRST	SCAN1		;NOTHING TO BE TYPE FROM TTYS TP BUFFER
				;GO SEE IF HE HAS INPUT - - -
	MOVEM	1,EMPBF1	;HE HAS SOMETHING TO TYPE / SEE IF HIS TTY
	MOVE	2,[XWD 2,EMPBF] ;OUTPUT BUFFER IS EMPTY (SO WE CAN FILL IT!)
	CALLI	2,116		;SKIP - IF TTY BUFFER -NOT- EMPTY
	JRST	.+2		;JUMP OVER NEXT
	JRST	NXTTY		;TTY BUFFER NOT EMPTY / GO LOOK AT NEXT TTY
	SETOM	GETP		;SET 1 WORD FLAG TO TELL OUTTTY: THAT
				;WE WANT TO FILL TTY RING BUFFER FROM TP BUFFER
	JSR	OUTTTY		;GO FILL & WRITE
	JRST	NXTTY		;GO LOOK @ NEXT TTY

;	CHECK TO SEE IF COBOL PROGRAM WANTS THIS TTY
;	TO RETURN WITH  NO-MESSAGE

SCAN1:	HLLZ	2,TTYTBL+2(5)	;MOVE FLAG HALF-WORD TO AC1
	TLZN	2,200000	;SKIP - IF 'NO-RETURN'
	JRST	SCAN2		;GO LOOK TO SEE IF HE HAS INPUT
	HLLM	2,TTYTBL+2(5)	;REPLACE FLAGS WITH BIT CLEARED
	HLRZ	2,TTYTBL(5)	;JAM LOGICAL TTY #
	MOVEM	2,@TTYADR	;  INTO  I-O-TTY
	JRST	RESTAC		;GO TO  RETURN TO  COBOL

SCAN2:	SETZM	TTYTBL+5(5)	;ZERO BYTE COUNTER SO WE START WITH CLEAN ONE
	SUBI	1,200000	;REMOVE 200000 FOR TTCALL 6 (BUG)
	TTCALL	6,1		;GET LINE INFO ON TTY
	TLNN	1,100		;TEST TO SEE IF LINE HAS BEEN TYPED
				;SKIP - IF LINE HAS BEEN TYPED!!
	JRST	NXTTY		;LINE NOT READY / GO LOOK AT NEXT TTY IN TABLE
	JRST	INPUT		;TTY HAS LINE READY / GO GET IT


;
;	GET INPUT FROM USERS TTY
;

INPUT:	MOVE	1,TTYTBL+1(5)	;MOVE SIXBIT TTY NAME
	MOVEM	1,OPNTTY+1	;TO CHANNEL INFO
	OPEN	14,OPNTTY	;OPEN TTY ON CHANNEL 14
	JRST	ERR6		;OPEN FAILED / GO TELL 'EM
	MOVE	1,[XWD SAIBUF,IBUF] ;SET UP BLT
	BLT	1,IBUF+2	;INITIALIZE INPUT BUFFER HEADER
	IN	14,		;READ INTO BUFFER
	JRST	.+2		;JUMP OVER ERROR RETURN
	OUTSTR	[ASCIZ/
??INPUT ERROR FROM TTY (THIS IS TP)
/]
	SETZ	3,		;ZERO AC3 (^C FOUND SWITCH)
	MOVE	1,POINT4	;MOVE COBOL I-O
	MOVEM	1,POINT3	;AREA POINTER
	HRRZI	2,^D72		;COBOL I-O AREA COUNTER
INPLOP:	ILDB	1,IBUF+1	;GET BYTE FROM RING BUFFER
	CAIL	1,40		;SKIP IDPB -  IF CHARACTER LESS THAN SPACE
				;THIS REMOVES TAB,CR,LF,FF,BELL ESC, ETC.
				;OCTAL 00 - 37 ARE REMOVED /
				;NOTHING IS SUBSTITUTED
	JRST	INPLOK		;GREATER THAN 37 (GO PASS CHARACTER)

	CAIN	1,11		;HORIZONTAL TAB <TAB>
	JRST	INPLOK		;<TAB> IS OK   (GO PASS IT ON!!)

	CAIN	1,15		;CARRIAGE RETURN  <CR>
	JRST	INPLOK		;<CR> IS OK   (GO PASS IT ON!!)

;    PLACE CODE HERE TO PASS ON ANY MORE SPECIAL CHARACTERS!!!!

	CAIN	1,3		;CONTROL-C  (^C)
	ADDI	3,1		;SET  ^C  SWITCH UP BY 1
	JRST	INPLK1		;  DROP CHARACTER

INPLOK:	IDPB	1,POINT3	;PUT IT IN COBOL AREA
INPLK1:	AOS	CHRIN		;ADD 1 TO # CHARACTERS TYPED IN
	SOSE	IBUF+2		;DECREMENT RING BUFFER BYTE COUNTER
				;SKIP - WHEN EMPTY
	SOJN	2,INPLOP	;LOOP IF COBOL NOT FULL - - 
	RELEASE	14,		;BREAK CHANNEL/DEVICE BOND

;	JAM LOGICAL TTY# IN COBOL PROGRAM

	HLRZ	1,TTYTBL(5)	;MOVE LOGICAL TTY# TO AC1
	MOVEM	1,@TTYADR	;THEN JAM IN COBOL PROGRAM

;	CHECK FOR  ^C  & PROCESS IF ANY IN INPUT STRING

	JUMPE	3,NOUPC		;JUMP TO NO CONTROL-C FOUND
	HRRZ	4,CNTRLC	;MOVE ADDRESS IN CONTROL-C-DISPATCH TO AC4
	HRRZ	2,GOTOAD	;MOVE ADDRESS OF FIRST  GO TO DEPENDING ON TO AC2
	HRRM	2,.+1		;SET UP NEXT ADDRESS
	HRRM	4,.(1)		;MOVE ^C DISPATCH ADDRESS TO GO TO DEPENDING ON
				;TABLE (INDEXED BY LOGICAL TTY#  AC1)

	MOVE	1,POINT4	;SET UPP COBOL AREA BYTE POINTER
	MOVEI	2,40		;MOVE ASCII SPACE TO AC2
	MOVEI	3,^D75		;SET COUNTER TO 75 BYTES
INLOOP:	IDPB	2,1		;DEPOSIT  SPACE
	SOJN	3,INLOOP	;LOOP 'TIL DONE

NOUPC:	JRST	RESTAC		;GO TO RETURN TO COBOL

;
;	RESTORE AC'S
;

RESTAC:	MOVE	17,[XWD SAVEAC,0]	;SET UP FOR BLT
	BLT	17,17		;RESTORE THE AC'S
	MOVE 	17,SAVE17	;RESTORE AC17
	POPJ	17,		;RETURN TO COBOL PROGRAM

;
;	TELL MASTER TTY ABOUT NEW SLAVE TTY IN POOL
;

MSGENT:	0			;SAVE RETURN PC HERE!
	OUTSTR	@CRLF		;TYPE <CR><LF>
	OUTSTR	MESS1			;TTY #
	HRRZ	11,TTYTBL+2(5)	;MOVE PHYSICAL TTY # TO AC11
	SUBI	11,200000	;SUBTRACT 200000 FROM TTY #
	PUSHJ	17,OCTPNT	;TYPE TTY # IN OCTAL
	MOVE	1,OCTHLD	;SAVE SIXBIT
	MOVEM	1,SBITTY	;TTY NUMBER
	OUTSTR	[ASCIZ/ STARTED @ /]
	JSR	TIMER		;GO GET CURRENT TIME
	MOVE	11,14		;PLACE HOURS IN AC11
	PUSHJ	17,DECPNT
	OUTSTR	@COLON		;TYPE COLON
	MOVE	11,15		;PLACE MINUTES IN AC11
	CAMG	11,NINE		;SKIP - IF MORE THAN 9 MINUTES
	OUTSTR	@ZERO		;TYPE LEADING ZERO FOR MINUTES
	PUSHJ	17,DECPNT
	OUTSTR	@CRLF		;TYPE <CR><LF>
	JRST	@MSGENT		;RETURN


;
;	GET THE TIME OF DAY	    AC14 = HOURS (OCTAL)
;				    AC15 = MINUTES (OCTAL)
;				    AC16 = JIFFIES (OCTAL)
;

TIMER:	0			;SAVE RETURN PC HERE!
	CALL	16,[SIXBIT/TIMER/] ;PLACE CURRENT TIME 
				;IN JIFFIES IN AC16
				;24 HRS = 5,184,000 JIFFIES (23 BITS)
	MOVE	14,16		;MOVE TIME TO AC14
	IDIVI	14,^D3600	;CONVERT TIME TO MINUTES
	IDIVI	14,^D60		;CONVERT TIME TO HOURS  AC14
				;     REMAINDER MINUTES AC15
	JRST	@TIMER		;RETURN
PAGE

;
;	LOOK FOR TTYS ON SYSTEM / WITH OUR PAGE CALL
;

GETTTY:	0			;SAVE RETURN PC HERE!

	CALL	16,[SIXBIT/TIMER/] ;GET CURRENT TIME IN (JIFFIES)
	MOVEM	16,LSTSLV	;SAVE THE TIME
	MOVE	4,SYSTTY	;SET UP UNIVERSAL I/O INDEX
	ADDI	4,200000	;WITH NUMBER OF TTYS ON SYSTEM + 200000

GA:	HRRZI	3,1023		;SET UP FUNCTION CODE (PAGE SIZE)
	MOVE	2,[XWD 2,3]	;SET AC2 FOR CALLI (TRMOP.)
	CALLI	2,116		;GET TTY PAGE SIZE
	JRST	ERR2		;CALLI FAILED / TELL THE WORLD!!
	CAME	2,TPID		;SKIP IF TTY IS FOR THIS TP
	JRST	GB		;GO LOOK @ NEXT TTY /  NOT OUR PAGE
	JRST	CKTBL		;TTY IS FOR OUR PAGE - - -
				;GO SEE IF WE ALREADY HAVE HIM
				;IN OUR TTYTBL - - - - - - -

GB:	SUBI	4,1		;SUBTRACT 1 FROM TTY NUMBER
	CAIL	4,200000 	;SKIP IF TTY LESS THAN  0 (200000)
	JRST	GA		;GO CHECK NEXT TTY
	SETO	1,		;SET AC1 TO ONES (DID NOT FIND NEW TTY)
	JRST	@GETTTY		;RETURN

GC:	CAMN	1,BADTTY	;SKIP - IF THIS IS -NOT- THE LAST
				;     - TTY WE TOLD OPR: TO CLEAR PAGE
	JRST	GB		;GO LOOK AT NEXT TTY
	MOVEM	1,BADTTY	;SAVE THIS TTY NUMBER FOR NEXT TIME
	OUTSTR	[ASCIZ/
"OPR- PLEASE TELL TTY/]
	MOVE	11,4		;MOVE TTY# TO AC11
	SUBI	11,200000	;REMOVE OFFSET
	PUSHJ	17,OCTPNT	;GO CONVERT & TYPE
	OUTSTR	[ASCIZ/ TO LOG OUT OR CLEAR  (.SET TTY PAGE 63)
/]
	JRST	GB		;GO LOOK AT NEXT TTY

;
;	GOT ONE / CHECK TO SEE IF WE ALREADY HAVE HIM !!
;

CKTBL:	MOVEI	7,MAXTTY	;SET TABLE ENTRIES COUNT-DOWN
	SETZ	5,		;ZERO AC5 (INDEX)
CKTBA:	HRRZ	6,TTYTBL+2(5)	;MOVE PHYSICAL TTY # (+200000) TO AC6
	CAMN	4,6		;SKIP - IF TTY NOT HERE IN TTYTBL
	JRST	GB		;EQUAL - WE ALREADY HAVE HIM/
				;GO LOOK FOR ANOTHER POTENTIAL SLAVE - - - -
	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY (TABSIZ WORDS/ENTRY)
	SUBI	7,1		;SUBTRACT 1 FROM # TTYS IN TABLE
	JUMPG	7,CKTBA		;LOOP - UNTIL HIT/TABLE EXHAUSTED

;
;	WE HAVE A 'NEW'  TTY - - FIND 'HOLE' IN TABLE FOR HIM - -
;				IF HE IS NOT ATTACHED TO LOGGED-IN JOB
;

	MOVE	11,4		;MOVE TTY# TO AC11
	SUBI	11,200000	;REMOVE OFFSET
	SETOM	NOTYPE		;SET SWITCH TO 'NO-TYPE'
	PUSHJ	17,OCTPNT	;GO CONVERT TTY# TO SIXBIT
	SETZM	NOTYPE		;TURN OFF 'NO-TYPE' SWITCH
	MOVE	1,[SIXBIT/TTY   /]	;MOVE SIXBIT 'TTY   ' TO LH AC1
	HLR	1,OCTHLD	;MOVE SIXBIT TTY # TO RH AC1
	MOVEM	1,OPNTTY+1	;MOVE SIXBIT TTY NAME TO COMMAND LIST
	OPEN	14,OPNTTY	;TRY TO GET TTY### ON CH14
	JRST	GC		;OPEN FAILED - - TTY LOGGED IN??? 
				;TELL OPR & GO LOOK
				;AT NEXT TTY

	MOVEI	7,MAXTTY	;SET COUNT-DOWN (# ENTRIES IN TABLE)
	SETZ	5,		;ZERO AC5 (INDEX)
	
TBLA:	HRRZ	6,TTYTBL+2(5)	;MOVE PHYSICAL TTY# (+200000) TO AC6
	JUMPE	6,TBLB		;IF TTYTBL(WORD 3) = ZERO, WE HAVE HOLE
	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY(TABSIZ WORDS/ENTRY)
	SUBI	7,1		;SUBTRACT 1 FROM #TTYS IN TABLE
	JUMPG	7,TBLA		;LOOP - UNTIL  HOLE

	OUTSTR	@CRLF
	OUTSTR	[ASCIZ/ NOTE: TTY TABLE FULL - TELL SYSTEMS PERSON/]
	OUTSTR	@CRLF
	OUTSTR	@CRLF
	OUTSTR	[ASCIZ/"OPR: PLEASE  .SEND TTY:/]
	MOVE	11,4		;MOVE TTY# TO AC11
	SUBI	11,200000	;REMOVE OFFSET
	PUSHJ	17,OCTPNT	;GO TYPE OCTAL TTY#
	OUTSTR	[ASCIZ/:ON-LINE ENTRY FULL (PLEASE .SET TTY PAGE 63) AND TRY LATER
/]

	JRST	@GETTTY		;RETURN


;	WE HAVE A 'HOLE' - - - - - TABLE HIM - - - - - - -

TBLB:	MOVEM	4,TTYTBL+2(5)	;MOVE TTY# (+200000) TO TTYTBL
				;THIS ALSO CLEARS FLAGS!!!!
	HLRZ	3,TTYTBL(5)	;MOVE LOGICAL TTY# TO AC3
	MOVEM	3,@TTYADR	;JAM LOGICAL TTY# FOR COBOL TABLE ROLLING
	JSR	MSGENT		;TELL CONTROL TTY ABOUT NEW TTY

;
;	MAKE HIM A SLAVE   =   (.SET TTY SLAVE)
;
;	(AC4 CONTAINS TTY# + 200000)
;

	MOVEM	4,SETSL1	;MOVE TTY#+200000 TO SET SLAVE 
	MOVE	2,[XWD 3,SETSLV] ;SET AC2 FOR CALLI (TRMOP.)
	CALLI	2,116		;SLAVE THE TTY!!!!!!
	JRST	ERR2		;CALLI FAILED / COMPLAIN - - - 



;
;	TURN HIS GAG OFF  = (.SET TTY NO GAG)
;

	MOVEM	4,SETGG1	;MOVE TTY#+200000 TO SET NO GAG
	MOVE	2,[XWD 3,SETGAG] ;SET AC2 FOR CALLI (TRMOP.)
	CALLI	2,116		;SET HIS GAG BIT TO 'NO GAG'
	JRST	ERR2		;CALLI FAILED / COMPLAIN - - -

;
;	PRETEND HE HAS NO TABS	(.SET TTY NO TABS)
;

	MOVEM	4,NOTAB1	;MOVE TTY# + 200000 TO ARGS
	MOVE	2,[XWD 3,NOTAB]	;SET AC2 FOR CALLI (TRMOP.)
	CALLI	2,116		;SET HIS TAB SWITCH TO  'NO TABS'
	JRST	ERR2		;IF IT FAILS (WHICH IT DID) COMPLAIN



;	TELL MASTER TTY HOW MANY USERS WE NOW HAVE

	AOS	TTYS		;ADD 1 TO # OF SLAVE TTYS
	JSR	NAMCHG		;CHANGE NAME TO REFLECT # SLAVES

;	CLEAR HIS INPUT BUFFER (MONITOR LEAVES 'LINE-TYPED' BIT ON
;			       (FROM  .SET TTY SLAVE              )

;	HRRZI	3,3		;SET UP FUNCTION CODE (CLEAR TTY INPUT BUFFER)
;	MOVE	2,[XWD 2,3]	;SET AC2 FOR CALLI 116 (TRMOP.)
;	CALLI	2,116		;CLEAR HIS INPUT BUFFER
;	JRST	.+1		;ERROR RETURN (SO WHAT!!!!)
	HLR	1,SBITTY	;MOVE PHYSICAL TTY NAME
	HRRM	1,TTYTBL+1(5)	;TO TTYTBL
	MOVEM	16,TTYTBL+3(5)	;MOVE START-TIME (JIFFIES) TO TTYTBL
	JRST	RESTAC		;GO RESTORE ACS &  RETURN TO COBOL
				;WITH NEWLY FOUND TTY!!!!!!

PAGE

;	PROCESS REQUEST FROM MASTER TTY

PROMST:	0			;SAVE RETURN PC HERE
	TTCALL	11,0		;CLEAR INPUT BUFFER / LIKE (^U)
	CAMN	1,K		;SKIP - IF CHAR NO = 'K'
	JRST	PROKIL		;GO PROCESS KILL COMMAND
	CAMN	1,S		;SKIP - CHAR NOT = 'S'
	JRST	PROSLV		;GO PROCESS SLAVE LIST
	CAMN	1,H		;SKIP - IF CHAR NOT = 'H'
	JRST	HELP		;GO PROCESS HELP
	CAMN	1,POUND		;SKIP - IF CHAR NOT = '#'
	JRST	SLVCNT		;GO TYPE SLAVE-COUNT
	OUTSTR	[ASCIZ/ ?WHAT?     TRY   H   FOR HELP
/]
	
PROCNT:	OUTSTR	[ASCIZ"

T/P FOR   ON-LINE ORDER ENTRY   RUNNING

"]
	JRST	@PROMST		;RETURN

PAGE

;	PROCESS KILL-SLAVES  GRACEFULLY

PROKIL:	OUTSTR	[ASCIZ/ILL SLAVES & JOB
/]
PKA:	OUTSTR	[ASCIZ/
CONFIRM (Y-N) :/]
	TTCALL	0,1		;GET ANSWER INTO AC1
				;(WAIT IF NECESSARY)
	TTCALL	11,0		;CLEAR INPUT BUFFER LIKE (CTL U)
	CAME	1,N		;SKIP - IF 'N'
	JRST	PK1		;GO TO TEST FOR 'Y'
	OUTSTR	[ASCIZ/O
/]
	JRST	PROCNT		;RETURN

PK1:	CAMN	1,Y		;SKIP - IF NOT = 'Y'
	JRST	PK2		;GO PROCESS 'Y'
	OUTSTR	[ASCIZ/??

/]
	JRST	PKA		;INVALID CONFIRM: / GO TRY AGAIN

PK2:	OUTSTR	[ASCIZ/ES  BEGIN UNSLAVING TTYS

/]
	MOVE	1,JMPPK3	;MOVE JRST PK3A TO AC1
	MOVEM	1,JAMIT		;MOVE JRST PK3A TO JAMIT:
	SETZ	5,		;ZERO AC5
	MOVEI	7,MAXTTY	;MAX # TABLE ENTRIES

PK3:	MOVE	1,TTYTBL+2(5)	;PHYSICAL TTY# (+200000) TO AC1
	JUMPN	1,PK4		;GO UNSLAVE THIS GUY - - - - 
PK3A:	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY (TABSIZ WORDS/ENTRY)
	SUBI	7,1		;DECREMENT # TABLE ENTRIES LEFT
	JUMPG	7,PK3		;GO LOOK @ NEXT TABLE ENTRY
	OUTSTR	[ASCIZ/

ALL TTY'S UNSLAVED : RETURNING TO COBOL PROGRAM
/]
	MOVE	1,EXIT		;MOVE EXIT UUO TO AC1
	MOVEM	1,TP		;JAM EXIT ON TP:
	HRRZI	1,1		;JAM LOGICAL TTY#1
	MOVEM	1,@TTYADR	;IN COBOL PROGRAM / THIS TRIPS WRAP-UP ROUTINES
	JRST	RESTAC		;GO RETURN TO COBOL PROGRAM

EXIT:	CALLI	1,12		;EXIT UUO / WILL BE JAMMED ON TP:
				;@ CLOSE OF T/P
JMPPK3:	JRST	PK3A		;JUMP TO PK3A: / WILL BE JAMMED ON JAMIT:

PK4:	MOVE	1,STOPIT	;JAM USERS MESSAGE AREA
	MOVEM	1,@TYPPTR	;TO FORCE UNSLAVE
	JRST	DLA		;GO UNSLAVE TTY
				;RETURN WILL BE FROM JAMIT:
				;TO PK3: (JAMIT: WAS ALTERED IN PK2:)
PAGE

;	PROCESS SLAVE LIST

PROSLV:	OUTSTR	[ASCIZ"LAVE LIST (T/P PAGE "]
	MOVE	11,TPID		;MOVE TP PAGE TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	OUTSTR	[ASCIZ/)  @ /]
	JSR	TIMER		;GO GET CURRENT TIME
	JSR	TYTIME		;GO TYPE TIME (HH:MM)
				; (HH) IN AC14
				; (MM) IN AC15
	OUTSTR	[ASCIZ/

TTY #  CONN.  T.S.

/]
	SETZ	5,		;ZERO AC5
	MOVEI	7,MAXTTY	;MAX # TABLE ENTRIES
	SETZM	GOTANY		;CLEAR GOTANY: SWITCH

PS1:	HRRZ	1,TTYTBL+2(5)	;PHYSICAL TTY #(+200000) TO AC1
	JUMPN	1,PS3		;GOT ONE - GO TYPE HIM

PS2:	ADDI	5,TABSIZ	;BUMP INDEX TO NEXT ENTRY (TABSIZ WORDS/ENTRY)
	SUBI	7,1		;DECREMENT # TABLE ENTRIES LEFT
	JUMPG	7,PS1		;GO LOOK @ NEXT TABLE ENTRY
	SKIPN	GOTANY		;ALL DONE / SKIP IF SLAVES
	OUTSTR	[ASCIZ/* * NO SLAVES * *
/]
	SETZ	5,		;ZERO AC5
	MOVEI	7,MAXTTY	;MAX # TABLE ENTRIES
	JRST	PROCNT		;RETURN

PS3:	SUBI	1,200000	;SUBTRACT 200000 FROM TTY#
	OUTSTR	[ASCIZ/TTY/]
	MOVE	11,1		;MOVE OCTAL TTY# TO AC11
	PUSHJ	17,OCTPNT	;GO TYPE OCTAL
	OUTSTR	[ASCIZ/	/]
	JSR	CONTIM		;GO CALCULATE & TYPE CONNECT TIME
	OUTSTR	[ASCIZ/  /]
	HRRZ	11,TTYTBL(5)	;MOVE # TRANSACTION SETS TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	OUTSTR	@CRLF		;TYPE <CR><LF>
	SETOM	GOTANY		;SET 'WE HAVE SLAVES' SWITCH
	JRST	PS2		;GO LOOK @ NEXT TABLE ENTRY

PAGE

;	# SLAVES  (TYPE OUT ON MASTER TTY)

SLVCNT:	OUTSTR	[ASCIZ/ SLAVES CONNECTED = /]
	MOVE	11,TTYS		;MOVE # OF CONNECTED SLAVES TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	OUTSTR	@CRLF		;TYPE <CR><LF>
	JRST	PROCNT		;RETURN
PAGE

;	H E L P   THE MASTER TTY OPERATOR


HELP:	OUTSTR	[ASCIZ" E L P

ALL TTY COMMANDS TO T/P ARE SINGLE CHARACTERS WITH NO <CR>
"]
	OUTSTR [ASCIZ"

# -  # SLAVE TTYS RUNNING UNDER THIS T/P
H -  HELP (THIS TEXT)"]
	OUTSTR	[ASCIZ"
K -  KILL ALL SLAVES & JOB (REQUIRES CONFIRM:)"]
	OUTSTR	[ASCIZ"
S -  SLAVE LIST (TTY#, CONNECT TIME,TRANSACTION SETS)

END HELP
"]
	JRST	PROCNT		;RETURN

PAGE

;	TYPE TIME   HH:MM    ON MASTER TTY
;
;		(HH) AC14    (MM) AC15


TYTIME:	0			;SAVE RETURN PC HERE
	MOVE	11,14		;MOVE HOURS TO AC11
	CAMG	11,NINE		;SKIP - IF MORE THAN 9 HOURS
	OUTSTR	@ZERO		;TYPE LEADING ZERO FOR HOURS
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	OUTSTR	@COLON		;TYPE COLON
	MOVE	11,15		;MOVE MINUTES TO AC11
	CAMG	11,NINE		;SKIP - IF MORE THAN 9 MINUTES
	OUTSTR	@ZERO		;TYPE LEADING ZERO FOR MINUTES
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE
	JRST	@TYTIME		;RETURN


;	CALCULATE & TYPE SLAVES CONNECT TIME
;
;	AC5 MUST BE SET TO TTYTBL ENTRY FOR TTY
;
;	CURRENT TIME MUST BE IN AC16 (JIFFIES)


CONTIM:	0			;SAVE RETURN PC HERE
	MOVE	15,TTYTBL+3(5)	;MOVE START TIME (JIFFIES) FROM TTYTBL
	MOVE	14,16		;MOVE CURR TIME TO AC14 FOR DIVIDE 2 WORD RESULT
	SUB	14,15		;SUBTRACT START TIME FROM STOP TIME
	IDIVI	14,^D3600	;CONVERT JIFFIES TO MINUTES
	IDIVI	14,^D60		;CONVERT MINUTES TO HOURS  AC14
				;       REMAINDER MINUTES  AC15
	JSR	TYTIME		;GO TYPE TIME
	JRST	@CONTIM		;RETURN
PAGE
;
;	OUTPUT MESSAGE ON USERS TERMINAL (CHANNEL 14)
;

OUTTTY:	0			;SAVE RETURN PC HERE!
	SKIPE	GETP		;SKIP IF NOT GETTING FROM TP BUFFER
	JRST	OPNIT		;JUMP TO OPEN
	HRRZ	6,@LNSADR	;MOVE NUMBER OF LINES TO TYPE TO AC6
	JUMPN	6,OPNIT		;JUMP IF LINES NOT = ZERO
	SKIPN	UNSLAV		;SKIP - IF WE WANT TO UNSLAVE
	JRST 	OUTTYB		;JUMP OVER WRITE ROUTINE IF 0 LINES & NO UNSLAVE
OPNIT:	MOVE	1,TTYTBL+1(5)	;MOVE (SIXBIT) TTY NAME TO
	MOVEM	1,OPNTTY+1	;OPEN COMMAND LIST
	OPEN	14,OPNTTY	;OPEN TTY ON CHANNEL 14
	JRST	ERR3		;OPEN FAILED/GO TELL THE WORLD
BUFBLD:	JRST	.+1		;THIS IS ALTERED TO RESETO:
	MOVE	1,[XWD 0,RESETO]	;MOVE ADDRESS OF RESETO TO RH AC1
	HRRM	1,BUFBLD	;ALTER BUFBLD: TO PROCEED TO RESETO:
	INBUF	14,1		;SETUP 1 INPUT  BUFFER ON CH14
	OUTBUF	14,1		;SETUP 1 OUTPUT BUFFER ON CH14
	MOVE	1,[XWD OBUF,SAOBUF] ;SET UP BLT
	BLT	1,SAOBUF+2	;SAVE OBUF BUFFER RING HEADER
	MOVE	1,[XWD IBUF,SAIBUF] ;SET UP BLT
	BLT	1,SAIBUF+2	;SAVE IBUF BUFFER RING HEADER
	JSR	LOCKIT		;GO LOCK JOB IN CORE


RESETO:	MOVE	1,[XWD SAOBUF,OBUF] ;SET UP BLT
	BLT	1,OBUF+2	;RESET OBUF RING HEADER
	OUT	14,		;OUTPUT ON CHANNEL 14
	JRST	.+2		;OK- JUMP OVER FAILURE - - - 
	JRST	ERR4		;SORRY OUTPUT FAILED/ SNIFF!

;	CHECK TO SEE IF WE ARE GOING TO FILL TTY RING BUFFER
;	FROM TP BUFFER

	SKIPN	GETP		;SKIP - -IF WE WANT TO FILLTTY RING
				;BUFFER FROM TP BUFFER
	JRST	CKUNSL		;JUMP TO CHECK FOR UNSLAVE
	
TPLOOP:	ILDB	2,TTYTBL+6(5)	;GET BYTE FROM TP TABLE
	IDPB	2,OBUF+1	;PUT BYTE IN TTY RING BUFFER
	SOSN	OBUF+2		;DECREMENT RING BUFFER BYTE COUNTER
				;SKIP - WHEN NOT FULL -
	JRST	TPLOP1		;TTY RING BUFFER FULL - - GO WRITE
	SOSLE	TTYTBL+5(5)	;DECREMENT TP BUFFER BYTE COUNTER
				;SKIP - WHEN TP BUFFER EMPTY
	JRST	TPLOOP		;LOOP
TPLOPA:	MOVE	1,TTYTBL+4(5)	;RESET EXTRACT BYTE POINTER SINCE
	MOVEM	1,TTYTBL+6(5)	;BUFFER IS NOW EMPTY
	JRST	TPLOP2		;TP BUFFER EMPTY - GO WRITE(AFTER SWITCH CLEAR)
TPLOP1:	SOSG	TTYTBL+5(5)	;DECREMENT TP BUFFER BYTE COUNTER
				;SKIP - IF 'GREATER THAN'  ZERO
	JRST	TPLOPA		;GO RESET EXTRACT BYTE POINTER
TPLOP2:	SETZM	GETP		;CLEAR SWITCH (MOVE FROM TP SWITCH)
	SETOM	TALKED		;TELL SLEEPER THAT WE DID SOMETHING
	SKIPL	TTYTBL+5(5)	;SKIP IF BYTE COUNTER LESS THAN ZERO
	JRST	TPLOP3		;GO OVER ERROR ROUTINE
	SETZM	TTYTBL+5(5)	;ZERO THE DAMN THING/ TELL OPERATOR
	OUTSTR	[ASCIZ/
  BYTE COUNTER HAS GONE NEGATIVE FOR  TTY/]
	MOVE	11,TTYTBL+2(5)	;MOVE TTY NUMBER TO AC11
	SUBI	11,200000	;REMOVE TRMOP OFF-SET
	PUSHJ	17,OCTPNT	;GO TYPE IT IN OCTAL
	OUTSTR	[ASCIZ/  @  /]
	JSR	TIMER		;GO GET CURRENT TIME
	JSR	TYTIME		;GO TYPE TIME ON MASTER TTTY
	OUTSTR	[ASCIZ/

/]
TPLOP3:	JRST	OTD		;GO WRITE - - - - - - - -

;	CHECK FOR UNSLAVE REQUEST / BUILD FINAL USER MESSAGE ON UNSLAVE

CKUNSL:	SKIPN	UNSLAV		;SKIP - IF WE WANT TO UNSLAVE TTY
	JRST	OTA1		;LEAVE HIM SLAVED/NOT FINAL MESSAGE
	MOVE	1,POINT4	;MOVE POINTER FOR COBOL TTY I-O AREA TO AC1
	MOVEM	1,POINT3	;THEN TO POINT3
	MOVE	1,FINPT		;POINTER TO FINAL
	MOVEM	1,FINPNT	;USER MESSAGE
	HRRZI	4,^D30		;SET AC4 TO ^D30
OTL:	ILDB	3,FINPNT	;LOAD CHARACTER FROM FINAL MESSAGE
	IDPB	3,POINT3	;DEPOSIT CHARACTER IN COBOL I-O AREA
	SOJN	4,OTL		;SUBTRACT 1 FROM AC4
				;JUMP IF = 0
				;JUMP BACK IF NOT DONE
	HRRZI	6,1		;SET # LINES TO 1


;	MOVE FROM COBOL OCCURS 'N' TIMES  PIC X(75) ASCII
;	TO OUTPUT TTY RING BUFFER
;	THEN TO TP BUFFER WHEN TTY RING FULL
;	WHEN TP BUFFER FULL THROW AWAY ALL OTHER CHARACTERS
;	NOTIFY -  MASTER TTY OF LOST CHARACTERS
;

OTA1:	MOVE	13,TTYTBL+4(5)	;MOVE TP BUFFER BYTE POINTER TO AC13
	SETZ	14,		;ZERO BYTE COUNTER FOR TP BUFFER
	SETO	15,		;SET AC15 TO ONES INDICATING TTY RING BUFFER 
				;HAS ROOM LEFT
	SETO	16,		;SET AC16 TO ONES INDICATION TP BUFFER
				;HAS ROOM LEFT

;	LOOK FOR RIGHT MOST NON-SPACE IN COBOL I-O AREA

	HRRZI	4,40		;MOVE ASCII SPACE TO AC4 (RJ)
	MOVE	1,POINT4	;INITIALIZE BYTE POINTER
	MOVEM	1,POINT3	;FOR COBOL TTY I-O AREA
	MOVE 	10,1		;INITIALIZE BEGIN BUFFER POINTER AC10
	HRRZI	2,^D74		;INITIALIZE AC2 FOR COBOL I-O AREA SIZE
	MOVE	11,POINT3	;HOLD BYTE POINTER (BEGINNING OF BUFFER)
	
OTA:	ILDB	3,POINT3	;ILDB TO AC3 USING BYTE POINTER CBL I-O AREA
	CAME	3,4		;SKIP - IF CHAR = SPACE
	MOVE	10,POINT3	;SAVE BYTE POINTER IF NOT = SPACE
	SOJN	2,OTA		;DECREMENT CHARACTER COUNTER
				;IF NOT = 0  LOOP TO OTA:

	ILDB	3,POINT3	;MOVE CARRIAGE POSITION CHARACTER
				;FROM POS75 TO AC3


;	MOVE FROM COBOL I-O AREA TO TTY OUTPUT RING / TP BUFFER

OTB:	CAMN	10,11		;SKIP - IF WE HAVE NOT MOVED LAST CHAR FROM THIS LINE
	JRST	NXTLIN		;GO GET NEXT LINE
	ILDB	2,11		;GET NEXT BYTE FROM COBOL I-O AREA
	JSR	ADDCHR		;GO PUT CHAR IN TTY/TP BUFFER
	JRST	OTB		;LOOP

NXTLIN:	CAIN	3,40		;SKIP IF CTL CHAR NOT = SPACE	
	JRST	CRLFD		;GO TYPE <CR><LF>
	CAIN	3,116		;SKIP IF CTL CHAR NOT = 'N'
	JRST	NXTLNE		;GIVE NO CTL CHARACTERS
	CAIN	3,103		;SKIP IF CTL CHAR NOT = 'C'
	JRST	CR		;GO TYPE  <CR>
	OUTSTR	[ASCIZ/
% TP HAS UNRECOGNIZABLE CHARACTER  (/]
	OUTCHR	3		;PLACE HIS CHAR HERE
	OUTSTR	[ASCIZ/)   IN POS.75 
FOR RETURN MESSAGE LINE CONTROL WILL GIVE USR <CR><LF>
/]
	JRST	CRLFD		;GO TYPE  <CR><LF>


CRLFD:	HRRZI	2,15		;MOVE <CR> (OCTAL 15) 
	JSR	ADDCHR		;GO ADD <CR>
	HRRZI	2,12		;MOVE <LF> (OCTAL 12)
	JSR	ADDCHR		;GO ADD <LF>
	JRST	NXTLNE		;GO GET NEXT LINE FROM COBOL


CR:	HRRZI	2,15		;MOVE <CR> (OCTAL 15) TO AC2
	JSR	ADDCHR		;GO ADD <CR>
	JRST	NXTLNE		;GO GET NEXT LINE FROM COBOL

NXTLNE:	SOSN	6		;DECREMENT LINE COUNTER/
				;SKIP - IF NOT DONE
	JRST	OTD		;DONE  GO WRAP-UP
	MOVE	10,POINT3	;INITIALIZE
	MOVE	11,POINT3	;	POINTERS
	HRRZI	2,^D74		;	  AND BYTE COUNTER
	JRST	OTA		;GO LOOK FOR RIGHT MOST NON-SPACE


;	ADD CHARACTER TO OUTPUT RING BUFFER OR TP BUFFER

ADDCHR:	0			;STORE RETURN HERE
	AOS	CHROUT		;ADD 1 TO # CHARACTERS TYPED OUT
	JUMPE	16,TPBUF	;JUMP TO FILL TP BUFFER WHEN RING BUFFER FULL
	IDPB	2,OBUF+1	;DEPOSIT BYTE IN TTY RING BUFFER
	SOSE	OBUF+2		;DECREMENT RING BUFFER BYTE COUNTER
				;SKIP - WHEN   ZERO
	JRST	@ADDCHR		;RETURN
	SETZ	16,		;SET AC16 TO ZERO
				;THIS SAYS THAT TTY RING BUFFER FULL
	JRST	@ADDCHR		;RETURN

TPBUF:	JUMPE	15,@ADDCHR	;RETURN IF TP BUFFER FULL
	IDPB	2,13		;DEPOSIT BYTE IN TP BUFFER
	AOS	14		;ADD 1 TO TP BYTE COUNTER
	MOVEM	14,TTYTBL+5(5)	;MOVE BYTE COUNT TO TTYTBL
	CAIE	14,TBUFSZ	;SKIP - IF BUFFER FULL - - - - - 
	JRST	@ADDCHR		;RETURN
	SETZ	15,		;SET AC15 TO ZERO
	OUTSTR	[ASCIZ/TP MESS.TRUNCATED
/]
	JRST	@ADDCHR		;RETURN



OTD:	SETZ	2,		;ZERO (NULL) AC2
	MOVE	1,OBUF+1	;MOVE BYTE POINTER TO AC1
	IDPB	2,1		;PLACE 4 ASCII
	IDPB	2,1		;NULLS AT
	IDPB	2,1		;END OF
	IDPB	2,1		;BUFFER (TTY RING BUFFER)

	OUT	14,		;OUTPUT THE LINE
	JRST	.+2		;JUMP OVER ERROR
	JRST	ERR4		;OUTPUT FAILED/ COMPLAIN!
	SKIPN	UNSLAV		;SKIP - IF WE WANT TO UNSLAVE TTY
	JRST	OUTTYA		;LEAVE HIM SLAVED -


;
;	RESET HIS PAGE TO 63  =  (.SET TTY PAGE 63)
;

	MOVE	1,TTYTBL+2(5)	;MOVE PHYSICAL TTY#+200000 TO AC1
	MOVEM	1,SETPG1	;MOVE AC1 TO SET PAGE LIST
	MOVE	2,[XWD 3,SETPAG] ;SET AC2 FOR CALLI (TRMOP.)
	CALLI	2,116		;SET HIS PAGE COUNT TO 63
	OUTSTR [ASCIZ/
NOTE: CALLI FAILED IN PAGE RESET OF UNSLAVE
/]

;	UNSLAVE USERS TTY HERE - - - - - - - - - - 

	SETZM	UNSLAV		;CLEAR UNSLAVE SWITCH
	MOVE	1,[XWD 3,DESLAV];SET UP FOR UNSLAVE
	CALLI	1,116		;TRY THE -UNSLAVE-
	JRST	.+2		;UNSLAVE FAILED
	JRST	.+1		;UNSLAVE WORKED


;	THIS SECOND 'UNSLAVE' ROUTINE WITH THE ^C IS TO FAKE OUT MONITOR BUG
;	WHEN THE BUG IS FIXED THIS ROUTINE WILL STILL WORK - -

	CLOSE	14,0		;CLOSE TO FAKE OUT UNSLAVE BUG
	HRRZI	1,3		;MOVE <^C> (OCTAL 003) TO AC1
	IDPB	1,OBUF+1	;MOVE <^C> TO OUTPUT BUFFER
	SOS	OBUF+2		;DECREMENT BYTE COUNTER
	OUT	14,		;WRITE THE <^C>
	JRST	.+2		;WRITE OK
	JRST	.+1		;WRITE FAILED
	MOVE	1,[XWD 3,DESLAV];TRY THE UNSLAVE AGAIN
	CALLI	1,116		;-UNSLAVE-
	JRST	.+2		;UNSLAVE (SECOND TIME FOR MONITOR GLITCH!!) -FAILED-
	JRST	.+1		;SECOND UNSLAVE -OK-
OUTTYA:	RELEAS	14,		;BREAK CHANNEL/DEVICE BOND

;	SPACE OUT COBOL I-O AREA FOR NEXT MESSAGE FROM TTY (1 RECORD ONLY)

OUTTYB:	MOVE	1,POINT4	;SET UP COBOL AREA
	MOVEM	1,POINT3	;BYTE POINTER
	MOVEI	1,40		;MAKE AC1  ASCII SPACE (040)
	MOVEI	2,^D75		;SET COUNTER TO ^D75
OTZ:	IDPB	1,POINT3	;DEPOSIT SPACE
	SOJN	2,OTZ		;LOOP 'TIL ALL 75 CHAR SPACES

	JRST	@OUTTTY		;RETURN

OPNTTY:	1			;ASCII LINE  MODE FOR TTY
	SIXBIT /      /		;DEVICE TO BE OPENED
	XWD OBUF,IBUF		;ESTABLISH ADDRESSES FOR BUFFER HEADERS

OBUF:	BLOCK 3		;SPACE FOR OUTPUT BUFFER HEADER
IBUF:	BLOCK 3		;SPACE FOR INPUT  BUFFER HEADER

SAOBUF:	BLOCK 3		;SAVE AREA FOR OBUF HEADER
SAIBUF:	BLOCK 3		;SAVE AREA FOR IBUF HEADER

PAGE

;
;	ROUTINES TO CONVERT & TYPE ON TTY
;		 OF CONTROLLING JOB AN OCTAL NUMBER EITHER IN
;		 OCTAL OR DECIMAL (STRIPPING LEADING ZEROES)
;
;	THE OCTAL NUMBER MUST BE IN AC11
;
;	TO CALL:    PUSHJ  17,DECPNT   ;FOR DECIMAL CONVERT/TYPE
;		    PUSHJ  17,OCTPNT   ;FOR OCTAL TYPE
;



DECPNT:	MOVE	1,POINT2	;SET UP
	MOVEM	1,POINT1	;BYTE POINTER
	MOVE	1,SPACES	;MOVE SIXBIT SPACES TO
	MOVEM	1,OCTHLD	;WORD 1 OF OCTHLD
	IDIVI	11,12		;12 OCTAL = 10 DECIMAL
	PUSH	17,12		;SAVE REMAINDER
	SKIPE	11		;ALL DIGITS FORMED?
	PUSHJ	17,DECPNT	;NO- COMPUTE NEXT ONE
DECPN1:	POP	17,11		;YES-TAKE OUT IN OPPOSITE ORDER
	ADDI	11,20		;CONVERT TO SIXBIT
	IDPB	11,POINT1	;HOLD SIXBIT BYTE IN OCTHLD
	ADDI	11,40		;CONVERT FROM SIXBIT TO ASCII
	SKIPN	NOTYPE		;SKP - 'NO-TYPE'  SWITCH SET
	OUTCHR	11		;TYPE OUT CHARACTER
	POPJ	17,		;JUMP TO DECPN1 OR RETURN

OCTPNT:	MOVE	1,POINT2	;SET UP
	MOVEM	1,POINT1	;BYTE POINTER
	MOVE	1,SPACES	;MOVE SIXBIT SPACES TO
	MOVEM	1,OCTHLD	;WORD 1 OF OCTHLD
	IDIVI	11,10		;10 OCTAL = 10 OCTAL
	PUSH	17,12		;SAVE REMAINDER
	SKIPE	11		;ALL DIGITS FORMED
	PUSHJ	17,OCTPNT+4	;NO- COMPUTE NEXT ONE
OCTPN1:	POP	17,11		;YES-TAKE OUT IN OPPOSITE ORDER
	ADDI	11,20		;CONVERT TO SIXBIT
	IDPB	11,POINT1	;HOLD SIXBIT BYTE IN OCTHLD
	ADDI	11,40		;CONVERT TO ASCII
	SKIPN	NOTYPE		;SKIP - IF 'NO-TYPE' SWITCH SET
	OUTCHR	11		;TYPE OUT CHARACTER
	POPJ	17,		;JUMP TO OCTPN1 OR RETURN
PAGE
;
;	CHANGE THE PROGRAM NAME FOR SYSTAT  ETC.
;
;	TO REFLECT THE NUMBER OF SLAVES IN (RH)
;
;

NAMCHG:	0			;SAVE RETURN PC
	MOVE	11,TTYS		;MOVE # OF SLAVES TTYS TO AC11
	SETOM	NOTYPE		;SET NO TYPE SWITCH (WHILE CONVERTING)
	PUSHJ	17,DECPNT	;GO CONVERT TO DECIMAL
	HLRZ	1,OCTHLD	;MOVE SIXBIT # SLAVES
	HRRM	1,JOBNAM	;TO (RH) OF  JOB NAME
	MOVE	1,JOBNAM	;MOVE JOBNAM TO AC1
	CALLI	1,43		;GO CHANGE PROGRAM NAME
	SETZM	NOTYPE		;CLEAR  'NOTYPE'  SWITCH
	JRST	@NAMCHG		;RETURN

PAGE

;
;	ROUTINE TO TYPE ON MASTER TTY T/P VOLUME STATUS
;

STATUS:	0			;SAVE RETURN PC
	OUTSTR	[ASCIZ/#SLV= /]
	MOVE	11,TTYS		;MOVE # TTYS SLAVED TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE ON MASTER TTY
	OUTSTR	[ASCIZ/ ; #TS= /]
	MOVE	11,TSTOT	;MOVE # TRANSACTION SETS TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE ON MASTER TTY
	OUTSTR	[ASCIZ/ ; #CHR-IN= /]
	MOVE	11,CHRIN	;MOVE # CHARACTERS TYPED IN BY ALL TERMINALS
				;(NOT COUNTING MASTER TTY)  TO AC11
	PUSHJ	17,DECPNT	;CONVERT OT DECIMAL & TYPE ON MASTER TTY
	OUTSTR	[ASCIZ/ ; #CHR-OUT= /]
	MOVE	11,CHROUT	;MOVE # CHARACTERS TYPED OUT BY ALL TERMINALS
				;(NOT COUNTING MASTER TTY)  TO AC11
	PUSHJ	17,DECPNT	;CONVERT TO DECIMAL & TYPE ON MASTER TTY
	OUTSTR	[ASCIZ/ 
/]
	JRST	@STATUS		;RETURN

PAGE
;
;	ERROR MESSAGES
;

;	ERR1    GETTAB FAILED IN ESTABLISH THE NUMBER OF TTYS ON SYSTEM

ERR1:	OUTSTR	@CRLF		;TYPE <CR><LF>
	OUTSTR	[ASCIZ/? ERR1- GETTAB FAILED/]
	OUTSTR	@CRLF		;TYPE <CR><LF>
	HALT

;	ERR2	CALLI FAILED IN GETTTY ROUTINE (FIND SLAVED TTY)

ERR2:	OUTSTR	[ASCIZ/
? ERR2- CALLI FAILED IN GETTTY:
   OPERATOR: CHECK SYS:ACCT.SYS PRIV. WORD IF 5.06 OR LATER MONITOR
/]
	HALT

ERR3:	OUTSTR	[ASCIZ/
 ?ERR3- OPEN FAILED IN OUTTTY
/]
	JRST	@OUTTTY		;TRY NEXT GUY

ERR4:	OUTSTR	[ASCIZ/
 ERR4- OUTPUT FAILED IN OUTTTY
/]
	JRST 	@OUTTTY		;TRY NEXT GUY

ERR5:	OUTSTR	[ASCIZ/
? ERR5- GETTAB FAILED IN SYSTEM-ID
/]
	HALT

ERR6:	OUTSTR	[ASCIZ /
 ERR6- OPEN FAILED IN  INPUT:
/]
	JRST	NXTTY	;GO LOOK AT NEXT TTY
SAVE17:	BLOCK 1
SAVEAC:	BLOCK 20

TYPPTR:	BLOCK 1			;ADDRESS OF TTY I-O MESSAGE AREA

ENTRPC:	BLOCK 1			;HOLD ENTRY PC+1 (THIS ALSO IS ADDRESS OF NUMBER 
				;OF LINES TO TYPE)
TTYADR:	BLOCK 1			;ADDRESS OF LOGICAL TTY#
GOTOAD: BLOCK 1			;ADDRESS OF 1ST GO TO DEPENDING ON
ALTADD: BLOCK 1			;ADDRESS OF ALTERED GO TO - - (DISPATCHER)
MTCADR:	BLOCK 1		;ADDRESS OF MORE-TO-COME
				;SWITCH (COBOL PROGRAM WANTS T/P
				;        TO RETURN WITHOUT A MESSAGE)
LNSADR:	BLOCK 1			;ADDRESS OF NUMBER OF LINES RETURNED BY COBOL PROGRAM
CNTRLC:	BLOCK 1			;ADDRESS OF ^C DISPATCH IN COBOL PROGRAM
				;(CONTROL-C-DISPATCH)

LINTIM:	BLOCK 1			;TIME LAST LINE WAS TYPED TO USER (JIFFIES)

LSTSLV:	BLOCK 1			;TIME SLAVES LAST CHECKED FOR

HBFAIL:	BLOCK 1			;COUNTER FOR HIBERNATE FAILURES

HLDTIM: BLOCK 1			;TIME 'FIRST' SLAVE FOUND

SYSTTY: BLOCK 1			;TOTAL NUMBER OF TTYS ON SYSTEM (OCTAL)


;
;	TOTALS FOR ALL T/P
;

TSTOT:	XWD 0,0		;TOTAL # OF TRANSACTION SETS
CHRIN:	XWD 0,0		;TOTAL # CHARACTERS TYPED IN BY ALL TERMINALS
			;(NOT COUNTING MASTER TTY)
CHROUT:	XWD 0,0		;TOTAL # CHARACTERS TYPED OUT BY ALL TERMINALS
			;(NOT COUNTING MASTER TTY)
TTYS:	XWD 0,0		;NUMBER OF SLAVE TTYS CONNECTED
				;TO THIS JOB

JOBNAM:	SIXBIT/TGN   /		;NAME OF PROGRAM (RH- GETS # SLAVES)


;**************************************************************

DLYSLP:	XWD 0,454		;DELAY SLEEP UNTIL AFTER (300 JIFFIES)

INITIM: XWD 0,^D108000		;INITIAL TIME FOR 'QUICK' CKECKS FOR
				;SLAVES (30 MINUTES) / TIME DOES
				;NOT START UNTIL AFTER FIRST SLAVE FOUND

SLVCHK: XWD 0,^D180		;CHECK FOR NEW SLAVES EVERY 3 SECONDS
				;(180 JIFFIES)

SLVCK1: XWD 0,^D1800		;THIS IS JAMMED ON SLVCHK: AFTER
				;INITIM: JIFFIES AFTER FIRST SLAVE
				;FOUND

				;OF NO TTY ACTIVITY

MAXTTY=^D5		;MAXIMUM NUMBER OF TTYS FOR T/P

TABSIZ=^D125		;SIZE (IN WORDS) OF EACH ENTRY IN TTYTBL
TFIXSZ=^D7		;SIZE (IN WORDS) OF 'FIXED' TTY STUFF
TBUFSZ=<<TABSIZ - TFIXSZ>* 5>  	;SIZE (IN BYTES) OF TTY BUFFER SPACE

TTYTBL:	BLOCK TABSIZ * MAXTTY		;TTY TABLE
				;WORD 1 LH = LOGICAL TTY# (OCTAL STARTING WITH 2)
				;WORD 1 RH = NUMBER OF TRANSACTION SETS
				;WORD 2    = PHYSICAL TTY NAME (SIXBIT)
				;WORD 3 LH = FLAGS
				;     BIT 0  = DATA PHONE
				;     BIT 1  = NO 'ACCEPT' THIS TIME
				;  BITS 2-17   FREE
				;WORD 3 RH = PHYSICAL TTY # +200000
				;WORD 4    = BEGINNING TIME FOR TTY (JIFFIES)
				;WORD 5    = BYTE POINTER TO THIS TTY BUFFER
				;WORD 6    = BYTES LEFT TO BE TYPED FROM THIS BUFFER
				;WORD 7    = BYTE POINTER TO EXTRACT FROM THIS BUFFER
				;WORDS 8 THRU TABSIZ = TTY OUTPUT BUFFER SPACE


;**************************************************************

PAGE
SYSID:	BLOCK 5			;THIS WILL GET INITIALIZED WITH SYSTEM-ID IN ONCE:

NINE:	XWD 0,11		;DECIMAL NINE
POUND:	XWD 0,43		;ASCII '#'
H:	XWD 0,110		;ASCII 'H'
K:	XWD 0,113		;ASCII 'K'
N:	XWD 0,116		;ASCII 'N'
S:	XWD 0,123		;ASCII 'S'
Y:	XWD 0,131		;ASCII 'Y'


JRSTID:	XWD 0,254020		;LH OF JRST @
JRSTXX: XWD 0,254000		;LH OF JRST


;**************************************************



STOPIT:	ASCII/!STOP/		;THIS TELLS ME THAT TTY IS DONE

ECHON:	ASCII/ECHON/		;THIS TELLS ME USER WANTS HIS
				;ECHO STATUS 'ON'

ECHOFF:	ASCII/ECHOF/		;THIS TELLS ME USER WANTS HIS
				;ECHO STATUS 'OFF' (NO ECHO)

BADPW:  ASCII/BADPW/		;THIS TELLS ME USER BEING FLUSHED
				;DUE TO BAD PASSWORDS - - - - 
				;ACCORDING TO COBOL PROGRAM

TPID:	XWD 0,^D44		;THIS IS THE TP ID (44 DECIMAL
				;THE TERMINAL USER TYPES
				; (.SET TTY PAGE 10 <CR>)
				;THIS FEATURE ALLOWS MULTIPLE
				;TP'S TO BE ON THE SYSTEM @ ONE TIME

;********************************************************

SPACES: SIXBIT/      /		;1 WORD OF SIXBIT SPACES
ZERO:	[ASCII/0/]
SPACE:	[ASCIZ/ /]
COLON:	[ASCII/:/]
CRLF:	[ASCII/
/]
MESS1:	ASCIZ/TTY #/

SIXTTY:	SIXBIT/TTY   /
NOTYPE:	XWD 0,0			;NO-TYPE SWITCH FOR OCTAL CONVERT
				;ROUTINE  OCTPNT:
BADTTY:	BLOCK 1			;SIXBIT NAME OF LAST TTY OPR: WAS REQUSETED TO UNSLAVE
UNSLAV:	XWD 0,0			;UNSLAVE SWITCH / IF = 1, UNSLAVE TTY
TALKED:	XWD 0,0			;HAVE I TALKED TO TTY THIS LOOP
GOTANY:	BLOCK 1			;SWITCH FOR PROSLV: (SLAVES)
GETP:	XWD 0,0			;1 WORD SWITCH
				;(WHEN ONES, IT TELLS OUTTTY:
				; TO FILL RING BUFFER FROM TP BUFFER)

SLEEPCT:	XWD 0,0		;SLEEP COUNTER

FINMES:	ASCIZ/
END    MIKE & NICK
.                                 /



;****
PTYTBL:	POINT 7,TTYTBL		;BYTE POINTER FOR TTYTBL INITIALIZATION
;****

;****
POINT1:	BLOCK 1			;POINTER FOR DEPOSIT BYTE GETS MOVED HERE
POINT2:	POINT 6,OCTHLD		;POINTER FOR DEPOSIT BYTE
OCTHLD:	BLOCK 2			;HOLD SIXBIT EQUIVALENT OF OCTAL NUMBER
SBITTY:	BLOCK 1			;HOLD SIXBIT TTY # (OCTAL) LEFT JUSTIFIED
;****

;****
POINT3:	BLOCK 1			;POINTER FOR TTY I-O AREA (COBOL)
POINT4:	POINT 7,.		;MASTER POINTER HERE (FOR COBOL TTY I-O AREA)
				;RH - OF POINTER JAMMED IN ONCE:
				;WITH ADDRESS OF COBOL MESSAGE AREA
;****

;****
FINPNT:	BLOCK 1			;POINTER TO
FINPT:	POINT 7,FINMES		;FINAL USER MESSAGE
;****

PAGE
;****
SETSLV:	XWD 0,2004	;COMMAND
SETSL1:	XWD 0,0		;   ARGUMENTS FOR
SETSL2: XWD 0,1		;      .SET TTY SLAVE
;****

;****
DESLAV:	XWD 0,2004		;COMMAND
DESLA1: XWD 0,0			;   ARGUMENTS FOR
DESLA2: XWD 0,0			;      .SET TTY NO SLAVE
;****

;****
SETPAG:	XWD 0,2023		;COMMAND
SETPG1:	XWD 0,0			;   ARGUMENTS FOR
SETPG2:	XWD 0,^D63		;     .SET TTY PAGE 63
;****

;****
SETGAG:	XWD 0,2013		;COMMAND
SETGG1:	XWD 0,0			;   ARGUMENTS FOR
SETGG2:	XWD 0,1			;      .SET TTY NO GAG
;****


;****
NOTAB:	XWD 0,1005		;COMMAND
NOTAB1:	XWD 0,0			;  ARGUMENTS FOR
NOTAB2:	XWD 0,0			;    .SET TTY NO TABS
;****

;****
ECHO:	XWD 0,2007		;COMMAND
ECHO1:	XWD 0,0		;  ARGUMENTS FOR  .SET TTY PAGE
ECHO2:	XWD 0,0			;   ECHO2 BIT 35 = 1 FOR NO-ECHO
;****



;****
EMPBF:	XWD 0,2			;COMMAND ARGUMENTS FOR
EMPBF1:	XWD 0,0			; TRMOP (2 = SKIP IF OUTPUT BUFFER NOT EMPTY)
;****

LIT
END