[comp.sys.mac] Programming INITs

mha@batcomputer.tn.cornell.edu (Mark H. Anbinder) (01/22/89)

I've written a couple of INITs using Lightspeed Pascal, and they work
okay, but now I'm really interested in going further.  How do you write
an INIT that hangs around in memory AFTER startup?  Screen savers, and
so forth, are obviously still running in the background, paying attention
to various things.  How do I get my program to do that?  When I've tried
to put the program into a loop, it just doesn't give control to the next
INIT, and if the program doesn't loop, it just ends.

Also, anyone know if it's possible to make INITs with Microsoft's
QuickBASIC or their BASIC Compiler?


-- 
Mark H. Anbinder                                ** MHA@TCGould.tn.cornell.edu
NG33 MVR Hall, Media Services Dept.             ** THCY@CRNLVAX5.BITNET
Cornell University      H: (607) 257-7587 ********
Ithaca, NY 14853        W: (607) 255-1566 ******* Ego ipse custodies custudio

bob@accuvax.nwu.edu (Bob Hablutzel) (01/23/89)

> I've written a couple of INITs using Lightspeed Pascal, and they work
> okay, but now I'm really interested in going further.  How do you write
> an INIT that hangs around in memory AFTER startup?  Screen savers, and
> so forth, are obviously still running in the background, paying attention
> to various things.  How do I get my program to do that?  When I've tried
> to put the program into a loop, it just doesn't give control to the next
> INIT, and if the program doesn't loop, it just ends.

It takes more than just an INIT to hang around after boot time. You have to
get some code into the system heap (one way is to have the INIT load a resource
marked as SysHeap, Locked, and detach the resource from the resource file), and
have that code called periodically. The ways to do this are almost legion, but
basically consist of either VBL tasks (problem: called at interrupt time, no
memory manager calls), drivers (Problem: you have to write a driver. Not so
bad, really), trap patches (called whenever specific traps are called, usually
highly specialized INITs, and jGNEFilter routines (Problem: like all lo-mem,
this is marked for removal, and Apple specifically warns against filter procs.)

I realize that this is quite sketchy, but if you want more information, drop
me a line.

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

ech@pegasus.ATT.COM (Edward C Horvath) (01/23/89)

From article <7238@batcomputer.tn.cornell.edu>, by mha@batcomputer.tn.cornell.edu (Mark H. Anbinder):
> ...How do you write
> an INIT that hangs around in memory AFTER startup?

You have two problems: how to get your code to hang around, and how to get it
some cycles.

The first problem has two answers: install the code as System heap reasources;
at INIT time, LoadResource and DetachResource.  Make sure you supply a sysx
resource in your INIT file to let the INIT-31 process know how much to grow
the System heap.  The alternative, no longer recommended, is to decrease
BufPtr by a suitable amount and install your code between the new and old
values.

You can get your code cycles by installing it as a VBL task (which only gets
cycles, in effect, at interrupt time) or by SetTrapAddress on a commonly-used
trap (like SystemTask).  Don't tailPatch, i.e. do your thing, then call the
original SystemTask by jmp'ing to it.

Hope that helps, or at least points you in the right direction...

=Ned Horvath=

bob@accuvax.nwu.edu (Bob Hablutzel) (01/29/89)

> > ...How do you write
> > an INIT that hangs around in memory AFTER startup?

[ Stuff Deleted]

>   Make sure you supply a sysx
                           ^^^^
> resource in your INIT file to let the INIT-31 process know how much to grow
> the System heap. 

I just wanted to point out a typo in an otherwise accurate answer - the
resource type is 'sysz', not 'sysx'. 


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