housen@ssc-vax.UUCP (01/27/87)
Does anyone out there have any experience in writing INITs for the Mac? Im looking for any references (i.e. books), or perhaps source code, that might serve as an example. IM doesnt seem to be of much help. Thanks, Kevin Housen Boeing Aerospace MS 3H-29 Seattle, WA 98124 (206)-657-3484
mrh@Shasta.UUCP (01/28/87)
In article <1100@ssc-vax.UUCP>, housen@ssc-vax.UUCP (Kevin Housen) writes: > > Does anyone out there have any experience in writing INITs for the Mac? > Im looking for any references (i.e. books), or perhaps source code, > that might serve as an example. IM doesnt seem to be of much help. > Kevin Housen The book "Complete Book of Macintosh Assembly Language Programming Volume II" by Dan Weston has an example of using an init to patch a ROM call. Generally I have found his two books useful and recommend having a look, even if you aren't using pure assembly language. David Gelphman BITNET address: DAVEG@SLACVM Bin #88 SLAC ARPANET address: DAVEG@SLACVM.BITNET Stanford, Calif. 94305 UUCP address: ...psuvax1!daveg%slacvm.bitnet 415-854-3300 x2538 usual disclaimer #432 applies: my employer apologies for the fact that I have access to this net.
earleh@dartvax.UUCP (02/01/87)
In article <1100@ssc-vax.UUCP>, housen@ssc-vax.UUCP (Kevin Housen) writes: > > Does anyone out there have any experience in writing INITs for the Mac? Here's a little INIT that attemps to enable the "resume" box in the good old bomb box. Whether this is a good idea or not may be subject to debate. Perhaps it would be better if we could rely on application programmers to have their programs determine whether some form of recovery is possible in the event of a bomb box. Apparently most of them have decided to ignore the issue altogether. Anyway, some principles of writing INITs: a) End the INIT with an RTS b) Install patches to ROM routines in the system heap, or vertical-retrace tasks, or whatever you want. c) Use discretion. Don't consume big chunks of valuable heap space. d) Be careful to restore registers. The system is not so picky about a0, a1, d0, and d1, but might have a fit if you screw up the stack pointer, for instance. This is far from the flashy, glamorous INITs like StartUpDesk or JClock that make their presence known all through the computing session. However, it performs a useful service for me, and might be a good example of how to get started writing these pesky little pieces of code. ; ;resume.asm. An INIT written by Earle R. Horton. ; This INIT attempts to enable the "Resume" button in the good ; old bomb box. When calling Initdialogs, if the parameter ; passed to the toolbox routine is a pointer other than zero, ; then the resume button gets enabled, and the pointer passed ; to Initdialogs is the target of a long-jump upon pressing it. ; Calling Initdialogs is one of the first things done by a ; Macintosh application. ;INCLUDE system globals: (overkill) INCLUDE mds:library:newlib.d toolbox EQU $600 ;The following macro is for word aligned, long word values. MACRO LONG value = DC {value}>>16,{value}&$FFFF | ;Here we go! RESOURCE 'INIT' 20 'resume' 80 InitDialogs EQU $17B ;trap word for InitDialogs ExittoShell EQU $1F4 ;trap word for ExitToShell ;First, set up the patch-to-be. move.w #InitDialogs,d0 lea OldInitDialogs,a1 ;get address of toolbox InitDialogs _GetTrapAddress,toolbox move.l a0,(a1) ;put it in the patch move.w #ExittoShell,d0 lea ExitRoutine,a1 ;get address of toolbox ExittoShell _GetTrapAddress,toolbox move.l a0,(a1) ;put it in the patch ;Create the heap block. MOVE.L #HeapBlockEnd-HeapBlock,D1 MOVE.L D1,D0 ;get a system heap block as big _NewPtr,sys ;as our patch MOVE.L A0,A1 LEA HeapBlock,A0 MOVE.L D1,D0 _BlockMove ;move in the patch MOVE.W #InitDialogs,D0 ;make it the trap-table address LEA PatchInitDialogs-HeapBlock(A1),A0 _SetTrapAddress,toolbox ;Finally, do any one-shot stuff here ;Don't have any. RTS HeapBlock ;This is the patch to Initdialogs PatchInitDialogs lea ExitRoutine,a0 ;get stored address of ExittoShell move.l (a0),4(sp) ;replace caller's parameter ;with it ;the next is a long jump to the ROM address of Initdialogs DC.W $4EF9 OldInitDialogs ;address of ROM routine goes here LONG 0 ExitRoutine ;address of ROM routine goes here LONG 0 ; ;---------- HeapBlockEnd END ---------------The next is the linker command file--------------- ] /Output mds:resume /Type 'INIT' 'Earl' /Resources mds:src:resume:resume $ ##EOF## ##EOT##