
	;Open the Dos library.
		MOVE.L	4,A6
		LEA	DosName,A1
		JSR	_LVOOldOpenLibrary(A6)
		MOVE.L	D0,DosBase

	;Check the dos library version
		MOVE.L	D0,A0
		CMP.W	#37,20(A0)
		BLO	WrongDos

	;Call ReadArgs to pre-parse the command line.
		MOVE.L	DosBase,A6
		MOVE.L	#Template,D1
		MOVE.L	#Array,D2
		MOVEQ.L	#0,D3
		JSR	_LVOReadArgs(A6)
		MOVE.L	D0,RdArgs
		BEQ	SyntaxError

	;Test for no arguments at all
		MOVE.L	Array,D0
		ADD.L	Array+4,D0
		ADD.L	Array+8,D0
		ADD.L	Array+12,D0
		TST.L	D0
		BEQ	SyntaxError

	;Are we to wait for the left mouse button ?
		TST.L	Array
		BEQ	skip1
		
	;Wait for the left mouse button on
loop1:		BTST	#6,$BFE001
		BNE	loop1
		
	;Are we to wait for the release ?
		TST.L	Array+12
		BEQ	Exit
		
	;Wait for the left mouse button off
rloop1:		BTST	#6,$BFE001
		BEQ	rloop1
		BRA	Exit


	;Are we to wait for the right mouse button ?
skip1:		TST.L	Array+4
		BEQ	skip2
		
	;Wait for the Right mouse button on
loop2:		BTST	#10,$DFF016
		BNE	loop2

	;Are we to wait for the release ?
		TST.L	Array+12
		BEQ	Exit

	;Wait for the Right Mouse Button Off
rloop2:		BTST	#10,$DFF016
		BEQ	rloop2	
		BRA	Exit
	
	
	;Are we to wait for both buttons ?
skip2:		TST.L	Array+8
		BEQ	TestRelease
		
	;Wait for both mouse buttons on
loop3:		BTST	#6,$BFE001
		BNE	loop3
		BTST	#10,$DFF016
		BNE	loop3

	;Are we to wait for the release ?
TestRelease:	TST.L	Array+12
		BEQ	Exit
		
	;Wait for both mouse buttons off
rloop3:		BTST	#6,$BFE001
		BEQ	rloop3
		BTST	#10,$DFF016
		BEQ	rloop3
		

	;Free the RdArgs structure
Exit:		MOVE.L	DosBase,A6
		MOVE.L	RdArgs,D1
		JSR	_LVOFreeArgs(A6)

	;Close the dos library
		MOVE.L	4,A6
		MOVE.L	DosBase,A1
		JSR	_LVOCloseLibrary(A6)
		
WrongDos:
	;Return to the CLI
		CLR.L	D0
		RTS


	;Print a message telling user of the correct syntax
SyntaxError:	MOVE.L	DosBase,A6
		MOVE.L	#SyntaxErrorText,D1
		JSR	_LVOPutStr(A6)
		BRA.S	Exit



		SECTION data,data

Template:		DC.B	"LEFT/S,RIGHT/S,BOTH/S,RELEASE/S",0
DosName:		DC.B	"dos.library",0
SyntaxErrorText:	DC.B	"WaitMouse [LEFT|RIGHT|BOTH] [RELEASE]     ©1997 Mike Archer",10,10,0
Version:		DC.B	"$VER: WaitMouse V1.0",0

		SECTION data2,bss

DosBase:		DS.L	1
RdArgs:			DS.L	1
Array:			DS.L	4


