	.TITLE	RMSIO - RMS OPEN, READ, WRITE, CLOSE ROUTINES
	.IDENT	'V01-000'

;++
;
; FACILITY:	VAXNET / SNDRCV
;
; ABSTRACT:
;	These are the routines which do the RMS I/O for the
; VAXNET and SNDRCV programs.
;
; AUTHOR:	Robin Miller 		DATE:  22-Sept-1981
;
; MODIFIED BY:
;
;--

INPFAB:	$FAB	FAC = <GET>		; File Attributes Block

INPRAB:	$RAB	FAB = INPFAB,-		; Record Access Block
		MBF = 2,-		; Multibuffer Count
		ROP = <RAH>		; Read-ahead

OUTFAB:	$FAB	FAC = <PUT>		; File Attributes Block

OUTRAB:	$RAB	FAB = OUTFAB,-		; Record Access Block
		MBF = 2,-		; Multibuffer Count
		ROP = <WBH>		; Write-behind


	.SBTTL	OPEN_FILE - Open a file for GET
;++
; FUNCTIONAL DESCRIPTION:
;
;	This routine opens an existing file for a PUT
;	and copies the file attributes into a buffer.
;
; CALLING SEQUENCE:
;
;	CALLS/G	OPEN_FILE
;
; INPUT PARAMETERS:
;
;	4(AP)	Address of descriptor for filename buffer
;	8(AP)	Address of size of filename
;	12(AP)	Address of buffer to store file attributes
;	16(AP)  Address of location to store return status
;
; OUTPUT PARAMETERS:
;
;	16(AP)	Status returned by $OPEN or $CONNECT
;
;--

	.ENTRY	OPEN_FILE,^M<R2,R3,R4>

	MOVAB	INPFAB,R2		; Put address of FAB in R2
	MOVL	4(AP),R0		; Descriptor to filename
	MOVL	4(R0),FAB$L_FNA(R2)	; Store filename address
	MOVB	@8(AP),FAB$B_FNS(R2)	; Store filename size

	$OPEN	FAB = (R2)		; Open the file
	BLBC	R0,90$			; Error
	$CONNECT	RAB = INPRAB
	BLBC	R0,90$

; Copy file attributes into buffer

	MOVL	12(AP),R4		; Address of buffer
	MOVL	FAB$L_ALQ(R2),(R4)+	; Allocation quantity
	MOVL	FAB$L_FOP(R2),(R4)+	; File process options
	MOVL	FAB$L_MRN(R2),(R4)+	; Maximum record number
	MOVW	FAB$W_DEQ(R2),(R4)+	; Default extension quantity
	MOVW	FAB$W_BLS(R2),(R4)+	; Block size
	MOVW	FAB$W_MRS(R2),(R4)+	; Maximum record size
	MOVB	FAB$B_BKS(R2),(R4)+	; Bucket size
	MOVB	FAB$B_FSZ(R2),(R4)+	; Fixed control area size
	MOVB	FAB$B_ORG(R2),(R4)+	; Organization
	MOVB	FAB$B_RAT(R2),(R4)+	; Record attributes
	MOVB	FAB$B_RFM(R2),(R4)+	; Record format

90$:	MOVL	R0,@16(AP)		; Store status
	RET

	.SBTTL	CREATE_FILE - Create a file for GET

;++
; FUNCTIONAL DESCRIPTION:
;
;	This routine creates a file using the attributes passed to it.
;
; CALLING SEQUENCE:
;
;	CALLS/G	CREATE_FILE
;
; INPUT PARAMETERS:
;
;	4(AP)	Address of descriptor for filename buffer
;	8(AP)	Address of size of filename
;	12(AP)	Address of buffer to get file attributes
;	16(AP)  Address of location to store return status
;
; OUTPUT PARAMETERS:
;
;	16(AP)	Status returned by $CREATE or $CONNECT
;
;--

	.ENTRY	CREATE_FILE,^M<R2,R3,R4>

; Copy file attributes into FAB

	MOVAB	OUTFAB,R2		; Address of FAB in R2
	MOVL	4(AP),R0		; Get address of filename desc.
	MOVL	4(R0),FAB$L_FNA(R2)	; Store filename address
	MOVB	@8(AP),FAB$B_FNS(R2)	; Store filename size
	MOVL	12(AP),R4		; File attr. buffer addr.
	MOVL	(R4)+,FAB$L_ALQ(R2)	; Allocation quantity
	MOVL	(R4)+,FAB$L_FOP(R2)	; File process options
	MOVL	(R4)+,FAB$L_MRN(R2)	; Maximum record number
	MOVW	(R4)+,FAB$W_DEQ(R2)	; Default extension quantity
	MOVW	(R4)+,FAB$W_BLS(R2)	; Block size
	MOVW	(R4)+,FAB$W_MRS(R2)	; Maximum record size
	MOVB	(R4)+,FAB$B_BKS(R2)	; Bucket size
	MOVB	(R4)+,FAB$B_FSZ(R2)	; Fixed control area size
	MOVB	(R4)+,FAB$B_ORG(R2)	; Organization
	MOVB	(R4)+,FAB$B_RAT(R2)	; Record attributes
	MOVB	(R4)+,FAB$B_RFM(R2)	; Record format

	$CREATE	FAB = (R2)		; Create the file
	BLBC	R0,90$			; Error
	$CONNECT	RAB = OUTRAB

90$:	MOVL	R0,@16(AP)		; Return the status
	RET

	.SBTTL	GET_RECORD - Get next record from file

;++
; FUNCTIONAL DESCRIPTION:
;
;	This routine reads a block of data.
;
; CALLING SEQUENCE:
;
;	CALLS/G	GET_RECORD
;
; INPUT PARAMETERS:
;
;	4(AP)	Address of buffer
;	8(AP)	Size of buffer.
;	12(AP)	Address to store size of record
;	16(AP)	Address to store return status
;
; OUTPUT PARAMETERS:
;
;	12(AP)	Size of record read
;	16(AP)	Status returned by $GET
;
;--

	.ENTRY	GET_RECORD,^M<R2>

	MOVAL	INPRAB,R2		; Address of RAB
	MOVL	4(AP),RAB$L_UBF(R2)	; Buffer address
	MOVW	8(AP),RAB$W_USZ(R2)	; Size of buffer

	$GET	RAB = (R2)		; Do the read
	BLBC	R0,10$			; Error

	MOVW	RAB$W_RSZ(R2),@12(AP)	; The record size
10$:	MOVL	R0,@16(AP)		; Return the status
	RET

	.SBTTL	PUT_RECORD - Put a record to the file

;++
; FUNCTIONAL DESCRIPTION:
;
;	This routine writes a block of data.
;
; CALLING SEQUENCE:
;
;	CALLS/G	PUT_RECORD
;
; INPUT PARAMETERS:
;
;	4(AP)	Address of buffer
;	8(AP)	Address of size of transfer
;	12(AP)	Address of location to store return status
;
; OUTPUT PARAMETERS:
;
;	12(AP)	Status returned by $PUT
;
;--

	.ENTRY	PUT_RECORD,^M<>

	MOVAL	OUTRAB,R0		; Address of RAB
	MOVL	4(AP),RAB$L_RBF(R0)	; Buffer address
	MOVW	@8(AP),RAB$W_RSZ(R0)	; Buffer size

	$PUT	RAB = (R0)		; Do the write

	MOVL	R0,@12(AP)		; Copy the status
	RET

	.SBTTL	CLOSE_FILE - Close the file

;++
; FUNCTIONAL DESCRIPTION:
;
;	This routine closes the file.
;
; CALLING SEQUENCE:
;
;	CALLS/G	CLOSE_FILE
;
; INPUT PARAMETERS:
;
;	4(AP)	Flag for file to close:
;		1 = Input file
;		2 = Output file
;	8(AP)	Address of location to store status
;
; OUTPUT PARAMETERS:
;
;	8(AP)	Status returned by $CLOSE
;--

	.ENTRY	CLOSE_FILE,^M<>

	MOVAL	INPFAB,R0		; Presume input file
	CMPB	4(AP),#1		; Is it input ?
	BEQL	10$			; If EQ, yes
	MOVAL	OUTFAB,R0		; Set for output file

10$:	$CLOSE	(R0) 			; Close the file

	MOVL	R0,@8(AP)		; Return the status
	RET

	.END
