Src/MicrosecondTrapPresent.c

/*                              MicrosecondTrapPresent.c                        */
/*
 * MicrosecondTrapPresent.c
 * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
 */
#include <OSUtils.h>
#include "MicrosecondTrap.h"
 
static Boolean              TrapAvailable(
        short                   theTrap
    );
 
Boolean
MicrosecondTrapPresent(void)
{
        return (TrapAvailable(_Microseconds));
}
 
/*
 * TrapAvailable (see Inside Mac VI 3-8)
 */
#define NumToolboxTraps() (                             \
        (NGetTrapAddress(_InitGraf, ToolTrap)           \
                == NGetTrapAddress(0xAA6E, ToolTrap))   \
            ? 0x200 : 0x400                             \
    )
#define GetTrapType(theTrap) (                          \
        (((theTrap) & 0x800) != 0) ? ToolTrap : OSTrap  \
    )
 
static Boolean
TrapAvailable(
        short                   theTrap
    )
{
        TrapType                trapType;
        
        trapType = GetTrapType(theTrap);
        if (trapType == ToolTrap) {
            theTrap &= 0x07FF;
            if (theTrap >= NumToolboxTraps())
                theTrap = _Unimplemented;
        }
        return (
            NGetTrapAddress(theTrap, trapType)
            != NGetTrapAddress(_Unimplemented, ToolTrap)
        );
}