	.TITLE MSSEND
	.ENABLE LC
	.IDENT /130688/

;
;  Description: AMI Message Send Routine
;         File:[Message]MSSEND.MAC
;       Author: Jim Bostwick 13-JUN-1988 
;    Last Edit: 20-OCT-1989 01:54:36 
;      History: 
;		 20-OCT-1989 JMB - more header modifications
;		 18-OCT-1989 JMB- New Integrated Message_rec
;		 9-OCT-1989 -JMB- Major happy munging...
;				add call to MSGLEN (smoke and mirrors)

.REM |

Procedure MSSend (
	VAR Msg: Message_rec;
	EFN: Event_flag
	);External;

{*USER*

Send a pre-formated message. Message header controls how and to whom the
message is sent. 

EFN will be set upon successful completion of the send.

Status available in $DSW upon return. 

*ALWAYS* use MSINIT to format the header before calling this routine!
See MESSAGE.DOC, and other AMI Message System documentation for additional
information. 

If MSG_FLAGS contains bit MSG_AUTO_SIZE, call P3UTL routine MSGLEN to
	obtain current length of message body. Else, take what's in
	text_size, or if that is zero, use msmax. 
 } 

{*WIZARD*

Uses VSDA internally as the send mechanism. 

We don't actually send the first two words of the message. These contain
the destination 'physical' task name (usually a router) outbound, and
the 'physical' sender (also often a router) inbound. The MSRCV routine
receives this field 'free' as the sender task name. 
 }

|


	.mcall VSDA$S

	.include /pas$ext:pasmac.mac/
	.include /message.mac/

	PROC MSSEND
	PARAM a, address		; pointer to message
	PARAM efn, scalar		; event flag

	SAVE <R0,R1,R2,R3>
	BEGIN
	movb	efn(sp), r1		; get efn
	bic	#^C377, r1		; fix it up
	mov	a(sp), r0		; point to message
	mov	r0, r2			; skip first field for send
	add	#4, r2			; ...
;
; determine size, in words, to be sent
;
	bit	#mf.siz, flags(r0)	; auto size?
	beq	5$			; y - branch

	tst	-(sp)			; set up call to msglen
	mov	r0, -(sp)		; stuff msg address
	call	MSSIZE			; call Phil's message length
	.globl MSSIZE
	mov 	(sp)+, msgsiz(r0)	; stuff returned length

5$:	mov	msgsiz(r0),r3		; get length (Bytes) 
    	bne 	10$			; user is well-behaved
;
; User is not well-behaved, and didn't initialzie message body size.
; We all pay for his slovenly habits...
;
        mov     #<body+bdymax>, r3 	; set max possible body size
        
10$:	Sub	#3, r3			; drop first (2-word) field and
    					; round up ( -4 + 1) 
	asr	r3			; make it words 
;
; and send it
;
	VSDA$S 	r0,r2,r3,r1

	ENDPR

	.END

