; Requesters 1.1 : turn DOS Requesters on/off
; by Kyzer/CSG
; $VER: Requesters.asm 1.1 (08.04.98)
;
	incdir	include:
	include	lvo/exec_lib.i
	include	lvo/dos_lib.i
	include	dos/dosextens.i

stackf	MACRO	; stack_symbol, stackelement_symbol
	IFND	\1
\1	set	0
	ENDC
\1	set	\1-4
\2	equ	\1
	ENDM

	stackf	stk, swtoggle
	stackf	stk, swoff
	stackf	stk, swon
	stackf	stk, rdargs
args=swon

	move.l	4.w,a6
	suba.l	a1,a1
	jsr	_LVOFindTask(a6)
	move.l	d0,a3
	lea	pr_WindowPtr(a3),a3

	lea	dosname(pc),a1	; dos.library v36+
	moveq.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	tst.l	d0
	bne.s	start

; 1.3 compatible part (tee hee)
	moveq	#-1,d0
	cmp.l	(a3),d0
	bne.s	.go
	moveq	#0,d0
.go	move.l	d0,(a3)
	moveq	#0,d0
	rts

start	move.l	d0,a6
	link	a5,#stk

	lea	templat(pc),a0
	move.l	a0,d1
	lea	args(a5),a0	; to fill swon, swoff and swtoggle
	move.l	a0,d2
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	moveq	#0,d3
	jsr	_LVOReadArgs(a6)
	move.l	d0,rdargs(a5)
	beq.s	.noargs

	moveq	#0,d1
	tst.l	swon(a5)
	beq.s	.n1
	addq	#1,d1
.n1	tst.l	swoff(a5)
	beq.s	.n2
	addq	#1,d1
.n2	tst.l	swtoggle(a5)
	beq.s	.n3
	addq	#1,d1
.n3	cmp.b	#1,d1	; exactly one of on, off or toggle
	beq.s	.run
	moveq	#ERROR_TOO_MANY_ARGS,d1
	jsr	_LVOSetIoErr(a6)
	bra.s	.done

.run	moveq	#-1,d0
	tst.l	swtoggle(a5)
	beq.s	.nottog
	cmp.l	(a3),d0
	bne.s	.set
	moveq	#0,d0	; set to -1 if was not -1 before, otherwise set to 0
.nottog	tst.l	swon(a5)
	beq.s	.set	; d0 already set to 'off' - no change
	moveq	#0,d0	; swon WAS set - change from 'off' to 'on'
.set	move.l	d0,(a3)

.done	move.l	rdargs(a5),d1
	jsr	_LVOFreeArgs(a6)

.noargs	jsr	_LVOIoErr(a6)
	move.l	d0,d1
	moveq	#0,d2
	jsr	_LVOPrintFault(a6)

.exit	move.l	a6,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	unlk	a5
	moveq	#0,d0
	rts

dosname	dc.b	"dos.library",0
templat	dc.b	"ON/S,OFF/S,TOGGLE/S",0
