* AUTOREQ-Routine
* unterstützt den Aufruf von AutoRequestern
* unter Intuition
* Aufruf:
* C: AutoReq(window,bodyt,post,negt,posfl,negl)
* Ass:	       A0     A1   A2	A3   D0    D1
*
* window: Windowpointer des Windows, über dem der
*	  Requester geöffnet werden soll. Kann 0 sein,
*	  dann wird auf Workbench geöffnet
* bodyt : Text für den "Body" des Autorequester. Einzelne
*	  Zeilen werden mit '|' untertrennt.
* post	: string für den "positive-text", kann 0 sein
* negt	: string für den "negative-text"
* posfl : IDCMP-Flags, die als postive-select gewertet werden
* negl	: IDCMP-Flags, die als negativ-select gewertet werden
*
* D0 = 0 : negativ
*     -1 : positiv
*
* Die Routine ist re-entrant, kann also zur verwendung in einer
* exec-shared-library verwendet werden
*
call	MACRO
	xref	_LVO\1
	move.l	_IntuitionBase,a6
	jsr	_LVO\1(a6)
	ENDM

	xref	_IntuitionBase

*	 Code	 autoreqcode
* C-Interface
	xdef	_AutoReq
_AutoReq
	movem.l a2/a3,-(sp)
	movem.l 12(sp),a0-a3
	movem.l 28(sp),d0-d1
	bsr.s	.AutoReq
	movem.l (sp)+,a2/a3
	rts

* Assembler-Einsprung
	xdef	.AutoReq
.AutoReq
	movem.l d2-d7/a5-a6,-(sp)
	moveq	#40,d7
	link	a4,#-28 		* variablen-stack einrichten
	clr.l	-4(a4)			* Rememberkey
	move.l	d0,-20(a4)
	move.l	d1,-24(a4)
	move.l	a0,-28(a4)
	move.l	a1,-16(a4)
	clr.l	-8(a4)
	move.l	a2,d0
	beq.s	nopostxt
	lea	-4(a4),a0		* intuition-text struktur
	moveq	#20,d0			* für positiv-text
	move.l	#65536,d1		* erzeugen
	call	AllocRemember
	move.l	d0,a0			* und initialisieren
	move.l	d0,-8(a4)
	move.w	#6,4(a0)
	move.w	#3,6(a0)
	move.l	a2,12(a0)
nopostxt
	lea	-4(a4),a0		* intuition-text struktur
	moveq	#20,d0			* für negativ-text
	move.l	#65536,d1		* erzeugen
	call	AllocRemember
	move.l	d0,a0
	move.l	d0,-12(a4)
	move.w	#6,4(a0)
	move.w	#3,6(a0)
	move.l	a3,12(a0)
* x-y Grösse der Texteberechnen
* berechnen
	moveq	#90,d6
	move.l	-8(a4),d0
	beq.s	nopostxt2
	move.l	d0,a0
	call	IntuiTextLength
	add.l	d0,d6
nopostxt2
	move.l	-12(a4),a0
	call	IntuiTextLength
	add.l	d0,d6
* body erzeugen
	suba.l	a3,a3
	move.l	-16(a4),a2
	moveq	#4,d5
crbod	moveq	#0,d0
	move.l	a2,a0
crb1	addq.w	#1,d0
	tst.b	(a0)
	beq.s	ecrb
	cmp.b	#'|',(a0)+
	bne.s	crb1
ecrb	move.l	#65536,d1
	lea	-4(a4),a0
	call	AllocRemember
	move.l	d0,-(sp)
	move.l	d0,a0
crb3	move.b	(a2),(a0)+
	beq.s	crb6
	cmp.b	#'|',(a2)+
	bne.s	crb3
crb4	clr.b	-(a0)
crb6	moveq	#20,d0
	move.l	#65536,d1
	lea	-4(a4),a0
	call	AllocRemember
	move.l	d0,a0
	move.w	#14,4(a0)
	move.w	d5,6(a0)
	add.w	#8,d5
	add.w	#8,d7
	move.l	(sp)+,12(a0)
	move.l	a3,16(a0)
	move.l	a0,a3
	call	IntuiTextLength
	add.w	#56,d0		* ist der body länger als vorher ?
	cmp.w	d0,d6
	bcc.s	crb5
	move.w	d0,d6		* ja, neue länge als vergleichswert
crb5	tst.b	(a2)
	bne.s	crbod
	move.l	a3,a1
	move.l	-8(a4),a2
	move.l	-12(a4),a3
	move.l	-20(a4),d0
	move.l	-24(a4),d1
	move.l	-28(a4),a0
	move.l	d6,d2
	move.l	d7,d3
* anzeigen des AutoRequester
	call	AutoRequest
	move.l	d0,d7
	lea	-4(a4),a0
	moveq	#-1,d0
	call	FreeRemember
	unlk	a4
	move.l	d7,d0
	movem.l (sp)+,d2-d7/a5-a6
	rts

	END
