Gestalt Manager Calls
Gestalt Manager Routines
(Contributions to the Inline 68K code by Lawrence D'Oliveiro and Marco Piovanelli).
FUNCTION Gestalt (selector: OSType; VAR response: LongInt): OSErr;
Available since System 6.0.4.
Trap Macro
_Gestalt (0xA1AD); (old ?: _GestaltDispatch 0xA0AD)
Registers on entry D0: selector code
Registers on exit A0: response
D0: result code
Result codes
noErr 0 No error
gestaltUnknownErr -5550 Could not obtain the response
gestaltUndefSelectorErr -5551 Undefined selector
Inline 68K code
$225F, { move.l (sp)+, a1 }
$201F, { move.l (sp)+, d0 }
$A1AD, { _Gestalt }
$2288, { move.l a0, (a1) }
$3E80; { move.w d0, (sp) }
FUNCTION NewGestalt (selector: OSType; selectorfunction: ProcPtr): OSErr
Available since System 6.0.4.
Trap Macro
_NewGestalt (0xA3AD)
Registers on entry A0: address of new selector function
D0: selector code
Registers on exit D0: result code
Result codes
noErr 0 No error
memFullErr -108 Ran out of memory
gestaltDupSelectorErr -5552 Selector already exists
gestaltLocationErr -5553 Function not in system heap
Inline 68K code
$205F, { move.l (sp)+, a0 }
$201F, { move.l (sp)+, d0 }
$A3AD, { _NewGestalt }
$3E80; { move.w d0, (sp) }
FUNCTION ReplaceGestalt (selector: OSType; selectorfunction: ProcPtr;
VAR oldGestaltFunction: ProcPtr): OSErr;
Available since System 6.0.4.
Trap Macro
_ReplaceGestalt (0xA5AD)
Registers on entry A0: address of new selector function
D0: selector code
Registers on exit A0: address of old selector function
D0: result code
Result codes
noErr 0 No error
gestaltUndefSelectorErr -5551 Undefined selector
gestaltLocationErr -5553 Function not in system heap
Inline 68K code
$225F, { move.l (sp)+, a1 }
$205F, { move.l (sp)+, a0 }
$201F, { move.l (sp)+, d0 }
$A5AD, { _ReplaceGestalt }
$2288, { move.l a0, (a1) }
$3E80; { move.w d0, (sp) }
Gestalt Value Routines
Please note the GestaltValue routines can be invoked through a library,
but since System 7.5 the GestaltValue routines are also part of the OS.
The GestaltValue routines are stack based and don't use registers.
The GestaltValue library first checks to see if trap 0xABF1 is implemented
(System 7.5 and later). If trap 0xABF1 is implemented, all calls to the
library are routed to this trap, otherwise the library uses embedded code.
Several Apple System selectors use the GestaltValueDispatch A-trap to
install the response value starting with System 7.5.
WARNING:
The GestaltValue library distributed originally checks for the wrong trap
(_ThreadDispatch, 0xABF2). Make sure your software doesn't crash when this
trap is installed.
(Most info about the GestaltValue functions was provided by
Marco Piovanelli and Dave Radcliffe).
FUNCTION NewGestaltValue (selector: OSType; newValue: LongInt): OSErr;
Available as library and since System 7.5.
Trap Macro Selector
_GestaltValueDispatch (0xABF1) 0x0401
Result codes
noErr 0 No error
unimpErr -4 Unimplemented core routine
memFullErr -108 Ran out of memory
(and other memory errors)
gestaltDupSelectorErr -5552 Selector already exists
Inline 68K code
$303C, $0401, $ABF1;
FUNCTION ReplaceGestaltValue (selector: OSType;
replacementValue: LongInt): OSErr;
Available as library and since System 7.5.
Trap Macro Selector
_GestaltValueDispatch (0xABF1) 0x0402
Result codes
noErr 0 No error
unimpErr -4 Unimplemented core routine
memFullErr -108 Ran out of memory
(and other memory errors)
gestaltUndefSelectorErr -5551 Undefined selector
Inline 68 K code
$303C, $0402, $ABF1;
FUNCTION DeleteGestaltValue (selector: OSType): OSErr; and
FUNCTION Delete (selector: OSType): OSErr;
Available as library and since System 7.5.
Trap Macro Selector
_GestaltValueDispatch (0xABF1) 0x0203
Result codes
noErr 0 No error
unimpErr -4 Unimplemented core routine
gestaltUndefSelectorErr -5551 Undefined selector
Inline 68K code
$303C, $0203, $ABF1;
Undocumented Gestalt Manager Routines
FUNCTION? GetGestaltProcPtr? (selector?: OSType;
var selectorfunction: ProcPtr): OSErr;?
Trap Macro
_GetGestaltProcPtr (0xA7AD)
Registers on entry D0: selector code?
Registers on exit ??: address of selector function
Result codes
noErr 0 No error
???
NOTE:
Found in the MPW Traps Interface file on 'Bookmark CD 14'.
Available since System 6.0.4 but code will always return error -50
(paramErr). (Lawrence D'Oliveiro, Rene Ros)
FUNCTION SetGestaltValue (selector: OSType; newValue: LongInt): OSErr;
Available since System 7.5?
Trap Macro Selector
_GestaltValueDispatch (0xABF1) 0x0404
Result codes
noErr 0 No error
???
extern pascal OSErr GetGestaltSelectors(UInt32 theCount,
UInt32 skipCount,
GestaltIterator *theItems);
Available starting with Copland?
Trap Macro Selector
??? ???
Result codes
noErr 0 No error
???
struct GestaltIterator {
UInt32 totalItems;
UInt32 validItems;
UInt32 iterationKey;
OSType theItems[1];
};
typedef struct GestaltIterator GestaltIterator;
Custom Routines
This section lists functions which expand some Gestalt functions using inline assemly code.
FUNCTION GestaltSelectorZero (Selector: OSType): LongInt;
{returns the value of the specified Gestalt selector,}
{or zero if unknown.}
Inline 68K code
$201F, { move.l (sp)+, d0 }
$A1AD, { _Gestalt }
$6702, { beq.s @2 }
$91C8, { sub.l a0, a0 }
$2E88; { @2: move.l a0, (sp) }
Description:
With all the selectors that are supposed to return non-zero values
if installed, it may be helpful to have an utility routine that
returns a zero value (instead of an error) if a selector isn't
installed. It's short and sweet because it makes a direct call to
the _Gestalt trap; of course this means you can't use it on systems
earlier than 6.0.4. (Contributed by Lawrence D'Oliveiro)
FUNCTION GestaltBitTest(Selector: OSType; BitNr: Integer): Boolean;
Inline 68K code
$321F, { move.w (sp)+, d1 }
$201F, { move.l (sp)+, d0 }
$A1AD, { _Gestalt }
$6702, { beq.s @2 }
$91C8, { sub.l a0, a0 }
$2008, { @2: move.l a0, d0 }
$0300, { btst d1, d0 }
$56C0, { sne.b d0 }
$4400, { neg.b d0 }
$1E80; { move.b d0, (sp) }
Description
The GestaltBitTest is a piece of inline assembly code which tests if
the specified bit is set in the value from the specified Gestalt
selector (false if the Gestalt call returns an error). Example:
GestaltBitTest(gestaltAppleEventsAttr, gestaltAppleEventsPresent)
(Contributed by Lawrence D'Oliveiro)
FUNCTION CallGestaltDEF (selector: OSType;
var result: LongInt;
aRoutine: ProcPtr): OSErr;
inline $205F, $4E90;
{ move.l (sp)+, a0 }
{ jsr (a0) }
Description
Suppose you have just loaded an GDEF resource, or replaced one and
keep the original around and store a pointer to it somewhere
private. Suppose next, you want to call it to obtain a response
without using yet another selector.
That's what the this function is useful for. Just pass it the usual
selector and result parameters but also a pointer to the GDEF
(Lock it if it's a relocatable block).