/17 SUPER TTY HANDLER FOR OS/8
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974,1975,1977 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE
/AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
/CORPORATION.  DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS DOCUMENT.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED TO THE PURCHASER
/UNDER A LICENSE FOR USE ON A SINGLE COMPUTER SYSTEM AND CAN BE COPIED
/(WITH INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR USE IN SUCH
/SYSTEM, EXCEPT AS MAY OTHERWISE BE PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/

/S.W.,S.R.,H.J.,R.L.,S.R.

	*0

	-1
	DEVICE KL8E;DEVICE TTY;0;TTY&177+4000;ZBLOCK 2

/TWO-PAGE TELETYPE HANDLER FOR OS/8 V3.
/ON INPUT, RECOGNIZES ^Z, ^C, ^U, RUBOUT
/^Z	MEANS END OF INPUT, INSERT ^Z IN BUFFER,
/	PAD WITH ZEROES, AND ECHO "^Z"
/^C	MEANS ABORT JOB, RETURN TO OS/8 VIA LOC 7600 TO SAVE CORE AND PRINT "^C"
/^U	MEANS DELETE THE LAST LINE, ALLOW OPERATOR TO RETYPE
/	(LINE STARTS AT BEGIN OF BUFFER AND IS TERMINATED BY A CR)
/	A CR GETS ENTERED INTO BUFFER, CAUSES A LF TO ALSO ECHO
/	AND GET ENTERED INTO BUFFER, BUFFER IS THEN PADDED WITH NULLS.
/	CONVERTS LC TO UC

/ON OUTPUT RECOGNIZES ^C, ^O, ^S, ^Q FROM KEYBOARD
/^C	CAUSES JOB TO ABORT, RETURN TO OS/8 VIA LOCATION 7600
/	TO SAVE CORE AND PRINT "^C"
/^O	CAUSES ECHOING BY THE HANDLER TO CEASE
/	TYPING ANY OTHER CHARACTER RESUMES ECHOING.
/^S	CAUSES THE HANDLER TO STOP SENDING TO TERMINAL
/^Q	RESUMES HANDLER SENDING
/	^S AND ^Q ARE IGNORED  IN OTHER CASES

/WHENEVER PRINTING CHARACTERS (EITHER ON OUTPUT OR WHEN ECHOING),
/	IGNORES NULLS
/	FLAGS LC WITH AN APOSTROPHE
/	HANDLES TABS CORRECTLY (SEVERAL WAYS)
/	PRINTS ESCAPE AS $
/	DELAYS 16 MS AFTER LINEFEEDS
/	PRINTS CONTROL CHARACTERS AS "^K"

/DOES AUTOMATIC CR/LF AT END OF LINE WIDTH.

/MAINTENANCE RELEASE CHANGES:

/1.	ADDED KCC FOR NON-CONSOLE TELETYPES

/V3D CHANGES: (VERSION E)

/1.	ADDED DELAY OPTION FOR VT78
/2.	ADDED SCOPE RUBOUTS
/3.	CHANGED VT78 DEFAULTS
/4.	REARRANGED CODE FOR SET TTY ESC AND ARROW
	INDVC=03
	OUTDVC=04

	KSF=10^INDVC+6001
	KCC=10^INDVC+6002
	KRS=10^INDVC+6004
	KRB=KCC KRS
	TSF=10^OUTDVC+6001
	TCF=10^OUTDVC+6002
	TPC=10^OUTDVC+6004
	TLS=TCF TPC

	TTYVERSION="E&77
/BUILD YOUR OWN TELETYPE HANDLER:

/THIS SOURCE HAS MUMBLE LOCATIONS LEFT.

/THE FOLLOWING CONDITIONALS ALLOW YOU TO INCLUDE OPTIONAL FEATURES.
/YOU MAY INCLUDE AS MANY OR AS FEW AS YOU DESIRE PROVIDED THERE
/IS ROOM LEFT.

/CONDITIONAL	LOCATIONS	LOCATIONS	INCLUDED
/VARIABLE	PAGE 1		PAGE 2		FEATURES

/ DELAY		 0		 7		DELAY AFTER GIVEN CHAR
/ CTRL	 	 0 		 3		PRINT CONTROL CHARS AS ^K
/ RUB		 0		 0		PRINT CHAR RUBBED OUT ON RUBOUTS
/ SIMTAB	 0		10		SIMULATE TABS AS SPACES
/ SLOTAB	 0		 6		PUT OUT 2 RUBOUTS AFTER A TAB
/ ESC		 0		10		PRINT ESCAPE AS $
/ FLAGLC	 0		12		FLAG LOWER CASE CHARS ON OUTPUT
/ CNVLC		 0		 7		CONVERT LOWER CASE ON INPUT TO UPPER CASE
/ ALTMOD	 0		11		CONVERT ALTMODES (175,176) TO ESCAPE (33)
/ PAUS		 0		20		PAUSE BETWEEN PAGES
/ FREE LOCS:	 2		33

	VT78=1		/SET TO 0 TO ALLOW OTHER PARAMETERS
			/SET TO 1 TO FORCE OTHER PARAMETERS TO VT78 COMPATIBLE

	DELAY=0		/SET NON-ZERO TO ALLOW DELAY AFTER ANY CHAR (12=CR)
			/TYPICALLY AFTER LF FOR HIGH SPEED VT05
			/SET VALUE OF DELAY = 7-BIT CHAR TO DELAY AFTER

	CTRL=1		/SET TO 1 TO ECHO CONTROL CHARS AS ^K
			/SET TO 0 TO ACCEPT CONTROL CHARACTERS AND PUT
			/IN BUFFER, BUT NOT ECHO THEM (EXCEPT THE USUAL)
	RUB=1		/SET TO 0 TO ECHO EACH RUBOUT BY TYPING A BACK SLASH
			/SET TO 1 TO ECHO CHARS RUBBED OUT UPON RUB-OUT
			/SET TO 4000 TO PERFORM SCOPE TYPE RUBOUTS
	SIMTAB=1	/SET TO 1 TO SIMULATE TABS AS THE CORRECT NUMBER OF SPACES
			/SET TO 0 TO TYPE TABS AS TABS
	SLOTAB=0	/SET TO 1 TO TYPE 2 RUBOUTS AFTER A TAB
			/ONLY IS APPLICABLE IF SIMTAB=0
	ALTMOD=0	/SET TO 1 TO CONVERT 175,176 TO 33
			/(UPPER CASE TERMINALS ONLY)
	ESC=1		/SET TO 1 TO ECHO ESCAPE AS $
			/SET TO 0 TO ECHO ESCAPE AS A CONTROL CHAR (^[)
	FLAGLC=1	/SET TO 1 TO FLAG LOWER CASE CHARS ON OUTPUT
			/THIS IS FOR PEOPLE NOT PRIVELIDGED ENOUGH TO
			/OWN A LOWER CASE TERMINAL
			/SET TO 0 TO PRINT LOWER CASE CHARS AS IS
	CNVLC=0		/SET TO 1 TO CONVERT LOWER CASE CHARS ON INPUT TO UPPER CASE
			/SET TO 0 TO ACCEPT INPUTTED LOWER CASE CHARS AS IS
			/THIS IS FOR PEOPLE WHO ARE HANDICAPPED BY A LOWER CASE
			/TERMINAL AND ONLY WANT UPPER CASE
	PAUS=200	/NON-0 PAUSES BETWEEN SCOPE PAGES
	HEIGHT=30	/NUMBER OF LINES PER SCREEN

/SOME OF THE ABOVE OPTIONS SHOULD ACTUALLY BE IMPLEMENTED
/IN SUCH A MANNER THAT THE USER CAN CHANGE THEM VIA AN ALTER
/RATHER THAN HAVE TO REASSEMBLE.

	IFNZRO VT78 <
	DELAY=0
	CTRL=1
	RUB=4000
	SIMTAB=0
	SLOTAB=0
	ALTMOD=0
	ESC=1
	FLAGLC=0
	CNVLC=0
	IFNZRO INDVC-3 <CTRL=0>
	>
/CROSS PAGE LINKAGE:

/THIS CODE MUST BE ABLE TO LOAD INTO ANY TWO PAGES OF CORE
/THE ENTRY POINT IS AT THE NEXT LOCATION TO THE END OF THE FIRST PAGE
/AT THE END OF THE FIRST PAGE WE JMS TO PLINK,
/THIS LEAVES THE ADDRESS OF THE FIRST LOCATION OF THE NEXT PAGE
/IN LOCATION 'PLINK' .  THIS JUST HAPPENS TO BE THE ADDRESS
/OF BOTH TTYPCH AND TTYGCH.

/TTYPCH AND TTYGCH SHARE THE SAME ENTRY POINT.
/IF IT IS CALLED WITH A 0 AC, IT IS A CALL TO TTYGCH,
/IF IT IS CALLED WITH A NON-ZERO AC, IT IS A CALL TO TTYPCH.

/RETURN 1 MEANS GOT RUBOUT
/TTYGCH TAKES RETURN 2 IF IT GOT A ^Z.
/OTHERWISE IT TAKES RETURN 3 WITH CHARACTER GOTTEN IN AC.

/TTYPCH TAKES RETURN 1 IF IT WANTS THE HANDLER TO GO AWAY,
/I.E IF IT SAW A ^Z.
/AC IS NORMALLY NON-ZERO UPON RETURN
/AC IS POSITIVE MEANS DO A CRLF

/WHEN ECHOING WE WANT TO CALL TTYPRT
/BUT OTHERWISE WE WANT TO CALL TTYPCH (WHICH DOES ADDITIONAL
/STUFF LIKE CHECK ^O, ^Q, ETC.
/WE TELL BY WHETHER OR NOT TTYGCH HAD BEEN PREVIOUSLY CALLED.
	*200

PLINK,	0		/GETS ADDRESS OF TTYPCH AND TTYGCH (START OF NEXT PAGE)
	STL CLA RAR	/4000
	TAD I TTY	/RETRIEVE FUNCTION WORD, BUT PUT R/W BIT IN LINK
	AND L3700	/EXTRACT NUMBER OF DOUBLE-WORDS TO TRANSFER
	CMA		/GET COUNT+1
	DCA BUFSIZ	/STORE AWAY
	RDF		/FIND OUT THE USER'S DATA FIELD
	TAD CIFCDF	/FORM OUR EXIT CIF CDF
	DCA TTYXIT	/STORE AWAY FOR EXIT ROUTINE
	TAD TTY70	/GET FUNCTION WORD
L776,	AND I TTY	/ISOLATE FIELD OF BUFFER
	TAD TTYCDF	/FORM CDF TO FIELD OF BUFFER
	DCA TTCDBF	/STORE WHERE IT WILL BE USEFUL
			/AT SAME TIME, INITIALIZE TTYEOF
	ISZ TTY		/POINT TO BUFFER ADDRESS
	TAD I TTY	/AND GET IT
	DCA BUFSTRT	/AND SAVE IT
	ISZ TTY		/POINT TO BLOCK #
TTY376,	ISZ TTY		/POINT TO ERROR RETURN
SHIFT,			/OUTPUT SHIFT REGISTER
TTYEOF,			/0 IF SAW CR OR ^Z AND WISH TO PAD BUFFER WITH 0'S
TTCDBF,	HLT		/CDF BUFFER FIELD
	JMP TTYKLG
TTYLP,	SNL CLA		/LINK=1 MEANS OUTPUT
	JMP TTYGET	/INPUT IS FROM TTY:
/LINK MUST BE SET FIRST TIME THROUGH HERE.
/IT ACTS AS A GUARD BIT IN THE SHIFT REGISTER
ROTL,	RTL
	RTL
	SPA		/DO WE HAVE 8 BITS SHIFTED IN?
	JMP TELP
	DCA SHIFT	/SAVE SHIFT REGISTER
	TAD I BUFSTRT
	SZA
	JMS PUNCH	/PRINT A CHARACTER
	TAD I BUFSTRT
	ISZ BUFSTRT	/BUMP INPUT POINTER
TT7400,	7400		/PROTECT ISZ
	AND TT7400
	CLL RAL
	TAD SHIFT	/SHIFT HIGH ORDER 4 BITS INTO
	JMP ROTL	/SHIFT REGISTER
TELP,	JMS PUNCH	/PRINT 3RD CHARACTER OF DOUBLE-WORD
	STL		/***KLUDGE
TTYKLG,	ISZ BUFSIZ	/DONE?
	JMP TTYLP	/NOT YET
TTYX,	TAD TTYEOF	/IF INPUT AND WE WERE PADDING WITH 0'S
	SZA CLA		/TAKE SOFT ERROR EXIT
TTYRTN,	ISZ TTY		/POINT TO NORMAL RETURN
			/CAN'T GET ERROR OR END-OF-FILE ON OUTPUT
TTYXIT,	HLT		/RETURN TO USER'S FIELD
	JMP I TTY	/RETURN TO USER
TTYCA,	0
TTYWC,	0
BUFSIZ,	0
BUFSTRT,0
TTY70,	70

PUNCH,	0		/NEVER CALL TTYPCH WITH ZERO AC
	JMS I PLINK	/CALL TTYPCH
	JMP TTYRTN	/GO AWAY, WE SAW A ^Z
L7700,	SMA CLA		/DID WE REACH END OF TTY LINE?
	JMS CRLF	/YES, PERFORM CR/LF
	JMP I PUNCH	/RETURN

TMP,
CRLF,	0
	TAD L215
	JMS I PLINK	/CALL TTYPCH TO PRINT CR
L215,	215		/CAN'T RETURN HERE
	CLA		/****
	TAD L212
	JMS I PLINK	/CALL TTYPCH TO PRINT LF
L212,	212		/CAN'T RETURN HERE
	CLA		/****
	JMP I CRLF	/RETURN
CTRLU,	JMS CRLF	/PERFORM A CR/LF
TTYGET,	TAD BUFSTRT
	DCA TTYCA	/POINT TO START OF BUFFER
	TAD BUFSIZ
	CLL RAL		/CONVERT DOUBLE-WORDS TO WORDS
DCAWC,	DCA TTYWC	/SET SIZE OF BUFFER
TSTEND,	TAD TTYEOF
	SNA CLA
	JMP ZERO
	JMS I PLINK	/CALL TTYGCH TO GET A CHARACTER
	JMP RUBOUT	/RETURN 1 MEANS SAW RUBOUT
ZERO,	DCA I TTYCA	/RETURN 2 MEANS GOT CHARACTER
			/STORE AWAY TEMPORARILY
			/USING USER'S BUFFER AS A TEMP LOCATION
	TAD I TTYCA	/GET BACK CHARACTER
	IFNZRO .-320 <_ERROR>
	SZA
	JMS PUNCH	/ECHO IT
	TAD I TTYCA	/GET IT AGAIN
	TAD M32		/-^Z
	SNA
	JMP CTRLZ
	TAD L5		/^Z-^U
	SNA 		/IS IT ^U?
	JMP CTRLU	/YES
	TAD L7
GRUDGE,	DCA TMP
	ISZ TTYCA	/NO
L7,	7
	ISZ TTYWC	/IS BUFFER FULL?
TT10,	SKP
	JMP TTYX
	ISZ TMP		/WAS LAST CHAR A CR?
	JMP TSTEND	/NO
	DCA TTYEOF	/YES, SET "PAD WITH 0'S" FLAG
	ISZ TTY		/POINT TO NORMAL RETURN
			/CR IS NOT AN ERROR OR END-OF-FILE
	TAD L212	/IF LAST CHAR INPUT WAS CR, NOW PRETEND LF WAS INPUT
	JMP ZERO	/REJOIN PROCESSING

CTRLZ,	DCA TTYEOF
	JMS CRLF
	JMP GRUDGE

M32,	-32
L5,	5
L3700,	3700
CIFCDF,	CIF CDF 0
TTYCDF,	CDF 0

/TTYEOF IS ZERO MEANS PAD BUFFER WITH ZEROES
/DON'T DO YET:
/RUBOUT,	AND TTYWC	/177 IN AC
/	SNA CLA
/	JMP CTRLU

RUBOUT,	KCC		/TTYGCH DOESN'T CLEAR RO FROM BUFFER
	TAD TTYCA
	CIA
	TAD BUFSTRT
	SNA CLA		/ARE WE AT BEGIN OF BUFFER?
	JMP CTRLU	/YES
	STA
	TAD TTYCA
	DCA TTYCA
	IFZERO RUB <
LSLASH,	"\
	TAD LSLASH		/PRINT A BACK SLASH FOR EACH RUBBED OUT CHAR
	>
	IFNZRO RUB&4000+RUB <TAD I TTYCA>	/PRINT CHAR JUST DELETED
	IFNZRO RUB&4000 <TAD TT10>	/BACKSPACE-SPACE-BACKSPACE
	JMS PUNCH
	STA
	TAD TTYWC
	JMP DCAWC	/BUMP BACK WC AND GET ANOTHER CHAR

	ZBLOCK 376-.
TTY,	TTYVERSION	/ENTRY POINT TO HANDLER
	JMS PLINK	/SET UP CROSS PAGE LINKAGE
	IFNZRO TTY-376 <ENTERR,QQQQ>
	PAGE
/INTERLUDE:

/USA STANDARD CODE FOR INFORMATION INTERCHANGE:

/	000	001	010	011	100	101	110	111
/
/ 0000	NUL	DLE	SP	0	@	P	'	'P
/
/ 0001	SOH	DC1	!	1	A	Q	'A	'Q
/
/ 0010	STX	DC2	"	2	B	R	'B	'R
/
/ 0011	ETX	DC3	#	3	C	S	'C	'S
/
/ 0100	EOT	DC4	$	4	D	T	'D	'T
/
/ 0101	ENQ	NAK	%	5	E	U	'E	'U
/
/ 0110	ACK	SYN	&	6	F	V	'F	'V
/
/ 0111	BEL	ETB	'	7	G	W	'G	'W
/
/ 1000	BS	CAN	(	8	H	X	'H	'X
/
/ 1001	HT	EM	)	9	I	Y	'I	'Y
/
/ 1010	LF	SUB	*	:	J	Z	'J	'Z
/
/ 1011	VT	ESC	+	;	K	[	'K	'[
/
/ 1100	FF	FS	,	<	L	\	'L	'\
/
/ 1101	CR	GS	-	=	M	]	'M	']
/
/ 1110	SO	RS	.	>	N	^	'N	'^
/
/ 1111	SI	US	/	?	O	_	'O	'_
/
/TTYGCH:	GETS A CHAR FROM KBD
/	IF GOT ^Z, IT SETS TTYEOF FLAG
/	LEAVES IT IN AC IN 7-BIT

/TTYPRT:	PRINTS CHAR IN AC ON TTY
/	IGNORES NULLS
/	PRINTS ^X ON CONTROL CHARS (EXCEPT CR, LF, FF, VT, TAB)
/	PRINTS 'X ON LOWER CASE

/HANDLES TABS CORRECTLY
/	AND AUTOMATICALLY PRINTS CR/LF AT EOL
/	PRINTS ESCAPE AS $

/TTYTLS:	USED TO ACTUALLY PRINT CHAR
/		IT HANDLES TABS AUTOMATICALLY
/		AND CR/LF'S AT END OF LINE

/TTYPCH:	IT USES TTYPRT TO PRINT CHAR BUT ALSO RESPONDS TO
/		^C, ^O, ^S, ^Q.
/		IF ^Z IS BEING PRINTED, IT THEN STOPS FURTHER PRINTING
/MUST BE AT TOP OF PAGE
TTYPCH,			/ENTRY POINT TO TTY PUNCH ROUTINE
			/OR TTY PRINT ROUTINE
TTYGCH,	0		/ENTRY POINT TO TTY GET CHAR ROUTINE
	SNA
	JMS TGCH	/ZERO AC-MEANT CALL TO TTYGCH
PCH,	AND (177	/FORCE TO 7-BIT
	DCA TCHAR
	TAD TGCH
M140,	SZA CLA		/ARE WE ECHOING?
	JMP ECHO	/YES, IGNORE ^S AND STUFF
K5,	5		/MUST BE AT REL 10
	TAD TCHAR
	TAD (-32
	IFZERO PAUS <
	SNA CLA
	JMP I TTYPCH
	>
	IFNZRO PAUS <
	SNA
	JMP I TTYPCH
	TAD L15		/32-15
	SNA CLA		/LOOK FOR CR
	ISZ LINCNT	/AT END OF PAGE?
	JMP NOPAUS	/NOT AT CR, OR AT CR BUT NOT AT END OF PAGE
L15,	15		/MUST BE HERE FOR SET
	TAD PAUSN
	DCA TTYTLS	/SET COUNT FOR OUTER LOOP
	ISZ LINCNT
	JMP .-1
	ISZ TTYTLS
	JMP .-3
	TAD LINSYZ
	DCA LINCNT
	>
NOPAUS,	JMS TTYTST
	TAD (203-217	/NO
	SNA		/^O?
	DCA TCHAR	/YES, SET TO NULL SO IT WILL BE IGNORED
	TAD (217-223	/NO
	SZA CLA		/^S?
	JMP ECHO	/NO, IGNORE CHAR
TTCTLQ,	JMS TTYTST
	TAD (203-221	/NO, NOTHING ELSE MATTERS UNTIL ^Q
	SZA CLA		/^Q?
	JMP TTCTLQ	/NO, SUSPEND OUTPUTTING
TTY32,	KCC		/YES, REMOVE ^Q FROM BUFFER
/HAD NO ROOM FOR:
/	TAD LINSYZ
/	DCA LINCNT
ECHO,	DCA TGCH
	ISZ TTYPCH
	IFNZRO ESC <
	TAD TCHAR
	TAD (-33
	SZA CLA
	JMP .+3
	TAD L44
	DCA TCHAR
L44,	44
	>
	TAD TCHAR
	SNA
	JMP TTYCTO	/IGNORE NULLS
	IFNZRO RUB&4000 <
	TAD (-10
	SNA
	JMP RUBO
	TAD (10-16
	>
	IFZERO RUB&4000 <
	TAD (-16
	>
TTY100,	CLL
TTY10,	TAD K5
TTY240,	SZA		/TAB?
	JMP NOTAB
	IFNZRO SIMTAB <
TTYTAB,	TAD TTY240
	JMS TTYTLS
TTY7,	7		/HERE FOR NO SPECIAL REASON
	TAD TABCTR
	AND TTY7
	SZA CLA
	JMP TTYTAB
	JMP TTYCTO
	>
	IFNZRO SLOTAB <
	TAD TCHAR
	JMS TTYTLS
	TAD (177
	JMS TTYTLS
	TAD (177
	JMP PRIN+1
	>
	IFZERO SIMTAB+SLOTAB <JMP PRIN>

/BUG: IF HARDWARE TABS, DON'T COUNT COLUMNS CORRECTLY

	IFNZRO RUB&4000 <
RUBO,	TAD TTY10	/OUTPUT BACKSPACE-RUBOUT-BACKSPACE
	JMS TTYTLS
	TAD TTY240
	JMS TTYTLS
	TAD (-4
	TAD TABCTR
	JMP PREPRN
	>
NOTAB,	SZL CLA
	JMP SPCHR	/DON'T UPARROW CHARS LF,CR,TAB,VT,FF
	IFNZRO FLAGLC <
	TAD TCHAR
	AND TTY140
	TAD M140
	SZA CLA		/IS IT LC?
	JMP NOLC	/NO
TTYQUO,	"'
	TAD TTYQUO	/YES
	JMS TTYTLS	/PRINT QUOTE
	TAD M40
	JMP PRIN	/PRINT UPPER CASE OF CHAR
	>
NOLC,	TAD TCHAR	/NO, GET BACK CHAR
	AND TTY140	/HIGH ORDER BITS IRRELEVANT
	IFNZRO CTRL <
M40,	SMA SZA CLA	/CAN'T BE NEGATIVE
	JMP PRIN	/NOT A CONTROL CHARACTER
	TAD TTYUPA	/ECHO 201-237 AS ^X (EXCEPT 211-215)
	JMS TTYTLS
	TAD TTY100	/ADD X100 TO ^K TO GET K
	>
	IFZERO CTRL <
	SNA CLA		/IS CHAR A CONTROL CHAR?
	JMP TTYCTO	/YES, DON'T ECHO CONTROL CHARACTERS EXCEPT FOR 211-215
	>
PRIN,	TAD TCHAR
	JMS TTYTLS
TTYCTO,	TAD TABCTR	/RETURN TABCNT IN AC
	JMP I TTYPCH

	IFZERO CTRL <
M40,	-40
	>

TTY140,
SPCHR,	STA CLL
	TAD LINSIZ
PREPRN,	DCA TABCTR	/THESE CHARS RESET COLUMN COUNTER
	JMP PRIN
TGCH,	0		/NON-ZERO MEANS TTYGCH WAS CALLED
	KSF
	JMP .-1		/WAIT FOR CHAR TO BE TYPED
	JMS TTYTST
/WILD: (DON'T PUT IN)	SZA CLA /FALL THRU AND RETURN R.O.
/	ISZ TTYGCH
	TAD (203-377
	SNA CLA		/TAKE RETURN 1 ON RUB OUT
	JMP I TTYGCH	/"CLUMSY" - R.L. (9/18/73)
	ISZ TTYGCH
	KRB		/GET CHARACTER
TTYAND,	AND (177	/MUST RETURN CHAR IN 7-BIT
	IFNZRO CNVLC <
	DCA TCHAR
	TAD TCHAR
	AND TTY140
	TAD M140
	SNA CLA		/IS IT LC?
	TAD M40		/YES
	TAD TCHAR	/NO
	>
	IFNZRO ALTMOD <
	TAD (-175	/IS IT 175 OR 176?
	SMA
	JMP CONV	/YES, CONVERT ALTMODE TO ESCAPE
	TAD (175	/NO, RESTORE CHAR
	>
	JMP I TTYGCH	/TAKE RETURN 3

/SHOULDN'T TABCTR BE INITIALIZED TO C(LINSIZ) UPON ENTRY?

TABCTR,	-110

TTYTLS,	0
	TLS
	IFNZRO DELAY <
	TAD (-DELAY
	SZA CLA
	STA
	>
TTYTSF,	TSF
	JMP .-1
	IFNZRO DELAY <
	IAC
	SZA		/19.66 MS IS G.T. 1/60 SEC
	JMP TTYTSF
	>
	ISZ TABCTR
TTYUPA,	"^
TT7600,	7600
	JMP I TTYTLS
LINSIZ,	-110

	IFNZRO PAUS <
LINSYZ,	-HEIGHT
LINCNT,	-HEIGHT
PAUSN,	-PAUS
	>

	IFNZRO ALTMOD <
		IFNZRO KCC-6032 <
CONV,		CLA
		TAD (33
		JMP I TTYGCH
		>
	IFZERO KCC-6032 <
CONV,		CLA IAC
		TAD TTY32	/DEVICE DEPENDENT
		JMP TTYAND
		>
	>
TCHAR,	0

/TTYTST:	READS KEYBOARD STATICALLY AND RESPONDS TO ^C
/		OTHERWISE RETURNS CHAR (8-BIT) MINUS 203 IN AC.
/		IF FLAG IS NOT UP, IT RETURNS A 1.

TTYTST,	0
	TAD TT7600	/OR CHAR IN
	KRS
	TAD (-7603	/-7603=175
	KSF
	CLA IAC		/STUFF IN BUFFER IS UNRELIABLE IF FLAG ISN'T UP
	SZA
	JMP I TTYTST
	IFNZRO INDVC-3 <KCC>
	CIF CDF 0	/BRANCH TO OS/8 MONITOR AT 07600
	JMP I TT7600	/IT WILL PRINT "^C" FOR CHAR IN BUFFER
	PAGE
/	DYNAMICALLY MODIFYING THE KL8E HANDLER

/	*** I M P O R T A N T ***

/	THIS HANDLER CAN BE DYNAMICALLY CHANGED VIA SET COMMANDS.
/	CONSEQUENTLY, IT IS EXTREMELY IMPORTANT THAT PEOPLE
/	WHO MODIFY THIS SOURCE DO NOT AFFECT THE ALGORITHMS
/	NECESSARY TO PERFORM SUCH MODIFICATIONS.

/	THIS ALGORITHM IS EXPLAINED BELOW.

/	SET TTY WIDTH=N

/	SEARCH LOCATIONS 200-377 FOR A 7600.  CALL ITS ADDRESS X.
/	LET Y BE THE INSTRUCTION AT LOCATION X+1.
/	FORM THE (RELATIVE) ADDRESS T=Y&177+200-1.
/	THEN LOCATIONS T AND X+2 CONTAIN MINUS THE TTY WIDTH.
/	THE WIDTH MUST BE A MULTIPLE OF 10 AND MUST NOT BE 200.
/	(BECAUSE -200 IS THE MAGIC 7600)

/	SET TTY CODE XX

/	SEARCH ENTIRE HANDLER FOR INSTRUCTIONS OF THE FORM 6XXY
/	WHERE XX IS NOT 20 OR 21,
/	AND FURTHERMORE DON'T INCLUDE A 6031 IF 2 LOCATIONS
/	FOLLOWING IS A 7650
/	AND DON'T INCLUDE A 6034 IF 4 LOCATIONS FOLLOWING IS A 7650.


/	SET TTY [NO] ECHO

/	THE WORD INVOLVED IS AT (RELATIVE) LOCATION 120.
/	SET TO 7440 TO ECHO.
/	SET TO 7610 TO SUPPRESS ECHOING.


/	SET TTY LC

/	SEARCH LOCATIONS 200-377 FOR A 377.  CALL ITS ADDRESS X.
/	LOOK AT LOCATION X+5.
/	IF THIS LOCATION IS NOT A 7650, THEN LC TO UC CONVERSION
/	WAS NOT ENABLED AT ASSEMBLY TIME.
/	IF THE FEATURE IS ENABLED, CHANGE LOCATION X+5 TO A 7610
/	TO PREVENT THE CONVERSION.  TO ALLOW CONVERSION, SET
/	LOCATION X+5 BACK TO 7650.

/	SET TTY PAGE

/	SEARCH LOCATIONS 215-300 FOR A 7450. CALL ITS ADDRESS X.
/	SET X+3 TO 7640 TO ENABLE ^S, ^Q.
/	SET X+3 TO 7200 TO DISABLE ^S, ^Q.
/	SET TTY TAB

/	SEARCH LOCATIONS 200-300 FOR A 7.
/	IF NOT FOUND, SIMULATED TABS WAS NOT ENABLED AT ASSEMBLY TIME.
/	IF FOUND, CALL ITS ADDRESS X.
/	TO PATCH OUT SIMULATED TABS:
/		MOVE C(X-12) TO LOCATION X-2
/		CHANGE LOCATION X+3 TO A 7610
/	TO RESTORE SIMULATED TABS:
/		SET LOCATION X-2 TO X-4&77+1200
/		CHANGE LOCATION X+3 TO A 7640

/	SET TTY FILL

/	THE LITERAL 177 MUST REMAIN AT THE END OF PAGE 2
/	SEARCH LOCATIONS 200-300 FOR A 1377.
/	IF NOT FOUND, THEN FILL CHARACTERS WERE NOT ENABLED AT ASSEMBLY
/	TIME.  IF FOUND, CALL ITS ADDRESS X.
/	TO PATCH OUT FILL CHARACTERS, MOVE C(X+3) TO LOCATION X-1.
/	TO RESTORE FILL CHARACTERS, MOVE C(X+1) TO LOCATION X-1.

/	SET TTY FLAGLC

/	SEARCH LOCATIONS 200-377 FOR A 247.
/	IF NOT FOUND, LOWER CASE FLAGGING WAS NOT ENABLED AT ASSEMBLY TIME.
/	IF FOUND, CALL ITS ADDRESS X.
/	TO DISABLE FLAGGING, SET LOCATION X-2 TO A 7200.
/	TO RE-ENABLE FLAGGING, SET LOCATION X-2 TO A 7640.

/	SET TTY PAUSE [N]

/	SEARCH LOCATIONS 200-300 FOR A 15.
/	IF NOT FOUND, PAUSING WAS NOT ENABLED AT ASSEMBLY TIME.
/	IF FOUND, CALL ITS ADDRESS X.
/	TO DISABLE PAUSING AFTER A FULL SCREEN,
/	SET LOCATION X-3 TO A 7610.
/	TO RE-ENABLE PAUSING, SET LOCATION X-3 TO A 7650.
/	TO SET PAUSE DURATION, SEARCH LOCATIONS 300-377 FOR A 7600,
/	CALLING ITS ADDRESS X.  THEN (MINUS THE) PAUSE DURATION IS AT
/	LOCATION X+5.

/	SET TTY HEIGHT

/	THIS IS ONLY APPLICABLE IF SET TTY PAUSE HAS BEEN ASSEMBLED IN
/	(A 15 CAN BE FOUND ON SECOND PAGE).
/	NEGATIVE OF HEIGHT MUST BE SET IN BOTH LOCATIONS X+3 AND X+4
/	WHERE X IS THE ADDRESS OF A 7600 AS IN ABOVE.
/	SET TTY ESCAPE

/	SEARCH LOCATIONS 200-377 FOR A 44.
/	IF NOT FOUND, THEN $ WAS NOT ASSEMBLED INTO TTY HANDLER.
/	IF FOUND, CALL ITS ADDRESS X.
/	TO DISABLE PRINTING ESCAPE AS $, SET LOCATION X-4 TO A 'CLA'.
/	TO CAUSE ESCAPE TO PRINT AS AN ESCAPE, SET LOCATION X-4 TO SZA CLA.

/	SET TTY ARROW

/	SEARCH LOCATIONS 200-377 FOR 7740.

/	IF NOT FOUND, USING OLD HANDLER.
/	CALL ITS ADDRESS X.
/	IF LOCATION X+1 IS MORE THAN 7000,
/	THEN UPARROW MODE WAS NOT ASSEMBLED INTO KL8E.
/	OTHERWISE, TO ALLOW ARROWS, SET LOCATION X+3 TO THE
/	CONTENTS OF LOCATION X+6.
/	TO CAUSE CONTROL CHARACTERS TO ECHO AS IS, SET
/	LOCATION X+3 TO 'SKP CLA'.
/	NOTE THAT THIS IS A DIFFERENT OPTION THAN ASSEMBLING CTRL=0.
	IFDEF TEST <
	*600

/TEST ROUTINE FOR KL8E HANDLER

GO,	JMS I (TTY	/CALL HANDLER
	0600		/READ SIX PAGES
	1000		/BUFFER AT 01000
	0001		/BLOCK 1
	HLT		/ERROR RETURN
	JMS I (TTY	/CALL HANDLER AGAIN
	4600		/OUTPUT SIX PAGES
	1000
	0001
	HLT
	CLA
	JMP GO
	>
	$

