	.TITLE MsRply
	.ENABLE LC
	.IDENT /102589/

;
;  Description: AMI Message Reply Routine
;         File:[Message]MsRply.MAC
;       Author: Jim Bostwick  25-OCT-1989 
;    Last Edit: 5-APR-1990 23:41:22 
;      History: 
;
    
.REM |

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

{*USER*

Turn a message around, and send back to whoever sent it. 

EFN will be set upon successful completion of the send.

Status available in $DSW upon return. 


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 MsRply
	PARAM a, address		; pointer to message
	PARAM efn, scalar		; event flag
	

	SAVE <R0,R1,R2,R3>
	BEGIN
	mov	a(sp), r0		; point to message
;
; Swap source, destination task and node names. Leave router alone, 
; as that is who really sent it.  There are 2 words of task (rad50), 
; plus 3 words of node (6 ASCII) to be swapped.
;
	mov	r0, r1
	add	#stsk, r1		; point to source task field	
	mov	r0, r2	
	add	#dtsk, r2		; point to dest task field

	.rept 5
	mov	(r1), r3		; grab word to scratch
	mov	(r2), (r1)+		; word from dest to src
	mov	r3, (r2)+		; scratch word to dest
	.endm
	
	movb	efn(sp), r1		; get efn
	bic	#^C377, r1		; fix it up
	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

