
                    incdir         "include:"
                    include        "exec/execbase.i"
                    include        "dos/dosextens.i"
                    include        "libraries/dos.i"
                    include        "lvo/LVOs.i"

main                MOVEA.L        (4).w,A6
                    BTST.B         #AFB_68881,AttnFlags+1(A6)
                    BEQ.W          exit
                    LEA            LibName(PC),A1
                    MOVEQ          #36,D0
                    JSR            _LVOOpenLibrary(A6)
                    TST.L          D0
                    BNE.B          install
                    MOVEQ          #RETURN_FAIL,D0
                    RTS

install             MOVEA.L        D0,A5
                    JSR            _LVOForbid(A6)

                    MOVEA.W        #-6,A0
                    LEA            Open(PC),A1
                    BSR.S          patch

                    MOVEA.W        #-12,A0
                    LEA            exit(PC),A1 ; Close()
                    BSR.S          patch

                    MOVEA.W        #-18,A0
                    LEA            exit(PC),A1 ; Expunge()
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPFix,A0
                    LEA            Fix(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPFlt,A0
                    LEA            Flt(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPCmp,A0
                    LEA            Cmp(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPTst,A0
                    LEA            Tst(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPAbs,A0
                    LEA            Abs(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPNeg,A0
                    LEA            Neg(PC),A1
                    BSR.S          patch
                    BRA.S          next

                    ;----------------------------------

patch               MOVE.L         A1,D0
                    MOVEA.L        A5,A1
                    JMP            _LVOSetFunction(A6)

                    ;----------------------------------

next                MOVEA.W        #_LVOIEEESPAdd,A0
                    LEA            Add(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPSub,A0
                    LEA            Sub(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPMul,A0
                    LEA            Mul(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPDiv,A0
                    LEA            Div(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPFloor,A0
                    LEA            Floor(PC),A1
                    BSR.S          patch

                    MOVEA.W        #_LVOIEEESPCeil,A0
                    LEA            Ceil(PC),A1
                    BSR.S          patch

                    LEA            LibId(PC),A1
                    MOVE.L         A1,LIB_IDSTRING(A5)
                    MOVE.W         #881,LIB_REVISION(A5)

                    JSR            _LVOPermit(A6)

                    MOVEA.L        ThisTask(A6),A0
                    MOVEA.L        pr_CLI(A0),A0
                    ADDA.L         A0,A0
                    ADDA.L         A0,A0
                    CLR.L          cli_Module(A0)
exit                MOVEQ          #RETURN_OK,D0
                    RTS

LibName             DC.B           "mathieeesingbas.library",0
                    DC.B           "$VER:"
LibId               DC.B           "PatchMSB 14.881",0

;--------------------------------------------------------------

                    CNOP           0,4

Open                MOVE.L         A6,D0
                    BRA.S          fpcr

                    CNOP           0,4

Tst                 ADD.L          D0,D0
                    BHI.S          more
                    BNE.S          less
                    RTS

                    CNOP           0,4

Cmp                 TST.L          D1
                    BMI.S          minus
                    BEQ.S          Tst     ; D1=0 -> Tst
                    SUB.L          D1,D0
                    BLT.S          less
plus                BEQ.S          same
more                MOVEQ          #1,D0
                    RTS

                    CNOP           0,4

minus               TST.L          D0
                    BNE.S          skip
                    BSET.L         #31,D0  ; D0=0 -> -0
skip                SUB.L          D1,D0
                    BLS.S          plus
less                MOVEQ          #-1,D0
                    RTS

                    CNOP           0,4

Fix                 FMOVE.S        D0,FP0
                    MOVEQ          #$10,D0 ; extended precision
                    FMOVE.L        D0,FPCR ; round to zero
                    FMOVE.L        FP0,D0  ; float to long int
fpcr                MOVEQ          #0,D1   ; extended precision
                    FMOVE.L        D1,FPCR ; round to nearest
same                RTS

Abs                 BCLR.L         #31,D0
                    RTS

                    CNOP           0,4

Flt                 FMOVE.L        D0,FP0
                    BRA.S          done

                    CNOP           0,4

Floor               FINTRZ.S       D0,FP0
                    MOVE.L         D0,D1
                    FMOVE.S        FP0,D0
                    BPL.S          return
                    CMP.L          D0,D1
                    BEQ.S          return
                    FSUB.S         #1,FP0
                    BRA.S          done

                    CNOP           0,4

Ceil                FINTRZ.S       D0,FP0
                    MOVE.L         D0,D1
                    FMOVE.S        FP0,D0
                    BMI.S          return
                    CMP.L          D0,D1
                    BEQ.S          return
                    FADD.S         #1,FP0
                    BRA.S          done

                    CNOP           0,4

Add                 FMOVE.S        D0,FP0
                    FADD.S         D1,FP0
                    BRA.S          done

                    CNOP           0,4

Sub                 FMOVE.S        D0,FP0
                    FSUB.S         D1,FP0
                    BRA.S          done

                    CNOP           0,4

Mul                 FMOVE.S        D0,FP0
                    FMUL.S         D1,FP0
                    BRA.S          done

                    CNOP           0,4

Div                 FMOVE.S        D0,FP0
                    FDIV.S         D1,FP0
done                FMOVE.S        FP0,D0
return              RTS

Neg                 BCHG.L         #31,D0
                    RTS

                    CNOP           0,4

