home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TP8087.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  3.0 KB  |  128 lines

  1. ;******************************************************
  2. ;           TP8087.ASM 5.07
  3. ;        80x87 support routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10. ;NOTE:    This file must be assembled with MASM's /R command line option
  11.  
  12.     INCLUDE    TPCOMMON.ASM
  13.  
  14. ;******************************************************    Code
  15.  
  16. CODE    SEGMENT    BYTE PUBLIC
  17.  
  18.     ASSUME    CS:CODE
  19.  
  20.     PUBLIC    Save8087, Restore8087, Installed_8087, Exceptions8087, Error8087
  21.  
  22. ;******************************************************    Save8087
  23.  
  24. ;procedure Save8087(var    SaveBuf    : SaveBuffer8087);
  25. ;Saves the 8087    registers in the save buffer.
  26.  
  27. SaveBuf    EQU    DWORD PTR SS:[BX+4]
  28.  
  29. Save8087    PROC FAR
  30.  
  31.     StackFrame
  32.     LES    DI,SaveBuf        ;Point to save buffer
  33.     FSAVE    ES:[DI]            ;Save contents of 8087 registers
  34.     WAIT
  35.     RET    4            ;Remove    parameter and return
  36.  
  37. Save8087    ENDP
  38.  
  39. ;******************************************************    Restore8087
  40.  
  41. ;procedure Restore8087(var SaveBuf : SaveBuffer8087);
  42. ;Restores the 8087 registers from the save buffer.
  43.  
  44. Restore8087    PROC FAR
  45.  
  46.     StackFrame
  47.     LES    DI,SaveBuf        ;Point to save buffer
  48.     FRSTOR    ES:[DI]            ;Restore contents of 8087 registers
  49.     WAIT
  50.     RET    4            ;Remove    parameter and return
  51.  
  52. Restore8087    ENDP
  53.  
  54. ;******************************************************    Installed8087
  55.  
  56. ;function Installed_8087 : Boolean;
  57. ;Returns true if an 8087 or 80x87 coprocessor is installed
  58.  
  59. Installed_8087    PROC FAR
  60.  
  61.     StackFrame
  62.     FNINIT                ;Initialize co-processor
  63.     SetZero    AX            ;Assume    false
  64.     PUSH    AX            ;SS:[BX-2] = 0
  65.     FNSTCW    SS:[BX-2]        ;store control word
  66.     CMP    BYTE PTR SS:[BX-1],3    ;upper byte is 3 if math chip installed
  67.     JNE    Done            ;If not    3, no math chip    installed
  68.     INC    AX            ;AX = 1    (True)
  69. Done:    MOV    SP,BX            ;Restore stack and return
  70.     RET
  71.  
  72. Installed_8087    ENDP
  73.  
  74.  
  75. ;******************************************************    Exceptions8087
  76.  
  77. ;procedure Exceptions8087(On : boolean);
  78. ;Turn exception    interrupts on or off
  79.  
  80. OnOff        EQU BYTE PTR [BP+6]
  81. CtrlWord    EQU WORD PTR [BP-2]
  82.  
  83. Exceptions8087    PROC FAR
  84.  
  85.     StackFrameBP
  86.     DEC    SP              ;make    room for control word
  87.     DEC    SP              ;**
  88.     MOV    AL,OnOff
  89.     OR    AL,AL
  90.     JZ    ExceptionsOff
  91.  
  92.     MOV    CtrlWord,0372H          ;Unmask IM,ZM,OM
  93.     JMP    SHORT ExceptionsDone
  94.  
  95. ExceptionsOff:
  96.     FSTCW    CtrlWord          ;Get current control word
  97.     OR    CtrlWord,00FFh          ;Mask    all exceptions
  98.  
  99. ExceptionsDone:
  100.     FLDCW    CtrlWord          ;Change 8087 control word
  101.     ExitCode 2
  102.  
  103. Exceptions8087    ENDP
  104.  
  105. ;******************************************************    Error8087
  106.  
  107. ;function Error8087 : Word;
  108. ;Return    the Error status of the    8087
  109.  
  110. StatWord    EQU WORD PTR [BP-2]
  111.  
  112. Error8087    PROC FAR
  113.  
  114.     StackFrameBP
  115.     DEC    SP              ;make    room for status    word
  116.     DEC    SP              ;**
  117.     FSTSW    StatWord          ;Get current status word
  118.     MOV    AX,StatWord          ;Return in AX
  119.     AND    AX,03Fh              ;Just    the exception indicators
  120.     FCLEX                  ;Clear exception indicators
  121.     ExitCode 0
  122.  
  123. Error8087    ENDP
  124.  
  125. CODE    ENDS
  126.  
  127.     END
  128.