Google
 

Trailing-Edge - PDP-10 Archives - BB-4170G-SM - sources/ttfedv.mac
There are 21 other files named ttfedv.mac in the archive. Click here to see a list.
;<3A.MONITOR>TTFEDV.MAC.9, 12-May-78 16:34:51, EDIT BY MILLER
;FIX IT SOME MORE
;<3A.MONITOR>TTFEDV.MAC.8, 12-May-78 16:28:56, EDIT BY MILLER
;IF LINE ALREADY ON QUEUE AT BIGST2, DON'T TURN IT OFF
;<3A.MONITOR>TTFEDV.MAC.7, 24-Mar-78 14:25:24, EDIT BY MILLER
;ALWAYS USE MSTRDT FOR THE I.D. OF THE MASTER -11
;<3A.MONITOR>TTFEDV.MAC.6,  6-Mar-78 12:28:18, EDIT BY MILLER
;FIX TTDBEF
;<3.SM10-RELEASE-3>TTFEDV.MAC.5, 18-Jan-78 10:26:10, EDIT BY MILLER
;REDEFINE TTFMC TO BE EIGHT BITS
;<3.SM10-RELEASE-3>TTFEDV.MAC.4,  6-Dec-77 02:11:00, Edit by MCLEAN
;<3.SM10-RELEASE-3>TTFEDV.MAC.3,  6-Dec-77 01:33:20, Edit by MCLEAN
;<3.SM10-RELEASE-3>TTFEDV.MAC.2,  6-Dec-77 01:27:08, Edit by MCLEAN
;<3-MONITOR>TTFEDV.MAC.39,  9-Nov-77 09:58:50, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<3-MONITOR>TTFEDV.MAC.38, 12-Oct-77 14:20:09, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>TTFEDV.MAC.37, 22-Sep-77 09:27:49, EDIT BY MILLER
;MAKE CHECK FOR X-ON NEEDED IN SNDXN2 BEFORE DOING STKVAR
;<3-MONITOR>TTFEDV.MAC.36, 15-Sep-77 11:33:32, EDIT BY MILLER
;CHANGE TTVT12 OFFSET TO SET PARITY
;<3-MONITOR>TTFEDV.MAC.35, 14-Sep-77 16:15:08, EDIT BY MILLER
;CHANGE CALL DYNSTA TO DYNST
;<3-MONITOR>TTFEDV.MAC.34, 23-Aug-77 08:20:32, EDIT BY MILLER
;FIX TTYINT CODE
;<3-MONITOR>TTFEDV.MAC.34, 22-Aug-77 13:05:42, EDIT BY MILLER
;FIX TTYINT TO CORRECTLY RESTORE TTOOUT IF DTEQ FAILS
;<3-MONITOR>TTFEDV.MAC.33, 19-Aug-77 14:08:39, Edit by MCLEAN
;MOVE RESCD AT TTXON1 BACK UP ONE INSTRUCTION
;<3-MONITOR>TTFEDV.MAC.32, 11-Aug-77 15:22:33, EDIT BY MILLER
;MAKE TTMSAL RETURN PROPER CODE IN B
;<3-MONITOR>TTFEDV.MAC.31, 30-Jul-77 01:48:51, EDIT BY CROSSLAND
;REUSE TTVT11 FOR DEASIGNING DYNAMIC DATA
;<3-MONITOR>TTFEDV.MAC.30, 20-Jul-77 08:05:32, EDIT BY MILLER
;SUPPRESS SYSTEM MESSAGES ON PSEUDO-CTY'S
;<3-MONITOR>TTFEDV.MAC.29, 19-Jul-77 13:48:01, EDIT BY MILLER
;<3-MONITOR>TTFEDV.MAC.28, 19-Jul-77 11:31:10, EDIT BY MILLER
;<3-MONITOR>TTFEDV.MAC.27, 19-Jul-77 10:38:46, EDIT BY MILLER
;<3-MONITOR>TTFEDV.MAC.26, 19-Jul-77 10:34:00, EDIT BY MILLER
;ADD ROUTINE TO INITIALIZE PSEUDO-CTY'S
;<3-MONITOR>TTFEDV.MAC.25, 15-Jul-77 10:03:17, EDIT BY MILLER
;ADD CODE TO BIAS T/S LINE NUMBERS AROUND THE DL11W'S AND DL11E
;<3-MONITOR>TTFEDV.MAC.24, 29-Jun-77 08:21:01, EDIT BY MILLER
;DON'T DETACH JOBS ON FE RELOAD UNLESS IT IS THE MASTER -11
;<3-MONITOR>TTFEDV.MAC.23, 27-Jun-77 10:07:26, EDIT BY MILLER
;MORE TCO 1831. REMEMBER NEW SPEED FOR AUTO LINES
;<3-MONITOR>TTFEDV.MAC.22, 25-Jun-77 10:22:57, EDIT BY MILLER
;MAKE TTSBEF CHECK FOR LINE ACTIVE AS WELL AS CHARACTERS PRESENT
;<3-MONITOR>TTFEDV.MAC.21, 24-Jun-77 11:58:52, EDIT BY MILLER
;SET AUTO IF FE SAYS IT IS
;<3-MONITOR>TTFEDV.MAC.20, 24-Jun-77 11:13:15, EDIT BY MILLER
;TCO 1831. ADD CODE FOR "AUTO" SPEED
;<3-MONITOR>TTFEDV.MAC.19, 16-Jun-77 21:09:05, EDIT BY CROSSLAND
;CHANGE TTVT08 TO R SO IT WILL FALL INTO STPAR4 INSTEAD OF CALLING IT
;<3-MONITOR>TTFEDV.MAC.18,  9-Jun-77 04:32:31, EDIT BY CROSSLAND
;CHANGE TTVT12 AND TTVT19 TO FNXCT
;<3-MONITOR>TTFEDV.MAC.17,  7-Jun-77 17:17:25, EDIT BY HALL
;TCO 1740 - ADD TTVT38
;<3-MONITOR>TTFEDV.MAC.16, 14-May-77 19:27:49, EDIT BY CROSSLAND
;<3-MONITOR>TTFEDV.MAC.15, 12-May-77 00:46:25, Edit by MCLEAN
;CHANGE SO DUMMY MODULES NO LONGER NECESSARY
;<3-MONITOR>TTFEDV.MAC.14, 11-May-77 12:34:10, EDIT BY HALL
;MOVED SNDFNC AND TTDTRM HERE FROM TTYSRV
;<3-MONITOR>TTFEDV.MAC.13,  6-May-77 12:32:45, EDIT BY HALL
;TCO 1740 - VECTOR CHANGES FOR TTMSG JSYS
;<3-MONITOR>TTFEDV.MAC.12,  4-May-77 16:49:37, EDIT BY MILLER
;more edits to make ttspwd swappable
;<3-MONITOR>TTFEDV.MAC.11,  4-May-77 14:25:22, EDIT BY MILLER
;TCO 1740. MAKE TTSPWD SWAPPABLE
;<3-MONITOR>TTFEDV.MAC.10,  4-May-77 01:24:16, EDIT BY CROSSLAND
;<3-MONITOR>TTFEDV.MAC.9,  3-May-77 23:44:01, EDIT BY CROSSLAND
;<3-MONITOR>TTFEDV.MAC.8,  3-May-77 10:08:48, EDIT BY CROSSLAND
;TCO 1742 MERGE ARPANET SOURCES
;<3-MONITOR>TTFEDV.MAC.7, 12-Apr-77 14:52:00, EDIT BY HALL
;TCO 1777 - ADD PARITY TO XOFF AND XON WHEN SENDING TO TERMINAL
;<3-MONITOR>TTFEDV.MAC.6, 27-Mar-77 13:56:14, Edit by MCLEAN
;COMMENTS
;<3-MONITOR>TTFEDV.MAC.5, 22-Mar-77 01:17:58, Edit by MCLEAN
;<3-MONITOR>TTFEDV.MAC.4, 22-Mar-77 01:16:34, Edit by MCLEAN
;ADD PRINTX
;<3-MONITOR>TTFEDV.MAC.3, 20-Mar-77 13:40:37, Edit by MCLEAN
;REMOVE END STATEMENT
;<3-MONITOR>TTFEDV.MAC.2, 20-Mar-77 02:49:41, Edit by MCLEAN


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1976, 1977, 1978 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SUBTTL FRONT-END DEPENDENT CODE
;FRONT-END DEPENDENT CODE FOR TTYSRV
;THIS MODULE IS NECESSARY TO SUPPORT THE KL10 -DTE20 INTERFACE
;FOR TTYSRV.  IT DOES ALL THE DEVICE SPECIFIC FUNCTIONS AND
;PROCESSES DATA TO AND FROM THE FRONT END.


;DEFINITIONS FOR TTDEV FOR FE TYPE LINES


;DEFINITIONS FOR TT.FE LINE TYPE
TT%FPK==1B0			;WAITING FOR TO -11 DONE
MSKSTR TTFPK,TTDEV,TT%FPK
TT%FOW==1B1			;LINE ALLOCATION EXCEEDED
MSKSTR TTFOW,TTDEV,TT%FOW
DEFSTR TTFCT,TTDEV,27,8		;NUMBER BYTES IN FRONT END
DEFSTR TTFMC,TTDEV,35,8		;MAX BYTES IN FRONT END
SPCLIN==4			;HIGHEST SPECIAL LINE NUMBER
;
; FRONT-END VECTOR TABLE ENTRYS
;
	RESCD
TTFEVT=.
	TTDDLN			;LENGTH OF DYNAMIC DATA FOR THIS TYPE
	-1			;FIRST LINE OF THIS TYPE/-1 NO LINES
	IFIW!R			;INITALIZATION
	IFIW!R			;RESTART
	IFIW!TTCOB4		;CLEAR OUTPUT BUFFER
	IFIW!TTSSP2		;SET LINE SPEED
	IFIW!TTRSP1		;RETURN LINE SPEED
	IFIW!TTSNT1		;SUPRESS SYS MESSAGES
	IFIW!TTRNT1		;RETURN NON-TERMINAL DEV STATUS
	IFIW!TTSTO3		;STOP ACTIVE LINE
	IFIW!R			;SET TERMINAL CHARACT
	IFIW!RSKP		;PHYSICAL TERMINAL
	IFIW!TTXON1		;TTVT10 -XON
	IFIW!TTYDE0		;DEASIGN DYNAMIC DATA
	TRO 1,200		;APPLY PARITY
	IFIW!STRTO1		;START OUTPUT LINE
	IFIW!SNDXO2		;SEND XOFF
	IFIW!SNDXN2		;SEND XON
	IFIW!TTCQ1		;EMPTY BUFFER
	IFIW!TTCON1		;CARRIER ON
	IFIW!NTYCOF		;CARRIER OFF
	IFIW!TTHU2		;HANGUP
	IFIW!TTCHI3		;TTVT20 - STOP LINE
	IFIW!TTC7S1		;LOCAL/REMOTE CHECK FOR LOGIN
	IFIW!BIGST2		;LINE STORAGE
	IFIW!TTSND1		;SEND CHARACTER
	IFIW!TTDAL6		;DEALLOCATE LINE
	IFIW!DLSSX2
	IFIW!R			;EMPTY BUFFER
	IFIW!RSKP		;TTVT27 - OK TO DO SENDALL FOR A LINE
	IFIW!FEDABL		;DISABLE ENABLE
	IFIW!R
	IFIW!R			;30  CLEAR INPUT BUFFER
	IFIW!TTDBEF		;31  DOBE
	IFIW!R			;32  INPUT GA
	IFIW!TTSETF		;33  SET INIT. VALUES FOR A LINE
	IFIW!TTSBEF		;34  SOBE
	IFIW!TTOBEF		;35  WAKEUP IF OUTPUT BUFFER EMPTY
	IFIW!TTMSSN		;TTVT36 - DO ACTUAL SENDALL FOR A LINE
	IFIW!TTMSAL		;TTVT37 - DO SENDALL FOR ALL LINES
	JFCL			;TTVT38 - ADJUST WAKEUP CLASS

   IFN <.-TTVTMX>-TTFEVT,<PRINTX %%INVALID DEVICE DEPENDENT TABLE SIZE>
; CLEAR OUTPUT BUFFER ROUTINE

TTCOB4:	STKVAR <TTCBSV>
	MOVEM B,TTCBSV		;SAVE ADDRESS OF DYNAMIC DATA
	DYNST			;GET LINE NUMBER
	MOVE D,B		;GET COPY OF LINE NUMBER
	MOVS C,B		;LINE NUMBER
	MOVEI B,.FEDLS		;GET DEVICE CODE
	MOVE A,MSTRDT		;MASTER DTE, NO POST
	CALL FIXARG		;GET PROPER ARGS
	EXCH D,TTCBSV		;GET BACK DYNAMIC DATA
	OPSTR <SKIPE>,TTOTP,(D)	;OUTPUT IN PROGRESS?
	JRST [	EXCH D,TTCBSV	;YES. GET BACK ORIGINAL ARGUMENT
		PUSHJ P,DTEFLO	;YES, FLUSH DTE REQUESTS
		JRST TTCBF5]
	EXCH D,TTCBSV		;GET BACK ORIGINAL ARGUMENT
TTCBF5:	MOVS D,C		;LINE NUMBER AS ARG
	SETZ C,
	HRLI B,.DFFDO		;FLUSH FUNCTION
	CALL DTEQ		;QUEUE IT UP
	 JFCL			;DOESN'T MATTER
	MOVE B,TTCBSV		;GET BACK DYNAMIC DATA
	JRST TTCOB5
	SWAPCD

; SET TERMINAL SPEED

TTSSP2:	SKIPN FEFLG		;IN PRIMARY PROTOCOL?
	RET			;NO. IGNORE IT THEN
	ACVAR <W1>		;GET A WORK REG
	UMOVE W1,2		;GET FLAGS
	TXNE W1,MO%AUT		;DECLARING AUTO SPEED?
	JRST [	TXNE W1,MO%RMT	;YES. ALSO WANT REMOTE?
		JRST .+1	;YES. PROCEED THEN
		RET]		;NO. ILLEGAL REQUEST
	NOINT			;PREVENT INTS
	CALL ASGALL		;ASSIGN THE BUFFER
	MOVE C,[POINT ^D16,SNDALL]
	UMOVE D,C		;GET USER'S ARGS
	HLRZ A,D		;GET INPUT SPEED
	JN TTAUT,(B),TTSSP4	;IF NOW AUTO, SET THE SPEED
	OPSTR <SKIPN>,TTFEM,(B)	;ALREADY REMOTE?
TTSSP4:	TXNE W1,MO%AUT		;NO. DECLARING AUTO?
	SKIPA			;DON'T SET SPEED
	MOVEM D,TTSPWD(B)	;SET THE NEW SPEED
TTSSP1:	IDPB A,C		;STORE INPUT
	IDPB D,C		;STORE OUTPUT SPEED
	MOVEI D,0(D)
	MOVEI A,1		;ASSUME ONE STOP BIT
	CAIG D,^D110		;LESS THAN OR EQUAL TO 110 BAUD?
	MOVEI A,2		;YES. USE 2 STOP BITS THEN
	TXNE W1,MO%RMT		;WANT REMOTE?
	JRST [	MOVX D,SC%OPR!SC%WHL ;YES. SEE IF PRIVILEGED
		TDNN D,CAPENB	;IS IT?
		JRST TTSSP3	;NO. ERROR
		TRO A,(1B2)	;SET HIGH ORDER BIT
		LOAD D,TTFEM,(B)
		SETONE TTFEM,(B) ;SAY IS REMOTE
		TXNE W1,MO%AUT	;WANT "AUTO" SPEED?
		JRST [	SETONE TTAUT,(B) ;SET INDICATOR
			TRO A,(1B3) ;SET BIT IN MESSAGE TO FE
			JRST TTSSP5] ;AND PROCEED
		JUMPE D,.+1	;IF NOT NOW REMOTE, DECLARE SPEED
		UMOVE D,C	;YES. GET DEFAULT DECLARATION
		MOVEM D,TTSPWD(B) ;TO THE TABLE
		JRST .+1]	;GO SET SPEED ANYWAY
TTSSP5:	IDPB A,C		;STORE THIS
	MOVSI C,0(B)		;LINE TO LH OF C
	MOVE A,B		;SAVE LINE
	MOVE B,[.DFSPD,,.FEDLS]	;ARGS
	CALL FIXARG		;GO FIX THINGS UP
	MOVE D,[POINT ^D8,SNDALL]
	MOVSI A,INTALL		;ARRANGE TO FREE BUFFER
	HRR A,MSTRDT		;MASTER DTE
	HRRI C,6		;SIX BYTES OF ARG
	CALL DTEQ		;GO DO THE REQUEST
	 JFCL			;WILL GO
TTSSP6:	OKINT			;ALLOW INTS AGAIN
	RET			;AND DONE

;NONPRIVILEGED USER TRIED TO SET REMOTE

TTSSP3:	CALL INTALL		;FREE SEND ALL BUFFER
	JRST TTSSP6		;AND WRAP UP
TTSNT1:	SKIPN FEFLG		;IN PRIMARY PROTOCOL?

; SET/RETURN DEVICE NON-TERMINAL STATUS

	RET			;NO. IGNORE IT THEN
	STOR C,TTNTS,(B)	;SAVE NEW VALUE
	MOVE D,C		;GET VALUE TO BE SET
	MOVSI C,0(B)		;GET TTY # TO CHANGE
	MOVE B,[.DFMSG,,.FEDLS] ;ARGS (FCN,,DEVICE)
	CALL FIXARG		;FIX UP ARGS
	MOVE A,MSTRDT		;MASTER DTE
	CALL DTEQ		;DO THE REQUEST
	 JFCL			;WILL GO
	RET			;AND DONE
;TTMSG...

;CODE TO DO A SEND ALL FOR KL DTE20 CONFIGURATIONS

;TTMSSN FOR SINGLE LINE, TTMSAL FOR ALL LINES

TTMSSN:	SKIPA
TTMSAL:	SETOM B
	SAVET
	STKVAR <TTMSSV>
	MOVEM B,TTMSSV
	SKIPN FEFLG		;USING PRIMARY PROTOCOL?
	JRST [	JUMPGE B,2
		RETSKP]
	HRLI B,.DFSTA		;ASSUME SEND ALL
	SKIPL TTMSSV
	HRLI B,.DFHSD		;NO. STRING DATA THEN
	MOVSI A,DECSAL		;INTERRUPT LOCATION
	HRR A,MSTRDT
	HRL C,B			;THE LINE IF RELEVANT
	HRRI B,.FEDLS		;THE LINE SCANNER
	CALL FIXARG		;GO CHECK FOR CTY,ETC.
	HRR C,TTMSCT		;THE COUNT
	MOVE D,[POINT 8,SNDALL]	;THE POINTER
	TXO C,DTBYTM		;FORCE BYTE MODE SEND
	AOS SALCNT		;INCREMENT SENDALL COUNT
	CALL DTEQ		;GO SCHEDULE THE REQUEST
	 JFCL
	SKIPL B,TTMSSV
	RET
	RETSKP

	RESCD
DECSAL:	SOS SALCNT
	RET
	RESCD
; XON CODE
TTXON1:	SKIPN FEFLG		;IN PRIMARY PROTOCOL?

	JRST TTXON2		;NO .SKIP THE MESSAGE THEN
	MOVEI A,.DFXON		;FE XON FUNCTION
	PUSH P,B		;SAVE ADDRESS OF DYNAMIC DATA
	DYNST			;GET LINE NUMBER
	CALL SNDFNC		;TELL FE TO RESTART
	 JRST [	MOVEI A,DLSRCF+PGMONC
		HRLI A,0(B)	;MUST FORCE THIS AGAIN SOME TIME
		POP P,C		;CLEAN UP THE STACK
		CALLRET BIGSTO]	;LET SCHEDULER FIX THIS UP
	POP P,B			;RESTORE ADDRESS OF DYNAMIC DATA

	JRST TTXON2		;ENTER COMMON CODE

;ROUTINE TO SEND XOFF OR XON TO THE FRONT END
;ACCEPTS: A/ FUNCTION TO SEND
;	  B/ LINE NUMBER
;RETURNS:	+1 /COULD NOT SEND REQUEST
;		+2/ REQUEST SENT

SNDFNC:
	PUSH P,B		;SAVE LINE NUMBER
	MOVSI C,0(B)		;PUT LINE NUMBER IN CORRECT PLACE
	MOVSI B,0(A)		;FUNCTION CODE
	HRRI B,.FEDLS		;ASSUME DLS
	CALL FIXARG		;GO FIX UP THE ARGS
	HLRZ D,C		;LINE NUMBER AS DATUM
	SETZM C			;DIRECT
	MOVE A,MSTRDT		;TO THE MASTER -11
	CALL DTEQ		;QUEUE IT UP
	 JRST [	POP P,B		;RESTORE UNIT
		RET]		;GIVE BAD RETURN
	POP P,B			;RESTORE LINE
	RETSKP			;GIVE GOOD RETURN
;LINE IS ON RSX20F FRONT END

SNDXO2:	JN TTFXO,(B),R		;IF ALREADY HAVE ONE, JUST RETURN
	CONSZ PI,1B<^D20+DLSCHN> ;AT DTE PI LEVEL?
	JRST SNDXO1		;YES. GO TO IT
	NOSKD1			;PREVENT SCHEDULER INTERRUPTS
	CHNOFF DLSCHN		;AND DTE INTERRUPTS
SNDXO1:	SETONE TTFXO,(B)	;SAY X-ON NEEDED AT SOME TIME
	MOVEI D,XOFFC		;THE CHARACTER
	SKIPGE CHITAB(D)	;PARITY NEEDED?
	TXO D,200		;YES. APPLY IT
	MOVE A,MSTRDT		;SEND TO THE MASTER
	MOVSI C,0(B)		;LINE NUMBER
	MOVE B,[.DFHLC,,.FEDLS]
	CALL FIXARG		;FIX UP THE ARGS
	CALL DTEQ		;GO SEND IT
	 JFCL			;WE WILL GET IT THE NEXT TIME
	CONSZ PI,1B<^D20+DLSCHN> ;AT DTE PI LEVEL?
	RET			;YES. ALL DONE THEN
	CHNON DLSCHN		;RESTORE THE CHANNEL
	OKSKD1			;AND THE SCHEDULER
	RET			;AND DONE
;LINE IS ON RSX20F FRONT END. SEND XON ONLY IF LINE IS MARKED AS NEEDING
;ONE, AND IT HAS NOT STORED TOO MANY CHARACTERS IN EITHER ITS
;INPUT BUFFER OR TTBBUF

SNDXN2:	JE TTFXO,(B),R		;IF NOT WAITING, RETURN
	STKVAR <SNDXSV>
	MOVEM B,SNDXSV		;SAVE THE LINE NUMBER
	NOSKD1			;PREVENT SCHEDULER INTERRUPTION
	CHNOFF DLSCHN		;AND DTE INTERRUPTS
	CALL STADYN		;GET ADDRESS OF DYNAMIC DATA
	 JRST SNDXN3		;NOT ACTIVE. INPUT BUFFER CAN'T OVERFLOW
	LOAD A,TIMAX,(B)	;GET CAPACITY OF INPUT BUFFERS
	SUBI A,MINICT		;DOWN COUNT ARBITRARY AMOUNT
	CAMGE A,TTICT(B)	;IS INPUT BUFFER THIS FULL?
	JRST SNDXN1		;YES. DON'T SEND XON
SNDXN3:	MOVE B,SNDXSV		;GET LINE NUMBER
	LOAD A,TTFBB,(B)	;GET NUMBER OF WORDS USED IN TTBBUF
	CAIL A,MXBBC1		;MORE THAN ALLOWED FOR ONE TERMINAL?
	JRST SNDXN1		;YES. DON'T SEND XON

;XON IS TO BE SENT. TELL DTE SERVICE

	MOVE A,MSTRDT		;TO THE MASTER
	MOVEI D,XONC		;THE CHARACTER
	SKIPGE CHITAB(D)	;PARITY NEEDED?
	TXO D,200		;YES. APPLY IT
	MOVSI C,0(B)
	MOVE B,[.DFHLC,,.FEDLS]
	CALL FIXARG
	CALL DTEQ		;GO SEND THE BYTE
	 JRST SNDXN1		;AND GIVE UP
	MOVE B,SNDXSV		;GET LINE NUMBER
	SETZRO TTFXO,(B)	;NO X-ON NEEDED NOW
SNDXN1:	MOVE B,SNDXSV		;RESTORE LINE NUMBER
	CHNON DLSCHN		;RESTORE DTE
	OKSKD1			;AND THE SHCEDULER
	RET			;AND DONE
;THIS IS A FRONT END LINE

TTHU2:	SAVET			;SAVE TEMPS
	MOVE A,MSTRDT		;MASTER -11, NO INT
	MOVS C,B
	PUSH P,B		;SAVE LINE NUMBER
	MOVE B,[.DFLHU,,.FEDLS]	;HANG UP THIS LINE
	CALL FIXARG
	HLRZ D,C
	SETZ C,
	CALL DTEQ		;REQUEST THE HANGUP
	 JRST [	POP P,B		;LINE NUMBER
		MOVEI A,0(B)	;TO A AS WELL
		HRLI A,DLSCXF	;HANGUP
		SETONE TTCON,(B) ;SET CARRIER ON TO FORCE HANGUP
		CALLRET BIGSTO]	;GO SCHEDULE THIS AGAIN
	POP P,B			;RESTORE LINE NUMBER
	RET			;AND DONE
;FRONT END LINE. TELL FRONT END TO STOP SENDING TO TERMINAL

TTCHI3:	DYNST			;RESTORE LINE NUMBER
	MOVEI A,.DFXOF		;TELL FE TO STOP
	SKIPE FEFLG		;IN PRIMARY PROTOCOL?
	CALL SNDFNC		;DO IT
	 JFCL			;IF FAILED, DON'T TELL HIM
	RET
;LINE IS ON THE RSX20F FRONT END. LIMIT ITS STORAGE IN TTBBUF

BIGST2:	LOAD C,TTFBB,(B)	;GET COUNT OF CHARACTERS IN TTBBUF
	AOS C			;INCREASE IT
	CAIL C,MAXABC		;BEYOND BAD GUY CUTOFF?
	JRST [	JN TTIME,(B),R ;IF LINE ALREADY QUEUED, GO ON
		PUSH P,A	;SAVE DATUM
		PUSH P,B	;SAVE LINE NUMBER
		MOVSI C,0(B)	;THE LINE
		MOVE B,[.DFTOL,,.FEDLS]
		MOVE A,MSTRDT	;TO THE MASTER
		MOVEI D,.DFTLO	;TURN IT OFF
		CALL FIXARG
		CALL DTEQ	;OUTPUT IT
		 JRST [	POP P,B	;CLEAN UP THE STACK
			POP P,A	;CLEAN IT UP ALL THE WAY
			RET]	;AND GIVE UP NOW
		POP P,B		;RESTORE LINE NUMBER
		POP P,C		;THE DATUM
		MOVEI A,^D5000	;WHEN TO RESTORE LINE
		TXNE C,DLSRCF	;A RECEIVE?
		TRNE C,177	;YES. WAS IT A NULL?
		SKIPA		;NO
		MOVEI A,^D60000	;YES. MAKE IT WAIT A LONG TIME THEN
		MOVE C,[TTTOBL]	;C/THE ROUTINE TO CALL
		CALLRET TTQAD]	;GO Q IT UP AND LOSE DATUM
	STOR C,TTFBB,(B)	;UPDATE COUNT OF CHARACTERS IN TTBBUF
	CAIL C,MAXBBC		;BEYOND MAX COUNT?
	CALL SNDXOF		;YES. SEND X-OFF TO TERMINAL
	JRST BIGST1

;LINE IS ON RSX20F  STORE THE CHARACTER IN TTBBUF
;THIS CODE IS USED TO START UP A LINE TRANSFER VIA THE DTE20.

TTSND1:	SKIPN FEFLG		;USING PRIMARY PROTOCOL?
	JRST [	MOVEI A,0(C)	;NO
		PUSH P,B	;SAVE ADDRESS OF DYNAMIC DATA
		DYNST		;GET LINE NUMBER
		CALL DTECHO	;OUTPUT VIA SECONDARY
		 JRST [	POP P,B
			RET]
		POP P,B
		SETONE TTOTP,(B) ;INDICATE LINE IS ACTIVE
		RET]		;AND DONE
	MOVEI D,0(C)		;THE CHARACTER
	SETONE TTFPK,(B)	;SAY WAITING FOR TO -11 DONE
	SETONE TTOTP,(B)	;SAY LINE IS ACTIVE
	INCR TTFCT,(B)		;INCREASE COUNT OF BYTES IN -11
	PUSH P,B		;SAVE ADDRESS OF DYNAMIC DATA
	DYNST			;GET LINE NUMBER
	MOVSI C,0(B)		;LINE NUMBER
	MOVE B,[.DFHLC,,.FEDLS]	;ARGS
	CALL FIXARG		;GET PROPER ARGS
	PUSH P,F
	SETZ F,			;JUST IN CASE
	CALL DTSNGL		;GO DO A SINGLE REQUEST
	 JRST [	POP P,F		;FAILED. RESTORE FLAGS
		POP P,B		;RESTORE ADDRESS OF DYNAMIC DATA
		DECR TTFCT,(B)	;DECREMENT BYTES IN -11
		MOVE C,OBFFR	;GET ORIGINAL BUFFER POINTER
		MOVEM C,TTOOUT(B) ;RESTORE IT
		AOS TTOCT(B) 	;UP COUNT
		JRST INTRST]	;GO SCHEDULE RETRY
	POP P,F			;RESTORE FLAGS
	POP P,B			;ADDRESS OF DYNAMIC BLOCK
	RET			;AND DONE
;TTTOBL - ROUTINE CALLED FROM SCHEDULER TO TURN ON LINE AGAIN

;ACCEPTS:
;	T2/ INTERNAL LINE NUMBER

TTTOBL:	MOVE A,MSTRDT		;TO THE MASTER
	PUSH P,B		;SAVE LINE NUMBER
	MOVSI C,0(B)
	MOVE B,[.DFTOL,,.FEDLS]
	MOVEI D,.DFTOO		;TURN IT ON
	CALL FIXARG		;FIX UP ARGS
	CALL DTEQ		;QUEUE IT
	 JRST [	POP P,B
		MOVE C,[TTTOBL] ;MUST TRY AGAIN
		CALLRET TTQAD1]	;ARRANGE FOR IT
	POP P,B			;RESTORE LINE NUMBER
	CALLRET SNDXON		;ASSUME AN X-ON IS NEEDED

; ENABLE/DISABLE TTY'S

FEDABL:	SETZ C,0		;SET LINE # (ALL)
	MOVE A,MSTRDT		;GET ID OF MASTER
	MOVE B,[.DFEDR,,.FEDH1]	;ENABLE/DISABLE DATASETS
	CALL DTEQ
	JFCL
	RET

	SUBTTL FRONT-END TERMINAL HANDLING
	RESCD			;MUST BE RESIDENT

;THIS ROUTINE IS CALLED FROM THE DTE20 INTERRUPT ROUITNE TO COMPLETE
;A TTY OUTPUT REQUEST. INPUT IS:
;	A/ UNIQUE CODE (SEE BELOW)
;	B/UNIT NUMBER
;	C/DEVICE CODE

;UNIQUE CODE IS 
;	(0,,COUNT)
;WHERE	COUNT IS THE NUMBER OF CHARACTERS SENT TO THE 11 IN SOME CALL TO
;		DTEQ THAT SPECIFIED TTYINT AS ITS RETURN ADDRESS
;	IF COUNT IS 0, THIS WAS A SINGLE CHARACTER (DTSNGL WAS CALLED)
;		AND BUFFER COUNTS HAVE ALREADY BEEN UPDATED
;	IF COUNT IS NON-ZERO, THIS WAS MULTIPLE CHARACTERS, AND THE BUFFER
;		COUNT MUST BE UPDATED

;AT THIS POINT, THE CHARACTERS HAVE BEEN SENT TO THE 11 BUT NOT ACKNOWLEDGED

TTYINT::PUSH P,A		;SAVE UNIQUE CODE
	MOVE A,C		;MOVE DEVICE TO A
	CALL GETLIN		;GET PROPER CODE
	 JRST [	POP P,A		;RESTORE CODE
		RET]		;AND GIVE UP
	POP P,A			;GET BACK UNIQUE CODE
	CALL STADYN		;GET ADDRESS OF DYNAMIC DATA
	 JRST [	JUMPLE T2,R	;RETURN IF BECOMING ACTIVE OR INACTIVE
		JE TTMES,(T2),R ;RETURN IF NOT A TTEMES BLOCK
		JRST .+1]	;CONTINUE IF TTEMES BLOCK

;MULTIPLE CHARACTERS WERE SENT. UPDATE COUNT OF CHARACTERS IN OUTPUT 
;BUFFER

	JUMPE A,TTYIN1		;HAVE A CODE?
	MOVEI C,0(A)		;NUMBER OF CHARACTERS SENT
	SUB C,TTOCT(B)		;COMPUTE NEW COUNT OF CHARACTERS IN BUFFER
	MOVNM C,TTOCT(B)	;STORE NEW COUNT

TTYIN1:	MOVEI C,0(A)		;GET COUNT AGAIN
	LOAD D,TTFCT,(B)	;FRONT END CHARACTER COUNT
	ADDI D,0(C)		;ADD CHARACTERS JUST SENT
	STOR D,TTFCT,(B)	;NEW COUNT
	SETZRO TTFPK,(B)	;NO TO -11 DONE PENDING
	LOAD C,TTFMC,(B)	;GET LINE'S ALLOCATION
	CAIL D,0(C)		;ROOM FOR MORE?
	JRST [	SETONE TTFOW,(B) ;SAY LINE IS WAITING FOR UNBLOCK
		RET]		;AND GO DISMISS THIS INTERRUPT

;T2/ ADDRESS OF DYNAMIC DATA

TTYIN2:	JN TTSFG,(T2),[SETZRO TTOTP,(T2) ;IF CTRL/S WAS TYPED, CLEAR 
			RET]	; OUTPUT ACTIVE
	SKIPE C,TTOCT(B)	;ANY OUTPUT CHARACTERS?
	JRST TTYIN3		;YES. DO THEM
	SETZRO TTOTP,(T2)	;NO. CLEAR OUTPUT ACTIVE
	CALLRET CLENUP		;CLEAN UP AND RETURN
;TTYINT..

;CHARACTERS ARE IN OUTPUT BUFFER. CALL TTSND IF THERE IS ONLY ONE.
;OTHERWISE CALL DTEQ TO SEND THEM ALL

TTYIN3:	STKVAR <TTYVR1,TTYVR2>	;GET SOME SAVE CELLS
	MOVE C,TTOOUT(B)	;GET POINTER
	HRRZ A,C
	TDNN C,WRPMSK		;NEED TO ADVANCE?
	HRR C,1-TTSIZ(A)	;YES. DO IT
	MOVE A,TTOCT(B)		;GET OUTPUT COUNT
	CALL CNTSET		;GO ADJUST COUNT
	MOVEM C,TTYVR1		;SAVE STARTING BYTE POINTER
	CALL FNDEND		;GO GET CHARACTERS
	MOVE D,TTYVR1		;GET BACK ORIGINAL BYTE POINTER
	TRNN A,777776		;AT LEAST TWO?
	CALLRET TTSND		;NO. GO DO SINGLE CHARACTER
	MOVEM C,TTOOUT(B)	;NEW OUTPUT POINTER
	SETZ F,			;OUTPUT BUFFER
	HRR F,A			;GET COUNT OF BYTES FOUND
	MOVSI A,TTYINT		;IT'S TTY
	HRR A,MSTRDT		;TO THE MASTER
	SETONE TTFPK,(B)	;WAITING FRO TO -11 DONE
	MOVEM B,TTYVR2		;SAVE ADDRESS OF DYNAMIC DATA
	DYNST			;GET LINE NUMBER
	MOVS C,B		;LINE NUMBER
	HRR C,F			;COUNT
	MOVE B,[.DFHSD,,.FEDLS]	;STRING DATA
	CALL FIXARG		;FIX UP THE ARGS
	CALL DTEQ		;QUEUE THE REQUEST
	 JRST RSCHED		;GO DO RESCHEDULE
	RET			;GO DISMISS THE INTERRUPT

;DTEQ FAILED. RESTORE COUNTS AND ARRANGE FOR SCHEDULER TO RESTART OUTPUT

RSCHED:	MOVE B,TTYVR2		;ADDRSS OF DYNAMIC DATA
	ADDM F,TTOCT(B)		;ADD TO BUFFER COUNT
	MOVE D,TTYVR1		;GET ORIGINAL BYTE POINTER
	MOVEM D,TTOOUT(B)	;RESTORE OUTPUT BYTE POINTER
INTRST:	SETZRO TTFPK,(B)	;NOT WAITING FOR PACKET
	DYNST			;B/ LINE NUMBER
	SETZ A,			;A/ TIME UNTIL EVENT
	MOVE C,[TTSN10]		;START UP AS SINGLE CHARACTER
	CALLRET TTQAD		;GO DO IT
;CNTSET - ROUTINE TO FIGURE OUT MAX COUNT ALLOWED IN STRING DATA FUNCTION
;INPUT:	A/ TTY BUFFER COUNT
;	B/ ADDRESS OF DYNAMIC DATA
;RETURNS +1 ALWAYS WITH: A/-MAX COUNT,,0

CNTSET:	SAVEQ			;GET SOME WORK REGISTERS
	LOAD Q1,TTFMC,(B)	;MAX ALLOCATION
	LOAD Q2,TTFCT,(B)	;CURRENT FRONT END COUNT
	SUBI Q1,0(Q2)		;COUNT ALLOWED TO SEND
	CAILE A,0(Q1)		;CAN DO ALL?
	MOVEI A,0(Q1)		;NO. SET ALLOCATION AS BYTE COUNT
	MOVNI A,0(A)		;FOR AOBJN
	MOVSI A,0(A)		;TO THE LEFT HALF
	RET			;AND DONE

;FNDEND - FIND END OF MESSAGE TO SEND TO TERMINAL

;ACCEPTS:
;	T1/ AOBJN POINTER TO STEP THROUGH OUTPUT BUFFER
;	T3/ POINTER FOR REMOVING CHARACTERS FROM OUTPUT BUFFER

;	CALL FNDEND

;RETURNS +1: ALWAYS,
;		T3/ UPDATED POINTER TO OUTPUT BUFFER

FNDEND:	TDNN C,WRPMSK		;TO THE NEXT?
	RET			;YES. DONE FOR NOW
	ILDB D,C		;GET NEXT BYTE
	TRNE D,TTOESC		;ESCAPE CHARACTER?
	JRST [	ADD C,[^D9B5]	;DECREMENT BYTE POINTER
		TLNE C,(40B5)	;WENT INTO PREVIOUS WORD?
		SUB C,[44B5+1]	;YES. CORRECT IT
		RET]		;AND RETURN
	AOBJN A,FNDEND		;NO. GET MORE
	RET			;ALL EXHAUSTED

;ROUTINE TO SET SPEED OF LINE FROM VALUES SENT BY -11
;ACCEPTS:
;	A/ DEVICE CODE
;	B/ UNIT NUMBER
;	C/ REMOTE INDICATOR
;	D/ INPUT,,OUTPUT

TTSPST::CALL GETLIN		;GET INTERNAL LINE NUMBER
	 RET			;INVALID
ttsps2:	SKIPN A,SPDBLK		;HAVE A BLOCK FOR STORING SPEEDS?
	JRST TTSPER		;NO. ERROR THEN
	JUMPE C,TTSPS1		;IF NOT REMOTE, JUMP OFF
	SETONE TTFEM,(B)	;IS REMOTE
	TRNN C,(1B3)		;IS IT AUTO ALSO?
	JRST TTSPS1		;NO.
	SETONE TTAUT,(B)	;YES. SET INDICATOR
TTSPS1:	MOVE C,TTLINV+TT.FE
	SUB B,TT1LIN(C)		;COMPUTE RELATIVE LINE NUMBER
	ADD A,B			;GET OFFSET IN SPEED BLOCK
	MOVEM D,0(A)		;STORE IT
	RET			;AND DONE

TTSPER:	call ttspfr		;go get free space
	 ret			;no free space. give it up
	jrst ttsps2		;go do it
;routine to get free space block to store speeds

ttspfr:	savet			;save all regs
	MOVE T1,[.resp2,,NTTFE]	;SET UP TO GET A FREE BLOCK
	MOVE T2,[RS%SE0+.RESGP]	;FROM THE GENERAL POOL
	CALL ASGRES		;GET IT
	 JRST [	BUG(CHK,NOFRSP,<ttspst- COULD NOT GET A FREE BLOCK>)
		RET]		;SO, GIVE UP
	MOVEM T1,SPDBLK		;SAVE IT
	SETOM 0(T1)		;INIT ENTIRE BLOCK TO -1
	MOVEI T2,NTTFE-1(T1)	;END OF THE BLOCK
	HRLS T1			;SET UP FOR BLT
	AOS T1			;""
	BLT T1,0(T2)		;MAKE ENTIRE AREA -1
	RETskp			;AND DONE
;ROUTINE TO HANDLE SIGNAL FROM A FE THAT ITS LINE BUFFER FOR
;A GIVEN LINE IS EMPTY. ACCEPTS:
;	A/ DEVICE CODE
;	B/LINE NUMBER

TTYDON::JUMPL B,DONALL		;IF NEG HE WANTS TO ACK THEM ALL
	CALL GETLIN
	 RET			;ILLEGAL LINE
	CALL STADYN		;GET ADDRESS OF DYNAMIC DATA
	 JRST [	JUMPLE T2,R	;RETURN IF BECOMING ACTIVE OR INACTIVE
		JE TTMES,(T2),R ;RETURN IF NOT A TTEMES BLOCK
		JRST .+1]	;CONTINUE IF TTEMES BLOCK
	SETZRO TTFCT,(B)	;CLEAR COUNT OF BYTES IN -11
	JN TTFPK,(B),R		;IF TO -11 DONE PENDING, GO AWAY
	JE TTFOW,(B),R		;IS THIS LINE WAITING FOR THIS INT?
	SETZRO TTFOW,(B)	;YES. CLEAR WAIT CONDITION
	CALLRET TTYIN2		;CONTINUE OUTPUT TO THE LINE

;HERE WHEN FRONT END IS ACKING ALL UNITS

DONALL:	STKVAR <SAVEE>
	MOVSI C,NTTFE		;NUMBER OF FRONT END LINES
	MOVNS C			;MAKE AOBJN POINTER
DONAL1:	MOVEM C,SAVEE		;SAVE AOBJN POINTER
	MOVEI B,0(C)		;B/LINE NUMBER
	MOVEI A,.FEDLS		;ALL LINES ARE DLS
	CALL TTYDON		;GO ACK THIS GUY
	MOVE C,SAVEE
	AOBJN C,DONAL1		;DO ALL LINES
	MOVE B,CTYLNO		;GET CTY LINE NUMBER
	LOAD C,TTSTY,(B)	;GET LINE TYPE
	CAIE C,TT.FE		;FRONT END LINE?
	RET			;NO. DON'T ACK IT
	SKIPGE B,CTYUNT		;B/UNIT NUMBER FOR CTY
	RET			;NOT SET UP YET
	MOVEI A,.FEDLS		;A/ DEVICE .FEDLS
	CALLRET TTYDON		;GO ACK THE LINE
;ROUTINE TO HANDLE A DIAL UP SIGNAL FROM THE FE
;	A/DEVICE CODE
;	B/LINE NUMBER

TTYDLU::CALL GETLIN		;GET PROPER LINE NUMBER
	 RET			;ILLEGAL LINE
	MOVSI A,0(B)		;LINE NUMBER TO LH
	HRRI A,DLSCXF+CARONB	;INDICATE CARRIER ON
	CALLRET BIGSTO		;PUT IT IN BUFFER

;ROUTINE TO HANDLE HANG UP SIGNAL FROM FE
;	A/DEVICE CODE
;	B/LINE NUMBER

TTYHGU::CALL GETLIN		;GET LINE NUMBER
	 RET			;ILLEAGAL LINE
	MOVSI A,0(B)		;TO LH
	HRRI A,DLSCXF		;CARRIER TRANSITION
	CALLRET BIGSTO		;STORE IT

;DEFINE THE PROTOCOL TRANSFER VECTOR

TTYDTV::0			;NO STRING DATA
	TTYDON			;ACK
	0			;NO STATUS
	TTYSLA			;SET LINE ALLOCATION
	R			;NO ERROR REPORTING
	TTDTRM			;DETACH REMOTES ON RELOAD
;THIS ROUTINE IS CALLED FROM THE DTE INTERRUPT ROUTINE TO SET
;THE LINE ALLOCATION FOR A TTY LINE. ACCEPTS:
;	1/ DEVICE CODE
;	2/ ALLOCATION
;	3/ LINE NUMBER

TTYSLA::EXCH B,C		;GET ARGS IN PROPER PLACES
	CALL GETLIN		;GET INTERNAL LINE NUMBER
	 RET			;ILLEGAL LINE
	STOR C,TSFMC,(B)	;STORE NEW ALLOCATION
	RET			;AND DONE

;IDCTY - IDENTIFY THE CTY

;ACCEPTS:
;	T2/ UNIT NUMBER FOR THE CTY AS KNOWN BY THE FRONT END

;	CALL IDCTY

;RETURNS +1: ALWAYS

;CALLED FROM DTE SERVICE WHEN THE FRONT END SENDS OVER THE UNIT NUMBER
;WITHIN THE .FEDLS DEVICE THAT IT KNOWS AS THE CTY.  STORES:
;CTYUNT/ THE UNIT NUMBER
;CTYINT/ THE INTERNAL EQUIVALENT OF THAT (INTERNAL LINE NUMBER)

;THE CTY SHOULD ALWAYS BE ADDRESSED INTERNALLY BY CTYLNO, WHICH IS 
;SET UP BY TTINIT. CTYINT WILL CONTAIN THE INTERNAL
;EQUIVALENT OF THE LINE ON WHICH THE CTY IS PHYSICALLY LOCATED FOR THIS
;MONITOR LOAD. ADDRESSING THE LINE BY THIS NUMBER IS AN ERROR.
;IF CTYINT=CTYLNO, CTYINT IS SET TO -1 SO THAT NO LINE NUMBER WILL
;EVER MATCH IT

IDCTY::	SAVET
	PUSH P,T2		;SAVE UNIT NUMBER
	SETOM CTYUNT		;INDICATE CTY NOT KNOWN FOR GETLIN 
	MOVEI T1,.FEDLS		;T1/DEVICE
	CALL GETLIN		;GET THE INTERNAL EQUIVALENT
	 RET			;NOT A FRONT END LINE
	CAME T2,CTYLNO		;IS THIS ITS VALID INTERNAL LINE NUMBER?
	MOVEM T2,CTYINT		;NO. SAVE THIS AS ITS ALIAS
	POP P,CTYUNT		;SET UNIT NUMBER FOR CTY
	RET
;GETLIN - ROUTINE TO CONVERT DEVICE/LINE TO INTERNAL LINE NUMBER
;ACCEPTS:
;	A/DEVICE CODE (ONLY .FECTY OR .FEDLS)
;	B/LINE NUMBER
;RETURNS +1: FAILURE
;	 +2: SUCCESS,
;		T2/INTERNAL LINE NUMBER
;DOES NOT CLOBBER ANY REGISTERS EXCEPT B

GETLIN:	ACVAR <W1>		;GET A WORK REGISTER
	CAIN A,.FECTY		;THE CTY?
	JRST [	MOVE B,CTYLNO	;YES. USE INTERNAL NUMBER OF CTY
		RETSKP]		;AND RETURN WITH GOOD LINE

;THE DEVICE MUST BE .FEDLS

	CAMN B,CTYUNT		;THE UNIT NUMBER FOR THE CTY?
	JRST [	MOVE B,CTYLNO	;YES. GET INTERNAL LINE NUMBER FOR CTY
		RETSKP]
	CAIL B,NTTFE		;IS THE UNIT NUMBER WITHIN THE NUMBER
				; OF FRONT END LINES THAT WE KNOW ABOUT?
	RET			;NO. CAN'T BE A FRONT END LINE
	JUMPE B,GETLN1		;IF THE DL11, SKIP BIAS
	SUBI B,SPCLIN		;BIAS THE LINE
	SKIPG B			;NOW A GOOD T/S LINE NUMBER?
	ADDI B,NTTFE-1		;NO. WAS A SPECIAL. TRANSLATE THE LINE #
GETLN1:	MOVE W1,TTLINV+TT.FE	;YES. GET INTERNAL LINE NUMBER FOR FIRST
	ADD B,TT1LIN(W1)	; FRONT END LINE. COMPUTE FOR THIS LINE
	RETSKP			;RETURN SUCCESS


;FIXARG - ROUTINE TO DETERMINE PROPER DEVICE/LINE NUMBER FOR LINE ON RSX20F
;FRONT END

;ACCEPTS: RH B/ DEVICE (ONLY .FEDLS)
;	  LH C/ INTERNAL LINE NUMBER
;	CALL FIXARG
;RETURNS +1: ALWAYS,
;		RH B/ DEVICE AS KNOWN BY THE FRONT END
;		LH C/ UNIT AS KNOWN BY FRONT END

;CALLED IN PREPARATION FOR CALLING DTE SERVICE. LINE IS ASSUMED TO
;BE ON THE FRONT END

;NOTE: IF CALLED WITH -1, RETURNS IMMEDIATELY. THIS IS BECAUSE OF A
;FRONT-END BUG THAT REQUIRES RECEIVING -1 ON A SENDALL

FIXARG:	ACVAR <W1,W2>		;GET SOME WORK REGISTERS
	JUMPL C,R		;IF UNIT .LE. 0, NO CHANGE
	HLRZ W1,C		;GET INTERNAL LINE NUMBER
	CAMN W1,CTYLNO		;THE CTY?
	JRST [	HRRI B,.FECTY	;YES. USE THE CTY
		HRLI C,0	;AND UNIT 0
		RET]
	MOVE W2,TTLINV+TT.FE	;GET LINE TYPE VECTOR TABLE
	SUB W1,TT1LIN(W2)	;GET LINE NUMBER WITHIN TYPE
	JUMPE W1,FIXAR1		;IF THE DL11, ALL DONE
	ADDI W1,SPCLIN		;NOT. BIAS THE LINE NUMBER
	CAILE W1,NTTFE-1	;A VALID T/S LINE?
	SUBI W1,NTTFE-1		;NO. ONE OF THE SPECIALS THEN
FIXAR1:	HRL C,W1		;RETURN IT IN LH OF C
	RET			;AND DONE


;DTESTO - ROUTINE TO STORE A CHARACTER IN TTBBUF. CALLED AT INTERRUPT LEVEL
;FROM DTE SERVICE. DATA IS ALWAYS A CHARACTER AT THIS POINT.

;ACCEPTS:
;	T1/CHARACTER IN 8 BITS
;	T2/(0,, PHYSICAL LINE NUMBER)
;	T3/DEVICE TYPE

;RETURNS +1: ALWAYS

DTESTO::TRO A,DLSRCF		;INDICATE DATA IS A CHARACTER FOR TTBBUF
	EXCH C,A		;TYPE TO A, CHAR TO C
	CALL GETLIN		;GET INTERNAL LINE NUMBER FOR THIS LINE
	 RET			;LINE NOT ON FRONT END
	MOVE A,C		;RESTORE CHARACTER
	HRLI A,(B)		;1/(INTERNAL LINE NO.,,CHARACTER)
	JRST BIGSTO		;STORE DATA IN BUFFER
;DEVICE DEPENDENT CODE FOR DOBE

TTDBEF:	JN TTFCT,(2),RSKP	;IF BYTE IN FRONT END, GO DISMISS
	RET


;DEVICE DEPENDENT CODE FOR SOBE

TTSBEF:	LOAD T1,TTFCT,(2)	;GET FE CHARACTER COUNT
	ADD 1,TTOCT(2)		;ADD IN BYTES STILL IN -10 MEMORY
	OPSTR <SKIPN>,TTOTP,(2)	;NOW INACTIVE?
	SKIPLE 1		;EMPTY?
	RET			;NO. NOT EMPTY THEN
	RETSKP			;EMPTY


;DEVICE DEPENDENT CODE FOR WAKE UP ON OUTPUT BUFFER EMPTY

TTOBEF:	OPSTR <SKIPN>,TTFCT,(T2) ;CHARACTERS IN FRONT END?
	JRST TTOBE1		; NO.  GO MAKE THE REST OF THE CHECKS
	JRST 0(4)		;YES DON'T WAKE UP


;DEVICE DEPENDENT CODE FOR INIALIZING DYNAMIC STORAGE

TTSETF:	LOAD T3,TSFMC,(T2)	;GET FRONT END CHARACTER LIMIT FROM DYNAMIC
	STOR T3,TTFMC,(T1)	; AND COPY TO DYNAMIC
	JRST TTSET1		;GO DO THE REST OF THE INITILIZATION
;ROUTINE CALLED FROM PROTOCOL HANDLER TO DETACH ALL REMOTE JOBS FOR
;A GIVEN DTE. ACCEPTS:
;	A/ DTE NUMBER (NOT USED)
;RETURNS	+1 ALWAYS

	SWAPCD			;IS SWAPPABLE
TTDTRM:	CAME A,MSTRDT		;IS THIS FOR THE MASTER DTE?
	RET			;NO. DON'T DO ANYTHING THEN
	SAVET			;SAVE ALL TEMP REGISTERS
	MOVSI B,NTTFE		;NUMBER OF FE LINES
	MOVNS B			;SET UP AOBJN POINTER
	MOVE A,TTLINV+TT.FE	;GET NUMBER OF FIRST LINE OF THE TYPE TT.FE
	HRR B,TT1LIN(A)		;START WITH FIRST LINE AND LOOP THROUGH ALL
TTDTR1:	OPSTR <SKIPE>,TTFEM,(B) ;IS THIS LINE REMOTE?
	CALL TTJBDT		;YES. DETACH IT THEN
	AOBJN B,TTDTR1		; DO ALL LINES
	MOVEI A,.SFRMT		;SEE IF REMOTE LOGINS NOW ALLOWED
	TMON			;GET VALUE
	XCT [	CALL DTRMDS	;NOW DISALLOWED
		CALL DTRMEN](B)	;NOW ALLOWED
	RET			;AND DONE
;ROUTINE TO DEFINE THE DL11W PSEUDO-CTY'S.
;PRIMARY PROTOCOL MUST BE RUNNING

DFNDL1::ACVAR <W1>		;GET A WORK REG
	STKVAR <<DFNDLS,2>,<DFNDS1,1>>	;A STRING
	MOVE T2,[ASCII /TTY/]	;GET BASE STRING
	MOVEM T2,DFNDLS		;SAVE IT
	MOVE T2,[ASCIZ /DL0/]	;GET DEFINITION STRING
	MOVEM T2,DFNDS1		;SAVE IT
	MOVE W1,[-<SPCLIN-1>,,SPCLIN-2] ;THE LINES TO DO
DFNDLL:	HRRZ T2,W1		;GET LINE NUMBER
	MOVEI T1,.FEDLS		;FOR THE DLS DEVICE
	CALL GETLIN		;GET ITS INTERNAL NUMBER
	 JRST DFNDLE		;?
	SETONE TTIGI,(T2)	;SET IGNORE
	MOVEI T1,DFNDLS		;GET ADDRESS OF BYTE ARRAY
	HRLI T1,(<POINT 7,0,20>) ;MAKE IT A STRING POINTER
	MOVEI T3,10		;GET AN OCTAL NUMBER
	NOUT			;PUT LINE NUMBER IN STRING
	 JFCL
	MOVEI T3,":"		;GET TERMINATOR
	IDPB T3,T1		;STORE COLON
	SETZM T3		;GET A NULL
	IDPB T3,T1		;TIE OFF STRING
	MOVX T1,<BYTE (7)0,0,1>
	ADDM T1,DFNDS1		;CHANGE LOGICAL NAME STRING
	MOVEI T1,.TTDES(T2)	;GET DEVICE DESIGNATOR IN T1
	MOVEI T2,.MOSNT		;SET NON-TERMINAL STATUS
	MOVEI T3,.MOSMN		;SUPPRESS SYSTEM MESSAGES
	MTOPR			;DO IT
	 ERJMP .+1		;PROCEED IF IT FAILS
	MOVX T1,.CLNSY		;CREATE SYSTEM LOGICAL NAME
	HRROI T2,DFNDS1		;THE LOGICAL NAME
	HRROI T3,DFNDLS		;THE DEFINITION
	CRLNM			;DO IT
DFNDLE:	 BUG (INF,DLDEF,<LOGICAL NAME DEFINE FAILED FOR FE CTY>)
	AOBJN W1,DFNDLL		;DO THEM ALL
	RET			;AND DOND