home *** CD-ROM | disk | FTP | other *** search
- ;Turbo Pascal 4.0 function to check for math coprocessor presence and type
- ;using Intel recommended techniques. Returns 0 if coprocessor not present,
- ;87, 287, or 387 if corresponding coprocessor present.
-
- ;Reference: Which Math Coprocessor?, Ted Forgeron, PC Tech Journal, Aug 87.
- ;Adapted for use with Turbo Pascal 4.0 by John Haluska, CIS 74000,1106
-
- ;function NdpType : integer;
-
- .287 ;accept coprocessor instructions
- DATA SEGMENT BYTE PUBLIC
- Control DW ? ;local variable
- DATA ENDS
-
- CODE SEGMENT BYTE PUBLIC
- ASSUME CS : CODE, DS : DATA
- PUBLIC NdpType
-
- NdpType PROC FAR
-
- ;test for presence of coprocessor
- MOV DX,0 ;load not present message
- FNINIT ;initialize math coprocessor
- MOV BYTE PTR Control+1,0 ;clear memory byte
- FNSTCW Control ;store control word in memory
- MOV AH,BYTE PTR Control+1 ;upper byte is 03h if
- CMP AH,03h ; coprocessor is present
- JNE Msg ;no math coprocessor
- ;check if 8087
- MOV DX,87 ;load 8087 message
- AND Control, NOT 0080h ;turn interrupts on (IEM=0)
- FLDCW Control ;load control word
- FDISI ;disable interrupts (IEM=1)
- FSTCW Control ;store control word
- TEST Control, 0080h ;if IEM=1, then 8087
- JNZ Msg ;display 8087 message
- ;check if 80287 or 80387
- MOV DX,287 ;load 80287 message
- FINIT ;use default infinity mode
- FLD1 ;generate infinity
- FLDZ ; by dividing 1 by zero
- FDIV ;
- FLD ST ;form negative infinity
- FCHS ;
- FCOMPP ;compare +/- infinity
- FSTSW Control ;equal for 87/287
- FWAIT ;wait for FSTSW to complete
- MOV AX,Control ;get Ndp control word
- SAHF ;store condition bits in flags
- JZ Msg ;its a 80287 if infinities equal
- MOV DX,387 ;otherwise, its a 80387
- Msg: MOV AX,DX ;return NdpType in AX
- RET
-
- NdpType ENDP
-
- CODE ENDS
- END