[comp.sys.amiga] mini SetFunction

bryce@COGSCI.BERKELEY.EDU (Bryce Nesbitt) (06/24/87)

The SetFunction() function exists to allow a library function to be replaced
with other code.  DropShadow is a program that operates this way; it steals
certain routines to find out when and where to draw window Shadows.  "MWB"
(Multi-WorkBench) is another.

In order to REMOVE a Set Function two conditions must be verified:

1> You only remove the function that you added.
2> And nothing else has SetFunction()'ed the same place since you did.
   (That program may chain down to your program.  If your program is gone
   *poof!* you are staring at a flashing orange box.)

Here's a skeletal code sample that I copy to PUBLIC memory, then point to
with SetFunction():

		cnop	0,4		;Start at LONG alignment
Start:		bra.s	thecode
		dc.w	$4AFC		;Magic Cookie (ILLEGAL instruction)
size:		dc.w	123		;Size of the patch
oldvector:	dc.l	0		;Where the function used to point
IDString:	dc.b	'Groingk!',0
		cnop	0,2
thecode 	...
		...
		rts

If the added function does not need it's own process or task, the startup
code can go away after leaving this in PUBLIC memory.  The code is the
"Daemon", and may be very small.  The installer is the "User Interface" and
can be fancy, wiz-bang big without affecting free memory.

When the "User Interface" pops up again it can check to see if it is
already installed.  If not it can add itself.  If so it can give the
user the option on leaving it, removing it, or twiddling parameters.

There are *lots* of advantages to this, and only two, very minor,
possible hassles:

1> There is no such thing as a SetFunction() lock (yet??).
   Something ELSE may SetFunction() the same place.  This will always
   be a potential problem.  If you wanted single tasking you would have
   bought a Mac or Atari ST!
   You code can't be safely removed until the offending program
   reconsiders.  The user would have to quit in the reverse order
   that the SetFunctions where made.

2> A name conflict on the ID String.  A very remote possibility, but it
   could happen in *your* neighborhood.  This is why all names should be
   registered with Commmodore  [ 1/2 :-) ].

---------
	Ack!  (NAK,EOT,SOH)
|\ /|  .
{o O} . bryce@cogsci.berkeley.EDU -or- ucbvax!cogsci!bryce
( " ) 
  U	Single tasking?  Just say *NO!*