
ABSEXECBASE		EQU	$4
_LVOAllocMem		EQU	-198
_LVOCloseLibrary	EQU	-414
_LVOSetFunction		EQU	-420
_LVOOpenLibrary		EQU	-552
_LVOCopyMemQuick	EQU	-630
_LVOMakeVPort		EQU	-216

	SECTION S_0,CODE

SECSTRT_0:
	MOVEM	a6/d2/d3,-(a7)			; Save Registers
	LEA	(LibName,PC),A1			; Name of Graphics.library
	MOVEQ	#39,D0				; Version 39+
	MOVEA.L	(ABSEXECBASE).W,A6		; Put Execbase in A6
	JSR	(_LVOOpenLibrary,A6)		; Open Library
	TST.L	D0				; Ptr to lib
	BEQ.S	V37				; If V39 do V37 check
	MOVEA.L	D0,A1
	JSR	(_LVOCloseLibrary,A6)		; Else it's V39, close & xit
	BRA.S 	Exit
V37:
	LEA	(LibName,PC),A1			; Here we go again...
	MOVEQ	#37,D0				; Try for V37
	JSR	(_LVOOpenLibrary,A6)		; Open Library
	TST.L	D0				; Ptr to lib
	BEQ.S	Exit				; if !=37 exit

	MOVE.L	D0,D2				; Lib ptr to D2 for later

	MOVEQ	#Efunct-Sfunct,D0		; Size of Allocation
	MOVEQ	#1,D1				; Any Ram
	JSR	(_LVOAllocMem,A6)		; Allocate Ram
	MOVE.L	D0,D3				; Store ptr to new ram in D3
	BEQ.S	Exit				; And if null ptr,exit
	MOVEA.L	D0,A1				; Set pointer as destination
	LEA	Sfunct,A0			; Set Source
	MOVEQ	#Efunct-Sfunct,D0		; Set Size
	JSR	(_LVOCopyMemQuick,A6)		; Copymem
	
	MOVEA.L	D2,A1				; Get Lib ptr for gfx.lib

	MOVEA	#_LVOMakeVPort,A0		; MakeVport offset
	MOVE.L	D3,D0				; Retrieve New Fctn Pointer
	JSR	(_LVOSetFunction,A6)		; SetFunction
	MOVEA.L	D3,A0				; Get address of new fctn
	MOVE.L	D0,(oldfctn-Sfunct,A0)		; Give it pointer to old fctn
	JSR	(_LVOCloseLibrary,A6)		; Close library
Exit:
	MOVEQ	#0,D0
	MOVEM	(a7)+,a6/d2/d3			; Restore registers
	RTS

LibName:
	DC.B "graphics.library",00
	DC.B "$VER: MakeVport_Patch 37.4 (20.10.94)",00,00
Sfunct:
	MOVE.L	A2,-(A7)
	BTST	#2,(33,A1)
	BEQ.S	LAB_0003
	TST.L	(20,A1)
	BEQ.S	LAB_0003
	BTST	#0,(31,A1)
	BEQ.S	LAB_0003
	SUBQ	#1,(30,A1)
LAB_0003:
	MOVEA.L	oldfctn,A2
	JSR	(A2)
	MOVEA.L	(A7)+,A2
	RTS
oldfctn:
	DC.L	$FFFFFFFF		; Rubbish Padding...
Efunct:                   
	END

