Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/filmsc.mac
There are 52 other files named filmsc.mac in the archive. Click here to see a list.
;<3A.MONITOR>FILMSC.MAC.4, 17-May-78 11:10:53, EDIT BY MILLER
;FIX UP HANDLING OF RSCNBP TO AVOID SYSTEM CRASHES. CURRENT RSCAN
; CODE IS STILL WRONG AND FULL OF RACES
;<3A.MONITOR>FILMSC.MAC.3, 22-Feb-78 16:33:07, EDIT BY MILLER
;RETRY IN PTYIN IF TTSTO DOESN'T SKIP
;<3A.MONITOR>FILMSC.MAC.2, 20-Feb-78 14:54:01, EDIT BY MILLER
;FIX TYPEO IN TTYOPN
;<3.SM10-RELEASE-3>FILMSC.MAC.1,  6-Dec-77 15:01:03, EDIT BY MILLER
;CHECK FOR TTY ACCESS IN CERTAIN TTY MTOPRS.
;CHANGE RETBAD TO RETERR IN RSCAN JSYS
;<3-MONITOR>FILMSC.MAC.102,  7-Nov-77 13:01:55, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<3-MONITOR>FILMSC.MAC.101, 12-Oct-77 13:46:36, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>FILMSC.MAC.100, 19-Sep-77 09:54:36, EDIT BY HELLIWELL
;FIX PROTECTION AND STATUS INSERTION DISPATCHES IN NILDTB
;<3-MONITOR>FILMSC.MAC.99, 17-Aug-77 16:37:14, EDIT BY HURLEY
;FIX TTY AND PTY HUNGRY MTOPR FOR LINE ACTIVATION
;<3-MONITOR>FILMSC.MAC.98, 11-Aug-77 14:33:40, EDIT BY MILLER
;CHECK FOR DETACHED JOB IN TTYIN CODE
;<3-MONITOR>FILMSC.MAC.97, 30-Jul-77 01:43:08, EDIT BY CROSSLAND
;REMOVE SPECIAL CHECKS FOR NVT'S
;<3-MONITOR>FILMSC.MAC.96, 17-Jun-77 14:45:27, EDIT BY HALL
;TCO 1740 - MAKE PTYCLZ NOSKED WHILE DEASSIGNING TTY DATA AND 
;	CLEARING PTYSTS (FIX RACE)
;<3-MONITOR>FILMSC.MAC.95, 17-Jun-77 00:24:20, EDIT BY CROSSLAND
;FIX UP NVTDET CALL
;<3-MONITOR>FILMSC.MAC.94, 24-May-77 10:34:31, EDIT BY KIRSCHEN
;TCO 1802 - ADD SUPPORT FOR .MOSIG (IGNORE INPUT) FUNCTION
;<3-MONITOR>FILMSC.MAC.93, 23-May-77 14:19:24, EDIT BY HALL
;MADE OPEN AND CLOSE OF 'TTY:' ALWAYS SUCCEED
;<3-MONITOR>FILMSC.MAC.92,  8-May-77 19:01:54, EDIT BY CROSSLAND
;<3-MONITOR>FILMSC.MAC.91,  6-May-77 11:53:06, EDIT BY HURLEY
;ADD SET INPUT/OUTPUT AND ATTRIBUTE CHECK ENTRIES IN DISPATCH TABLE
;<3-MONITOR>FILMSC.MAC.90,  3-May-77 17:40:21, EDIT BY CROSSLAND
;TCO 1742 MERGE ARPANET SOURCES
;<3-MONITOR>FILMSC.MAC.89,  2-May-77 20:32:14, EDIT BY BOSACK
;<3-MONITOR>FILMSC.MAC.88, 14-Apr-77 16:49:47, EDIT BY HALL
;TCO 1740 - MADE TTYDAS ASSUME DEVICE LOCK IS LOCKED RATHER THAN LOCKING
;<3-MONITOR>FILMSC.MAC.87, 13-Apr-77 18:34:22, EDIT BY HALL
;TCO 1740 - BUG FIX IN TTMSLN - FORGOT TO CALL ULKTTY
;<3-MONITOR>FILMSC.MAC.86,  6-Apr-77 14:31:09, EDIT BY HALL
;TCO 1740 - MAKE TTYOPN CHECK FOR 'TTY'
;<3-MONITOR>FILMSC.MAC.85,  9-Mar-77 16:06:18, EDIT BY HALL
;TCO 1740 - MADE TTYDAS RETURN FAILURE TO CALLER RATHER THAN WAIT
;<3-MONITOR>FILMSC.MAC.84, 23-Feb-77 20:11:54, EDIT BY HALL
;TCO 1740 - MASSIVE CHANGES FOR TELETYPE REORGANIZATION
;<3-MONITOR>FILMSC.MAC.83,  3-Feb-77 21:01:59, Edit by MCLEAN
;<3-MONITOR>FILMSC.MAC.82,  1-Feb-77 19:04:45, EDIT BY HURLEY
;<3-MONITOR>FILMSC.MAC.81,  1-Feb-77 18:15:56, EDIT BY HURLEY
;MAKE OUTPUT TO DEV TTY: ALWAYS GO TO CONTROLING TTY
;<3-MONITOR>FILMSC.MAC.80, 13-Jan-77 18:25:38, Edit by MCLEAN
;TCO 1669 EXTENDED ADDRESSING
;<3-MONITOR>FILMSC.MAC.79, 13-Jan-77 16:47:19, EDIT BY HALL
;COMMENTS
;<3-MONITOR>FILMSC.MAC.78, 12-Jan-77 15:50:54, Edit by MCLEAN
;<3-MONITOR>FILMSC.MAC.77, 11-Jan-77 16:04:18, Edit by MCLEAN
;<3-MONITOR>FILMSC.MAC.76, 11-Jan-77 15:20:35, EDIT BY HALL
;COMMENTS ON TTYDTB
;<3-MONITOR>FILMSC.MAC.75, 27-Dec-76 17:32:17, EDIT BY HURLEY
;<2-MONITOR>FILMSC.MAC.74,  4-Nov-76 15:13:52, EDIT BY HURLEY
;TCO 1604- ADD NEW MTOPR FCN CODE TO SUPPRESS TTY MSG
;<2-MONITOR>FILMSC.MAC.73, 22-Oct-76 23:28:35, EDIT BY OSMAN
;TCO 1618 - FIX TTY BIN TO NOT READ FROM RSCAN BUFFER IF
;	      BKJFN WAS JUST DONE (USE BACKED UP CHAR FIRST)
;<2-MONITOR>FILMSC.MAC.72, 18-Oct-76 13:54:46, EDIT BY HURLEY
;TCO 1606 - FIX NUL: TO NOT CRASH ON GDSTS OR SDSTS
;<2-MONITOR>FILMSC.MAC.71, 12-Oct-76 10:39:46, EDIT BY MILLER
;RETURN MTOPR RESULTS IN 3 INSTEAD OF 2
;<2-MONITOR>FILMSC.MAC.70, 11-Oct-76 08:42:48, EDIT BY HURLEY
;TCO 1579 - MAKE PTY'S BE IDEAL TERMINALS
;<2-MONITOR>FILMSC.MAC.69,  7-Oct-76 11:26:54, EDIT BY MILLER
;TCO 1570. ADD MTOPR'S TO SET LENGTH AND WIDTH OF TTY'S
;<2-MONITOR>FILMSC.MAC.68,  6-Oct-76 19:17:18, EDIT BY HURLEY
;<2-MONITOR>FILMSC.MAC.67,  6-Oct-76 17:02:27, EDIT BY HURLEY
;<2-MONITOR>FILMSC.MAC.66,  6-Oct-76 16:07:52, EDIT BY HURLEY
;TCO 1571 - MAKE RSCAN BUFFER BE DYNAMICALLY ASSIGNED
;<2-MONITOR>FILMSC.MAC.65,  1-Oct-76 16:44:20, EDIT BY HURLEY
;MAKE NUL DEVICE BE OPENABLE IN BOTH READ AND WRITE MODES
;<2-MONITOR>FILMSC.MAC.64, 30-Sep-76 17:31:04, EDIT BY OSMAN
;<2-MONITOR>FILMSC.MAC.63, 30-Sep-76 17:26:06, EDIT BY OSMAN
;TCOS 1551-1552 1 IN AC1 FOR RSCAN MEANS COUNT REMAINING CHARS
;<1B-MONITOR>FILMSC.MAC.62, 16-Jun-76 19:24:26, EDIT BY HURLEY
;<1B-MONITOR>FILMSC.MAC.61, 16-Jun-76 19:21:00, EDIT BY HURLEY
;MORE OF TCO 1352 - MAKE TTYIN USE JOBPT IF DEVICE IS TTY:
;<1B-MONITOR>FILMSC.MAC.60, 16-Jun-76 19:08:34, EDIT BY HURLEY
;<1B-MONITOR>FILMSC.MAC.59, 16-Jun-76 18:00:26, EDIT BY HURLEY
;TCO 1440 - ALLOW ALL OPERATIONS TO BE SUCCESSFUL TO NUL DEVICE
;<1B-MONITOR>FILMSC.MAC.58, 10-JUN-76 17:51:56, EDIT BY HURLEY
;MORE OF TCO 1352
;<1B-MONITOR>FILMSC.MAC.57, 10-JUN-76 16:44:24, EDIT BY HALL
;TCO 1397 - ADDED RANGE CHECK ON CHANNEL NUMBER IN PTENAI
;<1B-MONITOR>FILMSC.MAC.56,  7-JUN-76 14:15:38, EDIT BY HURLEY
;TCO # 1352 - MAKE DETACHED FORK TO NO LONGER WAIT ON DETACHED TTY
;<1B-MONITOR>FILMSC.MAC.55, 26-MAY-76 12:57:19, EDIT BY MILLER
;TCO 1320. SET REFUSE ADVICE AT JOB INIT
;<1MONITOR>FILMSC.MAC.54, 23-MAR-76 18:18:04, EDIT BY HURLEY
;<1MONITOR>FILMSC.MAC.53, 23-MAR-76 17:17:57, EDIT BY HURLEY
;TCO 1216 - MAKE ALL UNSUPPORTED DISPATCH ENTRIES RETURN AN ERROR CODE
;<1MONITOR>FILMSC.MAC.52,  2-MAR-76 13:14:37, EDIT BY HURLEY
;TCO #1140 - CLEAR PTYSTS BITS ON OPEN AND CLOSF
;<2MONITOR>FILMSC.MAC.51,  3-FEB-76 20:32:55, EDIT BY MILLER
;FIX MCO 42 EDIT TO INCLUDE A RET
;<2MONITOR>FILMSC.MAC.50, 29-JAN-76 18:09:13, EDIT BY MURPHY
;MCO #42
;<2MONITOR>FILMSC.MAC.49, 16-JAN-76 17:47:32, EDIT BY MURPHY
;<2MONITOR>FILMSC.MAC.48, 23-DEC-75 12:48:59, EDIT BY LEWINE


;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.

	SEARCH PROLOG
	TTITLE FILMSC		;MISC - TTY, PTY, STRING AND NIL
	SWAPCD

;SPECIAL AC DEFINITIONS USED HEREIN

DEFAC (U,Q1)			;UNIT NUMBER
DEFAC (IOS,Q2)			;DEVICE STATUS FLAGS
DEFAC (STS,P1)			;SEE GTJFN FOR FUNCTIONS
DEFAC (JFN,P2)
DEFAC (DEV,P4)
DEFAC (F1,P5)

	SUBTTL NUL DEVICE FUNCTIONS

NILDTB::IFIW!NILSET
	IFIW!NILLKP		;NAME LOOKUP
	IFIW!NILLKP		;EXT LOOKUP
	IFIW!NILVLK		;VER LOOKUP
	DTBBAD			;PROTECTION INSERTION
	DTBSKP			;ACCOUNT INSERTION
	DTBBAD			;STATUS INSERTION
	IFIW!NILOPN		;OPEN
	IFIW!NILSQI		;INPUT
	IFIW!NILSQO		;OUTPUT
	DTBSKP			;CLOSF
	DTBSKP			;RENAME
	DTBSKP			;DELETE
	DTBBAD (DUMPX6)		;DUMPI
	DTBBAD (DUMPX6)		;DUMPO
	DTBSKP			;MOUNT
	DTBSKP			;DISMOUNT
	DTBSKP			;INIT DIRECTORY
	DTBSKP			;MTOPR
	DTBBAD			;DEVICE STATUS READ
	DTBBAD			;DEVICE STATUS SET
	DTBSKP			; RECORD OUT
	IFIW!RFTADN		; READ TAD
	IFIW!SFTADN		; SET TAD
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-NILDTB	;GLOBAL LENGTH OF DISPATCH TABLE

NILOPN:	TQCE <RNDF>		;WANT APPEND?
	TQO <WRTF>		;YES. LIGHT WRITE BIT THEN
	SETZB A,B
	CAIN JFN,377777
	RET			;ALL DONE FOR THIS GUY
	TQNN <READF>		;IS IT READ?
	HRLOI A,377777		;NO. DO OUTPUT
	MOVEM A,FILCNT(JFN)	;STORE COUNT
	SETZB A,FILBYT(JFN)	;RETURN ZEROS
	RETSKP			;AND RETURN SUCCESSFULLY

NILSQO:	SETZB A,B
	CAIN JFN,377777
	 RET
	TQNN <READF>		;IS IT READ?
	HRLOI A,377777		;NO, SET UP LARGE COUNT
	MOVEM A,FILCNT(JFN)
	SETZB A,FILBYT(JFN)
	RET

NILSQI:	TQO <EOFF>		;GENERATE EOF ON INPUT
	RET

NILSET:	TQO <NNAMF,NVERF>
	JRST SK2RET


NILLKP:	JUMPE A,SK2RET		;IF FIRST TIME, ALLOW IT
	TQNN <STEPF>		;STEPPING
	JRST SK2RET		;NO, GIVE OK RETURN
	RETBAD (GNJFX1)		;NO MORE NAMES

NILVLK:	CAME A,[-2]		;FIRST TIME?
	TQNN <STEPF>		;OR NOT STEPPING
	RETSKP			;THEN SAY OK
	RETBAD (GNJFX1)		;NO MORE VERSIONS
	SUBTTL STRING DEVICE FUNCTIONS

STRDTB::DTBBAD (GJFX32)	;DIR SET
	REPEAT BIND-1,<
	DTBBAD (DESX9)>
	STRIN
	IFIW!STROUT
	REPEAT DELD-BOUTD,<
	DTBBAD (DESX9)>
	DTBBAD (DUMPX6)		;DUMPI
	DTBBAD (DUMPX6)		;DUMPO
	DTBBAD (DESX9)		;MOUNT
	DTBBAD (DESX9)		;DISMOUNT
	DTBBAD (DESX9)		;INITIALIZE DIR
	DTBBAD (MTOX1)		; MTOPR
	DTBBAD (DESX9)		;GET DEV STATUS
	DTBBAD (DESX9)		;SET DEV STATUS
	DTBSKP			;RECORD OUT
	IFIW!RFTADN		; READ TAD
	IFIW!SFTADN		; SET TAD
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-STRDTB	;GLOBAL LENGTH OF DISPATCH TABLE

STRIN:	XCTBU [ILDB A,JFN]
	RET

STROUT:	XCTBU [IDPB A,JFN]
	RET

;DECREMENT BYTE POINTER
; A/ BYTE PTR
;	CALL DBP
; RETURNS +1, CLOBBERS B AND C

DBP::
	MOVNI T2,1		;ADJUST BY -1
	ADJBP T2,T1
	MOVEM T2,T1		;RETURN RESULT
	RET			;AND DONE
	SUBTTL PTY DEVICE FUNCTIONS

;DEVICE DEPENDENT ROUTINES. TO DO CERTAIN FUNCTIONS, THE RH OF DEV
;CONTAINS THE NAME OF A TABLE SUCH AS PTYDTB, AND A ROUTINE IS CALLED
;VIA 'CALL @FOO(DEV)', WHERE FOO IS A SYMBOL FOR AN OFFSET INTO THE 
;TABLE. THE SYMBOLS ARE DEFINED IN PROLOG. IN THE COMMENTS BELOW,
;THE OFFSET IS INDICATED ALONG WITH THE PURPOSE OF THE ROUTINE

PTYDTB::IFIW!PTYSET		;DLUKD - DIRECTORY SETUP
	DTBBAD (DESX9)		;INLUKD - NAME LOOKUP
	DTBBAD (DESX9)		;ELUKD - EXTENSION LOOKUP
	DTBBAD (DESX9)		;VLUKD - VERSION LOOKUP
	DTBBAD (DESX9)		;PULKD - PROTECTION INSERTION
	DTBBAD (DESX9)		;ALUKD - ACCOUNT INSERTION
	DTBBAD (DESX9)		;SLUKD - STATUS INSERTION
	IFIW!PTYOPN		;OPEND - OPEN FILE
	IFIW!PTYIN		;BIND - BYTE INPUT
	IFIW!PTYOUT		;BOUTD - BYTE OUTPUT
	IFIW!PTYCLZ		;CLOSD - CLOSE FILE
	DTBBAD (DESX9)		;REND - RENAME
	DTBBAD (DESX9)		;DELD - DELETE FILE
	DTBBAD (DUMPX6)		;DMPID - DUMP MODE INPUT
	DTBBAD (DUMPX6)		;DMPOD - DUMP MODE OUTPUT
	DTBBAD (DESX9)		;MNTD - MOUNT DEVICE
	DTBBAD (DESX9)		;DSMD - DISMOUNT DEVICE
	DTBBAD (DESX9)		;INDD - INITIALIZE DIRECTORY OF DEVICE
	IFIW!PTMTOP		;MTPD - DO MTAPE OPERATION
	DTBBAD (DESX9)		;GDSTD - GET DEVICE STATUS
	DTBBAD (DESX9)		;SDSTD - SET DEVICE STATUS
	DTBSKP			;RECOUT - FORCE RECORD OUT (SOUTR)
	IFIW!RFTADN		;RFTADD - READ FILE TIME AND DATE
	IFIW!SFTADN		;SFTADD - SET FILE TIME AND DATE
	DTBDSP (BIOINP)		;SET JFN FOR INPUT
	DTBDSP (BIOOUT)		;SET JFN FOR OUTPUT
	DTBBAD (GJFX49)		;CHECK ATTRIBUTE

	DTBLEN==:.-PTYDTB	;GLOBAL LENGTH OF DISPATCH TABLE

	DEFSTR (PTYFRK,PTYSTS(U),35,18) ;FORK INDEX OF OWNER
	DEFSTR (PTYCHN,PTYSTS(U),17,6) ;PSI CHANNEL NUMBER

;BITS IN AC 'IOS' - SEE DEFAC AT BEGINNING OF MODULE

FLG(POPEN,L,IOS,400000)		;PTY IS OPEN
FLG(PIIEN,L,IOS,200000)		;INPUT INTERRUPT ENABLED
FLG(POIEN,L,IOS,100000)		;OUTPUT INTERRUPT ENABLED
FLG(PIIEV,L,IOS,040000)		;INPUT EVENT OCCURRED
FLG(POIEV,L,IOS,020000)		;OUTPUT EVENT OCCURRED
FLG(PTBAT,L,IOS,010000)		;PTY IS BEING CONTROLED BY BATCH
;FUNCTION DLUKD FOR PTY - DIRECTORY SETUP

PTYSET:	TQO <NNAMF,NVERF>	;SAY NO NAME, VERSION, ETC
	RETBAD (GJFX32)

;OPEND FUNCTION FOR PTY - OPEN FILE

;ACCEPTS:
;	JFN/ JOB FILE NUMBER
;	DEV/ (UNIT NUMBER,,DISPATCH ADDRESS)

;CALL PTYOPN

;RETURNS +1: FAILURE
; 	 +2: SUCCESS

PTYOPN:	STKVAR <PTYOLN>
	CALL CHKAPD		;FIX APPEND BIT
	HLRZ U,DEV		;GET UNIT NUMBER
	MOVE IOS,PTYSTS(U)
	TQOE <POPEN>		;ALREADY OPEN?
	RETBAD OPNX9		;YES
	HLRZ T2,DEV		;T2/ PTY NUMBER
	CALL PTYTTY		;GET CORRESPONDING TELETYPE NUMBER
	MOVEM T2,PTYOLN		;SAVE LINE NUMBER
	CALL STADYN		;IS LINE ALREADY ACTIVE?
	 SKIPA			;NO
	RETBAD (OPNX7)		;YES. INDICATE ASSIGNED TO ANOTHER JOB
	MOVE T2,PTYOLN		;T2/ LINE NUMBER
	CALL TTYASC		;ASSIGN DYNAMIC DATA FOR LINE
	 RETBAD			;FAILED
	MOVE T2,PTYOLN		;T2/ LINE NUMBER
	MOVEI T1,-1		;T1/ JOB NUMBER
	CALL STCJOB		;INDICATE NO CONTROLLING JOB FOR TERMINAL
	MOVE T2,PTYOLN		;T2/ LINE NUMBER
	CALL STADYN		;POINT TO DYNAMIC DATA
	 JRST PTYOP1		;SHOULDN'T HAPPEN
	CALL STPRM		;MAKE THE DATA PERMANENT UNTIL PTY IS CLOSED
	MOVX IOS,POPEN		;SET THAT PTY IS NOW OPEN
	HRR IOS,FORKX		;REMEMBER FORK DOING OPEN
PTYRET:	MOVEM IOS,PTYSTS(U)
	RETSKP

PTYOP1:	BUG(CHK,TTNAC1,<LINE NOT ACTIVE AT PTYOPN>)
	RETBAD (TTYX01)
;FUNCTION BIND FOR PTY - BYTE INPUT

;ACCEPTS:
;	DEV/ (UNIT,,DISPATCH ADDRESS)

;	CALL PTYIN

;RETURNS +1: ALWAYS,
;		T1/ A CHARACTER

;GETS A CHARACTER FROM THE ASSOCIATED TERMINAL'S OUTPUT BUFFER TO
;SERVE AS INPUT ON THE PTY.  BLOCKS IF NECESSARY. ALWAYS RETURNS WITH
;CHARACTER

PTYIN:	HLRZ 2,DEV
	CALL PTYTTY		;GET INTERNAL LINE NUMBER
	CALL LCKTTY		;GET ADDRESS OF DYNAMIC DATA AND PREVENT
				; DEALLOCATION
	 JRST [	CALL ULKTTY	;NOT FULLY ACTIVE. ALLOW DEALLOCATION
		TQO <ERRF>	;INDICATE ERROR
		RET]
	CALL TTSTO		;GET CHAR FROM LINE, BLOCK IF NONE
	 JRST PTYIN		;TRY AGAIN
	CALL ULKTTY		;ALLOW DEALLOCATION
	RET

;FUNCTION BOUTD FOR PTY - BOUT OUTPUT

;ACCEPTS:
;	T1/ A CHARACTER
;	DEV/ (UNIT,,DISPATCH ADDRESS)

;	CALL PTYOUT

;RETURNS +1: ALWAYS

;FOR THE ASSOCIATED TERMINAL, SIMULATES REMOVING THE SPECIFIED
;CHARACTER FROM TTBBUF AND PLACING IT IN THE LINE'S INPUT BUFFER
;(ISSUING AN INTERRUPT IF NECESSARY, ECHOING, ETC.)

PTYOUT:	HLRZ 2,DEV		;GET PTY NUMBER
	CALL PTYTTY		;CONVERT TO INTERNAL LINE NUMBER
	CALL TTSTI		;PUT CHAR INTO LINE
	RET
;FUNCTION CLOSD FOR PTY - CLOSE FILE

;ACCEPTS:
;	DEV/ (UNIT,,DISPATCH ADDRESS)

;	CALL PTYCLZ

;RETURNS +1: FAILURE
;	 +2: SUCCESS

;ON FAILURE, IF BLOCKING IS NECESSARY, BLKF IS SET AND T1 CONTAINS
;(LINE NUMBER,,ADDRESS OF TEST ROUTINE)

PTYCLZ:	STKVAR <PTYCLN>
	HLRZ 2,DEV
	CALL PTYTTY		;GET LINE NUMBER
	MOVEM T2,PTYCLN		;SAVE LINE NUMBER
	CALL LCKTTY		;POINT TO DYNAMIC DATA
	 JRST [	CALL ULKTTY	;NOT ACTIVE
		JRST PTYCL1]	;SKIP DEALLOCATION AND DETACH
	CALL CLRPRM		;CLEAR PERMANENT BIT SO DEASSIGN WILL HAPPEN
	CALL ULKTTY		;ALLOW DEALLOCATION
	MOVE T2,PTYCLN		;T2/ LINE NUMBER
	CALL GTCJOB		;GET OWNING JOB
	 JRST PTYCL1		;LINE NOT ACTIVE. DON'T DETACH OR DEALLOCATE
	CAIN T3,-1		;ANY JOB?
	JRST PTYCL2		;NO. GO DEALLOCATE DATA

;A JOB EXISTS ON THIS LINE. GO DETACH IT. THIS WILL CAUSE THE TERMINAL
;DATA BLOCK TO BE DEASSIGNED

	NOSKED
	CALL NTYCOF		;CAUSE CARRIER OFF ACTION
	OKSKED
	JRST PTYCL1

;NO JOB EXISTS ON THIS LINE.  DEASSIGN TERMINAL'S DATA BASE
;AND INDICATE THAT THE PTY IS CLOSED

PTYCL2:	NOSKED			;NO INTERFERENCE UNTIL TTY AND PTY AGREE
	MOVE T2,PTYCLN		;T2/ LINE NUMBER
	CALL TTYDEA		;DEALLOCATE THE DYNAMIC DATA
	 JRST [	OKSKED
		JRST PTYCL4]	;FAILED. 
	HLRZ U,DEV		;GET PTY NUMBER
	SETZM PTYSTS(U)		;INDICATE PTY CLOSED
	OKSKED
	RETSKP

;TERMINAL SIDE IS NOT ACTIVE. INDICATE PTY IS CLOSED

PTYCL1:	HLRZ U,DEV		;GET PTY NUMBER
	SETZ IOS,		;CLEAR OPEN BIT AND ALL OTHERS
	JRST PTYRET

;UNABLE TO DEASSIGN. RETURN TO CALLER, WHICH WILL WAIT

PTYCL4:	TXZN T1,1B0		;FAILURE OR WAIT?
	RETBAD			;FAILURE. RETURN ERROR CODE
	HRL T1,T2		;WAIT. T1/(LINE NUMBER,,ROUTINE ADDRESS)
	TQO BLKF		;INDICATE WAIT NECESSARY
	RETBAD			;TAKE FAILURE RETURN
;FUNCTION MTPD FOR PTY - MTOPR

;ACCEPTS:
;	USER T2/ FUNCTION CODE
;	USER T3/ ARGUMENT OR ADDRESS OF ARGUMENT BLOCK
;	DEV/ (PTY NUMBER,,PTYDTB)

;	CALL PTMTOP

;RETURNS +1: FAILURE
;	 +2: SUCCESS

PTMTOP:	HLRZ U,DEV		;GET PTY NUMBER
	UMOVE 2,2		;GET FUNCTION CODE FROM USER
	MOVEI 3,0(2)		;MTOPR OP CODE
	CAIN 3,.MOAPI		;ASSIGN PTY INTERRUPT CHANNEL?
	JRST PTENAI		;ENABLE INTERRUPTS
	CAIN 3,.MOPIH		;PTY HUNGRY?
	JRST PTSTIH		;TEST INPUT HUNGRY
	CAIE 3,.MOBAT		;SET BATCH BIT?
	RETBAD (MTOX1)		;ILLEGAL FUNCTION
	MOVX T1,PTBAT		;INITIALIZE BATCH BIT TO 0
	ANDCAM T1,PTYSTS(U)
	XCTU [SKIPE 3]		;SETTING THE BATCH BIT?
	IORM T1,PTYSTS(U)	;YES, PTY IS A BATCH PTY
	RETSKP

;MTOPR FUNCTION .MOPIH - SEE IF PTY IS HUNGRY

;RETURNS +2: ALWAYS
;	USER T2/ 0 FOR NOT HUNGRY
;		 -1 FOR HUNGRY

PTSTIH:	MOVE T2,U		;T2/ PTY NUMBER
	CALL PTYTTY		;CONVERT TO INTERNAL LINE NUMBER
	CALL LCKTTY		;GET ADDRESS OF DYNAMIC DATA, PREVENT DEALLOCATION
	 JRST [	CALL ULKTTY	;NOT ACTIVE. ALLOW DEALLOCATION
		SETZ T1,	;ASSUME NOT HUNGRY
		SKIPN T2	;UNLESS LINE IS NOT ACTIVE AT ALL
		SETO T1,	;THEN MAKE IT HUNGRY
		JRST PTSTI1]
	CALL TTSTIH		;TEST INPUT HUNGRY ON TTY
	CALL ULKTTY		;ALLOW DEALLOCATION
PTSTI1:	UMOVEM 1,2		;RETURN ANSWER TO USER
	RETSKP
;MTOPR FUNCTION .MOAPI - ASSIGN INTERRUPT CHANNELS

PTENAI:	MOVE 3,FORKX		;GET THIS FORK'S INDEX
	HRRM 3,PTYSTS(U)	;REASSIGN FORK
	LDB 3,[POINT 6,2,17]	;GET CHANNEL ASSIGNMENT
	SKIPL 3			;IS THE CHANNEL NON-NEGATIVE?
	CAIL 3,<^D36-1>		;IS IT < 35?
	RETBAD (MTOX18)		;BAD VALUE. INPUT HAS TO BE <=34
				;SO OUTPUT CAN BE <=35
	STOR 3,PTYCHN		;REMEMBER IT
	MOVX 3,PIIEN		;INPUT INTERRUPT ENABLED FLAG
	ANDCAM 3,PTYSTS(U)
	TLNE 2,(MO%WFI)		;SET IT ACCORDING TO B0 OF ARG
	IORM 3,PTYSTS(U)
	MOVX 3,POIEN		;OUTPUT INTERRUPT ENABLED FLAG
	ANDCAM 3,PTYSTS(U)
	TLNE 2,(MO%OIR)		;SET IT ACCORDING TO B1 OF ARG
	IORM 3,PTYSTS(U)
	CALL PTTINT		;SEE IF INTERRUPT NOW POSSIBLE
	RETSKP
;PTYINI - ROUTINE CALLED FROM OPENF TO INITIALIZE THE PTY PARAMETERS

;ACCEPTS:
;	DEV/ UNIT,,CODE

;	CALL PTYINI

;RETURNS +1: ALWAYS

;INITIALIZES VALUES FOR THE TERMINAL ASSOCIATED WITH THE GIVEN PTY
;THIS IS DONE BEFORE THE JOB IS CREATED ON THE LINE SO THAT THE OWNER
;OF THE PTY CAN CONTROL THE LINE.  OPENING THE PTY HAS CAUSED THE
;ASSOCIATED TERMINAL TO HAVE PERMANENT DYNAMIC DATA, WHICH WILL
;BE DEALLOCATED WHEN THE PTY IS CLOSED

PTYINI::HLRZ B,DEV		;GET PTY UNIT
	CALL PTYTTY		;CONVERT TO LINE NUMBER
	MOVEI A,.TTDES(B)	;GET DESIGNATOR (400000+N)
	MOVE B,NORMTF		;GET NORMAL SETTING
	SFMOD			;SET MODES
	STPAR			;AND THESE AS WELL
	MOVEI B,.TTIDL		;SET IT TO BE "IDEAL" TERMINAL
	STTYP			;SET THE TYPE
	DMOVE B,TTICB1		;DEFAULT CONTROL ACTIONS
	SFCOC
	HRLI A,(TL%CRO+TL%COR+TL%SAB+TL%STA