; File:  M16.SANE
;
;
; Copyright Apple Computer, Inc. 1986-90
; All Rights Reserved
;
;
 MACRO
&lab _SANEBootInit
&lab ldx #$010A
     jsl $E10000
 MEND
 MACRO
&lab _SANEStartUp
&lab ldx #$020A
     jsl $E10000
 MEND
 MACRO
&lab _SANEShutDown
&lab ldx #$030A
     jsl $E10000
 MEND
 MACRO
&lab _SANEVersion
&lab ldx #$040A
     jsl $E10000
 MEND
 MACRO
&lab _SANEReset
&lab ldx #$050A
     jsl $E10000
 MEND
 MACRO
&lab _SANEStatus
&lab ldx #$060A
     jsl $E10000
 MEND
 MACRO
&lab _SANEFP816
&lab ldx #$090A
     jsl $E10000
 MEND
 MACRO
&lab _SANEDecStr816
&lab ldx #$0A0A
     jsl $E10000
 MEND
 MACRO
&lab _SANEElems816
&lab ldx #$0B0A
     jsl $E10000
 MEND
;-----------------------------------------------------------
; Addition.
;-----------------------------------------------------------
        MACRO
&lab    FADDX
&lab    FOPRF   FFEXT+FOADD
        MEND

        MACRO
&lab    FADDD
&lab    FOPRF   FFDBL+FOADD
        MEND

        MACRO
&lab    FADDS
&lab    FOPRF   FFSGL+FOADD
        MEND

        MACRO
&lab    FADDC
&lab    FOPRF   FFCOMP+FOADD
        MEND

        MACRO
&lab    FADDI
&lab    FOPRF   FFINT+FOADD
        MEND

        MACRO
&lab    FADDL
&lab    FOPRF   FFLNG+FOADD
        MEND

;-----------------------------------------------------------
; Subtraction.
;-----------------------------------------------------------
        MACRO
&lab    FSUBX
&lab    FOPRF   FFEXT+FOSUB
        MEND

        MACRO
&lab    FSUBD
&lab    FOPRF   FFDBL+FOSUB
        MEND

        MACRO
&lab    FSUBS
&lab    FOPRF   FFSGL+FOSUB
        MEND

        MACRO
&lab    FSUBC
&lab    FOPRF   FFCOMP+FOSUB
        MEND

        MACRO
&lab    FSUBI
&lab    FOPRF   FFINT+FOSUB
        MEND

        MACRO
&lab    FSUBL
&lab    FOPRF   FFLNG+FOSUB
        MEND

;-----------------------------------------------------------
; Multiplication.
;-----------------------------------------------------------
        MACRO
&lab    FMULX
&lab    FOPRF   FFEXT+FOMUL
        MEND

        MACRO
&lab    FMULD
&lab    FOPRF   FFDBL+FOMUL
        MEND

        MACRO
&lab    FMULS
&lab    FOPRF   FFSGL+FOMUL
        MEND

        MACRO
&lab    FMULC
&lab    FOPRF   FFCOMP+FOMUL
        MEND

        MACRO
&lab    FMULI
&lab    FOPRF   FFINT+FOMUL
        MEND

        MACRO
&lab    FMULL
&lab    FOPRF   FFLNG+FOMUL
        MEND

;-----------------------------------------------------------
; Division.
;-----------------------------------------------------------
        MACRO
&lab    FDIVX
&lab    FOPRF   FFEXT+FODIV
        MEND

        MACRO
&lab    FDIVD
&lab    FOPRF   FFDBL+FODIV
        MEND

        MACRO
&lab    FDIVS
&lab    FOPRF   FFSGL+FODIV
        MEND

        MACRO
&lab    FDIVC
&lab    FOPRF   FFCOMP+FODIV
        MEND

        MACRO
&lab    FDIVI
&lab    FOPRF   FFINT+FODIV
        MEND

        MACRO
&lab    FDIVL
&lab    FOPRF   FFLNG+FODIV
        MEND

;-----------------------------------------------------------
; Square root.
;-----------------------------------------------------------
        MACRO
&lab    FSQRTX
&lab    FOPRF  FOSQRT
        MEND

;-----------------------------------------------------------
; Round to integer, according to the current rounding mode.
;-----------------------------------------------------------
        MACRO
&lab    FRINTX
&lab    FOPRF  FORTI
        MEND

;-----------------------------------------------------------
; Truncate to integer, using round toward zero.
;-----------------------------------------------------------
        MACRO
&lab    FTINTX
&lab    FOPRF   FOTTI
        MEND

;-----------------------------------------------------------
; Remainder.  
;-----------------------------------------------------------
        MACRO
&lab    FREMX
&lab    FOPRF   FFEXT+FOREM
        MEND

        MACRO
&lab    FREMD
&lab    FOPRF   FFDBL+FOREM
        MEND

        MACRO
&lab    FREMS
&lab    FOPRF   FFSGL+FOREM
        MEND

        MACRO
&lab    FREMC
&lab    FOPRF   FFCOMP+FOREM
        MEND

        MACRO
&lab    FREMI
&lab    FOPRF   FFINT+FOREM
        MEND

        MACRO
&lab    FREML
&lab    FOPRF   FFLNG+FOREM
        MEND

;-----------------------------------------------------------
; Logb. 
;-----------------------------------------------------------
        MACRO
&lab    FLOGBX
&lab    FOPRF   FOLOGB
        MEND

;-----------------------------------------------------------
; Scalb.  
;-----------------------------------------------------------
        MACRO
&lab    FSCALBX
&lab    FOPRF   FOSCALB
        MEND

;-----------------------------------------------------------
; Copy-sign.
;-----------------------------------------------------------
        MACRO
&lab    FCPYSGNX
&lab    FOPRF   FFEXT+FOCPYSGN
        MEND

        MACRO
&lab    FCPYSGND
&lab    FOPRF   FFDBL+FOCPYSGN
        MEND

        MACRO
&lab    FCPYSGNS
&lab    FOPRF   FFSGL+FOCPYSGN
        MEND

        MACRO
&lab    FCPYSGNC
&lab    FOPRF   FFCOMP+FOCPYSGN
        MEND

        MACRO
&lab    FCPYSGNI
&lab    FOPRF   FFINT+FOCPYSGN
        MEND

        MACRO
&lab    FCPYSGNL
&lab    FOPRF   FFLNG+FOCPYSGN
        MEND

;-----------------------------------------------------------
; Negate.
;-----------------------------------------------------------
        MACRO
&lab    FNEGX
&lab    FOPRF   FONEG
        MEND

;-----------------------------------------------------------
; Absolute value.
;-----------------------------------------------------------
        MACRO
&lab    FABSX
&lab    FOPRF   FOABS
        MEND

;-----------------------------------------------------------
; Next-after.  NOTE:  both operands are of the
; the same format, as specified by the usual suffix.
;-----------------------------------------------------------
        MACRO
&lab    FNEXTS
&lab    FOPRF   FFSGL+FONEXT
        MEND

        MACRO
&lab    FNEXTD
&lab    FOPRF   FFDBL+FONEXT
        MEND

        MACRO
&lab    FNEXTX
&lab    FOPRF   FFEXT+FONEXT
        MEND

;-----------------------------------------------------------
; Conversion to extended.
;-----------------------------------------------------------
        MACRO
&lab    FX2X
&lab    FOPRF   FFEXT+FOZ2X
        MEND

        MACRO
&lab    FD2X
&lab    FOPRF   FFDBL+FOZ2X
        MEND

        MACRO
&lab    FS2X
&lab    FOPRF   FFSGL+FOZ2X
        MEND

        MACRO                           ; 16-bit integer, by address
&lab    FI2X
&lab    FOPRF   FFINT+FOZ2X
        MEND

        MACRO                           ; 32-bit integer, by address
&lab    FL2X
&lab    FOPRF   FFLNG+FOZ2X
        MEND

        MACRO
&lab    FC2X
&lab    FOPRF   FFCOMP+FOZ2X
        MEND

;-----------------------------------------------------------
; Conversion from extended.
;-----------------------------------------------------------
        MACRO
&lab    FX2D
&lab    FOPRF   FFDBL+FOX2Z
        MEND

        MACRO
&lab    FX2S
&lab    FOPRF   FFSGL+FOX2Z
        MEND

        MACRO
&lab    FX2I
&lab    FOPRF   FFINT+FOX2Z
        MEND

        MACRO
&lab    FX2L
&lab    FOPRF   FFLNG+FOX2Z
        MEND

        MACRO
&lab    FX2C
&lab    FOPRF   FFCOMP+FOX2Z
        MEND

;-----------------------------------------------------------
; Binary to decimal conversion.
;-----------------------------------------------------------
        MACRO
&lab    FX2DEC
&lab    FOPRF   FFEXT+FOB2D
        MEND

        MACRO
&lab    FD2DEC
&lab    FOPRF   FFDBL+FOB2D
        MEND

        MACRO
&lab    FS2DEC
&lab    FOPRF   FFSGL+FOB2D
        MEND

        MACRO
&lab    FC2DEC
&lab    FOPRF   FFCOMP+FOB2D
        MEND

        MACRO
&lab    FI2DEC
&lab    FOPRF   FFINT+FOB2D
        MEND

        MACRO
&lab    FL2DEC
&lab    FOPRF   FFLNG+FOB2D
        MEND

;-----------------------------------------------------------
; Decimal to binary conversion.
;-----------------------------------------------------------
        MACRO
&lab    FDEC2X
&lab    FOPRF   FFEXT+FOD2B
        MEND

        MACRO
&lab    FDEC2D
&lab    FOPRF   FFDBL+FOD2B
        MEND

        MACRO
&lab    FDEC2S
&lab    FOPRF   FFSGL+FOD2B
        MEND

        MACRO
&lab    FDEC2C
&lab    FOPRF   FFCOMP+FOD2B
        MEND

        MACRO
&lab    FDEC2I
&lab    FOPRF   FFINT+FOD2B
        MEND

        MACRO
&lab    FDEC2L
&lab    FOPRF   FFLNG+FOD2B
        MEND

;-----------------------------------------------------------
; Compare, not signaling invalid on unordered.
;-----------------------------------------------------------
        MACRO
&lab    FCMPX
&lab    FOPRF   FFEXT+FOCMP
        MEND

        MACRO
&lab    FCMPD
&lab    FOPRF   FFDBL+FOCMP
        MEND

        MACRO
&lab    FCMPS
&lab    FOPRF   FFSGL+FOCMP
        MEND

        MACRO
&lab    FCMPC
&lab    FOPRF   FFCOMP+FOCMP
        MEND

        MACRO
&lab    FCMPI
&lab    FOPRF   FFINT+FOCMP
        MEND

        MACRO
&lab    FCMPL
&lab    FOPRF   FFLNG+FOCMP
        MEND

;-----------------------------------------------------------
; Compare, signaling invalid on unordered.
;-----------------------------------------------------------
        MACRO
&lab    FCPXX
&lab    FOPRF   FFEXT+FOCPX
        MEND

        MACRO
&lab    FCPXD
&lab    FOPRF   FFDBL+FOCPX
        MEND

        MACRO
&lab    FCPXS
&lab    FOPRF   FFSGL+FOCPX
        MEND

        MACRO
&lab    FCPXC
&lab    FOPRF   FFCOMP+FOCPX
        MEND
       
        MACRO
&lab    FCPXI
&lab    FOPRF   FFINT+FOCPX
        MEND

        MACRO
&lab    FCPXL
&lab    FOPRF   FFLNG+FOCPX
        MEND

;-----------------------------------------------------------
; The following macros define a set of so-called floating
; branches.  They presume that the appropriate compare 
; operation, macro FCMPz or FCPXz, precedes.
;----------------------------------------------------------
        MACRO                           ; branch equal
&lab    FBEQ    &N1
&lab    BEQ     &N1
        MEND
       
        MACRO                           ; branch less
&lab    FBLT    &N1
&lab    BMI     &N1
        MEND
       
        MACRO                           ; branch less or equal
&lab    FBLE    &N1
&lab    BMI     &N1
        BEQ     &N1
        MEND
       
        MACRO                           ; branch greater
&lab    FBGT    &N1
&lab    BVS     &N1
        MEND
       
        MACRO                           ; branch greater or equal
&lab    FBGE    &N1
&lab    BVS     &N1
        BEQ     &N1
        MEND
       
        MACRO                           ; branch less or unordered
&lab    FBULT   &N1
&lab    BMI     &N1
        BVS     *+4
        BNE     &N1
        MEND
       
        MACRO                           ; branch unordered, less, or equal
&lab    FBULE   &N1
&lab    BMI     &N1
        BEQ     &N1
        BVC     &N1
        MEND
       
        MACRO                           ; branch unordered or greater
&lab    FBUGT   &N1
&lab    BVS     &N1
        BMI     *+4
        BNE     &N1
        MEND
       
        MACRO                           ; branch unordered, greater, or equal
&lab    FBUGE   &N1
&lab    BVS     &N1
        BEQ     &N1
        BPL     &N1
        MEND
       
        MACRO                           ; branch unordered
&lab    FBU     &N1
&lab    BVS     *+6
        BMI     *+4
        BNE     &N1 
        MEND
       
        MACRO                           ; branch ordered
&lab    FBO     &N1
&lab    BMI     &N1
        BVS     &N1
        BEQ     &N1
        MEND
       
        MACRO                           ; branch not equal
&lab    FBNE    &N1
&lab    BMI     &N1
        BVS     &N1
        BNE     &N1
        MEND
       
        MACRO                           ; branch unordered or equal
&lab    FBUE    &N1
&lab    BEQ     &N1
        BMI     *+4
        BVC     &N1
        MEND
       
        MACRO                           ; branch less or greater
&lab    FBLG    &N1
&lab    BMI     &N1
        BVS     &N1
        MEND

        MACRO
&lab    FCLASSS
&lab    FOPRF   FFSGL+FOCLASS
        MEND

        MACRO
&lab    FCLASSD
&lab    FOPRF   FFDBL+FOCLASS
        MEND

        MACRO
&lab    FCLASSX
&lab    FOPRF   FFEXT+FOCLASS
        MEND

        MACRO
&lab    FCLASSC
&lab    FOPRF   FFCOMP+FOCLASS
        MEND

        MACRO
&lab    FCLASSI
&lab    FOPRF   FFINT+FOCLASS
        MEND

        MACRO
&lab    FCLASSL
&lab    FOPRF   FFLNG+FOCLASS
        MEND

;-----------------------------------------------------------
; The following macros provide branches based on the 
; the result of a FCLASSz macro.
;-----------------------------------------------------------
        MACRO                           ; branch signaling NaN
&lab    FBSNAN  &N1
&lab    TXA
        ASL     A
        CMP     #2*FCSNAN
        BEQ     &N1
        MEND

        MACRO                           ; branch quiet NaN
&lab    FBQNAN  &N1
&lab    TXA
        ASL     A
        CMP     #2*FCQNAN
        BEQ     &N1
        MEND

        MACRO                           ; branch infinite
&lab    FBINF   &N1
&lab    TXA
        ASL     A
        CMP     #2*FCINF
        BEQ     &N1
        MEND

        MACRO                           ; branch zero
&lab    FBZERO  &N1
&lab    TXA
        ASL     A
        CMP     #2*FCZERO
        BEQ     &N1
        MEND

        MACRO                           ; branch normal
&lab    FBNORM  &N1
&lab    TXA
        ASL     A
        BEQ     &N1
        MEND

        MACRO                           ; branch denormal
&lab    FBDENORM &N1
&lab    TXA
        ASL     A
        CMP     #2*FCDENORM
        BEQ     &N1
        MEND

        MACRO                           ; branch non-zero num (norm or denorm)
&lab    FBNZENUM &N1
&lab    TXA
        XBA
        ASL     A
        BCC     &N1
        MEND
       
        MACRO                           ; branch number (zero, norm, or denorm)
&lab    FBNUM   &N1
&lab    TXA
        INC     A
        XBA
        ASL     A
        BCC     &N1
        MEND
       
        MACRO                           ; branch minus sign
&lab    FBMINUS &N1
&lab    BMI     &N1
        MEND

        MACRO                           ; branch plus sign
&lab    FBPLUS  &N1
&lab    BPL     &N1
        MEND

;-----------------------------------------------------------
; Get and set environment.
;-----------------------------------------------------------
        MACRO
&lab    FGETENV
&lab    FOPRF   FOGETENV
        MEND

        MACRO
&lab    FSETENV
&lab    FOPRF   FOSETENV
        MEND

;-----------------------------------------------------------
; Test and set exception. 
;-----------------------------------------------------------
        MACRO
&lab    FTESTXCP
&lab    FOPRF   FOTESTXCP
        MEND

        MACRO
&lab    FSETXCP
&lab    FOPRF   FOSETXCP
        MEND

;----------------------------------------------------------
; Procedure entry and exit.
;----------------------------------------------------------
        MACRO
&lab    FPROCENTRY
&lab    FOPRF   FOPROCENTRY
        MEND

        MACRO
&lab    FPROCEXIT
&lab    FOPRF   FOPROCEXIT
        MEND

;-----------------------------------------------------------
; Get and set halt vector.
;-----------------------------------------------------------
        MACRO
&lab    FGETHV
&lab    FOPRF   FOGETHV
        MEND

        MACRO
&lab    FSETHV
&lab    FOPRF   FOSETHV
        MEND
       
;-----------------------------------------------------------
; Elementary function macros.
;-----------------------------------------------------------
        MACRO                           ; natural (base-e) log
&lab    FLNX
&lab    FOPRE   FOLNX
        MEND

        MACRO                           ; base-2 log
&lab    FLOG2X
&lab    FOPRE   FOLOG2X
        MEND

        MACRO                           ; ln (1 + x)
&lab    FLN1X
&lab    FOPRE   FOLN1X
        MEND

        MACRO                           ; log2 (1 + x)
&lab    FLOG21X
&lab    FOPRE   FOLOG21X
        MEND

        MACRO                           ; base-e exponential
&lab    FEXPX
&lab    FOPRE   FOEXPX
        MEND

        MACRO                           ; base-2 exponential
&lab    FEXP2X
&lab    FOPRE   FOEXP2X
        MEND

        MACRO                           ; exp (x) - 1
&lab    FEXP1X
&lab    FOPRE   FOEXP1X
        MEND

        MACRO                           ; exp2 (x) - 1
&lab    FEXP21X
&lab    FOPRE   FOEXP21X
        MEND

        MACRO                           ; integer exponential
&lab    FXPWRI
&lab    FOPRE   FOXPWRI
        MEND

        MACRO                           ; general exponential
&lab    FXPWRY
&lab    FOPRE   FOXPWRY
        MEND

        MACRO                           ; compound
&lab    FCOMPOUND
&lab    FOPRE   FOCOMPOUND
        MEND

        MACRO                           ; annuity
&lab    FANNUITY
&lab    FOPRE   FOANNUITY
        MEND
       
        MACRO                           ; arctangent
&lab    FATANX
&lab    FOPRE   FOATANX
        MEND

        MACRO                           ; sine
&lab    FSINX
&lab    FOPRE   FOSINX
        MEND

        MACRO                           ; cosine
&lab    FCOSX
&lab    FOPRE   FOCOSX
        MEND

        MACRO                           ; tangent
&lab    FTANX
&lab    FOPRE   FOTANX
        MEND
       
        MACRO                           ; random number generator
&lab    FRANDX
&lab    FOPRE   FORANDX
        MEND
       
;-----------------------------------------------------------
; Scanner and formatter function macros.
;-----------------------------------------------------------
        MACRO                           ; Pascal string to decimal record
&lab    FPSTR2DEC
&lab    FOPRD   FOPSTR2DEC
        MEND
       
        MACRO                           ; C string to decimal record
&lab    FCSTR2DEC
&lab    FOPRD   FOCSTR2DEC
        MEND
       
        MACRO                           ; decimal record to (Pascal) string
&lab    FDEC2STR
&lab    FOPRD   FODEC2STR
        MEND

;-----------------------------------------------------------
; Auxiliary macros.
;-----------------------------------------------------------
        MACRO                           ; call FP
&lab    FOPRF   &N1
&lab    PEA     &N1
        LDX     #SANEtsNum+256*FPNum
        JSL     $E10000
        MEND

        MACRO                           ; call DecStr
&lab    FOPRD   &N1
&lab    PEA     &N1
        LDX     #SANEtsNum+256*DecStrNum
        JSL     $E10000
        MEND

        MACRO                           ; call Elems
&lab    FOPRE   &N1
&lab    PEA     &N1
        LDX     #SANEtsNum+256*ElemNum
        JSL     $E10000
        MEND

