	.title	recv - pl/i callable receive
	.ident	-010000-
;
; Copyright 1981. Duke University.
;+
; Abstract:	RECV, RECVS, RECVT, RECVX
;
;	PL/I callable subroutine to receive character strings via
;	the VMS mailbox facility.
;
; Calling sequence:
;
;	= RECV (tsknam, ti, data, prv)	/* Receive data		*/
;	= RECVS (tsknam, ti, data, prv)	/* Receive or suspend	*/
;	= RECVT (tsknam, ti, data, prv)	/* Receive or stop	*/
;	= RECVX (tsknam, ti, data, prv)	/* Receive or exit	*/
;
; Returns:	Fixed binary (15,0)
;
;	The VMS status return.
;
; Arguments:
;
; tsknam character (6) [varying]
;	The task name from which to receive the data.  This
;	is ignored under VMS.
;
; ti fixed binary (15,0)
;	The TI indicator from which the data came.  This is
;	derived from the process ID in VMS.
;
; data character (*) [varying]
;	The data buffer to do the receive.  This buffer will
;	have the first six bytes of the process name prefixed
;	to the data received.
;
; prv fixed binary (15,0)
;	Set to 1 if the sender task was privileged.  This is
;	ignored under VMS.
;
; Subroutines:
;
;	ilnar$	- Report illegal number of arguments.
;	savrg$	- Save registers 0 - 3
;
; Nonstandard features:
;
;	1. Written in Macro-11
;	2. Uses the undocumented VMS "elephant directive" to
;	   call a native mode image.
;
; Written: 07-Apr-1981, -1.0.0-, Bruce C. Wright
; Modified:
; Verified:
;-

;
; Macro calls
;
	.mcall	dir$
;
	.psect	$recv,rw,d
;
; Static Read/write section
;
exfc:	.byte	145.,8.		; Directive code for elephant directive
	.word	4		; Subfunction code - call native image
	.word	secnam		; Section name to call
	.word	seclen		; Length of section name
;
; Arguments to receive.
;
func:	.word	0		; Function code
buffer:	.word	0		; Address of buffer
buflen:	.word	0		; Length of buffer
iost:	.word	0,0,0,0		; VMS I/O status block
;
; Global section name
;
	.psect	$merli,ro,d,ovr
secnam:	.ascii	/_DBA0:[PLIUTL]NATVMODE.EXE/
seclen	=	.-secnam
;
; Parameter definitions
;
nargs	=	16		; Number of arguments
tsknam	=	nargs+2		; Task name (input)
ti	=	tsknam+2	; TI address (output)
data	=	ti+2		; Returned data (output)
prv	=	data+2		; Privilege return (output)
rtn	=	prv+2		; Return code

;
; Executable code
;
	.psect	merlin,rw,i
recv::	jsr	r0,savrg$	; Save registers 0 - 3
	mov	#2,r3		; Show ordinary receive.
	br	receiv		; And receive data.
recvs::
recvt::	jsr	r0,savrg$	; Save registers 0 - 3
	mov	#1,r3		; Show receive or stop.
	br	receiv		; And receive data.
recvx::	bpt			; *** later ***
;
; Receive data code
;
receiv:	cmp	nargs(sp),#5	; Right number of arguments?
	beq	10$		; J if so.
	jsr	r5,ilnar$	; Report illegal number of arguments.
10$:	mov	data(sp),r0	; Pick up string dope vector.
	mov	4(r0),r1	; Pick up address of string.
	mov	(r0),r2		; Pick up length of string.
	bpl	20$		; J if fixed-length string.
	tst	(r1)+		; Skip over length word.
20$:	bic	#140000,r2	; Remove garbage bits from length.
	mov	r3,func		; Set receive function code.
	mov	r2,buflen	; Set buffer length.
	mov	r1,buffer	; Point to buffer from directive.
	dir$	#exfc		; Execute extended function.
	tst	(r0)		; Is it a varying length string?
	bpl	30$		; J if not.
	mov	iost+2,-(r1)	; Set the new length of string.
30$:	clr	@prv(sp)	; Show sender not privileged.
	movb	iost+6,r1	; Get high order process ID.
	swab	r1		; Into high order r1
	clrb	r1		; Clear low order r1
	bisb	iost+4,r1	; Set the low order process ID.
	mov	r1,@ti(sp)	; Return the process ID.
	mov	iost,@rtn(sp)	; Return status to caller.
	rts	pc		; And return to the caller.
	.end
