	.TITLE *** RSX DISK FILES HANDLER OVERLAY #2
/
/ COPYRIGHT (C) 1975
/ DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/ THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/ THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/ SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/ VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/ EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/ THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/ SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/ WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/ MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/ DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/ OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY
/ DEC.
/
	.EJECT
/
/	EDIT	#75	26 JUN 75	C. PROTEAU
/					M. HEBENSTREIT
/
/
/ NOTE: THIS OVERLAY REQUIRES NO ASSEMBLY PARAMETERS.
/
/ INTERNALLY DEFINED GLOBAL SYMBOL: MUST BE THE SAME AS THE FILE NAME.
/
	.GLOBL	RFREAD
/
/ EXTERNALLY DEFINED GLOBAL SYMBOLS.
/
	.GLOBL	RFRQND,RFALUN,RFAL1B,RFSREV,RFGTBL,RFPTBL,RFBFAD,RFCLFL
/
/ 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.
R3=103				/GENERAL REGISTER #3.
R4=104				/GENERAL REGISTER #4.
NADD=107			/ENTRY POINT TO "ADD
				/NODE TO DEQUE" SUBROUTINE.
POOL=240			/HEAD OF THE EMPTY NODES DEQUE.
VAJX=342			/ENTRY POINT TO "VERIFY AND ADJUST I/O
				/TRANSFER PARAMETERS TO 17 BITS" SUBROUTINE.
/
/ 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.
/
RFREAD	0			/ENTRY POINT TO READ/WRITE OVERLAY WITH THE
	SAD	(027)		/FUNCTION CODE IN THE AC.
	JMP	RFWRIT		/WRITE.
				/READ.
	.TITLE *** READ FROM SEQUENTIAL FILE
/
	JMS	RFRWCS		/USE COMMON READ/WRITE CODE TO VERIFY
	32			/THAT A FILE WAS PROPERLY OPENED. VALIDATE
				/AND SAVE THE READ PARAMETERS IN THE FILE
				/BUFFER. THE 32 IS AN ARGUMENT TO THE
				/CALL -- IT IS THE CAL FUNCTION CODE FOR "SEEK".
				/(AC & XR ARE ALTERED).
				/RETURN HERE, IF NO ERROR OCCURRED, WITH
				/THE XR POINTING AT THE FILE BUFFER.
/
/ VALIDATE THE BUFFER SIZE.
/
	LAC	RFBFSZ		/THE BUFFER SIZE.
	DAC*	(R4)		/SAVE FOR "VAJX" BELOW.
	SPA
	JMP	RFIBSZ		/#/ ILLEGAL BUFFER SIZE (<0).
	AAC	-3
	SPA
	JMP	RFIBSZ		/#/ ILLEGAL BUFFER SIZE (<3).
/
/ VERIFY AND ADJUST THE ADDRESS OF THE LINE BUFFER HEADER TO 17 BITS.
/
	LAC*	RFRQND		/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	LAC	RFHEAD		/ADDRESS OF THE HEADER.
	DAC*	(R3)
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	RFXPER		/#/ YES -- BUFFER EXCEEDS PARTITION BOUNDS.
	LAC*	(R3)		/NO -- SAVE ADJUSTED HEADER ADDRESS.
	DAC	RFHEAD
	JMS	RFXRFB		/SET THE XR TO POINT TO THE FILE BUFFER.
/
	.EJECT
/ IS THERE ANYMORE DATA IN THE CURRENT DATA BLOCK? IF NOT, READ IN THE
/ NEXT BLOCK.
/
	JMS	RFDBFA		/IS THE DATA POINTER POINTING AT WORD
	AAC	+376		/376 (THE BACKWORD DATA LINK) IN THE
	SAD	RF.DPT,X	/FILE DATA BUFFER?
	JMP	RFBFMT		/YES -- BUFFER EMPTY.
RFRDNE	LAW	-1		/NO -- IS THE NEXT DATA WORD NON-0?
	TAD	RF.DPT,X
	DAC*	(X10)
	LAC*	X10
	SZA
	JMP	RFRDCH		/YES -- THERE'S MORE DATA IN THIS BLOCK.
/
/ THERE IS NO MORE DATA IN THE CURRENT BLOCK.
/
RFBFMT	CLC
	SAD	RF.DAT+377,X    /IS THE FORWARD LINKAGE WORD -1?
	JMP	RFEOFE		/#/ YES -- THIS IS THE FINAL BLOCK. THE READ
				/IS IN ERROR SINCE END-OF-FILE WAS NEVER READ.
/
/ PREPARE TO READ IN THE NEXT DATA BLOCK.
/
	JMS	RFDBFA		/RESET THE DATA POINTER TO THE BEGINNING
	DAC	RF.DPT,X	/OF THE DATA BLOCK.
	DZM	RF.PER,X	/CLEAR THE PARITY-ERROR-IN-BLOCK FLAG.
	LAC	RF.DAT+377,X    /GET THE FORWARD BLOCK LINKAGE.
	DAC	RF.BLK,X
	JMS*	RFGTBL		/READ IN THAT BLOCK.
				/(EFFECTIVELY, ALL ACTIVE REGISTERS ARE
				/ALTERED; THE XR IS LEFT POINTING AT THE
				/FILE BUFFER).
	SKP			/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC.
	JMP	RFRDNE		/RETURN HERE IF NO ERROR OCCURRED.
	PAL			/SAVE THE ERROR CODE FOR "RFDKER".
	AND	(367777)	/DID SOMETHING OTHER THAN A PARITY ERROR
	SZA!CLC			/OCCUR?
	JMP	RFDKER		/#/ YES.
	DAC	RF.PER,X	/NO -- SET THE PARITY ERROR FLAG.
	JMP	RFRDNE
/
	.EJECT
/ PREPARE TO READ THE NEXT DATA RECORD INTO THE REQUESTER'S LINE BUFFER.
/ FIRST, CHECK THE HEADER, WHOSE CONTENTS IS IN THE AC.
/
RFRDCH	DAC	RFTMP1		/SAVE CONTENTS OF THE HEADER.
	AND	(17)
	SAD	(5)		/END-OF-FILE?
	JMP	RFREOF		/YES.
	SAD	RFMODE		/IS THE RECORD BEING READ IN THE SAME
				/MODE AS IT WAS WRITTEN?
	SKP			/YES.
	JMP	RFMDER		/#/ NO -- ERROR.
/
/ CHECK THE HEADER WORD-PAIR-COUNT FOR VALIDITY AND THEN COMPARE IT TO
/ THE SIZE OF THE LINE BUFFER TO DETERMINE IF A SHORT BUFFER ERROR EXISTS.
/
RFRDCC	LAC	RFTMP1		/CONVERT THE WORD-PAIR-COUNT INTO A
	LRS	10		/WORD COUNT.
	AND	(776)
	DAC	RFWDCT
	SPA!SNA
	JMP	RFIWPC		/#/ ILLEGAL INPUT WORD-PAIR-COUNT.
/
/ COMPUTE THE NUMBER OF DATA WORDS REMAINING IN THE CURRENT FILE BLOCK
/ AND USE THIS AS AN UPPER LIMIT ON THE WORD COUNT.
/
	JMS	RFDBFA		/COMPUTE THE ADDRESS OF DATA WORD 376.
	AAC	+376
	TCA
	TAD*	(X10)		/SUBTRACT FROM IT THE ADDRESS OF THE
				/CURRENT DATA WORD. ACTUALLY, THE RESULT
				/IS NOW NEGATIVE.
	TAD	RFWDCT
	SMA!SZA
	JMP	RFIWPC		/#/ ILLEGAL INPUT WORD-PAIR-COUNT. IT INDI-
				/CATES MORE THAN REMAINS IN THE BLOCK.
	LAW	-1
	TAD*	(X10)
	DAC*	(X10)
	LAC	RFTMP1		/CLEAR OUT THE DATA VALIDITY BITS IN
	AND	(377017)	/HEADER WORD 0.
	DAC*	(X10)
/
	.EJECT
/ COMPARE THE LINE BUFFER SIZE TO THE RECORD SIZE. TRANSFER TO THE LINE
/ BUFFER THE NUMBER OF WORDS INDICATED BY THE SMALLER OF THESE COUNTS.
/
	DZM	RFSHTB		/CLEAR THE "SHORT BUFFER ERROR" FLAG.
	LAC	RFBFSZ		/WILL THE RECORD FIT IN THE LINE BUFFER?
	TCA
	TAD	RFWDCT
	SPA!SNA
	JMP	RFRECF		/YES -- RECORD FITS.
	DAC	RFSHTB		/NO -- SET THE "SHORT BUFFER ERROR" FLAG.
	LAC	RFBFSZ		/USE THE BUFFER SIZE.
	SKP
RFRECF	LAC	RFWDCT		/USE THE RECORD SIZE.
	JMS	RFRWTR		/TRANSFER THE DATA LINE.
	LAC	RFHEAD		/ARG. 1 -- LAC (TO).
	TAD	RF.DPT,X	/ARG. 2 -- TAD (FROM).
				/(X10, X11, X12, AC, RF.CNT & RF.DPT,X
				/ARE ALTERED).
/
/ CHECK FOR ERROR CONDITIONS, ONLY ONE OF WHICH CAN BE RECORDED IN THE
/ DATA VALIDITY BITS (12 & 13) IN HEADER WORD 0. IF TWO ERRORS OCCUR
/ AT ONE TIME, THE ORDER OF PRECEDENCE IS: PARITY ERROR, THEN SHORT
/ LINE BUFFER (ALIAS RECORD TOO LONG), AND FINALLY CHECKSUM ERROR.
/
	LAW	-1
	TAD	RFHEAD		/SET UP A POINTER TO THE LINE BUFFER HEADER.
	DAC*	(X10)
	DAC*	(X11)
	LAC	RF.PER,X	/DID A PARITY ERROR OCCUR?
	SZA!CLA
	JMP	RFSTPE		/YES.
	SAD	RFSHTB		/NO -- WAS THE LINE BUFFER SHORT?
	SKP			/NO.
	JMP	RFSTSB		/YES.
	SAD	RFCKSM		/WAS THERE A CHECKSUM ERROR?
	JMP	RFRQOC		/NO -- READ REQUEST OPERATION COMPLETED.
	AAC	20		/YES.
RFSTSB	AAC	20
RFSTPE	AAC	20
	XOR*	X10		/SET THE DATA VALIDITY BITS IN HEADER
	DAC*	X11		/WORD 0.
	JMP	RFRQOC		/READ REQUEST COMPLETED.
/
/ AN END-OF-FILE RECORD HAS BEEN READ. SET THE END-OF-FILE FLAG.
/
RFREOF	DAC	RF.EOF,X
	JMP	RFRDCC
	.TITLE *** WRITE INTO SEQUENTIAL FILE
/
RFWRIT	JMS	RFRWCS		/USE COMMON READ/WRITE CODE TO VERIFY
	33			/THAT A FILE WAS PROPERLY OPENED. VALIDATE
				/AND SAVE THE WRITE PARAMETERS IN THE
				/FILE BUFFER. THE 33 IS AN ARGUMENT TO
				/THE CALL -- CAL FUNCTION CODE FOR "ENTER".
				/(AC & XR ARE ALTERED).
				/RETURN HERE, IF NO ERROR OCCURRED, WITH
				/THE XR POINTING AT THE FILE BUFFER.
	DZM	RFERCD		/CLEAR THE "ERROR CODE" FLAG.
/
/ VERIFY THAT THE ADDRESS OF THE LINE BUFFER HEADER IS WITHIN THE TASK'S
/ PARTITION AND ADJUST THE HEADER ADDRESS TO 17 BITS.
/
	LAC*	RFRQND		/ADDRESS OF THE I/O REQUEST NODE.
	DAC*	(R2)
	LAC	RFHEAD		/ADDRESS OF THE HEADER.
	DAC*	(R3)
	CLA!IAC			/PRETEND THE BUFFER SIZE IS +1.
	DAC*	(R4)
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	RFXPER		/#/ YES -- HEADER OUTSIDE OF PARTITION.
	LAW	-1		/NO -- THE ADJUSTED ADDRESS IS IN R3.
	TAD*	(R3)		/DON'T STORE IT IN RFHEAD UNTIL THE NEXT
				/CALL IS MADE TO VAJX.
	DAC*	(X10)		/PREPARE TO ACCESS THE HEADER.
	DAC*	(X11)
/
/ VALIDATE THE WORD-PAIR-COUNT IN THE LINE BUFFER HEADER, CLEAR THE DATA
/ VALIDITY BITS AND BIT 0 (WHICH NO LONGER HAS ANY USE), AND SET THE
/ DATA MODE BITS.
/
	LAC*	X10		/SET THE DATA MODE IN HEADER WORD 0.
	AND	(377000)
	PAL			/SAVE THE WORD-PAIR-COUNT.
	TAD	RFMODE
	DAC*	X11
	PLA			/CONVERT THE WORD-PAIR-COUNT INTO A
	CLL			/WORD COUNT.
	LRS	10
	SNA
	JMP	RFIBSZ		/#/ ILLEGAL OUTPUT WORD-PAIR-COUNT ( =0).
	DAC	RFWDCT
	AND	(777400)
	SZA
	JMP	RFIBSZ		/#/ ILLEGAL OUTPUT WORD-PAIR-COUNT (>177). THE
				/MAXIMUM RECORD SIZE IS 376 WORDS FOR
				/A FILE BLOCK.
/
	.EJECT
/ VERIFY THAT THE LINE BUFFER LIES WITHIN THE TASK'S PARTITION. THE REQUEST
/ NODE ADDRESS SHOULD STILL BE IN R2.
/
	LAC	RFHEAD		/UNADJUSTED ADDRESS OF THE HEADER.
	DAC*	(R3)
	LAC	RFWDCT		/SIZE OF THE LINE BUFFER RECORD.
	DAC*	(R4)
	JMS*	(VAJX)		/(R3, R5, XR & AC ARE ALTERED).
				/ERROR?
	JMP	RFXPER		/#/ YES -- LINE BUFFER EXCEEDS PARTITION BOUNDS.
	LAC*	(R3)		/NO -- SAVE ADJUSTED HEADER ADDRESS.
	DAC	RFHEAD
	DAC*	(X10)
	DZM*	X10		/CLEAR THE CHECKSUM WORD, WHICH WILL BE
				/COMPUTED BELOW.
	JMS	RFXRFB		/SET THE XR TO POINT TO THE FILE BUFFER.
/
/ HAVE ANY BLOCKS BEEN ASSIGNED TO THIS FILE?
/
	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	RFEROR		/#/ 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		/COMPUTE THE NEGATIVE OF THE DIFFERENCE
	AAC	+376		/BETWEEN THE ADDRESS OF THE BACKWARD LINK
	TCA			/AND THE ADDRESS OF THE CURRENT DATA WORD.
	TAD	RF.DPT,X
	TAD	RFWDCT		/ADD THE SIZE OF THE LINE TO BE WRITTEN.
	SPA!SNA
	JMP	RFFITS		/THE LINE WILL FIT IN THE CURRENT BUFFER.
/
/ 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.
/
	JMS	RFDBFA		/IS THE DATA POINTER POINTING AT THE
	AAC	+376		/BACKWORD LINKAGE WORD?
	SAD	RF.DPT,X
	JMP	RFALNB		/YES.
	LAC	RF.DPT,X	/NO -- CLEAR THE NEXT WORD.
	JMS	RFADJX
	DZM	0,X
/
/ THE DATA LINE WON'T FIT IN THE CURRENT BLOCK. ALLOCATE ANOTHER BLOCK
/ AND THEN WRITE OUT THE OLD ONE.
/
RFALNB	JMS*	RFAL1B		/ALLOCATE A 256 WORD DISK BLOCK.
				/(EFFECTIVELY, ALL REGISTERS + RFTMP1
				/ARE ALTERED).
				/WAS A BLOCK ALLOCATED?
	JMP	RFEROR		/#/ NO -- THE ERROR CODE IS IN THE AC.
/
	PAL			/YES -- SAVE VALUE TEMPORARILY.
	JMS	RFXRFB		/SET THE XR TO POINT AT THE FILE BUFFER.
	PLA
/
	DAC	RF.NXB,X	/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).
	DAC	RFERCD		/#/ RETURN HERE, IF AN ERROR OCCURRED, WITH
				/THE ERROR CODE IN THE AC. SAVE FOR TEST BELOW.
				/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).
/
/ TEST IF AN ERROR OCCURRED WHILE TRYING TO WRITE OUT THE PREVIOUS FILE
/ DATA BLOCK.
/
	LAC	RFERCD
	SZA
	JMP	RFEROR		/#/ YES.
/
	.EJECT
/ TRANSFER THE DATA LINE FROM THE REQUESTER'S LINE BUFFER TO THE FILE
/ DATA BUFFER.
/
RFFITS	LAC	RFWDCT		/CALL SUBROUTINE TO TRANSFER DATA.
	JMS	RFRWTR
	LAC	RF.DPT,X	/ARG. 1 -- LAC (TO).
	TAD	RFHEAD		/ARG. 2 -- TAD (FROM).
				/(X10, X11, X12, AC, RF.CNT & RF.DPT,X
				/ARE ALTERED).
	LAC	RFCKSM		/STORE THE COMPUTED CHECKSUM.
	TCA
	DAC*	X12
/
/ REQUESTED OPERATION COMPLETED.
/
RFRQOC	CLA!IAC			/SET THE REQUESTER'S EVENT VARIABLE TO +1.
	JMP*	RFSREV
/
/ ERRORS.
/
RFIBSZ	LAW	-16		/ILLEGAL INPUT BUFFER SIZE OR ILLEGAL
	SKP			/OUTPUT WORD-PAIR-COUNT.
RFXPER	LAW	-30		/LINE BUFFER EXCEEDS PARTITION BOUNDS.
	SKP
RFEOFE	LAW	-52		/NO END-OF-FILE RECORD IN THE FILE.
	SKP
RFDKER	PLA			/DISK ERROR -- RETURN THE CONTENTS OF
	SKP			/THE DISK STATUS REGISTER.
RFMDER	LAW	-5		/RECORD BEING READ IN A DIFFERENT MODE THAN
	SKP			/IT WAS WRITTEN.
RFIWPC	LAW	-23		/ILLEGAL INPUT WORD-PAIR-COUNT.
RFEROR	JMP	RFSTFL		/SET THE REQUESTER'S EVENT VARIABLE.
	.TITLE *** READ/WRITE COMMON SETUP SUBROUTINE
/
/ SUBROUTINE RFRWCS -- COMPUTE THE PAGE ADDRESS PARAMETERS, DISSECT THE
/ I/O REQUEST NODE, SEARCH THE ACTIVE LUN DEQUE TO BE SURE THAT A FILE
/ HAS BEEN PROPERLY OPENED AND TO FIND THE FILE BUFFER ADDRESS, VALIDATE
/ AND SAVE THE READ/WRITE PARAMETERS IN THE FILE BUFFER.
/
/ CALLING SEQUENCE:
/
/	JMS	RFRWCS
/	32 IF READ; 33 IF WRITE
/	(RETURN, IF NO ERROR OCCURRED, WITH THE
/	XR POINTING AT THE FILE BUFFER).
/
/ ALTERED REGISTERS:
/
/	AC & XR
/
RFRWCS	0
	LAC	RFRWCS		/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	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
/
/ SEARCH THE ACTIVE LUN DEQUE TO BE SURE THAT A FILE IS OPEN.
/
	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	RFNOFO		/#/ YES -- NO FILE OPEN.
	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 "RFALUN"
/ IN RESIDENT CODE.
/
	LAC	2,X		/FIRST HALF OF TASK NAME FOUND?
	SAD*	X10
	SKP
	JMP	RFALLP		/NO -- TRY NEXT NODE.
	LAC	3,X		/SECOND HALF FOUND?
	SAD*	X10
	SKP
	JMP	RFALLP		/NO -- TRY NEXT NODE.
/
/ TEST FOR LUN.
/
	LAC*	X10		/SKIP THE PRIORITY CODE.
	LAC	5,X		/DO THE LUNS MATCH?
	XOR*	X10
	AND	(777000)
	SZA
	JMP	RFALLP		/NO -- TRY NEXT NODE.
/
/ THE TASK-LUN NODE IN RFALUN HAS BEEN FOUND.
/
	LAC	11,X		/SAVE THE FILE BUFFER ADDRESS.
	DAC*	RFBFAD
	JMS	RFXRFB		/YES -- SET THE XR TO POINT TO THE FILE BUFFER.
	LAC	RF.OPN,X	/WAS THE FILE OPENED FOR SEQUENTIAL
	SAD*	RFRWCS		/INPUT OR OUTPUT, AS APPROPRIATE?
	SKP			/YES.
	JMP	RFIFNC		/#/ NO -- ILLEGAL FUNCTION.
/
/ VALIDATE THE DATA MODE.
/
	LAC	RFMODE		/LEGAL DATA MODES: 0 THRU 3.
	SPA
	JMP	RFRWIM		/#/ ILLEGAL DATA MODE.
	AAC	-4
	SMA
	JMP	RFRWIM		/#/ ILLEGAL DATA MODE.
/
	IDX	RFRWCS		/NON-ERROR RETURN.
	JMP*	RFRWCS
/
RFRWIM	LAW	-7		/ILLEGAL DATA MODE.
	SKP
RFIFNC	LAW	-6		/ILLEGAL I/O FUNCTION IN THIS CONTEXT.
RFSTFL	DAC*	RFCLFL		/SET A FLAG FOR THE "DONE" CODE SO THAT
				/IT WILL CLOSE THE FILE.
	JMP*	RFSREV		/SET REQUESTER'S EVENT VARIABLE.
RFNOFO	LAW	-11		/NO FILE OPEN.
	JMP*	RFSREV
	.TITLE *** READ/WRITE COMMON TRANSFER SUBROUTINE
/
/ SUBROUTINE RFRWTR -- TRANSFERS A DATA LINE (AND COMPUTES THE CHECKSUM)
/ TO OR FROM THE FILE DATA BUFFER FROM OR TO THE LINE BUFFER.
/
/ CALLING SEQUENCE:
/
/	WORD COUNT (+) IN THE AC
/	JMS	RFRWTR
/	LAC	(TO)		/ARGUMENT 1.
/	TAD	(FROM)		/ARGUMENT 2.
/	(UNCONDITIONAL RETURN)
/
/ ALTERED REGISTERS:
/
/	X10, X11, X12, AC, RF.CNT & RF.DPT,X
/
RFRWTR	0
	TCA			/COMPUTE THE TWOS COMPLEMENT OF THE
	DAC	RF.CNT		/WORD COUNT.
	DZM	RFCKSM		/INITIALIZE THE CHECKSUM.
	XCT*	RFRWTR		/GET THE ADDRESS OF THE LOCATION TO
				/WHICH DATA WILL BE TRANSFERRED.
	DAC*	(X12)		/PREPARE AUTOINDEX REGISTER 12 FOR
				/STORING THE COMPUTED CHECKSUM (USED
				/ONLY DURING WRITE).
	AAC	-1		/PREPARE AUTOINDEX REGISTER 11 FOR
	DAC*	(X11)		/STORING.
	IDX	RFRWTR
	LAW	-1		/PREPARE AUTOINDEX REGISTER 10 FOR
	XCT*	RFRWTR		/PICKING UP DATA.
	DAC*	(X10)
RFTFLP	LAC*	X10		/TRANSFER A WORD AND ADD IT TO THE
	DAC*	X11		/CHECKSUM.
	TAD	RFCKSM
	DAC	RFCKSM
	ISZ	RF.CNT
	JMP	RFTFLP
/
/ MOVE THE FILE DATA POINTER AHEAD BY THE SIZE OF THE DATA LINE
/ EXCEPT WHEN THE END-OF-FILE FLAG IS SET. THIS WILL INSURE ONCE
/ AN EOF HAS BEEN READ THAT FURTHER READS WILL CAUSE THE EOF LINE
/ TO BE RETURNED. THIS IS IMPORTANT FOR PROGRAMS, SUCH AS THE EDITOR,
/ WHICH DOUBLE BUFFER I/O.
/
	LAC	RF.EOF,X	/END-OF-FILE?
	SZA
	JMP	RFRWEX		/YES.
	LAC	RF.DPT,X
	TAD	RFWDCT
	DAC	RF.DPT,X
RFRWEX	IDX	RFRWTR
	JMP*	RFRWTR
	.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
	.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.
RFMODE=RFARG1			/DATA MODE.
RFARG2	0			/I/O ARGUMENT 2.
RFHEAD=RFARG2			/ADDRESS OF THE REQUESTER'S LINE BUFFER HEADER.
RFARG3	0			/I/O ARGUMENT 3.
RFBFSZ=RFARG3			/SIZE OF REQUESTER'S LINE BUFFER.
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.
RFCKSM	0			/CHECKSUM.
RFWDCT	0			/WORD COUNT.
RFSHTB	0			/SET NON-0 WHEN A SHORT BUFFER ERROR OCCURS.
RFERCD	0			/FLAG SET NON-0 WHEN A DISK ERROR OCCURS
				/WHILE TRYING TO WRITE OUT A FILE DATA
				/BLOCK. THE FLAG IS SET NON-0 WITH THE
				/ERROR CODE.
/
	.END
RFHEAD=RFARG2			/ADDRESS OF THE REQUESTER'S LINE BUFFER HEADER.
RFARG3	0			/I/O ARGUMENT 3.
RFBFSZ=RFARG3			/SIZE OF REQUESTER'S LINE BUFFER.
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.
RFCKSM	0			/CHECKSUM.
RFWDCT	0			/WORD COUNT.
RFSHTB	0			/SET NON-0 WHEN A SHORT BUFFER ERROR OCCURS.
/
	.END
