שתשת                                        	incdir	include:
	include	exec/exec.i
	include	intuition/screens.i
	include	lvo/lvos.i

START:
	move.l	4.w,a6
	lea	IntName(pc),a1
	moveq	#37,d0
	CallLib	OpenLibrary		; Open intuition
	move.l	d0,a5
	tst.l	d0
	beq.b	.NoInt

	move.l	#FUNCTION_SIZE,d0
	move.l	#MEMF_ANY,d1
	CallLib	AllocMem		; Allocate mem for new function
	move.l	d0,a4
	tst.l	d0
	beq	.NoMem

	lea	NewFunction(pc),a0	; Source
	move.l	a4,a1			; Destination
	move.l	#FUNCTION_SIZE,d0	; Size
	CallLib	CopyMem			; Copy the new function into allocated
					; memory.

	CallLib	Forbid			; Disable multitasking

	move.l	a5,a1			; IntBase (lib to be changed)
	move.w	#_LVOOpenScreen,a0	; Function to be replaced.
	move.l	a4,a2			; Pointer to function's allocated mem
	move.l	a2,d0			; Pointer to new function.
	CallLib	SetFunction
	move.l	d0,OldFunction(a4)

	move.l	a5,a1			; IntBase (lib to be changed)
	move.w	#_LVOOpenScreenTagList,a0	; Function to be replaced.
	lea	NewFunction2(a4),a2
	move.l	a2,d0			; Pointer to new function.
	CallLib	SetFunction
	move.l	d0,OldFunction2(a4)

	CallLib	Permit			; Enable multitasking
.NoMem:
	move.l	a5,a1
	CallLib	CloseLibrary,4.w
.NoInt:
	moveq	#0,d0			; We don't want any returncode
	rts				; exit




****************************************************************************
*
* This is the new function for OpenScreen()
*

SCREEN_WIDTH:	EQU	724

NewFunction:
	cmp.l	#0,a0				; Check if input error, so
	beq.b	.OkWidth			; that intuition can take care
						; the crashing itself.. =)

	cmp.w	#SCREEN_WIDTH,ns_Width(a0)	; Check if used screen is
	bcc.b	.OkWidth			; wider than maxwidth. If so,
						; then skip my routine.
	move.w	#SCREEN_WIDTH,d0		; Get max screen width
	sub.w	ns_Width(a0),d0			; And subtract used width from
	asr.w	#1,d0				; it, and divide by two
	move.w	d0,ns_LeftEdge(a0)		; Save new leftedge

.OkWidth:
	move.l	OldFunct(pc),a1			; Jump to old function
	jmp	(a1)

OldFunction:	EQU	*-NewFunction
OldFunct:	dc.l	0

****************************************************************************
*
* This is the new function for OpenScreenTagList()
*

NewFunction2:	EQU	*-NewFunction

	cmp.l	#0,a0				; Check if NewScreen used
	beq.b	.NoNewScreen

	cmp.w	#0,ns_Width(a0)			; Check if no width used (ns)
	beq.b	.NoNewScreen

	cmp.w	#SCREEN_WIDTH,ns_Width(a0)	; Check if width is >= max
	bcc.b	.OkWidth

	move.w	#SCREEN_WIDTH,d0		; Get max width
	sub.w	ns_Width(a0),d0			; subtract used width from max
	asr.w	#1,d0				; And divide by two to get
	move.w	d0,ns_LeftEdge(a0)		; screen to middle of display

.OkWidth:

.NoNewScreen:

	movem.l	d7-a6,-(sp)
	move.l	a0,a4			; Save NewScreen struct pointer
	move.l	a1,a5			; Save TagList pointer

	move.l	4.w,a6
	lea	UtilName(pc),a1
	moveq	#37,d0
	CallLib	OpenLibrary		; Open utiltiy.library
	move.l	d0,a6
	tst.l	d0
	beq.b	.NoUtil

	move.l	a5,a0
	move.l	#SA_Width,d0
	CallLib	FindTagItem		; Check if SA_Width tag used
	tst.l	d0
	beq.b	.NoTags			; No tags used!

	move.l	d0,a0

	cmp.l	#SCREEN_WIDTH,ti_Data(a0)	; Check if screenwidth too big
	bge.b	.Ok_Width			; Yes it was!

	move.l	#SCREEN_WIDTH,d0	; Max width
	sub.l	ti_Data(a0),d0		; minus used width
	asr.l	#1,d0			; divided by two
	move.l	d0,d7			; Save LeftEdge

	move.l	a5,a0
	move.l	#SA_Left,d0
	CallLib	FindTagItem		; Check if SA_Left tag used
	tst.l	d0
	beq.b	.NoLeftTag		; No SA_Left tag used

	move.l	d0,a0

	move.l	d7,ti_Data(a0)		; Save LeftEdge to taglist

	bra.b	.Ok_Width

.NoLeftTag:				; No LeftEdge tag was found!

	cmp.l	#0,a4			; Check if NewScreen was used
	beq.b	.Ok_Width		; Nope!

	move.w	d7,ns_LeftEdge(a4)	; Save leftedge in newscreen struct

.Ok_Width:

.NoTags:
	move.l	a6,a1
	CallLib	CloseLibrary,4.w	; Close utility.library

	movem.l	(sp)+,d7-a6

.NoUtil:
	move.l	a2,-(sp)
	move.l	OldFunct2(pc),a2
	jsr	(a2)
	move.l	(sp)+,a2
	rts

OldFunction2:	EQU	*-NewFunction
OldFunct2:	dc.l	0
UtilName:	dc.b	'utility.library',0


FUNCTION_SIZE:	EQU	*-NewFunction

IntName:	dc.b	'intuition.library',0
