;MBWait (Test for l/r/both mouse buttons and/or display prompt text)
;Code: Zebedee/Carnage
;$VER: MBWait.s v1.03 (17-Oct-95)

	opt	o+
	section	MBWait,code_c

ProgStart
	move.l	a0,a5
	move.l	d0,d5
	moveq.l	#20,d4
	move.l	4.w,a6
	lea	DosName(pc),a1
	moveq.l	#0,d0
	jsr	-$228(a6)		;OpenLibrary(a1,d0)exec
	move.l	d0,DosBAdr
	beq.b	BadDos
	move.l	d0,a6
	jsr	-$3c(a6)		;Output()dos
	move.l	d0,Output
	beq.b	Exit
	moveq.l	#0,d4
	cmp.b	#"?",(a5)
	beq.w	ShowAbout
	cmp.b	#"m",1(a5)
	bne.w	ShowUsage
	cmp.b	#"b",2(a5)
	bne.w	ShowUsage
	cmp.b	#"l",(a5)		;LMB			(lmb)
	beq.b	WaitLeftMouse
	cmp.b	#"L",(a5)		;LMB with text		(Lmb)
	beq.w	ShowLeftText
	cmp.b	#"r",(a5)		;RMB			(rmb)
	beq.b	WaitRightMouse
	cmp.b	#"R",(a5)		;RMB with text		(Rmb)
	beq.w	ShowRightText
	cmp.b	#"b",(a5)		;Both MB		(bmb)
	beq.b	WaitBothButtons
	cmp.b	#"B",(a5)		;Both MB with text	(Bmb)
	beq.w	ShowBothText
	bra.w	ShowUsage
Exit	move.l	4.w,a6
	move.l	DosBAdr(pc),a1
	jsr	-$19e(a6)		;CloseLibrary(a1)exec
BadDos	move.l	d4,d0
	rts

ShowAbout
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	About(pc),a2
	move.l	a2,d2
	moveq.l	#91,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
	moveq.l	#5,d4
	bra.b	Exit

ShowUsage
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	Usage(pc),a2
	move.l	a2,d2
	moveq.l	#30,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
	moveq.l	#20,d4
	bra.b	Exit

WaitLeftMouse
	btst	#6,$bfe001
	bne.s	WaitLeftMouse
	bra.s	Exit
	
WaitRightMouse
	btst	#10,$dff016
	bne.s	WaitRightMouse
	bra.s	Exit

WaitBothButtons
	btst	#6,$bfe001
	bne.s	WaitBothButtons
	btst	#10,$dff016
	bne.s	WaitBothButtons
	bra.s	Exit

ShowLeftText
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	Left(pc),a2
	move.l	a2,d2
	moveq.l	#46,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
.loop	btst	#6,$bfe001
	bne.b	.loop
	bsr.b	DisplayReturn
	bra.w	Exit

ShowRightText
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	Right(pc),a2
	move.l	a2,d2
	moveq.l	#47,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
.loop	btst	#10,$dff016
	bne.s	.loop
	bsr.b	DisplayReturn
	bra.w	Exit

ShowBothText
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	Both(pc),a2
	move.l	a2,d2
	moveq.l	#43,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
.loop	btst	#6,$bfe001
	bne.s	.loop
	btst	#10,$dff016
	bne.s	.loop
	bsr.b	DisplayReturn
	bra.w	Exit

DisplayReturn
	move.l	DosBAdr(pc),a6
	move.l	Output(pc),d1
	lea	C_Ret(pc),a2
	move.l	a2,d2
	moveq.l	#5,d3
	jsr	-$30(a6)		;Write(d1/d2/d3)dos
	rts

Version	dc.b	'$VER: MBWait v1.03 (17-Oct-95)',0
DosName	dc.b	'dos.library',0
DosBAdr	dc.l	0
Output	dc.l	0
About	dc.b	$9b,'0;1;4mMBWait v1.03 by Zebedee ©1995 Carnage'
	dc.b	'(17-Oct-95)',$9b,'0m',$a,$a
Usage	dc.b	'Usage: MBWait <l|L|r|R|b|B>mb',$a
Left	dc.b	'Press the left mouse button to continue...',$9b,'0 p'
Right	dc.b	'Press the right mouse button to continue...',$9b,'0 p'
Both	dc.b	'Press both mouse buttons to continue...',$9b,'0 p'
C_Ret	dc.b	$9b,'1 p',$a
	end