
	;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 a WAIT parameter
		TST.L	Array
		BEQ	DontWait

	;Wait for a button to be pressed
loop:		BTST	#6,$BFE001
		BEQ	DontWait
		BTST	#10,$DFF016
		BNE	loop
	
	;Test which buttons are pressed
DontWait:	MOVE.L	#0,D0
		BTST	#6,$BFE001
		BNE	NoLeftButton
		ADD.L	#1,D0
NoLeftButton:	BTST	#10,$DFF016
		BNE	NoRightButton
		ADD.L	#2,D0
NoRightButton:

	;Now Decide which string to use.
		CMP.L	#1,D0
		BEQ	SetLeft
		CMP.L	#2,D0
		BEQ	SetRight
		CMP.L	#3,D0
		BEQ	SetBoth
		
		MOVE.L	#NoneMess,D2
		BRA	SetVar
		
SetLeft:	MOVE.L	#LeftMess,D2
		BRA	SetVar
		
SetRight:	MOVE.L	#RightMess,D2
		BRA	SetVar
		
SetBoth:	MOVE.L	#BothMess,D2

	;Set the variable
SetVar:		MOVE.L	DosBase,A6
		MOVE.L	#VariableName,D1
		MOVE.L	#-1,D3		;string is NULL terminated
		MOVE.L	#GVF_LOCAL_ONLY,D4
		JSR	_LVOSetVar(A6)	

	;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	"WAIT/S",0
DosName:		DC.B	"dos.library",0
SyntaxErrorText:	DC.B	"TestMouse [WAIT]                ©1997 Mike Archer",10,10,0
Version:		DC.B	"$VER: WaitMouse V1.0",0

NoneMess:		DC.B	"NONE",0
LeftMess:		DC.B	"LEFT",0
RightMess:		DC.B	"RIGHT",0
BothMess:		DC.B	"BOTH",0

VariableName:		DC.B	"Mouse",0

		SECTION data2,bss

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


