Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uakari.primate.wisc.edu!dogie.macc.wisc.edu!uwm.edu!srcsip!manyjars!mnkonar From: mnkonar@manyjars.SRC.Honeywell.COM (Murat N. Konar) Newsgroups: comp.sys.mac.programmer Subject: Re: Patching a trap question Message-ID: <32476@srcsip.UUCP> Date: 25 Sep 89 21:00:23 GMT References: <6582@hubcap.clemson.edu> Sender: news@src.honeywell.COM Reply-To: mnkonar@src.honeywell.com (Murat N. Konar) Organization: ipd Lines: 30 In article <6582@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes: >I know how to get a trap address and set a new address for the trap. However, >how can i get it to jump to my routine first and then let my routine decide >whether or not to pass the event or whatever on to the old routine that was >originally pointed to by the trap? Now please keep in mind that i know >absolutely no assembly language. Is it possible to do this in C or Pascal? >The responses that i got last time said that assembly was the only way. What I do is write the patch in Pascal, compile it to a PROC resource (exactly what you call it is unimportant). Then I use DisAsm3 (avilable at ftp sites) to disassemble the patch, find the epilogue (the part where the procedure cleans up after itself and returns). I'm not going to go into just what this looks like; for a real good explanation check out Scott Knasters "How To Write Macintosh Software." Anyhow, I find the epilogue and note what assembly instructions are involved and write a similar epilogue (using inline assembly) that leaves the stack in the same state as it was when entered (except for data modifications) and then JMPs to the real routine (never a JSR). Then I recompile the patch proc with the inline code inserted. (Gawd, I hope you can follow that!) This method will only work for stack based traps. Some trap routines are register based and need glue. I haven't played with any of those yet. ____________________________________________________________________ Have a day. :^| Murat N. Konar Honeywell Systems & Research Center, Camden, MN mnkonar@SRC.honeywell.com (internet) {umn-cs,ems,bthpyd}!srcsip!mnkonar(UUCP)