	.TITLE *** DEFINE TERMINAL CHARACTERISTICS MCR FUNCTION ***
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ 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 RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED 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 PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
/
/ EDIT #5	M. HEBENSTREIT		OCT. 23 1974
/
/ COPYWRITE 1974 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/
/ THIS MCR FUNCTION IS USED TO DEFINE THE TERMINAL CHARACTERISTICS OF
/ TELETYPES IN AN RSX SYSTEM. THE COMMAND FORMAT IS AS FOLLOWS:
/
/	MCR>DTC TT# NAME (BAUD)$
/
/ WHERE TT# IS THE TELETYPE IDENTIFIER (# IS A 1 OR 2 CHARACTER OCTAL
/ NUMBER), NAME IS THE NAME OF THE DEVICE (KSR33,KSR35,LA30,GT40, VT05,
/ VT50, OR LA36)
/ BAUD IS THE BAUD RATE IN DECIMAL (ONLY GIVEN FOR LA30, VT50, OR VT05)
/ THE BAUD RATE CAN TAKE ON THE FOLLOWING VALUES:
/	LA30: 300 OR SOME NUMBER LESS THAN 300
/	VTO5: 2400, 1200, 600, OR SOME NUMBER LESS THAN 600
/	VT50: 2400, 1200, 600, OR SOME NUMBER LESS THAN 600
/	LA36: NO BAUD RATE SPECIFICATION IS NEEDED FOR THIS DEVICE
/ $ INDICATES THE LINE TERMINATOR.
/
/
FAC=174
MCRRI=171
.ENB=705521
.INH=705522
IDX=ISZ
/
START	JMS	CHART		/IS THIS CHAR. A T?
	124
	JMS	CHART		/YES -- IS THIS CHAR. A T?
	124
	JMS*	(FAC		/GET NEXT CHAR.
	JMS	UNUM		/GET A NUMBER (OCTAL)
	DAC	UNIT		/AND SAVE AS A PARTITAL UNIT NO.
	JMS*	(FAC		/GET NEXT CHAR.
	SAD	(40		/IS IT A SPACE?
	JMP	LOC1		/YES -- THEN WE HAVE THE UNIT NO.
	JMS	UNUM		/NO -- GET THE NUMBER
	DAC	TEMP
	LAC	UNIT		/CONSTRUCT A 2 CHAR UNIT NO.
	CLL
	ALS	3
	TAD	TEMP
	DAC	UNIT		/SAVE THE UNIT NO.
	JMS*	(FAC		/GET NEXT CHAR.
	SAD	(40		/IS IT A SPACE?
	SKP			/YES
	JMP	ERR1		/NO -- ERROR
LOC1	LAC*	(203		/GET THE ADDR. OF TTWD06
	DAC	TTWD6		/SAVE THE BASE OF TABLE (TTWD06)
	LAC*	(176		/GET THE NO. OF TTY'S IN SYSTEM
	TCA
	DAC	TEMP		/AND SAVE 2'S COMP. FOR UNIT TEST
	TAD	TTWD6		/GET BASE ADDR OF TTWD05 TABLE
	DAC	TTWD5		/SAVE BASE ADDR OF TABLE
	LAC*	(202		/GET THE BASE ADDR OF TTWD00 TABLE
	DAC	TTWD0		/AND SAVE IT.
	LAC	UNIT		/IS THE UNIT NO. VALID?
	TAD	TEMP
	SMA!SZA
	JMP	ERR2		/NO -- ERROR
	LAC	TTWD0		/YES -- GET ADDR OF TABLE ENTRIES
	TAD	UNIT
	DAC	TTWD0
	LAC	TTWD5
	TAD	UNIT
	DAC	TTWD5
	LAC	TTWD6
	TAD	UNIT
	DAC	TTWD6
/
	JMS*	(FAC		/GET THE NEXT CHAR. AND PREPARE TO
				/DISPATCH TO PROPER ROUTINE.
	SAD	(40		/WAS CHAR A SPACE?
	JMP	.-2		/YES -- READ NEXT CHAR.
	SAD	(107		/NO -- A G?
	JMP	G		/YES -- GT40?
	SAD	(113		/NO -- A K?
	JMP	K		/YES -- KSR33 OR KSR35?
	SAD	(114		/NO -- AN L?
	JMP	L		/YES -- LA30?
	SAD	(126		/NO -- A V?
	SKP			/YES -- VT05?
	JMP	ERR1		/NO -- ERROR
/
V	JMS	CHART		/IS NEXT CHAR A T?
	124
	JMS*	(FAC		/YES -- GET THE NEXT CHARACTER
	SAD	(60		/IS IT A ZERO?
	JMP	VT0		/YES -- PROBABLY A VT05
	SAD	(65		/NO -- IS IT A FIVE?
	SKP
	JMP	ERR1		/NO -- ERROR
	JMS	CHART		/YES -- IS NEXT CHAR. A ZERO?
	60
	JMP	VT05		/YES -- TREAT VT05'S AND VT50'S THE SAME
/
VT0	JMS	CHART		/IS NEXT CHAR A 5?
	65
VT05	JMS	NUMBER		/YES -- GET THE BAUD RATE
	JMP	ERR1		/RETURN HERE ON ERRORS
	DAC	TERM		/RETURN HERE IF OK -- SAVE BREAK
	LACQ			/GET BAUD RATE INTO AC
	DAC	BAUD		/AND SAVE IT.
	SAD	D600		/TEST FOR LEGAL BAUD RATE
	JMP	VTBOK
	SAD	D1200
	JMP	VTBOK
	SAD	D2400
	JMP	VTBOK
	TAD	DM601
	SMA
	JMP	ERR4		/ILLEGAL BAUD RATE -- ERROR
VTBOK	JMS	IDLE		/TEST TO SEE IF TTY IS IDLE
	LAC*	TTWD5		/SET TTWD05
	AND	(777177
	XOR	(000600
	DAC*	TTWD5
	LAC	BAUD		/SET UP BAUD RATE IN TTWD06
	SAD	D600
	JMP	VT600
	SAD	D1200
	JMP	VT1200
	SAD	D2400
	JMP	VT2400
	CLA
	SKP
VT600	LAC	(010000
	SKP
VT1200	LAC	(020000
	SKP
VT2400	LAC	(030000
	DAC	TEMP
	LAC*	TTWD6
	AND	(747777
	XOR	TEMP
	DAC*	TTWD6
	DBK			/DROP TO API LEVEL 7
	JMP	EXIT
/
G	JMS	CHART		/IS NEXT CHAR A T?
	124
	JMS	CHART		/YES -- IS NEXT CHAR A 4?
	64
	JMS	CHART		/YES -- IS NEXT CHAR A 0?
	60
	DZM	GTFLG		/YES -- SET FLAG TO SHOW A GT40
	JMP	KSR35		/GO TO KSR35 ROUTINE
/
L	JMS	CHART		/IS NEXT CHAR AN A?
	101
	JMS	CHART		/YES -- IS NEXT CHAR A 3?
	63
	JMS*	(FAC		/YES -- GETD THE NEXT CHARACTER
	SAD	(60		/IS IT A ZERO?
	JMP	LA30		/YES -- DEVICE IS AN LA30
	SAD	(66		/NO -- IS IT A SIX?
	JMP	KSR33		/YES -- TREAT LA36'S AS KSR33'S
	JMP	ERR1		/NO -- ERROR
LA30	JMS	NUMBER		/YES -- GET THE BAUD RATE
	JMP	ERR1		/RETURN HERE ON AN ERROR
	DAC	TERM		/RETURN HERE IF OK -- SAVE BREAK CHAR
	LACQ			/GET BAUD RATE INTO AC
	DAC	BAUD		/AND SAVE IT
	SAD	D300		/TEST FOR LEGAL BAUD RATE
	JMP	LABOK
	TAD	DM301
	SMA
	JMP	ERR4		/ILLEGAL BAUD RATE -- ERROR
LABOK	JMS	IDLE		/CHECK THAT TTY IS IDLE
	LAC*	TTWD5		/SET TTWD05 FOR AN LA30
	AND	(777177
	XOR	(000400
	DAC*	TTWD5
	LAC	BAUD		/SET UP BAUD RATE IN TTWD06
	SAD	D300
	JMP	LA300
	CLA
	SKP
LA300	LAC	(010000
	DAC	TEMP
	LAC*	TTWD6
	AND	(747777
	XOR	TEMP
	DAC*	TTWD6
	DBK			/DROP TO API LEVEL 7
	JMP	EXIT
/
K	JMS	CHART		/IS NEXT CHAR AN S?
	123
	JMS	CHART		/YES -- IS NEXT CHAR AN R?
	122
	JMS	CHART		/YES -- IS NEXT CHAR A 3?
	63
	JMS*	(FAC		/YES -- WHAT IS THE NEXT CHAR?
	SAD	(63		/A 3?
	JMP	KSR33		/YES -- TTY IS A KSR33!
	SAD	(65		/NO -- A 5?
	SKP			/YES -- TTY IS A KSR35!
	JMP	ERR1		/NO -- ERROR
KSR35	CLA
	SKP
KSR33	LAC	(000200
	DAC	TEMP
	JMS*	(FAC		/PICK UP THE FINAL (?) CHAR
	DAC	TERM		/SAVE TERMINATOR (?)
	JMS	IDLE		/CHECK THAT TTY IS IDLE
	LAC*	TTWD5		/SET TTYWD05 FOR PROPER DEVICE
	AND	(777177
	XOR	TEMP
	DAC*	TTWD5
	LAC*	TTWD6
	AND	(747777
	DAC*	TTWD6
	LAC	GTFLG		/IS THIS DEVICE A GT40?
	SZA
	JMP	EXITK		/NO -- EXIT AS USUAL
	LAC*	TTWD0		/YES -- SET BIT IN TTWD00 TO INDICATE
	AND	(767777		/THAT ALTMODES SHOULD BE PRINTED.
	XOR	(010000
	DAC*	TTWD0
EXITK	DBK			/DROP TO API LEVEL 7
/
EXIT	LAC	TERM		/FIND THE REAL LINE TERM.
	SAD	(15
	JMP	EXITCR
	SAD	(175
	JMP	EXITAM
	JMS*	(FAC
	JMP	EXIT+1
EXITCR	CAL	REQMCR
	CAL	(10
EXITAM	DZM*	(MCRRI
	CAL	(10
/
/ SUBROUTINES
/
/ SUBROUTINE CHART -- TEST NEXT CHARACTER
/
/ CALLING SEQ.:		JMS	CHART
/			#
/
/ WHERE # IS THE ASCII YOU WANT TO TEST FOR.
/ RETURN AT JMS+2 IF CHAR IS #, JMP ERR1 IF NOT
/
CHART	0
	JMS*	(FAC
	SAD*	CHART
	SKP
	JMP	ERR1
	IDX	CHART
	JMP*	CHART
/
/ SUBROUTINE UNUM -- GET PART OF AN OCTAL UNIT NO.
/
/ CALLING SEQ.:		LAC 	CHAR	/AC HAS CHARACTER
/			JMS	UNUM
/
/ RETURN AT JMS+1 IF CHAR IS A OCTAL NO. WITH OCTAL IN AC
/ JMP TO ERR1 IF CHAR IS NOT AN OCTAL DIGIT.
/
UNUM	0
	DAC	TEMP
	AAC	-60
	SPA
	JMP	ERR1
	LAC	TEMP
	AAC	-70
	SMA
	JMP	ERR1
	LAC	TEMP
	AND	(7
	JMP*	UNUM
/
/ SUBROUTINE IDLE -- TEST THAT THE TTY IS IDLE
/
/ CALLING SEQ.:		JMS	IDLE
/
/ IF THE TTY IS IDLE RETURN AT JMS+1
/ IF NOT JMP ERR3
/
IDLE	0
	LAC	(400020		/RAISE TO LEVEL 3 TO PREVENT INTERRUPTION
	ISA
	LAC*	TTWD0
	AND	(777
	SZA
	JMP	ERR3
	LAC*	TTWD0		/SET UP TTWD00 NOT TO PRINT ALTMODES
	AND	(767777
	DAC*	TTWD0
	JMP*	IDLE
/
/ SUBROUTINE NUMBER -- READ A DECIMAL NUMBER OF UP TO 4 DIGITS
/			OFF THE MCR TTY.
/ 
/ ALTERED REGISTERS: AC AND MQ
/ 
/ CALLING SEQUENCE:
/		JMS	NUMBER
/		JMP	???	/RETURN HERE IF 1ST CHARACTER
/				/AFTER A BUNCH OF SPACES IS NOT
/				/A DECIMAL DIGIT WITH THE CHARACTER
/				/IN THE AC.
/		???	???	/RETURN HERE IF 1ST CHARACTER
/				/AFTER A BUNCH OF SPACES IS A DECIMAL
/				/DIGIT WITH THE BREAK CHARACTER IN THE
/				/AC AND THE NUMBER IN THE MQ.
/ 
NUMBER	0
	LAW	-4		/SET DIGIT COUNTER
	DAC	COUNT
	DZM	NUM		/ZERO PREVIOUS RESULTS
	CLC			/SET A FLAG TO INDICATE THAT SPACES
	DAC	NUMFLG		/ARE NOT BREAK CHARACTERS YET.
NUM1	JMS*	(FAC		/GET A CHARACTER
	SAD	(40		/WAS THE CHARACTER A SPACE?
	JMP	NUMSPC		/YES
	DZM	NUMFLG		/NO -- CLEAR FLAG TO INDICATE THAT ANY
				/SPACES ENCOUNTERED SHOULD BE USED AS
				/BREAK CHARACTERS.
	DAC	NUMT		/SAVE IT TEMPORARILY
	AAC	-60		/IS IT A DIGIT?
	SPA
	JMP	NUM2		/NO -- EITHER A BREAK OR AN ERROR
	DAC	CHAR		/SAVE THE POTENTIAL DIGIT
	AAC	-12
	SMA
	JMP	NUM2		/NO -- EITHER A BREAK OR AN ERROR
	LAC	NUM		/YES -- PICK UP THE REAL NUMBER
				/THAT HAS ALREADY BEEN CONSTRUCTED
	CLL
	MUL			/MULTIPLY IT BY 10 DECIMAL
	12
	LACQ			/GET RESULT INTO AC
	TAD	CHAR		/ADD THE DIGIT JUST READ
	DAC	NUM		/SAVE THE RESULTING DECIMAL NUMBER
	ISZ	COUNT		/HAVE 4 DIGITS BEEN READ?
	JMP	NUM1		/NO -- READ SOME MORE
	JMS*	(FAC		/YES -- READ A BREAK CHARACTER
NUM3	DAC	CHAR		/SAVE THE CHARACTER TEMPORARILY
	IDX	NUMBER		/PREPARE TO RETURN AT JMS+2
	LAC	NUM		/PICK UP THE DECIMAL NUMBER
	LMQ			/STORE IT IN THE MQ
	LAC	CHAR		/GET THE BREAK CHAR INTO THE AC
	JMP*	NUMBER		/RETURN AT JMS+2
NUM2	LAW	-4		/CHARACTER IS EITHER A BREAK OR ERROR
	SAD	COUNT		/IF THIS WAS THE 1ST CHARACTER READ
				/ITS AN ERROR. OTHERWIZE ITS A BREAK.
	JMP	NUMERR		/ERROR
	LAC	NUMT		/BREAK -- GET THE CHARACTER INTO AC
	JMP	NUM3
NUMERR	LAC	NUMT		/ERROR SO GET CHARACTER INTO AC
	JMP*	NUMBER		/AND RETURN AT JMS+1
NUMSPC	LAC	NUMFLG		/CHAR. WAS A SPACE -- IS IT A BREAK CHAR.?
	SZA
	JMP	NUM1		/NO -- THE SPACE SHOULD BE IGNORED
	LAC	(40		/YES -- TREAT THE SPACE AS A BREAK CHAR.
	DAC	NUMT
	JMP	NUM2
/
/ MISC ROUTINES AND OTHER STUFF
/
REQMCR	1
	0
	.SIXBT "..."
	.SIXBT "MCR"
	0
/
WRITE	2700
	EV
	3
	2
	XX
/
WAIT	20
	EV
/
UNIT	0
TEMP	0
TTWD0	0
TTWD5	0
TTWD6	0
BAUD	0
TERM	0
COUNT	0
NUM	0
NUMFLG	0
NUMT	0
CHAR	0
GTFLG	-1
	.DEC
D600	600
D1200	1200
D2400	2400
DM601	-601
D300	300
DM301	-301
	.OCT
/
ERR3	DBK			/DROP TO API LEVEL 7
	LAC	(MSG3
	SKP
ERR1	LAC	(MSG1
	SKP
ERR2	LAC	(MSG2
	SKP
ERR4	LAC	(MSG4
	DAC	WRITE+4
	CAL	WRITE
	CAL	WAIT
	JMP	EXITCR
/
MSG1	MSG2-MSG1/2*1000
	0
	.ASCII "DTC -- FORMAT ERROR "<15>
MSG2	MSG3-MSG2/2*1000
	0
	.ASCII "DTC -- ILLEGAL UNIT NUMBER"<15>
MSG3	MSG4-MSG3/2*1000
	0
	.ASCII "DTC -- TERMINAL BUSY"<15>
MSG4	EV-MSG4/2*1000
	0
	.ASCII "DTC -- ILLEGAL BAUD RATE"<15>
EV	0
	.END
