	.TITLE	ADD-A-DEVICE MCR FUNCTION
/
/ COPYRIGHT (C) 1975
/ DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/ THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/ THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/ SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/ VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/ EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/ THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/ SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/ WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/ MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/ DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/ OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY
/ DEC.
/
	.EJECT
/
/
/ 	EDIT #3		AUG 11 75	M. HEBENSTREIT
/
/
/	THIS PROGRAM IS AN MCR FUNCTION TO ADD A DEVICE TO THE
/	PHYSICAL DEVICE LIST.	THE FORMAT OF THE INPUT STRING IS
/	MCR>ADV NMT    OR      NM#T	OR NM##T
/	WHERE NM INDICATES A TWO CHARACTER NAME AND # IS A DIGIT
/	T IS EITHER AN ALTMODE OR A CARRIAGE RETURN.
/
/
/
/
PDVL=252
.ENB=705521
.INH=705522
PENP=115
MCRRI=171
FAC=174
LUTP1=142
LUTP2=143
X10=10
X11=11
X12=12
START	LAC	(START		/GET XR ADJ
	AND	(70000
	DAC	XRPOS
	TCA
	DAC	XRADJ
	JMS	GETDEV	/GET DEVICE NAME AND UNIT NO.
	JMP	ERR01        /RETURN HERE IS A FORMAT ERROR IS FOUND
	SAD	(40	/NO ERRORS -- WHAT IS THE NEXT CHAR.?
	JMP	SPACE        /SPACE
	SAD	(15
	JMP	H1   /CARRIAGE RETURN
	SAD	(175
	JMP	H1   /ALTMODE
	JMP	ERR01 /ANY OTHER CHARACTERS ARE ERRORS
SPACE	JMS*	(FAC   /LOOK FOR THE TERMINATOR
	SAD	(40
	JMP	.-2
	SAD	(15
	JMP	H1
	SAD	(175
	JMP	H1
	JMP	ERR01        /OTHER CHARACTERS ARE ERRORS
H1	DAC	TERM       /SAVE THE TERMINATOR
	LAC	GN2	/SAVE THE UNIT NUMBER
	DAC	UNIT
	LAC	GN1	/SAVE THE NAME
	DAC	NAME1
	CLC		/SET THE FLAG FOR S.R. DEQUE
	DAC	FLAG
	JMS	DEQUE        /TRY TO FIND DEVICE IN PDVL LIST
	SKP	/RETURN HERE IF NOT FOUND -- THAT'S OK
	JMP	ERR02        /IF DEVICE IS IN LIST THAT'S AN ERROR
	LAC	UNIT	/SEE IF UNIT NUMBER IS ZERO
	SNA
	JMP	.+11	/YES -- IT'S ZERO
	CLC		/NO -- NOT ZERO SO SEE IF PREVIOUS UNIT IN PDVL
	TAD	UNIT /SUBTRACT 1 FROM THE UNIT NO.
	DAC	UNIT /LOOK UP THE MODIFIED DEVICE IN PDVL
	DZM	FLAG	/CLEAR THE FLAG
	JMS	DEQUE
	JMP	ERR03	/CANT'T FIND NODE -- ERROR - DEVICES MUST BE IN ORDER
	ISZ	UNIT	/RESTORE PROPER UNIT NUMBER
	JMP	ADD1	/NODEAD HAS THE ADDRESS OF NODE TO INSERT NEW NODE AFTER
	LAC	NAME1        /TEST FOR BD DEVICE
	AND	(777700
	SAD	(020400
	SKP
	JMP	.+5	/DEVICE IS NOT BD
	PXA	/DEVICE IS BD SO SET NODEAD SO NEW NODE
	TAD	XRPOS      /IS INSERTED AT END OF DEQUE
	DAC	NODEAD
	JMP	ADD1
	LAC	(PDVL        /UNIT #=0 SO SET NODEAD SO NEW NODE
	JMS	SETXR        /WILL BE INSERTED AFTER FIRST NODE
	LAC	0,X
	DAC	NODEAD
ADD1	LAC*        (X10	/WHERE ANY UNITS WITH SAME NAME IN PDVL?
	SAD	(TABLE-1
	JMP	ADD	/NO
	LAC*	(LUTP1      /YES -- CHECK TO SEE THAT NONE ARE ASSIGNED
	AAC	-1		/INITIALIZE X12
	DAC*	(X12
ADD2	LAC	(TABLE-1	/INITIALIZE X11
	DAC*	(X11
	LAC*	(X12        /END OF LUT TABLE?
	SAD*	(LUTP2
	JMP	ADD	/YES -- THE NEW NODE CAN BE ADDED
	LAC*	X12	/NO -- CHECK TO SEE IF LUT TABLE ENTRIES ARE
	LMQ		/THE SAME AS THE ADDRESSES OF THE START OF ANY
ADD3	SAD*        X11     /PDVL NODE FOR THIS DEVICE.
	JMP	ERR06        /A MATCH -- THAT'S AN ERROR
	LAC*	(X11        /ARE WE AT THE END OF THE TABLE OF PDVL NODES?
	SAD*	(X10
	JMP	ADD2	/YES -- RE INIT. X11
	LACQ		/NO -- COMPARE NEXT TABLE ENTRY
	JMP	ADD3
ADD	JMS* (PENP   /GET A NODE FROM THE POOL
	JMP	ERR04        /POOL IS EMPTY -- ERROR
	DAC	NNODE        /SAVE THE ADDRESS OF THE NEW NODE
	LAC	NODEAD	/GET THE FORWARD POINTER OF PREVIOUS NODE
	JMS	SETXR
	LAC	0,X	/SAVE THE FP
	DAC	FP
	LAC	NNODE        /STORE THE FP IN 0 WORD OF NEW NODE
	JMS	SETXR
	LAC	FP
	DAC	0,X
	LAC	NODEAD	/STORE BP FOR THE NEW NODE (WORD 1)
	DAC	1,X
	LAC	NAME1        /STORE NAME IN WORD 2
	DAC	2,X
	DZM	3,X	/CLEAR WORDS 3 AND 4
	DZM	4,X
	LAC	UNIT	/STORE UNIT NO. IN WORD 5
	DAC	5,X
	PXA		/SET WORDS 6 AND 7 TO ADDR. OF WORD 6
	TAD	XRPOS
	AAC	6
	DAC	6,X
	DAC	7,X
	DZM	10,X	/CLEAR WORDS 10 AND 11
	DZM	11,X
	.INH	/INHIBIT INTERUPTS WHILE NEW NODE GETS INSERTED
	LAC	NODEAD	/CORRECT FP IN PREVIOUS NODE
	JMS	SETXR
	LAC	NNODE
	DAC	0,X
	LAC	FP   /CORRECT BACK POINTER IN NEXT NODE
	JMS	SETXR
	LAC	NNODE
	DAC	1,X
	.ENB	/ALLOW INTERUPTS -- NODE HAS BEEN INSERTED IN PDVL
EXIT	LAC TERM    /EXIT ACCORDING TO THE LINE TERMINATOR
	SAD	(15
	CAL	REQMCR
	SAD	(175
	DZM*	(MCRRI
	CAL	(10
REQMCR	1
	0
	.SIXBT "..."
	.SIXBT "MCR"
	0
/
/       S.R. TO LOOK UP A NODE IN PDVL
/       ONE ENTRY THE 1ST HALF OF THE NAME MUST BE IN NAME1 AND
/       THE UNIT NUMBER MUST BE IN UNIT.        ON RETURN, NODEAD HAS THE
/       ADDRESS OF THE INDICATED NODE (ASSUMING NO ERROR WERE DETECTED)
/       AND THE RETURN IS TO JMS+2. IF, HOWEVER, ERRORS WERE DETECTED
/       RETURN IS AT JMS+1.
/
DEQUE	0
	LAW	-1	/CHECK THE FLAG TO SEE IF DEQUE SHOULD CONSTRUCT A
	SAD	FLAG	/TABLE OF PDVL NODE ADDRESSES
	SKP
	JMP	.+3	/DON'T CONSTRUCT THE TABLE
	LAC	(TABLE-1     /CONSTRUCT THE TABLE	INIT. X10
	DAC*	(X10
	LAC	(PDVL	/SET XR TO ACCESS HEADER OF PDVL
	JMS	SETXR
	LAC	0,X	/GET ADDR. OF 1ST NODE
D1	JMS	SETXR      /COMPARE THE NAME AND UNIT NUMBER, JMP TO D2 IF NO MATCH
	LAC	2,X
	SAD	NAME1	/1ST HALF OF NAME MATCHES?
	SKP
	JMP	D2	/NO
        LAC     3,X		/YES -- 2ND HALF OF NAME?
	SZA
	JMP	D2	/NO
	LAW	-1	/YES
	SAD	FLAG	/IS DEQUE CONSTUCTING A TABLE?
	SKP
	JMP	.+4	/NO
	PXA	/YES	--       PUT NODE ADDRESS INTO TABLE
	TAD	XRPOS
	DAC*	X10
	LAC	5,X	/DOES THE UNIT NO. MATCH
	SAD	UNIT
	SKP
	JMP	D2	/NO
	PXA		/YES -- SAVE THE NODE ADDR
	TAD	XRPOS
	DAC	NODEAD
	ISZ	DEQUE	/RETURN AT JMS+2 -- NODE FOUND
	JMP*	DEQUE
D2	LAC	0,X        /NO MATCH SO TEST FOR END OF DEQUE
	SAD	(PDVL
	JMP*	DEQUE
	JMP	D1	/NOT THE END OF THE DEQUE -- CHECK NEXT NODE
/
/       S.R. TO ADJUST THE XR
/
SETXR   0
	TAD	XRADJ
	PAX
	JMP*	SETXR
XRADJ	0
XRPOS	0
TERM	0
UNIT	0
NODEAD	0
EV	0
GN1	0
GN2	0
GNNFLG	0
GNTEMP	0
NNODE	0
FP	0
NAME1	0
FLAG	0
TABLE	.BLOCK 10	/TABLE OF PDVL NODE ADDRESSES
/
/       S.R. TO GET A DEVICE NAME AND UNIT NUMBER
/       ON RETURN GN1 HAS 1ST HALF OF NAME AND GN2 HAS UNIT NUMBER
/       IF ANY ERRORS ARE DETECTED RETURN AT JMS+1
/       IF NO ERRORS ARE DETECTED RETURN AT JMS+2 WITH AC=NEXT CHAR.
/
GETDEV	0
	DZM	GN1	/INIT. NAME AND UNIT NO.
	DZM	GN2
	CLC		/INIT. FLAG -- SPACES NOW LEGAL
	DAC	GNNFLG
	JMS	GDSR /GET 1ST LETTER
	ALS	14
	DZM	GNNFLG	/CLEAR FLAG -- SPACES NOW ILLEGAL
	DAC	GN1	/SAVE CHAR.
	JMS	GDSR /GET 2ND CHAR
	ALS	6
	TAD	GN1
	DAC	GN1	/SAVE NAME OF DEVICE
	JMS	NEXT /GET NEXT CHAR
	JMS	NUMCK	/MAKE SURE IT'S A NO.
	DAC	GN2	/SAVE UNIT NO.
	JMS	NEXT /GET NEXT CHAR
	JMS	NUMCK	/MAKE SURE IT'S A NO.
	DAC	GNTEMP	/CONVERT 2 DIGIT DECI NO. INTO OCATL
	CLL
	LAC	GN2
	MUL
	12
	LACQ
	TAD	GNTEMP
	DAC	GN2	/SAVE UNIT NO.
	JMS*	(FAC	/GET NEXT CHAR INTO AS
	JMP	GDOK /PREPARE TO RETURN
/
/       S.R. TO GET NEXT NUMERICAL CHAR.
/
NEXT	0
	JMS*	(FAC
	SAD	(40	/SPACE?
	JMP	GDOK /YES
	SAD	(175 /NO -- ALTMODE?
	JMP	GDOK /YES
	SAD	(15	/NO -- CR?
	JMP	GDOK /YES
	DAC	GNTEMP	/NO -- SAVE CHAR
	JMP*	NEXT
/
/       S.R. TO CHECK TO SEE NUMBER IS REALLY A NUMBER
/       ON ENTRY AC HAS ASCII OF DIGIT
/       ON EXIT AC HAS OCTAL VALUE OF DIGIT
/       ERRORS FORCE A JMP TO GDERR
/
NUMCK	0
	TAD	(-60
	SPA
	JMP	GDERR	/ERROR IF ASCII<60
	LAC	GNTEMP
	TCA
	TAD	(71
	SPA
	JMP	GDERR	/ERROR IF ASCII>71
	LAC	GNTEMP
	AND	(17	/OK -- AC CONTAINS OCTAL NO.
	JMP*	NUMCK
/
/       S.R. TO CHECK THAT CHARACTER IS A LETTER
/       ON EXIT AC HAS SIXBT OF CHAR
/       ERRORS RESULT IN A JMP TO GDERR
/
GDSR	0
	JMS*	(FAC	/READ NEXT CHAR.
	DAC	GNTEMP
	SAD	(40	/SPACE?
	JMP	GDSPAC	/YES
	SAD	(15	/NO -- CR?
	JMP*	GETDEV	/YES -- RETURN AT JMS+1
	SAD	(175 /NO -- ALTMODE?
	JMP*	GETDEV	/YES -- RETURN
	LAC	(-101	/NO
	TAD	GNTEMP
	SPA
	JMP	GDERR	/ERROR IF ASCII<101
	LAC	GNTEMP
	TCA
	TAD	(132
	SPA
	JMP	GDERR	/ERROR IF ASCII>132
	LAC	GNTEMP
	AND	(77
	CLL
	JMP*	GDSR
GDSPAC	LAC	GNNFLG /IS THE SPACE LEGAL?
	SZA
	JMP	GDSR+1	/YES
GDERR	LAC	GNTEMP	/ERROR
	JMP*	GETDEV
GDOK	ISZ	GETDEV	/OK -- RETURN AT JMS+2
	JMP*	GETDEV
WRITE	2700
	EV
	2
	2
	0
WAIT	20
	EV
ERR01	LAC	(MSG1
	DAC	WRITE+4
	CAL	WRITE
	CAL	WAIT
	CLA
	JMP	EXIT+2
ERR03	LAC	(MSG3
	JMP	ERR01+1
ERR02	LAC        (MSG2
	JMP	ERR01+1
ERR04	LAC	(MSG4
	JMP	ERR01+1
ERR06	LAC        (MSG6
	JMP	ERR01+1
MSG1	MSG2-MSG1/2*1000
	0
	.ASCII "FORMAT ERROR"<15>
MSG2	MSG3-MSG2/2*1000
	0
	.ASCII "DEVICE EXISTS ALREADY"<15>
MSG3	MSG4-MSG3/2*1000
	0
	.ASCII "UNIT NUMBER IS OUT OF ORDER"<15>
MSG4	MSG6-MSG4/2*1000
	0
	.ASCII "POOL IS EMPTY"<15>
MSG6	MSG7-MSG6/2*1000
	0
	.ASCII "UNITS OF THIS DEVICE ARE ASSIGNED"<15>
MSG7	0
	.END
