Link to home
Start Free TrialLog in
Avatar of 8BEE
8BEE

asked on

Read sector(s) from floppy

Hi, I want to read a floppy sector-by-sector.

E.G.
...
  asm
    mov ah, 02h   //function 2 : read sector
    mov dl, 00h    //first drive A:
    mov dh, 00h  //head 0
    mov ch, 00h  //track 0
    mov cl, 01h   //sector 1
    mov al, 01h   //read 1 sector
    mov es, SEG buff  //segment address of buffer
    mov bx, OFFSET buff  //offset address of buffer
    int 13h      //read sector with interrupt 13
  end;
...

But, "SEG" is not available in Delphi2,
so what do I do then???
Avatar of Madshi
Madshi

This won't work with 32bit windows. You'll have to use CreateFile and DeviceIOControl instead. Please look in the win32 help file for a topic called "Calling DeviceIOControl on Windows 95" or "Using DeviceIOControl...".

Sorry, have no sources available at this moment...   :-(

Regards, Madshi.
Hello
Here is a demo from dejanews  
It shows how to change the serial numberof a floppy disk using deviceiocontrol. it may be of assistance if only to help you understand how to use deviceiocontrol

InThe

USE IT AT YOUR OWN RISK!!!

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls;type  TForm1 = class(TForm)
    Button1: TButton;    procedure Button1Click(Sender: TObject);  private
    { Private-Deklarationen }  public    { Public-Deklarationen }  end;var
  Form1: TForm1;const  VWin32_DIOC_DOS_Int25 = 2; // direkter Lesezugriff
                                              // direct read access
  VWin32_DIOC_DOS_Int26 = 3; // direkter Schreibzugriff
                                              // direct write accesstype
  TDevIoCtl_Reg = packed Record  Reg_EBX   : DWord;  Reg_EDX   : DWord;
  Reg_ECX   : DWord;  Reg_EAX   : DWord;  Reg_EDI   : DWord;  Reg_ESI   : DWord;
  Reg_Flags : DWord;end;type  TDiskIO = packed record  StartSektor    : DWord;
  AnzahlSektoren : Word;  PBuffer        : DWord;end;implementation{$R *.DFM}
// Bootsektor lesen, Seriennummer ändern und// Bootsektor zurückschreiben
// read boot sector, change serial number, and// write boot sector back
procedure TForm1.Button1Click(Sender: TObject);var  DevIoHandle   : THandle;
  BytesReturned : DWord;  Reg           : TDevIoCtl_Reg;
  DiskIO        : TDiskIO;
  DatenBuffer   : Array [0..511] of Byte;   //  = 512 Bytes
  // Die Sektorgröße kann man mit GetDiskFreeSpace ermitteln
  // (normalerweise = 512 Bytes, bei CD-ROMs = 2048 Bytes).
  // The size of one sector can be found out with GetDiskFreeSpace
  // (normaly = 512 bytes, CD-ROMs = 2048 bytes).begin
  // DiskIO und Reg initialisieren  // initialize DiskIO and Reg  with DiskIO do
    begin      StartSektor := 0;          // ab Sektor 0 / from sector 0
      AnzahlSektoren := 1;       // 1 Sektor lesen / read 1 sector
      PBuffer := DWord(@DatenBuffer);    end;  with Reg do    begin
      reg_EAX := 0;              // Laufwerk: / drive: 0 = A, 1 = B usw.
      reg_EBX := DWord(@DiskIO);
      reg_ECX := $FFFF;          // benutze / use DiskIO    end;
  // Handle für DeviceIoControl holen.  // retrieve handle for DeviceIoControl
  DevIoHandle := CreateFile(                 '\\.\vwin32',
                 Generic_Read,
                 File_Share_Read or File_Share_Write,                 nil,
                 Open_Existing,                 File_Attribute_Normal,
                 0);  // Nur weiter, wenn Handle gültig ist.
  // only proceed, if handle is valid
  if DevIoHandle <> Invalid_Handle_Value then    begin
      // direkter Lesezugriff      // direct read access
      DeviceIoControl(DevIoHandle,                      VWin32_DIOC_DOS_Int25,
                      @Reg,                      SizeOf(Reg),
                      @Reg,                      SizeOf(Reg),
                      BytesReturned,                      nil);
      // neue Seriennummer = $12345678      // new serial number = $12345678
      DatenBuffer[39] := $78;      DatenBuffer[40] := $56;
      DatenBuffer[41] := $34;      DatenBuffer[42] := $12;
      // direkter Schreibzugriff      // direct write access
      DeviceIoControl(DevIoHandle,                      VWin32_DIOC_DOS_Int26,
                      @Reg,                      SizeOf(Reg),
                      @Reg,                      SizeOf(Reg),
                      BytesReturned,                      nil);
      // Handle freigeben      // release handle      CloseHandle(DevIoHandle);
    end;end;end.

ps..sorry that's such a bloody mess:-)
I am looking for a function that reads a disk until there is an error and then give the sector
as result .. So actually I am looking for the same stuff you are looking for. If I find something
i'll inform you about it ;-)

SkAtAn
ASKER CERTIFIED SOLUTION
Avatar of dwwang
dwwang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, any progress?