Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!bionet!apple!bloom-beacon!tut.cis.ohio-state.edu!osu-cis!killer!pollux!ti-csl!mips!holland From: holland@mips.csc.ti.com (Fred Hollander) Newsgroups: comp.sys.mac.programmer Subject: Re: How to Patch Summary: example source Keywords: trap patch init Message-ID: <63003@ti-csl.CSNET> Date: 8 Nov 88 16:43:54 GMT References: <10050042@eecs.nwu.edu> <563@poseidon.ATT.COM> Sender: news@ti-csl.CSNET Reply-To: holland@mips.UUCP (Fred Hollander) Organization: TI Computer Science Center, Dallas Lines: 67 Thanks to those who responded to my request for help. I finally got something to work. Here it is in case anybody else would like to use it. Build a code resource, type INIT, with the System and Locked attributes. There's a bit of a kludge in there because, unless I'm mistaken, the standard header provided by LightSpeed C trashes A0 beyond recovery. I modified the header (in ResEdit) by putting an extra instruction to push registers A0-A2 on the stack. An alternative would be to store the globals' base address and skip the header or write a custom header. Does anyone have the standard header? What else does it do besides put the entry point into A0? Fred Hollander Computer Science Center Texas Instruments, Inc. holland%ti-csl@csnet-rela The above statements are my own and not representative of Texas Instruments. The code below is my own and not representative of Texas Instruments. #include #define trapSysBeep 0xA9C8 long oldTrapAddress; Handle trapHandle; char installed = false; void main () { /* Manually put this (48E7 00E0) in the header at 0x000C so that it is called before AO is trashed! Change 0x0000 from 600E to 600A to point to this move. (May be easier to write a custom header.) asm{ movem.l A0-A2,-(A7) } */ RememberA0 (); SetUpA4 (); if (installed) { /* Put your stuff here */ asm{ move.l oldTrapAddress,A3 } RestoreA4 (); asm{ movem.l (A7)+,A0-A2 } asm{ jmp (A3) } } else { asm{ move.l A4,A0 _RecoverHandle move.l A0,trapHandle } DetachResource (trapHandle); HLock (trapHandle); oldTrapAddress = GetTrapAddress (trapSysBeep); SetTrapAddress ((long) *trapHandle, trapSysBeep); installed = true; RestoreA4 (); asm{ movem.l (A7)+,A0-A2 } } }