	.TITLE +++ XVM/RSX EXECUTIVE VERSION 1A (PART 2) +++
/
/ 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
/
/
	.LST
	.IFUND	L.LUN
	.NOLST
	.ENDC
/
P2EDTN=200161	/PART TWO [OF SOURCE FILE] EDIT NUMBER
/
/ DATE OF LAST EDIT: DEC 30, 1975
/ 
	.IFPNZ	10020-.
	.LOC	10020	/MAKE CERTAIN THAT WE ARE HIGH ENOUGH HERE
	.ENDC
/
/ ATL NODE FOR THE SYSTEM CONFIGURATION ROUTINE.  THIS ROUTINE 
/ IS ASSEMBLED INTO THE SYSTEM AS AN ACTIVE TASK WHICH WILL RUN ONCE,
/ REMOVE ITSELF FROM THE SYSTEM , AND EXIT.  THIS NODE IS RETURNED
/ TO THE POOL UPON EXIT.
/
SFG	ATKL		/FORWARD LINKAGE
	IORD		/BACKWARD LINKAGE
	.SIXBT	"SFG"	/TASK NAME (FIRST HALF)
	.SIXBT	"@@@"	/TASK NAME (SECOND HALF)
	1000		/TASK PRIORITY
	SFGIC-P.IC	/PARTITION BLOCK ADDRESS
	SCF		/STL NODE ADDRESS
	4		/TASK STATUS (READY TO RESUME)
	SCONF		/RESUMPTION ADDRESS
	0		/EVENT VARIABLE ADDRESS
	.IFPNZ	NDSZMT
	.REPT	NDSZMT
	0
	.ENDC
	.TITLE *** DISK - UFD TABLE ***
/
/ THIS TABLE RELATES THE DEFAULT UFD NAME FOR ALL DISKS TO
/ THE DISK UNIT. THE TABLE IS SETUP FOR THE SYSTEM DISK BY
/ SCF. THE MNT MCR FUNCTION SETS THE TABLE FOR USER DISKS
/ WHILE THE DSM MCR FUNCTION CLEARS THE TABLE FOR THE
/ SPECIFIED DISK. THE FIRST EIGHT ENTRIES ARE FOR RP0-RP7.
/ THE NEXT EIGHT ENTRIES ARE FOR RK0-RK7. THE LAST ENTRY
/ IS FOR THE RF. NOTE THAT THE NAME OF THE UFD IS STORED IN
/ THIS TABLE AND NOT THE UFD STARTING BLOCK.
/
/
UFDDSK=.
	.REPT	21
	0
/
	.LST
	.IFUND	L.MAC
	.NOLST
	.ENDC
	.TITLE *** TIME SLICING SUBROUTINE
/ 
/ ***   NOTES ON TIME SLICING   ***
/  
/ TIME SLICING IS IMPLEMENTED BY SETTING ONE TASK IN THE ATL
/ HAVING THE CORRECT PRIORITY TO STATUS 5 WHILE ALL OTHER TASKS
/ IN THE PRIORITY RANGE IN STATUS 5 HAVE THEIR STATUS SET TO 7.
/ STATUS 5 MEANS THE TASK IS READY TO BE RUN OR CONTINUES .
/ STATUS 7 MEANS THAT EXECUTION OF THE TASK SHOULD BE HELD UP.
/ NOTE THAT A TASK HAVING A STATUS OTHER THAN 5 OR 7 IS NOT
/ AFFECTED BY TIME SLICING.
/ WHEN THE INDICATED NUMBER OF TICKS HAVE ELAPSED, THE TASK IN
/ STATUS 5 HAS ITS STATUS CHANGED TO 7 AND SOME OTHER TASK IN
/ STATUS 7 HAS ITS STATUS CHANGED TO 5.
/ THIS PROCEDURE DOES NOT GUARENTEE THAT A TASK WILL ACTUALLY
/ RUN DURING ITS ALLOTED TIME, SINCE OTHER TASKS IN THE SYSTEM
/ CAN STEAL TIME FROM THE TIME-SLICED TASK. FURTHERMORE, MORE
/ THAN ONE TASK IN THE PRIORITY RANGE MAY BE IN STATUS 5
/ SINCE STATUS'S OTHER THAT 5 AND 7 ARE NOT CHANGED BY THE TIME
/ SLICING SUBROUTINE. NOTE THAT AN ACTIVE TASK THAT HAS
/ STARTED EXECUTION MAY HAVE ITS STATUS CHANGED FROM 5
/ TO FOR EXAMPLE STATUS 4 IN WHICH CASE TIME SLICING WILL
/ NOT SET A STATUS FROM 4 TO 7.
/ NOTE THAT EVERY FEW TIMES TIME SLICING SUBROUTINE IS ENTERED,
/ NO TASK IS SET TO STATUS 5. THIS IS TO ALLOW TASKS WHICH ARE
/ IN THE TIME SLICING RANGE BUT HAVE A PRIORITY LOW ENOUGH TO
/ HAVE DIFFICULTY GETTING INTO STATUS 5 TO GET TO STATUS 5.
/ THIS 'TIME OUT' ALSO ALLOWS BATCH AND TASKS WITH VERY LOW
/ PRIORITY TO RUN A LITTLE.
/ THE NUMBER OF TIMES THE TIME SLICING SUBROUTINE IS ENTERED BEFORE 
/ ALLOWING A 'QUANTUM' TO FALL IS DETERMINED BY THE LAST PARAMETER
/ GIVEN TO THE SLICE MCR FUNCTION. IN ADDITION, ONE TICK IS ALLOWED TO
/ FALL EVERY OTHER QUANTUM PROVIDED THAT THE PREVIOUS QUANTUM
/ DIDN'T FALL. 
/ ESSENTIALLY, THIS SUBROUTINE TREATS PROCESSING TIME LIKE WATER IN A
/ LEAKY BUCKET WHICH HAS WATER SPLASH OUT PERIODICALLY. THE LEAKS ARE
/ FALLING TICKS AND THE SPLASHES ARE FALLING QUANTA.
/ 
/ 
SLICE	0
	LAC*	(SLITIM		/IS TIME SLICING ON?
	SNA
	JMP*	SLICE		/NO -- RETURN
	ISZ	SLICNT		/YES -- HAS THE TIME COUNTER RUN OUT?
	JMP*	SLICE		/NO -- RETURN
	DZM	SLIT1		/YES -- CLEAR THE FLAG
	LAC	SLIT3		/IF SLIT3 IS SET THEN SLIT2 IS NOT ZEROED
	DAC	SLIT2		/THIS IS TO ALLOW A LOW ATL ENTRY TASK
				/TO RUN AFTER A QUANTUM OR TICK FELL
	LAC*	(SLITIM		/RESET THE TIME COUNTER
	DAC	SLICNT
	LAC	(ATKL		/PREPARE TO ACCESS THE ATL
	JMS	SLI.ST
SLI.N	LAC	A.FP,X		/IS THIS THE END OF THE ATL?
	SAD	(ATKL
	JMP	SLI.E		/YES -- PREPARE TO SET 1 TASK TO STATUS 5
	JMS	SLI.SR		/NO -- CHECK STATUS AND PRIO. OF NEXT TASK
	JMP	SLI.N		/RETURN HERE IF PRIORITY IS BAD
	JMP	SLI.N		/RETURN HERE IF STATUS NOT 5 OR 7
	LAC	SLIT1		/RETURN HERE IF STATUS AND PRIO ARE OK
				/IS SLIT1 SET?
	SZA
	JMP	.+3		/YES -- DON'T SET SLIT1 AGAIN
	PXA			/NO -- SET SLIT1 WITH THE XR
	DAC	SLIT1		/NEEDED TO ACCESS THIS NODE
				/SLIT1 WHEN SET GUARENTEES THAT
				/THERE IS AT LEAST 1 TASK IN THE ATL
				/HAVING A PRIO. IN THE CORRECT RANGE
				/AND IN EITHER STATUS 5 OR 7.
				/SLIT1 INDICATES THE 1ST TASK IN THE
				/ATL WHICH MEETS THESE CONDITIONS.
	LAC	A.TS,X		/IS THE TASK AT STATUS 5?
	AND	(7
	SAD	(5
	SKP
	JMP	SLI.N		/NO -- PROCESS NEXT NODE
	LAC	(7		/YES -- SET THE STATUS TO 7
	DAC	A.TS,X
	LAC	A.FP,X		/ SET SLIT2 WITH THE POINTER TO THE
	DAC	SLIT2		/NEXT NODE IN THE ATL
				/SLIT2 WHEN SET INDICATES THAT THERE
				/WAS AT LEAST 1 TASK IN THE PRIO RANGE
				/WHICH HAD A STATUS OF 5.  THEREFORE
				/THE NEXT TASK CAPABLE OF BEING TIME-
				/SLICED SHOULD BE ALLOWED TO RUN NEXT.
				/IF NO TASK AFTER THIS NODE IS OK, THEN
				/LET THE TASK INDICATED BY SLIT1 RUN NEXT.
	JMP	SLI.N		/PROCESS NEXT ATL NODE
/ 
/ END OF ATL SCAN -- LET SOME TASK RUN
/ 
SLI.E	ISZ	SLITCK		/SHOULD A TICK FALL?
	JMP	SLI.K		/NO -- NOT YET
	LAW	-2
	DAC	SLITCK		/RESET THE FALLING TICK COUNTER
				/TICKS FALL AFTER EVERY 2 QUANTA BUT
				/ONLY IF THE LAST QUANTUM DIDN'T FALL
	LAC	SLIOUT		/MAYBE A TICK SHOULD FALL BUT 1ST CHECK
	SAD	SLITMO		/IF LAST QUANTUM FELL
	JMP	SLI.K		/DON'T LET THE TICK FALL A QUANTUM JUST FELL
	LAW	-1		/LET THE TICK FALL -- SET COUNTER TO -1
	DAC	SLICNT		/SO ONLY A TICK WILL FALL
	LAC	SLIT2		/SET SLIT3 SO TASKS DOWN ATL CAN RUN
	DAC	SLIT3
	JMP	SLI.J		/LEAVE WITHOUT SETTING ANY TASK TO 5
SLI.K	ISZ	SLIOUT		/SHOULD A QUANTUM FALL?
	JMP	SLI.I		/NO -- PROCEED NORMALLY
	LAC	SLIT2		/SET SLIT3 FOR SAME REASON AS ABOVE
	DAC	SLIT3
	LAC	SLITMO		/YES -- RESET THE TIME OUT COUNTER AND
	DAC	SLIOUT		/EXIT WITHOUT SETTING ANY TASK TO
	JMP	SLI.J		/STATUS 5.
SLI.I	LAC	SLIT2		/EXAMINE SLIT2
	SAD	(ATKL		/DOES IT POINT TO THE ATL LISTHEAD?
	JMP	SLI.A		/YES -- THEN USE SLIT1 AS THE INDICATOR
				/FOR DETERMINING WHICH TASK SHOULD HAVE
				/ITS STATUS SET TO 5.
	SZA			/NO -- IS SLIT2 SET?
	JMS	SLI.SR		/YES -- EXAMINE ATL NODE POINTED TO
				/BY SLIT2.
	JMP	SLI.A		/NO OR RETURN HERE IF THE NEXT ATL
				/IS NOT IN THE PRIORITY RANGE.
	JMP	SLI.B		/RETURN HERE IF NEXT TASK NOT AT STATUS 7
	JMP	SLI.C		/RETURN HERE IF THE NEXT NODE IS
				/OK AND SET ITS STATUS TO 5.
/ 
SLI.A	LAC	SLIT1		/IS SLIT1 SET?
	SNA
	JMP*	SLICE		/NO -- RETURN
	PAX			/YES -- SET THE STATUS OF THE TASK
				/INDICATED BY SLIT1 TO 5.
SLI.C	LAC	(5
	DAC	A.TS,X
	DZM	SLIT3
SLI.J	.SET6			/CAUSE A SIGNIFICANT EVENT
	JMP*	SLICE		/RETURN
/ 
SLI.B	LAC	A.FP,X		/PREPARE TO ACCESS NEXT NODE SINCE
	DAC	SLIT2		/TASK INDICATED BY SLIT2 WAS NOT
	DAC	SLIT3
	JMP	SLI.I+1		/IN STATUS 7. MAYBE NEXT NODE IS OK
/ 
	.EJECT
/ 
/ 
/ SUBROUTINE SLI.SR -- SEE IF TASK IS IN PRIO RANGE AND AT STATUS 5 OR 7
/ 
/	IF NOT IN RANGE RETURN AT JMS+1
/	IF NOT IN STATUS 5 OR 7 RETURN AT JMS+2
/	IF IN PRIO RANGE AND IN EITHER STATUS 5 OR 7 RETURN AT JMS+3
/ 
/	ON ENTRY THE AC POINTS TO THE NODE
/ 
/	THE FOLLOWING REGISTERS ARE ALTERED: AC, XR, LINK
/ 
/ 
SLI.SR	0
	JMS	SLI.ST		/SET XR TO ACCESS NODE
	LAC	A.TP,X		/IS TASK PRIO IN RANGE?
	TAD*	(SLILR
	SPA
	JMP*	SLI.SR		/NO -- RETURN AT JMS+1 (TOO LOW A PRIO. NO.)
	LAC	A.TP,X
	TCA
	TAD*	(SLIHR
	SPA
	JMP*	SLI.SR		/NO -- RETURN AT JMS+1 (TOO HIGH A PRIO. NO.)
	LAC	A.TS,X		/YES -- IS STATUS 5 OR 7?
	AND	(5
	SAD	(5
	IDX	SLI.SR		/YES -- RETURN AT JMS+3
	IDX	SLI.SR		/NO -- RETURN AT JMS+2
	JMP*	SLI.SR
/ 
/ SUBROUTINE SLI.ST -- ADJUST THE XR TO ACCESS ATL FROM PAGE 1
/ 
SLI.ST	0
	TAD	(-010000
	PAX
	JMP*	SLI.ST
/ 
/ TIME SLICING VARIABLES
/ 
SLIT1	0	/FLAG GIVING XR NEEDED TO ACCESS 1ST NODE IN RANGE
		/AND WITH STATUS 5 OR 7
SLIT2	0	/FLAG GIVING POINTER TO NEXT NODE THAT SHOULD PROBABLY
		/BE SET TO STATUS 5.
/ 
/ THE NEXT 3 LOCATIONS ARE ORDER DEPENDENT. THEREFORE, DON'T PUT
/ ANY VARIABLES OR INSTRUCTIONS IN BETWEEN!
/
SLICNT	0	/TWOS COMPLEMENT COUNTER FOR THE NUMBER OF TICKS
		/A TASK SHOULD BE ALLOWED TO BE IN STATUS 5.
SLIOUT	0	/THIS IS A COUNTER FOR THE NUMBER OF TIMES THE TIME
		/SLICING S.R. HAS BEEN ENTERED WITHOUT ALLOWING LOW
		/PRIORITY TASKS TO RUN. WHEN THE COUNTER RUNS OUT
		/NO TASK IS SET BACK TO STATUS 5.
SLITMO	0	/COUNTER USED TO INITIALIZE SLIOUT ONCE TIME SLICEING
		/HAS BEEN STARTED.
SLITCK	-2	/COUNTER FOR FALLING TICKS
SLIT3	0	/SAME VALUE RANGE AS SLIT2 BUT THIS VARIABLE IS USED TO
		/RESTORE SLIT2 AFTER A QUANTUM OR TICK HAS FALLEN. THE
		/INTENTION HERE IS TO ALLOW THE N-TH TASK IN THE
		/PRIORITY RANGE TO RUN WHEN N ENTRIES TO THE TIME SLICING
		/S.R. WAS GIVEN. IF SLIT3 WERE NOT SET INTO SLIT2 THEN
		/THE N-TH AND N+1-TH ETC TASKS WOULD NEVER RUN.
/ 
	.LST
	.IFUND	L.TTY
	.NOLST
	.ENDC
 .TITLE *** TTY MULTI-TERMINAL TASK
/
/ ******************************
/
/ INTERNAL CONVENTIONS
/
/ ******************************
/
/ TERMINOLOGY:
/
/ INITIALLY, THIS TASK IS MEANT TO CONTROL I/O ONLY TO
/ TELETYPES. IT MAY BE DESIRABLE IN THE FUTURE TO
/ ALLOW FOR TELETYPE-LIKE TERMINALS, E.G., SERIAL ASCII
/ CARD READER OR VT05 DISPLAY. THEREFORE, THE FOLLOW-
/ ING TERMINOLOGY HAS BEEN USED HEREIN:
/
/	TTY			AN I/O TERMINAL CONNECTED TO
/				THE LT15 OR LT19 CONTROLS, OR
/				THE CONSOLE TERMINAL. ALSO,
/				"TTY" IS THE NAME OF THIS TASK.
/
/	"KEYBOARD"		THE INPUT HARDWARE OF A TTY
/
/	"PRINTER"		THE OUTPUT HARDWARE OF A TTY
/
/	MCR TTY			THE "KEYBOARD" OR INPUT SIDE
/				OF THE TTY FROM WHICH THE
/				MONITOR CONSOLE ROUTINE (MCR)
/				MAY BE INVOKED (BY "TYPING"
/				CTRL C).
/
/	CTRL			THE "CONTROL" KEY ON A TELETYPE.
/
/	.LE.			"IS LESS THAN OR EQUAL TO"
/
/ LABELLING CONVENTION:
/
/	ALL ADDRESS TAGS DEFINED IN THIS TASK BEGIN WITH "TT".
/
IDX=ISZ				/USED HEREIN TO ADD 1 TO A REGISTER
				/WHEN THERE IS NO INTENTION TO SKIP.
/
/ THIS TASK IS ALWAYS CORE RESIDENT, AND RESIDES IN A "PARTITION" THAT
/ IS NOT AVAILABLE FOR OTHER TASKS.  IT CONTAINS A "PARTITION BLOCK"
/ THAT IS ONLY USED AS A REGISTER SAVE AREA (WHEN THE TASK IS INTERRUPTED
/ BY THE EXECUTIVE).  IT IS NOT A PART OF THE "PARTITION BLOCK DESCRIPTIONS
/ LIST" NOR IS THE "FLAGS" WORD EVER CHECKED OR ALTERED.
/
/ IT CONTAINS AN ACTIVE TASK LIST NODE WITH STATUS INITIALLY SET
/ TO FOUR, WHICH MEANS THAT THE TASK IS READY TO BE STARTED OR RESUMED.
/
/ THE TASK WILL PERFORM A 'WAITFOR' ON THE DEVICE'S TRIGGER EVENT
/ VARIABLE SO THAT THE TASK IS RUN ONLY WHEN APPROPRIATE I/O
/ REQUESTS ARE QUEUED AND READY TO BE PROCESSED OR WHEN INTERRUPTS HAVE
/ OCCURRED AND ARE READY TO BE PROCESSED.
/
/ TTY IS NEVER REQUESTED, NOR DOES IT EVER EXIT.  THEREFORE THERE IS
/ NO SYSTEM TASK LIST ENTRY FOR IT.
/
/ RECOGNIZED I/O FUNCTIONS:
/
/	24	ATTACH
/	25	DETACH
/	26	INPUT (READ)
/	27	OUTPUT (WRITE)
/	36	HINF
/
/ LEGAL DATA MODES:
/
/	2	IOPS ASCII
/	3	IMAGE ASCII
/
	.EJECT
/ EVENT VARIABLES RETURNED:
/
/	+Y0XX01	VALUE SET BY THE HINF FUNCTION TO INDICATE DEVICE
/		CODE (1), UNIT NUMBER (XX), NON-DIRECTORY-ORIENTED INPUT
/		AND/OR OUTPUT (Y).
/
/	+2	(1) IOPS ASCII OUTPUT ABORTED BY "TYPE-IN" OF
/		    CTRL U.
/
/		(2) IOPS ASCII INPUT LINE ENDS WITH CARRIAGE
/		    RETURN RATHER THAN ALTMODE.
/
/	+1	OPERATION SUCCESSFULLY COMPLETED OTHER THAN
/		AS INDICATED ABOVE.
/
/	-6	UNIMPLEMENTED FUNCTION OR FUNCTION IS ILLEGAL
/		FOR THIS TTY.
/
/	-7	ILLEGAL DATA MODE.
/
/	-16	ILLEGAL WORD-PAIR-COUNT OR BUFFER SIZE.
/
/		(1) IOPS ASCII INPUT -- BUFFER SIZE IS NEGATIVE
/		    OR LESS THAN +4.
/
/		(2) IMAGE ASCII INPUT -- BUFFER SIZE IS NEGATIVE
/		    OR LESS THAN +3.
/
/		(3) IMAGE ASCII OUTPUT -- WORD PAIR COUNT IN
/		    LINE BUFFER HEADER IS LESS THAN +2.
/
/	-24	I/O REQUEST REJECTED BECAUSE THE LUN VIA
/		WHICH THE REQUEST WAS MADE HAS BEEN
/		REASSIGNED AWAY FROM THIS PHYSICAL DEVICE.
/
/	-30	I/O TRANSFER PARAMETER (ADDRESS OR BUFFER)
/		EXCEEDS THE TASK'S PARTITION BOUNDS.
/
/	-203	ATTACH/DETACH NOT ISSUED AT TASK LEVEL.
/
	.EJECT
/ CAL PARAMETER BLOCK FOR "WAITFOR" DIRECTIVE.
/
TTWT4	20			/"WAITFOR" TTY TRIGGER EVENT
	TTTGEV			/VARIABLE.
/
/ THIS TASK IS INITIALLY ENTERED HERE AT TASK LEVEL (API-7).
/
TTYTW	CAL	TTWT4		/'WAITFOR' TTY TRIGGER EVENT VARIABLE
/
/ NOTE -- THE TRIGGER IS NOT CLEARED UNTIL IT IS CHECKED FURTHER ON
/ FOR AN "ABORT" REQUEST.
/
/ NOTE -- CONTROL DOES NOT RETURN TO THIS LOCATION UNTIL
/ TTTGEV IS SET (NON-0), INDICATING A QUEUED TTY I/O REQUEST
/ OR INDICATING THAT THE TTY INTERRUPT SERVICE ROUTINE
/ RECEIVED AN INTERRUPT.  PROCESSING WILL BE DONE IN ORDER
/ OF IMPORTANCE:
/
/	1.  "KEYBOARDS" AND "PRINTERS"
/	2.  "ABORT" I/O REQUEST
/	3.  NORMAL I/O REQUESTS
/
/ NOTE -- EVERYTIME A "KEYBOARD", "PRINTER" OR I/O REQUEST HAS
/ BEEN SERVICED, BELOW, CONTROL RETURNS TO THIS POINT TO
/ SCAN FOR MORE INTERRUPTS OR REQUESTS.  
/ WHEN A COMPLETE SCAN IS MADE AND NOTHING
/ SERVICEABLE IS FOUND, CONTROL GOES TO "TTYTW",
/ ABOVE, TO "WAITFOR" THE TASK'S "TRIGGER".
/
/ CHECK FOR SERVICEABLE "KEYBOARD" OR "PRINTER"
/ INTERRUPTS AT API LEVEL 3 TO PREVENT GETTING IN-
/ TERRUPTED IN THE MIDDLE OF A TEST.
/
TTSCAN	.RTL3			/RAISE TO API-3.
	LAC*	(TTYNUM)	/# OF TTY'S ON THIS MACHINE.
	PAL
	CLX
TTKPLP	PXA			/SAVE THE TTY UNIT NUMBER.
	DAC	TTUNIT
	LAC	TTK.EV,X	/TEST FOR SPECIAL "KEYBOARD"
	AND	(177)		/CHARACTERS.
	SAD	(003)
	JMP	TTC.C		/CTRL C.
	SAD	(024)
	JMP	TTC.T		/CTRL T.
	SAD	(025)
	JMP	TTC.U		/CTRL U.
	SAD	(030)
	JMP	TTC.X		/CTRL X.
/
/ THOSE ARE THE ONLY INPUT CHARACTERS WHICH CAN BE PRO-
/ CESSED WHILE THE TTY'S "PRINTER" IS TIED UP.
/
TTTSTP	LAC	TTWD06,X	/IS A "PRINTER" INTERRUPT EXPECTED?
	SMA!RTL			/(MOVE BIT 1 INTO LINK).
	JMP	TTTRYK		/NO. TRY "KEYBOARD" INPUT.
	SNL!CLL			/YES. DID ONE OCCUR?
	JMP	TTKPNX		/NO. HOWEVER, SINCE ONE IS
				/EXPECTED, "KEYBOARD" INPUT
				/TO THIS UNIT MUST WAIT.
	RTR			/YES. CLEAR THE FLAG
	DAC	TTWD06,X	/THAT SAYS IT DID (BIT-1).
	DBK			/DEBREAK FROM API-3 TO API-7
	JMP	TTPSVC		/AND SERVICE THIS "PRINTER".
/
TTTRYK	LAC	TTK.EV,X	/CHECK FOR "KEYBOARD" INPUT
	SNA			/FROM THIS TTY.
	JMP	TTKPNX		/NO.
	DBK			/YES. DEBREAK FROM API-3 TO API-7
	JMP	TTKSVC		/AND SERVICE THIS "KEYBOARD".
/
TTKPNX	AXS	1		/TRY NEXT TTY
	JMP	TTKPLP
/
	DBK			/DEBREAK FROM API-3 TO API-7.
/
/ CHECK THE TRIGGER EVENT VARIABLE TO SEE IF AN "ABORT" REQUEST IS IN
/ THE TTY0 QUEUE.
/
	.INH			/INHIBIT INTERRUPTS.
	LAC	TTTGEV		///
	.ENB			///ENABLE INTERRUPTS.
	DZM	TTTGEV		///
	RTL			/BIT 2 ON INDICATES "ABORT" QUEUED.
	SMA
	JMP	TTRQSC		/NO.
/
/ DE-QUEUE THE "ABORT" REQUEST.
/
	LAW	-D.QF		/COMPUTE THE ADDRESS OF TTY0'S
	TAD	TTWD07		/PHYSICAL DEVICE NODE.
	DAC*	(R1)
	JMS*	(DQRQ)		/DE-QUEUE THE "ABORT" REQUEST.
				/(R1, R2, R4, R5, R6, XR & AC ARE ALTERED).
				/WAS A REQUEST FOUND?
	JMP	TTRQSC		/NO -- SHOULD NEVER COME HERE.
	DAC	TTABNA		/YES -- SAVE ITS ADDRESS.
	TAD	TTXADJ
	PAX
/
/ SAVE PARAMETERS FROM THE "ABORT" REQUEST.
/
	LAC	2,X		/SAVE THE STL NODE ADDRESS OF THE
	DAC	TTABSN		/TASK BEING ABORTED.
	LAC	6,X		/SAVE THE I/O RUNDOWN TASK'S EVENT
	DAC	TTRDEV		/VARIABLE ADDRESS.
/
/ DECREMENT THE "TRANSFERS PENDING" COUNT.
/
	LAC	TTABNA		/ADDRESS OF THE ABORT REQUEST NODE.
	DAC*	(R2)
	JMS*	(IOCD)		/(R5, XR & AC ARE ALTERED).
/
/ ABORT ALL I/O INITIATED OR PENDING FOR THE INDICATED TASK ON EACH TTY.
/
	DZM	TTUNIT		/START WITH TTY 0.
TTABLP	JMS	TTUINX		/SET THE XR WITH THE TTY UNIT NUMBER.
/
/ FIRST, DETACH FROM THIS TTY UNIT, IF NECESSARY, AND REMOVE ALL I/O
/ REQUESTS BY THIS TASK FROM THIS TTY'S QUEUE.
/
	LAW	-D.QF		/COMPUTE THE ADDRESS OF THIS TTY'S
	TAD	TTWD07,X	/PHYSICAL DEVICE NODE.
	DAC*	(R1)
	LAC	TTABNA		/ADDRESS OF THE ABORT REQUEST NODE.
	DAC*	(R2)
	JMS*	(DMTQ)		/DETACH LUN & DEVICE, IF NECESSARY,
				/AND THEN EMPTY THIS TTY'S REQUEST
				/QUEUE OF ALL I/O REQUESTS MADE BY THE
				/TASK BEING ABORTED.
				/(R1, R2, R3, R5, R6, X10, X11, X12,
				/XR & AC ARE ALTERED).
/
/ IS I/O IN PROGRESS FOR THIS TTY OR IS IT IDLE?
/
	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT NUMBER.
	LAC	TTWD00,X	/THE TTY IS IDLE IF THE CAL FUNCTION
	AND	(777)		/CODE = 0.
	SNA
	JMP	TTABNX		/IDLE -- TRY NEXT TTY.
/
/ THIS TTY IS NOT IDLE -- IS IT PERFORMING I/O FOR THE TASK BEING
/ ABORTED?
/
	LAC	TTWD09,X	/ADDRESS OF THE I/O REQUEST NODE.
	TAD	TTXADJ
	PAX
	LAC	2,X		/COMPARE STL NODE ADDRESSES.
	SAD	TTABSN
	SKP			/SAME.
	JMP	TTABNX		/DIFFERENT -- TRY NEXT TTY.
/
/ IS A "PRINTER" INTERRUPT EXPECTED?
/
	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT NUMBER.
	.INH			/INHIBIT INTERRUPTS.
	LAC	TTWD06,X	///IS A "PRINTER" INTERRUPT EXPECTED?
/
/  START OF EDIT #161
/
	AND	(30000		/KEEP ONLY BAUD BITS
	DAC	TTWD06,X
	777000			/MARK TELETYPE AS NO LONGER BUSY
	AND	TTWD00,X
	DAC	TTWD00,X
	LAC	TTWD09,X	/GIVE BACK REQUEST NODE
	DZM	TTWD09,X	/CLEAR NODE; NECESSARY ?
	.ENB			/LET SYSTEM BACK IN
/
/  END OF EDIT #161
/
	DAC*	(R2)
	JMS*	(IOCD)		/(R5, XR & AC ARE ALTERED).
/
/ RETURN THE I/O REQUEST NODE TO THE EMPTY POOL. THE REQUEST NODE
/ ADDRESS SHOULD STILL BE IN "R2".
/
	LAC	(POOL)		/ADDRESS OF THE EMPTY POOL.
	DAC*	(R1)
	JMS*	(NADD)		/(R2, R6, XR & AC ARE ALTERED).
/
/ PREPARE FOR NEXT TTY UNIT.
/
TTABNX	IDX	TTUNIT
	LAC*	(TTYNUM)	/NUMBER OF TTY'S ON THIS MACHINE.
	SAD	TTUNIT		/ANY MORE TO PROCESS?
	SKP			/NO.
	JMP	TTABLP		/YES.
/
/ RELINQUISH THE ABORT NODE.
/
	LAC	TTABNA		/ADDRESS OF THE ABORT NODE.
	DAC*	(R2)
	LAC	(POOL)		/ADDRESS OF THE EMPTY POOL DEQUE.
	DAC*	(R1)
	JMS*	(NADD)		/ADD NODE TO DEQUE.
				/(R1, R2, R6, XR & AC ARE ALTERED).
/
/ I/O RUNDOWN IS COMPLETE. SET THE EVENT VARIABLE OF THE I/O RUNDOWN
/ TASK.
/
	LAC	TTRDEV		/ADDRESS OF THE I/O RUNDOWN EVENT
	TAD	TTXADJ		/VARIABLE.
	PAX
	CLA!IAC
	DAC	0,X
	.SET6			/DECLARE A SIGNIFICANT EVENT.
/
/ SCAN I/O REQUEST QUEUE FOR EACH TTY.
/
TTRQSC	LAC*	(TTYNUM)	/# OF TTY'S ON THIS MACHINE.
	PAL
	CLX
TTRQLP	LAC	TTWD07,X	/GET POINTER TO TTY'S REQUEST QUEUE.
	DAC	TTTEMP
	LAC*	TTTEMP		/IF THE REQUEST QUEUE LIST
	SAD	TTTEMP		/HEAD POINTS TO ITSELF, THE
	JMP	TTRQNX		/QUEUE IS EMPTY -- NO PENDING I/O.
	LAC	TTWD00,X	/BITS 9-17 OF TTY WORD 0 IN-
	AND	(777)		/DICATE THAT THE UNIT
	SNA			/IS FREE (IDLE) IF = 0.
	JMP	TTRSVC		/YES. SERVICE TTY I/O REQUEST.
/
TTRQNX	AXS	1		/TRY NEXT TTY.
	JMP	TTRQLP
/
/ A COMPLETE SCAN OF "KEYBOARD" AND "PRINTER" INTERRUPTS AND
/ OF TTY I/O REQUESTS HAS BEEN MADE; NOTHING
/ SERVICEABLE WAS FOUND.  RETURN TO WAIT FOR "TTTGEV"
/ TO TRIGGER TASK EXECUTION.
/
	JMP	TTYTW
/
/ RETURN HERE IF THE TTY IS ATTACHED AND IF
/ NONE OF THE I/O REQUESTS WERE MADE BY THE
/ ATTACHED TASK.
/
TTNXRQ	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT NUMBER.
	JMP	TTRQNX
/
/ CTRL C INPUT FROM "KEYBOARD."
/
TTC.C	DBK			/DEBREAK FROM API-3 TO API-7.
	DZM	TTK.EV,X	/SET THE "KEYBOARD" EVENT
				/VARIABLE TO 0.
/
/ WHEN CTRL C IS "TYPED" AT THE CURRENT MCR
/ TTY, THE MCR TASK IS REQUESTED.
/
	PXA			/IS THIS UNIT THE
	SAD*	(TTMCTT)	/MCR TTY?
	SKP!CLA
	JMP	TTSCAN		/NO. IGNORE CTRL C AND
				/SCAN FOR MORE TTY I/O.
/
	SAD*	(MCRRI)		/YES. IS THE "MCR REQUEST
				/INHIBIT" FLAG SET (NON-0)?
	JMP	TTRMCR		/NO.
/
/ SET THE INHIBIT FLAG TO -1 (INSTEAD OF +1) TO INDICATE
/ THAT CTRL C WAS INPUT WHEN THE INHIBIT FLAG WAS AL-
/ READY SET; AND THEN IGNORE THE CTRL C.
/
	LAW	-1
	DAC*	(MCRRI)
	JMP	TTSCAN
/
/ THE INHIBIT FLAG IS NOT SET.  SET IT TO +1 AND THEN "REQUEST"
/ THAT THE TASK "...MCR" BE RUN.
/
TTRMCR	IDX*	(MCRRI)
/
	CAL	TT.MCR		/"REQUEST" THE TASK "...MCR".
/
	JMP	TTSCAN
/
/ CTRL T INPUT FROM "KEYBOARD".
/
TTC.T	DBK			/DEBREAK FROM API-3 TO API-7.
	DZM	TTK.EV,X	/CLEAR THE KEYBOARD EVENT VARIABLE.
/
	PXA			/REQUEST "TDV..." (TASK DEVELOPMENT DISPATCH
	SAD*	(TTTDTT)	/ROUTINE) IF CTRL T WAS TYPED ON TDV INPUT TTY.
	CAL	TT.TDV
/
	JMP	TTSCAN		/CTRL T HAS BEEN PROCESSED.
/
/ CTRL X INPUT FROM "KEYBOARD".
/
TTC.X	DBK			/DEBREAK FROM API-3 TO API-7.
	DZM	TTK.EV,X	/CLEAR THE KEYBOARD EVENT VARIABLE.
/
	PXA			/FORM THE TASK NAME FROM THE TTY NUMBER
	LRSS	3		/("TTY.NN" FOR TTY #NN).
	ALS	3
	LLS	3
	XOR	(566060)
	DAC	TT.CTX+3
/
	CAL	TT.CTX		/REQUEST THE TASK.
/
	JMP	TTSCAN		/CTRL X HAS BEEN PROCESSED.
/
/ CAL PARAMETER BLOCKS FOR "REQUEST" DIRECTIVES.
/
TT.MCR	1			/"REQUEST" CODE
	0			/NO EVENT VARIABLE
	.SIXBT	"..."		/TASK NAME (FIRST HALF)
	.SIXBT	"MCR"		/TASK NAME (SECOND HALF)
	0			/DEFAULT PRIORITY
/
TT.TDV	1			/"REQUEST" CODE
	0			/NO EVENT VARIABLE
	.SIXBT	"TDV"		/TASK NAME (FIRST HALF)
	.SIXBT	"..."		/TASK NAME (SECOND HALF)
	0			/DEFAULT PRIORITY
/
TT.CTX	1			/"REQUEST" CODE
	0			/NO EVENT VARIABLE
	.SIXBT	"TTY"		/TASK NAME (FIRST HALF)
	.SIXBT	".NN"		/TASK NAME (SECOND HALF)
	0			/DEFAULT PRIORITY
/
/ CTRL U INPUT FROM "KEYBOARD."
/
/ PROCESS THIS CHARACTER NOW ONLY IF THE TTY IS SELECTED
/ FOR OUTPUT (WRITE) IN IOPS ASCII MODE.
/
TTC.U	LAC	TTWD00,X	/BITS 6-8 = 2 (IOPS ASCII) AND
	AND	(007777)	/BITS 9-17 = 027 (WRITE)?
	SAD	(002027)
	SKP			/YES.
	JMP	TTTSTP		/NO, CONTINUE THE SCAN.
/
/ NOTE -- SINCE "OUTPUT" HAS BEGUN TO THIS TTY,
/ THE OUTPUT REGISTER [TTWD06] MUST ALREADY INDI-
/
	LAC	TTWD06,X	/SET BIT 3=1 IN THE
	AND	(737777)	/OUTPUT REGISTER TO
	XOR	(040000)	/CAUSE CARRIAGE RETURN
	DAC	TTWD06,X	/TO BE "PRINTED".
/
/ THE PRECEDING MODIFICATION MUST BE DONE AT API LEVEL 3
/ TO PREVENT THE "PRINTER" INTERRUPT FROM OCCURRING IN MID-
/ STREAM.
/
	DBK			/DEBREAK FROM API-3 TO
	DZM	TTK.EV,X	/API-7, CLEAR THE "KEYBOARD"
	JMP	TTSCAN		/EVENT VARIABLE, AND
				/RESCAN FOR MORE TTY I/O.
 .TITLE *** TTY I/O REQUEST SERVICE
/
/ CONTROL COMES HERE WHEN AN I/O DIRECTIVE REQUEST HAS BEEN
/ QUEUED FOR A TTY THAT IS CURRENTLY IDLE
/ (NOT SERVICING ANOTHER REQUEST).  THE TTY UNIT NUMBER
/ IS IN THE XR.
/
/ NOTE -- INITIALLY NONE OF THE TERMINALS ARE "ATTACHED"
/ TO SPECIFIC TASKS.  WHEN A DEVICE IS NOT
/ ATTACHED TO A TASK, I/O REQUESTS TO THAT DEVICE ARE
/ PROCESSED IN ORDER OF PRIORITY.  WHEN A DEVICE IS
/ ATTACHED TO A TASK, ONLY THE I/O REQUESTS MADE BY
/ THAT TASK ARE PROCESSED.  REQUESTS MADE BY OTHER
/ TASKS REMAIN QUEUED (DORMANT) UNTIL THE TASK
/ RELINQUISHES THE DEVICE VIA A "DETACH" REQUEST.
/
TTRSVC	PXA			/SAVE LOGICAL UNIT #
	DAC	TTUNIT		/OF CURRENT TTY.
/
/ USE A COMMON MONITOR SUBROUTINE TO PICK AN I/O REQUEST FROM
/ THIS TTY'S QUEUE.
/
	LAW	-D.QF		/COMPUTE THE PHYSICAL DEVICE NODE
	TAD	TTWD07,X	/ADDRESS & STORE IT IN R1.
	DAC*	(R1)
	JMS*	(DQRQ)		/DE-QUEUE AN I/O REQUEST.
				/(R1, R2, R4, R5, R6, XR
				/& AC ARE ALTERED).
				/WAS A REQUEST FOUND?
	JMP	TTNXRQ		/NO -- TRY NEXT TTY.
	PAL			/YES -- SAVE REQUEST NODE ADDRESS TEMPORARILY.
/
/ GET AND SAVE ALL THE USEFUL INFORMATION FROM THE REQUEST NODE.
/
	JMS	TTUINX		/RESTORE THE INDEX REGISTER
				/WITH THE LOGICAL TTY UNIT #.
	PLA			/SET UP AUTO INDEX REGISTER 10
	DAC	TTWD09,X	/TO START WITH THE 6TH
	AAC	4		/WORD IN THE REQUEST NODE.
	DAC*	(X10)
/
/ THE SIXTH WORD IN THE REQUEST NODE CONTAINS THE LOGICAL
/ UNIT # (LUN) IN THE LEFT HALF AND THE CAL FUNCTION CODE
/ IN THE RIGHT HALF.
/
	LAC*	X10		/GET LUN & CAL CODE.
	AND	(777)		/SAVE THE CAL CODE
	DAC	TTWD01,X	/(TEMPORARILY).
	777000			/LAW 17000
	AND	TTWD00,X
	TAD	TTWD01,X
	DAC	TTWD00,X
/
	LAC*	X10		/GET ADDRESS OF REQUESTOR'S
	DAC	TTWD01,X	/EVENT VARIABLE (0 IF NONE).
/
	LAC*	X10		/GET DATA MODE AND SAVE
	AND	(7)		/IN BITS 6-8 OF TTY WORD 0.
	SWHA
	DAC	TTWD02,X	/SAVE TEMPORARILY.
	770777			/LAW 10777
	AND	TTWD00,X
	TAD	TTWD02,X
	DAC	TTWD00,X
/
	LAC*	X10		/GET AND SAVE ADDRESS OF
	DAC	TTWD02,X	/REQUESTOR'S LINE BUFFER HEADER.
	DAC	TTHDR0
	AAC	2
	DAC	TTWD03,X
/
	LAC*	X10		/GET AND SAVE THE
	DAC	TTWD04,X	/LINE BUFFER SIZE.
/
/ SET BIT 14=0 IN TTY WORD 5 SO THAT SUCCESSFUL COMPLETION OF THE
/ I/O REQUEST WILL CAUSE THE REQUESTOR'S EVENT VARIABLE TO BE
/ SET TO +1. SUBSEQUENTLY, OUTPUT ABORTED BY CTRL U OR IOPS
/ ASCII INPUT ENDING WITH CARRIAGE RETURN (RATHER THAN ALTMODE)
/ WILL SET BIT 14=1 TO CAUSE THE EVENT VARIABLE TO BE SET TO +2.
/
	777767			/LAW 17767
	AND	TTWD05,X
	DAC	TTWD05,X
/
/ EXAMINE CAL FUNCTION CODE AND DISPATCH TO APPROPRIATE
/ ROUTINE.
/
	LAC	TTWD00,X
	AND	(777)
	SAD	(24)
	JMP	TTATCH		/"ATTACH" REQUEST.
	SAD	(25)
	JMP	TTDTCH		/"DETACH" REQUEST.
	SAD	(26)
	JMP	TTREAD		/"READ" REQUEST.
	SAD	(27)
	JMP	TTWRIT		/"WRITE" REQUEST.
	SAD	(36)
	JMP	TTHINF		/"HINF" REQUEST.
/
/ UNIMPLEMENTED OR ILLEGAL FUNCTION -- SET REQUESTOR'S
/ EVENT VARIABLE TO -6 AND IGNORE THE REQUEST.
/
TTIFNC	LAW	-6
	JMP	TTSREV		/SET REQUESTOR'S EVENT VARIABLE.
/
/
/
/ (CODE 24) ATTACH TTY TO A TASK.
/
TTATCH	LAW	-D.QF		/COMPUTE THE PHYSICAL DEVICE NODE
	TAD	TTWD07,X	/ADDRESS & STORE IT IN R1.
	DAC*	(R1)
	LAC	TTWD09,X	/STORE THE I/O REQUEST NODE'S
	DAC*	(R2)		/ADDRESS IN R2.
	JMS*	(ALAD)		/ATTACH THE LUN & PHYSICAL DEVICE
				/TO THE TASK.
				/(R3, R4, R5, R6, X10, X11, XR & AC
				/ARE ALTERED).
				/WAS THE ATTACH DONE?
	JMP	TTSREV		/NO -- THE PROPER EVENT VARIABLE SETTING
				/IS IN THE AC.
	JMP	TTDTC2		/YES.
/
/
/ (CODE 25) DETACH TTY FROM A TASK.
/
TTDTCH	LAW	-D.QF		/COMPUTE THE PHYSICAL DEVICE NODE
	TAD	TTWD07,X	/ADDRESS & STORE IT IN R1.
	DAC*	(R1)
	LAC	TTWD09,X	/STORE THE I/O REQUEST NODE'S
	DAC*	(R2)		/ADDRESS IN R2.
	JMS*	(DLAD)		/DETACH THE LUN & PHYSICAL DEVICE
				/FROM THE TASK.
				/(R3, R4, R5, R6, X10, X11, XR & AC
				/ARE ALTERED).
				/WAS THE DETACH DONE?
	JMP	TTSREV		/NO -- THE PROPER EVENT VARIABLE SETTING
				/IS IN THE AC.
TTDTC2	JMS	TTUINX		/RESTORE THE XR WITH THE LOGICAL TTY UNIT #.
	JMP	TTRQOC		/REQUEST OPERATION COMPLETED.
/
/
/ (CODE 26) READ DATA FROM TTY INTO REQUESTOR'S LINE BUFFER.
/
TTREAD	LAC	TTWD00,X	/MAKE SURE THAT THIS TTY
	SMA			/CAN SEND DATA TO THE CPU.
/
/ SINCE THIS TTY IS STRICTLY AN OUTPUT TERMINAL, "READ" IS
/ AN ILLEGAL FUNCTION (TREATED AS AN UNIMPLEMENTED
/ FUNCTION). RETURN -6 IN THE REQUESTOR'S EVENT VARIABLE.
/
	JMP	TTIFNC
/
	AND	(007000)	/VALIDATE DATA MODE IN
	SAD	(002000)	/BITS 6-8 OF TTY WORD 0.
	JMP	TTTRUN		/O.K. -- IOPS ASCII.
	SAD	(003000)
	JMP	TTRWCC		/O.K. -- IMAGE ASCII.
/
	JMP	TTIMDE		/SET REQUESTOR'S EVENT VARIABLE
				/TO INDICATE "ILLEGAL MODE".
/
/ FOR IOPS ASCII INPUT, TRUNCATE THE LINE-BUFFER-SIZE TO MAKE
/ SURE IT IS A MULTIPLE OF TWO.
/
TTTRUN	777776			/LAW 17776
	AND	TTWD04,X
	DAC	TTWD04,X
/
TTRWCC	LAC	TTWD04,X	/BUFFER SIZE MUST
	SPA			/BE POSITIVE.
	JMP	TTILWC		/NO. ERROR.
	AAC	-3		/SIZE MUST BE AT
	SPA			/LEAST 3.
	JMP	TTILWC		/NO. ERROR.
	TAD	(-773)		/DOES SIZE EXCEED 776?
	SPA!SNA
	JMP	.+3		/NO.
	LAC	(776)		/YES. LIMIT THE SIZE
	DAC	TTWD04,X	/TO 776 SINCE THE
				/LARGEST RECORDABLE
				/WORD PAIR COUNT
				/IS 377.
	LAC	TTWD04,X
	DAC*	(R4)		/SAVE FOR CALL BELOW TO "VAJX".
/
/ VERIFY THAT THE LINE BUFFER RESIDES ENTIRELY WITHIN THE REQUESTER'S
/ PARTITION (THE CHECK IS MADE ONLY FOR NORMAL MODE TASKS) AND ADJUST
/ THE HEADER ADDRESS TO 17 BITS.
/
	LAC	TTWD09,X	/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	LAC	TTHDR0		/ADDRESS OF THE LINE BUFFER HEADER WORD 0.
	DAC*	(R3)
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	TTXPER		/YES -- BUFFER EXCEEDS PARTITION BOUNDS.
	JMS	TTUINX		/NO -- RESTORE THE XR WITH THE LOGICAL TTY UNIT #.
	LAC*	(R3)		/SAVE THE ADJUSTED HEADER ADDRESS.
	DAC	TTHDR0
	DAC	TTWD02,X
	AAC	+2
	DAC	TTWD03,X
/
	LAC	TTWD00,X	/INITIALIZE REQUESTOR'S
	SWHA			/LINE BUFFER HEADER WORD 0.
	AND	(7)		/1002 MEANS 1 WORD PAIR
	TAD	(001000)	/(THE HEADER ITSELF) AND MODE 2;
	JMS	TTSETX		/SET X12 & X13 TO ACCESS THE HEADER.
	DAC*	X13		/1003 MEANS THE SAME FOR MODE 3.
/
	777770			/LAW 17770
	AND	TTWD05,X	/INITIALIZE IOPS ASCII
	DAC	TTWD05,X	/BYTE COUNT TO 0.
/
	DZM	TTK.EV,X	/ZERO THIS TTY'S "KEYBOARD"
				/EVENT VARIABLE TO IGNORE
				/INPUT PRIOR TO THIS READ
				/REQUEST.
	JMP	TTINLF		/TTY UNIT HAS BEEN SELECTED FOR A READ
				/OPERATION. CHECK IF AN INITIAL LINE
				/FEED IS NEEDED.
/
/ (CODE 27) WRITE DATA FROM REQUESTOR'S LINE BUFFER TO TTY.
/
TTWRIT	LAC	TTWD00,X	/MAKE SURE THAT THIS TTY CAN
	RAL			/RECEIVE DATA FROM THE CPU.
	SMA!RAR
/
/ SINCE THIS TTY IS STRICTLY AN INPUT TERMINAL, "WRITE" IS
/ AN ILLEGAL FUNCTION (TREATED AS AN UNIMPLEMENTED
/ FUNCTION). RETURN -6 IN THE REQUESTOR'S EVENT VARIABLE.
/
	JMP	TTIFNC
/
/ VERIFY THAT THE ADDRESS OF THE LINE BUFFER HEADER IS WITHIN THE TASK'S
/ PARTITION (FOR NORMAL MODE TASKS ONLY) AND ADJUST THE HEADER ADDRESS
/ TO 17 BITS.
/
	LAC	TTWD09,X	/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	LAC	TTHDR0		/ADDRESS OF LINE BUFFER HEADER WORD 0.
	DAC*	(R3)
	CLA!IAC			/PRETEND THE BUFFER SIZE IS 1.
	DAC*	(R4)
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	TTXPER		/YES -- HEADER OUTSIDE OF PARTITION.
	LAC*	(R3)		/NO -- DON'T SAVE THE ADJUSTED HEADER
				/ADDRESS IN TTHDR0 BECAUSE VAJX MUST
				/BE CALLED AGAIN.
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THE HEADER.
	JMS	TTUINX		/RESTORE THE XR.
/
/ CHECK THE I/O REQUEST NODE TO SEE IF THE TASK IS RUNNING IN EXECUTIVE
/ MODE. IF SO, AND IF THE MODE IS IOPS ASCII, THERE MIGHT BE NO HEADER
/ WORD PAIR (THIS IS TRADITIONAL AS WELL AS A CONVENIENCE). SET THE
/ NEGATIVE WORD COUNT [TTWD04] TO ZERO SO THAT IT IS EFFECTIVELY VERY LARGE.
/
	LAC	TTWD00,X	/IS THE DATA MODE IOPS ASCII?
	AND	(007000)
	SAD	(002000)
	SKP			/YES.
	JMP	TTVWPC		/NO.
	LAC	TTWD09,X	/I/O REQUEST NODE ADDRESS.
	AAC	+3
	DAC	TTTEMP
	LAC*	TTTEMP
/
/ !!!!! THE FOLLOWING TWO COMMENT LINES (SZA; JMP TTVWPC) SHOULD BE
/ !!!!! CHANGED INTO REAL CODE WHENEVER IT IS DECIDED THAT MACRO,
/ !!!!! FORTRAN, ET AL, WHICH NORMALLY RUN AS NORMAL MODE TASKS WITH
/ !!!!! MEMORY PROTECT ENABLED, HAVE BEEN PROPERLY CONVERTED SO THAT
/ !!!!! THEY USE LINE BUFFER HEADERS WITH CORRECT WORD-PAIR-COUNTS
/ !!!!! FOR ALL TELETYPE MESSAGES. UNTIL THEN, THIS HANDLER WILL NOT
/ !!!!! PROTECT AGAINST NON-EX-MEM IF THE BUFFER HAPPENS NOT TO HAVE
/ !!!!! A LINE TERMINATOR IN IOPS ASCII MODE. WHEN THE TWO INSTRUCTIONS
/ !!!!! ARE INSERTED AS MENTIONED ABOVE, THE JMP TTTCOD (TEMPORARY CODE)
/ !!!!! MUST BE REMOVED.
/
/	SZA			/SKIP IF EXEC MODE TASK.
/	JMP	TTVWPC		/NO.
	DZM	TTWD04,X	/SET A VERY LARGE WORD COUNT.
/
/ TEMP. CODE !!!!!!!!!!!!!!!!!
/
	JMP	TTTCOD
/
/ END TEMP. CODE !!!!!!!!!!!!!
/
	JMP	TTWR02		/WRITE IN IOPS ASCII.
/
/ GET AND VALIDATE THE LINE BUFFER'S WORD-PAIR-COUNT.
/
TTVWPC	LAC*	X12		/GET THE WORD-PAIR-COUNT FROM HEADER WORD
	SWHA			/0, CONVERT TO A TWOS COMPLEMENT WORD COUNT,
	AND	(377)		/DECREASE THE COUNT BY 2 TO BYPASS THE
	RCL			/HEADER WORD PAIR, AND VALIDATE THE WORD ...
	DAC*	(R4)		/SAVE FOR THE CALL BELOW TO "VAJX".
	TCA			/... COUNT (WHICH MUST STILL BE NEGATIVE).
	AAC	2
	DAC	TTWD04,X
	SMA
	JMP	TTILWC		/ILLEGAL WORD COUNT.
/
/ VERIFY THAT THE LINE BUFFER LIES WITHIN THE TASK'S PARTITION. THE REQUEST
/ NODE ADDRESS SHOULD STILL BE IN R2.
/
	LAC	TTHDR0		/UNADJUSTED ADDRESS OF LINE BUFFER HEADER
	DAC*	(R3)		/WORD 0.
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	TTXPER		/YES -- LINE BUFFER EXCEEDS PARTITION BOUNDS.
	JMS	TTUINX		/NO -- RESTORE THE XR.
TTTCOD	LAC*	(R3)		/SAVE THE ADJUSTED HEADER ADDRESS.
	DAC	TTHDR0
	DAC	TTWD02,X
	AAC	+2
	DAC	TTWD03,X	/SAVE THE ADJUSTED DATA POINTER ADDRESS.
/
/ VALIDATE THE DATA MODE AND DISPATCH.
/
	LAC	TTWD00,X
	AND	(007000)	/VALIDATE DATA MODE IN
	SAD	(002000)	/BITS 6-8 OF TTY WORD 0.
	JMP	TTWR02		/O.K. -- IOPS ASCII.
	SAD	(003000)
	JMP	TTWR03		/O.K. -- IMAGE ASCII.
/
TTIMDE	LAW	-7		/SET REQUESTOR'S EVENT VARIABLE
	JMP	TTSREV		/TO INDICATE "ILLEGAL MODE".
/
/ IMAGE ASCII WRITE.
/
TTWR03=.
/
/ FOR IMAGE ASCII WRITE AND FOR IOPS AND IMAGE ASCII READ: IF THE
/ LAST READ/WRITE COMMAND WAS IN IOPS ASCII AND IF THE LINE WAS
/ TERMINATED BY A CARRIAGE RETURN (TTWD05 BIT 13=1), PRINT AN
/ INITIAL LINE FEED.
/
TTINLF	LAC	TTWD05,X	/SAVE BIT 13 OF TTWD05 IN THE MQ.
	AND	(20)
	LMQ
	XOR	TTWD05,X	/CLEAR BIT 13.
	DAC	TTWD05,X
	LACQ			/IS A LEADING LINE FEED NECESSARY?
	SNA
	JMP	TTNOLF		/NO.
	LAC	TTWD00,X	/CHECK TO SEE IF TERMINAL
	RAL			/CAN RECEIVE OUTPUT BEFORE
	SMA			/SENDING LINE FEED.
	JMP	TTNOLF
	LAC	TTWD06,X
	AND	(030000)
	TAD	(600412)	/YES -- SET THE TTY'S OUTPUT REGISTER
				/TO INDICATE THAT A "PRINTER" INTERRUPT
				/IS EXPECTED (BIT 0), THAT IT OCCURRED
				/(BIT 1), AND THAT 1 LINE FEED MUST BE
				/"PRINTED".
	JMP	TTWRGO
/
/ IN IOPS ASCII (MODE 2) WRITE'S, THE HEADER WORD-PAIR-COUNT IS USED ONLY
/ AS AN UPPER LIMIT ON THE MESSAGE SIZE. OUTPUT NORMALLY TERMINATES WHEN
/ A CARRIAGE RETURN OR ALTMODE CHARACTER IS ENCOUNTERED.
/
TTWR02	777770			/LAW 17770
	AND	TTWD05,X	/INITIALIZE IOPS ASCII
	DAC	TTWD05,X	/BYTE COUNT TO 0.
/
TTNOLF	LAC	TTWD06,X	/SET TTY'S OUTPUT REGISTER
	AND	(030000)	/(TTWD06,X) TO INDICATE THAT A
	TAD	(600000)	/"PRINTER" INTERRUPT IS EXPECTED
				/(BIT 0) AND THAT IT
				/OCCURRED (BIT 1)
	DAC	TTCHR1		/SET "CHARACTER 1" FLAG NON-0 SO THAT
				/THE FIRST CHARACTER IN THE LINE BUFFER
				/CAN BE TESTED.
TTWRGO	DAC	TTWD06,X
	JMP	TTSCAN		/RESCAN FOR MORE I/O
				/SERVICING TO BE DONE.
/
TTILWC	LAW	-16		/ILLEGAL WORD-PAIR-COUNT OR ILLEGAL
	JMP	TTSREV		/BUFFER SIZE.
TTXPER	LAW	-30		/I/O TRANSFER ADDRESS OR BUFFER EXCEEDS
	JMP	TTSREV		/THE PARTITION BOUNDS.
/
/ (CODE 36) SET REQUESTOR'S EVENT VARIABLE WITH HANDLER INFORMATION
/ CODE TO SIGNIFY: DEVICE CODE 1; TTY UNIT NUMBER; NON-DIRECTORY-ORIENTED
/ INPUT AND/OR OUTPUT.
/
TTHINF	LAC	TTUNIT		/SHIFT TTY UNIT # LEFT 6 BITS AND
	CLL			/ADD IN THE REST OF THE HINF CODE.
	ALS	6
	IAC			/DEVICE CODE 1.
	DAC	TTTEMP
	LAC	TTWD00,X	/PICKUP THE "SEND"
	RAR			/AND "RECIEVE" BITS.
	AND	(300000)
	XOR	TTTEMP
	JMP	TTSREV		/SET REQUESTOR'S EVENT VARIABLE.
 .TITLE *** TTY "KEYBOARD" INPUT SERVICE
/
/ CONTROL COMES HERE FROM THE TTSCAN ROUTINE WHEN THE 
/ "KEYBOARD" EVENT VARIABLE FOR THIS TTY IS NON-0
/ (CONTAINS A CHARACTER) AND A "PRINTER" INTERRUPT
/ IS NOT EXPECTED.
/
/ THE CHARACTER "CTRL C" (7-BIT CODE 03) IS PROCESSED
/ OUTSIDE OF THIS ROUTINE.
/
/ THE CHARACTER "CTRL U" (7-BIT CODE 25), WHEN INPUT
/ WHILE THE TTY IS SELECTED FOR DOING OUTPUT IN
/ IOPS ASCII, IS PROCESSED OUTSIDE OF THIS ROUTINE.
/
/ ALL OTHER CHARACTERS WHICH ARE INPUT WHILE THE TTY
/ IS SELECTED FOR OUTPUT ARE DISCARDED.
/
TTKSVC	LAC	TTWD02,X	/GET POINTER TO LINE
	DAC	TTHDR0		/BUFFER HEADER WORD 0.
/
	LAC	TTK.EV,X	/GET AND SAVE THE INPUT
	AND	(177)		/CHARACTER (MASKED TO
	DAC	TTCHAR		/7 BITS) AND THEN CLEAR
	DZM	TTK.EV,X	/THE "KEYBOARD" EVENT VARIABLE.
/
	LAC	TTWD00,X	/IS THIS TTY UNIT IDLE?
	AND	(777)
	SNA
	JMP	TTSCAN		/YES. SCAN FOR MORE TTY I/O.
	LAC	TTCHAR
/
/////////////////////////////
/
/ CTRL D SHOULD BE DETECTED
/ HERE IF IT IS TO BE USED AS
/ A MEANS OF CREATING AN
/ END OF FILE CONDITION.
/
/////////////////////////////
/
	SAD	(176)		/CONVERT CODES 176 AND
	LAC	(175)		/33, WHICH ARE POSSIBLE
	SAD	(33)		/OTHER FORMS OF ALTMODE
	LAC	(175)		/(PREFIX OR ESCAPE) TO
	DAC	TTCHAR		/THE PDP-15 STANDARD IN-
				/TERNAL 175 REPRESENTATION.
/
/ DISPATCH ON DATA MODE.
/
	LAC	TTWD00,X
	AND	(7000)
	SAD	(2000)
	JMP	TTRIOP		/READ IN IOPS ASCII.
/
/ ASSUME IMAGE ASCII (MODE 3).
/
	LAC	TTWD03,X	/GET DATA STORAGE POINTER AND ...
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THAT WORD.
	LAC	TTCHAR		/ ... STORE THE INPUT CHARACTER IN THE
	DAC*	X13		/REQUESTOR'S LINE BUFFER.
	IDX	TTWD03,X	/INCREMENT THE STORAGE POINTER.
/
	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	LAC*	X12		/ADD 1/2 TO THE
	TAD	(400)		/WORD PAIR COUNT.
	DAC*	X13
/
	JMS	TT.OUT		/IF NECESSARY, OUTPUT THE
				/CHARACTER TO THE "PRINTER".
				/(AC ALTERED).
/
	LAC	TTHDR0		/END TEST -- IS THE DATA
	TAD	TTWD04,X	/POINTER EQUAL TO THE HEADER
	SAD	TTWD03,X	/POINTER PLUS THE BUFFER SIZE?
	SKP
	JMP	TTSCAN		/NO. RESCAN FOR MORE I/O.
/
/ IMAGE ASCII INPUT BUFFER IS FULL.  EXCEPT FOR
/ THE POSSIBLE "PRINTING" OF THE LAST CHARACTER,
/ THIS I/O REQUEST IS DONE.
/
	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	LAC*	X12		/ADD 1/2 TO THE LINE BUFFER
	TAD	(400)		/WORD PAIR COUNT IN HEADER
	AND	(777377)	/WORD 0 (IN CASE THE
	DAC*	X13		/NUMBER OF CHARACTERS INPUT
				/WAS ODD) AND THEN GET
				/RID OF A POSSIBLE EXTRA 1/2.
	JMP	TTDONE
/
/ IOPS ASCII (MODE 2) INPUT.
/
TTRIOP	LAC	TTCHAR		/TEST FOR ERASE CHARACTERS.
	SAD	(25)
	JMP	TTCTLU		/CTRL U.
	SAD	(177)
	JMP	TTR.O.		/RUBOUT.
/
/ DON'T TEST FOR BUFFER OVERFLOW IF THE CHARACTER
/ IS CARRIAGE RETURN OR ALTMODE.
/
	SAD	(15)		/CARRIAGE RETURN?
	SKP
	SAD	(175)		/ALTMODE?
	JMP	TTIAST		/YES.
/
/ TEST FOR BUFFER OVERFLOW.
/
	LAC	TTHDR0		/IS THE DATA POINTER POINTING
	TAD	TTWD04,X	/AT THE LAST DATA WORD IN THE
	AAC	-1		/LINE BUFFER?
	SAD	TTWD03,X
	SKP
	JMP	TTIAST		/NO.  O.K. TO STORE CHARACTER.
/
	LAC	TTWD05,X	/IS THE BYTE COUNT = 4?
	AND	(7)		/(IS IT READY FOR THE FINAL
	SAD	(4)		/CHARACTER IN 5/7 WORD PAIR?)
	SKP
	JMP	TTIAST		/NO.
/
////////////////////////////////
/
/ THE LAST CHARACTER IN THE
/ BUFFER WILL BE FORCED TO
/ BE A CARRIAGE RETURN.
/
////////////////////////////////
/
	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	777717			/LAW 17717.
	AND*	X12		/SET BITS 12 & 13 IN LINE
	AAC	60		/BUFFER HEADER WORD 0 TO
	DAC*	X13		/INDICATE "SHORT BUFFER".
/
	LAC	(15)		/CHANGE THE INPUT
	DAC	TTCHAR		/CHARACTER TO A
				/CARRIAGE RETURN.
/
/ STORE THE CHARACTER IN IOPS (5/7) ASCII FORMAT.
/
TTIAST	LAC	TTWD05,X	/GET 5/7 BYTE COUNT
	AND	(7)		/AND COMPUTE DISPATCH
	TAD	(XCT TTRDTB)	/INSTRUCTION.
	DAC	TTRXCT		/SAVE XCT INSTRUCTION.
/
	LAW	-10000		/SET XR TO POINT TO THE CURRENT DATA WORD
	TAD	TTWD03,X	/IN THE LINE BUFFER. THE PAGE BITS FOR
	PAX			/PAGE 1 HAVE BEEN SUBTRACTED FROM IT.
/
	LAC	TTCHAR		/GET 7-BIT CHARACTER,
	CLL			/CLEAR LINK, AND XCT THE
TTRXCT	XX			/INSTRUCTION IN THE TABLE.
/
/ RETURN HERE FOR BYTES 1, 3 AND 4 WITH THE CHARACTER
/ CORRECTLY POSITIONED IN THE AC.
/
	JMP	TTRDST
/
TTRDTB	JMP	TTRDB0		/BYTE 0
	ALS	4		/BYTE 1
	JMP	TTRDB2		/BYTE 2
	ALS	10		/BYTE 3
	RAL			/BYTE 4
/
TTRDB0	DZM	0,X		/BEFORE STORING THE FIRST
	DZM	1,X		/BYTE, CLEAR THE WORD PAIR.
	ALS	13
	JMP	TTRDST
/
TTRDB2	CLQ			/SPLIT BYTE 2 BETWEEN
	LRS	3		/THE TWO WORDS IN THE
	XOR	0,X		/DATA WORD PAIR.
	DAC	0,X		/WORD 1 COMPLETE.
	AXR	1		/POINT AT WORD 2.
	LACQ
/
TTRDST	XOR	0,X		/MERGE THE CHARACTER INTO THE
	DAC	0,X		/LINE BUFFER WORD.
/
	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT #.
/
	IDX	TTWD05,X	/ADD 1 TO THE BYTE COUNT.
	LAC	TTWD05,X	/IF THE BYTE COUNT WENT
	AND	(7)		/FROM 2 TO 3
	SAD	(3)		/ADD 1 TO THE
	IDX	TTWD03,X	/DATA STORAGE POINTER.
/
	SAD	(1)		/IF THE BYTE COUNT WENT FROM
	JMP	TTRDB1		/0 TO 1...
	SAD	(5)		/IF THE BYTE COUNT WENT
	SKP			/FROM 4 TO 5, RESET THE
	JMP	TTRDPR		/COUNT TO 0, AND ADD 1
	777770			/TO THE DATA STORAGE POINTER.
	AND	TTWD05,X
	DAC	TTWD05,X
	IDX	TTWD03,X
	JMP	TTRDPR
/
TTRDB1	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	LAC*	X12		/... ADD 1 TO THE LINE
	TAD	(001000)	/BUFFER HEADER WORD
	DAC*	X13		/PAIR COUNT.
/
TTRDPR	JMS	TT.OUT		/IF NECESSARY, OUTPUT THE
				/CHARACTER TO THE "PRINTER".
				/(AC ALTERED).
	LAC	TTCHAR
	SAD	(175)		/ALT MODE?
	JMP	TTDONE		/YES.  END OF LINE.
	SAD	(15)		/CARRIAGE RETURN?
	SKP			/YES.  END OF LINE.
	JMP	TTSCAN		/I/O REQUEST NOT YET COMPLETED.
				/RESCAN FOR I/O TO BE
				/SERVICED.
/
/ IOPS ASCII INPUT TERMINATED BY CARRIAGE RETURN.
/ SET BIT 14=1 IN TTY WORD 5 TO INDICATE
/ THAT THE REQUESTOR'S EVENT VARIABLE SHOULD
/ BE SET TO +2 RATHER THAN +1 WHEN THE I/O
/ REQUEST OPERATION IS COMPLETED. ALSO, SET BIT 13 = 1
/ TO INDICATE THAT THE CARRIAGE IS IN POSITION FOR A
/ POSSIBLE OVERPRINT.
/
	777747			/LAW 17747
	AND	TTWD05,X
	AAC	30
	DAC	TTWD05,X
	JMP	TTDONE
/
/ CONTROL U INPUT IN IOPS ASCII ERASES THE ENTIRE LINE BUFFER.
/
TTCTLU	LAC	(100)		/CHANGE CHARACTER TO
	JMS	TTPRNT		/AN @ AND (MAYBE) "PRINT" IT.
				/(AC & TTCHAR ALTERED).
/
	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	LAC*	X12		/RESET LINE BUFFER HEADER
	AND	(777)		/WORD PAIR COUNT TO 1.
	TAD	(1000)
	DAC*	X13
/
	LAC	TTHDR0		/RESET LINE BUFFER DATA
	AAC	2		/POINTER TO THE FIRST
	DAC	TTWD03,X	/DATA WORD (2 AFTER THE
				/HEADER).
/
	777770			/LAW 17770.
	AND	TTWD05,X	/RESET 5/7 ASCII BYTE
	DAC	TTWD05,X	/COUNT TO 0.
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
/
/ RUBOUT INPUT IN IOPS ASCII ERASES ONE CHARACTER PRE-
/ VIOUSLY "TYPED" IN.
/
TTR.O.	777000			/IF THE LINE BUFFER HEADER ...
	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	AND*	X12		/... WORD PAIR COUNT IS 1, THE
	SAD	(1000)		/BUFFER IS EMPTY SO THERE
	JMP	TTSCAN		/IS NOTHING TO RUBOUT.
/
	LAC	(134)		/CHANGE "RUBOUT" TO A "\"
	JMS	TTPRNT		/FOR "PRINTING" AND DO
				/IT IF NECESSARY.
				/(AC & TTCHAR ALTERED).
/
	LAC	TTWD03,X	/GET AND SAVE LINE BUFFER DATA POINTER.
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THE DATA.
/
	LAC	TTWD05,X	/GET BYTE COUNT AND
	AND	(7)		/COMPUTE DISPATCH JMP
	TAD	(JMP TTROTB)	/INSTRUCTION.
	DAC	.+1
	XX			/JMP TTROTB + "BYTE COUNT".
TTROTB	JMP	TTROB4		/RUBOUT BYTE 4.
	JMP	TTROB0		/RUBOUT BYTE 0.
	JMP	TTROB1		/RUBOUT BYTE 1.
	JMP	TTROB2		/RUBOUT BYTE 2.
/
/ RUBOUT BYTE 3.
/
	LAC*	X12		/GET DATA WORD AND SET
	AND	(700000)	/BYTE 3 TO ZERO.
	JMP	TTRDAC
/
/ RUBOUT BYTE 4.
/
TTROB4	LAC	TTWD05,X	/SET BYTE COUNT TO 5 SO
	AAC	5		/THAT IT WILL BE DECREMENTED
	DAC	TTWD05,X	/TO 4 (BELOW).
	LAC*	(X12)		/SET THE DATA POINTER BACK 1 REGISTER.
	DAC	TTWD03,X
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THE DATA.
	777400			/GET DATA WORD AND SET
	JMP	TTRAND		/BYTE 4 TO ZERO.
/
/ RUBOUT BYTE 0.
/
TTROB0	JMS	TTSETX		/SET X12 & X13 TO ACCESS HEADER WORD 0.
	LAW	-1000		/SUBTRACT 1 FROM THE LINE BUFFER HEADER
	TAD*	X12		/WORD-PAIR-COUNT.
	DAC*	X13
	CLA			/SET DATA BYTE 0 TO ZERO.
	JMP	TTRDAC
/
/ RUBOUT BYTE 1.
/
TTROB1	774000			/LAW 14000.
	JMP	TTRAND		/SET DATA BYTE 1 TO ZERO.
/
/ RUBOUT BYTE 2.
/
TTROB2	DZM*	X12		/ZERO 2ND 1/2 OF BYTE 2.
	LAC*	(X13)		/MOVE THE DATA POINTER BACK 1 REGISTER.
	DAC	TTWD03,X
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THE DATA.
	777760			/LAW -20.
TTRAND	AND*	X12		/ZERO 1ST 1/2 OF BYTE 2.
TTRDAC	DAC*	X13
/
	LAW	-1		/SUBTRACT ONE FROM THE
	TAD	TTWD05,X	/BYTE COUNT.
	DAC	TTWD05,X
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
 .TITLE *** TTY "PRINTER" OUTPUT SERVICE
/
/ CONTROL COMES HERE FROM THE TTSCAN ROUTINE WHEN
/ THE OUTPUT REGISTER FOR THIS TTY INDICATES THAT
/ A "PRINTER" INTERRUPT WAS EXPECTED AND HAS
/ OCCURRED. THE LATTER (BIT 1) IS CLEARED BY TTSCAN.
/
/ COMPUTE TLS "PRINTING" INSTRUCTION FOR THIS UNIT
/ IN CASE MORE OUTPUT IS TO BE DONE.
/
TTPSVC	LAC	TT.TSF,X	/GET "TSF" INSTRUCTION
	AAC	3		/FROM TABLE AND CONVERT
	DAC	TT.TLS		/TO "TLS".
/
/ CHECK THIS TTY'S OUTPUT REGISTER TO SEE IF ANY FUR-
/ THER PROCESSING IS TO BE DONE AS A RESULT OF
/ THIS INTERRUPT.
/
	LAC	TTWD06,X
	AND	(007400)	/CHECK THE CHARACTER REPEAT
	SNA			/COUNT.
	JMP	TTCNT0		/ZERO.
/
	LAW	-400		/SUBTRACT 1 FROM THE
	TAD	TTWD06,X	/REPEAT COUNT.
	DAC	TTWD06,X
/
	AND	(377)		/OUTPUT THE 8-BIT CHARACTER.
TT.TLS	XX			/"TLS" INSTRUCTION TO "PRINT"
				/ON THIS TTY FROM THE AC.
	SAD	(12		/WAS THE CHAR. A LINE FEED?
	SKP
	JMP	TTSCAN		/NO -- RESCAN FOR MORE TTY I/O.
	LAC	TTWD05,X	/YES -- IS THIS TTY A VT05?
	AND	(600
	SAD	(600
	SKP
	JMP	TTSCAN		/NO -- RESCAN FOR MORE TTY I/O.
	JMS	TTVTFX		/YES -- PREPARE TO ENTER SOME FILLERS
	LAC	TTWD06,X
	AND	(770000
	OMQ
	DAC	TTWD06,X
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
/
/ REPEAT COUNT IS ZERO.
/
TTCNT0	LAC	TTWD06,X	/IF BIT3=1 IN THE OUTPUT
	AND	(040000)	/REGISTER, CTRL U WAS
	SNA			/TYPED TO ABORT THE
	JMP	TTCKDN		/CURRENT "WRITE" COMMAND.
/
	777747			/LAW 17747.
	AND	TTWD05,X	/OUTPUT LINE CUT SHORT
	AAC	30		/IS INDICATED BY RETURN-
	DAC	TTWD05,X	/ING +2 IN THE USER'S
				/EVENT VARIABLE.  BIT14=1
				/IN TTY WORD 5 SIGNALS
				/THIS. ALSO, SET BIT 13 = 1
				/TO INDICATE THAT THE CARRIAGE
				/IS IN POSITION TO PERFORM AN
				/OVERPRINT IF SO REQUESTED.
/
/ BEFORE PRINTING A CARRIAGE RETURN, SET THE OUTPUT
/ REGISTER TO INDICATE THE FOLLOWING: (BIT0=1) A "PRINTER"
/ INTERRUPT IS EXPECTED; (BIT2=1) THE I/O REQUEST IS
/ COMPLETE WHEN THE INDICATED "PRINTING" IS DONE.
/
	LAC	TTWD06,X
	AND	(030000)
	TAD	(500000)
	DAC	TTWD06,X
	LAC	(215)		/CARRIAGE RETURN.
	JMP	TT.TLS
/
TTCKDN	LAC	TTWD06,X	/PICK UP THE CONTENTS OF
				/AND THEN CLEAR THE OUTPUT
	RTL			/REGISTER.
	RAL			/SAVE BIT 2 IN LINK FOR TESTING.
	LAC	TTWD06,X
	AND	(030000)
	DAC	TTWD06,X
	SZL			/REQUEST DONE (BIT 2=1)?
	JMP	TTRQOC		/YES.
/
/ CONTROL COMES HERE ONLY AFTER THE CURRENT
/ CHARACTER (WHICH MIGHT INVOLVE A CHARACTER
/ AND SEVERAL FILLERS, E.G., FORM FEED) HAS
/ BEEN FULLY "PRINTED".  IS THE
/ UNIT SELECTED FOR INPUT OR FOR OUTPUT? IF IT IS
/ SELECTED FOR INPUT, RESCAN FOR MORE TTY I/O.
/
	LAC	TTWD00,X
	AND	(777)
	SAD	(26)		/CAL FUNCTION CODE FOR "READ".
	JMP	TTSCAN
/
/ ASSUME "WRITE".
/
TTWRNX	LAC	TTWD03,X	/GET AND SAVE THE LINE BUFFER DATA POINTER.
	JMS	TTSETT		/SET X12 & X13 TO ACCESS THE DATA.
/
/ DISPATCH ON DATA MODE.  UNIT IS DOING A "WRITE".
/
	LAC	TTWD00,X
	AND	(7000)
	SAD	(2000)
	JMP	TTWIOP		/WRITE IN IOPS ASCII.
/
/ ASSUME IMAGE ASCII (MODE 3).
/
	LAC*	X12		/GET NEXT CHARACTER AND
	JMS	TTPRNT		/(MAYBE) "PRINT" IT.
				/(AC & TTCHAR ALTERED).
/
	IDX	TTWD03,X	/MOVE DATA POINTER AHEAD 1 REGISTER.
	ISZ	TTWD04,X	/DECREMENT THE WORD COUNT.
	SKP
	JMP	TTDONE		/OUTPUT COMPLETE (EXCEPT FOR
				/POSSIBLE "PRINTER" INTERRUPT).
/
TTWRON	LAC	TTWD06,X	/IF NOT EXPECTING A "PRINTER"
	SMA			/INTERRUPT (BIT 0=0 IN TTY
	JMP	TTWRNX		/WORD 6) THE LAST CHARACTER
	JMP	TTSCAN		/WAS DISCARDED (E.G., A NULL).
				/TO KEEP I/O TO THIS UNIT
				/GOING, MUST GO BACK AND
				/PROCESS THE NEXT CHARACTER
				/NOW.
/
/ WRITE IN IOPS ASCII (MODE 2).
/
TTWIOP	LAC	TTWD05,X	/GET CURRENT IOPS ASCII
	AND	(7)		/BYTE COUNT AND COMPUTE
	TAD	(XCT TTWRTB)	/THE DISPATCH INSTRUCTION.
	DAC	TTWXCT
/
	IDX	TTWD05,X	/ADD 1 TO BYTE COUNT.
	LAC	TTWD05,X
	AND	(7)
	SAD	(3)		/IF COUNT NOW EQUALS 3...
	JMP	TTWNXT
	SAD	(5)		/IF COUNT NOW EQUALS 5...
	SKP
	JMP	TTWLAC		/COUNT NOT 3 NOR 5.
/
	XOR	TTWD05,X	/...RESET BYTE COUNT TO 0.
	DAC	TTWD05,X
	IDX	TTWD04,X	/DECREMENT THE WORD COUNT BY 2.
	ISZ	TTWD04,X
	SKP
	JMP	TTXPER		/THE LINE BUFFER WORD-PAIR-COUNT IS EX-
				/CEEDED. NOTE -- THE CARRIAGE IS NOT RE-
				/TURNED IN SUCH A CASE.
/
TTWNXT	IDX	TTWD03,X	/...MOVE DATA POINTER AHEAD 1 REGISTER.
/
TTWLAC	CLL			/CLEAR THE LINK AND
	LAC*	X12		/GET CURRENT DATA WORD.
TTWXCT	XX			/XCT TTWRTB + "BYTE COUNT".
/
/ BYTES 0, 1, 3, AND 4 RETURN HERE WITH THE 7-BIT
/ CHARACTER RIGHT JUSTIFIED IN THE AC.
/
	JMP	TTWAND
/
TTWRTB	LRS	13		/BYTE 0
	LRS	4		/BYTE 1
	JMP	TTWRB2		/BYTE 2
	LRS	10		/BYTE 3
	RAR			/BYTE 4
/
/ BYTE 2
/
TTWRB2	PAL			/SAVE FIRST 4 BITS (14-17) IN THE LR,
	LAC*	X12		/GET NEXT WORD, MOVE 3
	LMQ			/BITS (0-2) TO THE MQ,
	PLA			/RELOAD THE AC WITH THE
	LLS	3		/HIGH-ORDER 4 BITS AND
				/REASSEMBLE THE CHARACTER
				/BY SHIFTING LEFT.
/
/ UNPACKED CHARACTER IS IN THE AC. SAVE IT AND CHECK IF THIS IS THE
/ FIRST CHARACTER FROM THE LINE BUFFER. IF IT IS, AND IF THE PRE-
/ VIOUS LINE WAS IOPS ASCII (INPUT OR OUTPUT) TERMINATED BY A CAR-
/ RIAGE RETURN (INDICATED BY TTWD05 BIT 13 = 1), SUPPLY A LEADING
/ LINE FEED IF THE FIRST CHARACTER IS NOT LINE FEED OR OVERPRINT.
/
TTWAND	AND	(177)
	DAC	TTCHAR		/SAVE THE 7-BIT CHARACTER.
	LAC	TTCHR1		/IS THIS THE 1ST CHARACTER FROM THE
	SNA			/LINE BUFFER?
	JMP	TTWPRT		/NO.
	DZM	TTCHR1		/YES -- CLEAR THE "FIRST CHARACTER" FLAG.
/
/ WAS THE LAST LINE IOPS ASCII TERMINATED BY A CARRIAGE RETURN?
/
	LAC	TTWD05,X	/IS BIT 13 ON?
	AND	(20)
	SNA
	JMP	TTCKLF		/NO.
	XOR	TTWD05,X	/YES -- CLEAR IT.
	DAC	TTWD05,X
/
/ MUST A LEADING LINE FEED BE SUPPLIED?
/
	LAC	TTCHAR		/IS THE FIRST CHARACTER A
	SAD	(12)		/LINE FEED?
	SKP			/YES.
	SAD	(20)		/OVERPRINT?
	JMP	TTWPRT		/YES.
/
/ THE FIRST IS NOT A LINE FEED OR OVERPRINT CHARACTER; THEREFORE,
/ "PRINT" A LINE FEED SINCE THE LAST LINE TERMINATED WITH A CARRIAGE
/ RETURN.
/
	777770			/RESET THE BYTE COUNT TO 0 SINCE THE
	AND	TTWD05,X	/1ST LINE BUFFER CHARACTER WILL NOT
	DAC	TTWD05,X	/BE PROCESSED AT THIS TIME.
	LAC	(12)		/"PRINT" A LINE FEED.
	JMS	TTPRNT		/(AC & TTCHAR ARE ALTERED).
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
/
/ IGNORE THE FIRST CHARACTER IF IT IS A LINE FEED SO THAT IOPS ASCII
/ OUTPUT FOLLOWING IMAGE ASCII OUTPUT (WHICH NORMALLY ENDS IN C.R.L.F.)
/ WILL NOT DOUBLE SPACE UNNECESSARILY.  THIS MEANS THAT ONE CANNOT
/ LINE FEED IN IOPS ASCII IMMEDIATELY FOLLOWING AN IOPS ASCII LINE
/ TERMINATED BY ALTMODE, BUT SO WHAT?!
/
TTCKLF	LAC	TTCHAR		/LINE FEED?
	SAD	(12)		/NO.
	JMP	TTWRON		/YES -- IGNORE IT AND GET THE NEXT
				/BUFFER CHARACTER.
/
/ A LEADING LINE FEED NEED NOT BE SUPPLIED -- "PRINT" THE CURRENT
/ LINE BUFFER CHARACTER.
/
TTWPRT	LAC	TTCHAR
	JMS	TTPRNT		/(MAYBE) "PRINT" THE CHARACTER.
				/(AC & TTCHAR ALTERED).
/
	LAC	TTCHAR		/CHECK FOR LINE TERMINATION.
	SAD	(15)		/CARRIAGE RETURN?
	JMP	TT.RET		/YES.
	SAD	(175)		/ALTMODE?
	JMP	TTDONE		/YES.
	JMP	TTWRON		/NO.  OUTPUT NOT FINISHED.
/
/ AN IOPS ASCII LINE TERMINATED BY A CARRIAGE RETURN MEANS THAT THE
/ CARRIAGE IS IN POSITION TO DO AN OVERPRINT IF SO REQUESTED. SIGNAL
/ THIS CONDITION BY SETTING TTWD05 BIT 13 = 1.
/
TT.RET	777757			/LAW 17757.
	AND	TTWD05,X
	AAC	20
	DAC	TTWD05,X
 .TITLE *** TTY I/O REQUEST DONE
/
/ THE I/O REQUEST IS DONE EXCEPT FOR A POSSIBLE "PRINTER" INTERRUPT.
/
TTDONE	.INH			/INHIBIT INTERRUPTS
	LAC	TTWD06,X	/IS A "PRINTER" INTERRUPT EXPECTED
	SMA			/FOR THIS TTY?
	JMP	TTRQOC		/NO -- REQUEST OPERATION COMPLETED.
	AND	(677777)	/YES -- SET BIT 2 TO INDICATE THAT THE
	XOR	(100000)	/REQUEST IS COMPLETE BUT FOR THE PENDING
	DAC	TTWD06,X	/INTERRUPT.
	.ENB			/ENABLE INTERRUPTS
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
/
/ I/O REQUEST OPERATION COMPLETED.
/
TTRQOC	LAC	TTWD05,X	/IF TTY WORD 5 BIT 14=1, SET
	LRS	3		/REQUESTOR'S EVENT VARIABLE
	AND	(1)		/TO +2 (+1 OTHERWISE).
	IAC
	.ENB			/ENABLE INTERRUPTS
TTSREV	PAL			/SAVE VALUE TEMPORARILY.
	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT #.
	LAC	TTWD05,X	/IF BIT 12 OF TTWD05 IS SET, DON'T
	AND	(40)		/DECREMENT THE I/O PENDING COUNT, DON'T
	SNA			/SET THE REQUESTER'S EVENT VARIABLE,
	JMP	.+4		/AND DON'T RETURN THE I/O REQUEST NODE.
	XOR	TTWD05,X	/ALL THAT WAS DONE BY THE ABORT CODE.
	DAC	TTWD05,X
	JMP	TTFREE
/
	LAC	TTWD09,X	/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	JMS*	(IOCD)		/DECLARE I/O COMPLETED BY DECREMENTING
				/THE COUNT OF PENDING I/O TRANSFERS TO
				/THE TASK'S PARTITION (NORMAL MODE TASK
				/ONLY). (R5, XR & AC ARE ALTERED).
	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT #.
	LAC	TTWD01,X	/GET REQUESTOR'S EVENT
	SNA			/VARIABLE ADDRESS (IF ANY).
	JMP	TTNOEV		/NONE.
/
	JMS	TTSETT		/SET X12 TO STORE THE EVENT VARIABLE VALUE.
	PLA
	DAC*	X12		/SET EVENT VARIABLE.
/
/ RETURN THE I/O REQUEST NODE TO THE EMPTY POOL.
/
TTNOEV	LAC	(POOL)		/ADDRESS OF THE EMPTY POOL.
	DAC*	(R1)
	LAC	TTWD09,X	/THE I/O REQUEST NODE ADDRESS.
	DZM	TTWD09,X	/SHOW WE GAVE IT BACK (#161)
	DAC*	(R2)
	JMS*	(NADD)		/ADD NODE TO "POOL".
				/(R2, R6, XR & AC ARE ALTERED).
/
TTFREE	JMS	TTUINX		/RESTORE THE XR WITH THE TTY UNIT #.
	777000			/SET THE CAL FUNCTION CODE = 0 TO
	AND	TTWD00,X	/INDICATE THAT THIS TTY IS FREE (IDLE).
	DAC	TTWD00,X
/
TTDECL	.SET6			/DECLARE A SIGNIFICANT EVENT.
/
	JMP	TTSCAN		/RESCAN FOR MORE TTY I/O.
 .TITLE *** TTY MISCELLANEOUS SUBROUTINES
/
/ SUBROUTINE TTPRNT -- STORE THE CHARACTER FROM THE AC
/ INTO "TTCHAR" AND CALL "TT.OUT" TO (POSSIBLY) "PRINT"
/ IT.  DO NOT CALL "TT.OUT" FOR CERTAIN CHARACTERS.
/ NULL AND RUBOUT ARE NOT "PRINTED" IN ORDER THAT
/ 1-CHARACTER-AT-A-TIME OUTPUT IN IMAGE ASCII CAN
/ BE DONE AT FULL SPEED. RECALL THAT THE LINE BUFFER
/ WORD PAIR COUNT IS USED AND, THEREFORE, AN EVEN
/ NUMBER OF CHARACTERS ARE UNPACKED.
/
/ CALLING SEQUENCE:
/
/	(7-BIT CHARACTER IN THE AC)
/	JMS	TTPRNT
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	AC & TTCHAR
/
TTPRNT	0
	AND	(177)
	DAC	TTCHAR
	LAC	TTWD00,X	/DOES THIS DEVICE REQUIRE PRINTING ALTM.?
	AND	(010000
	SNA
	JMP	.+3		/NO -- THEN TEST FOR AN ALTMODE
	LAC	TTCHAR		/YES -- (GT40) THEN SKIP ALT. CHECK
	JMP	TTPRN1
	LAC	TTCHAR
	SAD	(175)		/ALTMODE?
	SKP			/YES.
TTPRN1	SAD	(177)		/RUBOUT?
	SKP			/YES.
	SNA			/NULL?
	JMP*	TTPRNT		/YES.  DON'T PRINT.
/
	JMS	TT.OUT		/"PRINT" (MAYBE).
				/(AC ALTERED).
	JMP*	TTPRNT
/
	.EJECT
/ SUBROUTINE TT.OUT -- CALLED TO ECHO CHARACTERS
/ INPUT FROM A "KEYBOARD" BACK TO THE "PRINTER"
/ AND CALLED TO "PRINT" CHARACTERS ON OUTPUT
/ IF THE UNIT IS CAPABLE OF RECEIVING DATA FROM THE CPU.
/
/ NOTE -- THE 8TH BIT IS COMPUTED ON OUTPUT
/ TO FORM AN EVEN PARITY CHARACTER, WHICH IS
/ TYPICALLY REQUIRED FOR ASYNCHRONOUS DATA
/ CHANNELS AND FOR PAPER TAPE. TAPES PUNCHED ON
/ MODEL ASR TELETYPES, OR THE LIKE, PROVIDED
/ THAT THEY ARE NOT OIL BASE TAPES, CAN BE READ
/ VIA THE PC15 HIGH SPEED PAPER TAPE READER.
/ UNLIKE THE PC15 PUNCH HANDLER, HOWEVER, TTY
/ DOES NOT RECOGNIZE THE CLOSE FUNCTION AND
/ THEREFORE DOES NOT OUTPUT AN EOT (END-OF-
/ TRANSMISSION) CHARACTER, WHICH THE PC15
/ READER HANDLER INTERPRETS AS END-OF-FILE.
/
/ CALLING SEQUENCE:
/
/	(7-BIT CHARACTER IN "TTCHAR")
/	(TTY UNIT # IN THE XR)
/	JMS	TT.OUT
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	AC
/
/ THE FOLLOWING COULD BE DONE BUT ISN'T:
/
/ DON'T KEEP TRACK OF THE POSITION WITHIN A LINE IN ORDER
/	TO SIMULATE HORIZONTAL TAB ON A TTY WHICH
/	DOES NOT HAVE THE TABBING MECHANISM.
/
/ DON'T SIMULATE VERTICAL TABS AND FORM FEEDS.  A
/	TTY WHICH CAN RECEIVE OUTPUT IS ASSUMED
/	TO HAVE THE HARDWARE MECHANISM WHICH
/	CAN DO VERTICAL TABS AND FORM FEEDS.
/
/ DON'T TEST FOR A DEVICE THAT IS FULL DUPLEX WITH
/	LOCAL COPY.  FOR NOW, ALL TTY'S THAT CAN BOTH
/	SEND AND RECEIVE ARE ASSUMED TO BE
/	FULL DUPLEX WITHOUT LOCAL COPY, WHICH IM-
/	PLIES THAT "KEYBOARD" INPUT MUST BE SENT
/	BACK TO THE "PRINTER".
/
	.EJECT
TT.OUT	0
	LAC	TTWD00,X	/IF TTY WORD 0, BIT1=0,
	RAL			/RETURN IMMEDIATELY
	SMA			/SINCE THE TTY CANNOT RE-
	JMP*	TT.OUT		/CEIVE DATA FROM THE CPU.
/
/TEST HERE TO DETERMINE DEVICE TYPE, TTWD05 BITS 9 & 10
/00=KSR35; 01=KSR33; 10=LA30; 11=VT05.
/
	LAC	TTWD05,X
	AND	(000600)
	SAD	(200)
	JMP	TTY33		/DEVICE IS A KSR33.
	SAD	(400)
	JMP	TTLA30		/DEVICE IS AN LA30.
	SAD	(600)
	JMP	TTVTST		/DEVICE IS A VT05.
	LAC	TTCHAR		/CHECK FOR CERTAIN CHARACTERS.
	SAD	(11)
	JMP	TTHTAB		/HORIZONTAL TAB.
TTY35	SAD	(13)
	JMP	TTVTAB		/VERTICAL TAB.
	SAD	(07)
	JMP	TTBELL		/BELL.
	SAD	(14)
	JMP	TTFORM		/FORM FEED.
	SAD	(21)
	JMP	TTDBSP		/DOUBLE SPACE.
	LAC	TTWD00,X	/MUST WE PRINT AN ALTMODE FOR THIS TTY?
	AND	(010000
	SZA
	JMP	TT1INT		/YES
	LAC	TTCHAR		/NO -- THEN TEST FOR AN ALTMODE
	SAD	(175)
	JMP*	TT.OUT		/DON'T PRINT ALT MODE.
/
/ THE PRECEDING CHARACTERS MAY NEED MORE THAN A
/ SINGLE CHARACTER TO BE OUTPUT.  GENERALLY, THEY
/ REQUIRE FILLER CHARACTERS (USUALLY NULLS) TO
/ FOLLOW THEM IN ORDER TO PROVIDE THE TIMING DELAY
/ NOT EXISTING IN THE HARDWARE.  FOR EXAMPLE, A
/ HORIZONTAL TAB CANNOT ALWAYS COMPLETE WITHIN A
/ SINGLE CHARACTER TIME. THE NUMBER OF FILLERS
/ NEEDED IS A FUNCTION OF THE OUTPUT BAUD RATE
/ OF THE TERMINAL.
/
/ THE PRIMARY CHARACTER IS "PRINTED" DIRECTLY BY THIS SUB-
/ ROUTINE.  THE FILLER CHARACTER AND REPEAT COUNT ARE
/ ENTERED IN THE TTY'S OUTPUT REGISTER.
/
TT1INT	LAC	(400000)	/SET THE "PRINTER INTERRUPT EXPECTED"
	LMQ
TTSETO	LAC	TTWD06,X	/BIT IN THE OUTPUT REGISTER.
	AND	(030000)
	OMQ			/OR IN FLAGS AND FILL
	DAC	TTWD06,X	/CHARACTER CODE AND COUNT.
/
/ COMPUTE THE TLS "PRINTING" INSTRUCTION FOR THIS UNIT.
/
	LAC	TT.TSF,X	/GET "TSF" INSTRUCTION
	AAC	3		/FROM TABLE AND CONVERT
	DAC	TT.PRT		/TO A "TLS".
/
/ CONVERT THE 7-BIT CHARACTER TO AN 8-BIT EVEN PARITY
/ CHARACTER. THIS IS DESIRABLE FOR PUNCHED PAPER TAPE
/ OUTPUT AND MAY BE REQUIRED BY FUTURE TTY TERMINALS.
/
	LAW	-7		/SET PARITY LOOP COUNT.
	DAC	TTPCNT
	CLL			/SET INITIAL PARITY BIT = 0.
	LAC	TTCHAR		/PICK UP THE 7-BIT CHARACTER.
TTPRTY	SZL!RAR			/SKIP THEN ROTATE.
	CML
	ISZ	TTPCNT
	JMP	TTPRTY
	LAC	TTCHAR
	SZL!CLL
	AAC	200		/SET CHARACTER BIT 8.
TT.PRT	XX			/"TLS" INSTRUCTION FOR TTY UNIT.
	JMP*	TT.OUT
/
/ SPECIAL CASE -- VERTICAL TAB, HORIZONTAL TAB & BELL.
/
TTHTAB=.
TTBELL=.
TTVTAB	LAC	(401000)	/SET OUTPUT REGISTER TO EXPECT
	LMQ
	JMP	TTSETO		/"PRINTER" INTERRUPT AND TO
				/FOLLOW UP WITH 2 NULL CHARACTERS
				/FOR DELAY.
/
/ SPECIAL CASE -- FORM FEED.
/
TTFORM	LAC	(406000)	/SET THE OUTPUT REGISTER TO EXPECT
	LMQ
	JMP	TTSETO		/"PRINTER" INTERRUPT AND TO FOLLOW
				/UP WITH 12 DECIMAL NULL CHARACTERS
				/FOR DELAY.
/
/ SPECIAL CASE -- DOUBLE SPACE. ONE OF THE ROUTINES IN THE FORTRAN
/ OBJECT TIME SYSTEM PUTS A CODE 21 AT THE BEGINNING OF AN IOPS
/ ASCII LINE FOR OUTPUT TO MEAN DOUBLE SPACE. (THIS IS NOT THE
/ MEANING OF CODE 21 AS DEFINED IN USASCII).
/
/ CONVERT THE 21 TO A CODE 12 (LINE FEED). IF THIS IS THE FIRST
/ CHARACTER FROM THE OUTPUT LINE BUFFER, A SECOND LINE FEED WILL
/ ALREADY HAVE BEEN PRINTED PROVIDED THAT THE PRECEDING LINE WAS
/ TERMINATED BY A CARRIAGE RETURN IN IOPS ASCII. IF CODE 21 APPEARS
/ IN THE MIDDLE OF A LINE, ONLY A SINGLE LINE FEED WILL BE PRINTED.
/
TTDBSP	LAC	(12)
	DAC	TTCHAR
	JMP	TT1INT
/
/TEST HERE FOR SPECIAL VT05 CHARACTERS.
/
TTVTST	LAC	TTCHAR		/GET CHARACTER.
	SAD	(12
	JMP	TTVT05		/LINE FEED.
	SAD	(13
	JMP	TTVT05		/MOVE CURSOR DOWN.
	SAD	(16
	JMP	TTCAD		/CURSOR DIRECT ADDRESS.
	SAD	(32
	JMP	TTVT05		/MOVE CURSOR UP.
	SAD	(35
	JMP	TTVT05		/MOVE CURSOR TO ORIGIN.
	SAD	(37
	JMP	TTVT05		/ERASE TO END OF SCREEN.
	SAD	(175		/ALTMODE
	JMP*	TT.OUT		/DON'T PRINT THE ALTMODE
/
/NOT SPECIAL CHARACTER BUT TEST FOR CURSOR DIRECT
/ADDRESSING BY TESTING CAD UNDERWAY FLAG IN TTWD05.
/
	LAC	TTWD05,X	/EXTRACT BIT 11
	AND	(000100)	/TO TEST FOR
	SNA			/CAD UNDERWAY?
	JMP	TT1INT		/NO, REGULAR CHARACTER.
	XOR	TTWD05,X	/YES,TURN OFF
	DAC	TTWD05,X	/CAD UNDERWAY BIT.
/
/SPECIAL CASE -- VT05 CHARACTERS USED FOR VERTICAL CURSOR
/MOVEMENTS REQUIRE FILL CHARACTERS. THE NUMBER OF
/CHARACTERS IS A FUNCTION OF BAUD RATE:
/	 600 BAUD = 1 FILLER
/	1200 BAUD = 2 FILLERS
/	2400 BAUD = 4 FILLERS.
/
TTVT05	JMS	TTVTFX		/CONSTRUCT WORD FOR FILLERS
	JMP	TTSETO
/
/ SUBROUTINE TO CONSTRUCT FILLERS FOR VT05
/
TTVTFX	0
	LAC	TTWD06,X	/GET OUTPUT REGISTER AND
	AND	(030000)	/EXTRACT BAUD RATE.
	SAD	(030000)	/SKIP IF NOT 2400 BAUD.
	LAC	(040000)	/SET TO 4 FILLERS.
	LRSS	4		/OTHERWISE CODE = # OF FILLERS.
	TAD	(400000)	/POSITION AND SET TO EXPECT
	LMQ			/INTERRUPT. SAVE IN MQ.
	JMP*	TTVTFX
/
	.EJECT
/
/SPECIAL CASE -- CURSOR DIRECT ADDRESSING ON VT05.
/THIS FEATURE PERMITS ABSOLUTE POSITIONING OF THE CURSOR.
/THE CAD CHARACTER ITSELF (ASCII 16) REQUIRES NO DELAY.
/HOWEVER, IT IS FOLLOWED BY TWO "PRINTABLE" CHARACTERS WHICH
/HAVE A SPECIAL MEANING TO THE VT05 AS ABSOLUTE CURSOR Y AND X
/POSITIONS. THE Y POSITION CHARACTER MUST BE FOLLOWED BY FILL
/CHARACTERS SINCE IT INITIATES VERTICAL CURSOR MOVEMENT. A
/CAD UNDERWAY FLAG IS SET IN TTWD05 WHEN A CAD IS DETECTED
/AND IS RESET AFTER THE NEXT CHARACTER IS RECEIVED.
/
TTCAD	LAC	TTWD05,X	/GET STATUS REGISTER
	AND	(777677)	/AND SET BIT 11 TO
	XOR	(000100)	/INDICATE A CAD IS
	DAC	TTWD05,X	/NOW UNDERWAY.
	JMP	TT1INT
/
/
/TEST HERE FOR A CARRIAGE RETURN TO A KSR33. MUST RESET THE
/PRINT POSITION COUNTER BEFORE PRINTING THE CR. OTHER
/CHARACTERS ARE PROCESSED THRU THE LA30 AND KSR35 ROUTINES.
/
TTY33	LAC	TTCHAR
	SAD	(15		/CARRIAGE RETURN?
	SKP!CLA
	JMP	TTAB33		/NO,GO TO LA30 ROUTINE.
				/YES, MUST RESET COUNT
	JMP	TTSTUP		/AND PRINT CR.
/
	.EJECT
/
/THIS SECTION TESTS FOR CR AND TAB GOING TO LA30'S.
/KEEPS TRACK OF PRINT POSITION FOR TAB SIMULATION AND
/CARRIAGE RETURN DELAY COMPUTATION. KSR33'S USE THE
/TAB SIMULATION SECTION AND ENTER AT TTAB33.
/
TTLA30	LAC	TTCHAR		/GET THE CHARACTER.
	SAD	(15
	JMP	TTLACR		/CARRIAGE RETURN.
TTAB33	SAD	(11
	JMP	TTABLA		/HORIZONTAL TAB.
	SAD	(176
	JMP	TTSPC1		/THIS IS A SPACING CHAR.
	AAC	-40		/CHARACTER CODES
	SPA			/LESS THAN 40 ARE
	JMP	TTGO35		/NON-SPACING.
TTSPC1	JMS	TTSPAC		/BUMP PRINT POSITION
	1			/COUNTER BY ONE.
TTGO35	LAC	TTCHAR		/RETURN TO KSR35 ROUTINE
	JMP	TTY35		/TO PROCESS OTHER CHAR.
/
/
TTSPAC	0
	LAC	TTWD05,X	/INCREMENT PRINT
	SWHA			/POSITION COUNTER
	TAD*	TTSPAC		/BY CONTENTS OF
	SWHA			/ARGUMENT FOLLOWING
	DAC	TTWD05,X	/THE JMS INSTRUCTION.
	IDX	TTSPAC
	JMP*	TTSPAC
/
/
TTRSET	0
	LAC	TTWD05,X	/CLEAR PRINT
	AND	(000777)	/POSITION COUNTER,
	TAD	(001000)	/SET TO ONE
	DAC	TTWD05,X	/AND RESTORE.
	JMP*	TTRSET
/
	.EJECT
/
/THE TIMING CHARACTERISTICS FOR THE CARRIAGE RETURN FUNCTION
/ON THE LA30 DECWRITER OPERATING AT 300 BAUD ARE PECULIAR.
/THE WORST CASE DELAY OCCURS AT CHARACTER POSITION 12 (DECIMAL),
/DROPS OFF TO CHARACTER 20 AND THEN INCREASES MORE SLOWLY TO
/POSITION 79.
/
/NINE FILL CHARACTERS ARE REQUIRED IN THE WORST CASE;
/HOWEVER,BECAUSE TIMING CHARACTERISTICS VARY FROM UNIT TO UNIT,
/AN ALGORITHM TO FIT NUMBER OF FILLERS TO PRINT POSITION IS NOT
/PRACTICAL. THEREFORE,THIS PROGRAM USES A VALUE OF SEVEN FILLERS
/WHICH WILL WORK IN MOST CASES. IF THE TIMING OF A PARTICULAR
/DEVICE APPROACHES WORST CASE, SO THAT ERRORS CONTINUE TO APPEAR,
/THE USER SHOULD MODIFY THE LITERAL LOADED AT TT300 TO INCREASE
/THE NUMBER OF FILLERS (FILL COUNT IN BITS 6 TO 9).
/
/
/LINE POSITION = 1 TO 80.
/IF POSITION 1 THRU 16, FILLERS = POSITION/2.
/IF POSITION 17 THRU 20, FILLERS = 5.
/IF POSITION 21 THRU 80, FILLERS = (POSITION + 40.)/16.
/
/
TTLACR	LAC	TTWD06,X	/CHECK BAUD RATE.
	AND	(030000)
	SZA
	JMP	TT300		/300 BAUD, GO ADD DELAY.
	JMS	TTRSET		/110 BAUD, NO DELAY NEEDED
	JMP	TTGO35		/BUT MUST RESET PRINT
				/POSITION COUNTER.
TT300	LAC	(003400)	/PRINT 7 FILLERS.
TTSTUP	TAD	(400000)	/SET PRINTER INTERRUPT
	LMQ			/EXPECTED BIT.
	JMS	TTRSET		/RESET POSITION COUNT.
	JMP	TTSETO
/
/
/SPECIAL CASE -- HORIZONTAL TAB ON LA 30 AND KSR33 MUST BE
/SIMULATED. THIS ROUTINE CONVERTS TAB CHARACTERS TO SPACES,
/DEPENDING ON THE CARRIAGE POSITION. A TAB IS CONSIDERED TO
/BE 8 SPACES FROM THE PREVIOUS TAB. TAB STOPS ARE LOCATED
/AT POSITIONS 1,9,17,25,33,41,49,57,65 AND 73. TABS AFTER
/POSITION 73 MOVE THE CARRIAGE ONE SPACE UNTIL POSITION 80,
/THEN ARE IGNORED.
/
TTABLA	LAC	TTWD05,X	/EXTRACT PRINT
	SWHA			/POSITION COUNTER.
	AND	(000777)
	DAC	TTTMPR		/SAVE IT.
	.DEC
	AAC	-73
	SPA!CLL			/IS POSITION .GE. 73?
	JMP	TTLT73		/NO.
	AAC	-6		/YES, BUT IS
	SMA!SZA			/POSITION .GT. 79?
	JMP*	TT.OUT		/YES, SO IGNORE THE TAB.
	CLA!IAC			/NO,BUMP PRINT POSITION
	JMP	TT1SPC		/COUNTER BY ONE.
TTLT73	AAC	72		/AC=0 TO 71;L=0.
	LRS	3		/DIVIDE BY 8.
	IAC!CLL			/AC=1 TO 9 NOW.
	ALS	3		/MULTIPLY BY 8 & ADD ONE
	IAC			/TO = ABSOLUTE TAB POSITION.
	TCA
	TAD	TTTMPR		/DIFFERENCE IS NUMBER
	TCA			/OF SPACES TO PRINT
TT1SPC	DAC	TTTMPR		/TO SIMULATE TAB.
	.OCT
	LAC	(40)		/CHANGE TAB
	DAC	TTCHAR		/TO A SPACE.
	JMS	TTSPAC		/BUMP PRINT POSITION
TTTMPR	.-.			/COUNTER THIS MUCH.
	LAC	TTTMPR		/SET REPEAT COUNTER
	AAC	-1		/TO # SPACES MINUS ONE
	ALS	10		/SINCE ONE SPACE IS
	TAD	(400240)	/PRINTED DIRECTLY. SET
	LMQ			/INTERRUPT EXPECTED FLAG
	JMP	TTSETO		/AND GO PRINT.
/
	.EJECT
/
	.EJECT
/ SUBROUTINE TTSETX -- SET AUTOINCREMENT REGISTERS 12 AND 13 TO ACCESS
/ THE LINE BUFFER HEADER WORD 0.
/
/ CALLING SEQUENCE:
/
/	JMS	TTSETX
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	X12 & X13
/
TTSETX	0
	DAC	TTSETA		/SAVE THE AC.
	LAC	TTHDR0
	AAC	-1
	DAC*	(X12)
	DAC*	(X13)
	LAC	TTSETA
	JMP*	TTSETX
TTSETA	0			/TEMPORARY AC STORAGE.
/
/
/
/ SUBROUTINE TTSETT -- SET AUTOINCREMENT REGISTERS 12 AND 13 TO ACCESS THE
/ ADDRESS IN THE AC.
/
/ CALLING SEQUENCE:
/
/	ADDRESS IN THE AC
/	JMS	TTSETT
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	X12, X13 & AC
/
TTSETT	0
	AAC	-1
	DAC*	(X12)
	DAC*	(X13)
	JMP*	TTSETT
/
/ SUBROUTINE TTUINX -- SET THE TTY LOGICAL UNIT NUMBER IN THE XR.
/
/ CALLING SEQUENCE:
/
/	JMS	TTUINX
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	XR & AC
/
TTUINX	0
	LAC	TTUNIT
	PAX
	JMP*	TTUINX
 .TITLE *** TTY INTERRUPT SERVICE
/
/ FOR THE LT15 AND LT19 DEVICES, CHARACTERS RECEIVED BY
/ THE CPU TRAP VIA API CHANNEL 35 (REGISTER 75),
/ WHICH CONTAINS THE INSTRUCTION "JMS* (TTYKI)".
/
/ FOR THE LT15 AND LT19 DEVICES, COMPLETION OF TRANS-
/ MISSION OF A CHARACTER FROM THE CPU TO THE DEVICE,
/ WHICH INDICATES THAT THE DEVICE IS READY TO RE-
/ CEIVE MORE DATA, CAUSES A TRAP VIA API CHANNEL 34
/ (REGISTER 74), WHICH CONTAINS THE INSTRUCTION
/ "JMS* (TTYPI)".
/
/ THE CONSOLE TTY, WHICH IS NOT CONNECTED TO
/ THE API HARDWARE, INTERRUPTS VIA LOCATION 0
/ AS DO ALL PIC DEVICES.  THE EXECUTIVE WILL,
/ HOWEVER, SIMULATE AN API INTERRUPT SO THAT
/ THE CONSOLE TTY WILL CAUSE ENTRY TO THE
/ INTERRUPT SERVICE ROUTINES IN THE SAME MANNER
/ AS DO THE LT15 AND THE LT19.
/
/ "TTYKI" AND "TTYPI" ARE ENTERED AT API LEVEL 3.
/
/ A CONNECT DIRECTIVE IS NOT ISSUED BECAUSE THE
/ EXECUTIVE STARTS UP WITH THE TTY INTERRUPT LINES
/ ALREADY CONNECTED TO THE INTERRUPT SERVICE ROUTINES.
/
/
/ "KEYBOARD" INTERRUPT SERVICE ROUTINE
/
TTYKI	0
	DBA			/ENTER PAGE ADDRESSING MODE.
	DAC	TTIAC		/SAVE AC
	PXA
	DAC	TTIXR		/SAVE XR
	PLA
	DAC	TTILR		/SAVE LR
/
	LAC*	(TTYNUM)	/# OF TTY'S ON THIS MACHINE
	PAL
	CLX			/INITIALIZE KYBD SKIP-CHAIN LOOP
TTKSLP	XCT	TT.KSF,X	/KSF0, KSF1, ...
	SKP
	JMP	TTKFND		/"KEYBOARD" FLAG FOUND.
	AXS	+1
	JMP	TTKSLP
	JMP	TTKIGN		/SHOULD NEVER EXECUTE THIS INSTRUCTION
/
TTKFND	LAC	TT.KSF,X	/CONVERT KSF TO KRB WITH
	AAC	11		/BIT 14 SET (TO CLEAR AC).
	DAC	TT.KRB
/
/ BEFORE READING IN THE CHARACTER, CHECK IF THE
/ DEVICE IS UNIT 0 (THE CONSOLE TTY). IF SO,
/ EXECUTE "KRS" INSTEAD OF "KRB" SO THAT UNIT 0
/ IS OPERATED IN FULL DUPLEX MODE.
/
	PXA
	SZA			/SKIP IF CONSOLE TTY.
	JMP	TT.KRB
	KRS			/READ TT0 BUFFER AND
	SKP			/SELECT FULL DUPLEX MODE.
TT.KRB	XX			/READ "KEYBOARD" BUFFER.
/
/ NOTE -- THE "KEYBOARD" READ INSTRUCTION ALSO CLEARS
/ THE "KEYBOARD" FLAG.
/
	DAC	TTITMP		/SAVE 8-BIT CHARACTER TEMPORARILY.
	LAC	TTWD07,X	/IGNORE INTERRUPT IF NO PDVL NODE
	SNA			/(I.E., IF THE UNIT IS NOT KNOWN
	JMP	TTKIGN		/TO THE SYSTEM)
	LAC	TTK.EV,X	/IGNORE IT IF THE TTY'S
	SZA			/"KEYBOARD" EVENT VARIABLE
	JMP	TTKIGN		/IS NON-0.
	LAC	TTWD00,X	/IGNORE IT IF THE TTY
	SMA			/CANNOT SEND DATA TO THE CPU.
	JMP	TTKIGN		/(THIS BIT MIGHT BE CLEARED IF THE TTY WERE
				/FAULTY.)
/
	777400			/LAW 17400
	TAD	TTITMP		/IF ZERO, SET THE EVENT VARIABLE NON-0
	DAC	TTK.EV,X	/BY STORING THE CHARACTER THERE. SET
				/BITS 0-9 TO ONES IN CASE THE 8-BIT
				/CHARACTER IS 0 (FOR AN EVEN PARITY TTY).
	LAC	TTTGEV		/SET BIT 1 OF THE TRIGGER EVENT VARIABLE
	AND	(577777)	/TO INDICATE A "TTY INTERRUPT".
	TAD	(200000)
	DAC	TTTGEV
/
	.SET6			/DECLARE A SIGNIFICANT EVENT.
/
TTKIGN	LAC	TTILR
	PAL			/RESTORE LR.
	LAC	TTIXR
	PAX			/RESTORE XR.
	LAC	TTIAC		/RESTORE AC.
	DBR
	JMP*	TTYKI		/DISMISS THE INTERRUPT.
/
	.EJECT
/ TABLE OF "KEYBOARD" SKIP IOT'S.
/
TT.KSF	KSF			/KSF0 -- SKIP IF TT0 HAS A CHARACTER.
	704101			/KSF1
	704121			/KSF2
	704141			/KSF3
	704161			/KSF4
	704301			/KSF5
	704321			/KSF6
	704341			/KSF7
	704361			/KSF10
	704501			/KSF11
	704521			/KSF12
	704541			/KSF13
	704561			/KSF14
	704701			/KSF15
	704721			/KSF16
	704741			/KSF17
	704761			/KSF20
/
	.EJECT
/ "PRINTER" INTERRUPT SERVICE ROUTINE
/
TTYPI	0
	DBA			/ENTER PAGE ADDRESSING MODE.
	DAC	TTIAC		/SAVE AC
	PXA
	DAC	TTIXR		/SAVE XR
	PLA
	DAC	TTILR		/SAVE LR
/
	LAC*	(TTYNUM)	/# OF TTY'S ON THIS MACHINE.
	PAL
	CLX
TTTSLP	XCT	TT.TSF,X	/TSF0, TSF1, ...
	SKP
	JMP	TTPFND		/"PRINTER" FLAG FOUND.
	AXS	1
	JMP	TTTSLP
	JMP	TTPIGN		/SHOULD NEVER EXECUTE
				/THIS INSTRUCTION.
/
TTPFND	LAC	TT.TSF,X	/CONVERT TSF TO TCF.
	AAC	1
	DAC	.+1
	XX			/CLEAR THE "PRINTER" FLAG.
	LAC	TTWD06,X	/CHECK THIS TTY'S OUTPUT REG-
	SMA!RTL			/ISTER TO SEE IF THIS IN-
				/TERRUPT IS EXPECTED.  IF
	JMP	TTPIGN		/NOT, IGNORE IT.  IF THE
	STL			/INTERRUPT IS EXPECTED,
	RTR			/SET BIT1=1 TO INDICATE
	DAC	TTWD06,X	/THAT IT OCCURRED.
/
	LAC	TTTGEV		/SET BIT 1 OF THE TRIGGER EVENT VARIABLE
	AND	(577777)	/TO INDICATE THAT A "TTY INTERRUPT"
	TAD	(200000)	/OCCURRED.
	DAC	TTTGEV
/
	.SET6			/DECLARE A SIGNIFICANT EVENT.
/
TTPIGN	LAC	TTILR
	PAL			/RESTORE LR.
	LAC	TTIXR
	PAX			/RESTORE XR.
	LAC	TTIAC		/RESTORE AC.
	DBR
	JMP*	TTYPI		/DISMISS THE INTERRUPT.
/
	.EJECT
/ TABLE OF "PRINTER" SKIP IOT'S.
/
TT.TSF	TSF			/TSF0 -- SKIP IF TT0 "PRINTER" IS READY.
	.IFPOZ	TTYS-2
	704001			/TSF1
	.ENDC
	.IFPOZ	TTYS-3
	704021			/TSF2
	.ENDC
	.IFPOZ	TTYS-4
	704041			/TSF3
	.ENDC
	.IFPOZ	TTYS-5
	704061			/TSF4
	.ENDC
	.IFPOZ	TTYS-6
	704201			/TSF5
	.ENDC
	.IFPOZ	TTYS-7
	704221			/TSF6
	.ENDC
	.IFPOZ	TTYS-10
	704241			/TSF7
	.ENDC
	.IFPOZ	TTYS-11
	704261			/TSF10
	.ENDC
	.IFPOZ	TTYS-12
	704401			/TSF11
	.ENDC
	.IFPOZ	TTYS-13
	704421			/TSF12
	.ENDC
	.IFPOZ	TTYS-14
	704441			/TSF13
	.ENDC
	.IFPOZ	TTYS-15
	704461			/TSF14
	.ENDC
	.IFPOZ	TTYS-16
	704601			/TSF15
	.ENDC
	.IFPOZ	TTYS-17
	704621			/TSF16
	.ENDC
	.IFPOZ	TTYS-20
	704641			/TST17
	.ENDC
	.IFPOZ	TTYS-21
	704661			/TSF20
	.ENDC
/
/ THE FOLLOWING 4 REGISTERS ARE FOR USE
/ ONLY BY TTY INTERRUPT SERVICE.
/
TTIAC	0			/SAVE THE AC
TTIXR	0			/SAVE THE XR
TTILR	0			/SAVE THE LR
TTITMP	0			/TEMPORARY STORAGE
 .TITLE *** TTY TERMINAL DATA REGISTERS
/
/ EACH TTY TERMINAL HAS A SET OF DATA AND STATUS
/ REGISTERS AS DEFINED BELOW. BECAUSE IT IS CONVENIENT
/ TO USE THE INDEX REGISTER TO INDEX ACCORDING TO
/ LOGICAL TTY UNIT NUMBER, A GIVEN TTY'S REGISTERS
/ ARE NOT LOCATED CONTIGUOUSLY IN CORE. INSTEAD,
/ EACH REGISTER TYPE IS GROUPED IN ORDER OF
/ UNIT NUMBER (E.G., ALL THE POINTER'S TO THE RE-
/ QUESTOR'S EVENT VARIABLE).
/
/ WORD 0 -- STATUS REGISTER -- [TTWD00]
/
/	BIT=0 MEANS "NO"; BIT=1 MEANS "YES"
/
/	BIT 0	IS TERMINAL CAPABLE OF TRANSMITTING TO THE
/		CPU (E.G., KEYBOARD)?
/
/	BIT 1	IS TERMINAL CAPABLE OF RECEIVING DATA
/		FROM THE CPU (E.G., PRINTER)?
/
/	BIT 2	IS THIS A FULL DUPLEX TERMINAL, I.E., ONE
/		WHICH DOES NOT HAVE A LOCAL COPY
/		MECHANISM? (NOTE--THIS BIT HAS MEANING
/		ONLY IF BITS 0-1 BOTH=1).
/		<<< THIS BIT IS PRESENTLY UNUSED >>>
/
/	BIT 3	DOES THIS TERMINAL HAVE A HORIZONTAL
/		TABBING MECHANISM?  HORIZONTAL TAB STOPS
/		ARE ASSUMED TO BE 8 SPACES APART.
/		<<< THIS BIT IS PRESENTLY UNUSED >>>
/
/	BIT 4	DOES THIS TERMINAL HAVE A VERTICAL
/		TABBING MECHANISM?  VERTICAL TAB STOPS
/		ARE ASSUMED TO BE 6 LINES APART.
/		<<< THIS BIT IS PRESENTLY UNUSED >>>
/
/	BIT 5	DOES THIS TERMINAL NEED ALTMODES PRINTED?
/
/	BIT 6	DATA MODE -- 2 = IOPS ASCII; 3 = IMAGE ASCII.
/	THRU
/	8
/
/	BIT 9	CURRENT I/O FUNCTION -- 0 MEANS THAT
/	THRU	THE TTY UNIT IS FREE (IDLE).
/	17	24=ATTACH; 25=DETACH; 26=INPUT (READ);
/		27=OUTPUT (WRITE).
/
	.REPT	TTYS		/ASSEMBLE EACH TTY ASSUMING:
TTWD00	760000			/SEND, RECEIVE, FULL DUPLEX WITHOUT
				/LOCAL COPY, HAS HORIZONTAL TAB,
				/HAS VERTICAL TAB, DON'T PRINT ALTM..
/
/ WORD 1 -- REQUESTOR'S EVENT VARIABLE ADDRESS -- [TTWD01]
/		
/		IF THE REQUESTOR DID NOT GIVE AN EVENT
/		VARIABLE ADDRESS IN HIS I/O CALL, THIS
/		WORD CONTAINS ZERO.
/
	.REPT	TTYS
TTWD01	0
/
/ WORD 2 -- POINTER TO LINE BUFFER HEADER -- [TTWD02]
/
/		THIS WORD CONTAINS THE ADDRESS OF HEADER
/		WORD 0 OF THE REQUESTOR'S LINE BUFFER.
/
	.REPT	TTYS
TTWD02	0
/
/ WORD 3 -- CURRENT DATA WORD POINTER -- [TTWD03]
/
/		INITIALLY THIS WORD IS SET TO POINT
/		TWO LOCATIONS FOLLOWING LINE
/		BUFFER HEADER WORD ZERO, I.E., THE
/		FIRST DATA WORD.  AS DATA IS STORED
/		IN OR READ FROM THE LINE BUFFER,
/		THIS POINTER IS INCREMENTED ACCORDINGLY.
/		ON INPUT, IT IS ALWAYS LEFT POINTING AT
/		THE DATA WORD IN WHICH THE NEXT CHARACTER
/		IS TO BE STORED.  ON OUTPUT, IT IS LEFT
/		POINTING AT THE DATA WORD FROM WHICH
/		THE NEXT CHARACTER IS TO BE TAKEN.
/
	.REPT TTYS
TTWD03	0
/
/ WORD 4 -- BUFFER SIZE/WORD COUNT -- [TTWD04]
/
/		FOR AN INPUT (READ) COMMAND, THE
/		LINE BUFFER SIZE SPECIFIED IN THE
/		REQUESTOR'S CPB IS STORED HERE.
/		3 .LE. BUFFER SIZE .LE. 776.
/		THE SIZE MUST BE AT LEAST 3 TO
/		ACCOUNT FOR 1 DATA WORD AND
/		2 HEADER WORDS. SHOULD THE SIZE
/		EXCEED 776, IT IS STORED AS 776
/		SINCE 377 IS THE LARGEST RECORD-
/		ABLE WORD PAIR COUNT.
/
/		PRIOR TO THESE TESTS, IF THE
/		INPUT DATA MODE IS IOPS ASCII,
/		THE BUFFER SIZE IS TRUNCATED
/		TO AN EVEN NUMBER.
/
/		FOR AN OUTPUT (WRITE) COMMAND IN IOPS ASCII, THIS WORD
/		IS USED AS A LIMIT COUNT. OUTPUT IS NORMALLY TERMINATED
/		WHEN A CARRIAGE RETURN OR ALTMODE CHARACTER
/		IS ENCOUNTERED (OR WHEN THE LINE BUFFER OVERFLOWS).
/
/		FOR IMAGE ASCII OUTPUT, THE WORD PAIR COUNT
/		IS TAKEN FROM THE LINE BUFFER HEADER AND
/		IS STORED HERE AS A NEGATIVE (2'S COMPLE-
/		MENT) WORD COUNT.  THE RESULTING WORD COUNT
/		IS VALIDATED TO INSURE THAT IT IS 3
/		OR MORE.
/
	.REPT	TTYS
TTWD04	0
/
/ WORD 5 -- STATUS REGISTER -- [TTWD05]
/
/	BIT 0	 PRINT HEAD HORIZONTAL POSITION COUNTER.
/	THRU
/	8
/
/	BIT 9	TERMINAL DEVICE TYPE:
/	AND		00=KSR35
/	10		01=KSR33
/			10=LA30
/			11=VT05
/	BIT 12	SET=1 BY THE ABORT CODE (WHEN A "PRINTER" INTERRUPT FOR
/		THIS TTY IS EXPECTED BUT HASN'T YET OCCURRED) TO SIGNAL
/		THE I/O DONE CODE NOT TO DECREMENT THE I/O PENDING COUNT,
/		NOT TO SET THE REQUESTER'S EVENT VARIABLE, NOT TO RETURN
/		THE I/O REQUEST NODE, OR IN ANY WAY MODIFY THE TASK'S
/		PARTITION OR PARTITION BLOCK NODE.
/
/	BIT 13	SET=1 AFTER AN IOPS ASCII INPUT OR OUTPUT LINE IS
/		TERMINATED (NORMALLY OR NOT) BY A CARRIAGE
/		RETURN TO INDICATE THAT THE CARRIAGE IS
/		IN POSITION TO DO AN OVERPRINT. OVERPRINT
/		IS DONE ONLY FOR IOPS ASCII WRITE; THERE-
/		FORE, OTHER FUNCTIONS MUST TEST THIS BIT
/		AND SUPPLY THE MATCHING LINE FEED IF
/		NECESSARY.
/
/	BIT 14	WHEN THE CURRENT I/O REQUEST IS COMPLETED,
/		SHOULD THE REQUESTOR'S EVENT VARIABLE BE
/		SET TO +2 RATHER THAN +1 IF SUCCESSFUL?
/		0=NO; 1=YES.
/
/	BIT 15	IOPS ASCII BYTE COUNT -- 0=CHARACTER 1,
/	THRU	1=CHARACTER 2, ... , 4=CHARACTER 5.  THE
/	17	COUNT IS ALWAYS SET FOR THE NEXT STORAGE
/		POSITION (ON INPUT) OR THE NEXT CHARAC-
/		TER TO BE "PRINTED" (ON OUTPUT).
/
	.REPT	TTYS
TTWD05	0
/
/ WORD 6 -- OUTPUT REGISTER -- [TTWD06]
/
/	BIT 0	SET TO 1 IF THE TTY IS EXPECTING AN
/		INTERRUPT FROM ITS "PRINTER".
/
/	BIT 1	SET TO 1 BY THE INTERRUPT SERVICE (ONLY
/		IF BIT 0=1) TO INDICATE THAT THE "PRINTER"
/		INTERRUPT OCCURRED.
/
/	BIT 2	SET TO 1 WHEN THE CURRENT I/O REQUEST
/		IS COMPLETE EXCEPT FOR THE "PRINTING"
/		TO BE DONE AS SPECIFIED IN THIS REGISTER.
/
/	BIT 3	SET TO 1 WHEN CTRL U HAS BEEN "TYPED
/		IN" TO ABORT THE "PRINTING" OF THE
/		REMAINDER OF THIS "OUTPUT" REQUEST.  THIS
/		WILL CAUSE CARRIAGE RETURN TO BE "PRINTED".
/
/	BIT 4	TERMINAL BAUD RATE:
/	AND 5		VT05:	00	<600 BAUD
/				01	 600  "
/				10	1200  "
/				11	2400  "
/
/			LA30:	00	<300 BAUD
/				01	 300   "
/
/
/	BIT 6	REPEAT COUNT -- INDICATES HOW MANY
/	THRU	TIMES THE CHARACTER IN BITS 10-17
/	9	IS TO BE "PRINTED".
/
/	BIT 10	8-BIT ASCII CHARACTER -- EVEN PARITY --
/	THRU	USUALLY NULL (FILLER CHARACTERS) TO PROVIDE
/	17	A TIMING DELAY.
/
	.REPT	TTYS
TTWD06	0
/
/ WORD 7 -- REQUEST QUEUE POINTER -- [TTWD07]
/
/		ADDRESS OF THE FIRST WORD (HEAD) OF THE TTY'S
/		I/O REQUEST QUEUE, WHICH BEGINS IN THE TTY'S
/		PHYSICAL DEVICE LIST (PDVL) NODE.
/
TTWD07	TT0DQ			/TT0 ALWAYS EXISTS.
	.REPT	20		/THE REMAINING ENTRIES ARE SET BY THE
	0			/SYSTEM CONFIGURATION ROUTINE WHEN THE
				/CORRESPONDING PDVL NODES ARE GENERATED.
				/A ZERO ENTRY IMPLIES NO PDVL NODE.
/
/ WORD 8 -- "KEYBOARD" EVENT VARIABLE -- [TTK.EV]
/
/		THE WORD IS SET=0 WHEN THERE IS NO
/		"KEYBOARD" INPUT FOR THIS UNIT. WHEN A
/		CHARACTER HAS BEEN READ BY THE INTER-
/		RUPT SERVICE ROUTINE, THE 8 BITS ARE
/		STORED RIGHT-JUSTIFIED IN THE EVENT
/		VARIABLE AND THE REMAINDER OF THE
/		WORD IS SET TO ONES (IN CASE A
/		NULL CHARACTER (0) IS INPUT ON
/		AN EVEN PARITY TTY).
/
	.REPT	TTYS
TTK.EV	0
/
/ WORD 9 -- I/O REQUEST NODE ADDRESS -- [TTWD09]
/
	.REPT	TTYS
TTWD09	0
/
	.EJECT
/
/ TTY "SHORT PARTITION BLOCK" (FOR REGISTER SAVE USE ONLY)
/
TTYIC	0			/TTYIC = PARTITION BLOCK
	DBA			/ADDRESS PLUS AN OFFSET.
	JMS*	(SAVE)
	.REPT	PBIB
	0
	SKP
	.REPT	PBMM
	0
	.REPT	PBFP
	0
/
/ ACTIVE TASK LIST NODE
/
TTY	IORD			/FORWARD LINKAGE
	DSA			/BACKWARD LINKAGE
	.SIXBT	"TTY"		/TASK NAME (FIRST HALF)
	0			/TASK NAME (SECOND HALF)
	1			/TASK PRIORITY
	TTYIC-P.IC		/PARTITION BLOCK ADDRESS
	0			/STL NODE ADRESS (NONE)
	4			/TASK STATUS (INITIALLY READY FOR RESUMPTION)
	TTYTW			/RESUMPTION ADDRESS
	0			/EVENT VARIABLE ADDRESS
	.IFPNZ	NDSZMT
	.REPT	NDSZMT
	0
	.ENDC
/
/ PHYSICAL DEVICE LIST NODE FOR TT-0
/
TT00	PDVL			/FORWARD LINKAGE
	DSK0			/BACKWARD LINKAGE
	.SIXBT	"TT@"		/DEVICE NAME (FIRST HALF)
	0			/DEVICE NAME (SECOND HALF)
	0			/DEVICE ATTACH FLAG
	0			/UNIT NUMBER
TT0DQ	.			/REQUEST QUEUE (FORWARD LINKAGE)
	.-1			/REQUEST QUEUE (BACKWARD LINKAGE)
	TTTGEV			/TRIGGER EVENT VARIABLE ADDRESS
	0			/(UNUSED)
/
TTUNIT	0			/LOGICAL TTY UNIT NUMBER.
TTTGEV	0			/TTY TRIGGER EVENT VARIABLE.
				/BIT 0 IS SET BY THE "QUEUE I/O" DIRECTIVE.
				/BIT 1 IS SET BY TTY'S INTERRUPT SERVICE.
				/BIT 2 IS SET BY I/O RUNDOWN TASK WHEN
				/IT HAS QUEUED AN "ABORT" REQUEST.
TTCHAR	0			/7-BIT INPUT OR OUTPUT CHARACTER.
				/BITS 0-10 MUST ALWAYS BE 0.
TTHDR0	0			/ADDRESS OF HEADER WORD 0 IN THE
				/REQUESTOR'S LINE BUFFER.
TTTEMP	0			/TEMPORARY STORAGE.
TTPCNT	0			/COUNTER USED WHEN COMPUTING
				/OUTPUT CHARACTER PARITY.
TTCHR1	0			/SET NON-0 TO INDICATE TO THE IOPS
				/ASCII WRITE ROUTINE THAT IT IS
				/DEALING WITH THE FIRST CHARACTER
				/IN THE LINE BUFFER.
TTABNA	0			/ADDRESS OF THE "ABORT" I/O REQUEST NODE.
TTABSN	0			/STL NODE ADDRESS OF THE ABORTING TASK.
TTRDEV	0			/ADDRESS OF THE I/O RUNDOWN TASK'S EVENT
				/VARIABLE.
TTXADJ	.&70000\777777+1	/INDEX REGISTER ADJUSTMENT FACTOR -- TWOS
				/COMPLEMENT OF THE PAGE BITS OF THE PAGE
				/IN WHICH THIS CODE RESIDES -- CANCELS
				/OUT THE PAGE BITS ADDED BY THE HARDWARE
				/ON INDEXED MEMORY REFERENCE INSTRUCTIONS.
/
	.LST
	.IFDEF	L.SEL
	.NOLST
	.ENDC
/
	.LTORG
/
	.TITLE *** ADDITIONAL EMPTY POOL
/
/ FILL REMAINDER OF PAGE ONE WITH NODES BUT
/ LEAVE ENOUGH SPACE OF TABLES.
/
	.DEFIN	EN
	.IFDEF	USRTAB
TABSIZ=3*NLU+USRTAB		/SIZE OF LUT,AFT,LUN-UFD, AND USER-TABLE
	.ENDC
	.IFUND	USRTAB
TABSIZ=3*NLU
	.ENDC
TOPEX=16100+TABSIZ+377&777400	/TOP OF EXEC ROUNDED TO 400 OCTAL
TOPNOD=TOPEX-TABSIZ		/TOP OF NODE SPACE IN PAGE 1
	.IFPOZ	TOPNOD-NDSZ-NDSZ-.
	.+NDSZ
	.-1-NDSZ
	.REPT	NDSZM2
	0
	.ENDC
	.ENDM
/
PG1NB=.
/
BPLPG1	.+NDSZ
	EPLPG0
	.REPT	NDSZM2
	0
/
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
	EN
/
EPL	POOL
	.-1-NDSZ
	.REPT	NDSZM2
	0
/
PG1NE=.-1
/
	.LST
	.IFUND L.LUN
	.NOLST
	.ENDC
 .TITLE *** LOGICAL UNIT TABLE
/
/ LOGICAL I/O UNITS ARE EQUIVALENCED TO PHYSICAL UNITS VIA THIS TABLE.
/ EACH LOGICAL UNIT IS REPRESENTED BY A ONE-WORD ENTRY IN THIS TABLE,
/ WITH THE FIRST WORD REPRESENTING LOGICAL UNIT NUMBER (LUN) ONE.
/ EACH PHYSICAL UNIT IS REPRESENTED BY A NODE IN THE PHYSICAL DEVICE
/ LIST (PDVL).
/
/ WHENEVER A LOGICAL UNIT NUMBER IS ASSIGNED TO A PHYSICAL UNIT, THE
/ CORESPONDING TABLE ENTRY IS SET TO THE ADDRESS OF THE PDVL NODE.
/
/ WHENEVER A LOGICAL UNIT NUMBER IS NOT ASSIGNED TO A PHYSICAL UNIT
/ (ASSIGNED TO 'NONE"), THE CORESPONDING TABLE ENTRY IS SET TO ZERO.
/
	.DEC
NLUM21=NLU-21		/INITIAL DEVICE ASSIGNMENTS:
	.OCT		/
LUT	DSK0		/LUN 1 -- DISK DRIVER
	TT00		/LUN 2 -- TTY 0
	TT00		/LUN 3 -- TTY 0
	TT00		/LUN 4 -- TTY 0
	0		/LUN 5 -- NONE
	0		/LUN 6 -- NONE
	0		/LUN 7 -- NONE
	0		/LUN 8 -- NONE
	0		/LUN 9 -- NONE
	0		/LUN 10 -- NONE
	0		/LUN 11 -- NONE
	TT00		/LUN 12 -- TTY 0
	TT00		/LUN 13 -- TTY 0
	TT00		/LUN 14 -- TTY 0
	0		/LUN 15 -- NONE
	TT00		/LUN 16 -- TTY 0
	0		/LUN 17 -- NONE
	0		/LUN 18 -- NONE
	0		/LUN 19 -- NONE
	TT00		/LUN 20 -- TTY 0
	TT00		/LUN 21 -- TTY 0
	.REPT NLUM21	/ALL OTHERS -- NONE
	0
/
	.TITLE *** LUN - UFD TABLE ***
/
/ THIS TABLE RELATES A UFD NAME WITH A DISK-LUN PAIR.
/ THE TABLE IS ACCESSED BY MNT, DSM, REA, AND THE DISK
/ FILES HANDLERS. IF A LUN IS NOT ASSOCIATED WITH A DISK
/ THIS TABLE HAS NO INFORMATION. HOWEVER, WHENEVER A LUN
/ IS ASSIGNED TO A DISK AND THE DISK IS MOUNTED, THEN THE
/ LUN UFD TABLE ENTRY GIVES THE FILES HANDLER THE UFD TO
/ BE USED FOR THAT LUN-DISK PAIR.
/
LUNUFD=.
	.REPT	NLU	/NUMBER OF LUNS = NLU
	0
/
 .TITLE *** ATTACH FLAG TABLE
/
/ THIS TABLE CONSISTS OF A ONE-WORD ENTRY FOR EACH LOGICAL UNIT,
/ AND IS USED TO INDICATE WHETHER A LUN IS ATTACHED OR UNATTACHED
/ TO A TASK.
/
/ WHENEVER A LUN IS ATTACHED TO A TASK, ITS ENTRY IS SET TO THE
/ TASK'S STL NODE ADDRESS.
/
/ WHENEVER A LUN IS NOT ATTACHED TO A TASK, ITS ENTRY IS SET
/ TO ZERO.
/
	.REPT	NLU
AFT	0
	.TITLE *** USER I.D. TABLE ***
/
/ THIS TABLE IS CURRENTLY UNUSED IN RSX
/
USERT=.
	.IFDEF	USRTAB
	.REPT	USRTAB
	0
	.ENDC
/
	.LST
	.IFUND	L.SCF
	.NOLST
	.ENDC
 .TITLE *** SYSTEM CONFIGURATION TASK
/
/
/
	.LOC 50020
/
SCFBEG=.		/BEGINNING OF SCF
/
/ THE SYSTEM CONFIGURATION ROUTINE IS AN ACTIVE TASK THAT IS
/ LOADED INTO CORE ONLY UPON A COLD START BOOTSTRAP. IT RUNS 
/ WITHOUT REGARD TO CORE PARTITIONS (THEY ARE NOT DEFINED
/ AT SYSTEM CONFIGURATION INITIATION) AND REMOVES ITSELF FROM
/ THE SYSTEM UPON COMPLETION OF SYSTEM CONFIGURATION.
/
/ XVM/RSX HAS DYNAMIC REPARTITIONING. THE SYSTEM CONFIGURATOR
/ MUST MERELY SET UP SOME DEFAULT SYSTEM TO GET RUNNING.  THE USER
/ CAN LATER CHANGE TO A SPECIFIC CORE LAYOUT OF HIS CHOICE.
/ THE DEFAULT SYSTEM LIST IS AT 'PARPNT'.  THE SAME HOLD TRUE
/ FOR DEVICES; THEIR DEFAULT LIST IS AT 'DEVPNT'.  IN ORDER TO ALLOW
/ DYNAMIC RECONFIGURATION, NODES MUST NOW BE OF TWO TYPES, SMALL
/ (SAME AL ALWAYS) AND LARGE (FOR PBDL).  THE POOL OF LARGE NODES
/ IS CALLED 'LPOOL'.  FUTHERMORE, NODES MUST BE CONSTRUCTED IN
/ PARTITIONS RATHER THAN IN ALL THE NOOKS AND CRANNIES TO ALLOW
/ FOR CHANGING THE CORE LAYOUT ON THE FLY.  WE WILL ASK THE SCF
/ TERMINAL OPERATOR TO DEFINE THE MINIMUM NUMBER OF SMALL AND LARGE
/ NODES NEEDED.
/
/ WARNING: NODES CAN ALWAYS BE ADDED LATER BUT NEVER DELETED!!
/
/ EACH PARTITION IN THE SYSTEM MUST HAVE A LARGE NODE FOR THE PBDL.
/ LARGE NODES FIT 5 PER 400 OCTAL WORD BLOCK OF A LARGE NODE PAR-
/ TITION IF THE SYSTEM HAS FLOATING POINT HARDWARE (6/400 WORD BLOCK
/ IF FLOATING POINT IS NOT ON THE SYSTEM).  SMALL NODES FIT 25 PER
/ 400 OCTAL WORD BLOCK OF A SMALL NODE PARTITION.
/
/
/ AFTER THE POOL AND PARTITION BLOCKS HAVE BEEN CONSTRUCTED, ALL 
/ TASKS RECORDED ON SYS. DSK THAT CAN BE INSTALLED INTO THE NEWLY
/ CONFIGURED SYSTEM, ARE INSTALLED.  NORMALLY THE MCR & I/O 
/ HANDLER TASKS ARE INITIALLY INSTALLED AT THIS TIME.  AT LEAST
/ "INSTALL", "REASSIGN", AND AN I/O HANDLER MUST BE INSTALLED
/ DURING SYSTEM CONFIGURATION FOR SYSTEM DEVELOPMENT TO CONTINUE.
/
/ AFTER INSTALLATION FROM SYS. DSK, THE NUMBER OF EMPTY NODES IN THE
/ POOL IS TYPED OUT, AND THE SYSTEM IS LEFT RUNNING.
/
/
	.EJECT
/
SCONF	SKP		/MUST START HERE, BUT WANT SCF000 EASILY ACCESSIBLE
SCF000	TTYS		/SO USER CAN PATCH IT, OR KEY IN NEW VALUE
	JMS	CRTN
	JMS	CRTN
	JMS	CRTN
	JMS*	(TYPE)
	MES500
	JMS*	(TYPE
	MES577
	JMS*	(TYPE
	MES578
/
/INITIALIZE VALUES
/
	LAC	PARPNS
	DAC	PARPNT	/POINTER TO PARTITION LIST
	LAC	DEVPNS
	DAC	DEVPNT	/POINTER TO DEVICE LIST
	CLL		/CALCULATE THE TOP OF THE EXEC, I.E.
	LAC	(NLU	/1ST LOCATION ABOVE IT. MULTIPLY BY
	MUL		/THE NUMBER OF LUNS TIMES 3 (THREE TABLES)
	3
	LACQ		/THEN ADD THE SIZE OF THE USRTAB
	.IFDEF	USRTAB
	TAD	(USRTAB
	.ENDC
	TAD	(16100	/ADD THE END OF ALL EXEC CODE
	AAC	377	/ROUTND UP TO NEXT 400 WORD BLOCK
	AND	(777400
	DAC*	(XSIZE	/SAVE THIS VALUE
	DAC	SCFCOR	/DEFAULT VALUE TOP OF EXEC
	CLX
	LAC	(21
	PAL
	DZM	SCFSYF,X /ZERO ALL DISK DEVICES
	AXS	1
	JMP	.-2
/
/ TEST FOR THE "RE-ENTRANT ECO PACKAGE" -- I.E., CHECK THE '.INH'
/ AND '.ENB' INSTRUCTIONS AND THE INTERRUPT-FREE PERIOD FOLLOWING
/ A 'JMS' INSTRUCTION
/
	.INH		/INHIBIT INTERRUPTS IF ECO EXISTS
	LAC	(402000)/TRIGGER AN API-5 INTERRUPT
	ISA
	NOP
/
/ IF NOT INHIBITED, CONTROL WILL BE TRANSFERRED TO 'SCF1' AT THIS POINT.
/
	NOP		/(IN CASE OF SLOW API)
	NOP
	LAC	(SCF2)	/LOAD AC WITH NEW API-5 TRANSFER VECTOR
	.ENB		/ENABLE INTERRUPTS (INTERRUPT FREE INST AFTER IOT)
	JMS	.+1
	0
/
/ IF NO FREE PERIOD AFTER 'JMS', CONTROL WILL BE TRANSFERRED TO 'SCF1'
/
	DAC*	(ITVTB+1)/SET NEW API-5 TRANSFER VECTOR
/
/ INTERRUPT SHOULD OCCUR AT THIS TIME, RESULTING IN A TRANSFER TO 'SCF2'
/
	JMP	.
/
SCF1	DBK		/RE-ENTRANT ECO PKG NOT PRESENT, DEBREAK FROM API-5,
	JMS*	(TYPE)	/TYPE ERR MESSAGE, AND ABORT SYSTEM CONFIGURATION.
	MES598
	HLT
	JMP	.-1
/
SCF2	DBK		/RE-ENTRANT ECO PKG EXISTS, DEBREAK FROM API-5,
	LAC	(DBK)	/SET A DEBREAK INSTRUCTION IN THE API-5 TRAP
	DAC*	(L41)	/LOCATION, AND CLEAR TRANSFER VECTOR.
	DZM*	(ITVTB+1)
/
	FPT		/DOES FLOATING POINT HARDWARE EXIST?
	JMP	.+3	/NO -- LEAVE SWITCH RESET (NOP)
	LAC	(SKP)	/YES -- SET SWITCH (SKP)
	DAC*	(FPHDWE)
/
/ TEST FOR THE EXISTENCE OF THE KM15 AND KT15 HARDWARE.
/
	IOF		/PREVENT INTERRUPTS
	CAF
	LAC*	(21)	/SAVE "JMP CALDSP" INSTRUCTION.
	DAC	SCFTMP
	DZM*	(R2)	/CLEAR "PROTECT BUT NO RELOCATE" FLAG.
	LAC	(620101)/JMP* R1
	DAC*	(21)	/SET UP LOCATION 21 TO RETURN TO SCF.
	LAC	(SCFPRC)
	DAC*	(R1)
	MPEU		/ENTER USER MODE.
	NOP		/WAIT FOR USER MODE (NOT SURE THIS IS NEEDED).
	LAS		/VIOLATE PROTECTION.
SCFTPA	JMP	SCNOPR	/NO PROTECTION FOUND.
SCFPRC	LAC*	(20)	/RELOCATE?
	AND	(77777)
	SAD	(SCFTPA)
	JMP	SCNORL	/NO, JUST PROTECT.
	LAC	(SKP)	/CHANGE NOP INTO SKP TO INDICATE THAT THIS
	DAC*	(PRHDWE)/MACHINE HAS PROTECT/RELOCATE.
	SKP
SCNORL	IDX*	(R2)	/INDICATE PROTECT BUT NO RELOCATE.
SCNOPR	LAC	SCFTMP
	DAC*	(21)	/RESTORE LOCATION 21.
	CAF		/CLEAR PROTECT FLAGS AND API.
	ION		/TURN PIC BACK ON.
	LAC	(400001)/TURN API BACK ON AND RAISE TO TASK LEVEL (API-7)
	ISA
	LAC*	(R2)	/PROTECT BUT NO RELOCATE?
	SNA
	JMP	SCF4	/NO.
	JMS	CRTN
	JMS*	(TYPE)	/TYPE "*** IF YOU HAVE KT15 (MEMORY RELOCATE) THE
	MES498
	JMS*	(TYPE)	/      *** PROTECT/RELOCATE SWITCH IS SET WRONG
	MES499
/
SCF4	LAC	(PBSZ)	/ESTABLISH PARTITION BLOCK SIZE 'SCFPBZ'
	XCT*	(FPHDWE)
	AAC	-PBFP
	DAC	SCFPBZ
	KRS		/SELECT TT0 FOR FULL DUPLEX MODE.
/
/ACCEPT CLOCK FREQUENCY
/
SCF10	JMS	CRTN	/REQUEST CLOCK TICKS PER SECOND
	JMS*	(TYPE
	MES504
SCF41	JMS	SCIFAC
	JMS	FACSV	/GET NEXT CHAR
	JMS	TCX	/CR OR ALTM?
	JMP	SCF41A	/YES -- USE DEFAULT
	JMS	ADECKI	/ASSEMBLE DECIAML CONSTANT
	JMS	TCX	/CR OR ALTM. TERMINATOR?
	SKP		/YES
	JMP	SCF48	/NO -- ERROR
	PLA		/IS VALUE BETWEEN 1CPS AND 1KC?
	JMS	COMP
	.DEC
	(1
	(1000
	.OCT
	JMP	SCF49	/NO -- ERROR
SCF41B	DAC*	(TPS	/YES -- STORE THE DATA AWAY
	DAC*	(TPX1
	DAC*	(TPX2
	DAC*	(TPX3
	DAC*	(NTSCSE
	TCA
	DAC*	(CTPS
	LAW	-1	/TURN ON THE CLOCK
	DAC*	(7
	CLON
	JMP	SCF50
/
SCF41A	LAC	(D60	/PUT DEFAULT CLOCK TICKS INTO AC (60 DECIMAL)
	JMP	SCF41B	/CONTINUE
/
SCF48	JMS	SCERR	/TYPE SYNTAX ERROR AND RETRY
	JMP	SCF41
/
SCF49	JMS*	(TYPE	/TYPE INVALID NUMBER ERROR
	MES593		/MESSAGE AND RETRY
	JMP	SCF41
/
/ ACCEPT SIZE OF CORE
/
SCF50	JMS	CRTN	/REQUEST CORE SIZE
	JMS*	(TYPE)
	MES501
SCF11	JMS	SCIFAC
	JMS	FACSV
	JMS	TCX	/EMPTY LINE
	JMP	SCF13	/YES, DEFAULT TO 32K
/
	JMS	ADECKI	/ASSEMBLE DECIMAL CONSTANT
	SAD	(113)	/"K" TERMINATED?
	SKP
	JMP	SCF18	/NO -- SYNTAX ERR
	JMS	FACSV	/YES -- END OF INPUT LINE?
	JMS	TCX
	SKP
	JMP	SCF18	/NO -- SYNTAX ERR
	PLA		/YES -- IS NUMBER BETWEEN 24 & 128?
	JMS	COMP
	.DEC
	(24
	(128)
	.OCT
	JMP	SCF19	/NO -- INVALID SIZE
SCF12	DAC	SCFT3	/YES, IS IT A MULTIPLE OF 4
	AND	(777774)
	SAD	SCFT3
	SKP
	JMP	SCF19	/NO -- INVALID SIZE
	CLQ		/YES -- SET 'CSIZE' IN SCOM
	LLS	12	/(ALSO SETUP DUMMY NODE IN DEQUE
	DAC	SCFT4	/HOLD LIMIT+1
	AAC	-1	/TO SORT ALLOCATED BLOCKS OF CORE.)
	DAC*	(CSIZE)
/
/
/ ADJUST SIZE OF TDV PARTITION IF CORE SIZE IS 24K OR 28K
/
/
	LAC	(710000	/CONSTANTS OF -28K
	TAD	SCFT4	/ADD IN TOTAL CORE
	SMA!SZA		/SKIP IF LESS THAN 32K
	JMP	SCF17	/32K, LEAVE AS IS
	SZA		/CORE SIZE IS 28K?
	LAC	(-10000	/NO -- 24K
	TAD	(30000	/YES
	DAC	SCFPST
/
/
/  NOW ADJUST HOW MANY PARTITIONS >32K
/
SCF17	LAW	-1
	TAD	SCFT3
	CLL!RAR
	RTR
	AND	(14
	PAX
	LAW	-1
	DAC	SCFEND,X
	LAC	SCFEND-2,X
	CMA!IAC
	TAD	SCFT4
	DAC	SCFEND-1,X
	JMP	SCF192
/
SCF13	LAC	(40	/DEFAULT 32K
	JMP	SCF12	/REJOIN EVERYONE ELSE
/
/
SCF18	JMS	SCERR	/TYPE SYNTAX ERR MESS & RETRY
	JMP	SCF11
SCF19	JMS*	(TYPE)	/TYPE SIZE ERR MESS & RETRY
	MES592
	JMP	SCF11
/
/
/  ASK USER FOR SIZE OF MCR PARTITION
/
/  DEFAULT 3000(8), MAXIMUM 3000(8), MINIMUM 0 (I.E. NONE)
/
SCF192	JMS	CRTN
	JMS*	(TYPE
	MES536
SCF193	JMS	SCIFAC
	JMS	FACSV
	JMS	TCX	/EMTPY LINE?
	JMP	SCF20	/YES, DEFAULT, DO NOTHING
	JMS	AOCTKI	/MAKE OCTAL CONTANT IN LIMIT REG.
	JMS	TCX	/SHOULD BE NO ADDNT'L CHAR'S
	SKP		/SKIP OK
	JMP	SCF198	/SYNTAX ERROR
	PLA		/GET BACK NUMBER FOR LIMIT CHECK
	JMS	COMP
	(0
	(3000
	JMP	SCF199	/OUT OF RANGE
	SAD	(3000	/MAXIMUM? (ALSO DEFAULT)
	JMP	SCF20	/IS DEFAULT, DO NOTHING
	DAC	SCFT4	/SAVE WHILE DO DIVISIBLE BY 400 CHECK
	AND	(777400	/DIVISIBLE BY 400 IF SAME BEFORE+ AFTER
	SAD	SCFT4
	SKP		/SAME, OK
	JMP	SCF199	/SIZE ERROR
	DAC	SCFPSM	/PLACE IN SIZE OF MCR PARTITION
	TCA		/SUBTRACT THIS FROM 3000
	TAD	(3000	/TO GET SIZE OF MISC1
	SNA		/IS RESULT>0?
	JMP	SCF20	/NO -- PROCEED
	DAC	SCFPSB	/YES -- SAVE THE SIZE  OF MISC1
	LAC	(30000	/GET BASE OF MISC1
	TAD	SCFPSM	/ADD BASE OF MCR PLUS SIZE OF MCR
	DAC	SCFPBB	/TO GET BASE OF MISC1
	JMP	SCF20	/GO FIND OUT ABOUT SYSTEM DISK
SCF198	JMS	SCERR	/SYNTAX ERROR + RETRY
	JMP	SCF193
SCF199	JMS*	(TYPE	/SIZE ERROR
	MES592
	JMP	SCF193	/RETRY
/
/  
/
/
/  IN THIS SECTION OBTAIN SYSTEM DISK, AND AMOUNT OF EACH
/  OF THE THREE TYPES OF DISK.
/
SCF20	JMS	CRTN
	JMS*	(TYPE
	MES532
SCF201	JMS	SCIFAC
	JMS	FACSV
	JMS	TCX	/MT LINE
	JMP	SCF203	/YES, DEFAULT TO RF, GO TO ITS SETUP
	SAD	(122	/'R'?
	SKP		/YES
	JMP	SCF202	/NO, SYTAX
	JMS	FACSV	/GET NEXT
	SAD	(106	/'F'?
SCF203	JMP	SCF20F	/GO SET UP RF
	SAD	(120	/'P'?
	JMP	SCF20P	/GO SET UP RP
	SAD	(113	/'K'?
	JMP	SCF20K	/GO SET UP RK
	JMP	SCF202	/ILLEGAL SYNTAX
/
SCF20F	LAC	(106	/INCASE DEFAULT HERE, NOT ON FINDING 'F'
	JMS	SCFION	/MAKE PARTITION NAME FOR SYSTEM DISK
	AAC	2	/MAKE A 2;SCFION MADE AC=0
	DAC*	(SYSDSK	/RSX SYSTEM DISK TYPE
	LAW	-1
	DAC	SCFDSK	/SET UP OUR! SYSDISK INDICATOR
	LAC	(25000	/RF HANDLER ONLY TAKES 3000
	DAC	SCFPB0	/SO START IT AT 25000
	LAC	(3000	/ALSO REDUCE SIZE OF 'RFDISK'
	DAC	SCFPS0
	JMP	SCF204	/REJOIN LOOP TO GET # OF EACH DISK TYPE
/
/
SCF20P	JMS	SCFION	/MAKE SYSTEM DISK PARTITION NAME
	AAC	3	/MAKE SYSTEM DISK TYPE; AC=0
	DAC*	(SYSDSK
	DZM	SCFDSK	/OUR WHICH DISK CODE FOR RP
	JMP	SCF204	/REJOOIN
/
/
SCF20K	JMS	SCFION	/MAKE SYSTEM DISK PARTITION NAME
	AAC	24	/RSX SYSTEM DISK INDICATOR;AC=0
	DAC*	(SYSDSK
	CLA!IAC
	DAC	SCFDSK
	JMP	SCF204
/
/  ROUTINE TO MAKE NAME R?DISK FOR SYSTEM DISK PARTITION
/  CALL WITH ASCII CHAR IN AC TO REPLACE THE ?
/
SCFION	0
	LLS	6
	AND	(7700
	TAD	(220004	/'R@D'
	DAC	SCFPN0
	CLA		/FOR CALLER'S CONVENIENCE
	JMP*	SCFION
/
/
/  ROUTINE TO FIND BLOCK OF 'RSX' UFD ON SYSTEM DISK
/
SCF20C	LAC	SCFDSK	/OUR DISK TYPE
	SNA!CLA		/SKIP UNLESS RP DISK.CLEAR AC FOR TAD'S
	TAD	(45041	/47040-1777;MAKE RP BLOCK # 47040
	TAD	(1777	/1777 IS BLOCK # FOR RF AND RK
SCF20D	JMS	CONV	/CONVERT BLOCK # TO ADDR. FOR CAL
	CAL	DOTGET	/BRING IN MFD BLOCK
	JMS	.WFDP	/WAIT FOR COMPLETION
	LAC	(DBUF	/STARTING ADDR OF BUFFER
	JMS	SETXR	/CORRECTED XR FOR SCAN OF MFD FOR 'RSX'
	AAC	374	/LOOP CONTROL
	PAL		/
SCF20E	LAC	0,X	/FOUR WORD UFD ENTRIES; NAME FIRST
	SAD	(222330	/COMPARE TO 'RSX' IN SIXBIT
	JMP	SCF20G	/YES, GOT IT!
	AXS	4	/NOPE, GO TRY NEXT ONE
	JMP	SCF20E
	LAC	3,X	/RAN OUT OF BLOCK, IS THERE ANOTHER ONE?
	SAD	(-1	/IF -1, NO MORE
	JMP	SCF20X	/NO MORE, NO 'RSX', ERROR EXIT
	JMP	SCF20D	/GO BRING IN NEW BLOCK AND KEEP GOING
/
SCF20G	LAC	1,X	/GET UFD BLOCK
	DAC	SCFUFD	/AND SAVE
	LAC*	(SYSDSK	/WHAT IS THE SYSTEM DISK?
	SAD	(3	/RP?
	JMP	SCF20N	/YES
	SAD	(2	/NO -- RF?
	JMP	SCF20M	/YES
	LAC	(10	/NO -- RK (GET OFFSET OF DISK-UFD TABLE)
	SKP
SCF20N	CLA		/RP -- GET OFFSET OF DISK-UFD TABLE
	SKP
SCF20M	LAC	(20	/RF -- GET OFFSET OF DISK-UFD TABLE
	TAD*	(DUFD1	/ADD START OF DISK-UFD TABLE
	JMS	SETXR	/PREPARE XR TO ACCESS TABLE ENTRY FOR SYSTEM DISK
	LAC	(222330	/GET 'RSX" IN SIXBT (NAME OF DEFAULT UFD FOR SYSDSK
	DAC	0,X	/ENTER DEFAULT UFD NAME OF SYSTEM DISK
	JMP	SCF23	/GO GET LARGE NODE INFO
/
SCF20X	JMS*	(TYPE	/ERROR EXIT
	MES915		/NO 'RSX' UFD
	HLT
	JMP	.-1	/DISCOURAGE THE ETERNAL OPTIMISTS!
/
SCF202	JMS	SCERR	/SYNTAX MESSAGE
	JMP	SCF201	/RETRY
/
/  FIND OUT HOW MANY RF PLATTERS
/
/
SCF204	JMS	CRTN
	JMS*	(TYPE
	MES533
SCF205	JMS	SCIFAC
	JMS	ADECK	/DECIMAL CONSTANT
	JMS	TCX	/SHOULD BE NO ADDITIONAL CHAR'S
	SKP
	JMP	SCF208	/WERE, SYNTAX
	PLA
	JMS	COMP	/RANGE OF RF 0-8
	(0
	(10
	JMP	SCF209	/OUT OF RANGE MESSAGE
	AAC	-1	/STORE - IF NONE, MAX UNIT IF SOME
	DAC*	(DSIZE
	SMA
	JMP	SCF206	/GO MAKE DEVICE NAME FOR RF
	SAD	SCFDSK	/IF NONE, AND SYSTEM, ERROR
	JMP	SCF208	/ERROR
	DZM	SCFSYF	/NO RF, CLEAR OUT OF OUR DEVICES TABLE
	JMP	SCF214	/CHECK OUT RP
SCF206	LAC	(220600	/'RF@' CONVERTED TO 'RF' UNIT 0
	DAC	SCFSYF	/SLOT FOR 'RF' DEVICE NAME
	JMP	SCF214
/
SCF208	JMS	SCERR
	JMP	SCF205
/
SCF209	JMS*	(TYPE
	MES592		/SIZE ERROR
	JMP	SCF205
/
/
SCF214	JMS	CRTN
	JMS*	(TYPE
	MES534
SCF215	JMS	SCIFAC
	JMS	ADECK
	JMS	TCX
	SKP
	JMP	SCF218
	PLA
	JMS	COMP
	(0
	(10
	JMP	SCF219
	AAC	-1
	DAC*	(RPDISK
	SMA!CLA		/SKIP IF NO RP'S SPECIFIED
	JMP	.+4	/SOME WERE, HOP OVER NEXT TEST
	SAD	SCFDSK	/IS RP SYSTEM DISK
	JMP	SCF218	/YES, AND 0 UNITS SPECIFIED, COMPLAIN
	JMP	SCF224	/NO, NO FURTHER WORK TO DO
	CLX		/SET UP LOOP TO MAKE REQUIRED DEVICE NAMES
	LAC	(222000	/'RP@'  , CONVERTED TO 'RP' AND UNIT 0
	DAC	SCFSYP,X /SLOT FOR RP UNITS
	IAC		/MOVE TO DEVICE 1
	AXS	1	/LIMIT ALREADY HAS NUMBER OF UNITS FOR CONTROL
	JMP	.-3
	JMP	SCF224
/
SCF218	JMS	SCERR
	JMP	SCF215
SCF219	JMS*	(TYPE
	MES592
	JMP	SCF215
/
/  HOW MANY RK'S
/
SCF224	JMS	CRTN
	JMS*	(TYPE
	MES535
SCF225	JMS	SCIFAC
	JMS	ADECK
	JMS	TCX	/LEFTOVERS?
	SKP
	JMP	SCF228	/YES, TROUBLE
	PLA		/LIMIT HAS ASSEMBLED # FROM ADECK
	JMS	COMP	/LEGAL # OF RK PLATTERS?
	(0
	(10
	JMP	SCF229	/WRONG NUMBER
	AAC	-1	/STORE -1 IF NONE, HIGHEST UNIT# IF SOME
	DAC*	(RKDISK
	SMA!CLA!IAC	/SKIP IF NONE SPECIFIED
	JMP	.+4	/SOME WERE SPECIFIED, WE HAVE NO PROBLEM
	SAD	SCFDSK	/IS THIS SYTEM DEVICE
	JMP	SCF228	/THIS IS SYSTEM, AND NO PLATTERS, COMPLAIN!
	JMP	SCF20C	/GO COMPLETE WORK FOR DISKS
	CLX
	LAC	(221300	/SAME GAME, MAKE DEVICE CODES
	DAC	SCFSYK,X
	IAC
	AXS	1
	JMP	.-3
	JMP	SCF20C	/GO COMPLETE DISK WORK
/
/
SCF228	JMS	SCERR
	JMP	SCF225
/
SCF229	JMS*	(TYPE
	MES592
	JMP	SCF225
/
/  ACCEPT NODE INFORMATION
/
/  LARGE NODES FIRST
/
SCF23	LAC	SCFPBZ	/SET UP SIZES OF LARGE+SMALL PARTITIONS
	DAC	SCRSIZ+1	/IN LISTS OF 'SCFNSB'
	LAC	(NDSZ
	DAC	SCRSIZ	/SMALL ONES
	JMS	CRTN
	JMS*	(TYPE	/PROMPT HIM
	MES530
SCF231	JMS	SCIFAC	/GET TYPED LINE
	JMS	FACSV
	JMS	TCX	/IS IT ZERO LENGTH
	JMP	SCF237	/YES DEFAULT TO 10 LARGE NODES (1000 OCTAL
/			/PARTITION TO CONTAIN THEM
	JMS	ADECKI	/MAKE UP DECIMAL CONSTANT
	JMS	TCX	/IF STUFF AFTER NUMBERS, ERROR
	SKP		/END OF LINE, OK
	JMP	SCF238	/SYNTAX ERROR
	PLA		/BRING IN ASSEMBLED NUMBER
	JMS	COMP	/BETWEEN 1 AND 600(8) 16K WORTH
	(1
	(600
	JMP	SCF239	/OUT OF RANGE
SCF233	DAC	SCFT3	/HOLD NUMBER, DEFAULT REJOINS HERE
	LAC	SCFPBZ	/LARGE NODE SIZE
	DAC	SCF232	/TO MULTIPLY BY # OF NODES
	LAC	SCFT3
	CLL		/NEED FOR MUL??
	MUL
SCF232	57		/WRITTEN OVER BEFORE USE
	LACQ
	AAC	377	/ROUND UP TO NEXT MULT OF 400
	AND	(777400
	PAL		/SAVE THIS IN LR
	TAD	(400	/ADD SOME SPACE FOR LARGE NODES
	TAD	SCFCOR	/ADD SIZE OF EXEC
	TCA		/NEGATE
	TAD	SCFPB0	/ADD BASE OF DISK HANDLER'S PARTITION
	SPA		/DID THE USER ASK FOR TOO MANY NODES?
	JMP	SCF240	/YES -- ERROR
	PLA		/NO -- RESTORE VALUE
	CLL!CML		/GOING TO CALL 'SCFNSB' TO MAKE NODES. LINK SAYS LARGE
	JMS	SCFNSB
	JMP	SCF24
SCF237	LAC	(12	/DEFAULT NUMBER OF LARGE NODES
	JMP	SCF233
/
SCF238	JMS	SCERR	/SYNTAX ERROR AND RETRY
	JMP	SCF231
/
SCF239	JMS*	(TYPE	/TYPE SIZE ERROR AND RETRY
	MES592
	JMP	SCF231
/
SCF240	JMS*	(TYPE	/TYPE TOO MANY NODES ERROR AND RETRY
	MES596
	JMP	SCF231
/
/  NOW SAME THING FOR SMALL NODE PARTITION
/
SCF24	JMS	CRTN
	JMS*	(TYPE
	MES531
SCF241	JMS	SCIFAC
	JMS	FACSV
	JMS	TCX
	JMP	SCF247	/DEFAULT 150(10) NODES 3000(8) SIZE PART.
	JMS	ADECKI
	JMS	TCX	/ERROR IF ANY NON-NUMBER CHAR'S LEFT IN LINE
	SKP
	JMP	SCF248	/OOOPS
	PLA
	JMS	COMP	/1 TO 3100(8) 16K WORTH . NOTE 1 GIVES YOU 25(10)
	(1
	(3100
	JMP	SCF249	/OUT OF RANGE, TILT!!
SCF243	DAC	SCFT3	/HOLD NUMBER
	CLL
	LAC	(NDSZ	/SMALL NODE SIZE, IN CASE NOT 10(10)
	DAC	SCF242	/FOR MULTIPLY TO GET PARTITION SIZE
	LAC	SCFT3
	MUL
SCF242	12		/WRITTEN OVER BEFORE USE
	LACQ
	DAC	SCRSV3	/SAVE CORE NEED FOR NODES TEMP.
	LAC	(-PG0NB	/FIND OUT HOW MANY SMALL NODES WERE IN EXEC
	TAD	(PG0NE
	IAC
	DAC	SCRSV2	/SAVE SPACE FOR SMALL NODES IN PAGE 0
	LAC	(-PG1NB
	TAD	(PG1NE
	IAC		/SAME THING FOR SMALL NODES IN PAGE 1
	TAD	SCRSV2	/AC NOW HAS WDS. USED FOR NODES IN EXEC
	TCA		/SUBTRACT THIS FROM SPACE FOR NODES CALCULATED
	TAD	SCRSV3	/ABOVE
	AAC	377	/ROUND UP TO NEXT 400(8
	AND	(777400
	PAL		/SAVE THIS FOR A MOMENT
	TAD	SCFCOR	/FIND OUT IF THERE ARE TOO MANY SPECIFIED
	TCA
	TAD	SCFPB0
	SPA		/TOO MANY?
	JMP	SCF250	/YES -- ERROR
	PLA		/NO -- RESTORE VALUE
	CLL		/LINK OFF FOR SMALL NODES
	JMS	SCFNSB	/MAKE NODES
/
/  NOW WE HAVE PUT IN NODES, IS ANY SPACE LEFT FOR PARTITION
/  UNDER DISK FILES HANDLER
/
SCF244	LAC	SCFCOR	/POINTER TO FREE SPACE ABOVE NODES
	DAC	SCFPBA	/DEFAULT, THIS IS BASE OF PARTITION
	CMA!IAC		/NEG FOR COMPARE TO BASE OF R?DISK
	TAD	SCFPB0
	DAC	SCFPSA	/DEFAULT, THIS IS SIZE OF 'XTRA' PARTITION
	SMA!SZA		/NOW, IS THERE REALLY ROOM FOR ONE
	JMP	SCF30	/YES, THERE IS, GO GET TTY'S
	LAC	(400000	/WASN'T ROOM, KILL PARTITION
	DAC	SCFPBA
	JMP	SCF30	/GO FIND OUT # OF TTY'S
/
/
SCF247	LAC	(226	/DEFAULT NUMBER OF SMALL NODES, 150(10)
	JMP	SCF243	/REJOIN MAIN LOOP
/
SCF248	JMS	SCERR	/SYNTAX ERROR
	JMP	SCF241	/RETRY
/
SCF249	JMS*	(TYPE	/SIZE ERROR
	MES592
	JMP	SCF241	/RETRY
/
SCF250	JMS*	(TYPE	/TYPE ERROR MESSAGE TOO MANY NODES AND RETRY
	MES596
	JMP	SCF24
/
/  SUBROUTINE SCFNSB CREATES A PARTITION FILLED WITH NODES
/  AND NOTIFIES SYSTEM (EITHER SNDL OF LNDL DEQUE) OF CREATION
/
/  LINK IS 0 FOR SMALL NODE CREATION, LINK IS 1 FOR LARGE
/  AC CONTAINS AMOUNT OF CORE TO BE CONVERTED TO NODES
/  SCFCOR POINTS TO FIRST FREE ADDR ABOVE EXEC
/
/  THE FOLLOWING PAIRS OF LOCATIONS MUST REMAIN AS PAIRS, AS
/   SCFNSB USES XR OF 0 FOR SMALL NODES, AND XR OF 1 FOR LARGE.
/
SCRPOO	POOL		/DEQUE INTO WHICH TO PLACE CREATED SMALL NODES
	LPOOL		/DEQUE INTO WHICH TO PLACE CREATED LARGE NODES
SCRNAM	.SIXBT	'SN0'	/SECOND HALF PARTITION NAME SMALL NODES
	.SIXBT	'LN0'	/SAME FOR LARGE
SCRLIS	SNDL		/SMALL NODES DECRIPTOR LIST DEQUE TO DECRIBE NODE PART.
	LNDL		/SMAE FOR LARGE
SCRSIZ	0		/SIZE OF SMALL NODES (INIT'ED AT SCF23
	0		/SAME FOR LARGE
SCRSVX	0		/SAVE LINK AS 0 OR 1, FOR PLACEMENT IN XR
SCRSV1	0		/TEMP STORAGE FOR TABLE AND NODE MANIPULATION
SCRSV2	0
SCRSV3	0
/
/
SCFNSB	0
	DAC	SCFT4	/SMOUNT OF CORE TO CONVERT TO NODES
	CLA!RAL		/GET LINK TO AC17
	DAC	SCRSVX	/FOR LATER INDEXING
SCR001	LAC	SCFT4	/GET REMAINING SIZE TO CREATE 
/
	SNA!SPA		/SKIP IF MORE TO DO
	JMP*	SCFNSB	/NOPE, EXIT
SCR010	LAC	SCFCOR	/POINTER TO FIRST FREE
	DAC	RCHLL	/BOTTOM OF NODE BLOCK FOR 'RCNOD'
	TAD	SCFT4	/ADD AMOUNT TO DO, GET TOP+1
	DAC	RCHUL	/FOR 'RCNOD'
	DAC	SCFCOR	/UPDATE LOWEST FREE LOCATION POINTER
	JMS	SCFSCR	/GO DO REAL WORK
	JMP*	SCFNSB	/GUANTTEED TO BE DONE IN UPPER CHUNK
/
/
/  SUBROUTINE  SCFSCR
/
/  RCHLL CONTAINS LOWER LIMIT OF CORE BLOCK TO BE NODES
/  RCHUL CONTAINS UPPER+1 OF BLOCK (BOTH THESE PASSED TO 'RCNOD'
/
/  SCRSVX  CONTAINS 0 FOR SMALL NODES, 1 FOR LARGE
/
SCFSCR	0
	LAC	RCHUL	/LOOP TO CONVERT BLOCK TO 0'S
	JMS	SETLR
/
/  TRICKY, WE WANT TO FIND IF WE ARE ABOUT TO CONVERT OURSELVES
/  INTO NODES. SETLR SUBTRACTS OUR STARTING ADDR. FROM
/  UPPER LIMIT OF NODES BLOCK, SO....
/
	SMA!SZA		/THIS WILL SKIP WHEN WE ARE OK!
	JMP	SCF999	/DISASTER, GET OUT
	LAC	RCHLL
	JMS	SETXR
	DZM	0,X
	AXS	1
	JMP	.-2
	LAC	SCRSVX	/LARGE-SMALL POINTER
	PAX
	ISZ	SCRNAM,X  /MAKE NAME ONE MORE THAN LAST ONE 'LN1' TO 'LN2'
	LAC	SCRNAM,X  / ETC. PLACE NAME IN TEMPORARY
	DAC	SCFT3
	JMS*	(PENP	/GET SMALL NODE FROM POOL TO DECRIBE PARTITION
	JMP	SCF999	/DISASTER, OUT OF SMALL NODES
	DAC	NAPNA	/SAVE NODE ADDR TO PLACE IN SYSTEM DEQUE
	JMS	SETXR	/ADDR TO XR FOR FILLING NODE
	LAC	(233123	/GET 'SYS' IN SIXBIT
	DAC	2,X
	LAC	SCFT3	/SECOND HALF
	DAC	3,X
	LAC	RCHLL	/BASE OF PARTITION
	DAC	4,X
	CMA!IAC		/CALCULATE SIZE
	TAD	RCHUL
	DAC	5,X
	DZM	6,X	/ZERO REST
	DZM	7,X
	DZM	10,X
	DZM	11,X
	LAC	SCRSVX	/GET BACK LARGE-SMALL
	PAX
	LAC	SCRLIS,X /WHICH SYSTEM DEQUE GETS THE NODE DESCRIBING PARTITION
	JMS	NAPE	/PLACE IN SYSTEM DEQUE
	LAC	SCRPOO,X /NOW WHICH SYSTEM DEQUE GETS THE NODES THEMSELVES
	DAC	RC0	/ARGUMENT HOLDER FOR 'RCNOD'
	LAC	SCRSIZ,X /SIZE OF NODES IN AC
	JMS	RCNOD	/THIS ROUTINE MAKES THE NODES, NAD PUTS IN SYSTEM
	JMP*	SCFSCR	/THAT'S ALL
/
/
/
/  ACCEPT NUMBER OF TTY'S
/
/  WE HAVE A PROBLEM HERE. THE 'ADD-A-DEVICE' ROUTINE DOESN'T
/  WORK FOR TTY'S. THUS, IF A USER SPECIFIES A SMALL NUMBER, AND
/  LATER WANTS TO ADD ON, HE CAN GET HUNG. WE ARE GOING TO
/  DEFAULT TO THE MAXIMUM ASSEMBLED INTO THE MONITOR (USUALLY 6).
/  IF THE USER HAS FEW TELETYPES, AND IS REALLY TIGHT ON CORE, HE
/  CAN GET AROUND THIS BY PATCHING RSXIMG (HE SAVES ABOUT TWO SMALL
/  NODES PER TELETYPE).  FOR A NORMAL >=24K SYSTEM:
/
/	$MICLOG SYS
/
/	$PATCH
/
/	PATCH V10A
/	>RSXIMG
/	>L 50021/000006>2
/	>EXIT
/
/	DOS-15 V3A
/	$
/
/
/  FOLLOW THE 2 WITH AN ALT-MODE; THIS REDUCES THE NUMBER
/  OF TELETYPES FROM 6 TO 2.
/
/  IF YOU ARE HANDY WITH THE CONSOLE KEYS, STOP THE COMPUTER
/  ANYTIME BEFORE ANSWERING THE LAST QUESTION, AND DEPOSIT THE
/  DESIRED NUMBER INTO 50021. THEN HIT CONTINUE, AND THE DIALOGUE
/  WILL START UP AGAIN.
/
/
SCF30	LAC	SCF000	/GET MAGIC # OF TTY'S FROM 50021 
	JMS	COMP	/CHECK IF USER PATCHED A FUNNY
	(1
	(TTYS
	JMP	SCF39	/BAD NUMBER
	DAC	SCFTTS	/SINCE DEVICE ADDER CAN'T PUT IN TTY'S LATER!!
	JMP	SCF150
/
SCF39	JMS*	(TYPE	/BAD PATCH!
	MES503
	HLT		/FIX PATCH
	JMP	SCF30	/TRY AGAIN
/
/
/
/ CONSTRUCT PHYSICAL DEVICE NODES FOR ADDITIONAL TTYS
/ (A NODE EXISTS FOR THE MANDATORY TT-0)
/
SCF150	DZM	SCFTTN	/INITIALIZE UNIT NUMBER
	LAC*	(TTYRQT)/USE AUTO-INCREMENT REG X13 TO SET
	DAC*	(X13)	/REQUEST QUEUE LISTHEAD ADDRESSES IN TABLE
/
SCF151	ISZ	SCFTTN	/SET NEXT TTY UNIT NUMBER
	LAC	SCFTTN	/IS THERE A 'PDVL' NODE FOR ALL TTY'S?
	SAD	SCFTTS
	JMP	SCF157	/YES -- SET NUMBER OF TTY'S IN SCOM
/
	JMS*	(PENP)	/NO -- PICK A NODE FROM THE POOL TO CONSTRUCT
			/A 'PDVL' NODE.  IS POOL EMPTY?
	JMP	SCF999	/YES -- ABORT SYSTEM CONFIGURATION
	DAC	NAPNA	/NO -- SAVE NODE ADDRESS FOR 'NAPE'
	JMS	SETXR	/SETUP XR TO FILL NODE
/
	LAC	(242400)/DEVICE NAME (FIRST HALF)
	DAC	D.N1,X
	DZM	D.N2,X	/DEVICE NAME (SECOND HALF)
	LAC	SCFTTN	/UNIT NUMBER
	DAC	D.UN,X
	DZM	D.AF,X	/CLEAR DEVICE-UNIT ATTACH FLAG
	LAC	NAPNA	/REQUEST QUEUE (DEQUE) LISTHEAD
	AAC	+D.QF
	DAC	D.QF,X
	DAC	D.QB,X
	DAC*	X13	/(SET REQUEST QUEUE TABLE ENTRY)
	LAC	(TTTGEV)/TRIGGER EVENT VARIABLE ADDRESS
	DAC	D.TG,X
	DZM	D.AI,X	/ASSIGN INHIBIT FLAG
/
	LAC	(PDVL)	/APPEND NODE TO 'PDVL' DEQUE
	JMS	NAPE
/
	JMP	SCF151	/TEST FOR ANOTHER NODE NEEDED
/
SCF157	LAC	SCFTTS	/SET NUMBER OF TTY'S IN SCOM
	DAC*	(TTYNUM)
/
/
/
/  TAKE DEVICES FROM DEFAULT DEVICE LIST AND MAKE THEIR 'PDVL'
/
SCF161	ISZ	DEVPNT	/MOVE POINTER TO NEXT
	LAC*	DEVPNT	/TOP TWELVE BITS TWO CHAR SIXBIT NAME
/			/BOTTOM SIX BITS UNIT NUMBER IN BINARY
	SNA		/SKIP UNLESS NULL DEVICE
	JMP	SCF161	/WAS, GO GET NEXT
	SAD	(-1	/-1 IS LIST TERMINATOR
	JMP	SCF167	/DONE, ON TO NEXT TASK
	DAC	SCFT2	/WE ARE GOING TO GIN UP SCFT1,SCFT2
/			/SO WE CAN USE EXISTING CODE
	AND	(777700	/KEEP SIX BIT NAME FOR SCFT1
	DAC	SCFT1	/THERE!
	XOR	SCFT2	/AND UNIT # FOR SCFT2
	DAC	SCFT2	/AND THERE!
/
/  AT THIS POINT SPLICE TO EXISTING CODE!
/
	LAC	(SCFT1)	/SCAN THE 'PDVL' DEQUE FOR THIS "NAME"
	DAC*	(R2)
	LAC	(PDVL)
	DAC*	(R1)
	JMS*	(SNAM)	/(R1, R2, R6, X17, XR & AC ARE ALTERED)
	SKP		/NAME FOUND?
	JMP	SCF165	/YES -- NAME/UNIT ERR
			/NO -- A 'PDVL' NODE CAN BE FORMED
/
	JMS*	(PENP)	/PICK A NODE FROM POOL -- EMPTY POOL?
	JMP	SCF999	/YES -- ABORT SYSTEM CONFIGURATION
	DAC	NAPNA	/NO -- SAVE NODE ADDRESS FOR 'NAPE'
	JMS	SETXR	/SETUP XR TO FILL NODE
	LAC	SCFT1	/DEVICE NAME (FIRST HALF)
	DAC	D.N1,X
	LAC	SCFT2	/DEVICE "NAME" (SECOND HALF)
	DAC	D.N2,X
	DAC	D.UN,X	/DEVICE UNIT NUMBER
	DZM	D.AF,X	/CLEAR DEVICE-UNIT ATTACH FLAG
	LAC	NAPNA	/REQUEST QUEUE (DEQUE) LIST HEAD
	AAC	+D.QF
	DAC	D.QF,X
	DAC	D.QB,X
	DZM	D.TG,X	/TRIGGER EVENT VARIABLE ADDRESS
	DZM	D.AI,X	/ASSIGN INHIBIT FLAG
/
/ SCAN THE PDVL FOR THE DEVICE NAME (FIRST HALF ONLY). IF FOUND, INSERT
/ THE NEW PDVL NODE THERE SO THAT ALL NODES FOR A GIVEN PHYSICAL DEVICE
/ ARE ADJACENTLY LINKED (A REQUIREMENT FOR THE I/O RUNDOWN TASK 'IORD').
/ IF NOT FOUND, APPEND THE NODE TO THE END OF THE PDVL DEQUE.
/
	LAC	(PDVL)	/SET PDVL LISTHEAD IN XR.
	JMS	SETXR
/
SCF163	LAC	0,X	/END OF DEQUE?
	SAD	(PDVL)
	JMP	SCF164	/YES -- APPEND NODE.
	JMS	SETXR	/NO -- SAVE NEW NODE'S ADR IN XR.
	LAC	2,X	/COMPARE DEVICE NAMES.
	SAD	SCFT1
	SKP		/SAME.
	JMP	SCF163	/DIFFERENT.
	LAC	0,X	/ADDRESS OF NEXT NODE.
SCF164	JMS	NAPE
	JMP	SCF161
/
SCF165	JMS*	(TYPE)	/TYPE NAME/UNIT ERR MESS & RETRY
	MES595
	JMP	SCF161
/
SCF166	JMS	SCERR	/TYPE SYNTAX ERR MESS & RETRY
	JMP	SCF161
/
SCF167	LAC	(PDVL)	/CLEAR SECOND HALF OF NAME DOUBLE-WORD
	JMS	SETXR	/IN ALL PHYSICAL DEVICE LIST NODES.
SCF168	LAC	D.FP,X	/(THESE WORDS HAVE BEEN SET TO THE
	SAD	(PDVL)	/DEVICE UNIT NUMBERS FOR INPUT SYNTAX 
	JMP	SCF169	/CHECKING.)
	JMS	SETXR
	DZM	D.N2,X
	JMP	SCF168
/
/  NOW MAKE PBDL NODES
/
SCF169	JMS	SUBPAR	/THIS SUBROUTINE DOES IT
	JMP	SCF170	/NON-SKIP WHEN DONE
	JMP	SCF169	/SKIP WHEN NOT
/
SCF170	JMS	CRTN	/TYPE "INSTALLATION OF TASKS FROM DISK"
/
/  NOTE, AT PRESENT WE ARE ASSUMING DOS HAS PLACED TAKSS TO BE
/  INSTALLED ON DISK FOR ALL THREE DISK TYPES. WE INSTALL FROM DISK
/  POSSIBLE WARNING ! ! ! ! ! ! ####  OVERFLOW RF???????
/
	JMS*	(TYPE)
	MES600
/
	.IFDEF %DTCLD
	CAL	CDTCPB	/CONNECT DECTAPE INTERRUPT
	.ENDC
	.IFUND %DTCLD
	LAC	SCFUFD	/GET POINTER TO FIRST UFD BLOCK
SCFDP1	JMS	CONV	/AND SET UP FOR A GET ON LUN 1
	.ENDC
/
	JMS	FTSK	/FIND DESCRIPTION OF FILES WITH 'TSK'
			/EXTENSIONS, RECORD THEM IN 'FDT', AND
			/INITIALIZE 'SKPNTR' TO POINT TO THE FIRST.
/
SCF171	LAC*	SKPNTR	/ARE THERE 'TSK' FILES YET TO BE TRIED?
	.IFDEF %DTCLD
	SNA
	JMP	SCF800	/NO -- FINISH SYSTEM CONFIGURATION
	.ENDC
	.IFUND %DTCLD
	SZA
	JMP	SCFDP2
	LAC	.NUFD	/LAST BLK OF UFD LIST?
	SAD	(-1	/-1 SAYS NO MORE
	JMP	SCF800	/YES; CLEAN UP.
	JMP	SCFDP1	/NO; LOOP.
	.ENDC
SCFDP2	LAC	SKPNTR	/YES -- SETUP TASK NAME FOR INSTALL
	DAC*	(X13)
	LAC*	X13
	DAC	TKNAM+0
	LAC*	X13
	DAC	TKNAM+1
/
	JMS	INSTAL	/INSTALL (OR TRY TO INSTALL) TASK
/
	LAC	SKPNTR	/AUGMENT SEEK POINTER & TEST FOR ANOTHER FILE
	AAC	+3
	DAC	SKPNTR
	JMP	SCF171
/
/ DETERMINE AND OUTPUT THE SIZE OF THE POOL
/
SCF800	DZM	SCFT1	/INCREMENT 'SCFT1' THRU NUMBER OF POOL NODES
	LAC	(POOL)
SCF801	JMS	SETXR
	LAC	0,X
	SAD	(POOL)
	JMP	SCF802
	ISZ	SCFT1
	JMP	SCF801
/
SCF802	LAC	SCFT1	/SAVE INITIAL POOL SIZE IN SCOM
	DAC*	(PLSZ)
/
	LAC	(040)	/CONVERT NUMBER OF NODES TO DECIMAL
	DAC	SCFIB+7	/AND FILL IMAGE OUTPUT BUFFER
	LAC	(SCFIB+6)
	DAC	SCFT1
	LAC*	(PLSZ)
/
SCF804	CLL
	IDIV
	12
	XOR	(060)
	DAC*	SCFT1
	LAC	SCFT1
	SAD	(SCFIB+2)
	JMP	SCF805
	AAC	-1
	DAC	SCFT1
	LACQ
	JMP	SCF804
/
SCF805	JMS	CRTN	/TYPEOUT POOL SIZE
	CAL	SCFTIB
	CAL	WFCPB
	JMS*	(TYPE)
	MES519
/
/ TYPE "SYSTEM IS RUNNING" AND TERMINATE SYSTEM CONFIGURATION ROUTINE
/
	JMS	CRTN
	JMS*	(TYPE)
	MES520
	JMS	CRTN
	JMS	CRTN
	.IFDEF %DTCLD
	CAL	DDTCPB	/DISCONNECT DECTAPE INTERRUPT
	.ENDC
	LAC	(400	/PREPARE TO SET UP THE 1ST REMOVE BLOCK
	DAC	DSKCT1
	CAL	ALLCPB
	CAL	WFCPB
	LAC	EV	/WERE THERE ANY ALLOCATE ERRORS?
	SPA
	JMP	SAVER1	/YES -- LET THE OPERATOR KNOW
	LAC	(DKUFD-1 /NO -- ZERO THE BLOCK
	DAC*	(X10
	DZM*	X10
	LAC*	(X10
	SAD	(DKUFD+376
	SKP
	JMP	.-4
	LAW	-1	/SET THE LAST WORD OF THE BLOCK TO -1
	DAC	DKUFD+377
	LAC	(400	/PREPARE TO PUT THE BLOCK
	DAC	D.XUN+3
	LAC	(DKUFD
	DAC	D.XUN+2
	LAC	DSKCT1+1
	DAC	D.XUN
	LAC	DSKCT1+2
	DAC	D.XUN+1
	CAL	D.WRIT	/PUT THE BLOCK OUT ONTO DISK
	CAL	WFCPB
	LAC	EV	/WERE THERE ANY ERRORS?
	SPA
	JMP	SAVER2	/YES -- TELL THE OPERATOR
	LAC	DSKCT1+2
	LMQ		/GET THE BLOCK NO.
	LAC	DSKCT1+1
	LRSS	10
	LACQ
	DAC*	(311	/SAVE THE BLOCK NO.
	JMP	SAVOK	/OK TO EXIT NOW
SAVER1	JMS	TYPE
	SAVME1
	HLT
SAVER2	JMS	TYPE
	SAVME2
	HLT
SAVME1	SAVME2-SAVME1/2*1000
	0
	.ASCII "ALLOCATE ERROR"<15>
SAVME2	SAVOK-SAVME2/2*1000
	0
	.ASCII "PUT ERROR"<15>
SAVOK=.
	CAL	ENATDV	/ENABLE TASK "TDV...".
	LAC	(SCF)	/EFFECTIVELY REMOVE TASK BY DELETING
	DAC*	(R1)	/STL NODE
	JMS*	(NDEL)
/
	DZM*	(MCRRI)	/REQUEST RESIDENT MCR TASK
	CAL	REQCPB
/
	CAL	(10)	/EXIT TASK
/
SCF999	LAC	(BXTPL)	/INSUFFICIENT FREE CORE (EITHER OUT OF POOL
	DAC*	(POOL)	/OR STORAGE FOR ALL PARTITION BLOCKS CANNOT
	LAC	(EXTPL)	/BE FOUND -- EXTEND POOL, TYPE ERR MESSAGE,
	DAC*	(POOL+1)/AND ABORT SYSTEM CONFIGURATION
	JMS*	(TYPE)
	MES599
	HLT
	JMP	.-1
/
	.EJECT
/ TYPE -- SUBROUTINE TO OUTPUT TO LUN-3 THE MESSAGE WHOSE ADDRESS
/ FOLLOWS THE JMS.
/
TYPE	0
	LAC*	TYPE	/SET ADDRESS IN CPB
	DAC	TYPEAD
	ISZ	TYPE
/
	CAL	TYPCPB	/OUTPUT TO TTY
	CAL	TYPWPB
	JMP*	TYPE	/EXIT
/
TYPCPB	2700		/TYPE OUT CAL PARAMETER BLOCK
	TYPEV
	3
	2
TYPEAD	XX
/
TYPWPB	20
	TYPEV
/
TYPEV	0
/
	.EJECT
SCF	STKL		/STL NODE FOR SYSTEM CONFIGURATION TASK.
	TDV		/THIS NODE IS DELETED FROM THE STL BEFORE
	.SIXBT "SFG"	/THE TASK EXITS, AND IS NOT RETURNED TO THE
	.SIXBT "@@@"	/POOL.  (THE ATL NODE IS RETURNED TO THE
	440001		/POOL AT EXIT, AND IS A PART OF THE INITIAL
	SFGIC-P.IC	/POOL ASSEMBLED WITH THE SYSTEM.)  THE TASK IS
	0		/FLAGGED ACTIVE & FIXED-IN-CORE, WITH A
	0		/DEFAULT PRIORITY OF ONE.
	0
	SCONF
	.IFPNZ	NDSZMT
	.REPT	NDSZMT
	0
	.ENDC
/
/ PARTITION BLOCK
/
SFGPB4	SCONF-20	/BASE ADDRESS.
	0
	400		/TASK SIZE (NEEDED ONLY FOR KM15/KT15 TEST)
	.REPT	5
	0
SFGIC	0		/SHORT PARTITION BLOCK -- USED FOR REGISTER
	DBA		/SAVE ONLY.  (THERE ARE OTHER ACTIVE TASKS
	JMS*	(SAVE)	/THAT MAY INTERRUPT THIS TASK.  VIZ., THE
	.REPT	PBIB	/TTY HANDLER TASK.
	0
	SKP
	.REPT	PBMM
	0
	.REPT	PBFP
	0
/
/
/
/  THERE FOLLOWS A LIST OF DEFAULT PARTITIONS, TERMINATED BY -1
/
PARPNS	.+1		/TO REFILL PARPNT IN CASE OF RESTART
PARPNT	.		/POINTER TO PICK THEM UP
	.SIXBT	'MIS'	/PART. TO FILL SPACE ABOVE NODES AND BELOW R?DISK
	.SIXBT	'C0@'
SCFPBA	400000		/BASE -- UNDEFINED INITIALLY
SCFPSA	0		/SIZE -- UNDEFINED INITIALLY
SCFPN0	0		/R?DISK PARTITION (NAME WRITTEN DYNAMICALLY)
	.SIXBT	'ISK'
SCFPB0	24400		/BASE -- 25000 FOR RF
SCFPS0	3400		/SIZE -- 3000 IN CASE OF RF DISK
	.SIXBT	'MCR'	/MCR PARTITION
	.SIXBT	'@@@'
SCFPBM	30000		/BASE
SCFPSM	3000		/SIZE
	.SIXBT	'MIS'	/PART. TO FILL SPACE LEFT BY SHORT MCR PART
	.SIXBT	'C1@'
SCFPBB	400000		/BASE -- INITIALLY UNDEFINED
SCFPSB	0		/SIZE -- INITIALLY UNDEFINED
	.SIXBT	'LP@'	/LP PART.
	.SIXBT	'@@@'
SCFPB1	33000		/BASE -- 33000
SCFPS1	1400		/SIZE 1400 FOR LPT
	.SIXBT	'TAP'	/DT PART.
	.SIXBT	'E@@'
SCFPB2	34400		/BASE
SCFPS2	3400		/SIZE FOR DECTAPE OR MAGTAPE
	.SIXBT	'TDV'	/TDV PART.
	.SIXBT	'@@@'
SCFPBT	40000		/DEFAULT BASE 
SCFPST	40000		/DEFAULT SIZE 
/
/
/  NOW A PARTITION FOR EACH BLOCK OF CORE, THAT EXISTS.
/  A -1 WILL BE WRITTEN IN TO TERMINATE
/  AND LAST PARTITION WILL HAVE ITS SIZE ADJUSTED IF NECESSARY.
/  LABEL SCFEND  LETS US ADDRESS THESE GUYS
/
SCFEND	.SIXBT	'BLK'
	.SIXBT	'1@@'
	100000
	100000
	.SIXBT	'BLK'
	.SIXBT	'2@@'
	200000
	100000
	.SIXBT	'BLK'
	.SIXBT	'3@@'
	300000
	100000
	-1		/IN CASE FULL CORE!
/
/  SOME USEFUL LOCATIONS
/
SCFUFD	0		/STARTING BLOCK # OF 'RSX' UFD
SCFCOR	0		/BOTTOM OF PRESENT PARTITION
SCFDSK	-1		/OUR WHICH SYSTEM DISK. -1=RF;0=RP;1=RK
SCFT3	0		/TEMPORARY
SCFT4	0		/SAME
/
/  NOW DEFAULT DEVICE LIST
/
DEVPNS	.+1		/TO REFILL DEVPNT
DEVPNT	.		/POINTER TO GET THEM
SCFSYF	.SIXBT	'RF@'	/THESE DEVICE NAMES ARE REBUILT DYNAMICALLY
SCFSYP	.SIXBT	'RP@'	/AS NEEDED AFTER AN INITIAL ZERO OUT.
	.SIXBT	'RPA'
	.SIXBT	'RPB'
	.SIXBT	'RPC'
	.SIXBT	'RPD'
	.SIXBT	'RPE'
	.SIXBT	'RPF'
	.SIXBT	'RPG'
SCFSYK	.SIXBT	'RK@'
	.SIXBT	'RKA'	/A MAKES 01 IN LAST 6 BITS, WHICH IS UNIT #1
	.SIXBT	'RKB'
	.SIXBT	'RKC'
	.SIXBT	'RKD'
	.SIXBT	'RKE'
	.SIXBT	'RKF'
	.SIXBT	'RKG'
	.SIXBT	'LP@'	/LP DEVICE @ IS UNIT #
	.SIXBT	'DT@'
	.SIXBT	'DTA'
	.SIXBT	'DTB'
	-1		/FOR NOW NO OTHERS.
/
/
/  RCNOD  CONVERTS AN AREA OF CORE INTO NODES OF SPECIFIED SIZE
/    AND PLACES THE NODES INTO A SPECIFIED DEQUE.
/
/   CALL WITH THE NODE SIZE IN AC, AC MODIFIED ON RETURN.
/  RCHLL MUST HAVE THE LOWER LIMIT OF THE CORE. RCHUL MUST
/  HAVE THE UPPER LIMIT+1. RC0 MUST CONTAIN THE ADDRESS OF THE DEQUE
/  INTO WHICH THE CREATED NODES ARE TO BE PLACED.
/
RCNOD	0
	DAC	RCSIZ	/SAVE NODE SIZE
	LAW	-1	/CORRECT UPPER+1 TO UPPER
	TAD	RCHUL
	DAC	RCHUL
RCNOD1	JMS	RCPBX	/CORRECT FOR PAGE BOUNDARY
	JMS	RCFIT	/ANY MORE FIT
	JMP*	RCNOD	/NO
	LAC	RCHLL	/LOWER LIMIT IS NODE ADDR
	DAC	NAPNA	/APPEND NODE
	LAC	RC0	/TO THIS DEQUE
	JMS	NAPE
	LAC	RCHLL	/UPDATE LOWER LIMIT
	TAD	RCSIZ
	DAC	RCHLL
	JMP	RCNOD1	/KEEP GOING
/
/  TEMPORARIES
/
RCHLL	0
RCHUL	0
RCSIZ	0
RC0	0
/
/  RCFIT - SKIP RETUN IF A NODE OF SIZE RCSIZ CAN FIT BETWEEN
/  RCHLL AND RCHUL, AC MODIFIED
/
RCFIT	0
	LAC	RCSIZ
	TAD	RCHLL
	AAC	-1
	CMA!IAC
	TAD	RCHUL
	SMA
	ISZ	RCFIT
	JMP*	RCFIT
/
/  RCPBX - PREVENT A NODE FROM STRADDLING 0-17 OF A PAGE.
/  THIS IS ACCOMPLISHED BY INCREASING (IF NECESSARY) RCHLL TO
/  20 OF THE NEXT PAGE. AC AND RCHLL MAY BE MODIFIED.
/
RCPBX	0
	LAC	RCHLL	/FIND THIS NODE'S PAGE
	AND	(770000
	AAC	20	/ADD 20
	DAC	RCPBXT	/SAVE RESULT FOR LATER
	TCA		/NEGATE FOR TEST: SEE IF NODE
	TAD	RCHLL	/WILL BEGIN BEFORE LOC20 OF PAGE
	SMA
	JMP	RCPBX1	/NO -- OK
	LAC	RCPBXT	/YES -- ADJUST NODE'S ADDR
	DAC	RCHLL
RCPBX1	LAC	RCSIZ
	TAD	RCHLL
	AAC	-1
	XOR	RCHLL
	AND	(770000
	SNA
	JMP*	RCPBX	/OK AS IS
	LAC	RCHLL
	AND	(770000	/KEEP PAGE BITS
	TAD	(10020	/MOVE TO 20 OF NEXT PAGE
	DAC	RCHLL	/THAT DOES IT
	JMP*	RCPBX
/
RCPBXT	0		/TEMP STORAGE FOR NODE ADDR CHECK
/
/
/
/  SUBPAR  READS PARTITION DECRPITIONS FROM PARPNT AND
/  CONSTRUCTS PBDL NODES FOR THEM. STOPS WHEN A -1 IS ENCOUNTERED
/  AS FIRST WORD OF FOUR DESCRIBING THE NODE. IN THIS CASE A NON-SKIP
/  RETURN IS GENERATED AND NO PBDL IS CONSTRUCTED. 
/  IF THE PARTITION IN QUESTION HAS A 0 OR - BASE, IT IS IGNORED, A SKIP
/  RETURN IS GIVEN. IN ALL OTHER CASES, A PBDL IS CONSTRUCTED, AND A
/  SKIP RETURN IS GIVEN.
/
SUBP1	0		/HOLD FIRST 1/2 NAME
SUBP2	0		/HOLD SECOND 1/2 NAME
SUBP3	0		/HOLD BASE
SUBPAR	0
SCF101	ISZ	PARPNT
	LAC*	PARPNT
	SAD	(-1
	JMP*	SUBPAR	/YES
	DAC	SUBP1	/SAVE FIRST HALF NAME
	ISZ	SUBPAR	/MAKE SKIP RETURN
	ISZ	PARPNT	/GET SECOND HALF NAME
	LAC*	PARPNT
	DAC	SUBP2	/SAVE
	ISZ	PARPNT
	LAC*	PARPNT	/BASE
	DAC	SUBP3	/SAVE BASE
	ISZ	PARPNT	/MAKE PARPNT POINT TO SIZE
	SNA!SPA		/ILLEGAL BASE, DON'T DO PARTITION!!
	JMP*	SUBPAR	/YES IT WAS 
/
/
	LAC	(LPOOL	/GET A LARGE NODE
	DAC*	(R1
	JMS*	(PICK
	JMP*	SUBPAR	/NO MORE LARGE NODES; LET HIM TRY WITH
/			/WHATEVER PARTITIONS HE ALREADY HAS
	DAC	NAPNA	/SAVE ADDR. FOR LATER INSERTION IN PBDL
	JMS	SETXR	/FILL NODE SLOTS WITH XR
	LAC	SUBP1
	DAC	P.N1,X	/NAME PART 1
	LAC	SUBP2
	DAC	P.N2,X	/PART 2
	LAC	SUBP3
	DAC	P.BA,X	/BASE
	LAC*	PARPNT	/SIZE
	DAC	P.SZ,X
	DAC	P.TS,X	/DEFAULTS FOR TASK SIZE
	LAC	(SAVE	/
	DAC	13,X	/SAVE ENTRY POINT
	LAC	(DBA
	DAC	15,X
	PXA
	AAC	13
	AND	(7777
	XOR	(120000	/JMS*	(SAVE
	DAC	16,X
	LAC	(SKP
	DAC	P.SW,X
	LAC	(PBDL	/DEQUE HEAD FOR PARTITIONBLOCKS
	JMS	NAPE	/PUT IT THERE
	JMP*	SUBPAR	/ALL OTHER LOC'S WERE PREVIOUSLY 0'D
/
SETXRM=.&070000
/
SETXR	0
	TAD	(-SETXRM)
	PAX
	JMP*	SETXR
/
/  SAME FOR LIMIT REG
/
SETLR	0
	TAD	(-SETXRM
	PAL
	JMP*	SETLR
/
/
/ SCIFAC -- SUBROUTINE TO TYPE A PROMPTING CHARACTER AND
/ INITIALIZE THE FETCH-A-CHARACTER SUBROUTINE
/
SCIFAC	0
	JMS*	(TYPE)
	MES400
	JMS*	(IFAC)
	JMP*	SCIFAC
/
/ AOCTK -- SUBROUTINE TO FETCH CHARACTERS THRU A NON-OCTAL
/ TERMINATOR, AND ASSEMBLE AN OCTAL CONSTANT IN LR, AND RETURN
/ WITH THE TERMINATOR IN AC.
/
AOCTK	0
	CLLR		/CLEAR ASSEMBLY REGISTER
/
AOCTKL	JMS	FACSV	/ASSEMBLY LOOP -- FETCH A CHARACTER
AOCTKM	JMS	COMP	/OCTAL DIGIT?
	(60)
	(67)
	JMP*	AOCTK	/NO -- EXIT WITH TERMINATOR IN AC
	LRS	3	/YES -- ASSEMBLE DIGIT INTO CONSTANT
	PLA		/IN LIMIT REGISTER AND FETCH NEXT
	LLS	3	/CHARACTER
	PAL
	JMP	AOCTKL
/
/  ALTERNATE ENTRY POINT IS FIRST FACSV ALREADY CALLED
/
AOCTKI	0
	DAC	AOCTKB	/SAVE CHARACTER
	LAC	AOCTKI	/SET UP COMMON RETURN
	DAC	AOCTK
	CLLR		/DO MISSED INSTRUCTION
	LAC	AOCTKB	/RETRIEVE CHARACTER
	JMP	AOCTKM	/JOIN
AOCTKB	0		/TEMP
/
/ ADECK -- SUBROUTINE TO FETCH CHARACTERS THRU A NON-DECIMAL
/ TERMINATOR, AND ASSEMBLE A DECIMAL CONSTANT IN LR, AND RETURN
/ WITH THE TERMINATOR IN AC.
/
ADECK	0
	CLLR		/CLEAR ASSEMBLY REGISTER
/
ADECKL	JMS	FACSV	/ASSEMBLY LOOP -- FETCH A CHARACTER
ADECKM	JMS	COMP	/DECIMAL DIGIT?
	(60)
	(71)
	JMP*	ADECK	/NO -- EXIT WITH TERMINATOR IN AC
	AND	(017)	/YES -- ASSEMBLE DIGIT INTO CONSTANT
	DAC	ADECKB	/IN LIMIT REGISTER AND FETCH NEXT
	PLA		/CHARACTER
	CLL
	MUL
	12
	LACQ
	TAD	ADECKB
	PAL
	JMP	ADECKL
/
ADECKB	0
/
/  SAME THING AS ADECK, BUT CHAR INITIALLY IN AC!
/
ADECKI	0
	DAC	ADECKB	/SAVE FIRST CHAR
	LAC	ADECKI	/MAKE COMMON SUBROUTINE RETURN
	DAC	ADECK
	CLLR
/
	LAC	ADECKB	/CHAR BACK
	JMP	ADECKM	/ALTERNATE ENTRY
/
/ FACSV -- SUBROUTINE TO FETCH THE NEXT NON-BLANK CHARACTER AND SAVE
/ IT IN THE GENERAL ERROR MESSAGE, UNLESS CAR RTN OR ALTMODE
/
FACSV	0
FACSV1	JMS*	(FAC)	/FETCH CHARACTER
	JMS	TCX	/CAR RTN OR ALTMODE?
	JMP*	FACSV	/YES -- EXIT WITH CHAR IN AC.
	SAD	(040)	/NO -- BLANK?
	JMP	FACSV1	/YES -- FETCH ANOTHER CHARACTER
	RCL		/NO -- SET CHARACTER IN 20TH
	DAC	FACSVB	/POSITION IN 'MES591' AND EXIT
	LAC	MES591+11 /WITH CHARACTER IN AC.
	AND	(777400)
	XOR	FACSVB
	DAC	MES591+11
	AND	(000377)
	RCR
	JMP*	FACSV
/
FACSVB	0
/
/ SCERR -- GENERAL ERROR ROUTINE TO INDICATE POSITION OF ERROR
/ IN INPUT LINE.
/
SCERR	0
	JMS*	(TYPE)	/TYPE "^^^  SYNTAX ERR AT X -- PLEASE RETYPE"
	MES591		/WHERE X HAS BEEN SET BY 'FACSV'.
	JMP*	SCERR
/
/
/ SCFULX -- HOLE UPPER LIMIT CHECK
/
/ RETURN AT JMS+1 IF AC+LOWER LIMIT WILL OVERFLOW UPPER LIMIT
/ RETURN AT JMS+2 IF NO OVERFLOW
/
SCFULX	0
	TAD	SCFHLL
	AAC	-1
	TCA
	TAD	SCFHUL
	SMA
	ISZ	SCFULX
	JMP*	SCFULX
/
/ SCFPBX -- PAGE BOUND CHECK
/
/ RETURN AT JMS+1 IF AC+LOWER LIMIT WILL OVERFLOW A PAGE BOUND
/ RETURN AT JMS+2 IF NO OVERFLOW
/
SCFPBX	0
	TAD	SCFHLL
	AAC	-1
	XOR	SCFHLL
	AND	(770000)
	SNA
	ISZ	SCFPBX
	JMP*	SCFPBX
/
/ CRTN -- SUBROUTINE TO RETURN CARRIAGE
/
CRTN	0
	JMS*	(TYPE)
	MES2
	JMP*	CRTN
/
/ COMP -- SUBROUTINE TO COMPARE AC WITH LIMITS (INCLUSIVELY)
/
/ CALLING SEQUENCE:
/	JMS	COMP	/CALL
/	(MIN)		/ADDRESS OF MIN
/	(MAX)		/ADDRESS OF MAX
/	JMP	OUT	/RETURN AT JMS+3 IF OUT OF RANGE
/	---		/RETURN AT JMS+4 IF WITHIN RANGE
/
COMP	0
	DAC	COMPAC	/SAVE AC
	LAC*	COMP	/OUT OF RANGE IF AC<MIN
	ISZ	COMP
	DAC	COMPTV
	LAC*	COMPTV
	TCA
	TAD	COMPAC
	SPA
	JMP	COMPOR
	LAC*	COMP	/OUT OF RANGE IF AC>MAX
	DAC	COMPTV
	LAC	COMPAC
	TCA
	TAD*	COMPTV
	SMA
	ISZ	COMP	/AC WITHIN LIMITS -- RETURN AT JMS+4
COMPOR	ISZ	COMP	/AC WITHOUT LIMITS -- RETURN AT JMS+3
	LAC	COMPAC	/RESTORE AC
	JMP*	COMP
/
COMPAC	0
COMPTV	0
/
/ NAPE -- SUBROUTINE TO APPEND THE NODE WHOSE ADDRESS IS IN 'NAPNA'
/ AT THE END OF THE DEQUE WHOSE LISTHEAD IS IN AC OR, ALTERNATIVELY,
/ TO INSERT THE NODE WHOSE ADDRESS IS IN 'NAPNA' BEFORE THE NODE
/ WHOSE ADDRESS IS IN THE AC.
/
NAPNA	0	/NODE ADDRESS
/
NAPE	0
	IAC
	DAC	NAPR1
	LAC*	NAPR1
	DAC	NAPR2
	LAC*	NAPR2
	DAC*	NAPNA
	LAC	NAPNA
	DAC*	NAPR2
	DAC*	NAPR1
	ISZ	NAPNA
	LAC	NAPR2
	DAC*	NAPNA
	JMP*	NAPE
/
NAPR1	0
NAPR2	0
/
SCFHUL	0	/HOLE UPPER LIMIT
SCFHLL	0	/HOLE LOWER LIMIT
SCFRX1	0	/RECORD INDEX ONE
SCFRX2	0	/RECORD INDEX TWO
SCFTTN	0	/TTY UNIT NUMBER
SCFPBZ	0	/PARTITION BLOCK SIZE
SCFTTS	0	/NUMBER OF TTY UNITS
SCFT1	0	/TEMP CELL ONE
SCFT2	0	/TEMP CELL TWO (MUST FOLLOW 'SCFT1')
SCFTMP	0	/TEMP CELL
SCFRB	.BLOCK 12 /RECORD BUFFER
/
SCFTIB	2700	/CAL PARAMETER BLOCK TO 
	EV	/TYPE OUT IMAGE BUFFER
	2
	3
	SCFIB
/
SCFIB	004003	/IMAGE BUFFER
	.BLOCK 7
/
/ INSTALL -- SUBROUTINE TO INSTALL TASK WHOSE NAME IS IN 'TKNAM+0'
/ AND 'TKNAM+1' AND WHOSE STARTING BLOCK ON DT-0 IS IN THE 'FDT' WORD
/ POINTED TO BY 'SKPNTR'.
/
TKNAM	.SIXBT	'@@@@@@'	/TASK TO BE INSTALLED
/
	.TITLE *** INSTALL SUBROUTINE ***
/
/WRITTEN TO HANDLE BLOCK MODE (400 WORDS/BLOCK) MASS STORAGE DEVICES
/SUCH AS THE RP15 THAT WILL NOT HANDLE WORD ADDRESSABILITY. HOWEVER,
/IT WILL STILL WORK ON A WORD ADDRESSABLE DEVICE (SUCH AS RF15)
/
/THE ALLOCATION SIZE FOR THE TASK WAS IN A SPECIAL AREA JUST BEFORE THE
/ACTUAL TASK. THIS AREA WAS 10(8) WORDS LONG DUE TO THE FACT THAT THE
/LOW 3 BITS STILL HAD TO CONTAIN THE UNIT NUMBER. THE ALLOCATION WAS
/EXTENDED FOR 10(8) WORDS, AND THE STL NODE DISK ADDRESS WAS SET UP
/AS 10(8) MORE THAN IT WOULD HAVE BEEN. DUE TO THE FACT THAT ALL DISK
/TRANSFERS IN BLOCK MODE MUST START ON A SECTOR(BLOCK) BOUNDARY, THIS
/HAS NOW BEEN EXTENDED TO 400(8) WORDS. PERHAPS SOME USEFUL FUNCTION
/CAN BE DEVISED TO KEEP SOME MORE INFORMATION IN THE NOW WASTED 377(8)
/WORDS.
/
FDT=25000
X10=10
X11=11
X15=15
RELHWE=235		/CONTAINS A SKIP IF RELOCATE ON MACHINE
FPHDW=236		/CONTAINS A SKIP IF FP15 ON MACHINE
/
INSTAL=.		/BEGINNING OF INSTALL ROUTINE
I.TSKN=TKNAM		/IF ASSEMBLED WITH SCF, THEN THIS IS A SUBROUTINE
	0		/THIS IS ITS ENTRY POINT
	DZM	I.DSKA	/DISK AREA NOT ASSIGNED YET
	DZM	I.DFPR	/NO DEFAULT PRIORITY YET
/
/SCAN THE STL TO SEE IF THE TASK EXISTS ALREADY
/
	LAC	(STKL)
	DAC*	(R1)
	LAC	(I.TSKN) /ADDRESS OF THE NAME
	DAC*	(R2)
	JMS*	(SNAM)	/GO LOOK (ALMOST ALL REGISTERS WIPED OUT)
	SKP		/NOT FOUND, ALL IS WELL
	JMP	I.ER02	/FOUND, ERROR
/
/CODE TO DO THE INSTALL WORK:
/
/NOTE: ALL DISK ADDRESS CARRIED AROUND DURING PROCESSING, AND PASSED ON
/TO THE RSX EXECUTE PROGRAM VIA THE LINK TABLE ARE OF THE FORM
/ BLOCK NUMBER * 400 + UNIT NUMBER. THE 'ADD' INSTRUCTION INSTEAD OF THE
/'TAD' INSTRUCTION IS USED TO CALCULATE DISK ADDRESSES, AS THIS WILL
/INCREMENT THE UNIT NUMBER IF AN OVERFLOW OCCURS.
/
/
/
	JMS	SEEK	/SEEK THE FILE
	LAC	(377777) /FIND LINK #377777 FOR INFO
	DAC	I.LKNM	/
	DZM	I.ACNT	/COUNTING THE LINKS ON THE WAY
	JMS	I.FLNK	/GO DO IT
	LAC	INBUF+4	/BASE OF BLANK COMMON
	DAC	I.BCBS	/SAVED FOR PATCHING
/
	LAC	I.ACNT	/THE COUNT OF EXTERNAL LINKS+1 FOR THE ALLOCATION
	ALSS	10	/MULTIPLY BY 400
	TAD	INBUF+5	/NOW WE HAVE THE NUMBER OF BLOCKS *400
	AAC	377	/NEEDED TO HOLD THE IMAGE
	AND	(-400)	/ON THE DISK, WITH EACH OVERLAY
	DAC	I.ALSZ	/STARTING ON A BLOCK BOUNDARY
/
	LAC	INBUF+7	/SAVE THE BASE ADDRESS OF THE LINK TABLE
	DAC	I.LTBS
/
	LAC	INBUF+6	/AND THE SIZE OF THE RESIDENT IMAGE
	DAC	I.RISZ
/
	LAC	INBUF+11 /SAVE THE
	DAC	I.ENTR	/ENTRY POINT FOR THE TASK
	SMA		/IS FP15 REQUIRED?
	JMP	.+3	/NO
	XCT*	(FPHDW)	/SKIP IF FP IS THERE
	JMP	I.ER15	/NO, BUT IT IS NEEDED - ERROR
	DZM	I.XM		/ CLEAR XVM MODE BITS
	LAC	I.ENTR		/ IS THIS TASK EXEC MODE?
	RTL			/
	SMA			/
	JMP	I.OVXM		/ YES -- LEAVE XM BITS CLEARED
	LAC	INBUF+16	/ NO -- GET XM BITS
	DZM	INBUF+16	/ CLEAR GARBAGE OUT OF INBUF
	PAL			/ SAVE XM BITS TEMPORARILY
	AND	(1		/ IS TASK IN XVM MODE?
	SNA			/ 
	JMP	.+3		/ NO -- DON'T SET XVM MODE BITS IN STL NODE
	LAC	(000140		/ YES -- PREPARE TO SET XVM MODE BITS
	DAC	I.XM		/
	PLA			/ RESTORE AC WITH FORMER CONTENTS OF INBUF+16
	AND	(2		/ WILL TASK RUN IN IOT MODE?
	SNA			/
	JMP	I.OVXM		/ NO -- DON'T SET THE IOT BIT
	LAC	I.XM		/ YES -- PREPARE TO SET IOT BIT
	XOR	(20		/
	DAC	I.XM		/
I.OVXM=.			/
/
	LAC	INBUF+12 /MOVE THE PARTITION NAME IN
	DAC	I.PTNM
	LAC	INBUF+13
	DAC	I.PTNM+1
/
	LAC	INBUF+14 /SAVE THE BASE
	DAC	I.CORB	/ADDRESS OF THE PARTITION ACCORDING TO TKB
	DAC	I.LCOR	/SAVE THIS FOR LINK TABLE EXPANSION (&LINK #0)
/
	LAC	INBUF+15 /GET THE MAXIMUM TASK REGISTER
	AAC	377	/FORCE IT TO 400 WORD INCREMENTS
	AND	(-400)
	DAC	I.MXTR	/SAVE IT
	LAC	INBUF+15 /IF TASK SIZE IS 401,1001, ETC.,
	AND	(-400	/ADD 400 TO MAX TASK REG.
	SAD	INBUF+15
	SKP
	JMP	.+4
	LAC	I.MXTR
	TAD	(400
	DAC	I.MXTR
	LAC	I.ENTR	/NOW WE SEE IF THAT WAS A MISTAKE AND THIS IS
	RTL		/REALLY AN EXEC MODE TASK
	SPA		/SKIP ON MISTAKE
	JMP	I.OVRX	/NO, WE DID GOOD, WELL DIDN'T WE????
	LAC	INBUF+14 /PICK UP THE PARTITION BASE ADDRESS
	TCA		/NEGATE
	TAD	INBUF+15 /NOW WE HAVE THE SIZE -1 OF THE TASK
	IAC		/SO FIX IT UP
	DAC	I.MXTR	/AND REPLACE OUR ERROR
/
I.OVRX	LAC	(PBDL)	/NOW WE SCAN THE PARTITION BLOCK DESCRIPTOR LIST
	DAC*	(R1)	/FOR THIS PARTITION
	LAC	(I.PTNM) /NAME
	DAC*	(R2)	/
	JMS*	(SNAM)	/GO DO IT
	JMP	I.ER03	/NOT FOUND, WE HAVE TROUBLE HERE
	DAC	I.PBAD	/FOUND, SAVE THE ADDRESS FOR LATER
	AAC	4	/AND UP TO THE ADDRESS OF
	DAC	I.WRK	/THE PARTITION BASE ADDRESS
/
	LAC	I.ENTR	/PICK UP THE TASK ENTRY POINT AGAIN
	RTL		/AC0 IS THE PROTECTION INDICATOR
	SPA		/SKIP IF NOT PROTECTED
	JMP	I.RELT	/RELOCATED TASK, CHECK IT OUT
	LAC*	I.WRK	/NOT RELOCATED - WAS THE PARTITION BASE SPECIFIED
	SAD	INBUF+14 /CORRECTLY TO TKB?
	JMP	I.PARC	/YES -- GO CHECK THE PARTITION
	JMP	I.ER04	/NO, ERROR
I.RELM	LAC	I.DFPR	/PRIORITY REQUESTED?
	SZA		/SKIP IF NOT
	JMP	I.CBCK	/IF SO, USE IT - NOW CHECK COMMON BLOCKS
	LAC	INBUF+10 /WAS A PRIORITY SPECIFIED TO TKB?
	SNA		/SKIP IF SO
	JMP	I.ER12	/NO, NO PRIORITY AT ALL - ERROR
	DAC	I.DFPR	/YES, SAVE THIS
I.CBCK	LAC	(INBUF+15) /SET UP TO SCAN THE COMMON BLOCKS
	DAC*	(X15)	/ADDRESS OF LIST
	LAC*	X15	/PICK IT UP
	SNA		/ANYTHING THERE?
	JMP	I.ALLD	/NO, ALLOCATE THE DISK SPACE
	LAC*	(X15)	/YES, SET UP TO SCAN
	DAC*	(R2)	/THE SYSTEM COMMON BLOCK LIST
	LAC	(SCDL)	/FOR THIS COMMON BLOCK
	DAC*	(R1)	/NAME
	JMS*	(SNAM)	/GO DO IT - FOUND?
	JMP	I.ER09	/NO, ERROR
	AAC	4	/YES, SET UP TO COMPARE
	DAC*	(X10)	/THE BASE AND SIZE
	LAC*	X15	/SCAN OVER THE NAME SECOND HALF
	LAC*	X15	/ARE THE BASES THE SAME?
	SAD*	X10	/SKIP IF SO
	SKP
	JMP	I.ER09	/NO, ERROR
	LAC*	X15	/ONCE MORE
	SAD*	X10	/FOR THE SIZES
	JMP	I.CBCK+2 /ALL OK, KEEP LOOKING
	JMP	I.ER09	/NO, ERROR
/
I.RELT	XCT*	(RELHWE) /DO WE HAVE RELOCATION HARDWARE?
	JMP	I.ER14	/NO, SHOW THE ERROR
I.PARC	ISZ	I.WRK	/YES, CHECK THE SIZE OF THE PARTITION
	LAC*	I.WRK	/TO SEE IF THIS WILL FIT
	TCA		/NEGATE
	TAD	I.MXTR	/AND ADD THE HIGHEST TASK REGISTER IN
	SMA!SZA		/WILL IT FIT? SKIP IF SO
	JMP	I.ER04	/NO, TASK IS TOO LARGE - ERROR
	JMP	I.RELM	/YES IT WILL FIT, CARRY ON WITH OTHER THINGS
/
I.ALLD	CAL	I.ACPB	/ALLOCATE THE DISK SPACE NEEDED
	CAL	I.WAIT	/WAIT UNTIL COMPLETION
	LAC	I.EV	/PICK UP THE EV
	SAD	(-777)	/OUT OF POOL?
	JMP	SCF999	/YES - STOP SYSTEM CONFIG
	SPA		/ALLOCATION OK? - SKIP IF SO
	JMP	I.ER06	/NO - ERROR
	ISZ	I.DSKA	/YES, SHOW THAT WE HAVE ALLOCATED DISK SPACE
	LAC	I.ALSZ+1 /MOVE THE ADDRESS INTO THE
	DAC	I.PCPB	/PUT CPB
	LAC	I.ALSZ+2
	DAC	I.PCPB+1
	LAC	(I.BLOK-1) /CLEAR THE DISK I/O BLOCK
	DAC*	(X10)	/TO ZEROS
	LAW	-400
	DAC	I.WRK
	DZM*	X10
	ISZ	I.WRK
	JMP	.-2
	LAC	I.ALSZ	/NOW CLEAR ALL OF THE ALLOCATED DISK AREA TO
	DAC	I.WRK	/ZEROS
	CAL	I.PUTC	/PUT THE ZEROS OUT
	JMS	I.WFEV	/WAIT UNTIL DONE
	LAC	I.PCPB+1 /UP THE ADDRESS
	CLL
	TAD	(400	/TO THE NEXT BLOCK
	DAC	I.PCPB+1
	SZL		/IF OVERFLOW
	ISZ	I.PCPB	/UP THE HIGH-ORDER WORD ALSO
	LAW	-400	/COUNT DOWN
	TAD	I.WRK	/TO ZERO
	SMA!SZA		/DONE?
	JMP	.-14	/NO, KEEP ON
/
/THE DISK SPACE HAS BEEN ALOCATED, AND ALL OF IT IS ZEROED. NOW TO
/BRING THE CODE IN.
/
	LAC	I.ALSZ	/PICK UP THE SIZE OF THE ALLOCATION
	DAC	I.BLOK	/SET THIS IN AS WORD ZERO OF THE BLOCK
	LAC	I.PTNM	/NAME
	DAC	I.BLOK+1
	LAC	I.PTNM+1 /NAME
	DAC	I.BLOK+2
	LAC	I.CORB	/BASE
	DAC	I.BLOK+3
	LAC	I.ALSZ+2 /SET UP THE DISK GET/PUT CONTROL TABLE
	DAC	I.PCPB+1 /SO THE FIRST WRITE WILL SEND OUT
	LAC	I.ALSZ+1 /THE BLOCK WITH THE ALLOCATION SIZE IN IT
	DAC	I.PCPB
	XOR	I.ALSZ+2 /SET THIS BLOCK (IN CORE) AS BEING THE
	DAC	I.THIS	/FIRST ONE
	ADD	(400)	/NOW UP TO THE BLOCKS TO BE USED
	DAC	I.DSKB	/SAVE AS BASE OF LINK ZERO
	DAC	I.LBSE	/SET THIS ALSO AS THE BASE FOR THE FIRST LINK
	LAW	-1	/SHOW THAT CURRENT BLOCK HAS BEEN MODIFIED
	DAC	I.WRIT	/SO IT WILL BE WRITTEN OUT
/
/EXPAND THE LINK TABLE IF IT EXISTS
/
	JMS	I.EXPL	/DO IT
	JMS	SEEK	/RE-SEEK THE FILE
	DZM	I.LKNM	/FIND LINK #0
	JMS	I.FLNK	/
I.LOOP	JMS	I.EXPL	/EXPAND THIS LINK
	LAC	I.MXDK	/PICK UP THE MAXIMUM DISK BLOCK USED
	SZA
	JMP	.+3
	LAC	I.THIS
	DAC	I.MXDK
	ADD	(400)	/UP TO THE NEXT ONE
	DAC	I.WRK	/SAVE THIS AS THE BASE FOR THE NEXT LINK
	LAC	INBUF+3	/LAST LINK?
	SAD	(377777) /SKIP IF NOT
	JMP	I.DEXP	/YES, DONE EXPANDING THE TSK FILE
	JMS	I.LKTB	/NO, SET UP THE LINK TABLE FOR THE NEXT LINK
	JMP	I.LOOP	/ AND GO FOR MORE
/
/SUBROUTINE TO READ THROUGH UNTIL A CERTAIN LINK IS FOUND
/
I.FLNK	XX		/LINK NUMBER IS IN I.LKNM
	JMS	READ	/READ A RECORD
	LAC	INBUF+2	/IS THIS A TYPE ONE RECORD?
	AND	(IOT)
	SAD	(JMS)	/SKIP IF NOT
	JMP	I.OVRP	/IT IS, IS IT THE ONE WE WANT?
	SNA		/IT ISN'T - ERROR VIA TYPE 0 RECORD?
	JMP	I.ER10	/YES, LEAVE
	JMP	I.FLNK+1 /CYCLE ON FOR MORE
I.OVRP	LAC	INBUF+3	/TYPE ONE RECORD FOUND, IS IT THE ONE WE WANT?
	SAD	I.LKNM	/SKIP IF NOT
	JMP*	I.FLNK	/IT IS, LEAVE
	ISZ	I.ACNT	/IT IS NOT, COUNT THE LINKS FOUND
	NOP		/ANYWAY
	JMP	I.FLNK+1 /AND GO FOR MORE
/
/
/SUBROUTINE TO EXPAND A LINK. THE TYPE ONE RECORD HAS BEEN READ. UPON
/EXIT, A TYPE ONE RECORD WILL BE IN 'INBUF'.
/
I.EXPL	XX
	DZM	I.MXDK	/CLEAR OUT THE HIGHEST DISK ADDRESS USED
/
/I.LBSE SHOULD CONTAIN THE BASE DISK ADDRESS FOR THIS LINK
/I.LCOR SHOULD CONTAIN THE BASE CORE ADDRESS THAT CORESPONDS TO I.LBSE
/
I.EXLP	LAC	(INBUF+2)
	DAC	I.PNTR	/SET UP FOR 'GETW' ROUTINE
	JMS	READ	/READ A RECORD
	LAC	INBUF+2	/IS IT A TYPE TWO RECORD?
	AND	(IOT)
	SAD	(LAC)	/SKIP IF NOT
	JMP	I.TYP2	/IT IS, PROCESS IT
	SAD	(ADD)	/TYPE THREE?
	JMP	I.TYP3	/YES, PROCESS IT
	SAD	(JMS)	/TYPE ONE?
	JMP*	I.EXPL	/YES, LEAVE
	LAC	INBUF+2	/IS THIS THE EOF ON LINK EXPANSION?
	SZA		/MAYBE
	JMP	I.ER10	/NO, READ ERROR
	LAC	I.LKNM	/CHECK TO SEE IF THIS IS LINK 377777
	SAD	(377777) /SKIP IF NOT
	JMP*	I.EXPL	/IT IS, LEAVE
	JMP	I.ER10	/IT ISN'T - READ ERROR
I.TYP2	JMS	I.GETW	/PICK UP THE COUNT
	SAD	(-1)	/SKIP IF NOT THE END OF THE RECORD
	JMP	I.EXLP	/IT IS, GO FOR MORE RECORDS
	AND	(077777) /SINGLE IT OUT
	TCA		/NEGATE IT
	DAC	I.ACNT	/SAVE IT
	JMS	I.GETW
	JMS	I.GETA	/PICK UP AN ADDRESS AND READ THAT BLOCK INTO CORE
I.T2LP	JMS	I.GETW	/PICK UP A WORD
	JMS	I.PUTW	/SET IT DOWN
	ISZ	I.ACNT	/SKIP WHEN DONE
	JMP	I.T2LP	/UNTIL THEN
	JMP	I.TYP2	/GO UNTIL DONE
/
/SUBROUTINE TO PICK UP ONE WORD FROM THE BUFFER
/
I.GETW	XX
	LAC*	I.PNTR	/PICK IT UP
	ISZ	I.PNTR	/INCREMENT IT
	JMP*	I.GETW	/AND LEAVE
/
/SUBROUTINE TO PUT ONE WORD INTO THE DISK BLOCK
/(A CALL TO I.GETA SHOULD BE DONE FIRST TO SET UP THE PARAMETERS)
/
I.PUTW	XX
	DAC*	I.DPNT	/SET IT IN
	LAW	-1	/SHOW THAT THE BLOCK
	DAC	I.WRIT	/HAS BEEN MODIFIED
	ISZ	I.DPNT	/INCREMENT THE POINTER
	ISZ	I.BCNT	/SEE IF THE END OF THE BLOCK HAS BEEN REACHED
	JMP*	I.PUTW	/IT HASN'T, LEAVE
	LAC	I.THIS	/GO TO THE NEXT BLOCK
	ADD	(400)	/FOR THE CONTINUATION OF THIS ESCAPADE
	JMS	I.XDSK	/PICK UP THE BLOCK 
	LAC	(I.BLOK) /AND RESET THE
	DAC	I.DPNT	/POINTERS
	LAW	-400	/TO THE DISK
	DAC	I.BCNT	/BLOCK
	JMP*	I.PUTW	/LEAVE
/
/SUBROUTINE TO SEE THAT THE DISK BLOCK THAT WILL CONTAIN A CERTAIN ADDRESS
/IS IN CORE, AND TO SET UP POINTERS FOR I.PUTW
/CALL WITH THE DESIRED CORE ADDRESS IN THE AC - IT WON'T BE THERE ON RETURN
/
I.GETA	XX
	AND	(077777)
	TCA	/NEGATE
	TAD	I.LCOR	/ADD IN THE BASE
	TCA		/POP BACK TO POSITIVE
	DAC	I.DPNT	/SAVE
	AND	(-400)	/FIND OUT WHICH RELATIVE BLOCK
	ADD	I.LBSE	/FIND OUT WHICH ACTUAL BLOCK
	JMS	I.XDSK	/BRING THAT ONE INTO CORE
	LAC	(377)	/NOW WE PICK UP
	AND	I.DPNT	/THE OFFSET INTO THE DISK BLOCK
	AAC	-400	/CREAT THE NUMBER OF WORDS LEFT IN THE BLOCK
	DAC	I.BCNT	/SAVE THIS AS A COUNTER FOR I.PUTW
	TAD	(I.BLOK+400) /UP TO THE CORE ADDRESS IN REAL CORE
	DAC	I.DPNT	/WHERE THE WORD IS
	JMP*	I.GETA	/LEAVE
/
/SUBROUTINE TO MAKE CERTAIN THAT THE CORRECT BLOCK IS IN CORE. THE
/ONE CURRENTLY IN CORE IS WRITTEN OUT, IF IT HAS BEEN MODIFIED (I.WRIT=-1)
/
I.XDSK	XX		/ENTRY
	DAC	I.BCNT	/SAVE THIS
	XOR	I.THIS	/IS THE BLOCK THE ONE THAT IS IN CORE?
	SNA		/SKIP IF NOT
	JMP*	I.XDSK	/IT IS, LEAVE
	XOR	I.THIS	/RESORE THE ORIGINAL AC CONTENTS
	LMQ		/FIND OUT IF THE BLOCK JUST ABOUT TO BE READ IN
	LLS	12	/IS HIGHER NUMBERED THAN THE ONE SHOWN IN I.MXDK
	DAC	I.GETW	/SAVE THIS
	LAC	I.MXDK	/PICK UP THE CURRENT MAXIMUM
	LMQ
	LLS	12	/CREATE A PROPER COMPARISON NUMBER
	TCA		/NEGATE
	TAD	I.GETW	/ADD IN THE ONE WE ARE ABOUT TO GET
	RAL		/SAVE THE SIGN
	LAC	I.BCNT	/PICK UP THE ONE WE WANT
	SNL		/SKIP IF IT IS LOWER
	DAC	I.MXDK	/IF HIGHER OR EQUAL, RESET I.MXDK
	ISZ	I.WRIT	/HAS THE CURRENT RECORD BEEN MODIFIED?
	JMP	.+3	/NO, SO JUST READ THE NEW ONE IN
	CAL	I.PUTC	/PUT OUT THE CURRENT BLOCK
	JMS	I.WFEV	/WAIT UNTIL DONE
	DZM	I.WRIT	/CLEAR THE 'THE BLOCK HAS BEEN MODIFIED' FLAG
	LAW	777400	/PICK UP THE
	AND	I.BCNT	/BLOCK NUMBER
	DAC	I.PCPB+1 /AND SET IT IN THE DISK CONTROL TABLE
	XOR	I.BCNT	/PICK UP THE UNIT NUMBER
	DAC	I.PCPB	/AND SET IT IN ALSO
	XOR	I.PCPB+1 /NOW SET THE CURRENT BLOCK POINTER
	DAC	I.THIS	/TO POINT TO WHERE WE ARE NOW
	CAL	I.GETC	/GET THE NEW BLOCK
	JMS	I.WFEV	/WAIT
	JMP*	I.XDSK	/AND LEAVE
/
/
I.TYP3	XOR	INBUF+2	/PICK UP THE TOTAL NUMBER OF PATCHES
	SPA!SNA		/SKIP IF THERE ARE ANY
	JMP	I.EXLP	/NO, LOOK FOR SOMETHING ELSE TO DO
	DAC	I.TOTP	/SAVE THIS
I.T3LP	ISZ	I.PNTR	/FIND OUT HOW MANY
	JMS	I.GETW	/PATCHES ON THIS RECORD
	SPA!SNA!TCA	/SKIP IF THERE ARE ANY
	JMP	I.EXLP	/NO, CARRY ON WITH THE NEXT RECORD
	DAC	I.CCNT	/YES, SAVE THE COUNT
	TAD	I.TOTP	/AND SUBTRACT THIS FROM THE TOTAL
	DAC	I.TOTP
I.T3LQ	LAC*	I.PNTR	/PICK UP THE ADDRESS
	AND	(077777) /WHERE THE PATCH GOES
	JMS	I.GETA	/MAKE SURE THAT IT IS IN CORE
	JMS	I.GETW	/FIND OUT WHAT THE FUNCTION IS
	AND	(IOT)
	SAD	(JMS)	/IS IT ADDRESS FIELD MODIFICATION?
	JMP	I.T3AD	/YES, DO IT
	SAD	(LAC)	/IS IT BLANK COMMON OFFSET?
	JMP	I.T3CO	/YES
	SZA		/IS IT SIMPLE REPLACEMENT?
	JMP	I.ER10	/NO, MUST BE A READ ERROR
	JMS	I.GETW	/PICK UP THE WORD
I.T3BK	DAC*	I.DPNT	/SET IT IN THE DISK BLOCK
	LAW	-1	/SET THE 'MODIFIED BLOCK' FLAG
	DAC	I.WRIT	/TO SHOW THAT WE CHANGED THE BLOCK
	ISZ	I.CCNT	/COUNT THE PATCHES
	JMP	I.T3LQ	/NOT YET DONE, GO FOR MORE
	LAC	I.TOTP	/ARE WE COMPLETELY DONE?
	SPA!SNA		/SKIP IF NOT
	JMP	I.EXLP	/YES, READ A TYPE ONE RECORD
	JMS	READ	/NO, RESET FOR THE NEXT PATCH RECORD
	LAC	(INBUF+2)
	DAC	I.PNTR	/SET UP FOR 'GETW'
	LAC	INBUF+2	/MAKE CERTAIN THAT THIS IS
	AND	(IOT)	/A TYPE THREE RECORD
	SAD	(ADD)	/SKIP IF NOT
	JMP	I.T3LP	/IT IS, FINISH UP
	JMP	I.EXLP+3 /IT ISN'T, WHAT HAPPENED???
I.T3AD	LAC	I.ENTR	/PICK UP THE TASK ENTRY POINT
	RAL		/BANK/PAGE BIT TO AC0
	SMA!CLA
	LAC	(010000) /PAGE MODE, MUST KEEP THE INDEX BIT
	XOR	(760000) /CREATE A MASK
	PAL		/SAVE THIS
	AND*	I.DPNT	/PICK UP THE INSTRUCTION FIELD ONLY
	LMQ		/SAVE THIS
	PLA		/BRING THE MASK BACK
	CMA		/FLIP IT OVER
	AND*	I.PNTR	/BRING IN THE NEW ADDRESS FIELD
	OMQ		/AND BRING THE INSTRUCTION OUT
	ISZ	I.PNTR	/UP THE POINTER
	JMP	I.T3BK	/AND PUT THIS AWAY
I.T3CO	JMS	I.GETW	/PICK UP THE WORD
	TAD	I.BCBS	/ADD IN THE BASE OF BLANK COMMON
	JMP	I.T3BK	/AND PUT THE WORD AWAY
/
/
/SUBROUTINE TO SET UP THE LINK TABLE FOR THE LINK ABOUT TO BE PROCESSED
/
I.LKTB	XX
	LAC	I.CORB	/SET UP TO ACCESS ON LINK 0 LEVEL
	DAC	I.LCOR	/AS THIS IS LINK TABLE MODIFICATION
	LAC	I.DSKB
	DAC	I.LBSE
	LAC	I.LTBS	/PICK UP THE BASE ADDRESS OF THE LINK TABLE
	IAC		/PLUS ONE
I.LKLP	DAC	I.PNTR	/SAVE THIS
	JMS	I.GETA	/BRING THIS INTO CORE
	LAC*	I.DPNT	/IS THIS THE END OF THE LINK TABLE?
	SAD	I.LTBS	/SKIP IF NOT
	JMP	I.LKUP	/IT IS, SET UP FOR THE NEXT LINK
	LAC	I.PNTR	/PICK UP THE
	AAC	7	/LINK NUMBER WORD
	JMS	I.GETA	/
	LAC*	I.DPNT	/IS THIS THE LINK WE ARE WORKING ON NOW?
	SAD	INBUF+3	/SKIP IF NOT
	JMP	I.LKBS	/IT IS, SET UP THE DISK ADDRESS ON THIS ONE
I.LKMR	LAC	I.PNTR	/IT ISN'T, UP TO THE NEXT ONE
	AAC	13	/IN THE TABLE
	JMP	I.LKLP
/
/NOTE: EARLIER VERSIONS USED THE MINIMUM ADDRESS WORD TO FLAG THE LINKS
/THAT HAD BEEN UPDATED. HOWEVER, WITH THE LOW END OF THE DISK ALLOCATED
/TO THE SYSTEM IMAGE, IT IS VERY UNLIKELY THAT THE LINK NUMBERS WILL
/REACH THE SAME MAGNITUDE AS THE DISK ADDRESS THAT REPLACES IT.
/THEREFORE, THE SAD SHOULD BE ENOUGH.
/
I.LKBS	LAC	I.WRK	/SET THE BASE ADDRESS OF THIS LINK
	JMS	I.PUTW	/IN THE LINK TABLE
	LAC*	I.DPNT	/AND SET THE MINIMUM ADDRESS OF THE LINK
	DAC	I.TMP	/IN A SAFE PLACE FOR SETTIN I.LCOR WHEN DONE
	JMP	I.LKMR	/NOW LOOK AT THE NEXT LINK
/
I.LKUP	LAC	I.TMP	/SET THE CORE BASE ADDRESS FOR THIS LINK
	DAC	I.LCOR	/IN FOR DISK ADDRESS ADJUSTING
	LAC	I.WRK	/SET THE DISK BASE ADDRESS CORRESPONDING TO
	DAC	I.LBSE	/I.LCOR IN ALSO
	JMP*	I.LKTB	/AND LEAVE
/
/
/THE WHOLE THING IS DONE, NOW TO MAKE THE STL ENTRY FOR THIS TASK
/AND LEAVE THIS BLOODY MESS.
/
I.DEXP=.
	ISZ	I.WRIT	/DOES THE DISK BLOCK NEED RE-WRITING?
	JMP	I.DOVR	/NO, GO CLEAN UP
	CAL	I.PUTC	/YES, WRITE IT OUT
	JMS	I.WFEV	/AND WAIT FOR IT
I.DOVR	JMS*	(PENP)	/PICK AN EMPTY BEER CAN FROM THE POOL
	JMP	I.ER05	/AND SHOW AN ERROR IF NO LITTER IS AROUND
	DAC*	(R2)	/OTHERWISE, IF ONE IS FOUND, MAKE IT LOOK RESPECTABLE
	IAC		/BY CLEVERLY DISGUISING IS AS AN STL NODE FOR
	DAC*	(X11)	/THIS NEW TASK IN THE SYSTEM
	LAC	I.XM	/SET THE XVM MODE BITS IN THE STL NODE
	XOR	I.MXTR	
	DAC	I.MXTR
	LAC	TKNAM
	DAC*	X11
	LAC	TKNAM+1
	DAC*	X11
	LAC	(I.DFPR-1)
	DAC*	(X10)
	LAW	-6
	DAC	I.ACNT	/BY MOVING IT FROM THE NEAT BLOCK IT IS IN
	LAC*	X10	/FRESHLY PICKED
	DAC*	X11	/NODE
	ISZ	I.ACNT
	JMP	.-3
/
	LAC	(STKL)	/NOW ADD THIS TO
	DAC*	(R1)	/THE STL (R2 IS SET FROM ABOVE) (THANK GOD)
	JMS*	(NADD)
/
	JMP*	INSTAL	/DONE, LEAVE IF SCF SUBROUTINE
I.ERRR	DAC	I.ERRA	/SET THE ADDRESS OF THE MESSAGE TO PRINT
	JMS*	(TYPE)	/START PRINTING
	MES900		/THEE ERROR
	LAC	(SCFIB+1)	/NOW TO CREATE THE TASK NAME IN
	DAC*	(X10)	/IMAGE MODE
	LAC	TKNAM
	JMS	EREXS1	/FIRST THREE
	LAC	TKNAM+1
	JMS	EREXS1	/LAST THREE
	CAL	SCFTIB	/WRITE IT OUT
	CAL	WFCPB	/WAIT
	JMS*	(TYPE)	/NOW FINISH THE 'TASK XXXXXX NOT INSTALLED'
	MES901
	JMS*	(TYPE)	/PUT OUT THE REASON
I.ERRA	XX
	LAC	I.DSKA	/DISK SPACE ALLOCATED?
	SNA		/SKIP IF SO
	JMP	.+3	/OVER IF NOT
	CAL	I.DCPB	/DEALLOCATE IT IF SO
	CAL	I.WAIT
	JMP*	INSTAL	/AND LEAVE
/
EREXS1	XX
	LMQ
	JMS	EREXS2
	JMS	EREXS2
	JMS	EREXS2
	JMP*	EREXS1
/
EREXS2	XX
	LLS	6
	AND	(77)
	SNA
	AAC	177
	XOR	(40)
	TAD	(40)
	DAC*	X10
	JMP*	EREXS2
/
	.DEFIN	ABUF,TEXT,?B
	B-./2*1000+2 ; 0
	.ASCII	\@TEXT@\<15>
B=.
	.ENDM
I.ER02	LAC	(I.ME02)
	JMP	I.ERRR
I.ER03	LAC	(I.ME03)
	JMP	I.ERRR	/ERROR ROUTINES - PICK UP THE MESSAGE ADDRESS
I.ER04	LAC	(I.ME04) /AND GO OFF TO DO THE WORK
	JMP	I.ERRR
I.ER05	LAC	(I.ME05)
	JMP	I.ERRR
I.ER06	LAC	(I.ME06)
	JMP	I.ERRR
I.ER07	LAC	(I.ME07)
	JMP	I.ERRR
I.ER08	LAC	(I.ME08)
	JMP	I.ERRR
I.ER09	LAC	(I.ME09)
	JMP	I.ERRR
I.ER10	LAC	(I.ME10)
	JMP	I.ERRR
I.ER12	LAC	(I.ME12)
	JMP	I.ERRR
I.ER14	LAC	(I.ME14)
	JMP	I.ERRR
I.ER15	LAC	(I.ME15)
	JMP	I.ERRR
/
/ERROR MESSAGES:
/
I.ME01	ABUF	<SYNTAX ERROR>
I.ME02	ABUF	<TASK ALREADY IN SYSTEM>
I.ME03	ABUF	<PARTITION NOT IN SYSTEM>
I.ME04	ABUF	<TASK WOULD OVERFLOW PARTITION>
I.ME05	ABUF	<OUT OF POOL>
I.ME06	ABUF	<OUT OF DISK>
I.ME07	ABUF	<INPUT CHECKSUM ERR>
I.ME08	ABUF	<INPUT PAR ERR>
I.ME09	ABUF	<SYS COM BLK ERR>
I.ME10	ABUF	<READ ERR ON LUN 5>
I.ME11	ABUF	<DISK ERR>
I.ME12	ABUF	<NO DEFAULT PRIORITY>
I.ME13	ABUF	<FILE NOT FOUND ON LUN 5>
I.ME14	ABUF	<RELOCATION HARDWARE NOT AVA>
I.ME15	ABUF	<FLOATING POINT UNIT NOT AVA>
/
/SUBROUTINE TO WAIT FOR I.EV AND ANNOUNCE A DISK ERROR IF NEGATIVE WHEN
/COMPLETE.
/
I.WFEV	XX
	CAL	I.WAIT	/WAIT
	LAC	I.EV
	SMA		/ERRORS?
	JMP*	I.WFEV	/NO, LEAVE
I.ER11	LAC	(I.ME11)	/DISK ERROR
	JMP	I.ERRR	/ANNOUNCE IT AND CLEAN UP
/
/
/VARIABLES, CONSTANTS, AND CPBS WITH BUFFERS AS A SIDELINE
/
I.XM	0	/XVM MODE BITS
I.ACNT	0	/SCRATCH LOCATIONS
I.TMP	0
I.BCNT	0
I.CCNT	0
I.WRK	0
I.DPNT	0	/POINTER USED PRIMARILY BY I.PUTW
I.MXDK	0	/MAXIMUM DISK BLOCK USED BY THE CURRENT LINK
I.THIS	0	/DISK ADDRESS OF CURRENT BLOCK IN CORE
I.WRIT	0	/-1 WHEN CURRENT BLOCK HAS BEEN MODIFIED, 0 IF NOT
I.DSKA	0	/INDICATOR THAT THE DISK AREA HAS BEEN ALLOCATED (0 IF NOT)
I.LBSE	0	/DISK BASE ADDRESS FOR CURRENT LINK
I.LCOR	0	/CORE ADDRESS CORRESPONDING TO I.LBSE
I.LKNM	0	/NUMBER OF LINK BEING SOUGHT BY I.FLNK
I.PTNM	0 ; 0   /PARTITION NAME
I.TOTP	0	/COUNTER FOR PATCH RECORDS
I.LTBS	0	/LINK TABLE BASE ADDRESS
I.DFPR	0	/PRIORITY OF TASK
I.PBAD	0	/PARTITION DESCRIPTOR BLOCK ADDRESS
I.DSKB	0	/DISK BASE ADDRESS
I.RISZ	0	/RESIDENT IMAGE SIZE
I.MXTR	0	/MAXIMUM TASK REGISTER (CHANGED TO SIZE FOR STL NODE)
I.ENTR	0	/TASK ENTRY PC (WITH BANK/PAGE AND EXEC/NORM MODE BITS)
/
I.BCBS	0	/BASE OF BLANK COMMON FOR PATCHING
I.PNTR	0	/POINTER USED BY I.GETW
I.CORB	0	/CORE BASE ADDRESS (CORRESPONDING TO I.DSKB)
/
I.WAIT	20	/CPB FOR WAITING
	I.EV		/FOR THE EV
/
I.EV	0	/GENERAL PURPOSE EV
/
I.ACPB	1500	/ALLOCATE DISK SPACE CPB
	I.EV
	1	/ALLOCATE ON DISK - LUN 1
	I.ALSZ	/ADDRESS OF ALLOCATE/DEALLOCATE DISK CONTROL TABLE
/
I.DCPB	1600	/DEALOCATE DISK SPACE CPB (IN CASE OF ERRORS)
	I.EV
	1
	I.ALSZ	/OTHERWISE, SAME AS I.ACPB
/
I.ALSZ	0	/ALLOCATE/DEALLOCATE CONTROL TABLE
	0 ; 0
/
I.GETC	3000	/GET (DISK) CPB
	I.EV
	1
	I.PCPB	/GET/PUT CONTROL TABLE
/
I.PUTC	3100	/PUT (DISK) CPB
	I.EV
	1
	I.PCPB	/SAME AS I.GETC
/
I.PCPB	0	/GET/PUT CONTROL TABLE
	0	/DISK ADDRESS IS PUT HERE
	I.BLOK	/ALL I/O TO/FROM DISK IS DONE THROUGH THE I.BLOK BUFFER
	400	/AND IS EXACTLY ONE BLOCK LONG
/
I.BLOK	.BLOCK	400	/DISK I/O BUFFER
/
INBUF	.BLOCK	42	/INPUT BUFFER
TCX	0
	SAD	(015)	/SUBROUTINE TO SKIP IF AC DOES NOT
	JMP*	TCX	/CONTAIN A TERMINATOR
	SAD	(175)
	JMP*	TCX
	ISZ	TCX
	JMP*	TCX
ERR10=I.ER10		/TO ALLOW LABEL REFERENCING
BXTPL	.+NDSZ		/EXTENSION FOR POOL TO TYPE ERROR MESSAGE
	POOL
	.REPT NDSZM2
	0
/
	EN
/
EXTPL	POOL
	.-1-NDSZ
	.REPT NDSZM2
	0
/
	.EJECT
/
	TEXT 400,< >>,<175>
	TEXT 498,<*** IF YOU HAVE KT15 (MEMORY RELOCATE) THE>,<15>
	TEXT 499,<*** PROTECT/RELOCATE SWITCH IS SET WRONG>,<15>
	TEXT 500,<XVM/RSX VERSION 1A CONFIGURATOR;>,<15>
	TEXT 577,<NUMBERS IN DECIMAL UNLESS NOTED;>,<15>
	TEXT 578,<'CR' GIVES VALUE IN '[]'S.>,<15>
	TEXT 501,<SPECIFY CORE SIZE[32K]>,<175>
	TEXT 503,<ILLEGAL NUMBER OF TTY'S PATCHED IN>,<15>
	TEXT 504,<SPECIFY NUMBER OF CLOCK TICKS PER SECOND[60]>,<175>
	TEXT 519,<NODES IN POOL>,<15>
	TEXT 520,<SYSTEM IS RUNNING>,<15>
	TEXT 530,<HOW MANY LARGE NODES?[10]>,<175>
	TEXT 531,<HOW MANY SMALL NODES?[150]>,<175>
	TEXT 532,<SYSTEM DISK; [RF], RP, RK>,<175>
	TEXT 533,<HOW MANY RF PLATTERS?[0]>,<175>
	TEXT 534,<HOW MANY RP DISKS?[0]>,<175>
	TEXT 535,<HOW MANY RK DISKS?[0]>,<175>
	TEXT 536,<MCR PARTITION SIZE, OCTAL[3000]>,<175>
	TEXT 591,<^^^ SYNTAX ERR AT "X" -- RETYPE>,<15>
	TEXT 592,<^^^ INVALID SIZE -- RETYPE>,<15>
	TEXT 593,<^^^ INVALID NUMBER -- RETYPE>,<15>
	TEXT 594,<^^^ NAME ALREADY USED -- RETYPE>,<15>
	TEXT 595,<IMPOSSIBLE, CALL MAYNARD>,<15>
	TEXT 596,<NODES WOULD OVERFLOW DISK PARTITION>,<15>
	TEXT 598,<*** RE-ENTRANT ECO PACKAGE NEEDED>,<15>
	TEXT 599,<INSUFFICIENT CORE OR NODES,TRY AGAIN>,<15>
	.IFUND %DTCLD
	TEXT 600,<INSTALLATION OF TASKS FROM SYSTEM DISK>,<15>
	.ENDC
	.IFDEF %DTCLD
	TEXT 600,<INSTALLATION OF TASKS FROM DT-0>,<15>
	.ENDC
	TEXT 900,<TASK ">,<175>
	TEXT 901,<" NOT INSTALLED, >,<175>
	TEXT 902,<TASK ALREADY IN SYSTEM>,<15>
	TEXT 903,<PARTITION NOT IN SYSTEM>,<15>
	TEXT 904,<TASK WOULD OVERFLOW PARTITION>,<15>
	TEXT 906,<OUT OF DISK STORAGE>,<15>
	TEXT 907,<INPUT CHECKSUM ERR>,<15>
	TEXT 908,<INPUT PARITY ERR>,<15>
	TEXT 910,<READ ERROR>,<15>
	TEXT 911,<DISK WRITE ERROR>,<15>
	TEXT 912,<NO DEFAULT PRIORITY>,<15>
	TEXT 913,<RELOCATION HARDWARE NOT AVAILABLE>,<15>
	TEXT 914,<FLOATING POINT UNIT NOT AVAILABLE>,<15>
	TEXT 915,<'RSX' UFD NOT ON SYSTEM DISK>,<15>
/
/ DKGET -- SUBROUTINE TO READ DISK PER 'GETCPB'
/
DKGET	0
	JMS	D.SETU	/SET UP THE INFO IN A WAY WE CAN CHANGE
D.GLOP	JMS	D.GETI	/SET UP THE RIGHT DISK BLOCK IN CORE ANS ALL OF
			/THE PARAMETERS NEEDED TO MOVE
	LAC*	D.DSKA	/READING - MOVE FROM DISK
	DAC*	D.CORA	/TO CORE
	ISZ	D.DSKA
	ISZ	D.CORA
	ISZ	D.CNT	/DONE?
	JMP	.-5	/NO
	LAC	D.CWC	/HAS THE WC GONE TO ZERO?
	SMA!SZA		/SKIP IF SO
	JMP	D.GLOP	/NO, KEEP ON LOOKING
	JMP*	DKGET	/YES - LEAVE
/
D.SETU	XX
	LAC	DKXUN
	DAC	D.CUN
	LAC	DKXDA
	DAC	D.CDA
	LAC	DKXCA
	DAC	D.CORA
	LAC	DKXWC
	DAC	D.CWC
	JMP*	D.SETU
/
D.GETI	XX
	LAW	-400
	AND	D.CDA
	XOR	D.CUN
	XOR	D.THIS	/IS IT THE ONE IN CORE?
	SNA		/SKIP IF NOT
	JMP	D.GOTX	/IT IS - NO NEED TO GO TO THE DISK
	ISZ	D.MODI	/HAS THE BLOCK IN CORE BEEN MODIFIED?
	JMP	D.GOV	/NO, SKIP THE WRITE
	CAL	D.WRIT	/WRITE IT OUT
	CAL	WFCPB	/WAIT
	LAC	EV	/OK?
	SPA		/SKIP IF SO
	JMP	D.DKER	/NO - DISK ERROR
D.GOV	LAW	-400
	AND	D.CDA
	DAC	D.XDA
	LAC	D.CUN
	DAC	D.XUN
	XOR	D.XDA
	DAC	D.THIS	/SET UP THE NEW ONE AS BEING IN CORE
	CAL	D.READ	/READ IT IN
	CAL	WFCPB	/WAIT
	LAC	EV
	SPA		/OK?
	JMP	D.DKER	/NO
D.GOTX	LAC	(377
	AND	D.CDA
	DAC	D.OFST	/OFFSET INTO THE BLOCK
	TAD	(I.BLOK
	DAC	D.DSKA	/SET UP THE ADDRESS
	LAC	D.OFST
	AAC	-400
	DAC	D.OFST
	TAD	D.CWC	/ALL IN THIS BLOCK?
	DAC	D.CWC
	SMA		/YES, AND TOO MUCH MORE
	JMP	D.GXIT	/NO, OR EXACTLY,  LEAVE
	LAC	D.OFST
	TCA
	TAD	D.CWC
	TCA
	DAC	D.OFST
D.GXIT	LAC	D.OFST	/NOW UP THE PARAMETERS
	TCA		/FOR THE TRANSFER
	CLL
	TAD	D.CDA	/UP THE DISK ADDRESS
	DAC	D.CDA	/RESET
	SZL		/OVERFLOW?
	ISZ	D.CUN	/YES - UP THE UNIT NUMBER
	DZM	D.MODI	/CLEAR THE MODIFICATION FLAG
	JMP*	D.GETI	/LEAVE
D.CUN
D.CDA
D.CWC
D.CORA
D.CNT
D.OFST=D.CNT
D.XUN	0		/DISK CONTROL TABLE FOR REAL TRANSFERS
D.XDA	0
	I.BLOK
	400
D.THIS	-1		/CURRENT BLOCK
D.DSKA
D.MODI	0		/NOT YET MODIFIED
D.DKER	JMS*	(TYPE)
	D.MESG
	XX
	JMP	.-1
D.MESG	D.MEND-./2*1000+2 ; 0
	.ASCII	'***** DISK I/O ERROR - ABORT'<15>
D.MEND=.
/
/ DKPUT -- SUBROUTINE TO WRITE DISK PER 'PUTCPB'
/
DKPUT	0
	JMS	D.SETU	/SET UP
D.PLOP	JMS	D.GETI	/SET THE BLOCK PARAMETERS
	LAC*	D.CORA	/WRITING - MOVE FROM DORE
	DAC*	D.DSKA	/TO DISK
	ISZ	D.CORA
	ISZ	D.DSKA
	ISZ	D.CNT	/DONE?
	JMP	.-5	/NO
	LAC	D.CWC	/HAS THE WC GONE TO 0?
	SMA!SZA!CLC	/YES - SKIP
	JMP	D.PLOP	/NO - CONTINUE
	DAC	D.MODI	/SHOW THAT THE BLOCK HAS BEEN MODIFIED
	JMP*	DKPUT
/
/ CAL PARAMETER BLOCKS
/
WFCPB	20		/WAIT FOR 'EV'
	EV
/
REQCPB	1		/REQUEST RESIDENT MCR TASK
	0
	.SIXBT "..."
	.SIXBT "MCR"
	0
/
ENATDV	22		/ENABLE TASK "TDV...".
	0
	.SIXBT "TDV"
	.SIXBT "..."
	.IFDEF %DTCLD
/
CDTCPB	11		/CONNECT DECTAPE INTERRUPT LINE
	0
	4
	DTINT
/
DDTCPB	12		/DISCONNECT DECTAPE INTERRUPT LINE
	0
	4
	DTINT
	.ENDC
/
ALLCPB	1500		/ALLOCATE DISK STORAGE
	EV
	1
	DSKCT1
/
DALCPB	1600		/DEALLOCATE
	EV
	1
	DSKCT1
/
D.READ	3000		/GET -- DISK-TO-CORE XFR
	EV
	1
	D.XUN		/POINTER TO THE BUILT-UP CONTROL TABLE
/
D.WRIT	3100		/PUT -- CORE-TO-DISK XFR
	EV
	1
	D.XUN		/SAME AS ABOVE
/
EV	0		/GENERAL EVENT VARIABLE
/
/ DISK (DEVICE DEPENDENT) CONTROL TABLES
/
DSKCT1=.    /ALLOCATE-DEALLOCATE CONTROL TABLE
DKARS	0		/REQUIRED STORAGE IN WORDS
DKAUN	0		/UNIT OF ALLOCATED AREA
DKABA	0		/BASE ADDRESS OF ALLOCATED AREA
/
DSKCT2=.    /GET-PUT CONTROL TABLE
DKXUN	0		/UNIT NUMBER
DKXDA	0		/DISK ADDRESS
DKXCA	0		/CORE ADDRESS
DKXWC	0		/WORD COUNT
/
/ DISK BIT MAP -- 256 WORDS OF DISK STORAGE ARE REPRESENTED BY EACH
/ BIT -- 16 BITS PER MAP-WORD -- 4096 STORAGE WORDS ARE REPRESENTED 
/ BY EACH MAP-WORD -- 64 MAP-WORDS PER DISK UNIT.  THE BIT MAP IS
/ RECORDED AT DISK ADDRESS 777400 (THE 1ST 1/4 OF THE HIGHEST 256 WORDS).
/
DKBMAP	.BLOCK 100
/
/ 1ST UFD BLOCK.
/
	.LOC	DKBMAP
DKUFD	.BLOCK	400
/
	.EJECT
/ DECTAPE HANDLER
/
FW=000000	/FORWARD
RV=040000	/REVERSE
NG=000000	/NO GO (STOP)
GO=020000	/GO
NM=000000	/NORMAL MODE
CM=010000	/CONTINUOUS MODE
MV=000000	/MOVE
SE=001000	/SEARCH
RD=002000	/READ DATA
WD=004000	/WRITE DATA
DI=000000	/DISABLE DT INTERRUPTS
EI=000400	/ENABLE DT INTERRUPTS
CE=000000	/CLEAR ERR FLAG
PE=000200	/PRESERVE ERR FLAG
CD=000000	/CLEAR DONE FLAG
PD=000100	/PRESERVE DONE FLAG
/
DTCA=707541	/CLEAR STATUS REGISTER-A
DTRA=707552	/READ STATUS REGISTER-A
DTRB=707572	/READ STATUS REGISTER-B
DTXA=707544	/XOR AC INTO STATUS REG-A
DTLA=707545	/LOAD STATUS REG-A FROM AC
DTDF=707601	/SKIP ON DECTAPE DONE FLAG
DTEF=707561	/SKIP ON DECTAPE ERR FLAG
/
WCA	30	/WORD COUNT REGISTER ADDRESS
CAA	31	/CURRENT ADDRESS REGISTER ADDRESS
/
/ FTSK -- FIND FILES WITH "TSK" EXTENSIONS AND RECORD THE STARTING
/ BLOCK NUMBER AND THE TWO WORD TASK NAME IN THE FILE DESCRIPTION
/ TABLE ('FDT').  THE 'FDT' IS TERMINATED BY A ZERO ENTRY.
/
/
FTSK	0
	.IFDEF %DTCLD
	LAC	DTUN	/SELECT DECTAPE UNIT
	DTLA
	LAC	(RD!SE)	/SET RW-FLAG TO READ
	DAC	RWSW
	LAC	(JMP FXBLK) /FIND & READ BLOCK #100
	DAC	DISPX
	LAC	(100)
	JMS	WFDT
	.ENDC
	.IFUND %DTCLD
	CAL	DOTGET	/GET A UFD BLOCK FROM THE PACK
	JMS	.WFDP
	LAC	DBUF+377
	DAC	.NUFD	/POINTER TO NEXT UFD BLOCK (OR -1)
	.ENDC
/
	LAC	(FDT-1)/SETUP 'FSBN' INDEX
	DAC*	(X13)
	.IFDEF %DTCLD
	LAC	(DBUF+40)/SETUP XR & LR TO SCAN DIRECTORY
	.ENDC
	.IFUND %DTCLD
	LAC	(DBUF
	.ENDC
	AND	(007777)
	PAX
	.IFDEF %DTCLD
	TAD	(340)
	.ENDC
	.IFUND %DTCLD
/
/  WARNING FLAG ??><4><?? WHY NOT 374????
/
	TAD	(370
	.ENDC
	PAL
/
FTSK1	LAC	2,X	/"TSK" EXTENSION?
	SAD	(242313)
	SKP
	JMP	FTSK2	/NO -- AUG XR
	.IFDEF %DTCLD
	LAC	3,X	/YES -- IS EXISTENCE BIT SET?
	SMA
	.ENDC
	.IFUND %DTCLD
	LAC	0,X		/CHECK IF FILE EXISTS
	SNA
	.ENDC
	JMP	FTSK2	/NO -- AUG XR
	.IFDEF %DTCLD
	AND	(7777)	/YES -- RECORD FILE STARTING BLOCK NUMBER
	.ENDC
	.IFUND %DTCLD
	LAC	3,X
	AND	(77777
	.ENDC
	DAC*	X13	/AND TWO WORD TASK NAME
	LAC	0,X
	DAC*	X13
	LAC	1,X
	DAC*	X13
/
	.IFDEF %DTCLD
FTSK2	AXS	4	/AUGMENT X-REG -- END OF DIRECTORY?
	.ENDC
	.IFUND %DTCLD
FTSK2	AXS 10		/8 WORD ENTRIES IN THE UFD
	.ENDC
	JMP	FTSK1	/NO -- NEXT ENTRY
	DZM*	X13	/YES -- TERMINATE 'FDT'
	LAC	(FDT)	/AND SET SEEK POINTER 'SKPNTR'
	DAC	SKPNTR
/
	JMP*	FTSK	/EXIT
/
SKPNTR	0		/SEEK POINTER ('FDT' INDEX)
/
/ SEEK -- OPEN THE FILE WHOSE STARTING BLOCK NUMBER IS POINTED TO
/ BY 'SKPNTR' TO BE READ.
/
SEEK	0
	.IFDEF %DTCLD
	LAC	DTUN	/INITIALIZE FOR FORWARD DIRECTION READ
	DTLA
	LAW	-2
	DAC	DIROVS
	LAC	(JMS DIRFW)
	DAC	DIRFWV
	.ENDC
	.IFUND %DTCLD
	LAC*	SKPNTR
	JMS	DPNBLK
	.ENDC
	.IFDEF %DTCLD
/
	LAC*	SKPNTR	/SET 'NBT' & 'LBT' FOR STARTING BLOCK OF FILE
	DAC	LBT
	DAC	NBT
/
	LAC	(JMP FXBLK) /FIND & READ FIRST BLOCK OF FILE
	DAC	DISPX
	LAC	NBT
	JMS	WFDT
	.ENDC
	LAC	(DBUF)	/SET UNPACKING POINTER
	DAC	RDBFP
	JMP*	SEEK
/
/ READ -- WAIT FOR BLOCK READIN IF NECESSARY.  UNPACK AND 
/ TRANSFER A LOGICAL RECORD TO 'INBUF'.  INITIATE NEXT BLOCK
/ READ IF LAST RECORD OF BLOCK AND NOT LAST BLOCK OF FILE
/
READ	0
	LAC	(INBUF)	/SETUP LINE BUFFER ADDRESS
	DAC	UBUFA
	LAC	(21)	/SETUP MAX WORD-PAIR COUNT
	DAC	MAXWPC
/
READ1	DZM	CKSUM	/SETUP FOR A NEW RECORD
	LAC	UBUFA
	AAC	-1
	DAC*	(X10)
	DZM	RDVBTS
	.IFUND %DTCLD
	LAW -1		/DON'T ASSUME THAT THE 376TH WORD OF THE
	SAD	MAXCNT	/INPUT BUFFER IS 0 (BECAUSE IN DOS FILES
	JMP	READ4	/IT'S NOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	.ENDC
	JMS	RDFW	/FETCH FIRST WORD OF HEADER
	SAD	(1005)	/IS IT AN EOF?
	JMP	RDEOFX	/YES - SHOW IT
	LMQ
	ECLA!LLS 11
	SZA		/ZERO WORD-PAIR COUNT?
	JMP	READ2	/NO -- UNPACK RECORD FROM BUFFER
READ4	LAC	NBT
	SPA!CLA!CMA	/IS BLOCK NUMBER LEGAL?
			/BLOCK NUMBER IS NOT ALWAYS POSITIVE IF
			/AN ERROR HAS OCCURRED WHILE READING
			/SO THERE THIS TEST EXISTS
	JMP	ERR10	/DECTAPE ERROR
	LAC	NBT
	.IFDEF %DTCLD
	JMS	WFDT
	.ENDC
	.IFUND %DTCLD
	JMS	DPNBLK
	.ENDC
	LAC	(DBUF)
	DAC	RDBFP
	JMP	READ1
RDEOFX	DAC	INBUF	/SET THE EOF HEADER
	TCA		/AND CHECKSUM
	DAC	INBUF+1
	DZM	INBUF+2	/CLEAR THE FLAG
	LAW	-1	/BACK UP ONE
	TAD	RDBFP	/ON THE POINTER
	DAC	RDBFP	/SO WE WILL CONTINUE TO RETURN EOF
	JMP*	READ	/LEAVE
READ2	TCA		/SAVE 2'S COMPL WORD PAIR COUNT
	DAC	RDWPC
	TAD	MAXWPC	/IS RECORD TOO LONG?
	SMA!CLA
	JMP	READ3	/NO -- FETCH CHECKSUM WORD
	AAC	60	/YES -- INDICATE TRUNCATED RECORD
	JMS	RDSVB
	LAC	MAXWPC
	JMP	READ2
/
RDL1	JMS	RDFW
READ3	JMS	RDFW	/WORD PAIR COUNT OKAY -- FETCH CHECKSUM
/
RDXX	ISZ	RDWPC	/END OF RECORD?
	JMP	RDL1	/NO -- NEXT WORD PAIR
	LAC	CKSUM	/YES -- CHECKSUM OKAY?
	SNA!CLA
	JMP	RDXR	/YES -- SET VALIDITY BITS IN HEADER
	AAC	40	/NO -- INDICATE ERROR
	JMS	RDSVB
RDXR	LAC*	UBUFA	/SET VALIDITY BITS IN HEADER
	AND	(777717)
	XOR	RDVBTS
	DAC*	UBUFA
/
	JMP*	READ	/EXIT READ SUBROUTINE
/
/
	.IFUND %DTCLD
DPNBLK	0
	JMS	CONV
	CAL	DOTGET
	JMS	.WFDP
	LAW	-377	/RESET MAX READABLE WRDS/BLK COUNTER
	DAC	MAXCNT
	JMP*	DPNBLK
	.ENDC
/
RDSVB	0		/SET VALIDITY BITS SUBROUTINE
	DAC	RDSVB1
	LAC	RDVBTS
	SZA
	JMP*	RDSVB
	LAC	RDSVB1
	DAC	RDVBTS
	JMP*	RDSVB
/
RDVBTS	0
RDSVB1	0
/
RDWPC	0
RDBFP	0
CKSUM	0
/
RDFW	0
	LAC*	RDBFP
	DAC*	X10
	TAD	CKSUM
	DAC	CKSUM
	LAC*	RDBFP
	ISZ	RDBFP
	.IFUND %DTCLD
	ISZ MAXCNT
	NOP		/JUST IN CASE
	.ENDC
	JMP*	RDFW
/
/ WFDT -- SUBROUTINE TO WAIT FOR 'DTEV' TO BE SET NON-ZERO.
/         IF POSITIVE, OPERATION WAS PERFORMED.  IF NEGATIVE,
/         OPERATION WAS NOT PERFORMED, CLOSE UNIT, SET USER'S EVENT 
/         VARIABLE TO THE NEGATIVE QUANTITY, AND FETCH NEXT
/         REQUEST.
/
	.IFDEF %DTCLD
WFDT	0
	JMS	DISP
	CAL	WFDTEV
	LAW	-5
	DAC	ERCNT
	LAC	DTEV
	DZM	DTEV
	SMA
	JMP*	WFDT
/
	SAD	(-5)	/IS IT A SELECT ERROR
	SKP		/YES TELL USER
	JMP	ERR10	/DECTAPE ERROR
	CAL	NTRDY	/PRINT MESSAGE ON LUN 3
	CAL	WFDTEV	/WAIT FOR MESSAGE TO FINISH
	DZM	DTEV	/CLEAR EVENT VARIABLE
	LAC	OVSNRP	/SETUP OVERSHOOT PROTECTION DIRECTION
	SZA
	JMP	.+3
	LAC	(JMP FD1)
	SKP
	LAC	(JMP FD2)
	DAC	DISPX
/
MTWF	CAL	MTRQ	/10 TICK MARK TIME REQUEST
	DTXA+10		/CLEAR EF AND DT FLAGS
	CAL	WFDTEV	/WAIT FOR MARK TIME
	DTEF		/FLAGS CLEAR?
	SKP		/YES EXIT
	JMP	MTWF	/NO DO ANOTHER WAIT
	DZM	DTEV	/CLEAR EVENT VARIABLE
	JMP	WFDT+1
/
/ INTERRUPT BLOCK
/
DTINT	0
	DBA
	DAC	DTSVAC	/SAVE AC DURING INTERRUPT SERVICE
	JMS	DISP	/SERVICE INTERRUPT
	LAC	DTSVAC	/RESTORE AC BEFORE RETURNING
	DBR
	JMP*	DTINT	/RETURN TO NEXT TASK
/
/ DISPATCH
/
DISP	0
DISPX	XX		/DISPATCH SWITCH
/
/ FXBLK -- FIND & TRANSFER BLOCK WHOSE NUMBER IS IN AC
/
FXBLK	DAC	FDBLK	/SAVE BLOCK NUMBER
/
FD1	LAC	FDBLK	/SEARCH FORWARD
	JMS	SEARCH
	JMP	RWBLK	/BLOCK FOUND -- EXIT
	LAC	(FW!RV)	/OVERSHOOT -- SET REVERSE
	DTXA
	DAC	OVSNRP	/(DEPENDENT UPON INT FREE INST AFTER IOT)
FD2	LAC	DIROVS	/MOVE TAPE BACK TWO
	TAD	FDBLK
	JMS	SEARCH
	NOP		/OVERSHOOT IF BLK-2 IS 
	LAC	(FW!RV)	/SET FORWARD AND SEARCH FOR BLOCK
	DTXA
	DZM	OVSNRP	/(DEPENDENT UPON INT FREE INST AFTER IOT)
	JMP	FD1
/
/ DESIRED BLOCK NUMBER HAS BEEN FOUND, R/W BLOCK.  FLAGS ARE LEFT
/ SET UNTIL FUNCTION IS SWITCHED FORM SEARCH TO READ/WRITE SO THAT A
/ TIMING ERROR WILL OCCUR IF THE SWITCH IS NOT MADE BEFORE THE DATA 
/ AREA HAS REACHED THE R/W HEADS.
/
RWBLK	LAW	-400	/SET WORD COUNT FOR A STANDARD DECTAPE BLOCK (256 WDS)
	DAC*	WCA
	LAC	(JMP XFRFIN)/SET DISPATCH SWITCH
	DAC	DISPX
	LAC	RWSW	/CLEAR FLAGS AND SWITCH FROM SEARCH TO READ/WRITE
	DTXA		/(IOT MUST IMMEDIATELY PRECEDE 'JMP* DISP')
	JMP*	DISP	/EXIT -- WAIT FOR INTERRUPT
/
/ REQUESTED BLOCK HAS BEEN READ -- SETUP FOR NEXT BLOCK REQUEST
/
XFRFIN	DTEF		/ERR FLAG?
	SKP
	JMP	RETRY	/YES -- RETRY
	LAC	(NG!GO!DI!EI!CE!CD)/RESET GO-BIT, DISABLE INTERRUPTS,
	DTXA		/AND CLEAR DT FLAGS.
	LAC	NBT	/UPDATE 'NBT' & 'LBT'
	DAC	LBT
	LAC	DBUF+377
	DAC	NBT
	ISZ	DTEV	/SET EVENT VARIABLE POSITIVE
DIRFWV	NOP		/CHECK DIRECTION FOR NEXT BLOCK
/
XFINX	LAC	(401000)	/SET 6
	ISA
	LAC	(JMP FXBLK)	/SET DISPATCH SWITCH
	DAC	DISPX
	JMP*	DISP	/EXIT
/
FDBLK	0
DIROVS	-2	/OVERSHOOT BACKSPACE COUNT
/
/ DIRFW & DIRRV -- REVERSE THE DECTAPE DIRECTION WHEN NECESSARY
/
DIRFW	0
	TCA
	TAD	LBT
	SPA
	JMP*	DIRFW
	LAC	(2)
	DAC	DIROVS	/CHANGE DIRECTION
	LAC	(FW!RV)	/OF DECTAPE TO WRITE BACKWARDS
	DTXA
	LAC	(JMS	DIRRV)	/SET UP TRANSFER SWITCH
	DAC	DIRFWV
	JMP*	DIRFW
/
DIRRV	0
	TCA		/IN REVERSE DIRECTION
	TAD	LBT	/CHECK TO SEE IF DIRECTION CHANGE NEEDED
	SMA
	JMP*	DIRRV	/NO PROCEED
	LAW	-2
	DAC	DIROVS	/YES RESET POINTERS
	LAC	(FW!RV)
	DTXA		/AND REVERSE DECTAPE
	LAC	(JMS	DIRFW)
	DAC	DIRFWV
	JMP*	DIRRV
/
/ SEARCH -- SUBROUTINE TO SEARCH IN THE CURRENT DIRECTION FOR THE BLOCK
/           WHOSE BLOCK NUMBER IS IN AC.  RETURN WHEN THE BLOCK HAS BEEN FOUND.
/           THE DT FLAGS ARE CLEARED UPON ENTRY
/
/           IF BLOCK IS FOUND, RETURN AT JMS+1 WITH FLAGS LEFT SET
/           IF OVERSHOT, RETURN AT JMS+2 WITH GO-BIT & FLAGS CLEARED
/
SEARCH	0
	DAC	RBUF	/SAVE NUMBER OF REQUIRED BLOCK
SRCH2	LAC	(JMP SR1) /SET DISPATCH SWITCH
	DAC	DISPX
	DZM*	WCA	/SET WORD COUNT TO AVOID OVERFLOW
	LAC	(BBUF)	/SET CORE ADDRESS TO STORE BLOCK NUMBERS IN 'BBUF'
	DAC*	CAA
/
	DTRA		/ALTER NECESSARY BITS OF DT STATUS REGISTER A SUCH
			/THAT FUNCTION IS SEARCH, MODE IS NORMAL, THE GO-BIT IS SET,
			/INTERRUPTS ARE ENABLED, & THE FLAGS ARE CLEARED
			/(THE DIRECTION IS UNCHANGED).
	AND	(GO!NG!NM!CM!MV!SE!RD!WD!EI!DI)
	XOR	(GO!NM!SE!EI!PE!PD)
	DTXA		/(IOT MUST IMMEDIATELY PRECEDE 'JMP* DISP')
/
	JMP*	DISP	/EXIT -- WAIT FOR INTERRUPT
/
/ A BLOCK HAS BEEN READ
/
SR1	DTEF		/ERR FLAG?
	JMP	SR3	/NO -- DESIRED BLOCK CHECK
	DTRB		/YES -- END ZONE?
	AND	(270000)
	SNA
	JMP	SROVS	/YES -- EXIT AT JMS+2
RETRY	DTRB		/READ THE ERROR STATUS
	ISZ	ERCNT	/INCREMENT ERROR COUNT
	SKP!RTL		/PUT SELECT ERROR BIT IN BIT 0
	JMP	FATAL	/FATAL ERROR CAN'T RECOVER
	RAL	
	SPA!CLL		/IS IT A SELECT ERROR?
	JMP	SELER	/YES -- GO OUTPUT MESSAGE
	DTXA+10		/NO TRY AGAIN AND SEE IF IT CAN BE DONE THIS TIME
	JMP	SRCH2
/
FATAL	DTCA		/CLEAR DECTAPE STATUS
	LAW	-12
	DAC	DTEV
	JMP	XFINX	/SET EVENT VARIABLE TO NEGATIVE TO SIGNIFY FATAL ERROR
SELER	LAW	-5	/RESET THE ERROR COUNT
	DAC	DTEV
	LAC	(DI!EI)	/DISABLE INTERRUPT
	DTXA
	LAC	(401000)
	ISA		/SET SIGNIFICANT EVENT
	JMP*	DISP	/EXIT
SR3	LAC	BBUF	/DETERMINE DIFFERENCE BETWEEN DESIRED BLOCK
	AND	(1777)	/MASK OFF ILLEGAL BLOCK NUMBERS
	TCA		/AND JUST DETECTED BLOCK NUMBERS.
	TAD	RBUF
	SNA!CLL		/DESIRED BLOCK?
	JMP*	SEARCH	/YES -- EXIT SEARCH AT JMS+1 WITH FLAGS SET
	TCA
	SMA		/CALCULATE DIFFERENCE BETWEEN DESIRED BLOCK
	TCA!STL		/AND BLOCK FOUND
	DAC*	WCA	/PUT IN TWO'S COMPLEMENT IN BLOCK COUNTER (WORD COUNT)
/			/NO -- HAS DESIRED BLOCK BEEN OVERSHOT?
	DTRA
	AND	(FW!RV)
	SNA
	JMP	SR4
	SNL
	JMP	SROVS	/YES (OVERSHOOT) -- EXIT SEARCH AT JMS+2
	JMP	SR5	/NO (OVERSHOOT) -- CLEAR FLAGS & WAIT FOR NEXT INTERRUPT
SR4	SZL
	JMP	SROVS	/YES (OVERSHOOT) -- EXIT SEARCH AT JMS+2
SR5	LAC	(NM!CM)	/NO (OVERSHOOT) -- SET CONTINUOUS MODE SEARCH
	DTXA
	JMP*	DISP	/EXIT -- WAIT FOR INTERRUPT
/
/ CONTROL WILL BE TRANSFERRED TO 'SR1' AT NEXT INTERRUPT
/
SROVS	LAC	(GO!NG!CD!CE)	/RESET GO-BIT, CLEAR FLAGS, AND
	DTXA			/EXIT SEARCH ROUTINE AT JMS+2
	ISZ	SEARCH
	JMP*	SEARCH
	.ENDC
/
/
/
/
RBUF	0		/DESIRED BLOCK NUMBER (SEARCH)
/
	.IFDEF %DTCLD
NBT	0		/NEXT BLOCK TO BE TRANSFERRED
LBT	0		/LAST BLOCK TRANSFERRED
	.ENDC
/
BBUF	0		/BLOCK NUMBER BUFFER
DBUF	.BLOCK 400	/DECTAPE BLOCK BUFFER (MUST FOLLOW 'BBUF')
	.IFDEF %DTCLD
RWSW	0		/READ-WRITE SWITCH (CONSTANT TO SWITCH FROM SEARCH
	.ENDC
	.IFUND %DTCLD
MAXCNT	0
NBT=DBUF+377
	.ENDC
			/TO READ OR WRITE VIA XOR A-REG)
/
	.IFDEF %DTCLD
DTEV	0		/DECTAPE EVENT VARIABLE
DTUN	0		/TAPE UNIT NUMBER (BITS 0-2)
	.ENDC
MAXWPC	0		/MAX WORD-PAIR COUNT
UBUFA	0		/USER BUF ADDRESS
	.IFDEF %DTCLD
DTSVAC	0
/
ERCNT	-5
OVSNRP	0		/OVERSHOOT PROTECT FLAG
/
MTRQ	13		/MARK TIME REQUEST
	DTEV
	10		/10 TICKS
	1
/
NTRDY	2700
	DTEV
	3
	2
	NTMS-2
/
NTMS	.ASCII	"**** READY"
NTRD	.ASCII	" DT 0"<15>
/
WFDTEV	20
	DTEV
	.ENDC
.WFDP	0
	CAL	.WFEV
	LAC	..EV
	SMA
	JMP*	.WFDP
	DAC	CONV
	CAL	DP.ERR
	CAL	.WFEV
	LAC	CONV
	HLT
	JMP	SCONF
/
/
DOTGET	3000
	..EV
	1
	.GETCT
/
/
.GETCT	XX
.GTCT1	XX
	DBUF
	400
/
/  WARNING FLAG ??><5><?? IS OK FOR RF TOO?????
/
CONV
	LMQ
	ECLA!LLSS!10
	DAC	.GETCT
	LACQ
	DAC	.GTCT1
	JMP*	CONV
/
/
..EV
.NUFD
/
/
DP.ERR	2700
	..EV
	3
	2
	NTMS-2
/
	.IFUND	%DTCLD
/
NTMS	.ASCII "DISK PACK ERROR; EV IN AC."<15>
	.ENDC
/
.WFEV	20
	..EV
	.LTORG
/
/
/
	.END
