*
* Assembler: DevPac 2.14D			Date: 11-Sep-90, 04:21:50
*

	opt	c+,d-,o+

*
* SETREQ - example of an highly optimised assembler CLI command
*
* Written and optimised by Peter Fröhlich of Nephthys Software.
*

*
* This program is public domain software, but certain limitations have
* been implied in the accompaning DOC file.
*
* You are allowed to steal any ideas for your own programs of course,
* but only if you understand the inner workings of the tricks presented
* in this program, you have really "achieved" something.
* 

*
* NOTE: Of course this can be done shorter. But I wanted the user to know
*       wether the Requesters are on or off, and that just calls for some
*       text strings. But I even optimised THEM.
*
* ATTENTION: This source code is formatted for TAB = 10 characters!
*

	INCDIR	"INC:"

	INCLUDE	libraries/dosextens.i

	INCLUDE	misc/lib.i
	INCLUDE	misc/macros.i

CALLA	MACRO
	jsr	_LVO\1(a6)
	ENDM

_main:
	move.l	($4).w,a6
	subq.l	#4,SP		* reserve on long on the stack

	sub.l	a1,a1
	CALLA	FindTask		* get ^Process structure
	move.l	d0,a5
	beq.s	NoArpLib		* FindTask returned zero ->

	lea	_ArpName(PC),a1
	CALLA	OldOpenLibrary
	move.l	d0,a6
	beq.s	NoArpLib		* OpenLib returned zero ->

	tst.l	pr_WindowPtr(a5)
	beq.s	Disable		* pr_WindowPtr = 0 ->

	moveq.l	#0,d0		* set value to be put in pr_WindowPtr
	lea	TXT_ON(PC),a2	* address of argument for Printf
	bra.s	PrintMsg
Disable:
	moveq.l	#-1,d0		* set value to be put in pr_WindowPtr
	lea	TXT_OFF(PC),a2	* address of argument for Printf
PrintMsg:
	move.l	d0,pr_WindowPtr(a5)	* set pr_WindowPtr
	lea	TXT_SETREQ(PC),a0	* address of info text
	move.l	SP,a1		* use SP as address of pointer to argument
	move.l	a2,(a1)		* init pointer to argument (on stack)
	CALLA	Printf
Error:
	move.l	a6,a1
	move.l	($4).w,a6
	CALLA	CloseLibrary
NoArpLib:
	addq.l	#4,SP
	CLEAR	d0
	rts

TXT_SETREQ:
	dc.b	"Requesters %sabled.",10,0
TXT_OFF:
	dc.b	"dis",0
TXT_ON:
	dc.b	"en",0
_ArpName:
	dc.b	"arp.library",0

