	.TITLE *** RSX DISK FILES HANDLER. RESIDENT CODE
/
/ COPYRIGHT (C) 1975
/ DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/ THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/ THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/ SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/ VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/ EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/ THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/ SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/ WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/ MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/ DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/ OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY
/ DEC.
/
	.EJECT
/
/	EDIT	#75	26 JUN 75	C. PROTEAU
/					M. HEBENSTREIT
/
/
/ DEFINING %RF15 PRODUCES A VERSION FOR THE RF DISK.
/ DEFINING %RP02 PRODUCES A VERSION FOR THE RP02 DISK PACK.
/ DEFINING %RK05 PRODUCES A VERSION FOR THE RK05 CARTIDGE DISK.
/
	.IFUND %RF15
	.IFUND %RP02
	.IFUND %RK05
	.END    NO ASSEMBLY PARAMETERS SPECIFIED
	.ENDC
	.ENDC
	.ENDC
/
/ RSX PLUS FILE HANDLER FOR THE RP02, RK05, OR THE RF15. TWO
/ TYPES OF FILES ARE HANDLED: (1) SEQUENTIAL ACCESS FILES CONSISTING OF
/ NON-CONTIGUOUS DISK BLOCKS AND (2) RANDOM ACCESS FILES CONSISTING OF
/ CONTIGUOUS DISK STORAGE. BECAUSE I/O REQUESTS ARE PROCESSED ONE AT A
/ TIME BY THIS TASK, THE FUNCTIONS TO GET DATA FROM AND PUT DATA INTO
/ A RANDOM ACCESS FILE ARE HANDLED BY THE DISK I/O DRIVER TASK, WHICH
/ IS PART OF THE RESIDENT CODE WITH THE EXECUTIVE. ALSO, FOR SEQUENTIAL
/ FILES, THE I/O DRIVER PERFORMS THE ACTUAL DATA TRANSFERS (GET & PUT)
/ AND ALSO ALLOCATES AND DEALLOCATES DISK SPACE IN BLOCK INCREMENTS OF
/ 256 DECIMAL WORDS.
/
/ NOTE WELL -- RANDOM ACCESS FILES ARE OPENED AND CLOSED ONLY WHEN THEY
/ ARE TO BE RENAMED, NOT WHEN THEY ARE BEING ACCESSED. CONSEQUENTLY,
/ THERE IS NO PROTECTION AGAINST CONFLICT OF INTEREST WHEN TWO OR MORE
/ TASKS REFERENCE THE SAME RANDOM ACCESS FILE.
/
/ RECOGNIZED I/O FUNCTIONS:
/
/	16	CREATE (RANDOM ACCESS FILE)
/	17	ABORT
/	23	PREAL
/	26	INPUT (READ)
/	27	OUTPUT (WRITE)
/	32	SEEK (OPEN SEQUENTIAL FILE FOR INPUT)
/	33	ENTER (OPEN SEQUENTIAL FILE FOR OUTPUT)
/	34	CLOSE
/	35	DELETE
/	36	HINF
/	37	RENAME (OPEN FILE FOR RENAMING)
/	134	ERROR CLOSE
/	777	DISCONNECT AND EXIT
/
/ LEGAL I/O COMMAND SEQUENCES:
/
/	BRACKETED ITEMS [] INDICATE SEQUENCES THAT MAY BE REPEATED.
/
/	SEEK -- [READ] -- CLOSE
/
/	ENTER -- [WRITE] -- CLOSE
/
/	RENAME -- CLOSE
/
/	DELETE
/
/	ABORT, HINF, PREAL, OR CREATE (LEGAL ANYTIME)
/
/	DISCONNECT & EXIT
/
/ LEGAL DATA MODES FOR SEQUENTIAL FILE ACCESS:
/
/	0	IOPS BINARY
/	1	IMAGE BINARY
/	2	IOPS ASCII
/	3	IMAGE ASCII
/
/ LABELLING CONVENTION:
/
/	ALL ADDRESS TAGS DEFINED WITHIN THIS TASK
/	BEGIN WITH "RF".
/
/	COMMENT LINES WHERE ERRORS ARE DETECTED ARE
/	FORMATTED AS FOLLOWS:	/#/ COMMENT
/
/ RF15 DECDISK STATUS REGISTER BITS:
/
/	0	THE "INCLUSIVE OR" OF BITS 1 THRU 7 (THE ERROR FLAG)
/	1	HARDWARE ERROR
/	2	ADDRESS PARITY ERROR
/	3	MISSED TRANSFER
/	4	WRITE CHECK ERROR
/	5	DATA PARITY ERROR
/	6	WRITE LOCKOUT
/	7	NON-EXISTENT DISK
/	8	DATA CHANNEL TIMING ERROR
/	9	PROGRAMMING ERROR
/	10	DONE FLAG
/
	.EJECT
/ EVENT VARIABLES RETURNED:
/
/	+340002		VALUE SET BY THE HINF FUNCTION TO INDI-
/			CATE DEVICE CODE 2 AND DIRECTORY-ORIENTED
/			FILE INPUT AND OUTPUT.	(USED FOR THE RF DISK)
/
/	+340N03		IS THE HINF VALUE FOR THE RP02.
/	+340N24		IS THE HINF VALUE FOR THE RK05.
/			(N INDICATES THE UNIT NUMBER)
/
/
/	+1		NORMAL VALUE RETURNED FOR COMPLETION OF OPERATION.
/
/	-5		ILLEGAL HEADER WORD (THE DATA MODE IN THE
/			HEADER DOES NOT MATCH THE DATA MODE
/			ASSOCIATED WITH THE READ DIRECTIVE).
/			AN END-OF-FILE BLOCK IS AN EXCEPTION
/			SINCE THE MODE INDICATOR IS 5.
/
/	-6		UNIMPLEMENTED OR ILLEGAL CAL FUNCTION.
/			FUNCTION MIGHT BE LEGAL IN A DIFFERENT CONTEXT.
/
/	-7		ILLEGAL DATA MODE.
/
/	-10		SOME FILE STILL OPEN BY THIS TASK ON THIS LUN.
/
/	-11		FILE NOT OPEN.
/
/	-13		FILE NOT FOUND.
/
/	-15		MEDIUM FULL
/
/	-16		ILLEGAL INPUT BUFFER SIZE (SIZE MUST BE +3 OR LARGER)
/			OR ILLEGAL OUTPUT WORD-PAIR-COUNT.
/
/	-23		ILLEGAL INPUT WORD-PAIR-COUNT.
/
/	-25		BUFFER PREALLOCATION UNSUCCESSFUL -- NOT ENOUGH
/			ROOM IN THE PARTITION.
/
/	-30		I/O PARAMETER EXCEEDS THE PARTITION BOUNDS.
/
/	-33		UNINITIALIZED DIRECTORY OR DISMOUNTED UNIT
/
/	-50		RENAME ERROR -- FILE ALREADY EXISTS IN UFD
/
/	-51		ILLEGAL TO READ A TRUNCATED FILE
/
/	-52		INPUT FILE HAS NO END-OF-FILE RECORD.
/
/	-53		ILLEGAL (NULL) FILE NAME OR EXTENSION.
/
/	-54		THIS FILE ALREADY OPEN.
/
/	-55		THIS FILE ALREADY OPEN FOR MODIFICATION.
/
/	-56		NO I/O BUFFER AVAILABLE.
/
/	-57		SEQUENTIAL/RANDOM ACCESS FILE CONFLICT. "ENTER"
/			IS ILLEGAL IF THE FILE ALREADY EXISTS AS A
/			RANDOM ACCESS FILE. "CREATE" IS ILLEGAL IF THE
/			FILE ALREADY EXISTS AS A SEQUENTIAL ACCESS FILE.
/
/	-60		RANDOM ACCESS FILE EXISTS. SIZE DOESN'T MATCH
/			THE SIZE IN THE "CREATE" REQUEST.
/
/	-61		RANDOM ACCESS FILE EXISTS. ACCOUNTING INFORMA-
/			TION IN THE FILE DIRECTORY ENTRY DIFFERS FROM
/			THAT GIVEN IN THE "CREATE" REQUEST.
/
/	-62		RANDOM ACCESS FILE SIZE ERROR. SIZE REQUESTED
/			IS EITHER NEGATIVE OR GREATER THAN 777 OCTAL BLOCKS.
/
/	-203		CAL NOT ISSUED FROM TASK LEVEL.
/
/	-N		DISK ERROR (CODE = STATUS REGISTER CONTENTS)
/
/	-777		"POOL" EMPTY.
/
	.EJECT
/ NOTES ON ORGANIZATION AND OPERATION:
/
/ I/O REQUESTS ARE PROCESSED ONE AT A TIME; NO ATTEMPT IS MADE TO OVERLAP
/ I/O OPERATIONS. THIS DECISION WAS MADE IN ORDER TO REDUCE THE TIME IT
/ WOULD TAKE TO IMPLEMENT AND TEST THIS TASK AND TO ALLOW IT TO BE SEG-
/ MENTED INTO OVERLAYS, AS FOLLOWS:
/
/	.-------.-----------.
/	1	1	    1
/	1	1 OVERLAY 1 1
/	1	1	    1
/	1	.-----------.
/	1 RESI- 1	    1
/	1 DENT  1 OVERLAY 2 1
/	1	1	    1
/	1 CODE  .-----------.
/	1	1	    1
/	1	1 OVERLAY 3 1
/	1	1	    1
/	1	.-----------.
/	1	1	    1
/	1	1 OVERLAY 4 1
/	1	1	    1
/	1	.-----------.
/	1	1	    1
/	1	1 OVERLAY 5 1
/	1	1	    1
/	.-------.-----------.
/	(LOW CORE)	(HIGH CORE)
/
/ RESIDENT CODE:	TASK INITIALIZATION
/			I/O FUNCTION DISPATCH
/			HINF, PREAL AND EXIT
/			BLOCK ALLOCATE AND DEALLOCATE
/			I/O REQUEST COMPLETION
/
/ OVERLAY 1:		SEEK (OPEN SEQUENTIAL FILE FOR INPUT)
/			ENTER (OPEN SEQUENTIAL FILE FOR OUTPUT)
/			RENAME (OPEN FILE FOR RENAMING)
/
/ OVERLAY 2:		READ FROM SEQUENTIAL FILE
/			WRITE INTO SEQUENTIAL FILE
/
/ OVERLAY 3:		CLOSE FILE
/			ABORT TASK I/O
/
/ OVERLAY 4:		DELETE FILE
/
/ OVERLAY 5:		CREATE (RANDOM ACCESS FILE)
/
	.EJECT
/ EXTERNALLY DEFINED GLOBAL SYMBOLS.
/
	.GLOBL	RFOPEN,RFREAD,RFCLOS,RFDLET,RFCREA
/
/ INTERNALLY DEFINED GLOBAL SYMBOLS.
/
	.GLOBL	RFRQND,RFALUN,RFAL1B,RFSREV,RFGTBL,RFPTBL,RFBFAD,RFPDNA
	.GLOBL	RFFLBF,RFOPED,RFSTL,RFFCNT,RFCLFL,RFGPC1,RFCNVT,RFGPCT,RFLUNN
/
	.IFUND %RF15
	.GLOBL RFUNIT,RFCNTT,RFDNAT
	.ENDC
/
/ DEFINITION OF REGISTERS LOCATED WITHIN THE RSX EXECUTIVE.
/
R1=101				/GENERAL REGISTER #1.
R2=102				/GENERAL REGISTER #2.
R4=104				/GENERAL REGISTER #4.
NADD=107			/ENTRY POINT TO "ADD NODE TO DEQUE" SUBROUTINE.
NDEL=112			/ENTRY POINT TO "DELETE NODE FROM DEQUE"
				/SUBROUTINE.
SNAM=123			/ENTRY POINT TO "SEARCH
				/FOR NODE IN DEQUE UNDER
				/THIS NAME" SUBROUTINE.
SPRI=126			/ENTRY POINT TO "SEARCH DEQUE FOR PRIORITY
				/AND INSERT NODE" SUBROUTINE.
	.IFDEF %RF15
RFACTB=210			/LOCATION OF 3-WORD CONTROL TABLE USED
				/BY THIS HANDLER FOR ALLOCATING DISK
				/STOREAGE. STORAGE IS DEALLOCATED
				/WHENEVER THE MCR FUNCTION TASK ...SAV
				/IS REQUESTED.
				/WORD0=DESIRED STORAGE/STORAGE GRANTED.
				/WORD1=DISK PLATTER.
				/WORD2=DISK ADDRESS.
	.ENDC
	.IFDEF %RP02
RPACT0=364			/1ST WORD OF 1ST CTA FOR DISK PACK ALLOCATES
	.ENDC
	.IFDEF %RK05
RKACT0=414			/1ST WORD OF 1ST CTA FOR CARTIDGE DISK ALLOCATES
	.ENDC
POOL=240			/HEAD OF THE EMPTY NODES DEQUE.
STKL=242			/HEAD OF SYSTEM TASK LIST DEQUE.
PDVL=252			/HEAD OF THE PHYSICAL DEVICE LIST QUEUE.
DQRQ=337			/ENTRY POINT TO "DE-QUEUE REQUEST" SUBROUTINE.
IOCD=345			/ENTRY POINT TO "DECREMENT I/O PENDING
				/COUNT" SUBROUTINE.
PABF=350			/ENTRY POINT TO "PREALLOCATE BUFFER" SUBR.
DABF=356			/ENTRY POINT TO "DEALLOCATE BUFFER" SUBR.
	.IFUND %RF15
X10=10
	.ENDC
/
/ IOT AND PARAMETER DEFINITIONS.
/
.INH=705522			/INHIBIT INTERRUPTS.
.ENB=705521			/ENABLE INTERRUPTS.
IDX=ISZ				/IDX IS USED INSTEAD OF ISZ WHEN THE
				/INTENT IS TO ADD 1 TO A REGISTER BUT
				/NOT TO SKIP.
RFNFSD=22			/NUMBER OF FILE STATUS DESCRIPTORS.
	.IFUND %RF15
ECLA=641000			/CLEAR THE AC WITH AN EAE INSTUCTION
	.ENDC
	.TITLE *** USER FILE DIRECTORY (UFD)
/
/ DOS-15 EMPLOYS TWO TYPES OF FILE DIRECTORY. AT THE BASE OF THE SYSTEM
/ IS THE MASTER FILE DIRECTORY (MFD), WHICH IS A CATALOGUE OF THE NAMES
/ AND STARTING LOCATIONS OF ALL THE USER FILE DIRECTORIES (UFD). EACH
/ USER FILE DIRECTORY IS A LIST OF FILES. EACH FILE ENTRY CONSISTS OF
/ A FILE NAME AND RELEVANT INFORMATION ABOUT THE FILE, SUCH AS, ITS FIRST
/ DATA BLOCK NUMBER.
/
/ THE SIZE OF THE UFD IS UNLIMITED BECAUSE IT IS MADE UP OF LINKED
/ DISK BLOCKS.
/
/ EXAMPLE:      A 3-BLOCK UFD
/
/       1ST	2ND		3RD
/       UFD	UFD		UFD
/       BLOCK	BLOCK		BLOCK
/
/ XXXXXXXXX	XXXXXXXXX	XXXXXXXXX
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X       X     X       X       X       X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ X	  X	X	X	X	X
/ XXXXXXXXX	XXXXXXXXX	XXXXXXXXX
/ X	  X     X       X       X       X
/ X NONE  X<--------O   X<----------O   X
/ X       X     X       X       X       X
/ XXXXXXXXX	XXXXXXXXX	XXXXXXXXX
/ X       X     X       X       X       X
/ X   O-------->X   O---------->X NONE  X
/ X       X     X       X       X       X
/ XXXXXXXXX	XXXXXXXXX	XXXXXXXXX
/
	.EJECT
/ THERE ARE TWO FILE ENTRY FORMATS -- ONE FOR SEQUENTIAL ACCESS FILES
/ AND ANOTHER FOR RANDOM ACCESS FILES -- DETERMINED BY THE STATE OF
/ BIT 0 IN ENTRY WORD 4.
/
/ THE FORMAT OF A SEQUENTIAL ACCESS FILE ENTRY IN THE UFD AS SHOWN BELOW
/ IS DERIVED FROM DOS-15.
/
/ UFD SEQUENTIAL ACCESS FILE ENTRY FORMAT (IN GENERAL):
/
/ WORD	CONTENTS	MEANING
/
/ 0	.SIXBT "FIL" FILE NAME (1ST HALF) OR 0 IF FILE ENTRY IS FREE.
/ 1	.SIXBT "NAM" FILE NAME (2ND HALF) OR 0 IF FILE ENTRY IS FREE.
/ 2	.SIXBT "EXT" FILE EXTENSION OR 0 IF FILE ENTRY IS FREE.
/ 3	T+FB		T (BIT 0) = 1 IF FILE IS TRUNCATED (SEE DEF. BELOW).
/			FB (BITS 1-17) = 1ST BLOCK NUMBER OF THE FILE.
/ 4	TYPE+NB		TYPE (BIT 0) = 0 = A SEQUENTIAL ACCESS FILE.
/			NB (BITS 2-17) = NUMBER OF DATA BLOCKS IN THE FILE.
/ 5	RB		FIRST BLOCK NUMBER OF THE RETRIEVAL INFORMATION
/
/ 6	PC+WD		PC (BITS 0-2) = FILE PROTECTION CODE.(SET TO 1 IN RSX)
/			WD = THE WORD WITHIN THE FINAL FILE DATA BLOCK
/				IN WHICH THE RIB STARTS (0 IF THE RIB
/				CANNOT FIT AND THEREFORE MUST START IN
/				A BLOCK ALL ITS OWN).
/ 7	DATE		DATE THE FILE WAS CREATED:       MM/DD/YY
/				(YY = 0 FOR 1970).
/
/	.
/	.
/	.
/
/ 376	PB		PREVIOUS UFD BLOCK NUMBER OR -1 IF NONE.
/ 377	NB		NEXT UFD BLOCK NUMBER OR -1 IF NONE.
	.EJECT
/
/ DESCRIPTION OF TABLES IN THE EXECUTIVE TO ALLOW MULTIPLE UFD'S
/
/
/ RSX SUPPORTS MULTIPLE UFD'S FOR ALL DISK ATTACHED TO THE SYSTEM.
/ WHEN A LUN IS ASSIGNED TO A DISK, SOME UFD SPECIFICATION IS MADE
/ BY REASSIGN FOR THAT DISK-LUN PAIR. THE USER HAS THE CHOICE OF
/ NAMING A UFD IN REASSIGN'S COMMAND STRING OR ACCEPTING THE DEFAULT
/ UFD. WHEN REASSIGN HAS OBTAINED THE UFD NAME AND MADE SURE THAT THE
/ UFD IS INITIALIZED IN THE MFD, REASSIGN ENTERS THE UFD NAME IN THE
/ LUN-UFD TABLE FOR THE LUNS BEING ASSIGNED TO THE DISK. IF THE USER
/ DOES NOT TYPE A UFD NAME TO REASSIGN, THE REASSIGN WILL LOOK UP
/ THE DEFAULT UFD IN THE DISK-UFD TABLE FOR THE SPECIFIED DISK.
/ THE DISMOUNT MCR FUNCTION (DSM) WILL LOGICALLY DISMOUNT A USER
/ DISK BY ZEROING THE DEFAULT UFD NAME IN THE DISK-UFD TABLE AND
/ ZEROING ALL ENTRIES IN THE LUN-UFD TABLE FOR THE DISK SPECIFIED.
/ WHEN A DISK IS LOGICALLY MOUNTED, MOUNT WILL ENTER THE DEFAULT 
/ UFD NAME INTO THE DISK-UFD TABLE AND INTO ALL ENTRIES OF THE LUN-
/ UFD TABLE FOR LUNS ASSIGNED TO THE DISK.
/
/ HENCE THERE CAN BE AS MANY UFD'S ACTIVE FOR A DISK AS THERE ARE LUNS
/ ASSIGNED TO THE DISK.
/
/ NOTE: THE FIRST BLOCK OF THE MFD FOR THE THREE TYPES OF DISK IS
/ AS FOLLOWS.
/
/ RF -- 1777
/ RP -- 47040
/ RK -- 1777
/
	.EJECT
/
/
/ DEFINITION OF A TRUNCATED SEQUENTIAL ACCESS FILE:
/
/ WHEN A FILE IS OPENED FOR OUTPUT, A UFD ENTRY IS MADE THEN AND THERE
/ (INSTEAD OF WHEN THE FILE IS CLOSED) SO THAT OTHER SEQUENTIAL OUTPUT
/ FILES CAN BE OPENED AT THE SAME TIME. UNTIL THE FILE IS PROPERLY
/ CLOSED, IT CANNOT BE READ OR DELETED BECAUSE NEITHER THE NUMBER OF THE
/ FIRST DATA BLOCK (WORD 3) NOR THE TOTAL NUMBER OF BLOCKS (WORD 4) HAS
/ BEEN RECORDED. SUCH A FILE, FOLLOWING DOS-15 CONVENTION, IS CALLED A
/ "TRUNCATED FILE", WHOSE UFD ENTRY WORD 3 HAS BIT 0=1. EXCEPT WHEN A
/ FILE IS BEING CREATED, TRUNCATED FILES SHOULD NOT EXIST UNLESS THE
/ DISK IS MALFUNCTIONING.
/
	.EJECT
/ THE FORMAT OF A RANDOM ACCESS FILE ENTRY IN THE UFD IS DEPICTED BELOW.
/ NOTE THAT THIS IS ENTIRELY DIFFERENT FROM THE TYPE OF RANDOM ACCESS
/ FILE USED IN DOS-15. THE FILE ENTRY KEY, WHICH DISTINGUISHES ONE FOR-
/ MAT FROM ANOTHER, IS BIT 0 IN ENTRY WORD 4.
/
/ UFD RANDOM ACCESS FILE ENTRY FORMAT:
/
/ WORD	CONTENTS	MEANING
/
/ 0	.SIXBT "FIL" FILE NAME (1ST HALF) OR 0 IF FILE ENTRY IS FREE.
/ 1	.SIXBT "NAM" FILE NAME (2ND HALF) OR 0 IF FILE ENTRY IS FREE.
/ 2	.SIXBT "EXT" FILE NAME EXTENSION OR 0 IF FILE ENTRY IS FREE.
/ 3	FB		BIT 0 = 0 (UNUSED).
/			FB (BITS 1-17) = 1ST BLOCK NUMBER OF THE FILE.
/ 4	TYPE+NB		TYPE (BIT 0) = 1 = RANDOM ACCESS FILE.
/			NB (BITS 2-17) = NUMBER OF DATA BLOCKS IN THE FILE.
/ 5	ACCT1		ACCOUNTING INFORMATION (NUMBER OF RECORDS IN THE
/			FILE, IF FILE CREATED BY FORTRAN'S CALL DEFINE).
/ 6	ACCT2		ACCOUNTING INFORMATION (RECORD SIZE, IF FILE
/			CREATED BY FORTRAN'S CALL DEFINE).
/ 7	DATE		DATE THE FILE WAS CREATED: MM/DD/YY
/				(YY = 0 FOR 1970).
/
/	.
/	.
/	.
/
/ 376	PB		PREVIOUS UFD BLOCK NUMBER OR -1 IF NONE.
/ 377	NB		NEXT UFD BLOCK NUMBER OR -1 IF NONE.
	.TITLE *** INITIALIZATION CODE/VARIABLES
/
/ HANDLER INITIALIZATION CODE -- CONTROL STARTS AT THIS POINT AS A RESULT
/ OF A "REQUEST" BY THE MCR TASK "REASSIGN".
/
/ THIS CODE IS EXECUTED ONLY ONCE -- IT RESIDES WITHIN THIS HANDLER'S
/ INTERNAL FILE DATA BUFFER.
/
/ *******************************************************************
/
/ ************************* OVERLAYED *******************************
/
RFINIT	LAC	RFSTKL		/ADDRESS OF THE STL DEQUE.
	DAC*	(R1)
	LAC	RFHNAM		/ADDRESS OF: .SIXBT "RX...."
	DAC*	(R2)
	JMS*	RFSNAM		/SCAN THE SYSTEM TASK LIST FOR THE RX FILE
				/HANDLER'S NODE.
				/(R1, R2, R6, X17, XR & AC ARE ALTERED).
				/WAS THE NODE FOUND?
	CAL	(10)		/#/ NO -- EXIT.
	DAC	RFSTL		/YES -- SAVE THE NODE ADDRESS.
/
	.IFDEF %RF15
	LAC	RFPDVL		/ADDRESS OF THE PHYSICAL DEVICE LIST QUEUE.
	DAC*	(R1)
	LAC	RFPNAM		/ADDRESS OF: .SIXBT "RF@@@@".
	DAC*	(R2)
	JMS*	RFSNAM		/SCAN THE PHYSICAL DEVICE
				/LIST FOR THE RF DISK
				/FILE HANDLER'S NODE.
				/(R1, R2, R6, XR & AC ARE ALTERED).
/
/ NOTE -- THE RF DISK FILE HANDLER HAS A DIFFERENT PHYSICAL DEVICE
/ NODE THAN DOES THE RF DISK DRIVER. THIS IS DONE SO THAT EACH TASK
/ MAY HAVE ITS OWN I/O REQUEST QUEUE.
/
				/WAS THE NODE FOUND?
	CAL	(10)		/#/ NO -- EXIT.
	DAC	RFPDNA		/YES -- SAVE THE NODE ADDRESS.
/
/ SAVE THE ADDRESS OF THE REGISTER IN THE PHYSICAL DEVICE LIST NODE
/ WHICH IS SUPPOSED TO CONTAIN THE ADDRESS OF RF'S TRIGGER EVENT
/ VARIBALE. THEN, STORE THE TRIGGER EVENT VARIABLE ADDRESS IN THE
/ PHYSICAL DEVICE LIST NODE.
/
	AAC	+10
	DAC	RFPDEV
	LAC	RFPTTG		/PICK UP THE ADDRESS OF THE TRIGGER EVENT VARIABLE.
	DAC*	RFPDEV
/
	.EJECT
/ COMPUTE AND STORE THE INDEX REGISTER ADJUSTMENT FACTOR. WHEN USING
/ THE CONTENTS OF THE INDEX REGISTER AS A BASE ADDRESS AND THE ADDRESS
/ OPERAND AS A CONSTANT OFFSET, AS IN   LAC 3,X , ONE MUST ADD AN
/ ADJUSTMENT FACTOR TO THE CONTENTS OF THE XR TO OFFSET THE ADDRESS
/ OPERAND'S IMPLIED PAGE BITS.
/
	AND	RF70K		/SAVE THE PAGE BITS
	DAC	RFPAGE		/AS SUCH AND ALSO
	TCA			/AS A NEGATIVE
	DAC	RFXADJ		/ADJUSTMENT FACTOR.
	JMP	RF.TW		/WAIT FOR TRIGGER.
	.ENDC
	.IFUND %RF15
/
/ COMPUTE AND STORE THE XR ADJUSTMENT FACTOR
/
	DZM	RFUCNT		/CLEAR THE UNIT COUNTER
	LAC	RFPTTG		/FIX THE X ADJUST. FOR THE TRIGGER ADDR.
	AND	RF70K
	DAC	RFPAGE
	TCA
	DAC	RFXADJ
/
/ CONSTRUCT A TABLE OF PDVL NODE ADDRESSES FOR EACH UNIT
/
	LAC	(RFDNAT-1	/INIT. X10 TO POINT AT TABLE
	DAC*	(X10		/OF PDVL NODE ADDRESSES
	LAC	RFPDVL		/SET XR TO ACCESS PDVL LISTHEAD
	JMS	RFADJX
	LAC	0,X		/GET ADDR. OF 1ST PDVL NODE
RFINI1	JMS	RFADJX		/SET XR TO ACCESS PDVL NODE
	LAC	2,X		/GET NAME FROM A PDVL NODE
	SAD	RFNAME		/IS NAME=RX? (RP OR RK)
	SKP
	JMP	RFINI2		/NO -- CHECK NEXT NODE
	LAC	3,X
	SZA
	JMP	RFINI2
	LAC	6,X		/YES -- MAKE SURE THE PDVL NODE IS INIT.
	DAC	7,X
	DZM	11,X
	PXA			/SAVE THE NODE'S ADDRESS
	TAD	RFPAGE		/IN RFDNAT TABLE
	DAC*	X10
	LAC	RFPTTG		/PUT TRIGGER ADDR. INTO PDVL NODE
	DAC	10,X
	IDX	RFUCNT		/INCR. UNIT COUNTER
RFINI2	LAC     0,X		/TEST FOR END OF PDVL DEQUE
	SAD	RFPDVL
	SKP
	JMP	RFINI1		/NOT END OF DEQUE
	JMP	RF.TW		/ WAIT FOR THE TRIGGER
	.ENDC
/
/ DATA CONSTANTS USED ONLY DURING THE INITIALIZATION CODE.
/
	.IFDEF %RF15
RFNAME	.SIXBT	"RF@@@@"
	.ENDC
	.IFDEF %RP02
RFNAME	.SIXBT	"RP@@@@"
	.ENDC
	.IFDEF %RK05
RFNAME	.SIXBT	"RK@@@@"
	.ENDC
RFPDVL	PDVL			/ADDRESS OF THE PHYSICAL DEVICE
				/LIST QUEUE.
RFPNAM	RFNAME
RF70K	070000			/PAGE BIT MASK.
RFPTTG	RFTGEV			/ADDRESS OF THE TRIGGER EVENT VARIABLE.
RFSNAM	SNAM			/ADDRESS OF THE EXECUTIVE'S SNAM ROUTINE.
RFSTKL	STKL			/ADDRESS OF THE SYSTEM TASK LIST.
	.IFDEF %RF15
RFTNAM	.SIXBT	"RF...."
	.ENDC
	.IFDEF %RP02
RFTNAM	.SIXBT	"RP...."
	.ENDC
	.IFDEF %RK05
RFTNAM	.SIXBT	"RK...."
	.ENDC
RFHNAM	RFTNAM
/
/ ********************* END OF OVERLAYABLE CODE *******************
/
/ *****************************************************************
/
/ THE FOLLOWING IS THIS HANDLER'S OWN FILE DATA BUFFER, WHICH CONTAINS
/ SPACE FOR FILE STATUS DESCRIPTORS AND FOR A 256-WORD DATA BLOCK (SEE
/ FILE BUFFER STRUCTURE DESCRIPTION AT THE END OF THE RESIDENT CODE
/ LISTING). SUCH A BUFFER, NOT SUPPLIED BY SOME OTHER TASK, IS NECESSARY
/ SO THAT THE PROCESS OF DELETING OLD SEQUENTIAL ACCESS FILES CAN GO ON
/ WHILE OTHER FILES ARE OPENED. IT IS ALSO USED DURING RIB CREATION.
/
	.LOC	RFINIT
RFFLBF	.BLOCK	RFNFSD+400
/
/ THE FOLLOWING TWO TABLES ARE USED ONLY FOR DEVICES HAVING MORE THAN
/ ONE UNIT, NAMELY THE RP02 AND THE RK05. THE FIRST OF THESE TABLES
/ IS A LIST OF THE PDVL NODE ADDRESSES FOR EACH UNIT.   THE SECOND TABLE
/ CONTAINS THE COUNT OF OPEN FILES FOR EACH UNIT.
/
/ BEFORE DISPATCHING TO PROCESS AN I/O REQUEST RFPDNA AND RFFCNT ARE
/ SET TO CORRESPOND TO THE CORRECT TABLE ENTRY. WHEN THE PROCESS IS
/ COMPLETE THE TABLE ENTRY IS RESET TO THE NEW VALUE FOR RFFCNT.
/ RFCLOS ACCESSES THESE TABLES, WHEREAS THE OTHER OVERLAYS DON'T,
/ BECAUSE ON ABORT OR DISCONNECT AND EXIT MANY FILES MUST BE CLOSED
/ AND THEY MIGHT BE ON DIFFERENT UNITS.
/
	.IFUND %RF15
RFDNAT=.
	.REPT 10		/TABLE OF ADDR. OF PDVL NODES
	0
RFCNTT=.
	.REPT 10		/TABLE OF OPEN FILES COUNTERS
	0
	.ENDC
	.EJECT
	.TITLE *** PICK NEXT I/O REQUEST
/
/ WAIT FOR THE TASK TO BE TRIGGERED, WHICH WILL OCCUR AS THE RESULT
/ OF ONE OF TWO THINGS:
/
/	1 -- AN I/O REQUEST ENTERED BY THE "QUEUE I/O" CAL SERVICE
/	ROUTINE.
/
/	2 -- AN "ABORT" REQUEST ENTERED BY THE I/O RUNDOWN TASK "IORD".
/
RF.TW	CAL	RFWFTG		/"WAITFOR" RF FILE HANDLER TRIGGER
				/EVENT VARIABLE TO BE SET.
	DZM	RFTGEV		/CLEAR THE TRIGGER.
/
/ THE TASK HAS BEEN TRIGGERED. CHECK IF THERE IS ANYTHING
/ IN THE I/O REQUEST QUEUE IN THE PHYSICAL DEVICE NODE.
/
	.IFDEF %RF15
RFPICK	LAC	RFPDNA		/PUT PDVL NODE ADDR
	DAC*	(R1)		/INTO R1.
	JMS*	(DQRQ)		/DE-QUEUE AN I/O REQUEST.
				/(R1, R2, R4, R5, R6, XR & AC ARE ALTERED).
				/WAS A REQUEST FOUND?
	JMP	RF.TW		/NO.
	.ENDC
	.IFUND %RF15
/
/ FOR MULTIPLE UNITS NODES ARE DE-QUEUED BY PRIORITY
/
RFPICK	LAC       (RFDNAT-1		/SET X10 SO THE RFDNAT TABLE
	DAC*	(X10		/CAN BE SCANNED.
	LAW	-1500		/SET THE INITIAL PRIORITY VERY LOW
	DAC	RFTMP2
	LAC	RFUCNT		/SET THE COUNTER OF THE NO. OF UNITS CHECKED
	TCA
	DAC	RFTMP1		/SAVE 2'S COMP. IN RFTMP1
RFPCK1	LAC*    X10		/GET ADDR. OF A PDVL NODE
	JMS	RFADJX		/SET XR TO ACCESS THE PDVL NODE
	PXA			/COMPUTE THE ADDRESS OF WORD 6 IN THIS PDVL NODE
	TAD	RFPAGE
	AAC	6
	SAD	6,X		/ARE ANY NODES QUEUED?
	JMP	RFPCK2		/NO -- CHECK THE NEXT UNIT
	LAC	6,X		/YES -- SET XR TO ACCESS QUEUED NODE
	JMS	RFADJX
	LAC	4,X		/GET PRIORITY OF THIS REQUEST
	TAD	RFTMP2		/SUBTRACT CURRENT PRIORITY
	SPA			/IS THIS NODES PRIO. HIGHER THAN CURRENT PRIO.?
	JMP	RFPCK3		/YES -- THIS NODES PRIO IS HIGH
RFPCK2	ISZ     RFTMP1		/NO -- WAS THIS THE LAST UNIT?
	JMP	RFPCK1		/NO -- LOOK AT NEXT PDVL NODE
	LAW	-1500		/YES -- ANY NODES DETECTED?
	SAD	RFTMP2
	JMP	RF.TW		/NO -- WAIT FOR TRIGGER
	LAC	RFTMP3		/YES -- SET UP TO DEQUEUE A REQUEST NODE
	DAC*	(R1
	JMS*	(DQRQ		/DEQUEUE A NODE
	JMP	RF.TW		/NO NODE FOUND SO WAIT
	JMP	RFPCK4		/GOT THE NODE GO PROCESS IT.
RFPCK3	LAC     4,X		/SAVE THE NEW PRIORITY
	TCA
	DAC	RFTMP2
	LAC*	(X10		/SAVE THE ADDRESS OF THE PDVL NODE
	DAC	RFTMP3
	LAC*	RFTMP3
	DAC	RFTMP3
	JMP	RFPCK2		/GO LOOK AT NEXT PDVL NODE
	.ENDC
RFPCK4	DAC     RFRQND		/YES -- SAVE ITS ADDRESS
	JMS	RFADJX		/SET UP THE XR TO ACCESS
				/THE REQUEST NODE.
	LAC	6,X		/SAVE THE ADDRESS (OR 0
	DAC	RFRQEV		/IF NONE) OF THE REQUESTOR'S
				/EVENT VARIABLE.
	LAC	2,X		/WAS THIS DIRECTIVE ISSUED FROM TASK LEVEL?
	SNA
	JMP	RFNTSK		/#/NO -- ERROR.
	LAC	5,X		/GET THE LUN TO WHICH REQ. WAS MADE
	AND	(777000
	SWHA
	DAC	RFLUNN		/SAVE IT
	.IFUND %RF15
	PXA			/SAVE THE XR
	DAC	RFTMP1
	LAC	RFTMP3		/GET ADDR. OF PDVL HAVING THIS NODE
	DAC	RFPDNA		/SAVE THE ADDRESS
	JMS	RFADJX		/SET XR TO ACCESS PDVL NODE
	LAC	5,X		/GET THE UNIT NO.
	DAC	RFUNIT		/SAVE IT
	TAD	(RFCNTT		/GET COUNT OF OPEN FILES FOR THIS UNIT
	DAC	RFTMP2
	LAC*	RFTMP2
	DAC	RFFCNT		/SAVE IT
	LAC	RFTMP1		/RESTORE THE XR
	PAX
	.ENDC
/
	.EJECT
/ FETCH THE CAL FUNCTION CODE AND DISPATCH TO THE APPROPRIATE ROUTINE.
/ THE AC, CONTAINING THE FUNCTION CODE, IS PASSED ON TO EACH OVERLAY.
/
	LAC	5,X		/EXAMINE THE CAL FUNCTION CODE.
	AND	(777)
	SNA
	JMP	RFDEAL		/RF HANDLER'S INTERNAL DEALLOCATE.
	SAD	(016)
	JMS*	RFCREA		/CREATE.
	SAD	(017)
	JMS*	RFCLOS		/ABORT.
	SAD	(023)
	JMP	RFPRAL		/PREAL.
	SAD	(026)
	JMS*	RFREAD		/INPUT (READ).
	SAD	(027)
	JMS*	RFREAD		/OUTPUT (WRITE).
	SAD	(032)
	JMS*	RFOPEN		/SEEK.
	SAD	(033)
	JMS*	RFOPEN		/ENTER.
	SAD	(034)
	JMS*	RFCLOS		/CLOSE.
	SAD	(035)
	JMS*	RFDLET		/DELETE.
	SAD	(036)
	JMP	RFHINF		/HINF.
	SAD	(037)
	JMS*	RFOPEN		/RENAME.
	SAD	(134)
	JMS*	RFCLOS		/ERROR CLOSE.
	SAD	(777)
	JMP	RFEXIT		/DISCONNECT & EXIT.
/
/#/ UNIMPLEMENTED OR ILLEGAL FUNCTION.
/
RFIFNC	LAW	-6
RFSTFL	DAC	RFCLFL		/SET FLAG SO FILE WILL BE CLOSED IF
				/ONE IS OPEN.
	JMP	RFSREV		/SET REQUESTOR'S EVENT VARIABLE.
/
/#/ CAL NOT ISSUED FROM TASK.
/
RFNTSK	LAW	-203
	JMP	RFSREV
	.TITLE *** HINF/PREALLOCATE
/
/ HINF (HANDLER INFORMATION) FUNCTION. SET THE REQUESTOR'S EVENT
/ VARIABLE TO INDICATE THAT THE HANDLER PERFORMS
/ DIRECTORY-ORIENTED INPUT AND OUTPUT.
/
	.IFDEF %RF15
RFHINF	LAC	(340002)
	.ENDC
	.IFUND %RF15
RFHINF	LAC       RFUNIT
	CLL
	ALS	6
	.IFDEF %RP02
	TAD	(340003
	.ENDC
	.IFDEF %RK05
	TAD	(340024
	.ENDC
	.ENDC
	JMP	RFSREV
/
/ PREALLOCATE SPACE AT THE TOP OF THE TASK'S PARTITION FOR I/O BUFFERS.
/ THIS IS DONE FOR TASKS, SUCH AS THE ASSEMBLER, WHICH MUST RESERVE
/ SPACE FOR BUFFERS BEFORE THEY CAN GRAB REMAINING FREE CORE.
/
RFPRAL	LAC	RFRQND		/SET R2 WITH THE I/O REQUEST NODE ADDRESS.
	DAC*	(R2)
	LAC	(400+RFNFSD) /SET R4 WITH THE DESIRED BUFFER SIZE.
	DAC*	(R4)
	JMS*	(PABF)		/PREALLOCATE BUFFER SPACE.
				/(R4, R5, XR & AC ARE ALTERED).
	SKP			/#/ ERROR RETURN.
	JMP	.+3		/SUCCESSFUL RETURN.
	LAW	-25
	JMP	RFSTFL
	CLA!IAC
	JMP	RFSREV
	.TITLE *** DISCONNECT & EXIT
/
/ DISCONNECT THE INTERRUPT LINE, CLEAN UP, AND THEN EXIT (AN I/O REQUEST
/ MADE BY THE "REASSIGN" MCR TASK). DISCONNECT IS NOT DONE SINCE THIS
/ HANDLER IS NOT CONNECTED TO AN INTERRUPT LINE.
/
/ "REASSIGN" WILL TELL THE OPERATOR WHEN THIS HANDLER HAS OPEN FILES,
/ BUT THE OPERATOR MAY CHOOSE TO REASSIGN ANYWAY. IN CASE THIS SHOULD
/ HAPPEN AND A REQUEST TO EXIT RESULTS, A SCAN IS MADE HERE OF THE ACTIVE
/ LUNS DEQUE TO CLOSE ALL FILES.
/
RFEXIT	LAC	(777)		/CALL THE "CLOSE" OVERLAY TO CLOSE ALL
	JMS*	RFCLOS		/OPEN FILES, RELINQUISH SYSTEM RESOURCES,
				/AND RETURN HERE WHEN DONE.
	JMS	RFRTND		/RETURN THE I/O REQUEST NODE TO
				/THE POOL OF EMPTY NODES.
				/(R2, R6, XR AND AC ARE ALTERED).
	.IFDEF %RF15
	LAC	(RFACTB		/DEALLOCATE ALL THE SPARE DISK BLOCKS
	DAC	RFDALO+3
	CAL	RFDALO
	CAL	RFWAIT
	DZM*	(RFACTB
	.ENDC
	.IFUND %RF15
	LAC	RFUCNT		/SET TMP1 WITH 2'S COMP. OF NO. OF UNITS
	TCA
	DAC	RFTMP1
	.IFDEF %RP02
	LAC	(RPACT0		/GET ADDR. OF 1ST ALLO. CONTROL TABLE
	.ENDC
	.IFDEF %RK05
	LAC	(RKACT0
	.ENDC
	DAC	RFTMP2		/SAVE IT
RFEXT1	DAC     RFDALO+3	/DEALLOCATE BLOCKS FOR THIS UNIT
	CAL	RFDALO
	CAL	RFWAIT
	DZM*	RFTMP2
	LAC	RFTMP2		/GET NEXT CTA
	AAC	3
	DAC	RFTMP2		/SAVE IT
	ISZ	RFTMP1		/END OF ALL UNITS ?
	JMP	RFEXT1		/NO -- DEALLOCATE FOR NEXT UNIT
	.ENDC			/YES
	.IFDEF %RF15
	.INH			/INHIBIT INTERRUPTS.
	IDX	RFPDEV		/CLEAR THE "ASSIGN INHIBIT" FLAG LOCATED
	DZM*	RFPDEV		/IN THE PHYSICAL DEVICE NODE.
	.ENB			/ENABLE INTERRUPTS.
	.ENDC
	.IFUND %RF15
	LAC	RFUCNT		/SET UP 2'S COMP OF NO. OF UNITS
	TCA
	DAC	RFTMP1
	LAC	(RFDNAT		/SET TMP2 TO ACCESS RFDNAT TABLE
	DAC	RFTMP2
	.INH
RFEXT2	LAC*    RFTMP2		/GET ADDR. OF WORD IN PDVL NODE HAVING ASS. INH. FLAG
	AAC	11
	DAC	RFTMP3		/SAVE IT
	DZM*	RFTMP3		/ZERO THE WORD IN THE PDVL NODE
	IDX	RFTMP2		/INCR. PTR TO RFDNAT TABLE TO ACCESS NEXT NODE
	ISZ	RFTMP1		/END OF TABLE?
	JMP	RFEXT2		/NO -- FIX NEXT PDVL NODE
	.ENB			/YES -- EXIT
	.ENDC
	CAL	(10)		/EXIT.
	.TITLE *** DEALLOCATE
/
/ NORMAL DEALLOCATE REQUESTS ARE I/O FUNCTION CODE 16. THIS FORM OF
/ DEALLOCATE IS ENTERED WITH FUNCTION CODE 0 AND IS STRICTLY INTERNAL
/ TO THIS I/O HANDLER. THE REQUEST NODE CONTAINS THE NUMBER OF THE
/ STARTING BLOCK OF SOME FILE WHICH HAS BEEN DELETED AND ALSO THE NUMBER
/ OF BLOCKS IN THE FILE. IF IT IS A SEQUENTIAL ACCESS FILE, DEALLOCATION
/ WILL TERMINATE EITHER WHEN THE COUNT RUNS OUT OR WHEN THE FORWARD
/ LINKAGE WORD IN THE FINAL BLOCK IS -1. THE FOLLOWING CODE WILL READ
/ SEQUENTIALLY THROUGH THE FILE AND DEALLOCATE BLOCKS IN TURN. IF IT IS
/ A RANDOM ACCESS FILE, ITS BLOCKS ARE DEALLOCATED ALL AT ONCE SINCE
/ THEY ARE CONTIGUOUS.
/
RFDEAL	777000			/IF THE LUN IS NON-0, THIS I/O REQUEST
	AND	5,X		/WAS MADE OUTSIDE OF THIS HANDLER AND
	SZA			/IS THEN AN ILLEGAL FUNCTION.
	JMP	RFIFNC		/#/
	LAC	7,X		/SAVE THE FILE'S START BLOCK.
	PAL
	LAC	10,X		/EXAMINE THE FILE TYPE INDICATOR (BIT 0).
	SPA
	JMP	RFDERA		/ITS A RANDOM ACCESS FILE.
/
/ DEALLOCATE BLOCKS FROM A SEQUENTIAL ACCESS FILE.
/
	AAC	-1		/DECREMENT THE BLOCK COUNT AND SAVE THE
	DAC	10,X		/RESULT IN THE MQ.
	LMQ
	LAC	(RFFLBF)	/SET THE XR TO POINT TO THE BUFFER
	DAC	RFBFAD		/AND SAVE THE "CURRENT BUFFER" ADDRESS.
	JMS	RFADJX
	PLA
	DAC	RF.BLK,X
	LACQ			/IS THE BLOCK COUNT NOW 0 (INDICATING THAT
	SNA!CLC			/THIS IS THE FINAL BLOCK)?
	JMP	RFDEFB		/YES.
	JMS	RFGTBL		/NO -- GET CURRENT BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED. THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
				/DISK ERROR?
	SKP!CLC			/#/ YES -- PRETEND THIS IS THE FINAL BLOCK.
	LAC	RF.DAT+377,X /NO -- SAVE THE FORWARD LINKAGE WORD AS
RFDEFB	DAC	RF.NXB,X	/THE NEXT BLOCK.
/
	.EJECT
/ SET UP THE DEALLOCATE CONTROL TABLE.
/
	LAC	(400)		/SET THE WORD COUNT FOR ONE BLOCK'S WORTH.
	DAC	RFDACT+0
	CLL
	LAC	RF.BLK,X	/COMPUTE THE PLATTER NUMBER.
	SNA
	JMP	RFNODA
	.IFDEF %RF15
	LRS	12
	DAC	RFDACT+1
	LAC	RF.BLK,X	/COMPUTE THE DISK ADDRESS.
	AND	(1777)
	ALS	10
	.ENDC
	.IFUND %RF15
	LMQ
	LLSS!ECLA 10
	DAC	RFDACT+1
	LAC	RFUNIT
	ALS	17
	TAD	RFDACT+1
	DAC	RFDACT+1
	LACQ
	.ENDC
	DAC	RFDACT+2
	LAC	RF.NXB,X	/IS THIS THE FINAL BLOCK?
	SAD	(-1)
	JMP	RFDAFN		/YES.
	PAL			/NO.
	LAC	RFRQND		/SET THE XR TO POINT TO THE I/O REQUEST NODE.
	DAC*	(R2)
	JMS	RFADJX
	PLA			/STORE THE NEW BLOCK NUMBER IN PLACE OF
	DAC	7,X		/THE OLD.
	LAC	RFPDNA
	AAC	+6
	DAC*	(R1)
	JMS*	(SPRI)		/INSERT THE NODE BY PRIORITY.
				/(R1, R2, R3, R6, XR & AC ARE ALTERED).
	JMP	RFDCAL
/
/ DEALLOCATE BLOCKS FROM A RANDOM ACCESS FILE.
/
RFDERA	AND	(377777)	/# OF BLOCKS IS IN THE AC.
	CLL			/MULTIPLY BY THE NUMBER OF WORDS
	ALS	10		/PER BLOCK (MAY RESULT IN A NEGATIVE
				/NUMBER, WHICH IS ACTUALLY A LARGE, POSI-
				/TIVE 18-BIT NUMBER).
	DAC	RFDACT+0	/STORE THE WORD COUNT.
	CLL			/COMPUTE THE PLATTER NUMBER.
	LAC	7,X
	.IFDEF %RF15
	LRS	12
	DAC	RFDACT+1
	LAC	7,X		/COMPUTE THE DISK ADDRESS.
	AND	(1777)
	ALS	10
	.ENDC
	.IFUND %RF15
	LMQ
	LLSS!ECLA 10
	DAC	RFDACT+1
	LAC	RFUNIT
	ALS	17
	TAD	RFDACT+1
	DAC	RFDACT+1
	LACQ
	.ENDC
	DAC	RFDACT+2
/
RFDAFN	JMS	RFRTND		/RELINQUISH THE I/O REQUEST NODE.
				/(R2, R6, XR & AC ARE ALTERED).
RFDCAL	CAL	RFDALO		/DEALLOCATE.
	CAL	RFWAIT		/WAITFOR COMPLETION SO THAT DEALLOCATE
				/NODES DON'T PILE UP.
	JMP	RFPICK		/SEE IF ANOTHER I/O REQUEST IS PENDING.
RFNODA	JMS	RFRTND		/DEAL. OF BLK 0 IS ILLEGAL SO RETURN
	JMP	RFPICK		/THE NODE AND SEE IF A REQ. IS WAITING
	.TITLE *** I/O REQUEST COMPLETED
/
/ SET THE REQUESTOR'S EVENT VARIABLE (IF ANY).
/ IF AN ERROR OCCURRED, THE ERROR CODE IS IN
/ THE AC AND ENTRY IS AT THIS LOCATION. THE
/ HINF FUNCTION TRANSFERS HERE WITH THE HINF
/ CODE IN THE AC.
/
RFSREV	PAL			/SAVE VALUE TEMPORARILY.
	LAC	RFRQEV		/DID THE REQUESTER SPECIFY AN EVENT
	SNA			/VARIABLE ADDRESS?
	JMP	RFIOCD		/NO.
	JMS	RFADJX		/YES -- SET THE XR TO POINT TO THE EVENT
	PLA			/VARIABLE.
	DAC	0,X
RFIOCD	LAC	RFRQND		/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	LAC	RFCLFL		/CHECK IF AN ERROR OCCURRED THAT SHOULD
	SZA			/CAUSE A FILE TO BE CLOSED. IF SO, DON'T
	JMP	RFERCL		/DECREMENT THE TRANSFERS PENDING COUNT
				/BECAUSE THAT WILL BE DONE FOLLOWING THE
				/CLOSE.
	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).
	JMP	RFRLND
/
/ SUCCESSFUL COMPLETION OF A FILE OPEN DIRECTIVE WILL RETURN HERE WITH
/ +1 IN THE LR TO BYPASS DECREMENTING THE I/O PENDING COUNT. WHEN THE
/ FILE IS CLOSED, THE COUNT IS DOUBLY DECREMENTED TO MAKE UP FOR THIS.
/ THIS IS DONE SO THAT I/O RUNDOWN WILL ALWAYS BE INVOKED FOR A TASK THAT
/ HAS EXITED OR IS BEING ABORTED IF THE TASK HAS AN OPEN FILE.
/
RFOPED	LAC	RFRQEV		/DID THE REQUESTOR SPECIFY
	SNA			/AN EVENT VARIABLE ADDRESS?
	JMP	RFRLND		/NO.
	JMS	RFADJX		/YES -- SET THE XR TO POINT TO THE
	PLA			/EVENT VARIABLE.
	DAC	0,X
	JMP	RFRLND
/
/ AN ERROR OCCURRED WHICH REQUIRES THAT THE CURRENTLY OPEN FILE BE
/ CLOSED. QUEUE AN I/O REQUEST AS IF THE TASK HAD ISSUED AN "ERROR CLOSE"
/ COMMAND (SPECIFYING NO EVENT VARIABLE). SOME ERRORS WILL CAUSE THE
/ FLAG TO BE SET WITHOUT TESTING TO SEE IF A FILE IS OPEN.
/
RFERCL	DZM	RFCLFL		/CLEAR THE FLAG.
	LAC	RFRQND		/I/O REQUEST NODE ADDRESS.
	JMS	RFADJX
	777000			/CHANGE THE RIGHT HALF (FUNCTION CODE)
	AND	5,X		/TO 134 TO SIGNIFY "ERROR CLOSE".
	AAC	134
	DAC	5,X
	DZM	6,X		/CLEAR THE EVENT VARIABLE ADDRESS.
	DZM	7,X		/CLEAR THE FILE NAME AND EXTENSION
	DZM	10,X		/IN CASE THE FILE IS OPEN FOR RENAMING.
	DZM	11,X
/
	LAC	RFPDNA		/SET UP THE ADDRESS OF THE I/O REQUEST QUEUE.
	AAC	+6
	DAC*	(R1)
	LAC	RFRQND		/SET UP THE ADDRESS OF THE "TASK NAME"
	AAC	+2		/(REALLY AN STL POINTER).
	DAC*	(R2)
	JMS*	(SNAM)		/SCAN THE REQUEST QUEUE FOR A NODE ENTERED
				/UNDER THIS TASK NAME.
				/(R1, R2, R6, X17, XR & AC ARE ALTERED).
				/WAS A NODE FOUND?
	JMP	RFSPRI		/NO.
	JMS	RFADJX		/YES -- PICK UP ITS BACKWARD POINTER SO
	LAC	1,X		/THAT THE "CLOSE" REQUEST CAN BE INSERTED
	DAC*	(R1)		/BEFORE ANY OTHER REQUESTS MADE BY THIS TASK.
	LAC	RFRQND		/I/O REQUEST NODE ADDRESS.
	DAC*	(R2)
	JMS*	(NADD)		/ADD NODE TO DEQUE.
				/(R2, R6, XR & AC ARE ALTERED).
	JMP	RFSET6
/
RFSPRI	LAC	RFPDNA		/COMPUTE THE ADDRESS OF THE I/O REQUEST QUEUE.
	AAC	+6
	DAC*	(R1)
	LAC	RFRQND		/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	JMS*	(SPRI)		/SINCE THERE ARE NO OTHER REQUESTS IN THE
				/QUEUE MADE BY THIS TASK, SIMPLY INSERT
				/THE "CLOSE" REQUEST IN ORDER OF TASK PRIORITY.
				/(R1, R2, R3, R6, XR & AC ARE ALTERED).
	JMP	RFSET6
/
RFRLND	JMS	RFRTND		/RETURN THE I/O REQUEST NODE TO THE POOL
				/OF EMPTY NODES.
				/(R2, R6, XR & AC ARE ALTERED).
	.IFUND %RF15
	LAC	(RFCNTT		/UPDATE THE COUNT OF OPEN FILES TABLE
	TAD	RFUNIT
	DAC	RFTMP1
	LAC	RFFCNT
	DAC*	RFTMP1
	.ENDC
/
/ DECLARE A SIGNIFICANT EVENT BY POSTING
/ AN API LEVEL 6 INTERRUPT.
/
RFSET6	LAC	(401000)
	ISA
	JMP	RFPICK		/SEE IF ANOTHER I/O REQUEST IS PENDING.
	.TITLE *** ALLOCATE DISK SPACE SUBROUTINE
/
/ SUBROUTINE RFAL1B -- ALLOCATES ONE DISK FILE BLOCK (256 DECIMAL WORDS).
/ THIS ROUTINE ATTEMPTS TO MAINTAIN A GENERAL RESERVE OF DISK BLOCKS TO
/ BE DOLED OUT ONE AT A TIME FOR ANY I/O OPERATION BY ANY TASK. THIS IS
/ DONE IN ORDER TO CUT DOWN THE NUMBER OF DISK ACCESSES REQUIRED FOR
/ SPACE ALLOCATION.     THE CONTROL TABLE "RFACTB" IS LOCATED IN THE
/ SYSTEM COMMUNICATION AREA WITHIN THE EXECUTIVE SO THAT THE ALLOCATED
/ BLOCKS CAN BE DEALLOCATED BY THE MCR FUNCTION TASK ...SAV.    THIS
/ PREVENTS WRITING OVER EXISTING FILES FOLLOWING WARM STARTS.
/
/ CALLING SEQUENCE:
/
/	JMS	RFAL1B
/	(RETURN HERE WITH ERROR CODE IN THE AC)
/	(RETURN HERE WITH THE BLOCK NUMBER IN THE AC
/	AND THE XR LEFT POINTING AT THE FILE BUFFER)
/
/ ALTERED REGISTERS:
/
/	EFFECTIVELY ALL (DUE TO THE CAL) & RFTMP1
/
RFAL1B	0
	PXA			/SAVE THE XR.
	DAC	RFXRTP
/
/ CHECK IF THE RESERVE OF DISK BLOCKS IS EMPTY.
/
	.IFDEF %RF15
RFALCK	LAC*	(RFACTB)	/NUMBER OF AVAILABLE DISK WORDS.
	SNA
	JMP	RFALMT		/NONE.
	TAD	(-400)		/DECREMENT THE NUMBER OF WORDS REMAINING
	DAC*	(RFACTB)	/BY 400 (THE SIZE OF A FILE BLOCK).
	CLL
	LAC*	(RFACTB+1)	/EACH DISK PLATTER CONTAINS 2000 OCTAL
	ALS	12		/FILE BLOCKS.
	DAC	RFTMP1
	LAC*	(RFACTB+2)	/CONVERT THE DISK ADDRESS TO A FILE
	LRS	10		/BLOCK NUMBER.
	TAD	RFTMP1
	LMQ			/SAVE THE BLOCK NUMBER IN THE MQ.
	LAC*	(RFACTB+2)	/UPDATE THE DISK ADDRESS BY 400 OCTAL.
	TAD	(400)
	DAC*	(RFACTB+2)
	.ENDC
	.IFUND %RF15
RFALCK	CLL			/GET ADDRESS OF CORRECT CTA
	LAC	RFUNIT
	MUL
	3
	LACQ
	.IFDEF %RP02
	TAD	(RPACT0
	.ENDC
	.IFDEF %RK05
	TAD	(RKACT0
	.ENDC
	DAC	RFTMP1		/SAVE IT
	IAC
	DAC	RFTMP2		/GET ADDR. OF WORD 1 IN TABLE
	IAC
	DAC	RFTMP3		/GET ADDR. OF WORD 2 IN TABLE
	LAC	RFTMP1		/PUT ADDR. OF CTA INTO CPB
	DAC	RFALC8+3
	LAC*	RFTMP1		/ARE THERE ANY BLOCKS TO BE GIVEN OUT?
	SNA
	JMP	RFALMT		/NO -- ALLOCATE SOME
	TAD	(-400		/YES -- GET ONE OUT
	DAC*	RFTMP1		/GET THE BLOCK NO.
	LAC*	RFTMP3		/GET DISK ADDR. AND SAVE IN MQ
	LMQ
	LAC*	RFTMP2		/GET PLATTER NO.
	AND	(007777		/REMOVE UNIT NO.
	LRSS	10		/LEAVE BLOCK NO. IN MQ
	CLL
	LAC*	RFTMP3		/UPDATE THE DISK ADDRESS
	TAD	(400
	DAC*	RFTMP3
	SZL			/IF LINK GETS SET INCR. PLATTER NO.
	IDX*	RFTMP2
	.ENDC
	LAC	RFXRTP		/RESTORE THE XR.
	PAX
	IDX	RFAL1B		/SKIP ON RETURN AND RETURN WITH THE
	LACQ			/BLOCK NUMBER IN THE AC.
	.IFUND %RF15
	JMS	RFALSR		/UPDATE THE RFALAR AND RFALCT TABLES
	.ENDC
	JMP*	RFAL1B
/
/ THERE ARE NO FILE BLOCKS AVAILABLE.
/
RFALMT	CLL
	.IFUND %RF15
	LAC	(RFALT1		/GET RFALAR AND RFALCT FOR THIS UNIT
	TAD	RFUNIT
	DAC	RFTMP3
	LAC	(RFALT2
	TAD	RFUNIT
	DAC	RFTMP2
	LAC*	RFTMP3
	DAC	RFALAR
	LAC*	RFTMP2
	DAC	RFALCT
	.ENDC
	LAC	RFALAR		/CHANGE THE NUMBER OF 400-WORD FILE BLOCKS
	ALS	10		/TO THE NUMBER OF WORDS.
	.IFDEF %RF15
	DAC*	(RFACTB)
	.ENDC
	.IFUND %RF15
	DAC*	RFTMP1		/ENTER NO. OF WORDS AND UNIT NO.
	LAC	RFTMP1		/GET A PTR TO PLACE WHERE UNIT SHOULD
	IAC			/BE ENTERED
	DAC	RFTMP2
	CLL
	LAC	RFUNIT
	ALS	17
	DAC*	RFTMP2		/ENTER UNIT NO.
	.ENDC
	CAL	RFALC8		/ALLOCATE.
	CAL	RFWAIT		/WAITFOR COMPLETION.
	LAC	RFIOEV
	SMA			/WAS THERE AN ERROR?
	JMP	RFALCH		/NO.
/
/ THE ALLOCATE WAS NOT SUCCESSFULLY PERFORMED. IF THE AMOUNT REQUESTED
/ WAS MORE THAN 1 BLOCK, DIVIDE THAT AMOUNT IN TWO AND TRY AGAIN.
/
	LAC	RFALAR		/AMOUNT REQUESTED = 1?
	SAD	(1)
	JMP	RFALER		/#/ YES -- ERROR.
	RCR			/NO -- DIVIDE BY 2.
	DAC	RFALAR
	.IFUND %RF15
	DAC*	RFTMP3
	.ENDC
/
/ EACH TIME THE AMOUNT TO BE ALLOCATED IS HALVED, 8 SUCCESSFUL
/ ALLOCATES MUST BE PERFORMED AT THE HALVED VALUE BEFORE THE
/ FULL VALUE IS REINSTATED.
/
	LAW	-10
	DAC	RFALCT
	JMP	RFALMT
/
/ ALLOCATE WAS SUCCESSFUL. BEFORE DOLING OUT A BLOCK TO THE CALLER,
/ CHECK THE REPEAT COUNT TO SEE IF THE AMOUNT TO BE ALLOCATED SHOULD
/ BE DOUBLED.
/
RFALCH	LAC	RFALCT		/IS THE REPEAT COUNT NON-0?
	SNA
	JMP	RFALCK		/NO.
	ISZ	RFALCT		/YES -- WHEN THE COUNT RUNS OUT, DOUBLE
	JMP	RFALCK		/THE AMOUNT TO BE ALLOCATED NEXT TIME.
	LAC	RFALAR
	RCL
	DAC	RFALAR
	SAD	(10)		/BACK UP TO THE MAXIMUM OF 8?
	JMP	RFALCK		/YES.
	LAW	-10		/NO -- RESET THE REPEAT COUNT SO THAT
	DAC	RFALCT		/THE AMOUNT TO BE ALLOCATED WILL NOT
	JMP	RFALCK		/BE DOUBLED AGAIN UNTIL AFTER 8 SUCCESSFUL
				/ALLOCATES.
/
/#/ 1 BLOCK CANNOT BE ALLOCATED EITHER BECAUSE THE DISK IS FULL (-15)
/ OR BECAUSE OF A PERMANENT DISK FAILURE (-N).
/
RFALER	LAC	RFXRTP		/RESTORE THE XR.
	PAX
	LAC	RFIOEV		/RETURN THE ERROR CODE IN THE AC.
	.IFDEF %RF15
	DZM*	(RFACTB)	/ZERO RFACTB SINCE NO BLOCKS COULD BE
				/ALLOCATED AND SUPPLY IS EMPTY.
	.ENDC
	.IFUND %RF15
	DZM*	RFTMP1
	JMS	RFALSR		/UPDATE RFALAR AND RFALCT TABLES
	.ENDC
	JMP*	RFAL1B
/
/ THE FOLLOWING TWO TABLES ARE USED ONLY FOR DEVICES WITH MULTIPLE UNITS.
/ THE FIRST TABLE IS A LIST OF THE RFALAR VARIABLES FOR EACH UNIT.
/ THE SECOND TABLE IS A LIST OF THE RFALCR'S FOR EACH UNIT.
/
	.IFUND %RF15
RFALT1=.
	.REPT 10		/TABLE OF RFALAR'S
	10
RFALT2=.
	.REPT 10		/TABLE OF RFALCT'S
	0
/
/
/ SUBROUTINE RFALSR -- USED ONLY FOR DEVICES WITH MULTIPLE UNITS
/
/       THIS SUBROUTINE IS USED TO UPDATE THE VALUES OF RFALAR AND
/       RFALCT FOR A UNIT JUST PRIOR TO LEAVING THE RFAL1B S.R.
/       RETURN IS UNCONDITIONALLY TO LOCATION JMS+1.
/
/
/	NO REGISTERS ARE ALTERED.
/
RFALSR	0
	DAC	RFTMP1		/SAVE THE AC
	LAC	(RFALT1		/PUT NEW VALUE OF RFALAR INTO TABLE
	TAD	RFUNIT
	DAC	RFTMP2
	LAC	RFALAR
	DAC*	RFTMP2
	LAC	(RFALT2		/PUT NEW VALUE OF RFALCT INTO TABLE
	TAD	RFUNIT
	DAC	RFTMP2
	LAC	RFALCT
	DAC*	RFTMP2
	LAC	RFTMP1		/RESTORE THE AC
	JMP*	RFALSR
	.ENDC
	.TITLE *** MISCELLANEOUS SUBROUTINES
/
/ SUBROUTINE RFADJX -- SET THE INDEX REGISTER FROM THE VALUE IN THE AC
/ BY ADDING THE INDEX ADJUSTMENT FACTOR, WHICH COMPENSATES FOR THE
/ PAGE ADDRESS BITS ADDED FOR MEMORY REFERENCE INSTRUCTIONS.
/
/ CALLING SEQUENCE:
/
/	UNADJUSTED VALUE IN THE AC
/	JMS	RFADJX
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	AC & XR
/
RFADJX	0
	TAD	RFXADJ
	PAX
	JMP*	RFADJX
/
/
/
/
/
/ SUBROUTINE RFRTND -- RETURN THE I/O REQUEST NODE TO THE POOL OF EMPTY NODES.
/
/ CALLING SEQUENCE:
/
/	JMS	RFRTND
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	R2, R6, XR & AC
/
RFRTND	0
	LAC	RFRQND
	DAC*	(R2)		/SAVE THE NODE'S ADDRESS.
	LAC	(POOL)		/ADDRESS OF THE HEAD OF THE EMPTY POOL.
	DAC*	(R1)
	JMS*	(NADD)		/ADD THE NODE TO THE POOL.
				/(R2, R6, XR & AC ARE ALTERED).
	JMP*	RFRTND
/
	.EJECT
/ SUBROUTINE RFGTBL -- GET THE BLOCK WHOSE NUMBER IS IN (RF.BLK,X) AND
/ STORE IT IN THE INDICATED BUFFER.
/
/ CALLING SEQUENCE:
/
/	(BLOCK NUMBER IN RF.BLK,X)
/	JMS	RFGTBL
/	(RETURN WITH ERROR CODE IN THE AC)
/	(NO-ERROR RETURN WITH THE XR STILL
/	POINTING AT THE FILE BUFFER)
/
/ ALTERED REGISTERS:
/
/	EFFECTIVELY ALL (DUE TO THE CAL)
/
RFGTBL	0
	PXA			/SAVE THE XR.
	DAC	RFXRTP
	JMS	RFCNVT		/CONVERT THE BLOCK NUMBER INTO A DISK
				/ADDRESS AND PLATTER NUMBER AND STORE
				/THEM IN THE GET/PUT CONTROL TABLE.
				/(XR, AC & MQ ARE ALTERED).
	LAC	RFBFAD		/STORE THE BUFFER ADDRESS IN THE
	AAC	RF.DAT		/CONTROL TABLE.
	DAC	RFGPCT+2
	CAL	RFGBLK		/"GET" BLOCK FROM DISK.
	CAL	RFWAIT		/WAITFOR COMPLETION.
	LAC	RFXRTP		/RESTORE THE XR.
	PAX
	LAC	RFIOEV
	SMA			/#/ SKIP ON RETURN IF NO ERROR OCCURRED.
	IDX	RFGTBL
	JMP*	RFGTBL
/
	.EJECT
/ SUBROUTINE RFPTBL -- PUT BLOCK ON DISK.
/
/ CALLING SEQUENCE:
/
/	(BLOCK NUMBER IN RF.BLK,X)
/	JMS	RFPTBL
/	(RETURN HERE WITH THE ERROR CODE IN THE AC)
/	(RETURN HERE, IF NO ERROR OCCURRED, WITH
/	THE XR STILL POINTING AT THE FILE BUFFER)
/
/ ALTERED REGISTERS:
/
/	EFFECTIVELY ALL (DUE TO THE CAL)
/
RFPTBL	0
	PXA			/SAVE THE XR.
	DAC	RFXRTP
	JMS	RFCNVT		/CONVERT THE BLOCK NUMBER INTO A DISK
				/ADDRESS AND PLATTER NUMBER AND STORE
				/THEM IN THE GET/PUT CONTROL TABLE.
				/(XR, AC & MQ ARE ALTERED).
	LAC	RFBFAD		/STORE THE BUFFER ADDRESS IN THE CONTROL
	AAC	RF.DAT		/TABLE.
	DAC	RFGPCT+2
	CAL	RFPBLK		/"PUT" THE BLOCK ON THE DISK.
	CAL	RFWAIT		/WAITFOR COMPLETION.
	LAC	RFXRTP		/RESTORE THE XR.
	PAX
	LAC	RFIOEV
	SMA			/#/ SKIP ON RETURN IF NO ERROR OCCURRED.
	IDX	RFPTBL
	JMP*	RFPTBL
/
	.EJECT
/ SUBROUTINE RFCNVT -- PREPARE TO GET OR PUT A DATA BLOCK FROM OR TO
/ THE DISK. CONVERT THE BLOCK NUMBER INTO A DISK ADDRESS AND PLATTER
/ NUMBER. THESE PARAMETERS ARE STORED IN THE GET/PUT CONTROL TABLE.
/
/ CALLING SEQUENCE:
/
/	JMS	RFCNVT
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	XR, AC & MQ
/
RFCNVT	0
	JMS	RFXRFB		/SET THE XR TO POINT TO THE FILE BUFFER.
	CLL
	LAC	RF.BLK,X	/COMPUTE THE PLATTER NUMBER.
	.IFDEF %RF15
	LRS	12
	DAC	RFGPCT+0
	LAC	RF.BLK,X	/COMPUTE THE DISK ADDRESS.
	AND	(1777)
	ALS	10
	DAC	RFGPCT+1
	.ENDC
	.IFUND %RF15
	LMQ
	LLSS!ECLA 10
	DAC	RFGPCT+0
	CLL
	LAC	RFUNIT
	ALS	17
	TAD	RFGPCT+0
	DAC	RFGPCT+0
	LACQ
	DAC	RFGPCT+1
	.ENDC
	JMP*	RFCNVT
/
/
/
/
/
/ SUBROUTINE RFXRFB -- SET THE XR TO POINT TO THE FILE BUFFER.
/
/ CALLING SEQUENCE:
/
/	JMS	RFXRFB
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	AC & XR
/
RFXRFB	0
	LAC	RFBFAD
	JMS	RFADJX
	JMP*	RFXRFB
	.TITLE *** ACTIVE LUNS DEQUE (RFALUN)
/
/ THE LISTHEAD FOR THIS DEQUE BEGINS AT 'RFALUN'. A NEW NODE IS ADDED
/ TO THE DEQUE EACH TIME A REQUEST TO OPEN A FILE IS RECEIVED FROM A
/ NEW TASK-LUN COMBINATION. THE NUMBER OF OPEN FILES IS VIRTUALLY UN-
/ LIMITED AND SEVERAL TASKS MAY PERFORM I/O ON THE SAME LUN.
/
/ THIS DEQUE APPLIES MAINLY TO SEQUENTIAL ACCESS FILES. RANDOM ACCESS
/ FILES ARE NEVER OPENED UNLESS THEY ARE TO BE RENAMED.
/
/ FORMAT OF NODES IN THE "RFALUN" DEQUE:
/
/	WORD 0 FORWARD POINTER
/	WORD 1 BACKWARD POINTER
/	WORD 2 TASK NAME (1ST HALF -- .SIXBT)	<<< SEE NOTE BELOW
/	WORD 3 TASK NAME (2ND HALF -- .SIXBT)	<<< SEE NOTE BELOW
/	WORD 4 UNUSED
/	WORD 5 LUN (0-8); ZERO (9-17)
/	WORD 6 ADDRESS OF PDVL NODE (FOR RP OR RK VERSIONS)
/	WORD 7 DISK UNIT NUMBER (FOR RP OR RK VERSIONS)
/	WORD 10 UNUSED
/	WORD 11 FILE BUFFER POINTER
/
RFALUN	.			/FORWARD POINTER.
	.-1			/BACKWARD POINTER.
/
/ NOTE -- IN PHASE 1 OF RSX, I/O REQUEST NODES WERE FORMATTED WITH
/ THE TASK NAME IN WORDS 2 AND 3 (AS SHOWN ABOVE). FOR PHASE 2, WORD
/ 2 CONTAINS A POINTER TO THE STL NODE (IN WHICH THE TASK NAME CAN BE
/ FOUND IF NEEDED) AND WORD 3 CONTAINS 0 OR A POINTER TO THE TASK'S
/ PARTITION BLOCK NODE. SINCE THE STL POINTER IS UNIQUE, WHICH IS ALL
/ THAT MATTERS, WORDS 2 AND 3 ARE TREATED IN THIS HANDLER AS IF THEY
/ STILL CONTAIN THE TASK NAME.
	.TITLE *** FILE BUFFER STRUCTURE
/
/ FILE BUFFERS ARE CREATED IN THE TOP PART OF A TASK'S CORE PARTITION BY A
/ COMMON "GET BUFFER" SUBROUTINE WITHIN THE EXECUTIVE.
/ THE BEGINNING OF THE BUFFER IS USED FOR FILE STATUS DESCRIPTORS.
/ THESE ARE DEFINED BELOW RELATIVE TO THE BEGINNING OF THE BUFFER.
/
RF.FN1=0		/FILE NAME -- 1ST HALF.
RF.FN2=1		/FILE NAME -- 2ND HALF.
RF.EXT=2		/FILE NAME EXTENSION.
RF.OPN=3		/CAL FUNCTION CODE BY WHICH THIS FILE WAS OPENED.
RF.BLK=4		/CURRENT DISK DATA BLOCK NUMBER.
/
/ LOCATION OF A FREE FILE ENTRY IN THE UFD.
/
RF.FEF=5		/SET NON-0 (UFD START BLK.) BY "RFSRCH" WHEN A FREE FILE
			/	ENTRY HAS BEEN FOUND.
RF.FEB=6		/NUMBER OF THE UFD BLOCK WHICH HAS A FREE FILE ENTRY.
RF.FEL=7		/RELATIVE LOCATION WITHIN THE UFD BLOCK OF THE
			/	FREE FILE ENTRY.
RF.FES=10		/THE NEW FILE'S STARTING BLOCK NUMBER.
/
/ LOCATION OF THE OLD FILE ENTRY IN THE UFD.
/
RF.OFF=11		/SET NON-0 (-1) BY "RFSRCH" IF THE FILE ALREADY
			/	EXISTS IN THE DIRECTORY.
RF.OFB=12		/NUMBER OF THE UFD BLOCK WHICH HAS THE OLD FILE ENTRY.
RF.OFL=13		/RELATIVE LOCATION WITHIN THE UFD BLOCK OF THE
			/	OLD FILE ENTRY.
RF.OFS=14		/BIT 0 = 1 IF THE FILE IS TRUNCATED.
			/BITS 1-17 = THE FILE'S STARTING BLOCK NUMBER.
/
/ READ AND WRITE PARAMETERS.
/
RF.DPT=15		/POINTER TO A DATA LINE IN THE FILE DATA BLOCK.
RF.PER=16		/SET NON-0 WHEN THE CURRENT DATA BLOCK
			/	HAS A PARITY ERROR.
RF.EOF=17		/SET NON-0 WHEN AN END-OF-FILE RECORD
			/	HAS BEEN READ.
RF.FSZ=20		/SIZE OF THE CURRENT OUTPUT FILE IN
			/	NUMBER OF DATA BLOCKS.
RF.NXB=21		/NEXT DATA BLOCK NUMBER ALLOCATED PRIOR
			/	TO WRITING OUT THE CURRENT BLOCK.
/
	.EJECT
/ WITHIN THE FILE BUFFER THERE IS A FILE DATA BUFFER OF 256 (DECIMAL)
/ WORDS, WHICH STARTS IMMEDIATELY AFTER THE FILE STATUS DESCRIPTORS.
/ DATA BLOCKS ARE READ HERE FROM THE DISK OR ARE ASSEMBLED HERE AND
/ THEN WRITTEN TO THE DISK.
/
RF.DAT=RFNFSD		/START OF 400 OCTAL WORD FILE DATA BLOCK.
/
/ THE FOLLOWING CONDITIONAL WILL GENERATE AN ERROR IF THE NUMBER OF
/ FILE STATUS DESCRIPTORS VARIABLE IS INCORRECTLY DEFINED.
/
	.IFNZR	RF.DAT-22
	YYYYYY
	.ENDC
	.TITLE *** VARIABLES AND CAL PARAMETER BLOCKS
/
/ VARIABLES.
/
RFTGEV	0			/THE TRIGGER EVENT VARIABLE.
RFIOEV	0			/THE I/O EVENT VARIABLE.
RFRQND	0			/ADDRESS OF THE CURRENT I/O REQUEST NODE.
RFRQEV	0			/ADDRESS OF THE REQUESTER'S EVENT VARIABLE.
RFTMP1	0			/TEMPORARY STORAGE.
	.IFUND %RF15
RFTMP2	0
RFTMP3	0
RFUCNT	0			/COUNT OF THE NUMBER OF UNITS
RFUNIT	0			/CURRENT UNIT NUMBER
	.ENDC
RFLUNN	0			/CURRENT LUN NUMBER
RFPDNA	0			/ADDRESS OF THE PHYSICAL DEVICE NODE.
RFXADJ	0			/INDEX REGISTER ADJUSTMENT FACTOR (SEE
				/INITIALIZATION CODE FOR EXPLANATION).
RFPAGE	0			/PAGE ADDRESS BITS FOR THE PAGE IN
				/WHICH THIS CODE IS LOCATED.
				/C(RFXADJ) = -C(RFPAGE).
RFPDEV	0			/ADDRESS OF THE WORD IN THE PHYSICAL
				/DEVICE NODE THAT CONTAINS THE TRIGGER
				/EVENT VARIABLE ADDRESS.
RFFCNT	0			/COUNT OF THE NUMBER OF OPEN FILES.
RFCLFL	0			/FLAG SET NON-ZERO TO SIGNAL THE RESIDENT
				/"DONE" CODE NOT TO RELINQUISH THE I/O
				/REQUEST NODE BUT, INSTEAD, TO USE IT TO
				/CLOSE THE FILE.
RFALAR	10			/THE NUMBER OF 256-WORD BLOCKS TO BE
				/ALLOCATED AT A TIME. THIS COUNT
				/MIGHT BE HALVED IF NECESSARY.
RFALCT	0			/FLAG AND COUNTER USED BY THE ALLOCATE
				/SUBROUTINE TO DETERMINE (IF THE FLAG
				/IS NON-0) THAT THE NUMBER OF BLOCKS
				/ALLOCATED AT ONE TIME IS LESS THAN 8
				/BECAUSE OF DISK ERRORS OR NO ROOM.
				/THE COUNTER IS SET TO -8 AND IS IN-
				/CREMENTED EACH TIME AN ALLOCATE IS
				/SUCCESSFULLY PERFORMED. IF THE COUNT
				/GOES TO ZERO, THE AMOUNT TO BE ALLOCATED
				/IS DOUBLED (NOT TO EXCEED 8).
RFBFAD	0			/ADDRESS OF THE CURRENT FILE BUFFER.
RFSTL	0			/ADDRESS OF THIS HANDLER'S SYSTEM TASK
				/LIST NODE.
RFALNA	0			/ADDRESS OF THE CURRENT RFALUN NODE.
RFXRTP	0			/TEMPORARY STORAGE FOR THE XR.
/
	.EJECT
/ CAL PARAMETER BLOCKS.
/
RFWFTG	20			/"WAITFOR" THE TRIGGER EVENT VARIABLE
	RFTGEV			/TO BE SET NON-0.
/
RFWAIT	20			/"WAITFOR" THE I/O EVENT VARIABLE
	RFIOEV			/TO BE SET NON-0.
/
RFALC8	11500			/CODE FOR "ALLOCATE".
	RFIOEV			/EVENT VARIABLE.
	1			/LUN 1 = DISK I/O DRIVER.
	.IFDEF %RF15
	RFACTB			/CONTROL TABLE ADDRESS.
	.ENDC
	.IFUND %RF15
	XX			/MODIFIED TO THE CORRECT CTA ADDRESS
	.ENDC
	.IFDEF %RF15		/DEVICE CODE
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
/
RFDALO	11600			/CODE FOR "DEALLOCATE".
	RFIOEV			/EVENT VARIABLE ADDRESS.
	1			/LUN 1 = DISK I/O DRIVER.
	RFDACT			/CONTROL TABLE ADDRESS. THIS WORD IS
	.IFDEF %RF15		/DEVICE CODE
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
				/MODIFIED BY THE EXIT CODE.
/
RFGBLK	13000			/CODE FOR "GET".
	RFIOEV			/EVENT VARIABLE.
	1			/LUN 1 = DISK I/O DRIVER.
	RFGPCT			/CONTROL TABLE ADDRESS.
	.IFDEF %RF15		/DEVICE CODE
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
/
RFPBLK	13100			/CODE FOR "PUT".
	RFIOEV			/EVENT VARIABLE ADDRESS.
	1			/LUN 1 = DISK I/O DRIVER.
	RFGPCT			/CONTROL TABLE ADDRESS.
	.IFDEF %RF15		/DEVICE CODE
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
/
/ DEALLOCATE CONTROL TABLE.
/
RFDACT	XX			/NUMBER OF WORDS TO DEALLOCATE.
	XX			/DISK PLATTER NUMBER.
	XX			/DISK ADDRESS.
/
/ GET AND PUT CONTROL TABLE.
/
RFGPCT	XX			/DISK PLATTER.
RFGPC1	XX			/DISK ADDRESS.
RFGPC2	XX			/CORE BUFFER ADDRESS.
	400			/WORD COUNT.
/
	.END	RFINIT
