;<134-TENEX>FILTTY.MAC;2     8-Jul-78 17:25:46    EDIT BY PETERS
;<134-TENEX>FILTTY.MAC;15    28-APR-75 11:38:44    EDIT BY CLEMENTS
;<134-TENEX>FILTTY.MAC;14    24-APR-75 14:19:32    EDIT BY CLEMENTS
;<TENEX-132>FILTTY.MAC;13     9-NOV-73 19:57:16	EDIT BY CLEMENTS
; NTTYS TO NVTLO
;<TENEX-132>FILTTY.MAC;12    13-JUN-73 21:37:18	EDIT BY CLEMENTS
;<DLM/TEMP>FILTTY.MAC;11    19-OCT-72 19:57:41	EDIT BY TOMLINSON
;<FILESYSTEM>FILTTY.MAC;10    25-AUG-72 17:49:32	EDIT BY TOMLINSON
;<FILESYSTEM>FILTTY.MAC;9    29-JUN-72 10:11:50	EDIT BY TOMLINSON

	SEARCH	STENEX,PROLOG,MONSYM
	TITLE	FILTTY
	USE	SWAPPC

EXTERN	PBYTPO,PBYTSZ
EXTERN	SAVAC,RESAC,CHKDEV,CAPENB
EXTERN	CPOPJ,SKPRET,ITRAP1
EXTERN	CTRLTT		; Controlling tty
EXTERN	TCI,TCIB	; Character type in routine
EXTERN	TCO,TCOB	; Character type out routine
EXTERN	TTFORK		; Lh ==> job to which tty is assigned
EXTERN	JOBNO		; Current job number

; tty dispatch table

TTYDTB::TTYSET
REPEAT OPEND-1,<CPOPJ>
	TTYOPN
	TTYIN
	TTYOUT
	TTYCLZ
REPEAT MTPD-CLOSD-1,<CPOPJ>
	TTYMTP
REPEAT SDSTD-MTPD,<CPOPJ>

TTYSET:	TEST(O,NVERF,NNAMF)
	POPJ P,

TTYIN:	CAIL JFN,400000		; Real jfn?
	 JRST TTYINX		; No
	LDB B,[POINT 4,STS,35]
	JUMPE B,[LDB B,PBYTSZ
		CAIE B,8
		JRST .+2
		JRST .+3]
	CAIE B,10
TTYINX:	SKIPA B,[TCI]
	MOVEI B,TCIB
	PUSHJ P,SAVAC
	HLRZ 2,DEV
	PUSHJ P,@B-NSAC+1(P)
	MOVEM 1,A-NSAC+1(P)
	PUSHJ P,RESAC
	CAIL JFN,400000
	 POPJ P,
	HLLZ B,FILBYT(JFN)
	TLZ B,770000
	HRRI B,A
	LDB A,B
	POPJ P,

TTYOUT:	CAIL JFN,400000
	 JRST TTYOUX
	HLLZ B,FILBYT(JFN)
	TLZ B,770000
	HRRI B,A
	LDB A,B
	LDB B,[POINT 4,STS,35]
	JUMPE B,[LDB B,PBYTSZ
		CAIE B,8
		JRST .+2
		JRST .+3]
	CAIE B,10
TTYOUX:	SKIPA B,[TCO]
	MOVEI B,TCOB
	PUSHJ P,SAVAC
	HLRZ B,DEV
	PUSHJ P,@B-NSAC+1(P)
	PUSHJ P,RESAC
	POPJ P,

TTYOPN:	HLRZ B,DEV		; Get tty line number
	HLRZ C,TTFORK(B)	; Get job to which tty is assigned
	MOVE A,CAPENB
	TRNA A,WHEEL!OPR	; nls shared screens patch
	CAMN C,JOBNO		; Is assigned to this job?
	JRST TTYOP1
	MOVEI A,OPNX7
	CAIE C,777777		; Or not assigned?
	POPJ P,			; No. fail
	MOVE C,JOBNO
	HRLM C,TTFORK(B)
TTYOP1:	TEST(ZE,RNDF)		;TURN APPENDING INTO WRITING
	TEST(O,WRTF)		; ..
	TEST(O,SIZF)
	JRST SKPRET

TTYCLZ:	HLRZ B,DEV
	CAMN B,CTRLTT
	 JRST SKPRET
	HLRZ A,TTFORK(B)
	CAME A,JOBNO
	 JRST TTYCL1
	MOVEI A,400000(B)
	PUSHJ P,CHKDEV
	 POPJ P,
	TLNN C,(1B6)
	 HRROS TTFORK(A)
	HRRZ B,A
TTYCL1:	AOS (P)
IFG NNVTLN,<
	CAIL B,NVTLO
	 JRST NVTDET##
>
	CAIL B,NTTYS
	 POPJ P,
	HRLZ B,B
	CONO 374,B		;Disable line to hang up dataset
	MOVEI A,^D1000
	DISMS
	HRRI B,247
	CONO 374,B		;Reenable
	POPJ P,

;TTY MTOPRS
TTYMTP:	TQNN <OPNF>
	 ITERR (CLSX1)
	HLRE 2,DEV
	JUMPL 2,CPOPJ
	XCTUM [HRRZ 3,2]
	MOVSI 1,-NTTYMT
TTMTO1:	HLRZ 4,TTYMTB(T1)
	CAIN 4,(3)
	JRST [	HRRZ 3,TTYMTB(T1)
		JRST (3)]
	AOBJN T1,TTMTO1
	ITERR (MTOX1)

;MTOPR DISPATCH TABLE

TTYMTB:	.MOFCI,,TTMFCI
IFN NDLS,<
	.MORSP,,TTMRSP
	.MOSPD,,TTMSSP
	.MORLW,,TTMRLW
	.MOSLW,,TTMSLW
	.MORLL,,TTMRLL
	.MOSLL,,TTMSLL
>
NTTYMT==.-TTYMTB

TTMFCI:	HLRE 2,DEV		;GET LINE NUMBER
	CALL TTIFCI##		;READ 12-BIT CHARACTER FROM IT
	UMOVEM 1,3		;RETURN TO USER
	RET

IFN NDLS,<
TTMRSP:	HLRE 2,DEV
	CALL TTYRSP##
	UMOVEM 1,3
	RET

TTMSSP:	HLRE 2,DEV
	UMOVE T1,3
	CALL TTYSSP##
	RET

TTMRLW:	HLRE 2,DEV
	LDB 1,[POINT 7,TTFLGS##(2),17]
	UMOVEM 1,3
	RET

TTMSLW:	HLRE 2,DEV
	UMOVE 1,3
	DPB 1,[POINT 7,TTFLGS(2),17]
	RET

TTMRLL:	HLRE 2,DEV
	LDB 1,[POINT 7,TTFLGS(2),10]
	UMOVEM 1,3
	RET

TTMSLL:	HLRE 2,DEV
	UMOVE 1,3
	DPB 1,[POINT 7,TTFLGS(2),10]
	RET

>

	END

