home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_03 / 2n03053a < prev    next >
Text File  |  1991-01-15  |  2KB  |  74 lines

  1.  
  2. ;********************************************************************
  3. ; _Check8087 -- check for a numeric coprocessor.
  4. ;
  5. ; C Prototype :
  6. ;
  7. ;        short int Check8087(void)
  8. ;
  9. ; Input : Nothing
  10. ;
  11. ; Output: AX = 0 -- No Coprocessor
  12. ;              1 -- 8087
  13. ;              2 -- 80287
  14. ;              3 -- 80387
  15. ;
  16. ; Author : Bob Zigon
  17. ; Date   : July 23, 1989
  18. ;********************************************************************
  19.      dosseg
  20.      .model small
  21.      .code 
  22.       public _Check8087
  23.  
  24. _Check8087 proc near
  25.      local Control:word=ChLocals
  26.      push bp
  27.      mov bp,sp
  28.      sub sp,ChLocals             ; Allocate some locals
  29.  
  30.      finit                       ; Initialize math coprocessor
  31.      mov byte ptr Control+1,0    ; Clear memory byte
  32.      fnstcw Control              ; Store control word in memory
  33.      mov ah,byte ptr Control+1   ; Upper byte is 03h if
  34.      cmp ah,03h                  ;   ... coprocessor is present
  35.      jne No8087                  ; No math coprocessor
  36. ;
  37. ;  Check for 8087
  38. ;
  39.      and Control, NOT 0080h      ; Turn interrupts on (IEM=0)
  40.      fldcw Control               ; Load control word
  41.      fdisi                       ; Disable interrupts (IEM=1)
  42.      fstcw Control               ; Store control word
  43.      test Control, 0080h         ; If IEM=1, then 8087
  44.      jnz Is8087                  ; We have an 8087
  45. ;
  46. ;  Check if 80287 OR 80387
  47. ;
  48.      finit                       ; Use default infinity mode
  49.      fld1                        ; Generate infinity
  50.      fldz                        ;     by dividing 1 by zero
  51.      fdiv                        ;
  52.      fld st                      ; Form negative infinity
  53.      fchs                        ;
  54.      fcompp                      ; Compare +/- infinity
  55.      fstsw Control               ; Equal for 87/287
  56.      fwait                       ; Wait for fstsw to complete
  57.      mov ax,Control              ; Get NDP control word
  58.      sahf                        ; Store condition bits in flags
  59.      jz Is80287                  ; It's 287 if infinities equal
  60.      mov ax,3                    ; It must be an 80387
  61.  
  62. ChExit:  mov sp,bp
  63.          pop bp
  64.          ret
  65. No8087:  xor ax,ax
  66.          jmp short ChExit
  67. Is8087:  mov ax,1
  68.          jmp short ChExit
  69. Is80287: mov ax,2
  70.          jmp short ChExit
  71. _Check8087 endp
  72.  
  73.       end
  74.