home *** CD-ROM | disk | FTP | other *** search
- {
- »Hey.. do you know anything about checking For the existance of a disk
- »drive without actually needing a disk to be in the drive? (i.e a
- »floppy?)
-
- Try reading the floppy and then test the error code. Heck, you can get all
- the info you would ever like to have about that drive. I went digging
- through my Files and found this.
- }
- Uses
- Dos;
-
- Type
- bootrecptr = ^bootRecord;
- bootRecord = Record
- nj : Array[0..2] of Byte; {offset 0 Near jump code }
- oem : Array[0..7] of Byte; { 3 OEM name and ver }
- Bytesec : Word; { 11 Bytes/Sector }
- sectclus : Byte; { 13 Sectors/cluster }
- ressect : Word; { 14 Reserved sectors }
- fattables: Byte; { 16 FAT tables }
- direntrys: Word; { 17 Directory entries}
- logsec : Word; { 19 Logical sectors }
- MDS : Byte; { 21 Media descriptor }
- FatSects : Word; { 22 FAT sectors }
- Secstrak : Word; { 24 Sectors/track }
- NumHeads : Word; { 26 Number of heads }
- HidnSecs : Word; { 28 Hidden sectors }
- bootcode : Array[0..415] of Byte; { 30 boot code }
- partcode : Array[0..15] of Byte; { 446 partition info }
- bootcode2: Array[0..49] of Byte; { 462 rest of boot code}
- end;
-
- Var
- boot : bootRecord; { the boot Record Variable }
-
- {$L DiskInfo}
- { an Object File that allows For reading Absolute disk sectors }
- {$F+}
- Function diskread(drive: Byte; starting_sector: LongInt;
- number_of_sectors: Word; Var buffer): Word; external;
- { - read a disk sector Absolutely }
- {$F-}
-
- Procedure bootlook(Drive : Char);
- Var
- ReadResult : Word;
- I : Integer;
- begin
- { Get diskette info }
- ReadResult := DiskRead(ord(Drive)-ord('A'),0,1,boot);
- if ReadResult <> 0 then
- begin
- { Error code here }
- end
- else
- begin
- { read went ok, do something }
- end;
- end; { Procedure bootlook }
- {
-
- --------------------- CUT HERE -----------------------
- ; This part goes through Turbo Assembler
- ;
- ; Diskread Procedure
- ;
-
- .286P
- .8087
-
- CODE segment Byte Public
-
- ; Conditional jumps are all coded With the SHorT qualifier in
- ; order to minimize the size of the .OBJ File output of Turbo
- ; Assembler.
- ;--------------------------------------------------------------------
- Assume cs:CODE, ds:DATA, es:nothing
- public DISKREAD
-
- DISKREAD proc Far
- ; On entry:
- ; BP
- ; SP => Near return address
- ; offset of disk buffer
- ; segment " " "
- ; number of sectors to read
- ; starting logical sector number
- ; drive number (0=A, 1=B, etc.)
- ;
- ; On Exit:
- ;
- ; AX = Function result
- ; 00 - Function successful
- ; 01..FF - Dos inT 25H error result
- drive equ [bp + 16]
- starting_sector equ [bp + 12]
- number_of_sectors equ [bp + 10]
- buffer equ [bp + 6]
-
- push bp
- mov bp,sp
- mov ax,3000h ;get Dos version
- int 21h
- cmp al,4 ;Dos 4?
- jge read4 ;We have 4 or newer, so use Extended
- push es ;save regs
- push ds
- mov dl,drive ;get drive number (0=A,1=B,etc)
- mov ah,32h ;get driver parameter block
- int 21h
- push ds ;move ds to es
- pop es
- pop ds ;restore original ds
- les bx,[es:bx + 12h] ;point ES:BX to device driver
- mov ax,[es:bx + 4] ;get device attributes
- pop es
- test ax,2 ;check if bit 1 set
- jz read3 ;wasn't, so use old method
-
- read4:
- mov al,drive
- mov bx,starting_sector ;copy info into parameter block
- mov extd_starting_sector_lo,bx
- mov bx,starting_sector + 2
- mov extd_starting_sector_hi,bx
- mov bx,number_of_sectors
- mov extd_number_of_sectors,bx
- les bx,buffer ;get seg:ofs of buffer in ES:BX
- mov extd_bufofs,bx ;put into block
- mov extd_bufseg,es
- mov bx,offset Dos4_block ;DS:BX points to block
- mov cx,-1 ;-1 means Extended read
- push ds ;save DS (not Really needed, but lets
- ;me share code With Dos 3 read.)
- jmp short readit
- read3: mov al,drive
- mov dx,starting_sector
- mov cx,number_of_sectors
- push ds
- lds bx,buffer ;get seg:ofs of buffer in DS:BX
- readit: int 25H
- inc sp ; fix broken stack
- inc sp
- pop ds
- jc short diskread_01
- xor ax,ax
- diskread_01:
- pop bp
- ret 10
- DISKREAD endp
- }