/*------------------------------------------------------------------------
 * filename - stat87.cas
 *
 * function(s)
 *        _status87 - gets floating-point status
 *-----------------------------------------------------------------------*/

/*
 *      C/C++ Run Time Library - Version 5.0
 *
 *      Copyright (c) 1987, 1992 by Borland International
 *      All Rights Reserved.
 *
 */

#pragma inline

#include <float.h>
#ifndef _Windows
#include "emuvars.h"
#endif

/*--------------------------------------------------------------------------*

Name            _status87 - gets floating-point status

Usage           unsigned int _status87(void);

Prototype in    float.h

Description     _status87 gets the floating-point status word, which is a
                combination of the 80x87 status word and other
                conditions detected by the 80x87 exception handler.

Return value    The bits in the return value give the floating-point
                status.  See <float.h> for a complete definition of the bits
                returned by _status87.

Note:
The TC RTL controls the Denormal and Invalid exceptions, because certain
of these errors can be repaired without damage.  If a call to _control87()
attempted to mask these, then the bits are kept in memory instead of on
the coprocessor.

Denormal exceptions are never reported, as they can always be repaired.

*---------------------------------------------------------------------------*/

unsigned int _status87(void)
{
        volatile unsigned int Status;

#ifndef _Windows
#pragma warn -asm
asm     emul
#pragma warn .asm
#endif

asm     fstsw   Status
asm     fwait
asm     mov     ax, Status

#ifndef _Windows
/*
asm     or      al, byte ptr SS: _emu.control [1]
*/
asm     or      al, byte ptr SS: _emu.status2 [0]
#endif

        return _AX &
                SW_INVALID+SW_ZERODIVIDE+SW_OVERFLOW+SW_UNDERFLOW+SW_INEXACT;
}
