home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05046a < prev    next >
Text File  |  1992-02-06  |  7KB  |  196 lines

  1. ;======================================================================
  2. ; DISKTYPE.ASM
  3. ; Copyright (c) 1992 Schaefer Software, Robert L. Hummel
  4. ;----------------------------------------------------------------------
  5. ; DisketteType() is a function that attempts to identify the type
  6. ; (capacity) of a diskette drive using BIOS calls. It returns an
  7. ; integer value that identifies the type of drive. Note that this
  8. ; routine operates on PHYSICAL diskette drives, not logical drives.
  9. ;
  10. ; To be properly identified, the drive must be supported by the BIOS of
  11. ; the PC. Improper information in the CMOS or incompatible hardware
  12. ; will tend to give incorrect results.
  13. ;----------------------------------------------------------------------
  14. ; Usage:
  15. ;    Result = DisketteType(DriveNumber)
  16. ; where
  17. ;    DriveNumber = (16-bit integer) physical drive number.
  18. ;              0 = 1st physical diskette
  19. ;              1 = 2nd physical diskette
  20. ;              2 = 3rd physical diskette
  21. ;              etc.
  22. ;
  23. ;    Result = (16-bit integer)
  24. ;         0, Drive not present or cannot identify
  25. ;         1, 360K 5.25" 40 track
  26. ;         2, 1.2M 5.25" 80 track
  27. ;         3, 720K 3.5"  80 track
  28. ;          4, 1.4M 3.5"  80 track
  29. ;----------------------------------------------------------------------
  30. PUBLIC  DisketteType     ;BASIC, PASCAL (FAR)
  31. PUBLIC _DisketteType     ;C (FAR)
  32. PUBLIC  DisketteType$FAR ;ASM (FAR)
  33.  
  34. ;======================================================================
  35. ; Code segment.
  36. ;----------------------------------------------------------------------
  37. CSEG        SEGMENT    BYTE    PUBLIC    'CODE'
  38.     ASSUME    CS:CSEG
  39.  
  40. ;======================================================================
  41. ; DisketteType$FAR
  42. ; Copyright (c) 1992 Schaefer Software, Robert L. Hummel
  43. ;
  44. ; The common assembly routine called by the HLL interface routines.
  45. ; May also be called directly from assembly language.
  46. ; All arguments are passed via register.
  47. ;----------------------------------------------------------------------
  48. ; Entry:
  49. ;    DL = Physical drive number
  50. ; Exit:
  51. ;    AX = Drive type
  52. ;----------------------------------------------------------------------
  53. ; Changes: AX BX CX DX ES
  54. ;----------------------------------------------------------------------
  55. DisketteType$FAR    PROC    FAR
  56.     ASSUME    CS:CSEG
  57.  
  58.         PUSH    SI            ;Preserve registers
  59.         PUSH    DI
  60. ;----------------------------------------------------------------------
  61. ; The Read Drive Parameters BIOS function is supported by all PCs
  62. ; except the PC, XT, PCjr, and first AT (BIOS 1/10/84). If successful,
  63. ; it returns the drive type in BL. Otherwise, CF is set.
  64. ;----------------------------------------------------------------------
  65.         MOV    SI,DX            ;Save drive number
  66.  
  67.         MOV    AH,8            ;Get disk type
  68.                         ;Drive number in DL
  69.         INT    13H            ; thru BIOS
  70.     ASSUME    ES:NOTHING            ;May change ES
  71.         JNC    DT_3A
  72. ;----------------------------------------------------------------------
  73. ; The carry flag was set, indicating that this function, and 3.5"
  74. ; drives, are not supported by this BIOS.
  75. ;
  76. ; All PCs that support the 1.2M drive support the Read DASD (Direct
  77. ; Access Storage Device) Type function call.
  78. ;----------------------------------------------------------------------
  79.         MOV    AH,15H            ;Read DASD type
  80.         MOV    DX,SI            ;For drive in DL
  81.         INT    13H            ; thru BIOS
  82.         JNC    DT_2
  83. ;----------------------------------------------------------------------
  84. ; The carry flag was set, so 1.2M drives are not supported. The only
  85. ; choices left are 360k 5.25" or not present. Check the equipment list
  86. ; to see if the drive number is within range.
  87. ;----------------------------------------------------------------------
  88.         MOV    DX,SI            ;Drive number in DL
  89.  
  90.         INT    11H            ;Get equipment list
  91.         MOV    DH,AL            ;Drives into DH
  92.  
  93.         SUB    AX,AX            ;Assume not present
  94.  
  95.         TEST    DH,1            ;=1 if any drives
  96.         JZ    DT_EXIT
  97.  
  98.         ROL    DH,1            ;Isolate
  99.         ROL    DH,1            ; number of
  100.         AND    DH,3            ; diskette drives
  101.         INC    DH            ; and make upper limit
  102.  
  103.         CMP    DL,DH            ;CMP drive # to max
  104.         RCL    AL,1            ;Move CF into AL
  105.         JMP    SHORT DT_EXIT
  106. ;----------------------------------------------------------------------
  107. ; The Read DASD type call was successful.  AH contains the BIOS return
  108. ; code for the drive type. If the drive supports the change line it is
  109. ; a 1.2M. Otherwise, it is a 360k.
  110. ;----------------------------------------------------------------------
  111. DT_2:
  112.         SUB    AL,AL            ;Clear AL
  113.         XCHG    AH,AL            ;Put type in AX
  114.         JMP    SHORT DT_EXIT
  115. ;----------------------------------------------------------------------
  116. ; If CX=0, then the specified drive is not installed. AX already
  117. ; contains a 0 (cleared by the BIOS function), so simply return.
  118. ;----------------------------------------------------------------------
  119. DT_3A:
  120.         JCXZ    DT_EXIT
  121. ;----------------------------------------------------------------------
  122. ; If BL=0, then the CMOS was corrupt. Determine the drive type by
  123. ; matching the returned drive parameters.
  124. ;----------------------------------------------------------------------
  125.         ADD    AL,BL            ;ZF=1 if BL=0
  126.         JNZ    DT_EXIT
  127.  
  128.         MOV    AX,CX            ;Save tracks/sectors
  129.         MOV    CX,5            ;Preset return type
  130.  
  131.         CMP    AX,4F12H        ;If type 4
  132.         LOOPE    DT_3B            ; DEC CX and exit
  133.  
  134.         CMP    AX,4F09H        ;Type 3
  135.         LOOPE    DT_3B
  136.  
  137.         CMP    AX,4F0FH        ;Type 2
  138.         LOOPE    DT_3B
  139.  
  140.         CMP    AX,2709H        ;Type 1
  141.         LOOPE    DT_3B
  142. DT_3B:
  143.         MOV    AX,CX
  144. DT_EXIT:
  145.         POP    DI
  146.         POP    SI
  147.         RET
  148.  
  149. DisketteType$FAR    ENDP
  150.  
  151. ;======================================================================
  152. ; BASIC, PASCAL entry point.
  153. ;----------------------------------------------------------------------
  154. ; 1. Argument is passed by reference.
  155. ; 2. We clean up stack.
  156. ;----------------------------------------------------------------------
  157. DisketteType    PROC    FAR
  158.     ASSUME    CS:CSEG
  159.  
  160.         PUSH    BP            ;Create stack frame
  161.         MOV    BP,SP
  162.  
  163.         MOV    BX,WORD PTR [BP+6]    ;Get pointer
  164.         MOV    DX,WORD PTR [BX]    ;Drive number
  165.  
  166.         CALL    DisketteType$FAR
  167.  
  168.         POP    BP            ;Destroy stack frame
  169.         RET    (1)*2            ;Discard 1 argument
  170.  
  171. DisketteType    ENDP
  172.  
  173. ;======================================================================
  174. ; C entry point.
  175. ;----------------------------------------------------------------------
  176. ; 1. Argument is passed by value.
  177. ; 2. Caller cleans up stack.
  178. ;----------------------------------------------------------------------
  179. _DisketteType    PROC    FAR
  180.     ASSUME    CS:CSEG
  181.  
  182.         PUSH    BP            ;Create stack frame
  183.         MOV    BP,SP
  184.  
  185.         MOV    DX,WORD PTR [BP+6]    ;Get drive number
  186.  
  187.         CALL    DisketteType$FAR
  188.  
  189.         POP    BP            ;Destroy stack frame
  190.         RET
  191.  
  192. _DisketteType    ENDP
  193.  
  194. CSEG        ENDS
  195.         END
  196.