*************************
* Terminate HippoPlayer *
*************************
* If HippoPlayer's port exists, send there a message telling HiP to terminate.

 	incdir	include:
	include	exec/exec_lib.i
	include	exec/ports.i

	move.l	4.w,a6			
	lea	portname(pc),a1	
	jsr	_LVOFindPort(a6)
	tst.l	d0
	beq.b	exit
	move.l	d0,a3

	sub.l	a1,a1
	jsr	_LVOFindTask(a6)
	move.l	d0,owntask

	bsr.b	createport

	lea	message(pc),a0	
	NEWLIST	a0
	move.l	a3,a0		
	lea	message(pc),a1
	move.l	#port,MN_REPLYPORT(a1)
	jsr	_LVOPutMsg(a6)

	lea	port(pc),a0	
	jsr	_LVOWaitPort(a6)

	bsr.b	deleteport

exit
	moveq	#0,d0
	rts

	
createport	lea	port(pc),a2
		moveq	#-1,d0
		jsr	_LVOAllocSignal(a6)
		move.b	d0,MP_SIGBIT(a2)
		move.l	owntask(pc),MP_SIGTASK(a2)
		move.b	#NT_MSGPORT,LN_TYPE(a2)
		clr.b	MP_FLAGS(a2)
		move.l	a2,a1
		jmp	_LVOAddPort(a6)

deleteport	lea	port(pc),a2
		move.l	a2,a1
		jsr	_LVORemPort(a6)
		moveq	#0,d0
		move.b	MP_SIGBIT(a2),d0
		jmp	_LVOFreeSignal(a6)

owntask		dc.l	0
port		ds.b	MP_SIZE
message		ds.b	MN_SIZE
		dc.l	"KILL"		* Killer-message
	
portname	dc.b	"HiP-Port",0
