	.TITLE *** RSX DISK FILES HANDLER OVERLAY #5
/
/ 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
/
/ INTERNALLY DEFINED GLOBAL SYMBOL: MUST BE THE SAME AS THE FILE NAME.
/
	.GLOBL	RFCREA
/
/ EXTERNALLY DEFINED GLOBAL SYMBOLS.
/
	.GLOBL	RFRQND,RFALUN,RFAL1B,RFSREV,RFGTBL,RFPTBL,RFBFAD
	.GLOBL	RFCLFL,RFFLBF,RFLUNN
/
	.IFUND %RF15
	.GLOBL RFUNIT
	.ENDC
/
/ DEFINITION OF REGISTERS LOCATED WITHIN THE RSX EXECUTIVE.
/
X10=10				/AUTOINCREMENT REGISTER 10.
R1=101				/GENERAL REGISTER #1.
R2=102				/GENERAL REGISTER #2.
R3=103				/GENERAL REGISTER #3.
R4=104				/GENERAL REGISTER #4.
NADD=107			/ENTRY POINT TO "ADD
				/NODE TO DEQUE" SUBROUTINE.
MONTH=166			/1 - 12.
DAY=167				/1 - 31.
YEAR=170			/0 - 99.
POOL=240			/HEAD OF THE EMPTY NODES DEQUE.
VAJX=342			/ENTRY POINT TO "VERIFY AND ADJUST TO 17
LUFD1=304			/ADDR. OF PTR TO START OF LUN-UFD TABLE
				/BITS I/O TRANSFER PARAMETER" SUBROUTINE.
/
/ 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.
ECLA=641000			/CLEAR AC WITH EAE.
/
	.TITLE *** CREATE (A RANDOM ACCESS FILE)
/
RFCREA	0
	LAC	(.)		/COMPUTE THE PAGE ADDRESS BITS FOR THIS
	AND	(70000)		/OVERLAY AND SAVE THEM IN BOTH POSITIVE
	DAC	RFPAGE		/AND NEGATIVE FORM.
	TCA
	DAC	RFXADJ
	DZM	RFERCD
/
/ VERIFY THAT THE CONTROL TABLE LIES WITHIN THE TASK'S CORE.
/
	LAC*	RFRQND		/SET THE XR WITH THE REQUEST NODE'S ADDRESS.
	DAC*	(R2)
	JMS	RFADJX
	LAC	7,X		/ADDRESS OF THE CONTROL TABLE.
	DAC*	(R3)
	LAC	(11)		/SIZE OF THE CONTROL TABLE.
	DAC*	(R4)
	JMS*	(VAJX)		/VERIFY THE CONTROL TABLE LIMITS AND SET
				/THE ADJUSTED 17-BIT TABLE ADDRESS IN R3.
				/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	RFXPER		/#/ YES -- CONTROL TABLE EXCEEDS TASK LIMITS.
	LAC*	(R3)		/NO -- SAVE THE ADDRESS.
	DAC	RFCTAB
	JMS	RFADJX
/
/ PICK UP THE CONTROL TABLE PARAMETERS.
/
	LAC	0,X
	DAC	RFFNM1		/FILE NAME (FIRST HALF).
	LAC	1,X
	DAC	RFFNM2		/FILE NAME (SECOND HALF).
	LAC	2,X
	DAC	RFFEXT		/FILE NAME EXTENSION.
	LAC	3,X
	DAC	RFFSIZ		/FILE SIZE (# OF 256-WORD BLOCKS).
	AND	(777000)
	SZA
	JMP	RFSZER		/#/ SIZE ERROR -- NEGATIVE OR > 777.
	LAC	4,X
	DAC	RFACT1		/ACCOUNTING INFORMATION.
	LAC	5,X
	DAC	RFACT2		/ACCOUNTING INFORMATION.
	LAC	6,X
	DAC	RFUPDT		/UPDATE INDICATOR.
/
	.EJECT
/ USE THIS HANDLER'S INTERNAL FILE BUFFER TO READ IN UFD BLOCKS.
/
	LAC	RFFLBF
	DAC*	RFBFAD
/
/ SEARCH THE ACTIVE LUN DEQUE TO SEE IF THE FILE IS ALREADY IN USE.
/
	LAC	RFALUN		/SET THE INDEX REGISTER TO START AT
	JMS	RFADJX		/THE HEAD OF RFALUN.
/
RFALLP	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	RFANEW		/YES.
	JMS	RFADJX		/NO -- SET THE INDEX REGISTER TO
				/POINT TO THE NEXT NODE.
/
/ TEST FOR TASK NAME. (ACTUALLY, IT IS NOT A TASK NAME -- SEE COMMENTS
/ AT "RFALUN" IN RESIDENT CODE).
/
	LAC	2,X		/FIRST HALF OF TASK NAME FOUND?
	SAD*	X10
	SKP
	JMP	RFALCF		/NO -- TRY NEXT CHECK.
	LAC	3,X		/SECOND HALF FOUND?
	SAD*	X10
	SKP
	JMP	RFALCF		/NO -- TRY NEXT CHECK.
/
/ TEST FOR LUN.
/
	LAC*	X10		/SKIP THE PRIORITY CODE.
	LAC	5,X		/DO THE LUNS MATCH?
	XOR*	X10
	AND	(777000)
	SZA
	JMP	RFALCF		/NO -- TRY NEXT CHECK.
/
	.EJECT
/#/ THE TASK-LUN NODE IN RFALUN HAS BEEN FOUND. THAT MEANS THAT THAT TASK
/ STILL HAS A FILE OPEN ON THAT LUN, WHICH IS AN ERROR.
/
	LAW	-10
	DAC*	RFCLFL		/SET A FLAG FOR THE "DONE" CODE SO THAT
				/IT WILL CLOSE THE FILE.
	JMP*	RFSREV
/
/ CHECK THE ACTIVE LUN TO SEE IF THIS FILE IS ALREADY OPEN.
/
RFALCF	PXA
	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	RFNALN		/NO.
	LAC	RF.FN2,X	/YES -- SECOND HALF?
	SAD	RFFNM2
	SKP
	JMP	RFNALN		/NO.
	LAC	RF.EXT,X	/YES -- EXTENSION?
	SAD	RFFEXT
	JMP	RFFLOP		/#/ ERROR -- FILE ACTIVE.
/
/ TRY NEXT RFALUN NODE.
/
RFNALN	LACQ			/RESTORE THE XR.
	PAX
	JMP	RFALLP		/TRY THE NEXT NODE.
/
	.EJECT
/ A SCAN OF THE RFALUN DEQUE DID NOT TURN UP A NODE FOR THE TASK-LUN
/ COMBINATION OF THE CURRENT I/O REQUEST. VALIDATE THE FILE NAME AND
/ EXTENSION.
/
RFANEW	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.
/
	JMS	RFXRFB		/SET THE XR TO POINT TO THE FILE BUFFER.
	TAD	RFPAGE		/COMPUTE THE ADDRESS OF THE BUFFER AND
	JMS	RFZERO		/THEN ZERO OUT THE FILE DESCRIPTORS.
	-RF.DAT			/ARGUMENT -- NEGATIVE WORD COUNT.
				/(X10, RFTMP1 & AC ARE ALTERED).
/
/ MOVE THE FILE NAME TO THE FILE BUFFER, TO BE USED BY THE SEARCH
/ SUBROUTINE. ALTHOUGH THIS ADDS 6 INSTRUCTIONS WHICH COULD BE AVOIDED,
/ KEEPING THE SAME SUBROUTINE IN ALL THE OVERLAYS AVOIDS A POTENTIAL
/ BOOBYTRAP SHOULD SOMEONE WANT TO LIFT THE CODE.
/
	LAC	RFFNM1
	DAC	RF.FN1,X
	LAC	RFFNM2
	DAC	RF.FN2,X
	LAC	RFFEXT
	DAC	RF.EXT,X
/
/ DETERMINE WHERE THE 1ST BLOCK OF THE UFD IS STORED AND GET IT
/
	LAC*	(LUFD1		/CALC THE ADDR OF THE LUN-UFD TABLE ENTRY
	AAC	-1
	TAD*	RFLUNN
	DAC	RFTMP1		/SAVE IT
	LAC*	RFTMP1		/GET THE UFD NAME
	SNA			/IS DISK DISMOUNTED?
	JMP	RFUIDR		/#/YES -- ERROR
	DAC	RFTMP1		/NO -- SAVE UFD NAME
	.IFUND	%RP02
	LAC	(1777		/GET MFD START BLK FOR RF AND RK
	.ENDC
	.IFDEF	%RP02
	LAC	(47040		/GET MFD START BLOCK FOR RP
	.ENDC
RFMFD1	DAC	RF.BLK,X	/MAKE THIS BLOCK CURRENT
	JMS*	RFGTBL		/GET THIS BLOCK
	JMP	RFDKER		/#/RETURN HERE ON ERROR
	JMS	RFDBFA		/RETURN HERE IF OK -- MAKE AC+START OF BUFFER
	AAC	-1		/SETUP X10 AS A POINTER TO BUFFER
	DAC*	(X10
	AAC	370		/MAKE RFTMP2 POINT TO LAST ENTRY
	DAC	RFTMP2
RFMFD2	LAC*	X10		/GET AN UFD NAME
	SAD	RFTMP1		/DOES IT MATCH?
	JMP	RFMFD3		/YES
	LAC*	(X10		/NO -- END OF MFD BLK?
	SAD	RFTMP2
	JMP	RFMFD4		/YES
	AAC	3		/NO -- INCREMENT X10
	DAC*	(X10
	JMP	RFMFD2		/GO LOOK AT NEXT ENTRY
RFMFD4	LAC	RF.DAT+377,X	/LAST MFD BLOCK?
	SAD	(-1
	JMP	RFUIDR		/#/YES -- ERROR
	JMP	RFMFD1		/NO -- PREPARE TO GET NEXT MFD BLK
RFMFD3	LAC*	X10		/GET STARTING UFD BLK
	SAD	(-1		/IS IT INITIALIZED?
	JMP	RFUIDR		/#/NO -- ERROR
	DAC	RFUFDB		/YES -- SAVE BLK NO.
/
/ SEARCH THE FILE DIRECTORY FOR THE EXISTENCE OF THIS FILE AND FOR A FREE ENTRY
/
RFGBLN	DAC	RF.BLK,X	/SET THE CURRENT BLOCK NUMBER.
	JMS*	RFGTBL		/READ IN THE CURRENT BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	JMP	RFDKER		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE OTHERWISE.
	JMS	RFSRCH		/SEARCH THE UFD BLOCK FOR A FREE FILE
				/ENTRY SLOT AND FOR THE EXISTENCE OF
				/THE OLD FILE ENTRY.
				/(X10, LR, AC & RF.CNT ARE ALTERED).
	LAC	RF.OFF,X	/WAS THE OLD FILE FOUND?
	SZA
	JMP	RFENFF		/YES.
/
/ THE CURRENT UFD BLOCK DOES NOT CONTAIN THE FILE.
/
	LAC	RF.DAT+377,X    /IS THIS THE FINAL UFD BLOCK?
	SAD	RFL002		/SAD (-1).
	SKP			/YES.
	JMP	RFGBLN		/NO -- READ IN THE NEXT ONE.
/
/ THE FINAL UFD BLOCK HAS BEEN READ. IF A FREE FILE ENTRY SLOT HAS NOT
/ BEEN FOUND, ADD ANOTHER BLOCK TO THE UFD.
/
	LAC	RF.FEF,X	/WAS A FREE ENTRY FOUND?
	SZA
	JMP	RFNTER		/YES.
	JMS*	RFAL1B		/NO -- ALLOCATE A BLOCK OF 256 WORDS
				/ON THE DISK.
				/(EFFECTIVELY, ALL REGISTERS + RFTMP1
				/ARE ALTERED).
				/WAS A BLOCK ALLOCATED?
	JMP	RFDKER		/#/ NO -- ERROR CODE IS IN THE AC.
/
/ THE XR IS POINTING AT THE FILE BUFFER.
/
	DAC	RF.DAT+377,X    /YES -- SET THE FORWARD LINKAGE IN THE
				/CURRENT UFD BLOCK (WHICH WILL NOW BE
				/THE NEXT TO LAST UFD BLOCK) TO POINT
				/TO THE NEWLY ALLOCATED BLOCK.
	JMS*	RFPTBL		/WRITE OUT THE CURRENT UFD BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	DAC	RFERCD		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
/
/ *********************************************************************
/
/ NOTE -- I/O SHOULD NOT BE ABORTED AT THIS POINT SINCE THE UFD IS
/ NOW OPEN-ENDED, I.E., THE FORWARD LINK IN THE LAST UFD BLOCK ISN'T -1.
/
/ *********************************************************************
/
/ INITIALIZE THE NEWLY-CREATED UFD BLOCK.
/
	LAC	RF.BLK,X	/SAVE THE NUMBER OF THE NEXT-TO-LAST
	DAC	RF.DAT+376,X    /UFD BLOCK AS THE BACKWARD LINK.
	LAC	RF.DAT+377,X    /MAKE THE NEWLY ALLOCATED UFD BLOCK
	DAC	RF.BLK,X	/THE CURRENT DISK BLOCK.
	LAW	-1		/SET THE FORWARD BLOCK LINKAGE WORD
	DAC	RF.DAT+377,X    /TO INDICATE THIS IS THE LAST BLOCK.
	JMS	RFDBFA		/GET THE FILE DATA BUFFER ADDRESS AND ZERO
	JMS	RFZERO		/ALL BUT THE LAST 2 WORDS IN THE DATA BUFFER.
	-376			/(X10, RFTMP1 & AC ARE ALTERED).
	JMS	RFSRCH		/SEARCH THE UFD BLOCK FOR A FREE FILE
				/ENTRY SLOT.
				/(X10, LR, AC & RF.CNT ARE ALTERED).
	JMP	RFALOC		/ALLOCATE THE FILE STORAGE.
/
	.EJECT
/ THE FILE HAS BEEN FOUND. X10 IS SET FOR PICKING UP FILE ENTRY WORD 4.
/
RFENFF	LAC	RF.OFS,X	/SAVE THE FILE'S STARTING BLOCK NUMBER.
	DAC	RFSTBL
	LAC*	X10		/IS THIS A RANDOM ACCESS FILE?
	SMA
	JMP	RFNOTR		/#/ NO -- ERROR.
	AND	(377777)	/YES.
	DAC	RFSIZE		/SAVE FILE SIZE.
	SAD	RFFSIZ
	JMP	RFSZOK
	LAW	-60		/SIZE ERROR. SET ERROR CODE, BUT RETURN
	DAC	RFERCD		/THE PARAMETERS TO THE REQUESTER ANYWAY.
	JMP	RFCHKA
RFSZOK	LAC	RFUPDT		/DOES THE REQUEST ASK TO UPDATE THE
	SNA			/ACCOUNTING INFORMATION?
	JMP	RFCHKA		/NO.
/
/ UPDATE THE ACCOUNTING INFORMATION IN THE UFD ENTRY.
/
	LAC	RFACT1		/YES.
	DAC*	X10
	LAC	RFACT2
	DAC*	X10
	JMP	RFREWR		/REWRITE THE UFD BLOCK.
/
/ CHECK THE ACCOUNTING INFORMATION FOR A MATCH.
/
RFCHKA	LAC	RFCTAB		/SET THE XR TO POINT TO THE "CREATE"
	JMS	RFADJX		/CONTROL TABLE.
	LAC	RFSIZE
	DAC	3,X		/SAVE THE FILE SIZE.
	LAC*	X10
	SAD	RFACT1
	JMP	RFCKA2
	DAC	4,X		/SAVE THE ACCOUNTING INFORMATION.
	LAW	-61		/#/ ERROR -- ACCOUNTING INFORMATION DIFFERS.
	DAC	RFERCD
RFCKA2	LAC*	X10
	SAD	RFACT2
	JMP	.+4
	DAC	5,X		/SAVE THE ACCOUNTING INFORMATION.
	LAW	-61		/#/ ERROR -- ACCOUNTING INFORMATION DIFFERS.
	DAC	RFERCD
	JMP	RFDONE
/
	.EJECT
/ PREPARE TO ENTER THE FILE NAME INTO THE DIRECTORY. FIRST, MAKE SURE
/ THAT THE PROPER UFD BLOCK IS IN CORE.
/
RFNTER	LAC	RF.FEB,X	/IS THE CURRENT BLOCK THE ONE WITH THE
	SAD	RF.BLK,X	/FREE ENTRY?
	JMP	RFALOC		/YES.
	DAC	RF.BLK,X	/NO -- READ IN THAT UFD BLOCK.
	JMS*	RFGTBL		/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	JMP	RFDKER		/#/ RETURN HERE, IF AN ERROR OCCURRED,
				/WITH THE ERROR CODE IN THE AC.
				/RETURN HERE OTHERWISE.
/
/ ALLOCATE CONTIGUOUS DISK SPACE FOR THE FILE.
/
RFALOC	LAC	RFFSIZ		/CONVERT THE NUMBER OF BLOCKS INTO A
	CLL			/WORD COUNT.
	ALS	10
	DAC	RFALWC
	.IFUND %RF15
	LAC*	RFUNIT		/FOR MULTI-UNIT DISKS ADD IN THE UNIT NO.
	CLL			/TO THE HIGH ORDER 3 BITS OF THE PLATTER WORD.
	ALS	17
	DAC	RFPLAT
	.ENDC
	CAL	RFACPB		/ALLOCATE DISK STORAGE.
	CAL	RFWAIT		/WAITFOR COMPLETION.
	JMS	RFXRFB		/RESTORE THE XR WITH THE FILE BUFFER ADDRESS.
	LAC	RFIOEV		/ERROR?
	SPA!CLL
	JMP	RFDKER		/#/ YES -- ERROR CODE IS IN THE AC.
/
/ CONVERT THE DISK ADDRESS AND PLATTER NUMBER INTO A BLOCK NUMBER.
/
	.IFDEF %RF15
	LAC	RFPLAT		/EACH PLATTER CONTAINS 2000 OCTAL BLOCKS.
	ALS	12
	DAC	RFTMP1
	LAC	RFDADR		/CONVERT THE DISK ADDRESS TO A FILE BLOCK #.
	LRS	10
	TAD	RFTMP1
	.ENDC
	.IFUND %RF15
	LAC	RFDADR		/CALC. BLK NO. FOR RP AND RK
	LMQ
	LAC	RFPLAT
	AND	(007777		/MAKE SURE THE UNIT NO. IS REMOVED
	LRSS	10
	LACQ
	.ENDC
	DAC	RF.FES,X	/SAVE THE STARTING BLOCK NUMBER.
	DAC	RFSTBL
/
/ CHANGE THE FREE FILE ENTRY SLOT IN THE UFD TO ENTER THIS FILE.
/
	JMS	RFDBFA		/SET AUTOINDEX REGISTER 10 IN ORDER
	AAC	-1		/TO STORE THE FILE PARAMETERS IN THE
	TAD	RF.FEL,X	/FREE ENTRY SLOT.
	DAC*	(X10)
/
	LAC	RFFNM1		/STORE THE FILE NAME.
	DAC*	X10
	LAC	RFFNM2
	DAC*	X10
	LAC	RFFEXT		/STORE THE FILE NAME EXTENSION.
	DAC*	X10
	LAC	RF.FES,X	/STORE THE FILE'S STARTING BLOCK NUMBER.
	DAC*	X10
	LAC	RFFSIZ		/STORE THE FILE SIZE (NUMBER OF BLOCKS)
	TAD	(400000)	/AND SET BIT 0=1 TO INDICATE THAT THIS
	DAC*	X10		/IS A RANDOM RATHER THAN A SEQUENTIAL
				/ACCESS FILE.
	LAC	RFACT1		/STORE THE TWO WORDS OF ACCOUNTING
	DAC*	X10		/INFORMATION.
	LAC	RFACT2
	DAC*	X10
/
/ COMPUTE THE DATE AS IS DONE FOR DOS-15.
/
	CLQ			/STORE THE DATE IN THE FORM: MM/DD/YY,
				/WHERE YY=0 FOR 1970.
	.INH
	LAC*	(YEAR
	AAC	-106
	AND	(77
	DAC	RFTMP1
	LAC*	(MONTH
	AND	(77
	PAL
	LAC*	(DAY
	.ENB
	AND	(77
	CLQ
	LRS	6
	PLA
	LRS	6
	LACQ
	TAD	RFTMP1
	DAC*	X10
/
	.EJECT
/ WRITE THE UFD BLOCK ONTO THE DISK.
/
RFREWR	JMS*	RFPTBL		/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED -- THE XR IS LEFT POINTING AT
				/THE FILE BUFFER).
	JMP	RFDKER		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
				/RETURN HERE IF NO ERROR OCCURRED.
/
/ RETURN THE PLATTER NUMBER AND DISK ADDRESS CORRESPONDING TO THE START-
/ ING BLOCK OF THE FILE IN WORDS CTB+7 AND CTB+10 OF THE CONTROL TABLE.
/
RFDONE	LAC	RFCTAB		/SET THE XR TO POINT AT THE CONTROL TABLE.
	JMS	RFADJX
	.IFUND %RF15
	LAC*	RFUNIT
	CLL
	ALS	17
	DAC	RFTMP1
	.ENDC
	CLL			/COMPUTE THE PLATTER #.
	LAC	RFSTBL
	AND	(377777)
	.IFDEF %RF15
	LRS	12
	DAC	7,X
	LAC	RFSTBL		/COMPUTE THE DISK ADDRESS.
	AND	(1777)
	ALS	10
	.ENDC
	.IFUND %RF15
	LMQ
	LLSS!ECLA 10
	XOR	RFTMP1		/XOR IN THE UNIT NO.
	DAC	7,X
	LACQ
	.ENDC
	DAC	10,X
/
	LAC	RFERCD		/DID AN ERROR OCCUR?
	SZA
	JMP	RFDKER		/#/ YES.
	CLA!IAC			/NO -- I/O REQUEST COMPLETED. SET THE
	JMP*	RFSREV		/REQUESTER'S EVENT VARIABLE TO +1.
/
/ ERRORS.
/
RFXPER	LAW	-30		/CONTROL TABLE DOESN'T LIE WITHIN THE TASK.
	SKP
RFUIDR	LAW     -33		/UNINITIALIZED DIRECTORY OR DISMOUNTED DISK
	SKP
RFIFNM	LAW	-53		/ILLEGAL FILE NAME OR EXTENSION.
	SKP
RFFLOP	LAW	-54		/FILE OPEN ELSEWHERE.
	SKP
RFNOTR	LAW	-57		/CAN'T "CREATE" WHEN A SEQUENTIAL FILE
	SKP			/OF THE SAME NAME EXISTS.
RFSZER	LAW	-62		/RANDOM ACCESS FILE SIZE ERROR -- RE-
				/QUESTED SIZE IS NEGATIVE OR GREATER
				/THAN 777 OCTAL BLOCKS.
RFDKER	JMP*	RFSREV		/SET REQUESTER'S EVENT VARIABLE.
	.TITLE *** DIRECTORY SEARCH SUBROUTINE
/
/ SUBROUTINE RFSRCH -- A UFD BLOCK IS IN THE FILE DATA BUFFER. SEARCH
/ THE BLOCK FOR A FREE FILE ENTRY SLOT AND ALSO FOR THE FILE NAME IN
/ QUESTION.
/
/ CALLING SEQUENCE:
/
/	XR POINTING AT THE FILE BUFFER
/	JMS	RFSRCH
/	(UNCONDITIONAL RETURN)
/
/ THE CALLER MUST INITIALIZE THE FREE-ENTRY-FOUND FLAG (RF.FEF) AND
/ THE OLD-FILE-ENTRY-FOUND FLAG (RF.OFF) IN THE FILE BUFFER AS
/ APPROPRIATE.
/
/ ALTERED REGISTERS:
/
/	X10, LR, AC & RF.CNT
/
RFSRCH	0
	LAW	-37		/NUMBER OF FILE ENTRIES PER UFD BLOCK.
	DAC	RF.CNT
	DZM	RF.REL		/RELATIVE POSITION WITHIN THE BLOCK.
	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	RF.FN1,X
	SKP
	JMP	RFSRFE		/NO -- TRY FOR FREE ENTRY.
	LAC*	X10		/YES -- SECOND HALF MATCH?
	SAD	RF.FN2,X
	SKP
	JMP	RFSRCE		/NO.
	LAC*	X10		/YES -- EXTENSION MATCH?
	SAD	RF.EXT,X
	SKP
	JMP	RFSRCE		/NO.
/
/ OLD FILE ENTRY FOUND -- RECORD ITS LOCATION AND TYPE.
/
	LAC	RF.BLK,X	/NUMBER OF THE CURRENT UFD BLOCK.
	DAC	RF.OFB,X
	LAC	RF.REL		/RELATIVE LOCATION WITHIN THE BLOCK.
	DAC	RF.OFL,X
	LAC*	X10		/BIT 0 = 1 INDICATES A TRUNCATED FILE AND
	DAC	RF.OFS,X	/BITS 1-17 = THE STARTING BLOCK NUMBER.
RFL002	LAW	-1		/[USED AS A LITERAL].
	DAC	RF.OFF,X	/SET FLAG TO INDICATE "OLD FILE FOUND".
	JMP*	RFSRCH
/
/ TEST FOR FREE ENTRY IN UFD.
/
RFSRFE	SZA			/ENTRY = 0?
	JMP	RFSRCE		/NO -- NOT A FREE ENTRY.
	LAC	RF.FEF,X	/YES -- HAS A FREE ENTRY ALREADY BEEN FOUND?
	SZA
	JMP	RFSRCE		/YES.
	LAC*	X10		/NO -- WORD 2 = 0?
	SZA!CLC
	JMP	RFSRCE		/NO -- NOT A FREE ENTRY.
	SAD*	X10		/YES -- WORD 3 = 0?
	JMP	RFSRCE		/NO -- NOT A FREE ENTRY.
/
/ FREE FILE ENTRY FOUND -- RECORD ITS LOCATION.
/
	LAC	RFUFDB		/GET THE UFD BLOCK
	DAC	RF.FEF,X	/SET THE FLAG TO INDICATE "FREE FILE
				/ENTRY FOUND".
	LAC	RF.BLK,X	/NUMBER OF THE CURRENT UFD BLOCK.
	DAC	RF.FEB,X
	LAC	RF.REL		/RELATIVE POSITION WITHIN THE UFD BLOCK.
	DAC	RF.FEL,X
/
/ 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*	RFSRCH		/YES -- RETURN.
	LAC	RF.REL		/UPDATE THE RELATIVE FILE ENTRY LOCATION.
	AAC	+10
	DAC	RF.REL
	PLA			/UPDATE AUTOINCREMENT REGISTER 10 FOR
	AAC	+10		/THE NEXT ENTRY.
	JMP	RFSRCL
	.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 A NODE TO THE POOL OF EMPTY NODES.
/
/ CALLING SEQUENCE:
/
/	NODE ADDRESS IN THE AC
/	JMS	RFRTND
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	R2, R6, XR & AC
/
RFRTND	0
	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 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
/
/
/
/
/
/ 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
/
	.EJECT
/ 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
	.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 AND CAL PARAMETER BLOCKS
/
/ VARIABLES.
/
RFCTAB	0			/ADDRESS OF THE "CREATE" CONTROL TABLE.
RFFNM1	0			/1ST HALF OF FILE NAME IN .SIXBT.
RFFNM2	0			/2ND HALF OF FILE NAME IN .SIXBT.
RFFEXT	0			/FILE NAME EXTENSION IN .SIXBT.
RFFSIZ	0			/DESIRED FILE SIZE (# OF 256-WORD BLOCKS).
RFSIZE	0			/ACTUAL FILE SIZE (# OF 256-WORD BLOCKS).
RFACT1	0			/ACCOUNTING INFORMATION (# OF RECORDS).
RFACT2	0			/ACCOUNTING INFORMATION (# OF WORDS PER RECORD).
RFUPDT	0			/0=DON'T UPDATE; NON-0=UPDATE ACCOUNTING INFO.
RFSTBL	0			/FILE'S STARTING BLOCK NUMBER.
RFIOEV	0			/I/O EVENT VARIABLE.
RFTMP1	0			/TEMPORARY STORAGE.
RFTMP2	0
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.
RF.REL	0			/RELATIVE POSITION WITHIN UFD BLOCK.
RFERCD	0			/TEMPORARY STORAGE FOR THE ERROR CODE.
RFUFDB	0			/UFD START BLOCK
/
/ CAL PARAMETER BLOCKS AND CONTROL TABLES.
/
RFACPB	11500			/"ALLOCATE" DISK STORAGE CPB.
	RFIOEV
	1			/LUN 1 = RF DISK I/O DRIVER.
	RFALWC			/CONTROL TABLE ADDRESS.
	.IFDEF %RF15		/DEVICE CODE
	2
	.ENDC
	.IFDEF %RP02
	3
	.ENDC
	.IFDEF %RK05
	24
	.ENDC
/
RFALWC	0			/# OF WORDS DESIRED.
RFPLAT	0			/PLATTER #.
RFDADR	0			/DISK ADDRESS.
/
RFWAIT	20			/"WAITFOR" CPB.
	RFIOEV
/
	.END
