Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Processes
Chapter 4 - Vertical Retrace Manager / Using the Vertical Retrace Manager


Installing a Persistent VBL Task

A persistent VBL task continues to be executed even when the Process Manager switches out the application that installed it and that application is no longer in control of the CPU. If you want to install a persistent system-based VBL task, you need to load its VBL task record into the system partition. (Slot-based VBL tasks are always persistent, no matter where you put the task record.) Listing 4-15 illustrates a simple way to load a VBL task record into the system heap.

Listing 4-15 Installing a persistent VBL task

FUNCTION InstallPersistentVBL (VAR theVBLRec: VBLTask): OSErr;
TYPE
   ProcPtrPtr = ^ProcPtr;                       {a pointer to a ProcPtr}
CONST
   kJMPInstr = $4EF9;                           {this is an absolute JMP}
   kJMPSize = 6;                                {size of an absolute JMP}
VAR
   myErr:      OSErr;
   SysHeapPtr: Ptr;
   tempPtr:    Ptr;
BEGIN
   SysHeapPtr := NewPtrSys(kJMPSize);           {get a block in system heap}
   myErr := MemError;
   IF myErr <> noErr THEN                       {make sure we have the block}
      BEGIN
         InstallPersistentVBL := myErr;
         Exit(InstallPersistentVBL);
      END;
   IntegerPtr(SysHeapPtr)^ := kJMPInstr;        {move in the JMP instruction}
   tempPtr := Ptr(ORD(SysHeapPtr)+SizeOf(Integer));
   ProcPtrPtr(tempPtr)^ := theVBLRec.vblAddr;   {move in the JMP address}
   theVBLRec.vblAddr := ProcPtr(SysHeapPtr);    {point record at sys heap}
   InstallPersistentVBL := VInstall(@theVBLRec);{install the VBL task record}
END;
The InstallPersistentVBL function defined in Listing 4-15 allocates enough bytes in the system heap to hold an integer that encodes an assembly-language JMP instruction together with the absolute address to which to jump. It loads into that space the assembly-language instruction and the address of the original VBL task, which is extracted from the VBL task record passed to it as a parameter. Then InstallPersistentVBL replaces the address of the original VBL task in that record with the address of the block in the system heap. The net result is that the vblAddr field of the VBL task record now contains an address in the system partition, making the VBL task persistent.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
17 JUN 1996