שתשת     =  *B  '     +  )2  $}      
;TEST
		INCDIR	'a_include:'
		INCLUDE	'antix/sysmacros.i'
		INCLUDE	'exec/a_memory.i'
		INCLUDE	'libraries/a_gadtools.i'
		INCLUDE	'lvo/a_exec_lib.i'
		INCLUDE	'lvo/a_intuition_lib.i'
		INCLUDE	'lvo/a_gadtools_lib.i'
		INCLUDE	'lvo/a_utility_lib.i'

	***************************************************************

		SECTION	NEWLOOKMENUPATCH,CODE_P
o:
		bra.b	.skipver
		dc.b	'$VER: NewLookMenuPatch V1.0 by Cliff Earl (15.9.1997)',10,13,0
		EVEN
.skipver:
		PUSHA

		lea	o(pc),a5

		bsr	_openlibs
		beq	_exiterr

		bsr	_checkforfast

		bsr	_findkeygfx
		beq	_exiterr
		bsr	_findkeyimg
		beq	_exiterr
		bsr	_modifykey
		beq	_exiterr

		bsr	_findchkgfx
		beq	_exiterr
		bsr	_findchkimg
		beq	_exiterr
		bsr	_modifychk
		beq	_exiterr

		bsr	_installpatches
		bne	_exitok

	***************************************

_exiterr:
		bsr	_removepatches
		bsr	_resetchk
		bsr	_resetkey

	***************************************

_exitok:
		IFD	TEST
		bsr	_removepatches
		bsr	_resetchk
		bsr	_resetkey
		ENDC

		bsr	_closelibs

		POPA
		moveq	#0,d0
g:		rts

	***************************************************************

_checkforfast:
		GLIB	Sys
		moveq	#MEMF_FAST,d1
		CALL	AvailMem
		tst.l	d0
		beq.b	.0
		moveq	#-1,d0
.0:
		move.b	d0,ChipOnly-o(a5)
		rts

	***************************************************************

_installpatches:
		move.l	#PATCHSIZE,d0
		move.l	#MEMF_PUBLIC!MEMF_REVERSE,d1
		CALL	AllocVec
		move.l	d0,patchmem-o(a5)
		beq.w	.fail
		move.l	d0,a4

		CALL	Forbid
		CALL	Disable

		lea	CREATEMENUSAPATCH(a4),a2
		move.l	_GadToolsBase(pc),a1
		lea	_LVOCreateMenusA,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldcmptr-o(a5)

		move.l	_IntuitionBase(pc),d7

		lea	OPENSCREENPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOOpenScreen,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldosptr-o(a5)

		lea	OPENSCREENTAGLISTPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOOpenScreenTagList,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldostptr-o(a5)

		lea	OPENWINDOWPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOOpenWindow,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldowptr-o(a5)

		lea	OPENWINDOWTAGLISTPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOOpenWindowTagList,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldowtptr-o(a5)

		lea	OPENWORKBENCHPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOOpenWorkBench,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldowbptr-o(a5)

		lea	SETMENUSTRIPPATCH(a4),a2
		move.l	d7,a1
		lea	_LVOSetMenuStrip,a0
		move.l	a2,d0
		CALL	SetFunction
		move.l	d0,oldsmsptr-o(a5)

		move.l	#PATCHSIZE-1,d0
		lea	PATCHCODE(pc),a0
		move.l	a4,a1
.reloc:
		move.b	(a0)+,(a1)+
		dbf	d0,.reloc

		CALL	Enable
		CALL	Permit
		move.l	a4,d0
		rts
.fail:
		moveq	#0,d0
		rts

	***************************************

_removepatches:
		move.l	patchmem(pc),d0
		beq	.nomem

		move.l	d0,a4

		CALL	Forbid
		CALL	Disable

		move.l	_GadToolsBase(pc),a1
		lea	_LVOCreateMenusA,a0
		move.l	CREATEMENUSAPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOOpenScreen,a0
		move.l	OPENSCREENPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOOpenScreenTagList,a0
		move.l	OPENSCREENTAGLISTPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOOpenWindow,a0
		move.l	OPENWINDOWPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOOpenWindowTagList,a0
		move.l	OPENWINDOWTAGLISTPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOOpenWorkBench,a0
		move.l	OPENWORKBENCHPATCH-4(a4),d0
		CALL	SetFunction

		move.l	_IntuitionBase(pc),a1
		lea	_LVOSetMenuStrip,a0
		move.l	SETMENUSTRIPPATCH-4(a4),d0
		CALL	SetFunction

		CALL	Enable
		CALL	Permit

		move.l	a4,a1
		CALL	FreeVec
.nomem:
		rts

patchmem:	dc.l	0

	***************************************************************

	*	here's the patch code.

PATCHCODE:
		dc.l	'ATX!'			; an id for later..

_UtilityBase:	dc.l	0

oldcmptr:	dc.l	0

CREATEMENUSAPATCH	=	*-PATCHCODE

		move.l	a1,d0
		bne.b	.tags
		lea	cmtags2(pc),a1
		PUSH	a2
		move.l	oldcmptr(pc),a2
		jsr	(a2)
		POP	a2
		rts
.tags:
		PUSHM	a0-a2/a6
		move.l	a1,a2
		move.l	a1,a0
		GLIB	Utility
		lea	cmfilter(pc),a1
		moveq	#TAGFILTER_NOT,d0
		CALL	FilterTagItems
		lea	cmtags(pc),a1
		move.l	a2,ti_SIZEOF+ti_Data(a1)
		POPM	a0-a2/a6
		lea	cmtags(pc),a1
		PUSH	a2
		move.l	oldcmptr(pc),a2
		jsr	(a2)
		POP	a2
		rts

cmfilter:	dc.l	GTMN_FrontPen
		dc.l	TAG_DONE

cmtags2:	dc.l	GTMN_FrontPen,1
		dc.l	TAG_DONE

cmtags:		dc.l	GTMN_FrontPen,1
		dc.l	TAG_MORE,0

	***************************************

oldosptr:	dc.l	0

OPENSCREENPATCH	=	*-PATCHCODE

		move	ns_Type(a0),d0
		and	#NS_EXTENDED,d0
		bne.b	.isext
		move.b	#1,ns_DetailPen(a0)
		move.b	#2,ns_BlockPen(a0)
		PUSH	a2
		move.l	oldosptr(pc),a2
		jsr	(a2)
		POP	a2
		rts
.isext:
		PUSHM	a0-a2/a6
		move.l	a0,a2
		move.l	ens_Extension(a2),a0
		GLIB	Utility
		lea	nsfilter(pc),a1
		moveq	#TAGFILTER_NOT,d0
		CALL	FilterTagItems
		lea	nstags(pc),a0
		move.l	ens_Extension(a2),ti_SIZEOF*2+ti_Data(a0)
		move.l	a0,ens_Extension(a2)
		POPM	a0-a2/a6
		PUSH	a2
		move.l	oldosptr(pc),a2
		jsr	(a2)
		POP	a2
		rts

	***************************************

oldostptr:	dc.l	0

OPENSCREENTAGLISTPATCH	=	*-PATCHCODE

		move.l	a0,d0			; a0 not NULL means there's a newscreen struct..
		beq.b	.nons
		move.b	#1,ns_DetailPen(a0)
		move.b	#2,ns_BlockPen(a0)
.nons:
		move.l	a1,d0
		bne.b	.tags
		lea	nstags2(pc),a1
		PUSH	a2
		move.l	oldostptr(pc),a2
		jsr	(a2)
		POP	a2
		rts
.tags:
		PUSHM	a0-a2/a6
		move.l	a1,a2
		GLIB	Utility
		move.l	a1,a0
		lea	nsfilter(pc),a1
		moveq	#TAGFILTER_NOT,d0
		CALL	FilterTagItems
		lea	nstags(pc),a0
		move.l	a2,ti_SIZEOF*2+ti_Data(a0)
		POPM	a0-a2/a6
		lea	nstags(pc),a1
		PUSH	a2
		move.l	oldostptr(pc),a2
		jsr	(a2)
		POP	a2
		rts

nstags2:	dc.l	SA_DetailPen,1
		dc.l	SA_BlockPen,2
		dc.l	TAG_DONE

nstags:		dc.l	SA_DetailPen,1
		dc.l	SA_BlockPen,2
		dc.l	TAG_MORE,0

nsfilter:	dc.l	SA_DetailPen
		dc.l	SA_BlockPen
		dc.l	TAG_DONE

	***************************************

oldowptr:	dc.l	0

OPENWINDOWPATCH	=	*-PATCHCODE

		move.l	nw_Type(a0),d0
		and.l	#WFLG_NW_EXTENDED,d0
		bne.b	.isext
		move.b	#1,nw_DetailPen(a0)
		move.b	#2,nw_BlockPen(a0)
		PUSH	a2
		move.l	oldowptr(pc),a2
		jsr	(a2)
		POP	a2
		rts
.isext:
		PUSHM	a0-a2/a6
		move.l	a0,a2
		move.l	enw_Extension(a2),a0
		GLIB	Utility
		lea	nwfilter(pc),a1
		moveq	#TAGFILTER_NOT,d0
		CALL	FilterTagItems
		lea	nwtags(pc),a0
		move.l	enw_Extension(a2),ti_SIZEOF*2+ti_Data(a0)
		move.l	a0,enw_Extension(a2)
		POPM	a0-a2/a6
		PUSH	a2
		move.l	oldowptr(pc),a2
		jsr	(a2)
		POP	a2
		rts

	***************************************

oldowtptr:	dc.l	0

OPENWINDOWTAGLISTPATCH	=	*-PATCHCODE

		move.l	a0,d0			; a0 not NULL means there's a newscreen struct..
		beq.b	.nonw
		move.b	#1,nw_DetailPen(a0)
		move.b	#2,nw_BlockPen(a0)
.nonw:
		move.l	a1,d0
		bne.b	.tags
		lea	nwtags2(pc),a1
		PUSH	a2
		move.l	oldowtptr(pc),a2
		jsr	(a2)
		POP	a2
		rts
.tags:
		PUSHM	a0-a2/a6
		move.l	a1,a2
		GLIB	Utility
		move.l	a1,a0
		lea	nwfilter(pc),a1
		moveq	#TAGFILTER_NOT,d0
		CALL	FilterTagItems
		lea	nwtags(pc),a0
		move.l	a2,ti_SIZEOF*2+ti_Data(a0)
		POPM	a0-a2/a6
		lea	nwtags(pc),a1
		PUSH	a2
		move.l	oldowtptr(pc),a2
		jsr	(a2)
		POP	a2
		rts

nwtags2:	dc.l	WA_DetailPen,1
		dc.l	WA_BlockPen,2
		dc.l	TAG_DONE

nwtags:		dc.l	WA_DetailPen,1
		dc.l	WA_BlockPen,2
		dc.l	TAG_MORE,0

nwfilter:	dc.l	WA_DetailPen
		dc.l	WA_BlockPen
		dc.l	TAG_DONE

	***************************************

oldowbptr:	dc.l	0

OPENWORKBENCHPATCH	=*-PATCHCODE

		PUSH	a0
		move.l	oldowbptr(pc),a0
		jsr	(a0)
		POP	a0
		tst.l	d0
		beq.b	.nowb

		move.l	d0,a0
		move.b	#1,sc_DetailPen(a0)
		move.b	#2,sc_BlockPen(a0)
		lea	sc_RastPort(a0),a0
		move.b	#1,rp_FgPen(a0)
		move.b	#2,rp_BgPen(a0)

		PUSHM	d0/a1-a2
		move.l	sc_FirstWindow(a0),d0
		beq.b	.nowin
		move.l	d0,a0
		lea	-1.w,a1
		lea	-1.w,a2
		CALL	SetWindowTitles
.nowin:
		POPM	d0/a1-a2
.nowb:
		rts

	***************************************

oldsmsptr:	dc.l	0

SETMENUSTRIPPATCH	=*-PATCHCODE

		PUSHM	a2-a5
		move.l	a1,a2
.moremenus:
		move.l	mu_FirstItem(a2),d0
		beq	.noitems
.moreitems:
		move.l	d0,a3
		move.l	mi_SubItem(a3),d0
		beq.b	.nosubs
.moresubs:
		move.l	d0,a4
		move	mi_Flags(a4),d0
		and	#ITEMTEXT,d0
		bne.b	.notsubimg
		move.l	mi_ItemFill(a4),d0
		beq.b	.nextsub
.moresubimg:
		move.l	d0,a5
		move.b	#2,ig_PlanePick(a5)
		move.b	#1,ig_PlaneOnOff(a5)
		move.l	ig_NextImage(a5),d0
		beq.b	.nextsub
		bra.b	.moresubimg
.notsubimg:
		move.l	mi_ItemFill(a4),d0
		beq.b	.nextsub
.moresubitxt:
		move.l	d0,a5
		move.b	#1,it_FrontPen(a5)
		move.b	#2,it_BackPen(a5)
		move.l	it_NextText(a5),d0
		bne.b	.moresubitxt
.nextsub:
		move.l	mi_NextItem(a4),d0
		bne.b	.moresubs
.nosubs:
		move	mi_Flags(a3),d0
		and	#ITEMTEXT,d0
		bne.b	.notitemimg
		move.l	mi_ItemFill(a3),d0
		beq.b	.nextitem
.moreitemimg:
		move.l	d0,a5
		move.b	#2,ig_PlanePick(a5)
		move.b	#1,ig_PlaneOnOff(a5)
		move.l	ig_NextImage(a5),d0
		beq.b	.nextitem
		bra.b	.moreitemimg
.notitemimg:
		move.l	mi_ItemFill(a3),d0
		beq.b	.nextitem
.moreitemitxt:
		move.l	d0,a5
		move.b	#1,it_FrontPen(a5)
		move.b	#2,it_BackPen(a5)
		move.l	it_NextText(a5),d0
		bne.b	.moreitemitxt
.nextitem:
		move.l	mi_NextItem(a3),d0
		bne	.moreitems
.noitems:
		move.l	mu_NextMenu(a2),d0
		beq.b	.empty
		move.l	d0,a2
		bra	.moremenus
.empty:
		move.l	oldsmsptr(pc),a2
		jsr	(a2)
		POPM	a2-a5
		rts

PATCHSIZE	=*-PATCHCODE

	***************************************************************

_findchkgfx:
		move	#$7fff,_counter-o(a5)
		lea	0.w,a0
		lea	oldchkgfx(pc),a2
		movem	(a2),d0-d7
.find:
		cmp	(a0),d0
		beq.b	.found
.findnext:
		addq.l	#2,a0
		subq	#1,_counter-o(a5)
		bpl.b	.find
.notfound:
		moveq	#0,d0
		rts
.found:
		cmp	2(a0),d1
		bne.b	.findnext
		cmp	4(a0),d2
		bne.b	.findnext
		cmp	6(a0),d3
		bne.b	.findnext
		cmp	8(a0),d4
		bne.b	.findnext
		cmp	10(a0),d5
		bne.b	.findnext
		cmp	12(a0),d6
		bne.b	.findnext
		cmp	14(a0),d7
		bne.b	.findnext
		move.l	a0,chkgfx-o(a5)

		move.l	a0,d0
		rts

	***************************************

_findchkimg:
		move.l	_IntuitionBase(pc),a0
		tst.b	ChipOnly-o(a5)
		bne.b	.fast
		sub.l	a0,a0
.fast:
		move.l	chkgfx(pc),d0
		move.l	#$7fff,d1
.find:
		cmp.l	(a0),d0
		beq.b	.found
.findnext:
		addq.l	#2,a0
		dbf	d1,.find
.notfound:
		moveq	#0,d0
		rts
.found:
		sub.l	#ig_ImageData,a0
		cmp	#2,ig_LeftEdge(a0)
		bne.b	.findnext
		cmp	#0,ig_TopEdge(a0)
		bne.b	.findnext
		cmp	#15,ig_Width(a0)
		bne.b	.findnext
		cmp	#8,ig_Height(a0)
		bne.b	.findnext
		move.l	a0,chkimg-o(a5)
		move.l	a0,d0
		rts

	***************************************

_modifychk:
		moveq	#newchkgfxsize,d0
		move.l	#MEMF_CHIP!MEMF_REVERSE,d1
		CALL	AllocVec
		move.l	d0,chkbuff-o(a5)
		beq.b	.fail

		move.l	d0,a1
		lea	newchkgfx(pc),a0
		movem.l	(a0)+,d0-d7
		movem.l	d0-d7,(a1)

		move.l	chkimg(pc),a0

		movem.l	(a0),d0-d3
		movem.l	d0-d3,oldchkimg-o(a5)

		move	#2,ig_Depth(a0)
		move.b	#%11,ig_PlanePick(a0)
		move.b	#%0,ig_PlaneOnOff(a0)
		move.l	chkbuff(pc),ig_ImageData(a0)

		moveq	#1,d0
.fail:
		rts

	***************************************

_resetchk:
		move.l	chkbuff(pc),d4
		beq.b	.nochk
		move.l	chkimg(pc),a0
		movem.l	oldchkimg(pc),d0-d3
		movem.l	d0-d3,(a0)
		move.l	d4,a1
		CALL	FreeVec
.nochk:
		rts

	***************************************

chkgfx:		dc.l	0
chkimg:		dc.l	0
chkbuff:	dc.l	0
oldchkimg:	dcb.b	ig_SIZEOF

oldchkgfx:
		dc.w	$fff0!1
		dc.w	$ffe6!1
		dc.w	$ffce!1
		dc.w	$ff9e!1
		dc.w	$0f3e!1
		dc.w	$c67e!1
		dc.w	$e0fe!1
		dc.w	$f1fe!1
newchkgfx:
		dc.w	$000e,$0018,$0030,$0060,$f0c0,$3980,$1f00,$0e00
		dc.w	$fff0,$ffe6,$ffce,$ff9e,$0f3e,$c67e,$e0fe,$f1fe
newchkgfxsize	=*-newchkgfx

	***************************************************************

_findkeyimg:
		move.l	_IntuitionBase(pc),a0
		tst.b	ChipOnly-o(a5)
		bne.b	.fast
		sub.l	a0,a0
.fast:
		move.l	keygfx(pc),d0
		move.l	#$7fff,d1
.find:
		cmp.l	(a0),d0
		beq.b	.found
		addq.l	#2,a0
		dbf	d1,.find
		moveq	#0,d0
		rts
.found:
		sub.l	#ig_ImageData,a0
		tst.l	(a0)			; left/top both 0?
		bne.b	.find
		cmp	#23,ig_Width(a0)	; correct width?
		bne.b	.find
		cmp	#8,ig_Height(a0)	; correct height?
		bne.b	.find
		move.l	a0,keyimg-o(a5)	; good enough for me :^)
		move.l	a0,d0
		rts

	***************************************

_findkeygfx:
		move	#$7fff,_counter-o(a5)
		lea	0.w,a0
		lea	oldkeygfx(pc),a2
		movem.l	(a2),d0-d7
.find:
		cmp.l	(a0),d0
		beq.b	.found
		addq.l	#2,a0
		subq	#1,_counter-o(a5)
		bpl.b	.find
.notfound:
		moveq	#0,d0
		rts
.found:
		cmp.l	4(a0),d1
		bne.b	.find
		cmp.l	8(a0),d2
		bne.b	.find
		cmp.l	12(a0),d3
		bne.b	.find
		cmp.l	16(a0),d4
		bne.b	.find
		cmp.l	20(a0),d5
		bne.b	.find
		cmp.l	24(a0),d6
		bne.b	.find
		cmp.l	28(a0),d7
		bne.b	.find
		move.l	a0,keygfx-o(a5)

		move.l	a0,d0
		rts

	***************************************

_modifykey:
		moveq	#newkeygfxsize,d0
		move.l	#MEMF_CHIP!MEMF_REVERSE,d1
		CALL	AllocVec
		move.l	d0,keybuff-o(a5)
		beq.b	.fail

		move.l	d0,a1
		lea	newkeygfx(pc),a0
		movem.l	(a0)+,d0-d7
		movem.l	d0-d7,(a1)
		movem.l	(a0),d0-d7
		movem.l	d0-d7,4*8(a1)

		move.l	keyimg(pc),a0

		movem.l	(a0),d0-d3
		movem.l	d0-d3,oldkeyimg-o(a5)

		move	#2,ig_Depth(a0)
		move.b	#%11,ig_PlanePick(a0)
		move.b	#%0,ig_PlaneOnOff(a0)
		move.l	keybuff(pc),ig_ImageData(a0)

		moveq	#1,d0
.fail:
		rts

	***************************************

_resetkey:
		move.l	keybuff(pc),d4
		beq.b	.nokey
		move.l	keyimg(pc),a0
		movem.l	oldkeyimg(pc),d0-d3
		movem.l	d0-d3,(a0)
		move.l	d4,a1
		CALL	FreeVec
.nokey:
		rts

	***************************************

keygfx:		dc.l	0
keyimg:		dc.l	0
keybuff:	dc.l	0
oldkeyimg:	dcb.b	ig_SIZEOF

oldkeygfx:
		dc.l	$c0000600
		dc.l	$0003c000
		dc.l	$000fc000
		dc.l	$0039c000
		dc.l	$00e1c000
		dc.l	$03ffc000
		dc.l	$1f83f000
		dc.l	$c0000600
newkeygfx:
		dc.l	$3ffff800,$fffc3e00,$fff03e00,$ffc63e00
		dc.l	$ff1e3e00,$fc003e00,$e07c0e00,$3ffff800

		dc.l	$c0000600,$0003c000,$000fc000,$0039c000
		dc.l	$00e1c000,$03ffc000,$1f83f000,$c0000600
newkeygfxsize	=*-newkeygfx

	***************************************************************

_openlibs:
		move.l	4.w,a6
		move.l	a6,_SysBase

		lea	IntuitionName(pc),a1
		moveq	#37,d0
		CALL	OpenLibrary
		move.l	d0,_IntuitionBase-o(a5)
		beq.b	.fail

		lea	GadToolsName(pc),a1
		moveq	#37,d0
		CALL	OpenLibrary
		move.l	d0,_GadToolsBase-o(a5)
		beq.b	.fail

		lea	UtilityName(pc),a1
		moveq	#37,d0
		CALL	OpenLibrary
		move.l	d0,_UtilityBase-o(a5)
.fail:
		rts

	***************************************

_closelibs:
		move.l	_IntuitionBase(pc),d0
		beq.b	.noint
		move.l	d0,a1
		CALL	CloseLibrary
.noint:
		move.l	_GadToolsBase(pc),d0
		beq.b	.nogt
		move.l	d0,a1
		CALL	CloseLibrary
.nogt:
		move.l	_UtilityBase(pc),d0
		beq.b	.nout
		move.l	d0,a1
		CALL	CloseLibrary
.nout:
		rts

_counter:	dc.w	0

_SysBase:	dc.l	0
_IntuitionBase:	dc.l	0
_GadToolsBase:	dc.l	0

ChipOnly:	dc.b	0

IntuitionName:	dc.b	'intuition.library',0
GadToolsName:	dc.b	'gadtools.library',0
UtilityName:	dc.b	'utility.library',0

		EVEN

	***************************************************************

		END

