	include	"exec/funcdef.i"
	include	"exec/types.i"
	include	"exec/initializers.i"
	include	"exec/resident.i"
	include	"exec/libraries.i"
	include	"exec/memory.i"
	include	"exec/execbase.i"
	include	"exec/exec_lib.i"
	include	"dos/dos_lib.i"
	include	"intuition/intuition.i"
	include	"intuition/intuition_lib.i"

TextRequest	equ	-174

	STRUCTURE	TRStructure,0
	APTR	TR_Text
	APTR	TR_Controls
	APTR	TR_Window
	APTR	TR_MiddleText
	APTR	TR_PositiveText
	APTR	TR_NegativeText
	APTR	TR_Title
	WORD	TR_KeyMask
	WORD	TR_TextColor
	WORD	TR_DetailColor
	WORD	TR_BlockColour
	WORD	TR_VersionNumber
	UWORD	TR_Timeout
	LONG	TR_AbortMask
	UWORD	TR_rfu1
	LABEL	TR_SIZEOF

	STRUCTURE	ReqLib,LIB_SIZE
	APTR	rl_SysLib
	APTR	rl_DosLib
	APTR	rl_IntuiLib
	APTR	rl_GfxLib
	APTR	rl_SegList
	APTR	rl_Images
	BYTE	rl_Flags
	BYTE	rl_Pad
	APTR	rl_ConsoleDev
	APTR	rl_ConsoleHandle
	APTR	rl_RexxSysBase
	LABEL	MyLib_Sizeof

start	move.l	($4).w,a6
	lea	(dosname,pc),a1
	moveq	#0,d0
	jsr	(_LVOOpenLibrary,a6)
	tst.l	d0
	beq	exit
	move.l	d0,a5
	exg	a5,a6
	jsr	(_LVOOutput,a6)
	move.l	d0,d7
	cmpi.w	#37,(LIB_VERSION,a5)
	bcs	oldkick
	exg	a5,a6
	lea	(reqname,pc),a1
	moveq	#0,d0
	jsr	(_LVOOpenLibrary,a6)
	tst.l	d0
	beq	noreq
	move.l	d0,a4
	move.l	(TextRequest+2,a4),a3
	cmpi.l	#'RTP1',(-4,a3)
	beq	remove
	lea	(nt_CODE,pc),a3
	move.l	(-8,a3),d0
	moveq	#MEMF_PUBLIC,d1
	jsr	(_LVOAllocMem,a6)
	tst.l	d0
	bne.s	gocopy
	bsr.s	closedos
	move.l	a4,a5
	bra.s	closedos
gocopy	lea	(nt_START,pc),a0
	move.l	d0,a1
	lea	(12,a1),a3
	move.l	#nt_END-nt_START,d0
	jsr	(_LVOCopyMem,a6)
	jsr	(_LVOForbid,a6)
	move.l	a3,d0
	move.l	#TextRequest,a0
	move.l	a4,a1
	jsr	(_LVOSetFunction,a6)
	move.l	d0,(-12,a3)
	jsr	(_LVOPermit,a6)
	move.l	#text1,d2
	move.l	#text2-text1,d3
writemsg	exg	a5,a6
kickmsg	move.l	d7,d1
	jsr	(_LVOWrite,a6)
	exg	a5,a6
closedos	move.l	a5,a1
	jsr	(_LVOCloseLibrary,a6)
exit	moveq	#0,d0
	rts

oldkick	move.l	#text3,d2
	move.l	#text4-text3,d3
	bra.s	kickmsg

noreq	move.l	#text4,d2
	move.l	#text5-text4,d3
	bra.s	writemsg

remove	jsr	(_LVOForbid,a6)
	move.l	(-12,a3),d0
	move.l	#TextRequest,a0
	move.l	a4,a1
	jsr	(_LVOSetFunction,a6)
	jsr	(_LVOPermit,a6)
	lea	(-12,a3),a1
	move.l	(-8,a3),d0
	jsr	(_LVOFreeMem,a6)
	moveq	#1,d4
closereq	move.l	a4,a1
	jsr	(_LVOCloseLibrary,a6)
	dbf	d4,closereq
	move.l	#text2,d2
	move.l	#text3-text2,d3
	bra.s	writemsg

dosname	dc.b	"dos.library",0
reqname	dc.b	"req.library",0

text1	dc.b	$9b,"0;33;40mRTP v1.01",$9b,"0;31;40m by Martin Berndt",10
	dc.b	"Patch for req.library to use Kick 2.0 TextRequester.",10
text2	dc.b	$9b,"0;33;40mRTP v1.01",$9b,"0;31;40m removed.",10
text3	dc.b	"This programm needs Kickstart v37 or higher",10
text4	dc.b	"Can't open req.library",10
text5	dc.b	"$VER: RTP 1.01 (18.12.91)",0

nt_START	dc.l	0,nt_END-nt_START
	dc.b	"RTP1"

nt_CODE	tst.w	(TR_Timeout,a0)
	beq.s	nt_patch
nt_old	move.l	(nt_START,pc),-(sp)
nt_exit	rts

nt_count	move.l	a0,d0
	beq.s	nt_exit
	moveq	#0,d0
nt_cntlp	tst.b	(a0)+
	beq.s	nt_cntex
	addq.l	#1,d0
	bra.s	nt_cntlp
nt_cntex	add.l	d0,d2
	rts

nt_copy	move.b	(a0)+,(a3)+
	bne.s	nt_copy
	move.b	#'|',(-1,a3)
	rts

nt_patch	movem.l	d0-d1/a0-a1,-(sp)
	movem.l	d2-d7/a2-a6,-(sp)
	move.l	a0,a5
	moveq	#0,d2
	move.l	(TR_MiddleText,a5),a0
	bsr.s	nt_count
	move.l	(TR_PositiveText,a5),a0
	bsr.s	nt_count
	move.l	(TR_NegativeText,a5),a0
	bsr.s	nt_count
	moveq	#es_SIZEOF+3,d1
	add.l	d1,d2
	move.l	d2,-(sp)
	move.l	($4).w,a6
	move.l	d2,d0
	moveq	#MEMF_PUBLIC,d1
	jsr	(_LVOAllocMem,a6)
	tst.l	d0
	beq.s	nt_nomem
	move.l	d0,a4
	lea	(es_SIZEOF,a4),a3
	move.l	a3,(es_GadgetFormat,a4)
	move.l	(TR_PositiveText,a5),a0
	move.l	a0,d0
	beq.s	nt_skip1
	bsr.s	nt_copy
nt_skip1	move.l	(TR_MiddleText,a5),a0
	move.l	a0,d0
	beq.s	nt_skip2
	bsr.s	nt_copy
nt_skip2	move.l	(TR_NegativeText,a5),a0
	move.l	a0,d0
	beq.s	nt_skip3
	bsr.s	nt_copy
nt_skip3	clr.b	-(a3)
	moveq	#es_SIZEOF,d0
	move.l	d0,(es_StructSize,a4)
	clr.l	(es_Flags,a4)
	move.l	(TR_Text,a5),(es_TextFormat,a4)
	move.l	(TR_Title,a5),(es_Title,a4)
	move.l	(TR_Window,a5),a0
	move.l	a4,a1
	lea	(nt_IDCMP,pc),a2
	move.l	(TR_Controls,a5),a3
	move.l	(44,sp),a6
	move.l	(rl_IntuiLib,a6),a6
	jsr	(_LVOEasyRequestArgs,a6)
	exg	d0,d1
	move.l	(sp),d0
	move.l	d1,(sp)
	move.l	($4).w,a6
	move.l	a4,a1
	jsr	(_LVOFreeMem,a6)
	move.l	(sp)+,d0
	movem.l	(sp)+,d2-d7/a2-a6
	addq.w	#8,sp
	addq.w	#8,sp
	rts
nt_nomem	addq.w	#4,sp
	movem.l	(sp)+,d2-d7/a2-a6
	movem.l	(sp)+,d0-d1/a0-a1
	bra	nt_old
nt_IDCMP	dc.l	0
nt_END

	end
