Google
 

Trailing-Edge - PDP-10 Archives - BB-M836C-BM - tools/ttyini/ttyini.mac
There are 2 other files named ttyini.mac in the archive. Click here to see a list.
TITLE	TTYINI - SET TERMINAL CHARACTERISTICS

SEARCH MONSYM,MACSYM
.REQUIRE SYS:MACREL
.DIRECTIVE FLBLST
SALL
EXT <JSMSG0>

VGROUP==0
VMAJOR==16
VMINOR==0
VEDIT==100

; Date of last edit to sources
DEFINE DATE<ASCIZ \17-Aug-84\>

;Modified by Peter Mierswa to add comments, and all terms up to VT200s
;Modified by Scott Robinson to make LA12 be width:80/formfeed and type 15
;Modified by Scott Robinson to add terminals up to type 23 (CT-R(VT200))
;Modified by Scott Robinson to alphabetize switch tables.
;Modified by Scott Robinson to add terminals up to type 14 (LA12)
;Modified by Scott Robinson to add VT102 terminal 8-OCT-82
;MODIFIED BY HELLIWELL TO ADD GIGI TERMINAL OPERATING AS VT100 6-JUN-81.
;MODIFIED BY HELLIWELL TO TEST FOR IOX4&COMNX9 FOR EOF ON FILE INPUT 19-MAR-81.
;MODIFIED BY JACKSON TO SEND VT52 "EXIT HOLD PAGE MODE" (ESC \) AFTER ANSI
; INTERROGATE SEQUENCE 11-MAR-81.
;MODIFIED BY JACKSON TO WAIT 10 SEC BEFORE GIVING UP IF ON PTY 11-MAR-81.
;MODIFIED BY JACKSON TO TALK TO VT61 29-JAN-81.

; Registers
A=1
B=2
C=3
D=4
E=5
F=6
S=7

;16 IS USED BY MACSYM

P=17

;SHOULD BE IN MONSYM
.TT200==^D40

;BITS IN F
TTYOWN==1		;WE OWN TTY
TTYINA==2		;INACTIVE
TTYASG==4		;OWNED BY SOMEONE ELSE
WHOPR==10		;WE ARE WHEEL OR OPR

;BITS RETURNED BY GETJI
TTYASN==1B1		;TERMINAL IS ASSIGNED, NOT CONTROLLING

;BITS IN TTSTAT (used for INGORE-INPUT)
TT%IGI==1B6		;IGNORE INPUT

MAXJFN==^D20		;MAX 20 NESTED TAKES

MAXCHR==^D2000		;Size of the COMND% buffer in characters

MAXLEN==<MAXCHR+5>/5	;Size of the COMND% buffer in words

ABCHR==^D50		;Size of the COMND% atom buffer in characters

ABLEN==<ABCHR+5>/5	;Size of the COMND% atom buffer in words

PDLLEN==20		;Size of the stack

;Error processing macros
DEFINE JCERR(TEXT)<
	ERCAL [	JSERR<TEXT>
		RET]>

DEFINE JRERR(TEXT)<
	ERJMP [	JSERR<TEXT>
		RET]>

DEFINE JWERR(TEXT,ADDR)<
IFB<ADDR>,<ERCAL [>
IFNB<ADDR>,<ERJMP [>
	HRROI A,[ASCIZ \%'TEXT: \]
	PSOUT%
	CALL JSMSG0
IFB<ADDR>,<RET]>
IFNB<ADDR>,<JRST ADDR]>
>

DEFINE JSERR(TEXT)<
	CALL ERRDO
IFB<TEXT><HRROI A,[0]>
IFNB<TEXT><HRROI A,[ASCIZ \TEXT: \]>
	ESOUT%
	CALL JSMSG0
>
SUBTTL	MACROS

;LOAD A BLOCK WITH DATA AND ALLOCATE ENOUGH SPACE
;FOR LARGEST WORD

DEFINE LDBLK(LIST)<
..LEN==0
	IRP LIST,<.LDWRD(LIST)>
	.ORG .+..LEN
>

;USED TO STRIP OFF <>

DEFINE .LDWRD(A)<LDWRD(A)>

;LOAD 1 WORD CHECK MAX LENGTH

DEFINE LDWRD(A,B,C)<
	.ORG .+<A>
IFNB<C><C:>
	IFB<B>,<0;>B
	.ORG .-<A>-1
IFGE <A>-..LEN,<..LEN==<A>+1>
>

;KEYWORD TABLE MACROS

DEFINE TABLE<
	...BEG==.
	BLOCK 1
>

DEFINE TEND<
...LEN==.-...BEG
.ORG ...BEG
	...LEN-1,,...LEN
.ORG .+...LEN
>

DEFINE T(TEXT,VALUE)<	[ASCIZ \TEXT\],,VALUE>

;LOAD A FUNCTION DESCRIPTOR BLOCK
;USE FLDDB. MACRO FROM MONSYM. ARGS AS FOLLOWS:
;FLDDB.(TYP,FLGS,DATA,HLPM,DEFM,LST)
;TYP	COMND FUNCTION CODE (I.E. .CMKEY)
;FLGS	FLAGS (I.E. CM%SDH, SUPPRESS DEFAULT HELP)
;DATA	ARG TO SPECIFIC FUNCTION (I.E. RADIX FOR .CMNUM)
;HLPM	USER SUPPLIED HELP STRING (AUTOMATICALLY SETS CM%HPP)
;DEFM	DEFAULT STRING (AUTOMATICALLY SETS CM%DPP)
;LST	POINTER TO NEXT FUNCTION DESCRIPTOR BLOCK

;DEFINE SINGLE DATA WORD (OR WORDS)

DEFINE DATA(ADDR,SIZE)<
ADDR:	IFB<SIZE>,<BLOCK 1;>BLOCK SIZE
>

DEFINE CONFIRM(ERROR)<
	CALL DOCFM
IFB<ERROR>< JRST COMERR>
IFNB<ERROR>< JRST ERROR>
>


DEFINE COMINI(TEXT)<
IFNB<TEXT><HRROI A,[ASCIZ \TEXT\]>
IFB<TEXT><HRROI A,CMBUF>
	SKIPN B,CMJFNS
	MOVE B,[.PRIIN,,.PRIOU]
	CALL DOINI
>

DEFINE FIELD(FDB,ERROR)<
	MOVEI B,FDB
	CALL DOCOM
IFB<ERROR>< JRST COMERR>
IFNB<ERROR>< JRST ERROR>
>

DEFINE RFIELD(FDB)<
	MOVEI B,FDB
	MOVEI A,CMSTAT
	COMND%
	 ERJMP ERSCAN
	TXNE A,CM%NOP
	JRST ERSCAN
>

DEFINE CHECK(ADDR,NAME)<
	SKIPL ADDR
	JRST [	SKIPE FILEF
		RETSKP
		TMSG <?TTYINI: Cannot give NAME more than once
>
		RET]
>

DEFINE DEFAULT(SWIT,VAL)<
	MOVEI A,VAL
	SKIPGE SWIT
	MOVEM A,SWIT
>
SUBTTL	DATA AREA

EV:	JRST STRT
	JRST STRT
JOBVER:	BYTE (3)VGROUP(9)VMAJOR(6)VMINOR(18)VEDIT
EVL==.-EV

LOGIN:	BLOCK ^D20	;logged in directory

PDL:	BLOCK PDLLEN

CHRBUF:	BLOCK ^D40

CMSTAT:	LDBLK(<<.CMFLG,REPARS>,<.CMIOJ,<.PRIIN,,.PRIOU>>,<.CMBFP,<-1,,CMBUF>>,<.CMPTR,<-1,,CMBUF>>,<.CMCNT,MAXCHR>,<.CMINC,0>,<.CMABP,<POINT 7,ABBUF>>,<.CMABC,ABCHR>,<.CMGJB,CMGJFN>>)

CMGJFN:	BLOCK 16

CMBUF:	BLOCK MAXLEN

ABBUF:	BLOCK ABLEN

INIBLK:	FLDDB.(.CMINI)

TTYINI:	FLDDB.(.CMKEY,,RESKEY)

RESKEY:	TABLE
	T TTYINI,0
	TEND

COMAND:	FLDDB.(.CMCFM,,,,,COMSWT)

COMSWT:	FLDDB.(.CMSWI,,TYPSWT,,,COMTYP)

TYPSWT:	TABLE
	T ADVICE-ACCEPT,$ADVIC
	T ASSIGN,$ASS
	T AUTO-BAUD,$AUTO
	T CHARACTERISTICS,$CHAR
	T CHECK,$CHECK
	T DEFAULT-TYPE:,$DTYPE
	T EXIT,$EXIT
	T FILE:,$FILE
	T FLAG-UPPERCASE,$FLAG
	T FORMFEED,$FORM
	T FULLDUPLEX,$FULL
	T HALFDUPLEX,$HALF
	T HELP:,$HELP
	T IGNORE-INPUT,$IGNOR
	T INDICATE-FORMFEED,$INDFF
	T INHIBIT,$INHIB
	T INQUIRE,$CHECK
	T LENGTH:,$LENGT
	T LINE:,$LINE
	T LINK-ACCEPT,$LINK
	T LIST,$LIST
	T LOWERCASE,$LOWER
	T NOADVICE-ACCEPT,%ADVIC
	T NOAUTO-BAUD,%AUTO
	T NOFILE,%FILE
	T NOFLAG-UPPERCASE,%FLAG
	T NOFORMFEED,%FORM
	T NOIGNORE-INPUT,%IGNOR
	T NOINDICATE-FORMFEED,%INDFF
	T NOINHIBIT,%INHIB
	T NOLINK-ACCEPT,%LINK
	T NOLOWERCASE,%LOWER
	T NOPAGE-SPEED:,%PGSPD
	T NOPAUSE-AT-END-OF-PAGE,%PAUSE
	T NOPAUSE-ON-COMMAND,%PAUSC
	T NORAISE-INPUT,%RAISE
	T NOREMOTE,%REMOT
	T NOSYSTEM-MESSAGES,%SYSMS
	T NOTAB,%TAB
	T NOUSER-MESSAGES,%USRMS
	T PAUSE-AT-END-OF-PAGE,$PAUSE
	T PAUSE-ON-COMMAND,$PAUSC
	T RAISE-INPUT,$RAISE
	T REMOTE,$REMOT
	T SPEED,$SPEED
	T SYSTEM-MESSAGES,$SYSMS
	T TAB,$TAB
	T TAKE:,DOTAKE
	T USER-MESSAGES,$USRMS
	T VT100-52,$XXX52
	T VT100-ANSI,$XXX10
	T VTXXX-100,$XXX10
	T VTXXX-102,$XXX12
	T VTXXX-200,$XXX20
	T VTXXX-52,$XXX52
	T WIDTH:,$WIDTH
	TEND

COMSPD:	FLDDB.(.CMKEY,,SPDKEY,<
 Speed at or below which to disable /PAUSE-AT-END-OF-PAGE,
>)

SPDKEY:	TABLE
	T 110,^D110
	T 1200,^D1200
	T 134,^D134
	T 150,^D150
	T 1800,^D1800
	T 200,^D200
	T 2400,^D2400
	T 300,^D300
	T 4800,^D4800
	T 50,^D50
	T 600,^D600
	T 75,^D75
	T 9600,^D9600
	TEND

COMTYP:	FLDDB.(.CMKEY,,COMKEY)

COMDTY:	FLDDB.(.CMKEY,,COMKEY)

COMKEY:	TABLE
	T 33,$TT33
	T 35,$TT35
	T 37,$TT37
	T CHECK,-1
	T CT,$TT100
	T CTRO,$TT120
	T DEFAULT,$TTDEF
	T EP1,$TT120
	T EXECUPORT,$TTEXE
	T GIGI,$TTK10
	T GT40,$TTG40
	T H19,$TTH19
	T IDEAL,$TTIDL
	T INQUIRE,-1
	T LA12,$TTL12
	T LA120,$TT120
	T LA180,$TT180
	T LA24,$TTL34
	T LA30,$TTL30
	T LA34,$TTL34
	T LA36,$TTL36
	T LA38,$TTL38
	T LA80,$TT120
	T LQP02,$TTL34
	T LQPSE,$TTL34
	T TI,$TTEXE
	T VT05,$TTV05
	T VT100,$TT100
	T VT102,$TT102
	T VT125,$TT125
	T VT131,$TT131
	T VT132,$TT131
	T VT200-SERIES,$TT200
	T VT220,$TT200
	T VT240,$TT200
	T VT241,$TT200
	T VT278,$TTV52
	T VT50,$TTV50
	T VT52,$TTV52
	T VT55,$TTV52
	T VT61,$TTV52
	T VT80,$TT100
	TEND

COMCFM:	FLDDB.(.CMCFM)

COMNUM:	FLDDB.(.CMNUM,,^D10)

COMLIN:	FLDDB.(.CMCFM,,,,,COMSTR)

COMSTR:	FLDDB.(.CMTOK,,<-1,,[ASCIZ /*/]>,,,COMOCT)

COMOCT:	FLDDB.(.CMNUM,,10)

COMDEV:	FLDDB.(.CMDEV,CM%SDH,,<Terminal device name>,,TTYOCT)

TTYOCT:	FLDDB.(.CMNUM,CM%SDH,10,<Octal terminal number>)

COMEOL:	FLDDB.(.CMTXT)

COMFIL:	FLDDB.(.CMFIL)

ISPEED:	FLDDB.(.CMKEY,,SPEEDT,<Input speed,>)

OSPEED:	FLDDB.(.CMKEY,,SPEEDT,<Output speed,>)

COLON:	FLDDB.(.CMTOK,CM%SDH,<-1,,[ASCIZ /:/]>,<":" to specify different output speed>,<:>)

SPEEDT:	TABLE
	T 0,^D0
	T 110,^D110
	T 1200,^D1200
	T 134,^D134
	T 150,^D150
	T 1800,^D1800
	T 200,^D200
	T 2400,^D2400
	T 300,^D300
	T 4800,^D4800
	T 50,^D50
	T 600,^D600
	T 75,^D75
	T 9600,^D9600
	TEND

FILBLK:	LDBLK(<<.GJGEN,GJ%OLD>,<.GJEXT,<-1,,[ASCIZ /CMD/]>>,<.GJNAM,[ASCIZ /TTYINI/]>>)
FILLEN==.-FILBLK

HLPFIL:	FLDDB.(.CMFIL,CM%DPP,,,<TTY:>)
HLPBLK:	LDBLK(<<.GJGEN,GJ%FOU>,<.GJEXT,<-1,,[ASCIZ /HLP/]>>,<.GJNAM,<-1,,[ASCIZ /TTYINI/]>>>)
HLPLEN==.-HLPBLK

TAKFIL:	FLDDB.(.CMFIL)
TAKBLK:	LDBLK(<<.GJGEN,GJ%OLD>,<.GJDEV,<-1,,[ASCIZ /PS:/]>>,<.GJEXT,<-1,,[ASCIZ /CMD/]>>,<.GJNAM,<-1,,[ASCIZ /TTYINI/]>>>)
TAKLEN==.-TAKBLK

DATA	REPPDL			; saved stack pointer used by COMND% reparse
DATA	REPPC			; saved PC used by COMND% reparse
DATA	SYSCOM			; -1=use EXECs command line
				;  0=prompt for command
DATA	CMJFNS			; saved .CMIOJ word (i.e. take file JFN)
DATA	CMJFNP			; stack pointer for nested take file JFN stack
DATA	JFNSTK,MAXJFN		; stack for nested take file JFNS
DATA	PTY0			; # OF PTYS,,TTY number of first PTY
DATA	OURLIN			; TTY number of the line to work on
DATA	OWNLIN			; Controlling TTY
DATA	OWNJOB			; job number of job running TTYINI
DATA	TTYDES			; device designator for the line to work on
DATA	EXITS			; /EXIT switch was seen in a command file
DATA	HELPS			; /HELP switch was seen in a command file
DATA	LINES			; /LINE switch was seen in a command file
DATA	LISTS			; /LIST switch was seen in a command file
DATA	CHANGE			; >0=Read file with commands by TTY number
				; 0=Don't read file
DATA	TMP1			; temporary data storage
DATA	TMP2			; temporary data storage
DATA	FILEF			; 0=not currently reading file with TTY numbers
				; -1=currently reading file
				; 1=trying to read default file
DATA	IJFN			; JFN of the above file being currently read
DATA	SAVMOD			; saved RFMOD bits
DATA	PASS			; -1=currently doing first pass of /CHECK

DATABG==.
DATA	TYPE			; address of the terminal type routine
DATA	DTYPE			; address of the default term type routine

; Flags for switches

DATA	CHARF
DATA	CHRPTR
DATA	EXITF
DATA	LISTF
DATA	ASSF
DATA	FLAGF
DATA	LINE
DATA	FORMF
DATA	OJFN			; output JFN for /HELP
DATA	LENGTH
DATA	LINEF
DATA	LOWERF
DATA	PAUSEF
DATA	PAUSCF
DATA	RFCHNG
DATA	NSPEED
DATA	RAISEF
DATA	INDFFF
DATA	TABF
DATA	WIDTH
DATA	VTXXXF			; -1 No switch given
	WVT52=0			; 0 want to be a VT52
	WVT100=1		; 1 want to be a vt100
	WVT102=2		; 2 want to be a vt102
	WVT200=3		; 3 want to be a vt200
DATA	FJFN			; JFN of the file after /FILE
DATA	AADFLG
DATA	ALKFLG
DATA	TLKFLG
DATA	SPDWRD
DATA	RMTFLG
DATA	AUTFLG
DATA	SPDFLG
DATA	MSGFLG
DATA	USRFLG
DATA	INHFLG
DATA	IGNFLG
DATA	DTALKF
DATALN==.-DATABG

DATA	TMPARG,DATALN

TTSTAT:	-1	; used for IGNORE-INPUT

;TERMINAL TYPE TABLE FOR ANSI RESPONSE TO <ESC>Z

ANSITB:
T1001:	;LABEL USED FOR /VT100-52
	$TT100,,[ASCIZ /VT100/]       ; (1) VT100
	$TT120,,[ASCIZ /LA120/]       ; (2) LA120
	$TTL34,,[ASCIZ /LA34/]	       ; (3) LA34
T1002:	$TT131,,[ASCIZ /VT132/] ; (4) VT132
	$TTK10,,[ASCIZ /GIGI/]  ; (5) GIGI IN VT100 MODE
T1003:	$TT102,,[ASCIZ /VT102/] ; (6) VT102
T1004:	$TT131,,[ASCIZ /VT131/] ; (7) VT131
	$TTV52,,[ASCIZ /VT278/]  ; (8) VT278
	$TTL34,,[ASCIZ /LQPSE-F/]; (9) LQPSE-F
	$TTL34,,[ASCIZ /LA24/]   ;(10) LA24
	$TT120,,[ASCIZ /LA120-K/]      ;(11) LA120 Katakana
T1005:	$TT125,,[ASCIZ /VT125/] ;(12) VT125
	$TTL12,,[ASCIZ /LQP02/] ;(13) LQP02
	$TT102,,[ASCIZ /VT102J/];(14) VT102 Katakana
	$TTL12,,[ASCIZ /LA12/]  ;(15) LA12
	$TT120,,[ASCIZ /EP1/]	;(16) EP1 Electronic Printer
	$TT120,,[ASCIZ /CT-RO/]	;(17) CT Receive Only Printer
	$TT100,,[ASCIZ /VT80-CSS/];(18) VT80 CSS Japan
TALK:	$TTDEF,,[ASCIZ /DECtalk/] ;(19) DECtalk
	$TT120,,[ASCIZ /LA80-CSS/];(20) LA80 CSS Japan
	$TT100,,[ASCIZ /CT-I/] 	  ;(21) Internal CT
	$TT100,,[ASCIZ /CT-R/] 	  ;(22) Remote CT VT100
	$TT200,,[ASCIZ /CT-R/] 	  ;(23) Remote CT VT200
REPEAT ^D60-^D24+1, <$TTDEF,,[ASCIZ /UNKNOWN ANSI TERMINAL/]>;?
T1006:	$TT102,,[ASCIZ /VT102/]	; (61) VT102
T2001:	$TT200,,[ASCIZ /VT200-SERIES/] ; (62) VT200
   ANSIMX==.-ANSITB

;CHARACTERISTICS TABLES

;VT100 class terminals
CHRTAB:	0
	[ASCIZ /processor(STP)/]
	[ASCIZ /advanced video(AVO)/]
	[ASCIZ /processor(STP), advanced video(AVO)/]
	[ASCIZ /graphics(GPO)/]
	[ASCIZ /graphics(GPO), processor(STP)/]
	[ASCIZ /graphics(GPO), advanced video(AVO)/]
	[ASCIZ /graphics(GPO), processor(STP), advanced video(AVO)/]
	[ASCIZ /printer(PRT)/]
	[ASCIZ /printer(PRT)/]
	[ASCIZ /printer(PRT), advanced video(AVO)/]
	[ASCIZ /printer(PRT), advanced video(AVO)/]
	[ASCIZ /graphics(GPO), printer(PRT)/]
	[ASCIZ /graphics(GPO), printer(PRT)/]
	[ASCIZ /graphics(GPO), printer(PRT), advanced video(AVO)/]
	[ASCIZ /graphics(GPO), printer(PRT), advanced video(AVO)/]

;VT200 class terminals
VT2TAB:
	0
	[ASCIZ /132 cols/]
	[ASCIZ /printer/]
	[ASCIZ /regis/]
	[ASCIZ \sixels\]
	[ASCIZ /katakana/]
	[ASCIZ /selective erase/]
	[ASCIZ /DRCS/]
	[ASCIZ /UDK/]
	[ASCIZ /9/]
vt2end=.-vt2tab

;TERMINAL TYPE TABLE FOR DEC RESPONSE TO <ESC>Z

DEFINE DECENT(LETTER,ROUTINE,TYPE,ADDR)<
	LDWRD(<<"LETTER">-<"#">>,<ROUTINE,,[ASCIZ \TYPE\]>,ADDR)
>

DECTAB:
..LEN==0
DECENT	A,$TTV50,VT50
DECENT	B,$TTV50,VT50
DECENT	H,$TTV50,<VT52H>
DECENT	J,$TTV50,<VT52H>	;copier
DECENT	C,$TTV52,<VT55>
DECENT	K,$TTV52,VT52
DECENT	L,$TTV52,VT52		;copier
DECENT	M,$TTV52,VT52		;printer
DECENT	(Z,$TTV52,<VTxxx>,T10052)	;T10052 USED BY /VT100-ANSI
DECENT	E,$TTV52,<VT55>
DECENT	`,$TTV52,<VT61>	;VT61 no printer no copier
DECENT	a,$TTV52,<VT61>	;VT61 no printer copier
DECENT	b,$TTV52,<VT61>	;VT61 printer no copier
DECENT	c,$TTV52,<VT61>	;VT61 printer copier
DECENT	#,$TTV52,<VT71T>
DECMAX==..LEN
.ORG DECTAB+DECMAX

SUDTAB:
..LEN==0
DECENT	A,$80532,<SUDS(GT40/VT05/32/80)>
DECENT	B,$80542,<SUDS(GT62/VT05/42/80)>
DECENT	C,$85232,<SUDS(GT40/VT52/32/80)>
DECENT	D,$85242,<SUDS(GT62/VT52/42/80)>
DECENT	E,$70532,<SUDS(GT40/VT05/32/72)>
DECENT	F,$70542,<SUDS(GT62/VT05/42/72)>
DECENT	G,$75232,<SUDS(GT40/VT52/32/72)>
DECENT	H,$75242,<SUDS(GT62/VT52/42/72)>
SUDMAX==..LEN
.ORG SUDTAB+SUDMAX

FILINI:	PUSH P,A
	SETZM CMGJFN
	MOVE A,[CMGJFN,,CMGJFN+1]
	BLT A,CMGJFN+15
	POP P,A
	HRRZ B,A
	HRRI A,CMGJFN
	BLT A,CMGJFN-1(B)
	RET
SUBTTL	STARTUP
STRT:	RESET%
	MOVE P,[IOWD PDLLEN,PDL]
	MOVE A,[-MAXJFN,,JFNSTK-1]
	MOVEM A,CMJFNP
	SETZM CMJFNS
	MOVE A,['PTYPAR']
	SYSGT%
	MOVEM A,PTY0
	SETOM SYSCOM
	SETZ A,
	RSCAN%
	 ERJMP ERSCAN
	JUMPE A,ERSCAN
	COMINI()
	RFIELD(TTYINI)		;MUST START WITH PROGRAM NAME, OR NO ERRORS
	MOVEI B,COMCFM
	MOVEI A,CMSTAT
	COMND%
	 ERJMP REPAR1
	TXNE A,CM%NOP
	JRST REPAR1
	SETOM DATABG
	MOVE A,[DATABG,,DATABG+1]
	BLT A,DATABG+DATALN-1
	SETZM CHANGE
	AOS CHANGE		;FORCE FILE SCAN
	JRST COMDON		;GO DO TYPE FROM FILE

ERSCAN:	HRROI A,[0]
	RSCAN%
	 ERJMP .+1
	SETZM SYSCOM
	MOVEI A,.PRIOU
	CALL VERPNT
	TMSG <Type "/HELP" for help.
Type "/EXIT" to exit.
>
COMLOP:	CALL CLEAN
	SKIPE CMJFNS			;DON'T EXIT DURING TAKE
	JRST COMLP1
	SKIPE SYSCOM
	HALTF%
	SETZM SYSCOM
COMLP1:	HRROI A,[ASCIZ /TTYINI>/]
	SKIPN B,CMJFNS
	MOVE B,[.PRIIN,,.PRIOU]
	CALL DOINI
	CALL CLEAN
REPAR1:	SETZM CHANGE
	SETZM FILEF
	SETOM DATABG
	MOVE A,[DATABG,,DATABG+1]
	BLT A,DATABG+DATALN-1
COMNXT:	FIELD(COMAND,CMEOFC)
	HRRZ B,(B)
	MOVE D,B
	HRRZ C,C
	CAIN C,COMAND
	JRST COMDON		;CONFIRMED
	CAIN C,COMTYP
	MOVEI D,SETTYP
	CALL (D)
	 JRST COMERR
	JRST COMNXT

REPARS:	MOVE P,REPPDL
	MOVE A,REPPC
	MOVEM A,(P)
	RET

DOINI:	MOVEM A,CMSTAT+.CMRTY
	MOVEM B,CMSTAT+.CMIOJ
	MOVE A,(P)
	MOVEM A,REPPC
	MOVEM P,REPPDL
	MOVEI A,CMSTAT
	MOVEI B,INIBLK
	COMND%
	 ERJMP FATAL
	TXNN A,CM%NOP
	RET
FATAL:	JSHLT

CMEOFC:	SKIPN CMJFNS
	JRST COMERR
	MOVEI A,.FHSLF
	GETER%
	 ERJMP COMERR
	HRRZ B,B
	CAIE B,IOX4
	JRST COMERR
	TMSG <%TTYINI: End of >
	MOVEI A,.PRIOU
	HLRZ B,CMJFNS
	SETZ C,
	JFNS%
	 JCERR<>
	TMSG <
>
	CALL TAKFIN
	JRST COMLOP

DOCFM:	MOVEI B,COMCFM
DOCOM:	MOVEI A,CMSTAT
	COMND%
	 ERJMP R
	TXNE A,CM%NOP
	RET
	RETSKP

COMERR:	CALL ERRET
	JRST COMLOP

ERRET:	JSERR <TTYINI: Command error>
	RET

ERRDO:	SKIPN CMJFNS
	RET
	TMSG <%TTYINI: Error reading >
	MOVEI A,.PRIOU
	HLRZ B,CMJFNS
	SETZ C,
	JFNS%
	 JCERR<>
	TMSG <, command file input terminated.
>
	CALL TAKFIN
	JRST ERRDO

TAKFIN:	HLRZ A,CMJFNS
	MOVE B,CMJFNP
	POP B,CMJFNS
	MOVEM B,CMJFNP
	CLOSF%
	 JCERR <TTYINI: Error closing command file>
	RET

CLEAN:	SKIPG OJFN
	JRST CLEAN1
	MOVX A,CZ%ABT
	HRR A,OJFN
	CLOSF%
	 JFCL
	SETOM OJFN
CLEAN1:	HRROI A,[0]
	RSCAN
	 ERJMP .+1
	MOVX A,CZ%NCL!FLD(.FHSLF,CZ%PRH)
	CLZFF%
	 JCERR <TTYINI: Failed to release unopened JFNs>
	RET

VERPNT:	HRROI B,[ASCIZ /TTYINI version /]
	SETZ C,
	SOUT%
	LDB B,[POINT 9,JOBVER,11]	;MAJOR
	MOVEI C,10
	NOUT%
	 JCERR
	LDB B,[POINT 6,JOBVER,17]	;MINOR
	JUMPE B,NOMINR
	SUBI B,1
	IDIVI B,^D26
	JUMPE B,NOMINF
	MOVEI B,"A"-1(B)
	BOUT%
NOMINF:	MOVEI B,"A"(C)
	BOUT%
NOMINR:	HRRZ C,JOBVER			;EDIT
	JUMPE C,NOEDIT
	MOVEI B,"("
	BOUT%
	MOVE B,C
	MOVEI C,10
	NOUT%
	 JCERR
	MOVEI B,")"
	BOUT%
NOEDIT:	LDB C,[POINT 3,JOBVER,2]
	JUMPE C,NOGRP
	MOVEI B,"-"
	BOUT%
	MOVE B,C
	MOVEI C,10
	NOUT%
	 JCERR
NOGRP: 	HRROI B,[ASCIZ /, /]
	SETZ C,
	SOUT%
	HRROI B,[DATE]
	SOUT%
	HRROI B,[ASCIZ /
/]
	SOUT%
	RET

COMEND:	SKIPL EXITF
	HALTF%
	JRST COMLOP
SUBTTL	COMMAND HANDLERS
$DTYPE:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /DEFAULT-TYPE
>
		RET]
	FIELD(COMDTY,R)
	HRRZ B,(B)
	CHECK DTYPE,DEFAULT-TYPE
	MOVEM B,DTYPE
	JRST CRET

SETTYP:	CHECK TYPE,TYPE
	MOVEM B,TYPE
	JRST CRET

$EXIT:	SKIPE FILEF
	JRST [	SETZM EXITS
		RETSKP]
	CHECK EXITF,EXIT
	SETZM EXITF
	RETSKP

$ASS:	CHECK ASSF,ASSIGN
	SETZM ASSF
	RETSKP

%FLAG:	TDZA A,A
$FLAG:	MOVEI A,1
	CHECK FLAGF,FLAG-UPPERCASE
	MOVEM A,FLAGF
	SETZM RFCHNG
	JRST CRET

%FORM:	TDZA A,A
$FORM:	MOVEI A,1
	CHECK FORMF,FORMFEED
	MOVEM A,FORMF
	SETZM RFCHNG
	JRST CRET

$LIST:	SKIPE FILEF
	JRST [	SETZM LISTS
		RETSKP]
	CHECK LISTF,LIST
	SETZM LISTF
	RETSKP

$HELP:	TXNN A,CM%SWT
	JRST [	MOVEI B,.CTTRM	;DEFAULT TO TERMINAL IF NO ":"
		JRST $HELP1]
	MOVE A,[HLPBLK,,HLPLEN]
	CALL FILINI
	FIELD(HLPFIL)
	SKIPN FILEF
	JRST $HELP1
	HRRZ A,B
	RLJFN%
	 JFCL
$HELP1:	CHECK OJFN,HELP
	HRRZM B,OJFN
	RETSKP

$LINE:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /LINE
>
		RET]
	FIELD(COMDEV,R)
	CHECK LINE,LINE
	HRRZ C,C
	CAIE C,TTYOCT
	JRST $LINED
	CAIL B,10000		;LEGAL LINE?
	JRST LINER1		;NO
	HRLI B,.DVTTY!.DVDES
	MOVEI A,.NULIO
	DEVST%			;TRY TO CONVERT AS TERMINAL
	 ERJMP LINER1		;ERROR IF CAN'T CONVERT
$LINOK:	SETZM LINE		;FLAG /LINE
	HRRZM B,OURLIN
	TRO B,.TTDES
	HRRZM B,TTYDES
	RETSKP

$LINED:	HLRZ A,B		;GET DEVICE DESIGNATOR PART
	CAIN A,.DVTTY!.DVDES	;TERMINAL?
	JRST $LINOK
	TMSG <?TTYINI: Illegal device in /LINE:, must be terminal.
>
	RET

LINER1:	TMSG <?TTYINI: Illegal line number in /LINE:, not a legal line.
>
	RET

$LENGT:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /LENGTH
>
		RET]
	FIELD(COMNUM,R)
	CHECK LENGTH,LENGTH
	MOVEM B,LENGTH
	JRST CRET

%LOWER:	TDZA A,A
$LOWER:	MOVEI A,1
	CHECK LOWERF,LOWERCASE
	MOVEM A,LOWERF
	SETZM RFCHNG
	JRST CRET

$XXX52:	MOVEI A,WVT52
	JRST $XXXXX

$XXX10:	MOVEI A,WVT100
	JRST $XXXXX

$XXX12:	MOVEI A,WVT102
	JRST $XXXXX

$XXX20:	MOVEI A,WVT200
	JRST $XXXXX

$XXXXX:	SKIPL VTXXXF
	JRST [	SKIPE FILEF
		RETSKP
		TMSG <?TTYINI: Cannot give /VTXXX-type more than once
>
		RET]
	MOVEM A,VTXXXF
	JRST CRET

%PGSPD:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /NOPAGE-SPEED
>
		RET]
	FIELD(COMSPD,R)		;GET SPEED
	CHECK NSPEED,NOPAGE-SPEED
	HRRZ B,(B)		;GET VALUE
	MOVEM B,NSPEED		;AND SAVE HERE
	JRST CRET

%PAUSE:	TDZA A,A
$PAUSE:	MOVEI A,1
	CHECK PAUSEF,PAUSE-AT-END-OF-PAGE
	MOVEM A,PAUSEF
	SETZM RFCHNG
	JRST CRET		;NO, DONE

%PAUSC:	TDZA A,A
$PAUSC:	MOVEI A,1
	CHECK PAUSCF,PAUSE-ON-COMMAND
	MOVEM A,PAUSCF
	SETZM RFCHNG
	JRST CRET		;NO, DONE

%RAISE:	TDZA A,A
$RAISE:	MOVEI A,1
	CHECK RAISEF,RAISE-INPUT
	MOVEM A,RAISEF
	SETZM RFCHNG
	JRST CRET

%ADVIC:	TDZA A,A
$ADVIC:	MOVEI A,1
	CHECK AADFLG,ADVICE-ACCEPT
	MOVEM A,AADFLG
	SETZM TLKFLG
	JRST CRET

$CHECK:	MOVEI A,-1
	MOVEM A,TYPE
	JRST CRET

%LINK:	TDZA A,A
$LINK:	MOVEI A,1
	CHECK ALKFLG,LINK-ACCEPT
	MOVEM A,ALKFLG
	SETZM TLKFLG
	JRST CRET

$SPEED:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /SPEED
>
		RET]
	FIELD(ISPEED,ERRET)
	HRRZ D,(B)
	HRL D,D
	FIELD(COLON,GOTSPD)
	FIELD(OSPEED,ERRET)
	CHECK SPDFLG,SPEED
	HRR D,(B)
GOTSPD:	CHECK SPDWRD,SPEED
	MOVEM D,SPDWRD
	SETZM SPDFLG
	JRST CRET

%AUTO:	TDZA A,A
$AUTO:	MOVEI A,1
	CHECK RMTFLG,AUTO
	MOVEM A,AUTFLG
	SETZM SPDFLG
	JRST CRET

$CHAR:	CHECK CHARF,CHAR
	SETZM CHARF
	JRST CRET

%REMOT:	TDZA A,A
$REMOT:	MOVEI A,1
	CHECK RMTFLG,REMOTE
	MOVEM A,RMTFLG
	SETZM SPDFLG
	JRST CRET

%INDFF:	TDZA A,A
$INDFF:	MOVEI A,1
	CHECK INDFFF,INDICATE-FORMFEED
	MOVEM A,INDFFF
	JRST CRET

%TAB:	TDZA A,A
$TAB:	MOVEI A,1
	CHECK TABF,TAB
	MOVEM A,TABF
	SETZM RFCHNG
	JRST CRET

$WIDTH:	TXNN A,CM%SWT
	JRST [	TMSG <?TTYINI: No colon following /WIDTH
>
		RET]
	FIELD(COMNUM,R)
	CHECK WIDTH,WIDTH
	MOVEM B,WIDTH
	JRST CRET

$FULL:	MOVEI A,.TTFDX
	JRST DODUM

$HALF:	MOVEI A,.TTHDX
DODUM:	CHECK LINEF,DUPLEX
	MOVEM A,LINEF
	SETZM RFCHNG
	JRST CRET

%INHIB:	SKIPA A,[0]
$INHIB:	MOVEI A,1
	CHECK INHFLG,INHIBIT
	MOVEM A,INHFLG
	JRST CRET

%USRMS:	SKIPA A,[0]
$USRMS:	MOVEI A,1
	CHECK USRFLG,USER-MESSAGES
	MOVEM A,USRFLG
	JRST CRET

%SYSMS:	SKIPA A,[.MOSMN]
$SYSMS:	MOVEI A,.MOSMY
	CHECK MSGFLG,SYSTEM-MESSAGES
	MOVEM A,MSGFLG
	JRST CRET

%IGNOR:	TDZA A,A
$IGNOR:	MOVEI A,1
	CHECK IGNFLG,IGNORE-INPUT
	MOVEM A,IGNFLG
	JRST CRET

%FILE:	SETZ B,
	JRST GFILE

$FILE:	TXNN A,CM%SWT
	JRST [	SETO B,		;WON'T CHANGE FILE STATUS, WILL SET CHANGE
		JRST GFILE]
	MOVE A,[FILBLK,,FILLEN]
	CALL FILINI
	FIELD(COMFIL,R)
GFILE:	CHECK FJFN,FILE
	MOVEM B,FJFN
CRET:	AOS CHANGE
	RETSKP
SUBTTL	COMMAND EXECUTION
COMDON:	SKIPG A,OJFN
	JRST NOHELP
	CAIN A,.CTTRM		;CONTROLLING TERMINAL?
	JRST HELP1		;YES, DON'T NEED TO OPEN
	MOVX B,<FLD(7,OF%BSZ)!OF%WR>
	OPENF%
	 ERJMP [JSERR <TTYINI: OPENF failed for /HELP output file>
		JRST COMLOP]
HELP1:	CALL VERPNT
	HRRZ A,OJFN
	HRROI B,HLPMES
	SETZ C,
	SOUT%
	CAIN A,.CTTRM		;CONTROLLING TERMINAL?
	JRST NOHELP		;YES, DON'T CLOSE IT
	CLOSF%
	 JCERR <TTYINI: Failed to close /HELP output file>
NOHELP:	MOVNI A,1		;ELSE GET OUR LINE
	MOVE B,[1,,3]
	MOVEI C,.JITNO
	GETJI%
	 JSHLT
	MOVEM C,OWNLIN
	MOVNI A,1
	MOVE B,[1,,3]
	MOVEI C,.JIJNO
	GETJI%
	 JSHLT
	MOVEM C,OWNJOB
	SKIPL LINE		;DID USER SPECIFY /LINE:n?
	JRST GOTLIN		;YES, USE IT
	MOVE C,OWNLIN
	MOVEM C,OURLIN		;DEFAULT LINE TO USE
	TRO C,.TTDES
	MOVEM C,TTYDES
GOTLIN:	SKIPE ASSF		;REQUESTING ASSIGNMENT?
	JRST NOASS
	MOVE A,TTYDES		;GET DEVICE DESIGNATOR
	ASND%
	 JWERR <TTYINI: Failed to assign terminal>
NOASS:	SETZ F,			;INIT FLAGS
	MOVE A,OURLIN
	CAMN A,OWNLIN
	JRST [	TXO F,TTYOWN	;WE OWN IT
		JRST DOLINB]
	TMSG <Processing >
	MOVEI A,.PRIOU
	MOVE B,TTYDES
	DEVST%
	 JCERR <TTYINI: Failed to output terminal device name>
	TMSG <:>
	MOVE A,TTYDES
	HRROI B,D
	MOVEI C,.JIJNO
	GETJI%
	 ERJMP [MOVEI A,.FHSLF
		GETER%
		HRRZ B,B
		CAIN B,GTABX3
		JRST DOLINA
		JSERR <TTYINI: GETJI failed for terminal's job number>
		JRST DOLINA]
	CAMN D,[-1]
	JRST [	TMSG <, not in use.>
		TXO F,TTYINA		;FLAG INACTIVE
		JRST DOLINA]
	TMSG <, Job >
	MOVEI A,.PRIOU
	HRRZ B,D
	CAMN B,OWNJOB			;OWNED BY US?
	TXOA F,TTYOWN			;YES
	TXO F,TTYASG			;NO
	MOVEI C,^D10
	NOUT%
	 JCERR <>
	HRROI A,[ASCIZ / (Controlling terminal)./]
	TXNE D,TTYASN
	HRROI A,[ASCIZ / (Assigned)./]
	PSOUT%
DOLINA:	TMSG <
>
DOLINB:	MOVEI A,.FHSLF
	RPCAP%
	TXNE C,SC%WHL!SC%OPR
	TRO F,WHOPR		;FLAG WHEEL OR OPR
	SKIPG CHANGE
	JRST CHKLST
	TXNE F,TTYASG
	TXNE F,WHOPR
	CAIA
	JRST [	TMSG <%TTYINI: Cannot set terminal parameters, terminal is owned by someone else.
>
		JRST CHKLST]
	SETOM FILEF		;NOW READING FILE
FILCHK:	MOVE A,TYPE		;SEE IF NEED CHECK NOW
	CAIN A,-1
	JRST [	CALL DOCHK
		SKIPN TYPE
		JRST NOSTYP
		SKIPL TYPE	;STILL UNKNOWN?
		JRST COMXCT	;NOPE, NO FILE PLEASE
		JRST CKFILE]
CKFILE:	SKIPLE A,FJFN
	JRST FILGOT		;WE HAVE AN EXPLICIT FILE
	JUMPE A,COMXCT		;JUMP IF EXPLICIT NOFILE
	SKIPGE TYPE		;DEFAULT SEARCH ONLY IF NO TYPE
	SKIPL FILEF		;TRIED YET?
	JRST COMXCT		;YES, NO MORE
	MOVEI A,1
	MOVEM A,FILEF		;FLAG TRYING DEFAULT FILE
	MOVX A,GJ%OLD!GJ%SHT
	HRROI B,[ASCIZ /SYSTEM:TTYINI.CMD/]
	GTJFN%
	 JRST [	JSERR(<TTYINI: Can't get SYSTEM:TTYINI.CMD:>,%)
		JRST COMXCT]
FILGOT:	HRRZM A,IJFN
	MOVX B,FLD(7,OF%BSZ)!OF%RD
	OPENF%
	 JRST [	TMSG <
?TTYINI: Can't open >
		MOVEI A,.PRIOU
		MOVE B,IJFN
		SETZ C,
		JFNS%
		 ERCAL R
		TMSG < because: >
		CALL JSERR0
		JRST COMLOP]
	SETOM FJFN
	MOVE A,[DATABG,,TMPARG]	;SAVE USER ARGS
	BLT A,TMPARG+DATALN-1
FILLOP:	HRROI A,CMBUF
	MOVEI B,.NULIO
	HRL B,IJFN
	CALL DOINI
	CALL CLEAN		;CLEAN UP LAST SCAN
	SETOM EXITS
	SETOM HELPS
	SETOM LINES
	SETOM LISTS
	MOVE A,[TMPARG,,DATABG]
	BLT A,DATABG+DATALN-1
	FIELD(COMLIN,FILERR)
	HRRZ C,C
	CAIN C,COMSTR
	JRST ISOURS		;* ALWAYS MATCHES
	CAIE C,COMOCT
	JRST FILLOP		;IGNORE BLANK LINES
	CAMN B,OURLIN		;FIND OUR LINE?
	JRST ISOURS		;YES
FILERR:	MOVEI A,.FHSLF
	GETER%
	HRRZ B,B
	CAIE B,IOX4
	 CAIN B,COMNX9		;EOF?
	  JRST FILNON		;YES, NONE FOUND
	FIELD(COMEOL,FILLOP)	;EAT LINE TO IGNORE
	JRST FILLOP

ISOURS:	FIELD(COMAND,TRMERR)
	HRRZ B,(B)
	MOVE D,B
	HRRZ C,C
	CAIN C,COMAND
	JRST FILDON		;CONFIRMED
	CAIN C,COMTYP
	MOVEI D,SETTYP
	CALL (D)
	 JRST TRMERR
	JRST ISOURS

TRMERR:	JSERR <TTYINI: Command error in file>
	TMSG <Will ignore terminal data line and continue scan
>
	JRST FILERR

FILNON:	MOVE A,[TMPARG,,DATABG]
	BLT A,DATABG+DATALN-1
	JRST FILDN1

FILDON:	HRROI A,[ASCIZ \%TTYINI: Ignoring /EXIT from file
\]
	SKIPL EXITS
	PSOUT%
	HRROI A,[ASCIZ \%TTYINI: Ignoring /HELP from file
\]
	SKIPL HELPS
	PSOUT%
	HRROI A,[ASCIZ \%TTYINI: Ignoring /LINE:n from file
\]
	SKIPL LINES		;DID USER SPECIFY LINE?
	PSOUT%
	HRROI A,[ASCIZ \%TTYINI: Ignoring /LIST from file
\]
	SKIPL LISTS		;DID USER SPECIFY /LIST?
	PSOUT%
FILDN1:	MOVE A,IJFN
	CLOSF%
	 JCERR <TTYINI: CLOSF failed>
	JRST FILCHK

COMXCT:	SKIPL B,TYPE
	JRST DOSTYP
	SKIPGE B,DTYPE		;DEFAULT?
	JRST NOSTYP
	MOVEM B,TYPE		;YES, SET AS TYPE
	CAIN B,-1
	CALL DOCHK
	SKIPN TYPE
	JRST NOSTYP
	SKIPGE B,TYPE
	JRST NOSTYP
DOSTYP:	CALL (B)
	TXNE F,TTYINA
	JRST [	TMSG <%TTYINI: Cannot set some paramters, line is not active.
>
		JRST NOTLNK]
	TXNE F,TTYASG
	JRST [	TMSG <%TTYINI: Cannot set terminal type, terminal is owned by someone else.
>
		JRST NOSTYP]
	MOVE A,TTYDES
	STTYP%
	 JCERR <TTYINI: STTYP failed>
NOSTYP:	SKIPGE RFCHNG
	 JRST NODORF
	TXNE F,TTYINA
	JRST [	TMSG <%TTYINI: Cannot set some paramters, line is not active.
>
		JRST NOTLNK]
	MOVE A,TTYDES
	RFMOD%
	 JWERR <TTYINI: Failed to read terminal data to set new status>,NODORF
	SKIPN LOWERF
	TXZ B,TT%LCA
	SKIPLE LOWERF
	TXO B,TT%LCA
	SKIPN FORMF
	TXZ B,TT%MFF
	SKIPLE FORMF
	TXO B,TT%MFF
	SKIPN TABF
	TXZ B,TT%TAB
	SKIPLE TABF
	TXO B,TT%TAB
	SKIPN FLAGF
	TXZ B,TT%UOC
	SKIPLE FLAGF
	TXO B,TT%UOC
	SKIPN RAISEF
	TXZ B,TT%LIC
	SKIPLE RAISEF
	TXO B,TT%LIC
	SKIPL C,LINEF
	STOR C,TT%DUM,B
IFNDEF .MOXOF,<
	SKIPN PAUSEF
	TXZ B,TT%PGM
	SKIPLE PAUSEF
	TXO B,TT%PGM
>;IFNDEF .MOXOF
IFDEF .MOXOF,<
	SKIPN PAUSCF
	TXZ B,TT%PGM
	SKIPLE PAUSCF
	TXO B,TT%PGM
>;IFDEF .MOXOF
	STPAR%
	 JWERR <TTYINI: Failed to set new terminal mode data>
NODORF:	SKIPGE C,LENGTH
	 JRST NOLEN
	MOVE A,TTYDES
	MOVEI B,.MOSLL
	MTOPR%
	 JWERR <TTYINI: Failed to set LENGTH>
NOLEN:	SKIPGE C,WIDTH
	 JRST NOWID
	MOVE A,TTYDES
	MOVEI B,.MOSLW
	MTOPR%
	 JWERR <TTYINI: Failed to set WIDTH>
NOWID:
IFDEF .MOXOF,<
	SKIPGE PAUSEF
	 JRST NOXOF
	MOVE A,TTYDES
	MOVEI B,.MOXOF
	MOVEI C,.MOONX
	SKIPN PAUSEF
	MOVEI C,.MOOFF
	MTOPR%
	 JWERR <TTYINI: Failed to set PAUSE-AT-END-OF-PAGE>
NOXOF:
>;IFDEF .MOXOF
	SKIPGE INDFFF		;CHANGING STATE OF INDICATE FORMFEED?
	 JRST NOIFF		;NO
	SKIPE D,INDFFF		;REQUESTING INDICATE?
	JRST [	MOVX D,1B<^D12*2+1>	;YES, SET TO THIS VALUE
		JRST DOIFF]
	MOVE A,TTYDES		;ELSE WE MUST CHECK IF FORMFEEDS ON TERMINAL
	RFMOD%
	 JWERR <TTYINI: Failed to read terminal data for setting
 NOINDICATE-FORMFEED status>,NOIFF
	TXNE B,TT%MFF		;MECH. FORMFEED?
	SKIPA D,[2B<^D12*2+1>]	;YES, SEND FF
	MOVX D,3B<^D12*2+1>		;NO, SIMULATE
DOIFF:	MOVE A,TTYDES
	RFCOC%			;READ CURRENT SETTINGS
	 JWERR <TTYINI: Failed to read terminal data for setting
 INDICATE-FORMFEED>,NOIFF
	TXZ B,3B<^D12*2+1>
	TDO B,D			;SET NEW STATE
	SFCOC%
	 JWERR <TTYINI: Failed to set control character output control words for
 INDICATE-FORMFEED>
NOIFF:	SKIPGE TLKFLG
	 JRST NOTLNK
	MOVE A,TTYDES
	SKIPL AADFLG
	TXO A,TL%STA
	SKIPLE AADFLG
	TXO A,TL%AAD
	SKIPL ALKFLG
	TXO A,TL%SAB
	SKIPLE ALKFLG
	TXO A,TL%ABS
	TLINK%
	 JCERR <TTYINI: Failed to set state of LINK-ACCEPT and/or ADVICE-ACCEPT>
NOTLNK:	SKIPGE MSGFLG
	 JRST NOSYSM
	MOVE A,TTYDES
	MOVEI B,.MOSNT
	MOVE C,MSGFLG
	MTOPR%
	 JWERR <TTYINI: Failed to set SYSTEM-MESSAGES>
NOSYSM:	SKIPGE USRFLG
	JRST NOUSR
	MOVE A,TTYDES
	MOVEI B,.MORTF
	MTOPR%
	 JWERR <TTYINI: Failed to read USER-MESSAGES flag>,NOUSR
	MOVX D,MO%NUM
	ANDCAM D,C
	SKIPN USRFLG
	OR C,[MO%NUM]
	MOVEI B,.MOSTF
	MTOPR%
	 JWERR <TTYINI: Failed to set USER-MESSAGES>
	
NOUSR:	SKIPGE INHFLG
	JRST NOINH
	MOVE A,TTYDES
	MOVEI B,.MORTF
	MTOPR%
	 JWERR <TTYINI: Failed to read INHIBIT flag>,NOINH
	MOVX D,MO%NTM
	ANDCAM D,C
	SKIPE INHFLG
	OR C,[MO%NTM]
	MOVEI B,.MOSTF
	MTOPR%
	 JWERR <TTYINI: Failed to set INHIBIT>
	
NOINH:	SKIPGE IGNFLG
	 JRST NOIGNR
	MOVE A,TTYDES
	MOVEI B,.MOSIG
	MOVE C,IGNFLG
	MTOPR%
	 JWERR <TTYINI: Failed to set IGNORE-INPUT>
NOIGNR:	SKIPGE SPDFLG
	 JRST NOSPD
	MOVE A,TTYDES
	MOVEI B,.MORSP
	MTOPR%
	 JWERR <TTYINI: Failed to read current SPEED and REMOTE status>,NOSPD
	SKIPL RMTFLG
	TXZ B,MO%RMT
	SKIPLE RMTFLG
	TXO B,MO%RMT
	SKIPL AUTFLG
	TXZ B,MO%AUT
	SKIPLE AUTFLG
	TXO B,MO%AUT
	HRRI B,.MOSPD
	SKIPL SPDWRD
	MOVE C,SPDWRD
	MTOPR%
	 JWERR <TTYINI: Failed to set SPEED and REMOTE status>
NOSPD:	SKIPGE NSPEED		;SPEED TO CUT-OFF AT SPECIFIED?
	 JRST CHKLST
	MOVE A,TTYDES
	MOVEI B,.MORSP
	MTOPR%
	 JWERR <TTYINI: Failed to read SPEED for NOPAGE-SPEED check>,CHKLST
	CAMN C,[-1]
	JRST CHKLST
	HRRZ C,C		;GET OUTPUT SPEED
	CAMLE C,NSPEED		;SPECIFIED SPEED LESS THAN ACTUAL?
	JRST CHKLST		;YES, LEAVE PAGE MODE ON
	MOVE A,TTYDES
	MOVEI B,.MOXOF
	MOVEI C,.MOOFF
	MTOPR%
	 JWERR <TTYINI: Failed to set NOPAUSE-AT-END-OF-PAGE for NOPAGE-SPEED>
CHKLST:	SKIPE LISTF
	JRST COMEND
	TXNN F,WHOPR		;CAN WE GET THIS DATA?
	 JRST LST2A		;Quietly skip IGNORE-INPUT state.
	SKIPL TTSTAT
	JRST GOTADR
	MOVEI A,.SNPSY
	MOVE B,[SQUOZE 0,TTSTAT]
	SETZ C,
	SNOOP%
	 ERJMP [JSERR <TTYINI: Failed to find address of system table to obtain IGNORE-INPUT state>
		JRST LST2A]
	HRRZM B,TTSTAT
GOTADR:	MOVE A,OURLIN
	ADD A,TTSTAT
	HRLI A,1
	MOVEI B,C
	PEEK%
	 ERJMP [JSERR <TTYINI: Failed to read table word containing IGNORE-INPUT state>
		JRST LST2A]
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	TXNN C,TT%IGI
	PSOUT%
	TMSG <IGNORE-INPUT
>
LST2A:	TXNE F,TTYASG
	TXNE F,WHOPR
	CAIA
	JRST [	TMSG <%TTYINI: Cannot read terminal SPEED, WIDTH, PAUSE-AT-END-OF-PAGE
 or REMOTE status, terminal is owned by someone else.
>
		JRST LST2]
	MOVE A,TTYDES
	MOVEI B,.MORSP
	MTOPR%
	 JWERR <TTYINI: Failed to read SPEED and REMOTE status for /LIST>,LST1
	MOVEM B,TMP1
	MOVEM C,TMP2
	TXNE B,MO%AUT
	JRST [	TMSG < /SPEED:AUTO-BAUD>
		JRST LST1A]
	TMSG < /SPEED:>
	HLRE B,TMP2
	JUMPL B,[TMSG <Unknown>
		JRST LST1B]
	CALL DECOUT
LST1B:	HRRE B,TMP2
	HLRE C,TMP2
	CAMN C,B
	JRST LST1A
	TMSG <:>
	JUMPL B,[TMSG <Unknown>
		JRST LST1A]
	CALL DECOUT
LST1A:	TMSG <
>
	MOVE B,TMP1
	HRROI A,[ASCIZ \ /REMOTE
\]
	TXNE B,MO%RMT
	PSOUT%
LST1:	MOVE A,TTYDES
	MOVEI B,.MORTF
	MTOPR%
	 JWERR <TTYINI: Failed to read INHIBIT and USER-MESSAGES for /LIST>,LSTZ
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	TXNE C,MO%NUM
	PSOUT%
	TMSG <USER-MESSAGES
>
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	TXNN C,MO%NTM
	PSOUT%
	TMSG <INHIBIT
>

LSTZ:	MOVE A,TTYDES
	MOVEI B,.MORNT
	MTOPR%
	 JWERR <TTYINI: Failed to read SYSTEM-MESSAGES status for /LIST>,LST2
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	CAIE C,.MOSMY
	PSOUT%
	TMSG <SYSTEM-MESSAGES
>
LST2:	TXNE F,TTYINA		;CANNOT READ THIS FOR INACTIVE LINE
	JRST [	TMSG <%TTYINI: Cannot read remainder of terminal data, line is not active.
>
		JRST COMEND]
	MOVE A,TTYDES
	GTTYP%
	 JWERR <TTYINI: Failed to read terminal type for /LIST>,LST2D
	SKIPL B
	CAILE B,TYPLEN
	MOVEI B,TYPLEN
	TMSG < TERMINAL TYPE: >
	SKIPE A,TYPTAB(B)
	JRST LST2E
	MOVEI A,.PRIOU
	MOVEI C,10
	NOUT%
	 JCERR <>
	HRROI A,[ASCIZ / (Octal)/]
LST2E:	PSOUT%
	TMSG <
>
LST2D:	MOVE A,TTYDES
	RFMOD%
	 JWERR <TTYINI: Failed to read terminal mode data for /LIST>,LST2B
	MOVE D,B
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%PGM
	PSOUT%
	TMSG <PAUSE-ON-COMMAND
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%ALK
	PSOUT%
	TMSG <LINK-ACCEPT
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%AAD
	PSOUT%
	TMSG <ADVICE-ACCEPT
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%MFF
	PSOUT%
	TMSG <FORMFEED
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%TAB
	PSOUT%
	TMSG <TAB
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%LCA
	PSOUT%
	TMSG <LOWERCASE
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%UOC
	PSOUT%
	TMSG <FLAG-UPPERCASE
 />
	HRROI A,[ASCIZ /NO/]
	TXNN D,TT%LIC
	PSOUT%
	TMSG <RAISE-INPUT
 />
	LOAD C,TT%DUM,D
	HRROI A,[ASCIZ /UNKNOWN/]
	CAIN C,.TTFDX
	HRROI A,[ASCIZ /FULL/]
	CAIN C,.TTHDX
	HRROI A,[ASCIZ /HALF/]
	CAIN C,.TTLDX
	HRROI A,[ASCIZ /LINE-HALF/]
	PSOUT%
	TMSG <DUPLEX
>
LST2B:	MOVE A,TTYDES
	RFCOC%
	 JWERR <TTYINI: Failed to read terminal data for INDICATE-FORMFEED for /LIST>,LST2C
	LDB B,[POINT 2,B,^D12*2+1]
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	CAIN B,2
	PSOUT%
	TMSG <INDICATE-FORMFEED
>
LST2C:	TXNE F,TTYASG
	TXNE F,WHOPR
	CAIA
	JRST COMEND
	MOVE A,TTYDES
	MOVEI B,.MORLW
	MTOPR%
	 JWERR <TTYINI: Failed to read WIDTH for /LIST>,LST3
	TMSG < /WIDTH:>
	MOVE B,C
	CALL DECOUT
	TMSG <
>
LST3:	MOVE A,TTYDES
	MOVEI B,.MORLL
	MTOPR%
	 JWERR <TTYINI: Failed to read WIDTH for /LIST>,LST4
	TMSG < /LENGTH:>
	MOVE B,C
	CALL DECOUT
	TMSG <
>
LST4:	MOVE A,TTYDES
	MOVEI B,.MORXO
	MTOPR%
	 JWERR <TTYINI: Failed to read PAUSE-AT-END-OF-PAGE status for /LIST>,COMEND
	TMSG < />
	HRROI A,[ASCIZ /NO/]
	SKIPN C
	PSOUT%
	TMSG <PAUSE-AT-END-OF-PAGE
>
	JRST COMEND

DEFINE TYP(NAME)<-1,,[ASCIZ /NAME/]>

TYPTAB:	LDBLK(<<.TT33,TYP 33>,<.TT35,TYP 35>,<.TT37,TYP 37>,<.TTEXE,TYP EXECUPORT>,<.TTDEF,TYP SYSTEM-DEFAULT>,<.TTIDL,TYP IDEAL>,<.TTV05,TYP VT05>,<.TTV50,TYP VT50>,<.TTL30,TYP LA30>,<.TTG40,TYP GT40>,<.TTL36,TYP LA36>,<.TTV52,TYP VT52>,<.TT100,TYP VT100






























>,<.TTL38,TYP LA38>,<.TT120,TYP LA120>,<.TT125,TYP VT125>,<.TTK10,TYP VK100>,<.TT102,TYP VT102>,<.TTH19,TYP H19>,<.TT131,TYP VT131>,<.TT200,TYP VT200-SERIES>>)
	0
TYPLEN==.-TYPTAB
SUBTTL	HELP TEXT
HLPMES:	ASCIZ \
TTYINI sets the monitor's terminal type and terminal parameters.
By default, TYYINI reads the necessary information from the file
SYSTEM:TTYINI.CMD. You may selectively override any or all of the
values contained in the file or you may request that TTYINI determine
the terminal type by querying the terminal itself.
By default TTYINI sets terminal parameters for the current job; however,
TTYINI may be used to setup parameters for another job or line by
using the /LINE: switch (see description below).

The command format is an optional terminal type name followed by
optional switches.

Available terminal type names:

33		Model 33 hardcopy terminal.
35		Model 35 hardcopy terminal.
37		Model 37 hardcopy terminal.
CHECK		Synonym for INQUIRE.
CT		DEC CT terminal in VT100 mode.
CTRO		DEC CT Receive-Only printer.
DEFAULT		System default terminal type.
EP1		DEC EP1 electronic printer.
EXECUPORT	Execuport terminal.
GIGI		DEC VK100 in VT100 terminal mode.
GT40		DEC GT40 graphics terminal.
IDEAL		Does no special character processing.
INQUIRE		Special type. When given, causes the terminal
		to be polled to determine type. If the type is
		successfully determined, reading of any file is
		suppressed.  A report is typed of the form:
		[Terminal type is ACTUAL(SET)]
		Where ACTUAL is the type of terminal and SET is the
		monitor terminal type set for the job.
		Batch jobs are reported as BATCH and no terminal
		parameters are set. Jobs on PTYs are reported as PTY
		and no terminal parameters are set. The terminal
		connected to DECtalk is properly queried.
LA12		DEC LA12 terminal.
LA120		DEC LA120 terminal.
LA180		DEC LA180 terminal.
LA24		DEC LA24 terminal.
LA30		DEC LA30 terminal.
LA34		DEC LA34 terminal.
LA36		DEC LA36 terminal.
LA38		DEC LA38 terminal.
LA80		DEC LA80 terminal.
LQP02		DEC LQP02 terminal.
LQPSE		DEC LQPSE-F terminal.
TI		Same as EXECUPORT.
VT05		DEC VT05 video terminal.
VT100		DEC VT100 video terminal.
VT102		DEC VT102 video terminal.
VT125		DEC VT125 video terminal.
VT131		DEC VT131 video terminal.
VT132		DEC VT132 video terminal.
VT200-SERIES	DEC VT200 class video terminal.
VT220		DEC VT220 video terminal.
VT240		DEC VT240 video terminal.
VT241		DEC VT241 video terminal.
VT278		DEC VT278 video terminal.
VT132		DEC VT132 video terminal.
VT50		DEC VT50 video terminal.
VT52		DEC VT52 video terminal.
VT55		DEC VT55 video terminal. (VT52 with printer)
VT61		DEC VT61 video terminal.
VT80		DEC VT80 video terminal.

The following switches may be given:

/ADVICE-ACCEPT	Set to accept advice from other users.
		This allows other users to type commands at
		your terminal using the "ADVISE" command.
/ASSIGN		Assign the controlling terminal or terminal
		specified with the /LINE: switch to this job.
/AUTO-BAUD	Set terminal speed to automatic baud rate detection.
		This can only be set by WHEEL or OPERATOR and is used
		on REMOTE lines.
/CHARACTERISTICS
		Used with INQUIRE. After the terminal type has been
		determined, query the terminal further and report all
		known terminal characteristics, such as Advanced Video
		Option for VT100s.
/CHECK		Same as INQUIRE.
/DEFAULT-TYPE:type-name
		If terminal type not specified, use this type.
/EXIT		Exit at end of command.
/FILE:filespec	Read "filespec" for terminal data by line number.
		If ":filespec" is omitted, the default file
		SYSTEM:TTYINI.CMD will be searched even if
		the specified line is not the controlling TTY.
/FLAG-UPPERCASE	Flag upper case output (precede by ').
/FORMFEED	Say terminal has hardware formfeed.
/FULLDUPLEX	Set terminal to FULL DUPLEX mode.
/HALFDUPLEX	Set terminal to CHARACTER HALF DUPLEX mode.
/HELP:filespec	Output this text to the specified filespec.
		If the "filespec" is omitted, TTY: is assumed.
		If a "filespec" is given, the default is TTYINI.HLP.
/IGNORE-INPUT	Set terminal to ignore ^C typed when not in use.
/INDICATE-FORMFEED
		Set to output ^L for formfeed character.
/INHIBIT	Inhibit non-job output on this terminal.
/INQUIRE	Same as INQUIRE.
/LENGTH:n	Set terminal length (lines per page) to "n".
/LINE:n		Set terminal to operate on to "TTYn". "n" is octal.
/LINE:dev:	Set terminal to operate on to device "dev".
		"dev" must be a terminal.
/LINK-ACCEPT	Set to accept links from other users.
		This allows other users to converse with
		your terminal using the "TALK" command.
/LIST		List setting of all monitor terminal parameters. An enabled
		WHEEL or OPERATOR can do this for a terminal assigned
		to another user as well as determine the state of the
		IGNORE-INPUT bit. A terminal which is not in use does
		not have some parameters set at all. A warning is
		printed in this case. Some parameters may be read
		by anyone even if the terminal is assigned to another
		user. You are informed when some information is not
		available and why.
		Use INQUIRE/CHARACTERISITICS to list the terminals parameters.
/LOWERCASE	Pass lower case characters to terminal.
/NOFILE		Never read a file.
/NOFLAG		Don't flag upper case output.
/NOFORMFEED	Simulate formfeed characters.
/NOINDICATE	Set to either pass formfeeds directly to terminal
		or simulate form action depending on /FORMFEED or
		/NOFORMFEED status respectively.
/NOINHIBIT	Allow non-job output on this terminal.
/NOLOWERCASE	Convert lower case to upper case on output.
/NOPAGE-SPEED:n
		The value "n" is the speed at or below which to
		disable /PAUSE-AT-END-OF-PAGE. If the speed
		of output from the computer to the terminal is
		higher than the specified speed, the /PAUSE-ON-
		END-OF-PAGE will be allowed either implicitly or
		explicitly. The following speeds are allowed:

		110	1200	134	150	1800	200
		2400	300	4800	50	600	75	9600

/NOPAUSE-AT-END-OF-PAGE
		Don't stop output when end of page is reached.
/NOPAUSE-ON-COMMAND
		Don't use ^S and ^Q to stop and start typeout on terminal.
/NORAISE-INPUT	Don't convert lower case to upper case on input.
/NOREMOTE	Set terminal to not be a REMOTE line. This enables the
		line for input even if carrier detect is not asserted.
/NOSYSTEM-MESSAGES
		Disable output of system wide message to this terminal.
/NOTAB		Simulate tab characters.
/NOUSER-MESSAGES
		Disable output of user messages to this terminal.
/PAUSE-AT-END-OF-PAGE
		Stop terminal output at end of page (when lines per
		page lines have been output). Type ^Q to cause output
		to continue. This feature is disabled if /PAUSE-ON-COMMAND
		is not enabled.
/PAUSE-ON-COMMAND
		Enable ^S to stop terminal output and ^Q to resume it.
/RAISE-INPUT	Convert lower case to upper case on input.
/REMOTE		Set terminal to not accept input unless carrier detect
		is asserted. This is used for dial-up lines.
/SPEED:in:out	Set terminal speed to those specified by "in" and "out".
		If "out" is omitted, it is assumed to be the same as "in".
		The following speeds are allowed:

		0	110	1200	134	150	1800	200
		2400	300	4800	50	600	75	9600

/SYSTEM-MESSAGES
		Allow output of system wide message to this terminal.
/TAB		Send tab characters directly to terminal.
/TAKE		Suppress %End of file message when the end of the
		current take file is reached.
/TAKE:		Take input from PS:<logged-in-directory>TTYINI.CMD.
/TAKE:filespec	Take command input from the specified file. When the
		end of file is reached the message:
			%End of filespec
		is printed and input returns to previous file or terminal.
		/TAKE: may appear in command files nested to a level of 20.
		The following switches are ignored in command files:
		/HELP, /LIST, /EXIT, and /LINE.
/USER-MESSAGES	Allow output of user messages to this terminal.
/VTXXX-52	Used in conjuction with INQUIRE option. If the terminal is
		successfully identified as a terminal with VT52 compatibility
		mode, it is switched to VT52 mode, if necessary, and the
		terminal type is set to VT52.
/VTXXX-100	Used in conjuction with INQUIRE option. If terminal is
		successfully identified as a terminal with VT100 compatibility
		mode, it is switched to VT100 mode, if necessary,  and the
		terminal type VT100 is set.
/VTXXX-102	Used in conjuction with INQUIRE option. If terminal is
		successfully identified as a terminal with VT102 compatibility
		mode, it is switched to VT102 mode, if necessary,  and the
		terminal type VT102 is set. If the terminal cannot act as a
		VT102, but can act as a VT100, then this switch will perform
		the same action as the VTXXX-100 switch.
/VTXXX-200	Used in conjuction with INQUIRE option. If terminal is
		successfully identified as a terminal with VT200 compatibility
		mode, it is switched to VT200 with 7-bit control mode, if
		necessary, and the VT200 terminal type is set.
		Note that the VT220 does not support this feature.
/WIDTH:n	Set terminal width to "n" characters.

If terminal type is not given and no /FILE:filespec or /NOFILE switches
but some parameter is being set, the file SYSTEM:TTYINI.CMD is read.
As a special case, the EXEC command "TTYINI" alone will cause this file
to be read as well. Each line of the file has the following format:

<line #> <same as TTYINI command line>

The <line #> indicates which line the command line applies to. A "*" in
place of the <line #> will cause that line to be used if the desired line
number has not yet been found. The file is parsed using the COMND JSYS.

Examples:

	TTYINI<cr>

Determine terminal data from SYSTEM:TTYINI.CMD by line number.

	TTYINI/INQUIRE/VTXXX-100/NOPAUSE-AT-END

Determine terminal type by querying the terminal. If the terminal is
VT100 compatible, set the monitor's terminal type to VT100. Do
not pause at end of page.

The following type names imply the indicated default switches
unless explicity overridden:


CT	VT100
CTRO	LA120
EP1	LA120
GIGI	VK100
GT40	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
LA12	LA120/FORMFEED/WIDTH:80
LA120	/NORAISE-INPUT/LOWERCASE
LA180	LA120/NORAISE-INPUT/NOTAB/LOWERCASE/NOPAUSE-AT-END-OF-PAGE
LA24	LA34
LA30	LA36
LA34	LA120/NORAISE-INPUT/NOFORMFEED/LOWERCASE
LA36	/NORAISE-INPUT/LOWERCASE
LA38	/NORAISE-INPUT/LOWERCASE
LA38	LA34
LA80	LA120
LQP02	LA12
LQPSE	LA34
VT05	/RAISE-INPUT/NOPAUSE-AT-END-OF-PAGE
VT100	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT102	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT125	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT131	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT132	VT131/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT200	VT200/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT220	VT200/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT240	VT200/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT241	VT200/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT278	VT52
VT50	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE
VT52	/NORAISE-INPUT/NOPAUSE-AT-END-OF-PAGE/LOWERCASE
VT55	VT52
VT61	VT52
VT61	VT52
VT80	VT100
\
SUBTTL	CHECK HANDLER, TYPE ROUTINES
DOCHK:	TXNE F,TTYINA	;CAN'T DO THIS IF INACTIVE
	JRST [	TMSG <%TTYINI: Cannot do CHECK, line is not active.
>
		RET]
	TXNE F,TTYASG
	TXNE F,WHOPR
	CAIA
	JRST [	TMSG <%TTYINI: Cannot do CHECK, terminal is owned by someone else.
>
		RET]
	SETZM CHRPTR
	TMSG <[Terminal type is >
	HRREI A,-1
	MOVE B,[-1,,D]
	MOVEI C,.JIBAT		;BATCH?
	GETJI%
	 JWERR <TTYINI: Failed to get batch flag from GETJI>,NOBAT
	SKIPL D
	JRST NOBAT
	TMSG <BATCH]
>
	SETZM TYPE
	RET
NOBAT:	
	MOVE A,PTY0
	HLRZ B,A		;PTY COUNT
	HRRZ A,A		;FIRST PTY NUMBER
	CAMLE A,OURLIN		;SKIP IF THIS LINE # LESS THAN FIRST PTY #
	JRST NOPTY		;WE ARE A REAL TTY
	MOVN A,A
	ADD A,OURLIN
	ADDI A,1
	CAMLE A,B		;IS THIS A REAL PTY?
	JRST NOPTY
	TMSG <PTY]
>
	SETZM TYPE
	RET
NOPTY:	MOVE A,TTYDES
	DOBE%			;WAIT TILL OUT
	CFIBF%
	RFMOD%
	 JWERR <TTYINI: Failed to read terminal data modes to save for CHECK, aborting CHECK>,CHKEN1
	MOVEM B,SAVMOD
	TDZ B,[TT%ECO!TT%DAM]
	SFMOD%
	 JWERR <TTYINI: Failed to set terminal to image mode, aborting CHECK>,CHKEN1
	DOBE%
	SETOM PASS		;FIRST PASS
	HRROI B,[BYTE(7)33,132,0] ;QUERY FOR FIRST PASS
PASS2:	MOVE A,TTYDES
	SETZ C,
	SOUT%			;QUERY TERMINAL
	 JWERR <TTYINI: Failed to send query sequence to terminal, aborting CHECK>,CHKBAD
	DOBE%
DOWAIT:	MOVEI C,^D20		;20 * 250 MS = 5 SECONDS

	MOVE A,PTY0
	HLRZ B,A		;PTY COUNT
	HRRZ A,A		;FIRST PTY NUMBER
	CAMLE A,OURLIN		;SKIP IF THIS LINE # LESS THAN FIRST PTY #
	JRST CHKLOP		;WE ARE A REAL TTY

	MOVEI C,^D40		;NON TTY, WAIT 40 * 250 MS = 10 SEC.  THIS IS SO
				;THAT LOGING IN OVER THE NETWORK ALLOWS MORE
				;TIME FOR THE TERMINAL TO RESPOND.

CHKLOP:	SOJL C,CHKLOS
	CALL GETCHR
	 JRST CHKLOP
	CAIN A,12		;USE THIS FOR TRY SECOND PASS
	JRST CHKLOS
	CAIE A,33		;CORRECT RESPONSE?
	JRST CHKBAD		;NOT EVEN FIRST CHARACTER CORRECT
	CALL GETCHR
	 JRST CHKLOS
	CAIE A,"/"		;DEC terminal response?
	 JRST CKANSI		;NO, TRY ANSI RESPONSE
	CALL GETCHR		;yes, get arg
	 JRST CHKLOS
	CAIL A,"#"
	 CAILE A,"#"+DECMAX-1
	  JRST CHKLOS		;NOT IN DESIRED RANGE
	SKIPN DECTAB-"#"(A)
	 JRST CHKLOS		;NO ENTRY FOR THIS ONE
	MOVEI E,DECTAB-"#"(A)
	CAIN E,T10052		;IS THIS VT100 IN 52 MODE?
	 SKIPG VTXXXF		;YES, REQUESTING SWITCH TO 100 MODE?
	  CAIA			;NO, OK
	   JRST S100AN		;YES, SWITCH TO 100 MODE
	MOVE D,DECTAB-"#"(A)
	SKIPE CHARF
	JRST CHKOK
	MOVE E,[ASCIZ /copier/]
	CAIN A,"J"
	MOVEM E,CHRPTR
	CAIN A,"L"
	MOVEM E,CHRPTR
	CAIN A,"a"
	MOVEM E,CHRPTR
	MOVE E,[ASCIZ /printer/]
	CAIN A,"M"
	MOVEM E,CHRPTR
	CAIN A,"b"
	MOVEM E,CHRPTR
	MOVE E,[ASCIZ /copier, printer/]
	CAIN A,"c"
	MOVEM E,CHRPTR
CHKOK:	MOVE A,TTYDES
	CFIBF%
	JRST CHKEND

S100AN:	MOVE A,TTYDES
	HRROI B,[BYTE(7)33,"<",0]	;SET TO VT100-ANSI MODE
	SETZ C,
	SOUT%
	HRROI B,[BYTE (7)33,133,"C"+40,0]
	JRST PASS2

CHKBAD:	SETZM PASS		;IF BAD RESPONSE, NO SECOND-PASS
CHKLOS:	MOVE A,TTYDES
	CFIBF%
	AOSN PASS		;IS THIS FIRST PASS?
	JRST [	HRROI B,[BYTE (7)33,133,"C"+40,33,"\",0]
		JRST PASS2]	;YES, TRY AGAIN WITH ANSI QUERY SEQ, SEND VT52
				;EXIT HOLD SCREEN MODE TO PREVENT LOCKUP OF
				;VT52, VT61, ETC IF THEY DON'T ANSWER.
	MOVE D,[-1,,[ASCIZ /UNKNOWN/]]
CHKEND:	MOVE A,TTYDES
	MOVE B,SAVMOD
	SFMOD%
	 JWERR <TTYINI: Failed to restore terminal data modes>
	HRROI A,[ASCIZ /DECtalk and /]
	SKIPN DTALKF
	PSOUT%
	HLREM D,TYPE
	HRRZ A,D
	PSOUT%
	TMSG <(>
	MOVE B,TYPE
	JUMPL B,NOTYP
	CALL (B)
	MOVE A,TYPTAB(B)
	PSOUT%
NOTYP:	TMSG <)>
	TMSG <]
>
	SKIPN CHRPTR
	RET
	TMSG <[Characteristics: >
	MOVE A,CHRPTR
	SKIPE A
 	PSOUT%
	TMSG <]
>
	RET

CHKEN1:	SETOM TYPE
	RET

CKANSI:	CAIE A,"["
	 JRST CKSUDS
	MOVEI C,"?"
	CALL CHKCHR
	 JRST CHKLOS
	SETZ E,
	CALL GETCHR		; GET TYPE CODE
	 JRST CHKLOS
	CAIL A,"0"
	 CAILE A,"9"
	  JRST CHKLOS
CKGTYP:	SUBI A,"0"
	IMULI E,^D10
	ADD E,A
	CALL GETCHR
	 JRST CHKLOS
	CAIL A,"0"
	 CAILE A,"9"
	  SKIPA
	JRST CKGTYP
	CAIE A,";"
	 CAIN A,"C"+40
	  SKIPG E
	JRST CHKLOS
	CAILE E,ANSIMX
	 JRST CHKLOS
	SKIPN CHARF
	CALL CHARR
	MOVEI E,ANSITB-1(E)
	CAIN A,"C"+40
	 JRST CHKANE
;NOW GOBBLE ARBITRARY SEQUENCE OF DIGITS AND/OR SEMICOLONS
CHKARG:	CALL GETCHR
	 JRST CHKLOS
	CAIN A,";"
	 JRST CHKARG
	CAIL A,"0"
	 CAILE A,"9"
	  JRST CHKANE
	JRST CHKARG

CHKANE:	CAIE A,"C"+40
	JRST CHKLOS

	CAIN E,TALK		;IS IT A DECTALK
	JRST DECTLK		;YES
	CAIN E,T1001		;VTXXX IN ANSI MODE?
	JRST IS100
	CAIN E,T1002
	JRST IS100
	CAIN E,T1003
	JRST IS100
	CAIN E,T1004
	JRST IS100
	CAIN E,T1005
	JRST IS100
	CAIN E,T1006
	JRST IS100

	CAIN E,T1002
	JRST IS100
	JRST NOT100

IS100:	SKIPN VTXXXF		;YES, REQUESTING SWITCH TO 52 MODE?
	JRST S10052		;YES, DO IT

NOT100:	CAIE E,T2001		;ARE WE A VT200?
	JRST NOT200
	MOVE A,VTXXXF
	CAIN A,WVT52		;WANT TO BE A VT52?
	JRST S10052
	CAIE A,WVT102		;WANT TO BE A VT102 OR
	CAIN A,WVT100		;A VT100?
	JRST S20010
	CAIN A,WVT200		;WANT TO BE A VT200?
	JRST S20020

NOT200:	SKIPN D,(E)		;GET DISPATCH AND STRING (IF ANY)
	JRST CHKLOS
	JRST CHKOK

S20010:	MOVE A,TTYDES
	HRROI B,[BYTE(7)33,"[","6","1","""","p",0]
	SETZ C,
	SOUT%
	MOVE D,[$TT100,,[ASCIZ /VT200-SERIES/]]
	MOVE A,VTXXXF
	CAIN A,WVT102
	HRLI D,$TT102
	JRST CHKOK

S20020:	MOVE A,TTYDES
	HRROI B,[BYTE(7)33,"[","6","2",";","1","""","p",0]
	SETZ C,
	SOUT%
	MOVE D,T2001
	JRST CHKOK

S10052:	MOVE A,TTYDES
	HRROI B,[BYTE(7)33,"[","?","2","L"+40,0]	;SET TO VT100-52 MODE
	SETZ C,
	SOUT%
	MOVE D,T10052		;ASSUME OK, GET DISPATCH FOR VT100-52
	JRST CHKOK

DECTLK:	SETZM DTALKF
	JRST DOWAIT

CHARR:	PUSH P,E
	CAIN E,^D62
	JRST CHAR20		; GET CHARACTERISTICS OF VT200
	CAIN A,"c"
	 JRST CHRRET
	CALL GETCHR
	 JRST CHRRET
	CAIL A,"0"
	 CAILE A,"9"
	  JRST CHRRET
	SETZ E,
CHARR1:	SUBI A,"0"
	IMULI E,^D10
	ADD E,A
	CALL GETCHR
	 JRST CHRRET
	CAIL A,"0"
	 CAILE A,"9"
	  SKIPA
	JRST CHARR1
	MOVE E,CHRTAB(E)
	MOVEM E,CHRPTR

CHRRET: POP P,E
	RET

CHAR20:
	MOVE S,[POINT 7,CHRBUF]
CHAR6:	CALL GETCHR
	 JRST CHRRET
	CAIL A,"0"
	 CAILE A,"9"
	  JRST CHRRET
	SETZ E,
CHARR2:	SUBI A,"0"
	IMULI E,^D10
	ADD E,A
	CALL GETCHR
	 JRST CHRRET
	CAIL A,"0"
	 CAILE A,"9"
	  SKIPA
	JRST CHARR2
	CAIL E,VT2END
	JRST CHAR4
	MOVE E,VT2TAB(E)
	HRLI E,(POINT 7,)
CHAR3:	ILDB B,E
	JUMPE B,CHAR4
	IDPB B,S
	JRST CHAR3

CHAR4:	CAIE A,"c"
	JRST CHAR5
	SETZ B,
	IDPB B,S
	MOVE S,[POINT 7,CHRBUF]
	MOVEM S,CHRPTR
	JRST CHRRET
CHAR5:	MOVEI B,","
	IDPB B,S
	MOVEI B," "
	IDPB B,S
	JRST CHAR6

CKSUDS:	CAIE A,"\"		;SUDS TERMINAL?
	JRST CHKLOS
	CALL GETCHR		;yes, get arg
	 JRST CHKLOS
	CAIL A,"A"
	CAILE A,"A"+SUDMAX-1
	JRST CHKLOS		;NOT IN DESIRED RANGE
	SKIPN SUDTAB-"A"(A)
	JRST CHKLOS
	MOVE D,SUDTAB-"A"(A)
	JRST CHKOK

CHKCHR:	CALL GETCHR
	 RET
	CAMN C,A
	RETSKP
	RET

GETCHR:	MOVE A,TTYDES
	SIBE%
	JRST GETCH1
	MOVEI A,^D250
	DISMS%
	MOVE A,TTYDES
	SIBE%
	JRST GETCH1
	RET

GETCH1:	MOVE A,TTYDES
	BIN%
	MOVE A,B
	ANDI A,177
	RETSKP

$TT33:	MOVEI B,.TT33
	RET

$TT35:	MOVEI B,.TT35
	RET

$TT37:	MOVEI B,.TT37
	RET

$TTDEF:	MOVEI B,.TTDEF
	RET

$TTEXE:	MOVEI B,.TTEXE
	RET

$TTG40:	MOVEI B,.TTG40
	JRST VIDXIT

$TTIDL:	MOVEI B,.TTIDL
	RET

$TTL12:	MOVEI B,.TT120
	DEFAULT FORMF,1
	DEFAULT WIDTH,^D80
	JRST LOWXIT

$TTL30:	MOVEI B,.TTL30
	RET

$TTL34:	MOVEI B,.TT120
	DEFAULT FORMF,0
	JRST LOWXIT

$TTL36:	MOVEI B,.TTL36
	JRST LOWXIT

$TTL38:	MOVEI B,.TTL38
	JRST LOWXIT

$TTV05:	MOVEI B,.TTV05
	DEFAULT RAISEF,1
	AOS RFCHNG
	RET

$TTV50:	MOVEI B,.TTV50
	AOS RFCHNG
	RET

$TT120:	MOVEI B,.TT120
	JRST LOWXIT

$TT180:	MOVEI B,.TT120
	DEFAULT PAUSEF,0
	DEFAULT TABF,0
	JRST LOWXIT

$TT125:	MOVEI B,.TT125
	MOVE A,VTXXXF
	CAIE A,WVT100
	CAIN A,WVT102
	MOVEI B,.TT100
	JRST VIDXIT

$TTK10:	MOVEI B,.TTK10
	MOVE A,VTXXXF
	CAIE A,WVT100
	CAIN A,WVT102
	MOVEI B,.TT100
	JRST VIDXIT

$TT102:	MOVEI B,.TT102
	MOVE A,VTXXXF
	CAIN A,WVT100
	MOVEI B,.TT100
	JRST VIDXIT

$TTH19:	MOVEI B,.TTH19
	JRST VIDXIT

$TT131:	MOVEI B,.TT131
	MOVE A,VTXXXF
	CAIN A,WVT100
	MOVEI B,.TT100
	CAIN A,WVT102
	MOVEI B,.TT102
	JRST VIDXIT

$TT200:	MOVEI B,.TT200
	MOVE A,VTXXXF
	CAIN A,WVT100
	MOVEI B,.TT100
	CAIN A,WVT102
	MOVEI B,.TT102
	JRST VIDXIT

$TT100:
	SKIPA B,[.TT100]
$TTV52:	MOVEI B,.TTV52
VIDXIT:	DEFAULT PAUSEF,0
LOWXIT:	DEFAULT RAISEF,0
	DEFAULT LOWERF,1
	AOS RFCHNG
	RET

$80532:	DEFAULT LENGTH,^D32
	JRST $TT805

$80542:	DEFAULT LENGTH,^D42
$TT805:	MOVEI B,.TTV05
	JRST $TTS80

$85232:	DEFAULT LENGTH,^D32
	JRST $TT852

$85242:	DEFAULT LENGTH,^D42
$TT852:	MOVEI B,.TTV52
$TTS80:	DEFAULT WIDTH,^D80
	JRST VIDXIT

$70532:	DEFAULT LENGTH,^D32
	JRST $TT705

$70542:	DEFAULT LENGTH,^D42
$TT705:	MOVEI B,.TTV05
	JRST $TTS70

$75232:	DEFAULT LENGTH,^D32
	JRST $TT752

$75242:	DEFAULT LENGTH,^D42
$TT752:	MOVEI B,.TTV52
$TTS70:	DEFAULT WIDTH,^D70
	JRST VIDXIT
SUBTTL	/TAKE:filespec
DECOUT:	MOVEI A,.PRIOU
	MOVEI C,^D10
	NOUT%
	 JCERR <TTYINI: Unexpected error from NOUT>
	RET

DOTAKE:	TXNN A,CM%SWT
	JRST DOTAK1		;NO COLON, END QUIETLY
	HRREI A,-1
	MOVE B,[-1,,D]
	MOVEI C,.JIUNO
	GETJI%
	 JCERR <TTYINI: Unexpected error from GETJI>
	MOVE A,[POINT 7,LOGIN]
	MOVE B,D
	DIRST%
	 JCERR <TTYINI: Unexpected error from DIRST>
	MOVE A,[POINT 7,LOGIN]
	MOVEM A,TAKBLK+.GJDIR
	MOVE A,[TAKBLK,,TAKLEN]
	CALL FILINI
	FIELD(TAKFIL)
	HRRZ C,C
	CAIN C,COMCFM
	JRST DOTAK1
	MOVE D,B
	MOVE A,CMJFNP
	AOBJP A,[TMSG <?TTYINI: Too many nested "/TAKE" commands.
>
		RET]
	MOVE A,D
	MOVX B,<FLD(7,OF%BSZ)!OF%RD>
	OPENF%
	 JRERR <TTYINI: Error opening command input file.
>
	MOVE A,CMJFNP
	PUSH A,CMJFNS
	MOVEM A,CMJFNP
	HRLI D,.NULIO
	MOVSM D,CMJFNS
	RETSKP

DOTAK1:	SKIPE CMJFNS
	CALL TAKFIN
	RETSKP

	END XWD EVL,EV