*	ColorCatchExe
*	By Preben Nielsen
*
*	This is the code created by ColorCatch V2.0
*
*HISTORY
*          Made with Hisoft V2.12
*
*  V1.0   ??-???-90: First release.
*  V2.0   06-Aug-91: Rewritten to get rid of Reloc-32 information in the
*                    executable file. It is now smaller than V1.0.
*                    It can now even be made resident (pure).
*                    Works fine with kickstart 2.x.

	OPT O+
	OPT O1+		;Tells when a branch could be optimised to short
	OPT i+		;Tells when '#' is probably missing

		incdir		"AsmInc:"
		include		"P.i"
		include		"exec/exec_lib.i"
		include		"graphics/view.i"
		include		"graphics/graphics_lib.i"
		include		"intuition/intuition.i"
		include		"libraries/dosextens.i"

WBenchMsg	EQUR		D7
GraphBase	EQUR		D6
IntuiBase	EQUR		D5

ColorExe	moveq		#0,WBenchMsg
		moveq		#0,GraphBase
		moveq		#0,IntuiBase
		Prepare		Exec_Call
		suba.l		A1,A1
		CallLib		FindTask		;Find us
		movea.l		D0,A2
		tst.l		pr_CLI(A2)
		bne.S		GetLibs
		lea		pr_MsgPort(A2),A0
		CallLib		WaitPort		;wait for a message
		lea		pr_MsgPort(A2),A0
		CallLib		GetMsg			;then get it
		move.l		D0,WBenchMsg		;save it for later reply
GetLibs		lea		GfxName(PC),A1
		CallLib		OldOpenLibrary
		move.l		D0,GraphBase
		beq.S		Error
		lea		IntuiName(PC),A1
		CallLib		OldOpenLibrary
		move.l		D0,IntuiBase
		beq.S		Error
		move.l		IntuiBase,A0
		move.l		ib_FirstScreen(A0),A0	;IntuitionBase->FirstScreen
		lea		sc_ViewPort(A0),A0	;Screen.ViewPort
		move.w		ColorCount(PC),D0
		lea		ColorTable(PC),A1
		move.l		GraphBase,A6
		CallLib		LoadRGB4		;Set new colors

Error
Exit		Prepare		Exec_Call
FreeIntui	move.l		IntuiBase,D0
		beq.S		FreeGfx
		movea.l		D0,A1
		CallLib		CloseLibrary
FreeGfx		move.l		GraphBase,D0
		beq.S		ReplyWB
		movea.l		D0,A1
		CallLib		CloseLibrary
ReplyWB		move.l		WBenchMsg,D2
		beq.S		AllDone
		CallLib		Forbid
		movea.l		D2,A1
		CallLib		ReplyMsg		;Reply WBenchMessage if we are started from WB
AllDone		moveq		#0,D0
		rts

GfxName		dc.b		'graphics.library',0
IntuiName	dc.b		'intuition.library',0
		EVEN

ColorCount	dc.w		0
*»»» This is where ColorCatch stores the colors
ColorTable	dcb.w		32,0
		END

