Google
 

Trailing-Edge - PDP-10 Archives - AP-D543V_SB - ptyser.mac
There are 11 other files named ptyser.mac in the archive. Click here to see a list.
TITLE PTYSER - PSEUDO-TELETYPE SERVICE ROUTINES V3076
SUBTTL	R CLEMENTS/RCC/DAL  31 OCT 78
	SEARCH	F,S
	$RELOC
	$HIGH



;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1973,1974,1975,1976,1977,1978 BY DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
XP VPTYSR,3076
		;VERSION NUMBER FOR GLOB AND MAP

ENTRY PTYSER
PTYSER:		;DUMMY GLOBAL FOR PTY ROUTINES IN LIBRARY SEARCH

;ACCUMULATOR ASSIGNMENTS

;PTY DEVICE-DEPENDENT IO STATUS BITS (RH DEVIOS)

XP IOPTW,4000	;OUTPUT WAIT (CONTROLLED JOB HAS DONE INPUT)
XP IOPTRE,2000	;PTY RESPONSE. CONTROLLED JOB HAS DONE OUTPUT
XP MONMOD,1000	;THE CONTROLLED TTY IS IN MONITOR COMMAND MODE

;PSEUDO-TELETYPE DEVICE DATA BLOCK
;REMAINING DDB'S ARE BUILT BY THE ONCE-CODE.

INTERN PTYDDB,PTYLST
	$LOW
PTYLST=.	;LOCATION OF FIRST PTY DDB IN CHAIN

PTYDDB:	SIXBIT	/PTY0/		;PHYSICAL DEVICE NAME
	XWD	0,STTYBF+1	;DEVCHR. SIZE OF USER BUFFERS.
	0			;DEVIOS
	XWD	0,PTYDSP	;DEVSER. LH GETS DEVICE CHAIN
	XWD	DVIN+DVOUT,3	;DEVMOD. A AND AL MODES ONLY.
	0			;DEVLOG
	0			;DEVBUF
	XWD	R,0		;DEVIAD
	XWD	R,0		;DEVOAD
	Z			;DEVSTS - NOT USED
	XWD	.TYPTY,0	;DEVSTA
	Z			;DEVXTR - NOT USED
	Z			;DEVEVM
	Z			;DEVPSI
	Z			;DEVESE
	Z			;DEVHCW
	Z			;DEVJOB

XP PTYDDS,.-PTYDDB		;SIZE OF DDB FOR ONCE-CODE
	$HIGH
INTERNAL PTYDSP		;DISPATCH TABLE ADDRESS
EXTERNAL OUT,PTYINI

	POPJ	P,0		;SPECIAL ERROR STATUS
	JRST	PTYINE		;INIT ENTRY
	JRST	PTYINI(P2)	;INITIALIZATION
	POPJ	P,0		;HUNG DEVICE. CAN'T HAPPEN. STOP JOB.
PTYDSP:	JRST	PTYREL		;RELEASE
	JRST	OUT		;OUTPUT CLOSE
	JRST	PTYOUT		;OUTPUT UUO
	JRST	PTYIN		;INPUT UUO

EXTERNAL LDBDDB,TTYDET,PTYGET,CNCMOD

;CODE CALLED ON A RELEASE OF PTY

PTYREL:	PUSH	P,W		;SAVE FOR PTY DDB ADDR
	PUSH	P,P4		; AND PTY S
	PUSH	P,F		;SAVE DDB ADDRESS
	PUSHJ	P,PTSETL	;SET UP U TO LINKED TTY
	PUSHJ	P,PTYGET	;READ A CHARACTER
	  SKIPA			;NONE LEFT
	JRST	.-2		;KEEP READING TILL EMPTY
	PUSHJ	P,CNCMOD	;MAKE SURE AT COMMAND LEVEL
	PUSHJ	P,TSETBI##	;CLEAR TTY INPUT BUFFER
	HRRZ	F,LDBDDB(U)	;GET TTY'S DDB ADDRESS
	JUMPE	F,PTYRL2	;DONE IF NO DDB ATTACHED
	PUSH	P,J		;SAVE J OVER PSISIG
	LDB	J,PJOBN##	;GET OWNER OF DDB (ATTACHED JOB)
	MOVE	T1,DEVMOD(F)	;NEED TO MAKE SURE JOB WILL DETACH
	TLNE	T1,TTYATC	;IS DDB CONTROLLING A JOB??
	SKIPN	J		;AND A VALID JOB?
	JRST	PTYRL1		;NO, DON'T CALL PSISER
	SIGNAL	C$DATT		;GIVE DETACHING JOB AN INTERRUPT
	EXCTUU	<SETOM	IBKISW##(M)>  ;SET STATUS TO DETACHING IF ENABLED
PTYRL1:	POP	P,J		;RESTOR J FOR UUOCON
	PUSHJ	P,PTYDET##	;YES. DETACH FROM IT
PTYRL2:	POP	P,F		;RESTORE PTY DDB
	PUSHJ	P,LDBCLR##
	PJRST	P2POPJ		;RESTORE AC'S AND RETURN
;INIT ENTRY TO "LOCATE" A PTY

PTYINE:
IFN FTNET,<
	EXTERNAL JBTLOC,PDVSTA,JOB

	MOVE	J,JOB		;GET JOB NUMBER
	MOVE	T1,JBTLOC(J)	;GET JOB LOCATION
	DPB	T1,PDVSTA	;INSERT JOB LOCATION IN DEVICE LOC FIELD
>
EXTERN REGSIZ
	JRST	REGSIZ		;RETURN WITH BUFFER LEN (FROM DDB)
;HERE ON AN OUTPUT UUO TO PTY. SEND CHARACTERS TO THE LINKED
;TTY. CONVERT LOWER CASE TO UPPER UNLESS USER HAS REQUESTED LC.

EXTERN SPCHEK,UADRCK,LDLLCT,LDLCOM,PTYPUT,ADVBFE

PTYOUT:	PUSHJ	P,SAVE4##	;SAVE P1-P4
	MOVE	S,DEVIOS(F)	;GET DEVICE STATUS
	TLNE	S,IOBEG		;VIRGIN DEVICE?
	PUSHJ	P,PTYREL	;YES. CLEAR IT OUT.
	MOVSI	S,IOBEG		;CLEAR VIRGIN BIT
	ANDCAB	S,DEVIOS(F)	; ..
				;SAVE THESE AC'S JUST IN CASE
	PUSH	P,W		; UUOCON MIGHT WANT THEM
	PUSHJ	P,PTSETL	;SET UP U, P4
	HRRZ	T1,DEVOAD(P4)	;USUAL UUO ADDRESS CHECKS
	PUSHJ	P,UADRCK	;HIS BUFFER IN BOUNDS?
	MOVE	P1,DEVOAD(P4)	;OK. NOW GET ITS SIZE
	ADDI	P1,1
IFN FTKI10!FTKL10,<
	PUSHJ	P,RLCPTR##	;RELOCATE IT
>
	EXCTUX	<HRRZ	P2,@P1>
				;GET COUNT FROM BUFFER
	JUMPE	P2,PTYOU6	;UNLESS LESS THAN A WORD,
	ADDI	T1,1(P2)	;COMPUTE END OF BUFFER
	PUSHJ	P,UADRCK	;NOW CHECK END OF BUFFER
	IMULI	P2,5		;OK. ITEM COUNT IS 5 PER WORD
	HRRZ	P1,DEVOAD(P4)	;GET BYTE POINTER TO THOSE ITEMS
	ADD	P1,[XWD 700+R,1]	;MAKE ASCII POINTER
IFN FTKI10!FTKL10,<
	PUSHJ	P,RLCPTR##	;SET RELOCATION
>
PTYOU3:	EXCTUX	<ILDB	T3,P1>	;GET CHARACTER FROM BUFFER OF CONTROL JOB
	JUMPE	T3,PTYOU5	;DON'T PASS NULLS
	PUSHJ	P,SPCHEK	;IS IT A SPECIAL CHARACTER?
	  JRST PTYOU4		;NO. GO CHECK ON LOWER CASE.
PTYOU1:	PUSHJ	P,PTYPUT	;PASS CHAR TO SCNSER
	  JRST PTYOUE		; TOO MANY CHARACTERS. ERROR.
PTYOU5:	SOJG	P2,PTYOU3	;LOOP IF MORE IN CONTROLLERS BUFFER
	PUSHJ	P,PTEXCH	;SWAP AC'S AROUND SO PTY'S IN DDB
PTYOU6:	PUSHJ	P,ADVBFE	;ADVANCE CONTROLLER'S OUTPUT BUFFER
	  JFCL			;JUST SINGLE BUFFER
	MOVEI	S,IOPTW		;CLEAR INPUT WAIT BIT.
	ANDCAM	S,DEVIOS(F)	;IN PTY'S STATUS WORD
	MOVSI	S,IOFST		;SET FIRST-ITEM BIT
	IORB	S,DEVIOS(F)	; ..
	TLNE	U,LDLCOM	;CONTROLLED TTY AT TOP LEVEL?
	MOVEI	S,MONMOD	;YES. TELL CONTROLLER
	IORB	S,DEVIOS(F)	; ..
	JRST	WPOPJ##		;RESTORE W AND P4, RETURN TO UUOCON

PTYOU4:	CAIL	T3,140		;IS CHARACTER UPPER CASE?
	TLNN	U,LDLLCT	;NO. USER WANT TRANSLATION?
	JRST	PTYOU1		;LEAVE AS IS.
	CAILE	T3,174		;IN RANGE TO REDUCE?
	SUBI	T3,40		;YES. MAKE UPPER CASE
	JRST	PTYOU1		;RETURN TO LOOP

PTYOUE:	PUSHJ	P,PTEXCH	;POINT AT PTY, NOT TTY
	MOVEI	S,IOBKTL	;BLOCK-TOO-LARGE ERROR BIT
	JRST	PTYOU6		;STORE AND RETURN
;HERE ON AN INPUT UUO FOR PTY. GET CHARACTERS FROM LINKED
;TTY'S OUTPUT BUFFER, PASS THEM TO PTY CONTROL JOB

EXTERN BUFCLR,ADRERR,PTYGET,ADVBFF,LDBTOC,STOTAC,STOTC1,USRHCU

PTYIN:	PUSHJ	P,SAVE4##	;SAVE P1-P4
	PUSH	P,W		; ..
	PUSHJ	P,PTSETL	;SET UP U AND P4
	MOVE	F,P4		;USE PTY'S DDB IN BUFFER OPERATIONS
	PUSH	P,U		;SAVE U OVER CALLS TO UUOCON
	HRRZ	T1,DEVIAD(F)	;INPUT BUFFER ADDRESS
	PUSHJ	P,BUFCLR	;CLEAR USER'S BUFFER AND ADR CK
	  JRST ADRERR		;NO GOOD. GIVE ERROR MSG
	MOVE	P1,DEVIAD(F)
IFN FTKI10!FTKL10,<
	PUSHJ	P,RLCPTR##	;SET RELOCATION
>
	EXCTUX	<LDB	P2,[POINT 17,@P1,17]>
	SUBI	P2,1		;BUFFER SIZE IN WORDS, MINUS LINK
	IMULI	P2,5		;TO CHARACTERS
	POP	P,U		;RESTORE U
	HRRZ	P1,DEVIAD(F)	;MAKE POINTER TO USER BUFFER
	ADD	P1,[XWD 700+R,1]	;7-BIT BYTES
IFN FTKI10!FTKL10,<
	PUSHJ	P,RLCPTR##	;SET RELOCATION
>
PTYIN2:	PUSHJ	P,PTYGET	;GET CHARACTER FROM SCNSER,IF ANY
	  JRST PTYIN1		;NONE THERE.
	EXCTUU	<IDPB	T3,P1>	;STORE IN CONTROLLER'S BUFFER
	SOJG	P2,PTYIN2	;LOOP IF MORE ROOM
PTYIN1:	PUSHJ	P,PTEXCH	;GET PTY DDB BACK IN AC DDB
	MOVE	P3,DEVIAD(F)	;COMPUTE WORD COUNT FOR CONTROLLER
	SUBI	P1,1(P3)	; ..
	AOS	P3
IFN FTKI10!FTKL10,<
	HLL	P3,P1		;RELOCATE FOR CPU TYPE
>
	EXCTUU	<HRRM	P1,@P3>	;STORE IN HIS BUFFER
	PUSHJ	P,ADVBFF	;ADVANCE INPUT BUFFER
	  JFCL			;BUT JUST SINGLE BUFFER FOR NOW
	MOVEI	S,IOPTRE	;CLEAR RESPONSE-WAITING BIT
	ANDCAB	S,DEVIOS(F)	;IN HIS DDB
	SKIPLE	LDBTOC(U)	;IS THAT RIGHT? ANY MORE?
	MOVEI	S,IOPTRE	;MORE THERE. PUT BIT BACK ON.
	IORB	S,DEVIOS(F)	; TO FORCE BATCH TO DO ANOTHER INPUT
	JRST	WPOPJ##		;RETURN FROM INPUT UUO
INTERNAL CTLJOB,UJBSTS

IFN FTPTYUUO,<
;ROUTINE TO FIND CONTROLLER OF THIS JOB, IF IT'S CONTROLLED BY A PTY

EXTERNAL PTYTAB,TTYTAB,PUNIT,PTYOFS,PTYN

CTLJOB:	CAMN	T1,[-1]		;WHAT JOB DOES HE WANT?
	MOVE	T1,J		;HIS OWN IF -1
	PUSHJ	P,LGLPRC##	;SUPPLIED JOB NUMBER LEGAL?
	  POPJ	P,0		;NO. ERROR RETURN
	HRRZ	F,TTYTAB(T1)	;GET TTY DDB FOR THIS JOB
	PUSHJ	P,CTLJBD	;FIND CONTROLLING JOB
	PJRST	STOTC1		;OK RETURN STORE VALUE IN USER'S AC

;SUBROUTINE TO FIND JOB NUMBER OF JOB CONTROLLING THIS TTY
;ARGS F=DDB OF TTY
;VALUE T1=JOB NUMBER OF CONTROLLING JOB IF JOB'S TTY IS A PTY OR -1
;IF T1 POS, F=CONTROL JOB'S PTY DDB
;	U=LDB ADDRESS
;PRESERVES T3 AND T4 (SEE SNDHED IN COMCON)
	INTERN	CTLJB,CTLJBD
CTLJBD:	JUMPE	F,CTLJB1	;IF DDB=0 GIVE -1 RETURN
	HRRZ	U,DDBLDB(F)	;IF DETACHED, JOB IS NOT CONTROLLED
;FALL INTO CTLJBU
;
;SUBROUTINE TO FIND JOB NUMBER OF JOB CONTROLING THIS LINE.
;ARGS U=ADDRESS OF LDB
;VALUE IS SAME AS CTLJBD
CTLJBU::JUMPE	U,CTLJB1
	LDB	T2,LDPLNO	;GET UNIT NUMBER OF TTY
CTLJB:	SUBI	T2,PTYOFS	;CONVERT TO LINKED PTY
	JUMPL	T2,CTLJB1	;IF NEGATIVE, ITS A REAL TTY
	CAIL	T2,PTYN		;IS IT A LEGAL PTY NUMBER (BETTER BE)
	JRST	CTLJB1		;NO-MUST BE ON REMOTE
	MOVE	F,PTYTAB(T2)	;GET PTY DDB FOR THIS CONTROLLER
	LDB	T1,PJOBN	;GET GUY WHO INITED IT
	POPJ	P,		;RETURN THIS TO USER

CTLJB1:	MOVNI	T1,1		;RETURN MINUS ONE IF NOT CONTROLLED BY PTY
	POPJ	P,		; ..

;STILL IN FTPTYUUO CONDITIONAL
;ROUTINE TO RETURN STATUS OF JOB REQUESTED, AND ITS PTY IF ANY

EXTERNAL USRJDA,PTYOFS,PUNIT,TTPLEN,LDBDDB,LINTAB,LDBCMF
EXTERNAL JBTSTS,PJOBN,LDBDCH,LDLCOM,DDBLDB,LDBTOC,TTYOUW

UJBSTS:	MOVEI	U,0		;INITIALIZE AS A FLAG FOR BELOW
	JUMPL	T1,UJBST1	;ASKING FOR JOB OR PTY?
IFE FTVM,<
	CAMLE	T1,.CPHCU##(P4)	;CHAN TOO BIG?
	JRST	CHKUDX		;YES--LOOSE
	ADD	T1,P4		;POUNT TO CORRECT SLOT
	SKIPN	F,.CPJDA##(T1)	;GET DDB POINTER
>
IFN FTVM,<
	CAMG	T1,USRHCU##
	SKIPN	F,USRJDA##(T1)
>
	JRST	CHKUDX		;NONE-ERROR
UJBST0:	HLRZ	T1,DEVNAM(F)	;CHECK TO SEE IF ITS A PTY
	CAIE	T1,(SIXBIT /PTY/)	; ..
	POPJ	P,0		;NOT. GIVE FAIL RETURN.
	LDB	T1,PUNIT	;ITS A PTY. GET ITS NUMBER
	ADDI	T1,PTYOFS	;CONVERT TO TTY NUMBER IT CONTROLS
	CAIL	T1,TTPLEN	;A LEGAL TTY NUMBER (BETTER BE)
	POPJ	P,0		;SYSTEM FAILURE. GIVE ERR RET
	HRRZ	U,LINTAB(T1)	;GET LDB OF THE TTY
	HRRZ	F,LDBDDB(U)	;FOLLOW TO ATTACHED TTY DDB
	SKIPE	T1,F		;IF NONE, CLEAR T1
	LDB	T1,PJOBN	;GET JOB NUMBER OF CONTROLLED JOB
;MORE
UJBST1:	MOVMS	J,T1		;GET POSITIVE, IF USER SUPPLIED -JOB NUMBER
	PUSHJ	P,LGLPR1##	;MAKE SURE ITS A LEGAL JOB NUMBER
	  POPJ	P,0		;NOT.
	AOS	0(P)		;OK. FROM HERE ON, GIVE GOOD RETURN
IFN FTMS,<
	CAMN	J,COMJOB##	;TARGET JOB IN COMCON ON CPU0
				; SO THAT THESE BITS MIGHT BE CHANGING?
	PUSHJ	P,ONCPU0##	;YES, AVOID THE RACE
>
	PUSHJ	P,UJBSTX	;GET STATUS BITS
	PJRST	STOTAC		;AND SUPPLY THEM TO THE USER

UJBSTX:: MOVE	T2,JBTSTS(J)	;GET BITS FROM JOB STATUS TABLE
	MOVEI	T1,0(J)		;CLEAR LH, GET JOB NUMBER
	TLNE	T2,JNA		;MAKE SURE JOB EXISTS
	TLO	T1,(1B0)	;NOT ASSIGNED
	TLNE	T2,JLOG		;LOGGED IN?
	TLO	T1,(1B1)	;YES.
	TLNE	T2,JACCT	;IN PRIV CUSP?
	TLO	T1,(1B5)	;YES. THIS BIT MAY BE MORE COMPLEX SOON
	JUMPN	U,UJBST2	;IF LINE KNOWN LINE, SKIP THIS PART
	HRRZ	F,TTYTAB(J)	;NOW FIND TTY STATUS FOR THIS JOB
	JUMPE	F,CPOPJ##	;IF DETACHED, JUST STORE THIS
	HRRZ	U,DDBLDB(F)	;GET LDB ADDR
	JUMPE	U,CPOPJ		;REDUNDANT DETACH CHECK
UJBST2:	SKIPLE	LDBTOC(U)	;OUTPUT AVAILABLE?
	TLO	T1,(1B3)	;YES. FLAG IT.
	MOVE	T2,LDBDCH(U)	;GET LINE BITS
	TLNN	T2,LDLCOM	;AT COMMAND LEVEL?
	JRST	UJBSTU		;NO.
	TLO	T1,(1B2)	;FLAG COMMAND LEVEL
	MOVE	T2,JBTSTS(J)	;GET JOB STATUS BACK
IFN FTJCON,<
	SKIPN	LDBECC##(U)	;NO TI IF STILL ECHOING
	TRNE	T2,JDCON	;IS JOB IN DEVICE ERROR WAITR?
	POPJ	P,0		;YES DON'T TELL CALLER ABOUT TI HERE
>
	TLNN	T2,CMWB+RUN	;IDLE?
	SKIPGE	0(U)		;AND NO COMMAND WAITING TO BE SEEN?
	POPJ	P,0		;NOT IDLE, RETURN ANSWER TO CALLER
				;IDLE. FLAG IT.
				;RETURN ANSWER TO CALLER
	PJRST	UJBST3
UJBSTU:
	JUMPE	F,CPOPJ		;IF NO ATTACHED JOB, STORE THIS MUCH
IFN	FTMIC,<
	SKIPE	LDBECC(U)	;STILL CHARS TO ECHO?
	POPJ	P,		;YES - CAN'T BELIEVE JBTSTS
>	;END OF FTMIC
	MOVE	S,DEVIOS(F)	;GET TTY STATUS WORD
	TLNE	S,IOW		;IN A WAIT?
	TLNE	S,TTYOUW	;WAITING FOR INPUT?
	POPJ	P,0		;NO
UJBST3:	MOVE	T2,0(U)		;IF THERE IS AN UNPROCESSED FORCED COMMAND
	TLNN	T2,LDBCMF	; OUTSTANDING, DON'T LIGHT WAITING FOR INPUT
	TLO	T1,(1B4)	;YES. FLAG IT.
	POPJ	P,0		;RETURN ANSWER TO CALLER

>	;END CONDITIONAL ON FTPTYUUO
IFE FTPTYUUO,<
CTLJOB==CPOPJ##
UJBSTS==CPOPJ##
>
;ROUTINE TO CAUSE PTY CONTROL JOB TO START TAKING CHARACTERS
;FROM THE CONTROLLED TTY'S OUTPUT CHARACTER LIST. CALLED AT END
;OF VARIOUS TTY OUTPUT UUOS AND TTCALLS.
;USES P4 AND W, SO DON'T CALL THIS ROUTINE AT
;INTERRUPT LEVEL UNLESS YOU SAVED THEM.

INTERN PTYPE
EXTERN LDPLNO,PTYOFS,PTYTAB

PTYPE:	PUSH	P,W		;SAVE AC'S IN CASE NEEDED
	PUSH	P,P4		; ..
	LDB	T1,LDPLNO	;GET TTY LINE NUMBER
	SUBI	T1,PTYOFS	;CONVERT TO PTY UNIT NUMBER
	HRRZ	P4,PTYTAB(T1)	;GET PTY DDB ADDRESS
	MOVEI	W,IOPTRE	;RESPONSE BIT TO CONTROLLER
	IORB	W,DEVIOS(P4)	;SET IN CORE.
	PUSHJ	P,PTWAKE	;WAKE UP CONTROLLER
	JRST	P2POPJ		;RESTORE AC'S AND RETURN
;ROUTINE TO SEARCH CLOCK QUEUE FOR JOB CONTROLLING THIS PTY, TO SEE
;IF THAT JOB IS SLEEPING, AND IF SO TO REDUCE SLEEP TIME TO ONE TICK
;SO IT WILL WAKE UP AND START SERVICING THE PTY.

	EXTERN	CLKCHG,PJBNLH

;CALL WITH P4 SET TO PTY'S DDB. CLOBBERS T1,T2,T3

PTWAKE:	PUSH	P,T3		;SAVE CHARACTER AC
IFN FTPI,<
IFE FTVM,<
	SKIPN	JBTADR##(J)	;CAN'T GET EXTENDED PDL IF NO CORE
	JRST	PTWAK1		; SO DON'T BOTHER WITH INT.
>
	MOVE	T2,DEVIOS(P4)	;GET STATUS
	TRNN	T2,IOPTW	;PTY HUNGRY
	TDZA	T1,T1		;NO, NO BITS YET
	MOVEI	T1,IR.OUD	;YES, ASK FOR OUTPUT
	TRNE	T2,IOPTRE	;OUTPUT AVAILABLE
	TRO	T1,IR.IND	;ASK CONTROLLER TO READ IT
	JUMPE	T1,PTWAK1	;IGNORE IF NO BITS
	PUSH	P,F		;SAVE F
	HRRZ	F,P4		;PUT DDB ADDRESS THERE
	PUSHJ	P,PSIDVB##	;GENERATE AN INTERRUPT
	POP	P,F		;RESTORE F
PTWAK1:
> ;END FTPI
IFN FTHIBWAK,<	EXTERN WAKPST,PTYWUE,JBTRTD
	LDB	T1,PTYPJN	;GET CONTROLLING JOB'S JOB NUMBER
	MOVSI	T2,PTYWUE	;IS THE CONTROL HIBERNATING ON PTY'S
	TDNE	T2,JBTRTD(T1);WAKE JOB ONLY IF IT IS ENABLED FOR PTY WAKE
	PUSHJ	P,WAKPST	;GO WAKE THIS CONTROLLER JOB
>
IFE FTHIBWAK,<
	LDB	T1,PTYPJN	;GET CONTROLLER JOB AGAIN
	MOVEI	T2,1		;CHANGE CLOCK REQUEST TO 1 JIFFY
	MOVEI	T3,CLKR		;CLOCK1 REQUEST BIT
	TDNE	T3,JBTSTS##(T1)	;JOB HAVE A CLOCK REQUEST IN?
	PUSHJ	P,CLKCHG	;YES, SEARCH CLOCK QUEUE, WAKE CONTROLLER
	  JFCL			;IGNORE NOT FOUND RETURN
>
	POP	P,T3		;RESTORE CHARACTER AC
	POPJ	P,0		;AND RETURN.

PTYPJN:	XWD	PJBNLH+P4,DEVJOB  ;COPY OF PJOBN WITH DIFFERENT XR.
;ROUTINES TO KEEP CONTROL JOB INFORMED OF TTY LINE'S STATUS, AND
;TO WAKE CONTROLLER IF APPROPRIATE.
;CALL FROM SCNSER WITH LINE SET TO TTY'S LDB

EXTERNAL LDPLNO,PTYOFS,PTYTAB
INTERNAL PTYOW,PTMNMD,PTMNMZ

PTMNMD:	PUSH	P,W		;SAVVE THIS AC
	MOVEI	W,MONMOD!IOPTW	;LINKED TTY WENT TO MONITOR MODE
	JRST	PTYSET		;GO SET BIT

PTMNMZ:	PUSH	P,W		;SAVE THIS AC
	HRROI	W,MONMOD	;JOB WENT TO USER MODE
	JRST	PTYSET		;GO CLEAR BIT

PTYOW:	PUSH	P,W		;SAVE THIS AC
	MOVEI	W,IOPTW		;CONTROLLED TTY IN INPUT WAIT.
PTYSET:	PUSH	P,P4		;SAVE AC POSSIBLY NEEDED ELSEWHERE
	LDB	P4,LDPLNO	;GET LINE NUMBER OF CONTROLLED TTY
	SUBI	P4,PTYOFS	;CONVERT TO PTY UNIT NUMBER
	HRRZ	P4,PTYTAB(P4)	;GET THAT UNIT'S PTY DDB
	TLZE	W,-1		;CLEARING OR SETTING BIT IN S WORD?
	ANDCAB	W,DEVIOS(P4)	;CLEARING.
	IORB	W,DEVIOS(P4)	;(SETTING)
	TRNE	W,IOPTW		;WANT TO WAKE CONTROLLER?
	PUSHJ	P,PTWAKE	;YES. DO SO.
P2POPJ:	POP	P,P4		;RESTORE AC'S
	JRST	WPOPJ##		;AND RETURN

CHKUDX:	IFN FTMS,<
	PUSHJ	P,ONCPU0##	;RESCHEDULE
> ;END FTMS
	PUSHJ	P,DVCNSG##	;LOOK FOR UDX
	  POPJ	P,0		;ERROR
	JRST	UJBST0		;OK
;SUBROUTINE TO SWAP PTY AND TTY DDB AND S AC'S

PTEXCH:	EXCH	S,W		;SWAP THE STATUS ACS
	EXCH	F,P4		;SWAP THE DATA BLOCK AC'S
	POPJ	P,0		;AND RETURN

;SUBROUTINE TO SET UP AC LINE FOR A PTY UUO. CALL WITH DDB AT PTY'S DDB.
;P4 WILL GET DDB, LINE WILL GET LDB OF RELATED TTY.

EXTERN PUNIT,PTYOFS,LDBDCH,LINTAB

PTSETL:	LDB	U,PUNIT		;GET UNIT NUMBER OF THE PTY
	ADDI	U,PTYOFS	;CONVERT TO TTY LINE NUMBER
	HRRZ	U,LINTAB(U)	;GET LDB ADDRESS
	HLL	U,LDBDCH(U)	;AND CHARACTERISTICS BITS TOO
	MOVE	P4,F		;MAKE WAY FOR SCNSER TO USE DDB
	POPJ	P,0		;AND RETURN

;END OF PTY SERVICE ROUTINE

LIT

PTYEND:	END