🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #14293

Re: INITs, help...

#14293
From: earleh
Date: Sun, 01 Feb 1987 05:41
97 lines
4025 bytes
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##
Technical Details
Message-ID: <5623@dartvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bellcore!faline!ulysses!ucbvax!decvax!dartvax!earleh
References: <1100@ssc-vax.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bellcore!faline!ulysses!ucbvax!decvax!dartvax!earleh
From: earleh@dartvax.UUCP
Newsgroups: comp.sys.mac
Subject: Re: INITs, help...
Message-ID: <5623@dartvax.UUCP>
Date: Sun, 1-Feb-87 00:41:30 EST
Article-I.D.: dartvax.5623
Posted: Sun Feb  1 00:41:30 1987
Date-Received: Tue, 3-Feb-87 02:02:33 EST
References: <1100@ssc-vax.UUCP>
Organization: Society for the Prevention of Cruelty to Graduate Students
Lines: 97
Keywords: INIT resources
Summary: Here is one.