Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!elroy!usc!orion.cf.uci.edu!uci-ics!zardoz!dhw68k!thecloud From: thecloud@dhw68k.cts.com (Ken McLeod) Newsgroups: comp.sys.mac.programmer Subject: Re: Patching a trap address Message-ID: <23164@dhw68k.cts.com> Date: 24 May 89 10:18:00 GMT References: <5563@hubcap.clemson.edu> Reply-To: thecloud@dhw68k.cts.com (Ken McLeod) Organization: Wolfskill & Dowling residence; Anaheim, CA (USA) Lines: 27 In article <5563@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael K O'Rourke) writes: >I am new to the world of inits, so i have a question. I want to create an init >that will add certain functionality to the standard save/load dialogs. I >could patch the trap call, but then the old trap wouldn't get called. What i >want to do is have everything work normally until the user pushs a special >key combination while in the save/load dialog. If they press that combination >i want my routine to get called to do something. The general strategy for patching traps is to first call GetTrapAddress, which will give you the (current) address of the trap you're patching. You save this address off somewhere in your code, and then call SetTrapAddress to the entry point of your code. Thereafter, your code does whatever it does (i.e. examine the KeyMap to see if certain combinations of keys are down, or whatever), then it "exits" via a jmp to the saved address, and the original trap gets called. The alternative method, "tail patching", involves calling the original trap yourself (via a 'jsr'), and is NOT A GOOD IDEA AT ALL (no matter how careful you are, something will break it.) Also, when you patch a trap, you'll need to make doubly sure that you save and restore the correct registers (if the call is register-based), and that the stack pointer is at the same place you found it on entry. (You need to know exactly what your code does to the stack, especially if it's not written in assembly.) -- ========== ....... ============================================= Ken McLeod :. .: UUCP: ...{spsd,zardoz,felix}!dhw68k!thecloud ========== :::.. ..::: INTERNET: thecloud@dhw68k.cts.com //// =============================================