import sane
//-----------------------------------------------------------
// Operation code masks.
//-----------------------------------------------------------
const FOADD     = $0000     // add
const FOSUB     = $0002     // subtract
const FOMUL     = $0004     // multiply
const FODIV     = $0006     // divide
const FOCMP     = $0008     // compare, no exception from unordered
const FOCPX     = $000A     // compare, signal invalid if unordered
const FOREM     = $000C     // remainder
const FOZ2X     = $000E     // convert to extended
const FOX2Z     = $0010     // convert from extended
const FOSQRT    = $0012     // square root
const FORTI     = $0014     // round to integral value
const FOTTI     = $0016     // truncate to integral value
const FOSCALB   = $0018     // binary scale
const FOLOGB    = $001A     // binary log
const FOCLASS   = $001C     // classify
const FONEXT    = $001E     // next-after
//
const FOSETENV  = $0001     // set environment
const FOGETENV  = $0003     // get environment
const FOSETHV   = $0005     // set halt vector
const FOGETHV   = $0007     // get halt vector
const FOD2B     = $0009     // convert decimal to binary
const FOB2D     = $000B     // convert binary to decimal
const FONEG     = $000D     // negate
const FOABS     = $000F     // absolute value
const FOCPYSGN  = $0011     // copy sign
// UNDEFINED    = $0013
const FOSETXCP  = $0015     // set exception
const FOPROCENTRY = $0017   // procedure-entry
const FOPROCEXIT = $0019    // procedure-exit
const FOTESTXCP = $001B     // test exception
// UNDEFINED    = $001D
// UNDEFINED    = $001F
//-----------------------------------------------------------
// Operand format masks.
//-----------------------------------------------------------
const FFEXT     = $0000     // extended -- 80-bit float
const FFDBL     = $0100     // double   -- 64-bit float
const FFSGL     = $0200     // single   -- 32-bit float
// UNDEFINED    = $0300
const FFINT     = $0400     // integer  -- 16-bit integer
const FFCOMP    = $0500     // comp     -- 64-bit integer
// UNDEFINED    = $0600
// UNDEFINED    = $0700
//-----------------------------------------------------------
// Class.
//-----------------------------------------------------------
const FCSNAN    = $FC       // -4: signaling NAN
const FCQNAN    = $FD       // -3: quiet NAN
const FCINF     = $FE       // -2: infinite
const FCZERO    = $FF       // -1: zero
const FCNORM    = $00       //  0: normal
const FCDENORM  = $01       //  1: denormal
//-----------------------------------------------------------
// Exceptions.
//-----------------------------------------------------------
const FBINVALID = $01
const FBUFLOW   = $02
const FBOFLOW   = $04
const FBDIVZER  = $08
const FBINEXACT = $10
//-----------------------------------------------------------
// Elementary function operation code masks.
//-----------------------------------------------------------
const FOLNX     = $0000     // base-e log
const FOLOG2X   = $0002     // base-2 log
const FOLN1X    = $0004     // ln (1 + x)
const FOLOG21X  = $0006     // log2 (1 + x)
const FOEXPX    = $0008     // base-e exponential
const FOEXP2X   = $000A     // base-2 exponential
const FOEXP1X   = $000C     // exp (x) - 1
const FOEXP21X  = $000E     // exp2 (x) - 1
const FOXPWRI   = $0010     // integer exponentiation
const FOXPWRY   = $0012     // general exponentiation
const FOCOMPND  = $0014     // compound
const FOANNUIT  = $0016     // annuity
const FOATANX   = $0018     // arctangent
const FOSINX    = $001A     // sine
const FOCOSX    = $001C     // cosine
const FOTANX    = $001E     // tangent
const FORANDX   = $0020     // random
//-----------------------------------------------------------
// NaN error codes.
//-----------------------------------------------------------
const NANSQRT   = 1         // Invalid square root such as sqrt(-1).
const NANADD    = 2         // Invalid addition such as +INF - +INF.
const NANDIV    = 4         // Invalid division such as 0/0.
const NANMUL    = 8         // Invalid multiply such as 0 * INF.
const NANREM    = 9         // Invalid remainder or mod such as x REM 0.
const NANASCBIN = 17        // Attempt to convert invalid ASCII string.
const NANCOMP   = 20        // Result of converting comp NaN to floating.
const NANZERO   = 21        // Attempt to create a NaN with a zero code.
const NANTRIG   = 33        // Invalid argument to trig routine.
const NANINVTRIG = 34       // Invalid argument to inverse trig routine.
const NANLOG    = 36        // Invalid argument to log routine.
const NANPOWER  = 37        // Invalid argument to x^i or x^y routine.
const NANFINAN  = 38        // Invalid argument to financial function.
const NANINIT   = 255       // Uninitialized storage.
//-----------------------------------------------------------
// Comparison results.
//-----------------------------------------------------------
const FCMPGT    = $4040     // Greater Than
const FCMPLT    = $8080     // Less Than
const FCMPEQ    = $0002     // EQual
const FCMPUN    = $0101     // UNordered
//-----------------------------------------------------------
//
// Data types
//
struc t_single
    byte[3] s_mantissa
    byte    s_exponent
end
struc t_double
    byte[6] d_mantissa
    word    d_exponent
end
struc t_extended
    byte[8] x_mantissa
    word    x_exponent
end
struc t_bigint
    byte[8] l_int
end
//
// SANE PLASMA interface
//
struc t_sane
    word initFP
    word haltFP
    word op0FP
    word op1FP
    word op2FP
    word op3FP
    word op1ELEM
    word op2ELEM
    word op3ELEM
    word saveZP
    word restoreZP
end
end
