; MORE STUFF TAKEN FROM THE SUP32.LIB

		include "dh0:stone/dazsys/xrefs"

		OPT		o+			;optimize
		OPT		l+			;link

		xdef	_waitmsg

NT_MESSAGE	equ	5
NT_FREEMSG	equ	6
NT_REPLYMSG	equ	7

; Input a2 the message to on for a return reply
_waitmsg:
		movem.l		A2/A6,-(sp)
		move.l		(4).w,A6
	_wm_test:
		cmp.b		#NT_REPLYMSG,8(A2)				;has it been replied?
		beq.s		_wm_remove
		cmp.b		#NT_FREEMSG,8(A2)				;has it been freed?
		beq.s		_wm_freed
		move.l		14(A2),A1						;reply port
		move.l		A1,d0							;test a1
		beq.s		_wm_test						;NULL reply port, busy wait.
		move.b		15(A1),D1						;signal bit #
		moveq.l		#1,D0
		asl.l		D1,D0		    				;D0 = signal mask
		jsr			_LVOWait(A6)					;wait for signal
		bra.s		_wm_test						;loop again
	_wm_remove:
		jsr			_LVODisable(A6)
		move.l		A2,A1
		jsr			_LVORemove(A6)
		jsr			_LVOEnable(A6)
	_wm_freed:
		movem.l		(sp)+,A2/A6						; return the message
		move.l		A2,D0
		rts

