home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / drives.swg / 0013_EXIST-DD.PAS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  5.5 KB  |  152 lines

  1. {
  2. »Hey.. do you know anything about checking For the existance of a disk
  3. »drive without actually needing a disk to be in the drive? (i.e a
  4. »floppy?)
  5.  
  6. Try reading the floppy and then test the error code.  Heck, you can get all
  7. the info you would ever like to have about that drive.  I went digging
  8. through my Files and found this.
  9. }
  10. Uses
  11.   Dos;
  12.  
  13. Type
  14.   bootrecptr = ^bootRecord;
  15.   bootRecord = Record
  16.        nj       : Array[0..2] of Byte;       {offset  0   Near jump code   }
  17.        oem      : Array[0..7] of Byte;       {        3   OEM name and ver }
  18.        Bytesec  : Word;                      {       11   Bytes/Sector     }
  19.        sectclus : Byte;                      {       13   Sectors/cluster  }
  20.        ressect  : Word;                      {       14   Reserved sectors }
  21.        fattables: Byte;                      {       16   FAT tables       }
  22.        direntrys: Word;                      {       17   Directory entries}
  23.        logsec   : Word;                      {       19   Logical sectors  }
  24.        MDS      : Byte;                      {       21   Media descriptor }
  25.        FatSects : Word;                      {       22   FAT sectors      }
  26.        Secstrak : Word;                      {       24   Sectors/track    }
  27.        NumHeads : Word;                      {       26   Number of heads  }
  28.        HidnSecs : Word;                      {       28   Hidden sectors   }
  29.        bootcode : Array[0..415] of Byte;     {       30   boot code        }
  30.        partcode : Array[0..15] of Byte;      {      446   partition info   }
  31.        bootcode2: Array[0..49] of Byte;      {      462   rest of boot code}
  32.      end;
  33.  
  34. Var
  35.   boot : bootRecord;      { the boot Record Variable }
  36.  
  37. {$L DiskInfo}
  38.   { an Object File that allows For reading Absolute disk sectors }
  39. {$F+}
  40. Function diskread(drive: Byte; starting_sector: LongInt;
  41.   number_of_sectors: Word; Var buffer): Word; external;
  42.   { - read a disk sector Absolutely }
  43. {$F-}
  44.  
  45. Procedure bootlook(Drive : Char);
  46. Var
  47.   ReadResult : Word;
  48.   I          : Integer;
  49. begin
  50.   { Get diskette info }
  51.   ReadResult := DiskRead(ord(Drive)-ord('A'),0,1,boot);
  52.   if ReadResult <> 0 then
  53.   begin
  54.     { Error code here }
  55.   end
  56.   else
  57.   begin
  58.     { read went ok, do something }
  59.   end;
  60. end;  { Procedure bootlook }
  61. {
  62.  
  63. --------------------- CUT HERE -----------------------
  64. ; This part goes through Turbo Assembler
  65. ;
  66. ; Diskread Procedure
  67. ;
  68.  
  69. .286P
  70. .8087
  71.  
  72. CODE    segment Byte Public
  73.  
  74. ;       Conditional jumps are all coded With the SHorT qualifier in
  75. ;       order to minimize the size of the .OBJ File output of Turbo
  76. ;       Assembler.
  77. ;--------------------------------------------------------------------
  78.         Assume cs:CODE, ds:DATA, es:nothing
  79.         public  DISKREAD
  80.  
  81. DISKREAD        proc    Far
  82. ;       On entry:
  83. ;               BP
  84. ;       SP =>   Near return address
  85. ;               offset  of disk buffer
  86. ;               segment "   "     "
  87. ;               number of sectors to read
  88. ;               starting logical sector number
  89. ;               drive number (0=A, 1=B, etc.)
  90. ;
  91. ;       On Exit:
  92. ;
  93. ;               AX      = Function result
  94. ;                       00      - Function successful
  95. ;                       01..FF  - Dos inT 25H error result
  96.         drive                   equ     [bp + 16]
  97.         starting_sector         equ     [bp + 12]
  98.         number_of_sectors       equ     [bp + 10]
  99.         buffer                  equ     [bp + 6]
  100.  
  101.         push    bp
  102.         mov     bp,sp
  103.         mov     ax,3000h                ;get Dos version
  104.         int     21h
  105.         cmp     al,4                    ;Dos 4?
  106.         jge     read4                   ;We have 4 or newer, so use Extended
  107.         push    es                      ;save regs
  108.         push    ds
  109.         mov     dl,drive                ;get drive number (0=A,1=B,etc)
  110.         mov     ah,32h                  ;get driver parameter block
  111.         int     21h
  112.         push    ds                      ;move ds to es
  113.         pop     es
  114.         pop     ds                      ;restore original ds
  115.         les     bx,[es:bx + 12h]        ;point ES:BX to device driver
  116.         mov     ax,[es:bx + 4]          ;get device attributes
  117.         pop     es
  118.         test    ax,2                    ;check if bit 1 set
  119.         jz      read3                   ;wasn't, so use old method
  120.  
  121. read4:
  122.         mov     al,drive
  123.         mov     bx,starting_sector      ;copy info into parameter block
  124.         mov     extd_starting_sector_lo,bx
  125.         mov     bx,starting_sector + 2
  126.         mov     extd_starting_sector_hi,bx
  127.         mov     bx,number_of_sectors
  128.         mov     extd_number_of_sectors,bx
  129.         les     bx,buffer               ;get seg:ofs of buffer in ES:BX
  130.         mov     extd_bufofs,bx          ;put into block
  131.         mov     extd_bufseg,es
  132.         mov     bx,offset Dos4_block    ;DS:BX points to block
  133.         mov     cx,-1                   ;-1 means Extended read
  134.         push    ds                      ;save DS (not Really needed, but lets
  135.                                         ;me share code With Dos 3 read.)
  136.         jmp     short readit
  137. read3:  mov     al,drive
  138.         mov     dx,starting_sector
  139.         mov     cx,number_of_sectors
  140.         push    ds
  141.         lds     bx,buffer               ;get seg:ofs of buffer in DS:BX
  142. readit: int     25H
  143.         inc     sp                      ; fix broken stack
  144.         inc     sp
  145.         pop     ds
  146.         jc      short diskread_01
  147.         xor     ax,ax
  148. diskread_01:
  149.         pop     bp
  150.         ret     10
  151. DISKREAD        endp
  152. }