Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!linac!midway!news From: martin@cs.uchicago.edu (Charles Martin) Newsgroups: comp.sys.mac.programmer Subject: Re: inits & pascal & variables Message-ID: <1991Jan31.215826.15554@midway.uchicago.edu> Date: 31 Jan 91 21:58:26 GMT References: <1652@n-kulcs.cs.kuleuven.ac.be> Sender: news@midway.uchicago.edu (News Administrator) Reply-To: martin@cs.uchicago.edu (Charles Martin) Organization: University of Chicago Lines: 45 In-Reply-To: kpottie@icarus.cs.kuleuven.ac.be (Pottie Karl) kpottie@icarus (Pottie Karl) writes: >I recently found this file for writing simple inits in Pascal. It worked >fine till I tried to use variables How odd, to see one's own code reappear after many months... that bit of code I wrote before is buggy. Basically, the offsets were incorrect, which ended up overwriting the instructions that put the address of the code into A0 and ToolScratch (which you wouldn't miss in Pascal). Probably also overwrote the jump to main, which is why you crash as soon as you do anything exciting. Here's another try. Note: this is meant to be used with THINK Pascal code resources. THINK Pascal adds a default header that we will mangle to make our head patch. All we do is push the real trap address on the stack before entering our code segment, so the RTS puts us in the real trap with the same arguments. Modulo error checking, N...TrapAddress, and etc., here is the installer: unit install; interface procedure main; implementation const trap = <...>; type code_hdl = ^code_ptr; code_ptr = ^code_t; code_t = array [0..0] of integer; procedure main; var code: code_hdl; addr: longint; begin code := code_hdl (Get1Resource ('CODE',128)); DetachResource (Handle(code)); addr := GetTrapAddress (trap); code^^ [5] := $2F3C; { MOVE.L #,-(A7) } code^^ [6] := HiWord (addr); code^^ [7] := LoWord (addr); SetTrapAddress (longint(code^)+10, trap) end; end. Hope this helps! Charles Martin // martin@cs.uchicago.edu