Google
 

Trailing-Edge - PDP-10 Archives - bb-y393c-sm - monitor-sources/ttfedv.mac
There are 21 other files named ttfedv.mac in the archive. Click here to see a list.
; UPD ID= 258, FARK:<4-1-WORKING-SOURCES.MONITOR>TTFEDV.MAC.3,   9-Dec-82 16:11:10 by MOSER
;EDIT 2875 - USE .DFBKW TO DO XON/XOFF
; UPD ID= 48, FARK:<4-1-WORKING-SOURCES.MONITOR>TTFEDV.MAC.2,   3-Apr-82 19:13:17 by ZIMA
;Edit 2607 - add ENDAV.s to ACVARs to use v5 MACSYM.
;<4-1-FIELD-IMAGE.MONITOR>TTFEDV.MAC.2, 25-Feb-82 20:50:59, EDIT BY DONAHUE
;UPDATE COPYRIGHT DATE
;<4.MONITOR>TTFEDV.MAC.52,  3-Jan-80 08:10:39, EDIT BY R.ACE
;UPDATE COPYRIGHT DATE
;<4.MONITOR>TTFEDV.MAC.51,  1-Nov-79 17:15:09, EDIT BY MILLER
;<4.MONITOR>TTFEDV.MAC.50,  1-Nov-79 15:54:35, EDIT BY MILLER
;<4.MONITOR>TTFEDV.MAC.49,  1-Nov-79 10:01:55, EDIT BY MILLER
;<4.MONITOR>TTFEDV.MAC.48, 31-Oct-79 16:37:25, EDIT BY MILLER
;<4.MONITOR>TTFEDV.MAC.47, 31-Oct-79 16:13:10, EDIT BY MILLER
;FLUSH ALL DTE Q REQUESTS WHEN DYNAMIC DATA IS DEASSIGNED
;<4.MONITOR>TTFEDV.MAC.46, 31-Oct-79 13:08:36, EDIT BY ENGEL
;ADD MORE DISPATCH VECTOR NAMES TO TTFEVT
;<4.MONITOR>TTFEDV.MAC.45, 31-Oct-79 12:46:44, EDIT BY MILLER
;FIX HANDLING OF TTFPK. MAKE STRIO CONDITIONAL ON VALUE OF TTFPK.
;<4.MONITOR>TTFEDV.MAC.44, 31-Oct-79 10:20:25, EDIT BY ENGEL
;ADD DISPATCH VECTOR NAMES TO TTFEVT
;<4.MONITOR>TTFEDV.MAC.43, 30-Oct-79 17:26:31, EDIT BY MILLER
;CHECK AT TTYINT FOR TTOCT GOING NEGATIVE. IF SO, ASSUME CFOBF
; HAS JUST BEEN DONE AND DON'T UPDATE THE COUNT
;<4.MONITOR>TTFEDV.MAC.42, 24-Oct-79 16:14:15, EDIT BY MURPHY
;FASTER WAKEUP ON OUTPUT EVENTS
;<4.MONITOR>TTFEDV.MAC.41, 10-Oct-79 13:48:26, EDIT BY MURPHY
;FIX PROBLEMS WITH XOFF/XON
;<4.MONITOR>TTFEDV.MAC.38, 19-Sep-79 14:51:29, EDIT BY MURPHY
;CHANGE VECTOR OFFSET NAMES
;<OSMAN.MON>TTFEDV.MAC.1, 10-Sep-79 16:13:38, EDIT BY OSMAN
;TCO 4.2412 - Move definition of BUGHLTs, BUGCHKs, and BUGINFs to BUGS.MAC
;<4.MONITOR>TTFEDV.MAC.36,  3-Jul-79 13:19:52, Edit by MCLEAN
;MAKE CALL IN BIGST1 DO CALL TTQAD1 INSTEAD OF TTQAD
;<4.MONITOR>TTFEDV.MAC.35, 12-Jun-79 14:25:27, Edit by MCLEAN
;<4.MONITOR>TTFEDV.MAC.34, 12-Jun-79 11:26:33, Edit by MCLEAN
;DO XON/XOFF STATE BEFORE SETTING SPEED
;<4.MONITOR>TTFEDV.MAC.33, 15-May-79 12:47:25, Edit by MCLEAN
;MORE FIXES FOR LINE XOFF WHEN NOT ACTIVE
;<4.MONITOR>TTFEDV.MAC.32, 15-May-79 10:13:37, Edit by MCLEAN
;<4.MONITOR>TTFEDV.MAC.31, 15-May-79 09:39:06, Edit by MCLEAN
;REMOVE SPEED CODE FROM SNDXN2
;<4.MONITOR>TTFEDV.MAC.30, 13-May-79 21:51:14, Edit by MCLEAN
;GET CORRECT HALF WORD FOR TTSPWD FOR XOFF
;<4.MONITOR>TTFEDV.MAC.29, 30-Apr-79 22:57:07, Edit by MCLEAN
;STOP LINES THAT GET 2 CHARACTERS IN INPUT BUFFER BEFORE LINE IS ACTIVE
;<4.MONITOR>TTFEDV.MAC.28, 11-Mar-79 13:14:10, EDIT BY KONEN
;UPDATE COPYRIGHT FOR RELEASE 4
;<4.MONITOR>TTFEDV.MAC.27, 16-Feb-79 12:56:59, Edit by MCLEAN
;FIX COMMENTS AND REMOVE BLANK PAGE
;<4.MONITOR>TTFEDV.MAC.26, 16-Feb-79 12:51:46, Edit by MCLEAN
;FIX STORING OF LINE
;<4.MONITOR>TTFEDV.MAC.25, 13-Feb-79 13:32:02, Edit by MCLEAN
;REMOVE COMMENT CALL IN TTEXF TO DTEQ
;<4.MONITOR>TTFEDV.MAC.24, 12-Feb-79 17:20:02, Edit by MCLEAN
;TTEXF NEEDED A DYNST
;<4.MONITOR>TTFEDV.MAC.23, 10-Feb-79 17:16:09, Edit by MCLEAN
;NEW CHANGES FOR FRONT-END DOING XOFF
;<4.MONITOR>TTFEDV.MAC.22,  5-Feb-79 21:09:32, Edit by MCLEAN
;<4.MONITOR>TTFEDV.MAC.21,  3-Feb-79 00:34:14, Edit by MCLEAN
;<4.MONITOR>TTFEDV.MAC.20,  2-Feb-79 23:39:54, Edit by MCLEAN
;ADD NEW VECTOR VSFEXO FOR XOFF RECOGNITION IN FRONT END	;ENABLE/DISABLE FRONT-END XOFF RECOGNITION

;<4.MONITOR>TTFEDV.MAC.19, 25-Jan-79 18:26:32, Edit by MCLEAN
;FIX SNDXO1+5 SO IT GOES TO SNDXO3 NOT R
;<4.MONITOR>TTFEDV.MAC.18, 24-Jan-79 00:11:42, Edit by MCLEAN
;FIX STI OF XON COULD CRASH SYSTEM WITH KEEPALIVE
;<4.MONITOR>TTFEDV.MAC.17, 21-Jan-79 18:01:01, Edit by MCLEAN
;FIX SO XON HAS COUNT IS FROM EMPTY NOT FULL
;<4.MONITOR>TTFEDV.MAC.16, 14-Jan-79 15:07:57, Edit by MCLEAN
;REMOVE CODE REQUIRED FOR NON-RESIDENT TTSPWD
;<4.MONITOR>TTFEDV.MAC.14, 14-Jan-79 02:11:26, Edit by MCLEAN
;FIX IT SO TTXCN DOESN'T OVERFLOW
;<4.MONITOR>TTFEDV.MAC.13,  8-Jan-79 14:40:47, Edit by MCLEAN
;MAKE STPLNF FASTER AND SMALLER IT SHOULD ONLY SHUT OFF LINE FOR SHORT TIME
;<4.MONITOR>TTFEDV.MAC.12,  7-Jan-79 19:51:10, Edit by MCLEAN
;FIX CUTOFF FOR XON/XOFF
;<4.MONITOR>TTFEDV.MAC.10, 28-Dec-78 22:43:55, Edit by MCLEAN
;ADD VSTPLN STOP LINE (ABORT LINE AS IN NO INPUT!)	;STOP LINE

;<4.MONITOR>TTFEDV.MAC.8, 13-Nov-78 21:50:42, Edit by MCLEAN
;FIX TTXON SO IT DOES CHANNEL OFF BEFORE CALLING BIGSTO
;<4.MONITOR>TTFEDV.MAC.7, 13-Nov-78 21:48:15, Edit by MCLEAN
;REMOVE ADDM F,TTOCT(B) AT RSCHED+1 IT REALLY WAS WRONG THING TO DO
;<2MCLEAN>TTFEDV.MAC.6, 23-Oct-78 22:09:24, Edit by MCLEAN
;<2MCLEAN>TTFEDV.MAC.5,  8-Oct-78 21:32:28, Edit by MCLEAN
;<2MCLEAN>TTFEDV.MAC.4,  7-Oct-78 22:30:11, Edit by MCLEAN
;REMOVE OBFFR FOR SPEED
;<4.MONITOR>TTFEDV.MAC.5, 13-Oct-78 15:14:51, Edit by MCLEAN
;REMOVE FIX FOR XOFF FAILURE WE REALLY DON'T WANT TO CLEAR BIT HERE
;BECAUSE XOFF WILL BE DONE AGAIN.
;<4.MONITOR>TTFEDV.MAC.4,  8-Oct-78 21:30:14, Edit by MCLEAN
;TTMSAL AND A JUMPGE B,2 I PRESUME IT SHOULD HAVE BEEN JUMPGE 2,R
;<4.MONITOR>TTFEDV.MAC.3, 27-Sep-78 22:30:28, Edit by MCLEAN
;FIX XOFF SO FAILURE ON DTEQ WORKS CORRECTLY
;<4.MONITOR>TTFEDV.MAC.2, 27-Sep-78 09:39:27, EDIT BY MILLER
;ALWAYS SEND XOFF WHEN SNDXO2 IS CALLED
;<4.MONITOR>TTFEDV.MAC.1, 18-Jul-78 15:57:57, EDIT BY MILLER
;CHANGE DTESTO TO USE TTIDON.


;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,1979,1980,1981,1982 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%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			;DDLEN - LENGTH OF DYNAMIC DATA FOR THIS TYPE
	-1			;TT1LIN - FIRST LINE OF THIS TYPE/-1 NO LINES
	IFIW!R			;VITBLS - INITALIZATION
	IFIW!R			;VACTLN - RESTART
	IFIW!TTCOB4		;VCLOBF - CLEAR OUTPUT BUFFER
	IFIW!TTSSP2		;VSETSP - SET LINE SPEED
	IFIW!TTRSP1		;VGETSP - RETURN LINE SPEED
	IFIW!TTSNT1		;VSETTS - SUPRESS SYS MESSAGES
	IFIW!TTRNT1		;VGETTS - RETURN NON-TERMINAL DEV STATUS
	IFIW!TTSTO3		;VSTO - STOP ACTIVE LINE
	IFIW!R			;VSTPAR - SET TERMINAL CHARACT
	IFIW!RSKP		;VCKPHY - PHYSICAL TERMINAL
	IFIW!TTXON1		;VXON -XON	;PROCESS XON FROM TERMINAL

	IFIW!TTYDE0		;VDETDB - DEASIGN DYNAMIC DATA
	TRO 1,200		;VOPAR - APPLY PARITY
	IFIW!STRTO7		;VSTOUT - START OUTPUT LINE
	IFIW!SNDXO2		;VSXOFF - SEND XOFF
	IFIW!SNDXN2		;VSXON - SEND XON
	IFIW!TTCQ1		;VTTCS - EMPTY BUFFER
	IFIW!TTCON1		;VCON - CARRIER ON
	IFIW!NTYCOF		;VCOFF - CARRIER OFF
	IFIW!TTHU2		;VHNGUP - HANGUP
	IFIW!TTCHI3		;VXOFF - STOP LINE	;PROCESS XOFF FROM TERMINAL

	IFIW!TTC7S1		;RNEWCC - LOCAL/REMOTE CHECK FOR LOGIN
	IFIW!BIGST2		;VSTOBB - LINE STORAGE
	IFIW!TTSND1		;VSNDCH - SEND CHARACTER
	IFIW!TTDAL6		;VDET - DEALLOCATE LINE
	IFIW!DLSSX2		;VBBOV - HANDLE OVERFLOW OF TTBUFF
	IFIW!R			;VGCHBB - EMPTY BUFFER
	IFIW!RSKP		;VTTMSG - OK TO DO SENDALL FOR A LINE	;DO TTMSG FOR ONE LINE?

	IFIW!FEDABL		;TSETDS - DISABLE ENABLE
	IFIW!R			;VCKLIN - TTCH7 AFTER EMPTYING BUFFER
	IFIW!R			;VCLIBF - CLEAR INPUT BUFFER
	IFIW!TTDBEF		;VDOBE - DOBE
	IFIW!R			;VHNGRY - INPUT GA
	IFIW!TTSETF		;VSINIV  - SET INIT. VALUES FOR A LINE
	IFIW!TTSBEF		;VSOBE - SOBE
	IFIW!TTOBEF		;VDOBET - WAKEUP IF OUTPUT BUFFER EMPTY
	IFIW!TTMSSN		;VSNDA1 - DO ACTUAL SENDALL FOR A LINE	;SENDALL FOR ONE LINE

	IFIW!TTMSAL		;VSNDAL - DO SENDALL FOR ALL LINES	;SENDALL FOR ALL LINES

	JFCL			;VAJWCL - ADJUST WAKEUP CLASS	;ADJUST WAKEUP CLASS

	IFIW!STPLNF		;VSTPLN - STOP LINE	;STOP LINE

	IFIW!TTEXF		;VSFEXO - ENABLE/DISABLE XOFF RECOGNITION IN FRONT-END	;ENABLE/DISABLE FRONT-END XOFF RECOGNITION


   IFN <.-TTVTMX>-TTFEVT,<PRINTX %%INVALID DEVICE DEPENDENT TABLE SIZE>
;DEASSIGN DYNAMIC DATA
;	2/STATIC LINE NUMBER

   REPEAT 0,<			;A GOOD IDEA THAT DIDN'T HELP
TTYDEF:	NOSKD1			;OWN MACHINE
	SKIPG TTACTL(B)		;FULLY ACTIVE LINE?
	JRST TTYDF0		;NO. GIVE UP THEN
	PUSH P,B		;SAVE LINE NUMBER
	MOVE A,MSTRDT		;GET DTE #
	MOVSI C,0(B)		;GET LINE #
	MOVEI B,.FEDLS		;GET DEVICE
	CALL FIXARG		;FIX UP ARGS
	CHNOFF DLSCHN		;AND THE CHANNEL AS WELL
	CALL DTEFLA		;FLUSH ALL PACKETS FOR THE LINE
	CHNON DLSCHN		;UNDO OWNERSHIP
	POP P,B			;RESTORE REG
TTYDF0:	OKSKD1			;AND THIS TOO
	JRST TTYDE0		;AND DONE
   >				;END OF REPEAT 0
;START I/O

;	2/ DYNAMIC DATA ADDRESS

STRTO7:	DYNST T3		;GET STATIC BLOCK
	JN TTFPK,(T3),STRT11	;IF ON, DON'T START OUTPUT
	JRST STRTO1		;NOT. GO TO IT
; 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
	CALL TTEXFA		;SET XON/XOFF STATE
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
;**;[2607] Add one line at TTSSP3: +2L	JGZ	3-APR-82
	ENDAV.			;[2607] END ACVAR
; SET/RETURN DEVICE NON-TERMINAL STATUS

TTSNT1:	SKIPN FEFLG		;IN PRIMARY PROTOCOL?
	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


;ENABLE/DISABLE XOFF RECOGNITION IN THE FRONT-END

	RESCD


TTEXFA:	SAVET			;SAVE REGISTERS
	CALL STADYN
	RET			;NOT IMPORTANT
	JRST TTEXZ
	
TTEXF:	SKIPN FEFLG		;CHECK FOR PRIMARY PROTOCOL 
	RET			;NO. IGNORE IT THEN
	SAVET			;SAVE TEMPS
TTEXZ:	SETZ T4,0		;ASSUME CLEAR
	OPSTR <SKIPE>,TT%PGM,TTFLGS(T2)
	SETO T4,0		;SET
	DYNST			;GET STATIC TTY NUMBER
	MOVSI T3,0(T2)		;GET TTY # TO SET/CLEAR
	MOVE T2,[.DFXEN,,.FEDLS] ;ARGS (FCN,,DEVICE)
	CALL FIXARG		;FIX UP ARGS
	MOVE T1,MSTRDT		;MASTER DTE
	CALL DTEQ		;DO THE REQUEST
	 JFCL			;FORGET IT
	RET
	SWAPCD
;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,R
		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
	JFCL			;FORGET IT IT WILL COME AGAIN
	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 PB2		;RESTORE AND RETURN BAD
	POP P,B			;RESTORE LINE
	RETSKP			;GIVE GOOD RETURN
;LINE IS ON RSX20F FRONT END

SNDXO2:	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
	LOAD D,TTXCN,(B)	;GET COUNT OF XOFFS
	AOS D			;UPDATE COUNT
	STOR D,TTXCN,(B)
	SOJN D,SNDXO3		;RETURN IF NOT ZERO
	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
;**;[2875]CHANGE 1 LINE AT SNDXO1:+10L	TAM	9-DEC-82
	MOVE B,[.DFBKW,,.FEDLS]	;[2875]
	CALL FIXARG		;FIX UP THE ARGS
	CALL DTEQ		;GO SEND IT
	JFCL			;IGNORE FAILURE
SNDXO3:	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
	MOVE D,B		;SAVE LINE NUMBER
	CALL STADYN		;GET ADDRESS OF DYNAMIC DATA
	 JRST SNDXN3		;NOT ACTIVE. INPUT BUFFER CAN'T OVERFLOW
	MOVEI A,MINXON		;LEVEL AT WHICH TO START AGAIN
	CAMGE A,TTICT(B)	;IS INPUT BUFFER THIS FULL?
	JRST SNDXN1		;YES. DON'T SEND XON
	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

SNDXN3:	MOVE B,SNDXSV		;TURN IT ON IF NOT ACTIVE.
	SETZRO TTXCN,(B)	;ZERO XOFF COUNT
	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)
;**;[2875]CHANGE 1 LINE AT SNDXN3:+7L	TAM	9-DEC-82
	MOVE B,[.DFBKW,,.FEDLS]	;[2875]
	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:	SAVET			;SAVE TEMPS
	DYNST			;GET STAT ADDRESS
	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 STPLNF		;STOP LINE
	CAIG C,2		;CHECK FOR 2 IN BUFFER
	JRST BIGST4		;NO NOT THIS TIME
	SKIPG TTACTL(T2)	;YES CHECK TO SEE IF ACTIVE
	JRST STPLNF		;NO SHUT LINE DOWN IT IS ANOYING ME
BIGST4:	STOR C,TTFBB,(B)	;UPDATE COUNT OF CHARACTERS IN TTBBUF
	CAIGE C,MAXBBC		;MANY CHARS FOR THIS LINE?
	JRST BIGST1		;NO, CONTINUE
	MOVE C,TTBIGC		;YES, BIGBUF GETTING FULL TOO?
	CAIL C,TTBSIZ/2
	CALL SNDXOF		;YES, SEND XOF
	JRST BIGST1

STPLNF:	CALL SNDXOF		;TURN LINE OFF
	JN TTIME,(B),R 		;IF LINE ALREADY QUEUED, GO ON
	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 PB2		;RESTORE AND RETURN
	POP P,B			;RESTORE LINE NUMBER
	MOVE C,[TTTOBL]		;C/THE ROUTINE TO CALL
	CALLRET TTQAD1		;GO Q IT UP AND LOSE DATUM
;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 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
	SETONE TTFPK,(B)	;SAY WAITING FOR TO -11 DONE
	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
		MOVNI C,1	;BACK UP BUFFER
		ADJBP C,TTOOUT(B)
		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
	SETZRO TTFPK,(B)	;CLEAR WAITING FOR -11
	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
	SKIPG C			;IF COUNT WENT NEGATIVE, DON'T STORE IT
	MOVNM C,TTOCT(B)	;STORE NEW COUNT
	CALL CHKWRN		;SEE IF FORK WAKEUP NEEDED

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
	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
	SETONE TTOTP,(B)	;MAKE SURE THIS IS ON
	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
	MOVEM B,TTYVR2		;SAVE ADDRESS OF DYNAMIC DATA
	DYNST			;GET LINE NUMBER
	SETONE TTFPK,(B)	;WAITING FRO TO -11 DONE
	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
	MOVE D,TTYVR1		;GET ORIGINAL BYTE POINTER
	MOVEM D,TTOOUT(B)	;RESTORE OUTPUT BYTE POINTER
INTRST:	DYNST			;B/ LINE NUMBER
	SETZRO TTFPK,(B)	;NOT WAITING FOR PACKET
	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
	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:	MOVEM D,TTSPWD(B)	;STORE IT
	RET			;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
	JN TTFPK,(B),R		;IF TO -11 DONE PENDING, GO AWAY
	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
	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
;**;[2607] Add one line at GETLN1: +3L	JGZ	3-APR-82
	ENDAV.			;[2607] END ACVAR


;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
;**;[2607] Add one line at FIXAR1: +2L	JGZ	3-APR-82
	ENDAV.			;[2607] END ACVAR


;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::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
	CALLRET TTICNT		;GO STORE CHARACTER
;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 (DLDEF)
	AOBJN W1,DFNDLL		;DO THEM ALL
	RET			;AND DOND
;**;[2607] Add one line at DFNDLE: +3L	JGZ	3-APR-82
	ENDAV.			;[2607] END ACVAR