[comp.sys.mac.programmer] INIT's in LSC

poleary@bonnie.ics.uci.edu (Petey O'Leary) (04/01/89)

I've been trying for some time to write an INIT in LightSpeed C that
will stay resident after startup (it patches a trap).  Writing an INIT
is easy enough in LSC, writing a memory resident (what else do you call
it?) INIT is also easy enough IF you use lots of inline assembler and
use only one monolithic routine.  But what I want to do is take a LSC
program (any LSC program, for that matter) and turn it into an INIT
without having to re-write it in assembler.

Inside Mac says that when INIT 31 calls an INIT file, it places a handle
to the INIT resource in A0 before the call.  So all I have to do is call
DetachResource on it and the INIT resource will stay in memory, then I
just make sure to setup A4 correctly and the thing should work.  Nope.
I think I have a pretty good grasp of what is going on and what needs
to be done but I guess I am overlooking something.

Any help would be appreciated.  Thanks in advance.

--
Peter O'Leary.
"Speak of the Devil and the Devil may speak of you." - W. Hussey

bob@accuvax.nwu.edu (Bob Hablutzel) (04/03/89)

[ Question about writing an INIT in LSC ]

You didn't mention what kinds of problem you're having. Is the machine:

Crashing?  Make sure that the INIT is locked, and in the system heap. Anything
           else won't work right.

Ignoring the INIT?  Make sure that you've given some way for the INIT to be
	            called.

Doing something else? Post the problems more specifically, and I'll try to help.


Bob Hablutzel	Wildwood Software	BOB@NUACC.ACNS.NWU.EDU

MAC.ROMOS@applelink.apple.com (Ian Hendry) (04/12/89)

>Inside Mac says that when INIT 31 calls an INIT file, it places a handle
>to the INIT resource in A0 before the call.  So all I have to do is call
>DetachResource on it and the INIT resource will stay in memory, then I
>just make sure to setup A4 correctly and the thing should work.  Nope.
>I think I have a pretty good grasp of what is going on and what needs
>to be done but I guess I am overlooking something.

I am pretty sure that INIT 31 has its own heap into which the inits are 
loaded.  Detaching your resource leaves it in a heap that is dumped after 
the INIT31 process is finished.  You need to have you code in the system 
heap to stay around. 
Try setting the system heap flag.

Hope it helps....




Ian Hendry
MAC.ROMOS@applelink.apple.com
Make sure my name is in the subject of any Email, or post replies to 
network.
TE: 408-974-4737

Disclaimer:  It was all HIS idea anyway!  Nothing I say reflects anything 
my employer means... or anything I mean for that matter.

MAC.ROMOS@applelink.apple.com (Ian Hendry) (04/12/89)

>>Inside Mac says that when INIT 31 calls an INIT file, it places a handle
>>to the INIT resource in A0 before the call.  So all I have to do is call
>>DetachResource on it and the INIT resource will stay in memory, then I
>>just make sure to setup A4 correctly and the thing should work.  Nope.
>>I think I have a pretty good grasp of what is going on and what needs
>>to be done but I guess I am overlooking something.
>
>I am pretty sure that INIT 31 has its own heap into which the inits are 
>loaded.  Detaching your resource leaves it in a heap that is dumped after 
>the INIT31 process is finished.  You need to have you code in the system 
>heap to stay around. 
>Try setting the system heap flag.

After posting this I decided to check it out (a 4byte INIT with $A9FF 
$4E75, _Debugger Rts) and I can say what I posted above is correct.  
INIT31 does create its own heap into which resources are loaded and that 
setting the system heap flag in your INIT resource (to set the flag, use 
the resource attrs in the "set project type" dialog of THINKC or ResEdit 
later) will cause you to be loaded into the system heap.  At that point, 
detaching should be all you need to stick around.

Let me know if you still have a problem... (you may already be doing all
this and have another problem... hope not :-)  )

Ian Hendry
MAC.ROMOS@applelink.apple.com
Make sure my name is in the subject of any Email, or post replies to 
network.
TE: 408-974-4737

Disclaimer:  It was all HIS idea anyway!  Nothing I say reflects anything 
my employer means... or anything I mean for that matter.