	.TITLE *** RSX DISK FILES HANDLER OVERLAY #3
/
/ 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	25 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 CARTRIDGE DISK.
/ 
	.IFUND %RF15
	.IFUND %RP02
	.IFUND %RK05
	.END    NO ASSEMBLY PARAMETERS SPECIFIED
	.ENDC
	.ENDC
	.ENDC
/
/ INTERNALLY DEFINED GLOBAL SYMBOL: MUST BE THE SAME AS THE FILE NAME.
/
	.GLOBL	RFCLOS
/
/ EXTERNALLY DEFINED GLOBAL SYMBOLS.
/
	.GLOBL	RFRQND,RFALUN,RFAL1B,RFSREV,RFGTBL,RFPTBL,RFBFAD,RFPDNA
	.GLOBL	RFSTL,RFFCNT,RFCLFL,RFGPC1,RFCNVT,RFGPCT,RFLUNN,RFFLBF
/
	.IFUND %RF15
	.GLOBL RFUNIT,RFCNTT,RFDNAT
	.ENDC
/
/
/ DEFINITION OF REGISTERS LOCATED WITHIN THE RSX EXECUTIVE.
/
X10=10				/AUTOINCREMENT REGISTER 10.
X11=11
X12=12
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.
PENP=115			/ENTRY POINT TO "PICK AN EMPTY
				/NODE FROM POOL" SUBROUTINE.
SPRI=126			/ENTRY POINT TO "SEARCH DEQUE FOR
				/PRIORITY AND INSERT NODE" SUBROUTINE.
POOL=240			/HEAD OF THE EMPTY NODES DEQUE.
IOCD=345			/ENTRY POINT TO "DECREMENT I/O PENDING
				/COUNT" SUBROUTINE.
DABF=356			/ENTRY POINT TO "DEALLOCATE BUFFER" SUBR.
DMTQ=361			/ENTRY POINT TO "DETACH & EMPTY REQUEST
				/DEQUE" SUBROUTINE
LUTP1=142			/PTR TO START OF LUT TABLE
/
/ IOT AND PARAMETER DEFINITIONS.
/
IDX=ISZ				/IDX IS USED INSTEAD OF ISZ WHEN THE
				/INTENT IS TO ADD 1 TO A REGISTER BUT
				/NOT TO SKIP.
.INH=705522			/INHIBIT INT.
.ENB=705521			/ENABLE INT.
	.TITLE *** CLOSE
/
/ CLOSE AN OPEN FILE (OR ABORT TASK I/O) AND RELINQUISH SYSTEM RESOURCES.
/
RFCLOS	0
	DAC	RFCODE		/SAVE THE CODE FOR "CLOSE", "ERROR CLOSE",
				/"ABORT" OR "DISCONNECT & EXIT".
	LAC	(RFEOFL)	/COMPUTE THE PAGE ADDRESS BITS FOR THIS
	AND	(70000)		/OVERLAY AND SAVE THEM IN BOTH POSITIVE
	DAC	RFPAGE		/AND NEGATIVE FORM.
	TCA
	DAC	RFXADJ
/
/ PICK UP THE PARAMETERS FROM THE I/O REQUEST NODE.
/
	LAC*	RFRQND		/SET UP THE XR TO ACCESS THE NODE.
	JMS	RFADJX
	LAC	RFCODE		/ABORT?
	SAD	(017)
	SKP			/YES.
	JMP	RFFNOK		/NO -- CLOSE, ERROR CLOSE OR EXIT.
	777000			/ABORT IS AN ILLEGAL REQUEST FOR ALL TASKS
	AND	5,X		/EXCEPT "IORD", WHO SETS THE LUN=0.
	SZA
	JMP	RFIFNC		/#/ ILLEGAL FUNCTION.
/
RFFNOK	LAC	7,X		/SAVE I/O ARGUMENT 1.
	DAC	RFARG1
	LAC	10,X		/SAVE I/O ARGUMENT 2.
	DAC	RFARG2
	LAC	11,X		/SAVE I/O ARGUMENT 3.
	DAC	RFARG3
	DZM	RFERCD		/INITIALIZE THE ERROR CODE TO INDICATE
				/THAT NONE HAS YET BEEN DETECTED.
/
/ SEARCH THE ACTIVE LUN DEQUE TO BE SURE THAT A FILE IS OPEN.
/
RFABLP	LAC	RFALUN		/SET THE INDEX REGISTER TO START AT
	JMS	RFADJX		/THE HEAD OF RFALUN.
/
RFCLLP	LAC*	RFRQND		/SET AUTOINCREMENT REGISTER 10 TO
	IAC			/ACCESS THE TASK NAME IN THE REQUEST NODE.
	DAC*	(X10)
/
/ TEST FOR END OF DEQUE.
/
	LAC	0,X		/END OF RFALUN DEQUE?
	SAD	RFALUN
	JMP	RFNOFO		/YES -- NO FILE OPEN.
	DAC	RFALNA		/NO -- SAVE THE NODE'S ADDRESS.
	JMS	RFADJX		/SET THE INDEX REGISTER TO
				/POINT TO THE NEXT NODE.
/
/ TEST FOR TASK NAME IN ALL CASES EXCEPT ON A "DISCONNECT & EXIT" REQUEST.
/ ACTUALLY, IT IS NOT A TASK NAME -- SEE "RFALUN" IN RESIDENT CODE.
/
	LAC	RFCODE		/DISCONNECT & EXIT?
	SAD	(777)
	JMP	RFOUND		/YES.
	LAC	2,X		/NO -- FIRST HALF OF TASK NAME FOUND?
	SAD*	X10
	SKP
	JMP	RFCLLP		/NO -- TRY NEXT NODE.
	LAC	3,X		/SECOND HALF FOUND?
	SAD*	X10
	SKP
	JMP	RFCLLP		/NO -- TRY NEXT NODE.
/
/ TEST FOR LUN IF THIS IS "CLOSE" OR "ERROR CLOSE" RATHER THAN "ABORT".
/
	LAC	RFCODE		/ABORT OR CLOSE?
	SAD	(017)
	JMP	RFOUND		/ABORT -- DON'T TEST LUN.
	LAC*	X10		/SKIP THE PRIORITY CODE.
	LAC	5,X		/DO THE LUNS MATCH?
	XOR*	X10
	AND	(777000)
	SZA
	JMP	RFCLLP		/NO -- TRY NEXT NODE.
/
/ THE TASK-LUN NODE IN RFALUN HAS BEEN FOUND.
/
RFOUND	LAC	11,X		/SAVE THE FILE BUFFER ADDRESS.
	DAC*	RFBFAD
	.IFUND %RF15
	LAC	5,X		/GET THE LUN NUMBER
	AND	(777000
	SWHA
	DAC*	RFLUNN		/SAVE IT
	LAC	6,X		/GET THE ADDRESS OF THE PDVL NODE
	DAC*	RFPDNA
	LAC	7,X		/GET THE UNIT NUMBER
	DAC*	RFUNIT
	TAD	RFCNTT		/GET THE COUNT OF OPEN FILES
	DAC	RFTMP1
	LAC*	RFTMP1
	DAC*	RFFCNT		/SAVE IT
	.ENDC
	JMS	RFXRFB		/SET THE XR TO POINT TO THE BUFFER.
/
/ WHY IS THE FILE BEING CLOSED?
/
	LAC	RF.OPN,X	/EXAMINE THE FUNCTION CODE OF THE DIREC-
				/TIVE USED TO OPEN THE FILE.
	SAD	(033)
	JMP	RFCLSO		/CLOSE SEQUENTIAL OUTPUT FILE.
	SAD	(037)
	JMP	RFCLRN		/CLOSE FILE TO BE RENAMED.
				/CLOSE SEQUENTIAL INPUT FILE.
	.TITLE *** CLOSE INPUT FILE
/
/ CLOSE A FILE THAT WAS OPENED FOR SEQUENTIAL INPUT. CONTROL ALSO COMES
/ HERE TO FINISH UP THE "RFCLSO" AND "RFCLRN" CODE.
/
RFCLSI	LAC*	RFBFAD		/SET R4 WITH THE BUFFER'S ADDRESS.
	DAC*	(R4)
	JMS*	(DABF)		/RELINQUISH THE BUFFER.
				/(R4, R5, XR & AC ARE ALTERED).
/
/ RELINQUISH THE ACTIVE LUN NODE.
/
	LAC	RFALNA		/DELETE THE NODE FROM THE ACTIVE LUN DEQUE.
	DAC*	(R1)
	JMS*	(NDEL)		/(R1, R2, R6, XR & AC ARE ALTERED).
	LAC	(POOL)		/ADD THE NODE TO THE EMPTY POOL.
	DAC*	(R1)
	LAC	RFALNA
	DAC*	(R2)
	JMS*	(NADD)		/(R2, R6, XR & AC ARE ALTERED).
	LAC	RFERCD		/RETURN THE ERROR CODE IN THE REQUESTER'S
	SNA			/EVENT VARIABLE IF AN ERROR OCCURRED.
RFRQOC	CLA!IAC
	PAL
/
/ DECREMENT THE I/O PENDING COUNT.
/
	LAC*	RFRQND		/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	JMS*	(IOCD)		/DECREMENT THE I/O PENDING COUNT THAT
				/WAS NOT DONE WHEN THE FILE WAS OPENED
				/(SEE RESIDENT CODE AT "RFSREV").
				/(R5, XR & AC ARE ALTERED).
/
/ DECREMENT THE OPEN FILE COUNT.
/
	.IFUND %RF15
	LAC*	RFUNIT		/SUBTRACT 1 FROM TABLE ENTRY
	TAD	RFCNTT
	DAC	RFTMP1
	LAC*	RFTMP1
	AAC	-1
	DAC*	RFTMP1
	.ENDC
	LAW	-1		/SUBTRACT ONE FROM THE COUNT OF OPEN FILES.
	TAD*	RFFCNT
	DAC*	RFFCNT
	SZA			/NOW ZERO?
	JMP	RFCNZR		/NO.
	LAC*	RFPDNA		/YES -- SET THE XR WITH THE PHYSICAL
	JMS	RFADJX		/DEVICE NODE ADDRESS.
	LAC	11,X		/CLEAR BIT 1 IN THE "ASSIGN INHIBIT" FLAG
	AND	(577777		/TO INFORM THE "REASSIGNE" MCR FUNCTION
	DAC	11,X		/TASK THAT NO FILES ARE OPEN.
/
	.EJECT
/ IF THIS IS AN "ABORT" OR "DISCONNECT & EXIT" RATHER THAN A "CLOSE" OR
/ "ERROR CLOSE" REQUEST, LOOP BACK TO SEE IF OTHER FILES OPEN ARE TO BE
/ CLOSED.
/
RFCNZR	LAC	RFCODE
	SAD	(017)
	JMP	RFABLP		/ABORT.
	SAD	(777)
	JMP	RFABLP		/DISCONNECT & EXIT.
	PLA			/CLOSE OR ERROR CLOSE.
	JMP*	RFSREV		/SET THE REQUESTER'S EVENT VARIABLE.
/
RFNOFO	LAC	RFCODE		/NO FILE OPEN.
	SAD	(017)
	JMP	RFABDN		/ABORT.
	SAD	(777)
	JMP*	RFCLOS		/EXIT -- RETURN TO RESIDENT EXIT CODE.
	LAW	-11		/CLOSE OR ERROR CLOSE -- ERROR.
	JMP*	RFSREV
/
RFIFNC	LAW	-6		/ILLEGAL OR UNIMPLEMENTED I/O FUNCTION.
	DAC*	RFCLFL		/SET A FLAG FOR THE "DONE" CODE SO THAT
	JMP*	RFSREV		/IT WILL CLOSE THE FILE IF ONE IS OPEN.
/
/ TAIL END OF THE ABORT CODE. CLEAN UP THE I/O REQUEST QUEUE.
/
	.IFDEF %RF15
RFABDN	LAC*	RFPDNA		/PHYSICAL DEVICE NODE ADDRESS.
	DAC*	(R1)
	LAC*	RFRQND		/I/O REQUEST NODE ADDRESS.
	DAC*	(R2)
	JMS*	(DMTQ)		/EMPTY THE QUEUE OF ALL I/O REQUESTS MADE
				/BY THE TASK BEING ABORTED.
				/(R1, R2, R3, R5, R6, X10, X11, X12, XR
				/& AC ARE ALTERED).
	.ENDC
	.IFUND %RF15
RFABDN	LAW     -10		/SET COUNTER OF PDVL NODES
	DAC	RFRIB9
	LAC	RFDNAT		/SET UP TO ACCESS TABLE OF PDVL NODE ADDR.
	DAC	RFTMP1
RFABD2	LAC*	RFTMP1		/GET A NODE ADDRESS
	SNA			/IS THIS THE END OF THE TABLE?
	JMP	RFABD1		/YES
	DAC*	(R1		/NO -- EMPTY THE QUEUE
	LAC*	RFRQND
	DAC*	(R2
	JMS*	(DMTQ
	IDX	RFTMP1		/PREPARE TO GET NEXT PDVL NODE
	ISZ	RFRIB9		/END OF TABLE?
	JMP	RFABD2		/NO
	.ENDC
RFABD1	CLA!IAC			/SET THE I/O RUNDOWN EVENT VARIABLE AND
	JMP*	RFSREV		/SIGNAL COMPLETION.
	.TITLE *** CLOSE OUTPUT FILE
/
/ CLOSE A FILE THAT WAS OPENED FOR SEQUENTIAL OUTPUT. THE XR IS ALREADY
/ POINTING AT THE FILE BUFFER SINCE CONTROL COMES HERE FROM THE "RFCLOS" CODE.
/
/ CHECK THE "OLD FILE FOUND" FLAG. IF IT IS NON-0, THAT INDICATES THE
/ FILE IS BEING RECREATED. IF THE FUNCTION IS AN "ERROR CLOSE" (134),
/ THIS IS BEING FORCED DUE TO SOME ERROR. IN SUCH A CASE, SINCE THE NEW
/ VERSION OF THE FILE IS INCOMPLETE, DELETE THE NEW VERSION AND RETAIN
/ THE OLD ONE. THE SAME HOLDS TRUE IF THE FUNCTION IS "ABORT" OR "DIS-
/ CONNECT & EXIT".
/
RFCLSO	LAC	RF.OFF,X	/DOES THE OLD FILE EXIST?
	SNA
	JMP	RFCLOK		/NO.
	LAC	RFCODE		/YES -- IS THIS A NORMAL CLOSE?
	SAD	(034)
	JMP	RFCLOK		/YES.
	LAC	RF.FSZ,X	/NO -- IS THE NEW FILE SIZE 0?
	SZA
	JMP	RFCLE2		/NO -- DEALLOCATE ITS BLOCKS.
	JMP	RFCLE3		/YES -- REMOVE THE FILE ENTRY.
/
/ NORMAL "CLOSE" -- HAVE ANY BLOCKS BEEN ASSIGNED TO THIS FILE?
/
RFCLOK	LAC	RF.FSZ,X	/IS THE FILE SIZE NON-0?
	SZA
	JMP	RFWRHB		/YES -- THE FILE HAS BLOCKS.
	JMS*	RFAL1B		/NO -- ALLOCATE A 256 WORD DISK BLOCK.
				/(EFFECTIVELY, ALL REGISTERS + RFTMP1
				/ARE ALTERED).
				/WAS A BLOCK ALLOCATED?
	JMP	RFCLE3		/#/ NO -- THE ERROR CODE IS IN THE AC.
/
/ THE XR IS POINTING AT THE FILE BUFFER.
/
	DAC	RF.NXB,X	/YES -- SAVE AS THE NEXT BLOCK NUMBER.
	DAC	RF.FES,X	/SAVE THE FILE'S STARTING BLOCK NUMBER.
	LAW	-1		/SET THE BACKWARD LINK TO -1 TO INDICATE
	JMP	RFSTBL		/"NO PREVIOUS BLOCK".
/
/ WRITING HAS ALREADY BEEN DONE -- A BLOCK HAS BEEN ALLOCATED. WILL THE
/ LINE TO BE WRITTEN FIT INTO THE SPACE REMAINING IN THE CURRENT DATA BLOCK?
/
RFWRHB	JMS	RFDBFA
	AAC	+374
	TCA
	TAD	RF.DPT,X
	SPA!SNA
	JMP	RFFITS		/YES.
/
	.EJECT
/ THE DATA LINE WON'T FIT IN THE CURRENT BLOCK. ALLOCATE ANOTHER BLOCK
/ AND THEN WRITE OUT THE OLD ONE.
/
	JMS*	RFAL1B		/ALLOCATE A 256 WORD DISK BLOCK.
				/(EFFECTIVELY, ALL REGISTERS + RFTMP1
				/ARE ALTERED).
				/WAS A BLOCK ALLOCATED?
	JMP	RFCLE2		/#/ NO -- THE ERROR CODE IS IN THE AC.
/
/ THE XR IS POINTING AT THE FILE BUFFER.
/
	DAC	RF.NXB,X	/YES -- SAVE AS THE NEXT BLOCK NUMBER.
	DAC	RF.DAT+377,X	/STORE IN THE FORWARD LINK OF THE
				/CURRENT DATA BLOCK.
	JMS*	RFPTBL		/WRITE THE CURRENT BLOCK ONTO THE DISK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	JMP	RFCLE1		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
	LAC	RF.BLK,X	/SET THE BACKWARD LINKAGE TO
RFSTBL	DAC	RF.DAT+376,X	/POINT TO THE PREVIOUS BLOCK.
	LAC	RF.NXB,X	/SET THE NEWLY ALLOCATED BLOCK AS THE
	DAC	RF.BLK,X	/CURRENT BLOCK.
	JMS	RFDBFA		/RESET THE DATA BUFFER POINTER TO THE
	DAC	RF.DPT,X	/BEGINNING OF THE BUFFER.
	IDX	RF.FSZ,X	/INCREMENT THE FILE SIZE (NUMBER OF DATA
				/BLOCKS).
/
/ TRANSFER THE EOF LINE TO THE FILE DATA BUFFER.
/
RFFITS	LAC	RF.DPT,X	/GET THE ADDRESS OF THE LOCATION TO
				/WHICH DATA WILL BE TRANSFERRED.
	AAC	-1		/PREPARE AUTOINDEX REGISTER 11 FOR
	DAC*	(X11)		/STORING.
	LAC	RFEOFL
	DAC*	X11
	LAC	RFEOFC
	DAC*	X11
/
/ EXCEPT WHEN THE BLOCK IS NOW COMPLETELY FULL, ZERO THE NEXT WORD (THE
/ NEXT HEADER WORD 0) TO INDICATE THAT THERE IS NO MORE DATA IN THIS BLOCK.
/ FIRST, HOWEVER, INITIALIZE DATA FOR RIB CONSTRUCTION.
/
	DZM	RFRIB2		/ZERO RIB BLOCKS ALLOCATED COUNTER
	LAW	-1		/SET PREVIOUS RIB BLK NO. TO -1
	DAC	RFRIB7
	LAC	RFFLBF		/SET PTR'S TO WORDS 376 AND 377
	DAC	RFCLCT+2	/SET UP BUFFER ADDR. OF RIB BLK BUFF
	AAC	376		/OF THE RIB BLOCK BUFFER
	DAC	RFR376
	IAC
	DAC	RFR377
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF WORD 375 IN THE
	AAC	+375		/BLOCK AND COMPARE IT WITH X11.
	SAD*	(X11)
	JMP	RFRIBA		/RIB CAN'T POSSIBLE FIT IN THE LAST DATA BLOCK
	DZM*	X11		/DIFFERENT -- CLEAR THE NEXT WORD.
/
/ FIND OUT IF THE RIB WILL FIT IN THE LAST DATA BLOCK
/
	LAC*	(X11		/CALCULATE THE SPACE AVAILABLE IN THE
	TCA			/LAST DATA BLOCKTO SEE IF
	DAC	RFRIB1		/RIB WILL FIT
	JMS	RFDBFA
	AAC	375
	TAD	RFRIB1
	DAC	RFRIB1
	LAC	RF.FSZ,X	/RIB MIGHT FIT IF FILE SIZE +1 IS LESS THAN OR
	CMA			/EQUAL TO SPACE AVALIABLE
	TAD	RFRIB1
	SPA			/IF THERE SUFFICINET SPACE FOR THE RIB DATA?
	JMP	RFRIBA		/NO
/
/ RIB WILL FIT IN LAST DATA BLK SO SET WORDS FOR DIRECTORY ACCORDINGLY
/
	LAC*	(X11		/YES -- STORE THE 1ST RIB LOCATION
	DAC	RFRIB5
	LAC	RF.BLK,X	/STORE THE STARTING AND 
				/ONLY RIB BLOCK
	DAC	RFRIB6
	JMP	RFWOFB
/
/ RIB WON'T FIT SO ALLO. THE FIRST RIB BLOCK AND SET THE DIRECTORY PTRS.
/
RFRIBA	DZM	RFRIB5		/RIB WON'T FIT SO CLEAR WORDS USED IN DIRECTORY
	JMS	RFRIBZ		/ALLOCATE THE FIRST RIB BLOCK
	DAC	RFRIB6		/SAVE STARTING RIB BLOCK
	DAC	RFRIB8		/SAVE THE CURRENT RIB BLOCK
	DZM	RFRIB9		/ZERO THE NEXT RIB BLOCK PTR
/
	.EJECT
/ WRITE OUT THE FINAL DATA BLOCK.
/
RFWOFB	LAW	-1		/SET THE FORWARD LINKAGE WORD IN THE DATA
	DAC	RF.DAT+377,X    /BUFFER TO INDICATE THE FINAL BLOCK.
	JMS*	RFPTBL		/WRITE OUT THE CURRENT (AND FINAL) DATA BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	JMP	RFRIBE		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
/
/ FIX THE RIB DATA
/
RFRIB	LAC	RFFLBF		/INIT. X11 SO IT PTS TO WORD 0
				/WORD 0 RESERVED FOR THE NO. OF BLOCKS
				/DESCRIBED BY THIS RIB
	DAC*	(X11
	LAC	RF.BLK,X        /SAVE THE NUMBER OF THE LAST DATA BLOCK
	DAC	RFRIB4
	LAC	RF.FES,X        /INITIALIZE THE CURRENT DATA BLOCK (START OF FILE)
RFRIBC	DAC	RF.BLK,X
	LAC*	(X11		/SAVE X11 AROUND THE JMS*
	DAC	RFRIBZ
	JMS*	RFGTBL		/GET THE INDICATED DATA BLOCK
	JMP	RFRIBE		/RETURN HERE IF AN ERROR OCCURRED
	LAC	RFRIBZ		/RESTORE X11
	DAC*	(X11
	LAC	RF.BLK,X	/PUT THE BLK NO. INTO RIB BUFFER
	DAC*	X11
	SAD	RFRIB4		/IS THIS THE LAST DATA BLOCK?
	JMP	RFRIBD		/YES
	LAC	RFFLBF		/NO -- IS THE POINTER
	AAC	375		/AT THE END OF THE RIB BUFFER?
	SAD*	(X11
	JMP	.+3		/YES
RFRIBG	LAC	RF.DAT+377,X	/NO -- PREPARE TO READ IN NEXT DATA BLOCK
	JMP	RFRIBC
/
/ THE CURRENT RIB BLOCK IS FULL. THEREFORE, ALLO. ANOTHER BLOCK, UPDATE
/ THE POINTERS IN THE RIB BLOCK AND PROGRAM , AND WRITE THE OLD RIB OUT.
/
	LAC	(375		/YES -- END OF BUFFER SO SET 1ST WORD TO INDICATE
	DAC*	RFFLBF		/THE NUMBER OF DATA BLOCKS DESCRIBED IN THIS RIB
	LAC	RFRIB7		/SET BLOCK POINTERS INTO RIB BUFFER
	DAC*	RFR376
	LAC	RFRIB8
	DAC	RFRIB7
	JMS	RFRIBZ		/ALLOCATE THE NEXT RIB BLOCK
	DAC*	RFR377		/STORE PTR TO NEXT RIB BLOCK
	JMS	RFRIBP		/WRITE OUT THE RIB BLOCK
	LAC	RFFLBF		/RE-INITIALIZE X11
	DAC*	(X11
	LAC	RFRIB9		/UPDATE RIB BLOCK POINTERS
	DAC	RFRIB8
	DZM	RFRIB9
	JMP	RFRIBG
/
/ THERE ARE NO MORE DATA BLOCKS SO WRITE OUT THE LAST RIB BLOCK
/
RFRIBD	LAC	RFRIB6		/NO MORE DATA BLOCKS
	SAD	RFRIB4		/DOES THE RIB FIT IN LAST DATA BLOCK?
	SKP
	JMP	RFRIBF		/NO
/
/ THE RIB DATA FITS IN THE LAST DATA BLOCK SO PUT IN THE DATA AND WRITE
/ OUT THE BLOCK.
/
	DAC	RF.BLK,X	/YES -- ENTER RIB DATA IN LAST DATA BLK
	JMS*	RFGTBL		/READ IN THE LAST DATA BLOCK
	JMP	RFCLE2		/#/RETURN HERE IF ERRORS ARE FOUND
	LAC	RFRIB5		/RETURN HERE IF NO ERRORS ARE FOUND
	DAC*	(X11            /INITIALIZE X11
	LAC	RF.FSZ,X	/SET 1ST WORD OF RIB DATA
	DAC*	RFFLBF
	CMA
	DAC	RFTMP1		/INIT. TRANSFER COUNTER
	LAC	RFFLBF		/INIT. X10
	AAC	-1
	DAC*	(X10
	LAC*	X10		/TRANSFER RIB DATA TO LAST DATA BLOCK
	DAC*	X11
	ISZ	RFTMP1
	JMP	.-3
	JMS*	RFPTBL		/WRITE OUT THE BLOCK
	JMP	RFCLE2		/#/RETURN HERE IF ERRORS OCCUR
	JMS	RFDBFA		/SUBTRACT START OF BUFFER FROM RFRIB5
	TCA
	TAD	RFRIB5
	IAC
	DAC	RFRIB5
RFRIBH	JMS	RFXRFB		/RESTORE THE XR
	JMP	RFMUFD
/
/ THE RIB DATA DOESN'T FIT IN THE LAST DATA BLOCK AND THERE ARE NO MORE
/ DATA BLOCKS TO ENTER INTO THE RIBS SO WRITE OUT THE LAST RIB BLOCK.
/
RFRIBF	LAC	RFFLBF		/FIX THE NUMBER OF DATA BLOCKS
	TCA			/DESCRIBED BY THIS RIB BLOCK
	TAD*	(X11
	DAC*	RFFLBF
	LAC	RFRIB7		/SET PREVIOUS RIB BLOCK PTR
	DAC*	RFR376
	LAC	RFRIB8
	DAC	RFRIB7
	LAW	-1		/SET NEXT RIB BLOCK PTR
	DAC*	RFR377
	JMS	RFRIBP		/WRITE OUT THE RIB BLOCK
	JMP	RFRIBH
	.EJECT
/
/ SUBROUTINE TO ALLOCATE A RIB BLOCK
/ IF BLOCK CAN'T BE ALLOCATED JMP TO RFRIBE WITH ERROR CODE IN AC
/ IF ALLOCATION IS OK RETURN AT JMS+1 WITH BLOCK NUMBER IN AC AND
/ IN RFRIB9.
/
RFRIBZ	0
	JMS*	RFAL1B		/ALLOCATE
	JMP	RFRIBE		/#/RETURN HERE IF AN ERROR OCCURRED
	DAC	RFRIB9		/RETURN HERE IF NO ERROR WAS DETECTED
	IDX	RFRIB2		/INCREMENT THE COUNT OF RIB BLOCKS ALLOCATED
	JMP*	RFRIBZ
/
/ ERROR HANDLER FOR RIB BLOCK ROUTINES
/
RFRIBE	DAC	RFERCD		/ERROR ROUTINE -- DEALLOCATE ALL RIB BLOCKS AND JUMP TO EITHER
	LAC	RFRIB2		/HAVE ANY BLOCKS BEEN ALLOCATED?
	SNA
	JMP	RFCLE2+1	/NO
	LAC	RFRIB6		/YES -- IS 1ST RIB BLK=LAST DATA BLK?
	SAD	RFRIB4
	JMP	RFCLE2+1	/YES
	JMS	RFQDEA		/NO -- DEAL ALL RIB BLOCKS
RFRIB2	0			/COUNTER FOR RIB BLOCKS ALLOCATED
	NOP			/#/RETURN HERE IF POOL EMPTY
	LAC	RF.BLK,X	/WAS THE ERROR CAUSED ON A DIR READ?
	SAD	RF.FEB,X
	JMP	RFCLE4+1	/YES
	JMP	RFCLE2+1	/NO
/
/ SUBROUTINE TO WRITE OUT A RIB BLOCK
/
RFRIBP	0
	LAC	RF.BLK,X        /SAVE THE CURRENT DATA BLOCK'S NUMBER
	DAC	RFTMP1
	LAC	RFRIB7		/SET UP THE CONTROL TABLE TO
	DAC	RF.BLK,X	/WRITE OUT THE RIB BLOCK
	JMS*	RFCNVT		/CONVERT BLOCK NUMBER INTO PLATTER AND ADDRESS
	LAC*	RFGPCT		/GET THE PLATTER
	DAC	RFCLCT
	LAC*	RFGPC1		/GET THE ADDRESS
	DAC	RFCLCT+1
	CAL	RFRBPT		/PUT THE RIB BLOCK
	CAL	RFRBWT
	JMS	RFXRFB		/RESTORE THE XR
	LAC	RFTMP1		/RESTORE THE DATA BLOCK NUMBER
	DAC	RF.BLK,X
	LAC	RFCLEV		/CHECK THE EVENT VARIABLE
	SMA
	JMP*	RFRIBP		/PUT WAS OK
	LAC	RFRIB9		/#/PUT ERROR. DEAL. THE BLOCK JUST ALLO.
	SNA			/WAS A NEW RIB BLOCK ALLOCATED?
	JMP	.+7		/NO
	JMS	RFQDEA		/YES -- DEALLOCATE IT
	1
	NOP			/#/ POOL EMPTY
	CLC			/SUBTRACT 1 FROM COUNT OF RIB BLOCKS
	TAD	RFRIB2
	DAC	RFRIB2
	LAC	RFCLEV
	JMP	RFRIBE		/GO TO ERROR ROUTINE
/
/ CAL CONTROL BLOCKS AND VARIABLES USED IN THE RIB ROUTINES
/
RFRBPT	13100			/CAL BLOCK FOR PUTTING RIB BLOCKS ONTO DISK
	RFCLEV
	1
	RFCLCT
	.IFDEF %RF15
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
RFRBWT	20       	        /CAL BLOCK FOR WAITING FOR PUT TO COMPLETE
	RFCLEV
RFCLCT	0			/CONTROL TABLE FOR PUTS
	0
	XX			/ADDR. OF RIB BLOCK BUFFER
	400
RFCLEV	0			/EVENT VARIABLE FOR DISK PUTS
RFRIB1	0
RFRIB4	0
RFRIB5	0
RFRIB6	0
RFRIB7	0
RFRIB8	0
RFRIB9	0
RFR376	0		/PTR TO WORD 376 OF RIB BLOCK BUFFER
RFR377	0		/PTR TO WORD 377 OF RIB BLOCK BUFFER
	.EJECT
/
/ MODIFY THE FILE ENTRY IN THE UFD BLOCK.
/
RFMUFD	LAC	RF.FEB,X	/READ IN THE UFD BLOCK THAT CONTAINS
	DAC	RF.BLK,X	/THIS FILE'S ENTRY.
	JMS*	RFGTBL
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	JMP	RFRIBE		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
/
/ COMPUTE THE ADDRESS OF WORD 2 WITHIN THE 8-WORD FILE ENTRY IN THE UFD
/ BLOCK SO THAT AUTOINDEX REGISTER 10 CAN BE PREPARED TO MODIFY WORDS 3 & 4.
/
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF THE FILE DATA
	TAD	RF.FEL,X	/BUFFER.
	AAC	+2
	DAC*	(X10)
	LAC	RF.FES,X	/STORE THE FILE'S 1ST BLOCK NUMBER (ALSO
	DAC*	X10		/CLEARING THE "TRUNCATED" FILE INDICATOR).
	LAC	RF.FSZ,X	/STORE THE NUMBER OF DATA BLOCKS IN THE FILE;
	DAC*	X10		/BIT 0=0 TO INDICATE A SEQUENTIAL ACCESS FILE.
	LAC	RFRIB6		/STORE STARTING RIB BLOCK
	DAC*	X10
	LAC	RFRIB5		/STORE 1ST RIB WORD IN STARTING OR ONLY RIB BLOCK
	TAD	(100000		/ADD ON THE PROTECTION CODE
	DAC*	X10
	JMS*	RFPTBL		/WRITE OUT THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	JMP	RFCLSE		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
/
	.EJECT
	LAC	RF.OFF,X	/IS THERE AN OLD FILE ENTRY?
	SNA
	JMP	RFCLCC		/NO.
	LAC	RF.OFS,X	/YES -- GET THE OLD FILE'S STARTING BLOCK.
	JMS	RFQDEA		/DEALLOCATE THE OLD FILE'S BLOCKS.
	377777			/ARGUMENT -- NUMBER OF BLOCKS IN THE FILE
				/(SET SO LARGE THAT DEALLOCATION WILL
				/TERMINATE WHEN THE -1 LINK IS DETECTED
				/RATHER THAN WHEN THE COUNT RUNS OUT).
				/(R1, R2, R3, R6, LR, XR & AC ARE ALTERED;
				/THE XR IS LEFT POINTING AT THE FILE BUFFER).
	SKP			/#/ RETURN HERE IF THE "POOL" IS EMPTY.
	JMP	.+3		/RETURN HERE OTHERWISE.
	LAW	-777		/REMEMBER THAT A "POOL EMPTY" ERROR OCCURRED.
	DAC	RFERCD
/
/ REMOVE THE OLD FILE ENTRY FROM THE UFD.
/
	LAC	RF.OFB,X	/SET THE CURRENT BLOCK = THE UFD BLOCK
	DAC	RF.BLK,X	/CONTAINING THE OLD FILE ENTRY.
	JMS*	RFGTBL		/READ IN THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	JMP	RFCLSE		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF THE FILE ENTRY
	TAD	RF.OFL,X	/WITHIN THE DATA BLOCK.
	DAC	RFRIB1		/SAVE THE AC
	JMS	RFADJX		/SET THE XR UP TO ACCESS UFD ENTRY
	LAC	4,X		/GET THE FILE SIZE
	SPA			/IS THIS A RANDOM ACCESS FILE?
	JMP	RFCLZR-1	/YES -- THEN THERE IS NOT A RIB TO DEALLOCATE
	LAC	6,X		/NO -- GET THE STARTING RIB WORD
	AND	(077777		/AND OFF THE PROT. CODE
	SZA			/WAS THE RIB DATA IN LAST DATA BLOCK?
	JMP	RFCLZR-1	/YES -- THEN DON'T DEALLOCATE
	LAC	5,X		/NO -- GET THE STARTING RIB BLOCK AND
				/DEALLOCATE ALL RIB BLOCKS
	JMS	RFQDEA
	377777
	SKP			/#/RETURN HERE IF POOL WAS EMPTY
	JMP	.+3
	LAW	-1
	DAC	RFERCD
	LAC	RFRIB1		/RESTORE THE AC
RFCLZR	JMS	RFZERO		/ZERO OUT (FREE UP) THE FILE ENTRY.
	-10			/ARGUMENT -- WORD COUNT OF 8.
RFCLRW	JMS*	RFPTBL		/REWRITE THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
RFCLSE	DAC	RFERCD		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
RFCLCC	JMP	RFCLSI		/USE COMMON CODE TO RETURN THE FILE BUFFER
				/AND TO RELINQUISH THE ACTIVE LUN NODE.
/
	.EJECT
/ A DISK ERROR OCCURRED WHILE TRYING TO WRITE OUT THE OLD DATA BLOCK.
/
RFCLE1	DAC	RFERCD		/SAVE THE ERROR CODE.
	LAC	RF.NXB,X	/DEALLOCATE THE NEWLY-ALLOCATED BLOCK.
	JMS	RFQDEA		/(R1, R2, R3, R6, LR, XR & AC ARE ALTERED);
				/THE XR IS LEFT POINTING AT THE FILE BUFFER).
	1			/ARGUMENT -- BLOCK COUNT.
	JMP	RFCLPE		/#/ RETURN HERE IF THE "POOL" IS EMPTY.
	SKP			/RETURN HERE OTHERWISE.
/
/ A DISK ERROR OCCURRED (OR THE DISK IS FULL) WHILE TRYING TO
/ ALLOCATE ANOTHER BLOCK OR ELSE A DISK ERROR OCCURRED WHILE TRYING TO
/ WRITE OUT THE FINAL DATA BLOCK.
/
RFCLE2	DAC	RFERCD		/SAVE THE ERROR CODE.
	LAC	RF.BLK,X	/DEALLOCATE THE CURRENT DATA BLOCK.
	JMS	RFQDEA		/(R1, R2, R3, R6, LR, XR & AC ARE ALTERED;
				/THE XR IS LEFT POINTING AT THE FILE BUFFER).
	1			/ARGUMENT -- BLOCK COUNT.
	JMP	RFCLPE		/#/ RETURN HERE IF THE "POOL" IS EMPTY.
				/RETURN HERE OTHERWISE.
	LAW	-1		/IS THE FILE SIZE-1, WHICH EXCLUDES THE
	TAD	RF.FSZ,X	/CURRENT BLOCK JUST DEALLOCATED, EQUAL TO 0?
	SNA
	JMP	RFCL1B		/YES.
RFCLDA	DAC	.+3		/NO -- PREPARE TO DEALLOCATE THAT MANY BLOCKS.
	LAC	RF.FES,X
	JMS	RFQDEA		/(R1, R2, R3, R6, LR, XR & AC ARE ALTERED;
				/THE XR IS LEFT POINTING AT THE FILE BUFFER).
	XX			/ARGUMENT -- BLOCK COUNT.
	JMP	RFCLPE		/#/ RETURN HERE IF THE "POOL" IS EMPTY.
RFCL1B	SKP			/RETURN HERE OTHERWISE.
/
/ A DISK ERROR OCCURRED (OR THE DISK IS FULL) WHILE TRYING TO ALLOCATE
/ THE FILE'S FIRST DATA BLOCK. REMOVE THE FILE ENTRY FROM THE UFD.
/
RFCLE3	DAC	RFERCD		/SAVE THE ERROR CODE.
	LAC	RF.FEB,X	/SET THE CURRENT BLOCK = THE UFD BLOCK
	DAC	RF.BLK,X	/CONTAINING THE FILE ENTRY.
	JMS*	RFGTBL		/READ IN THAT UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	JMP	RFCLCC		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF THE FILE ENTRY
	TAD	RF.FEL,X	/WITHIN THE DATA BLOCK.
	JMS	RFZERO		/ZERO OUT (FREE UP) THE FILE ENTRY.
	-10			/ARGUMENT -- WORD COUNT OF 8.
				/(X10, RFTMP1 & AC ARE ALTERED).
/
	.EJECT
	JMS*	RFPTBL		/REWRITE THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	NOP			/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
	JMP	RFCLCC		/RETURN HERE IF NO ERROR OCCURRED.
/
/ A DISK ERROR OCCURRED WHILE TRYING TO READ IN THE UFD BLOCK CONTAINING
/ THE FILE ENTRY.
/
RFCLE4	DAC	RFERCD		/SAVE THE ERROR CODE.
	LAC	RF.FSZ,X	/DEALLOCATE ALL THE FILE'S BLOCKS.
	JMP	RFCLDA
/
/ DEALLOCATION CANNOT BE PERFORMED BECAUSE THE "POOL" IS EMPTY.
/
RFCLPE	LAW	-777
	DAC	RFERCD
	JMP	RFCLCC
	.TITLE *** CLOSE FILE TO BE RENAMED
/
/ VALIDATE THE FILE NAME AND EXTENSION.
/
RFCLRN	LAC	RFFNM1		/IS THE FILE NAME NULL?
	SZA!CLA
	JMP	.+3
	SAD	RFFNM2
	JMP	RFIFNM		/#/ YES -- ERROR.
	SAD	RFFEXT		/WHAT ABOUT THE EXTENSION?
	JMP	RFIFNM		/#/ YES -- ERROR.
/
/ SEARCH THE ACTIVE LUN DEQUE TO BE SURE THAT THE NEW FILE NAME IS NOT
/ ALREADY IN USE.
/
	LAC	RFALUN		/SET THE INDEX REGISTER TO START AT
	JMS	RFADJX		/THE HEAD OF RFALUN.
RFRNLP	LAC*	RFRQND		/SET AUTOINCREMENT REGISTER 10 TO
	IAC			/ACCESS THE TASK NAME IN THE REQUEST NODE.
	DAC*	(X10)
/
/ TEST FOR END OF DEQUE.
/
	LAC	0,X		/END OF RFALUN DEQUE?
	SAD	RFALUN
	JMP	RFRNSU		/YES.
	JMS	RFADJX		/NO -- SET THE INDEX REGISTER TO
				/POINT TO THE NEXT NODE.
/
/ CHECK THE ACTIVE LUN TO SEE IF THIS FILE IS ALREADY OPEN.
/
	LMQ			/SAVE THE NODE'S ADJUSTED ADDRESS IN THE MQ.
	LAC	11,X		/SET THE XR TO POINT TO THIS FILE'S
	JMS	RFADJX		/CORE BUFFER.
	LAC	RF.FN1,X	/FIRST HALF OF FILE NAME MATCH?
	SAD	RFFNM1
	SKP
	JMP	RFRNNM		/NO.
	LAC	RF.FN2,X	/YES -- SECOND HALF?
	SAD	RFFNM2
	SKP
	JMP	RFRNNM		/NO.
	LAC	RF.EXT,X	/YES -- EXTENSION?
	SAD	RFFEXT
	JMP	RFFLOP		/#/ YES -- ERROR -- FILE ALREADY OPEN.
/
/ TRY NEXT RFALUN NODE.
/
RFRNNM	LACQ			/RESTORE THE XR.
	PAX
	JMP	RFRNLP		/TRY THE NEXT NODE.
/
	.EJECT
/ SEARCH THE UFD TO BE SURE THAT THE FILE IS NOT BEING RENAMED WITH A
/ NAME ALREADY IN USE.
/
RFRNSU	JMS	RFXRFB		/SET THE XR TO POINT AT THE FILE BUFFER.
	LAC	RF.FEF,X	/GET THE STARTING BLOCK OF THE UFD
RFGBLC	DAC	RF.BLK,X	/SAVE THE BLOCK NUMBER.
	JMS*	RFGTBL		/GET THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
				/DISK ERROR?
	JMP	RFDKER		/#/ YES -- THE ERROR CODE IS IN THE AC.
	LAW	-37		/NUMBER OF FILE ENTRIES PER UFD BLOCK.
	DAC	RF.CNT
	JMS	RFDBFA		/PREPARE AUTOINDEX REGISTER 10 TO
	AAC	-1		/SCAN THROUGH THE DATA BLOCK (UFD).
/
RFSRCL	DAC*	(X10)
	PAL			/SAVE TEMPORARILY.
	LAC*	X10		/FIRST HALF OF FILE NAME MATCH?
	SAD	RFFNM1
	SKP
	JMP	RFSRCE		/NO.
	LAC*	X10		/YES -- SECOND HALF MATCH?
	SAD	RFFNM2
	SKP
	JMP	RFSRCE		/NO.
	LAC*	X10		/YES -- EXTENSION MATCH?
	SAD	RFFEXT
	JMP	RFRNER		/#/ ERROR -- FILE ALREADY EXISTS IN UFD.
/
/ MOVE TO THE NEXT UFD FILE ENTRY AND TEST FOR THE END OF THE BLOCK.
/
RFSRCE	ISZ	RF.CNT		/END OF UFD BLOCK?
	SKP			/NO.
	JMP	RFSRNB		/YES.
	PLA			/UPDATE AUTOINCREMENT REGISTER 10 FOR
	AAC	+10		/THE NEXT ENTRY.
	JMP	RFSRCL
/
/ THE CURRENT UFD BLOCK DOES NOT CONTAIN THE FILE. PREPARE TO READ IN
/ THE NEXT BLOCK IF ONE EXISTS.
/
RFSRNB	LAC	RF.DAT+377,X	/EXAMINE THE UFD BLOCK'S FORWARD LINKAGE.
	SAD	(-1)
	SKP
	JMP	RFGBLC		/READ IN THE NEXT UFD BLOCK.
/
	.EJECT
	LAC	RF.OFB,X	/SET THE CURRENT BLOCK = THE UFD BLOCK
	DAC	RF.BLK,X	/CONTAINING THE OLD FILE ENTRY.
	JMS*	RFGTBL		/READ IN THE UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	JMP	RFCLSE		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF THE FILE ENTRY
	TAD	RF.OFL,X	/WITHIN THE DATA BLOCK.
	JMS	RFADJX
	LAC	RFFNM1
	DAC	0,X
	LAC	RFFNM2
	DAC	1,X
	LAC	RFFEXT
	DAC	2,X
	JMP	RFCLRW		/REWRITE THE UFD BLOCK.
/
/ ERRORS.
/
RFRNER	LAW	-50		/RENAME ERROR -- FILE ALREADY EXISTS IN UFD.
	SKP
RFIFNM	LAW	-53		/ILLEGAL FILE NAME OR EXTENSION.
	SKP
RFFLOP	LAW	-54		/FILE OPEN ELSEWHERE.
RFDKER	JMP	RFCLSE		/USE COMMON CODE TO RETURN THE FILE BUFFER
				/AND TO RELINQUISH THE ACTIVE LUN NODE.
	.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 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
/
	.EJECT
/ SUBROUTINE RFDBFA -- COMPUTE THE ADDRESS OF THE FILE DATA BUFFER.
/
/ CALLING SEQUENCE:
/
/	XR POINTING AT THE FILE BUFFER
/	JMS	RFDBFA
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	AC
/
RFDBFA	0
	PXA
	TAD	RFPAGE
	TAD	(RF.DAT)
	JMP*	RFDBFA
/
/
/
/
/
/ SUBROUTINE RFZERO -- CLEAR A SPECIFIED AREA OF CORE.
/
/ CALLING SEQUENCE:
/
/	STARTING ADDRESS IN THE AC
/	JMS	RFZERO
/	TWOS COMPLEMENT WORD COUNT
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	X10, RFTMP1 & AC
/
RFZERO	0
	AAC	-1		/PREPARE AUTOINDEX REGISTER 10 WITH THE
	DAC*	(X10)		/FIRST ADDRESS MINUS 1.
	LAC*	RFZERO		/PICK UP THE WORD COUNT.
	DAC	RFTMP1
	DZM*	X10		/ZERO CORE.
	ISZ	RFTMP1
	JMP	.-2
	IDX	RFZERO
	JMP*	RFZERO
/
	.EJECT
/ SUBROUTINE RFQDEA -- QUEUE UP A DEALLOCATE REQUEST AT LOW PRIORITY (513).
/
/ CALLING SEQUENCE:
/
/	(FIRST BLOCK NUMBER IN THE AC)
/	JMS	RFQDEA
/	(NUMBER OF BLOCKS TO DEALLOCATE)
/	(ERROR RETURN IF "POOL" IS EMPTY)
/	(NON-ERROR RETURN WITH THE XR
/	POINTING AT THE FILE BUFFER)
/
/ ALTERED REGISTERS:
/
/	R1, R2, R3, R6, LR, XR & AC
/
RFQDEA	0
	PAL			/SAVE THE STARTING BLOCK NUMBER.
	JMS*	(PENP)		/PICK AN EMPTY NODE FROM THE POOL.
				/(R1, R6, XR & AC ARE ALTERED).
				/WAS A NODE FOUND?
	JMP	RFQDER		/#/ NO -- ERROR RETURN.
	DAC*	(R2)		/YES -- SAVE THE NODE'S ADDRESS FOR THE
				/CALL TO "SPRI".
	JMS	RFADJX		/SET THE XR TO POINT TO THE NODE.
	LAC*	RFSTL		/STORE THE ADDRESS OF THIS TASK'S STL NODE.
	DAC	2,X
	DZM	3,X		/0=EXECUTIVE MODE TASK.
	.DEC
	LAC	(513)		/ENTRY WILL BE MADE AT PRIORITY 513,
	.OCT			/WHICH IS LOWER THAN THAT OF ANY TASK
	DAC	4,X		/BUT HIGHER THAN REASSIGN'S "DISCONNECT
				/AND EXIT" REQUEST.
	DZM	5,X		/SPECIAL FORM OF DEALLOCATE IS I/O FUNCTION
				/CODE 0 MADE FROM LUN 0. SEE THE CHECK
				/MADE BY THE DEALLOCATE ROUTINE IN THE
				/RESIDENT PART OF THIS HANDLER.
	PLA			/SAVE THE FIRST BLOCK TO BE DEALLOCATED.
	DAC	7,X
	LAC*	RFQDEA		/SAVE THE COUNT OF THE NUMBER OF BLOCKS
	AND	(377777)	/TO BE DEALLOCATED. MAKE SURE BIT 0=0 TO
	DAC	10,X		/INDICATE THAT THESE BLOCKS COME FROM A
				/SEQUENTIAL ACCESS FILE.
	LAC*	RFPDNA		/COMPUTE THE ADDRESS OF THE HEAD OF THE
	AAC	+6		/I/O REQUEST DEQUE WITHIN THE PHYSICAL
	DAC*	(R1)		/DEVICE NODE.
	JMS*	(SPRI)		/INSERT THE NODE BY PRIORITY.
				/(R1, R2, R3, R6, XR & AC ARE ALTERED).
	IDX	RFQDEA
RFQDER	IDX	RFQDEA
	JMS	RFXRFB		/SET THE XR TO POINT TO THE FILE BUFFER.
	JMP*	RFQDEA
	.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.
/
/ 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=22		/START OF 400 OCTAL WORD FILE DATA BLOCK.
	.TITLE *** VARIABLES
/
/ VARIABLES.
/
RFARG1	0			/I/O ARGUMENT 1.
RFFNM1=RFARG1			/1ST HALF OF FILE NAME IN .SIXBT.
RFARG2	0			/I/O ARGUMENT 2.
RFFNM2=RFARG2			/2ND HALF OF FILE NAME IN .SIXBT.
RFARG3	0			/I/O ARGUMENT 3.
RFFEXT=RFARG3			/FILE NAME EXTENSION IN .SIXBT.
RFTMP1	0			/TEMPORARY STORAGE.
RFPAGE	0			/PAGE ADDRESS BITS FOR THE PAGE IN WHICH
				/THIS CODE IS LOCATED.
RFXADJ	0			/INDEX REGISTER ADJUSTMENT FACTOR (SEE
				/INITIALIZATION CODE IN RESIDENT SECTION
				/FOR AN EXPLANATION). C(RFXADJ) = -C(RFPAGE).
RF.CNT	0			/COUNTER.
RFALNA	0			/ACTIVE LUN NODE ADDRESS.
RFERCD	0			/TEMPORARY STORAGE FOR ERROR CODE.
RFCODE	0			/34=CLOSE; 17=ABORT; 134=ERROR CLOSE;
				/777=DISCONNECT & EXIT.
/
/ END-OF-FILE RECORD (CONSISTING OF ONLY A LINE BUFFER HEADER WORD PAIR).
/
RFEOFL	001005			/1 WORD PAIR; END-OF-FILE.
RFEOFC	776773			/CHECKSUM.
/
	.END
