	opt d+

;	NotifyWaitForWindows

INC_DOS		EQU	0 1
INC_INT		EQU	 1
INC_GFX		EQU	0 1
INC_GAD		EQU	0 1
INC_ASL		EQU	0 1
INC_UTI		EQU	 1
INC_WB		EQU	0 1

	incdir	INCLUDE:
	include	Automacros.i
	include	libraries/notifyintuition.i

	; StartUp Nr,TaskName,Stack     Taskname + Stack only for Async_Run
	STARTUP	3,<'Async TaskName'>,4096	; 0=OFF 1=WB+CLI 2=ONLY_WB 3=ONLY_CLI 4=ASYNC_RUN

 STRUCTURE test,0
	STRUCT	ncw_Notify,IntNotifyRequest_SIZEOF
	LONG	ncw_SigBits
	LABEL	test_SIZEOF

_main:	moveq	#5,d6
	suba.l	a5,a5
	OPENDOS	0
	CALLDOS	GetArgStr
	move.l	d0,a0
	move.l	d0,a2
	bsr	Len
	beq	Ende
	subq	#1,d0
	beq	Ende
	clr.b	(a2,d0)
	lea	NotIName(pc),a1
	moveq	#1,d0
	CALLEXEC OpenLibrary
	lea	_NotIBase(pc),a0
	move.l	d0,(a0)
	beq	Need
	subq	#1,d2
	beq	Usage
	moveq	#test_SIZEOF,d0
	move.l	#MEMF_CLEAR!MEMF_PUBLIC,d1
	CALLLIB	AllocVec
	move.l	d0,a5
	tst.l	d0
	beq	Ende
	moveq	#-1,d0
	CALLLIB	AllocSignal
	move.b	d0,d2
	suba.l	a1,a1
	CALLLIB	FindTask
	lea	ncw_Notify(a5),a0
	move.l	a2,inr_Name(a0)
	move.l	d0,inr_Task(a0)
	move.b	d2,inr_SignalNum(a0)
	move.l	#INRF_SEND_SIGNAL!INRF_AFTER_OPENWINDOW,ncw_Notify+inr_Flags(a0)
	move.l	_NotIBase(pc),a6
	CALLLIB	NotIStartNotify
	tst.l	d0
	beq	Ende
	moveq	#0,d7
	bset	#12,d7
	bset	d2,d7
Wait	move.l	d7,d0
	CALLEXEC Wait
	btst	#12,d0
	bne.s	Ende
	moveq	#0,d6
Ende:	move.l	a5,d0
	beq.s	.Closelibs
	tst.l	ncw_Notify+inr_ReqSemaphore(a5)
	beq.s	.NotInt
.Again	lea	ncw_Notify(a5),a0
	move.l	_NotIBase(pc),a6
	CALLLIB	NotIEndNotify
	tst.l	d0
	bne.s	.NotInt
	move.b	ncw_Notify+inr_Error(a5),d0
	cmp.b	#INRERROR_OUTSTANDING_MSGS,d0
	beq.s	.wait
	cmp.b	#INRERROR_ISLOCKED,d0
	beq.s	.wait
	cmp.b	#INRERROR_UNKNOWN,d0
	beq.s	.NotInt
	illegal
.wait	moveq	#5,d1
	CALLDOS	Delay
	bra.s	.Again
.NotInt	move.l	a5,a1
	CALLEXEC FreeVec
.Closelibs
	CLOSEDOS	MACRO schließt die dos.lib wenn sie offen war
	CLOSELIB _NotIBase
	move.l	d6,d0
	rts
Need	lea	YouNeed(pc),a0
Text	move.l	a0,d1
	CALLDOS	PutStr
	bra	Ende
Usage	lea	Usagetxt(pc),a0
	bra.s	Text
	LEN
	INCLUDE	INC_NAMES.i
_NotIBase	dc.l	0
NotIName	dc.b	'notifyintuition.library',0
YouNeed		dc.b	'You need "notifyintuition.library" to run this programm.',10,0
Usagetxt	dc.b	'Windowtitle/Pattern',10,0
