How can I write to floppy disk sector?????

I am trying to write disk sectors of a floppy from Delphi 2.... When I use inline asm code to try this (int 13h) I get the dreaded 'Blue Screen of Death' eeeeeeeeek!

My asm code is correctly written because I can make a stand alone program that works using TASM 2.0 ... so what is wrong here? Is windows trying to keep me from using int13h? or is it a limitation of Delphi?  Could this be done from Delphi 1...someone told me that under D1 you could access memory and ports and stuff like that much easier than with D2???
I know that it IS possible to somehow write to the sectors of a floppy using a program running in Win98 because I can do it using the WinHex sector editor....Does anyone know of a free component that would allow me to write floppy sectors??????  or can anyone provide some code to do it myself???
Who is Participating?
intheConnect With a Mentor Commented:
 >> I could kiss you :)

only if your a woman <g>

cheers glad it helped :-)
Hi Gewna

There's a lot of difference when it comes to using direct hardware access under Win32. For starters, you cannot have INT calls in your Assembly programs (if they are designed for Win32).

If you're using Delphi 2, you must follow the guidelines outlined in the Win32 SDK. Topic #95 of the file 95guide.hlp (title = "Direct Access") will give you the basic information of how it works.

In short, you can only do direct disk write/read if you lock the volumes and if your function goes through Windows' VXD for that. In order to do so you must use the IOCTL functions. Here's what the SDK says:

"32-bit Windows-based applications must call the exclusive volume-locking IOCTL functions indirectly by opening VWIN32.VXD and using its DeviceIoControl interface.

In response, VWIN32.VXD issues the low-level disk I/O functions (Interrupt 13h, Interrupt 25h, and Interrupt 26h) as well as the MS-DOS Interrupt 21h file handle read, write, seek, and IOCTL functions in the context of the calling process.

32-bit Windows-based applications may safely call the Windows ReadFile, WriteFile, SetFilePointer, and DeviceIoControl functions within a level 3 lock. Other Windows or C run-time library functions should not be used while in the level 3 lock, because these functions may call other functions that are not safe inside a level 3 lock."

Has that been of any help?


GwenaAuthor Commented:
Hi Alex...

Boo Hoo :'(
This is starting to sound like it's over my head (at least for the near future)
I don't have that file '95guide.hlp'  I wish I did so I could look at it.
The file 'VWIN32.VXD' does not seem to be anywhere in my windows dir (lots of other vxd's though)
I guess i'm just not going to be able to do this...unless someone can point me to
a component that can do it or point me to a complete working example that is
already coded.... I wish there was a site on the web that had all sorts of working delphi examples of low level I/O and other hard-to-do things so I could go look through them all.... I can  usually figure out a working example and adapt the code for my stuff....but I'm pretty much clueless wo the source code of a working example :'(

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

hi Gwena,

Here is a little demo. It shows how to change the serial number
of a floppy disk.

This demo will only work under Windows 95/98.

unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    { Private-Deklarationen }
    { Public-Deklarationen }

  Form1: TForm1;

  VWin32_DIOC_DOS_Int25 = 2;   // direct read access
  VWin32_DIOC_DOS_Int26 = 3;  // direct write access

  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;

  TDiskIO = packed record
  StartSektor    : DWord;
  AnzahlSektoren : Word;
  PBuffer        : DWord;


{$R *.DFM}

// read boot sector, change serial number, and
// write boot sector back

procedure TForm1.Button1Click(Sender: TObject);
  DevIoHandle   : THandle;
  BytesReturned : DWord;
  Reg           : TDevIoCtl_Reg;
  DiskIO        : TDiskIO;
  DatenBuffer   : Array [0..511] of Byte;   //  = 512 Bytes

  // The size of one sector can be found out with GetDiskFreeSpace
  // (normaly = 512 bytes, CD-ROMs = 2048 bytes).

  // initialize DiskIO and Reg

  with DiskIO do
      StartSektor := 0;          // from sector 0
      AnzahlSektoren := 1;       //  read 1 sector
      PBuffer := DWord(@DatenBuffer);

  with Reg do
      Reg_EAX := 0;              //  drive: 0 = A, 1 = B etc.
      Reg_EBX := DWord(@DiskIO);
      Reg_ECX := $FFFF;          //  use DiskIO

  // retrieve handle for DeviceIoControl

  DevIoHandle := CreateFile(
                 File_Share_Read or File_Share_Write,
  // only proceed, if handle is valid

  if DevIoHandle <> Invalid_Handle_Value then
      // direct read access


      // new serial number = $12345678

      DatenBuffer[39] := $78;
      DatenBuffer[40] := $56;
      DatenBuffer[41] := $34;
      DatenBuffer[42] := $12;

      // direct write access


      // release handle



Regards Barry
I have some code for direct disk access under win9x (I once downloaded it from somewhere). If you are interested, give me your eMail address or write me to "".

Regards, Madshi.
GwenaAuthor Commented:
Attn: Madshi :)

Yes Please send me the code!
send it to

GwenaAuthor Commented:
Hi inthe (Barry)

That code you posted WORKS....  :)
Did you write that???
I think I can pretty much just paste that into my project and get it to work...
I hope it's OK if I use it as is ??? I don't want the author of this demo to get p'd off at me ;-)
I sure wish I actually understood how this works... but as a delphi newbie it looks
very obscure... I think that I understand it enough that I can load/save any particular sector on a floppy...and that's all I would be cool if it could work under
NT as well...but maybe I can figure that out sometime later...what I'm trying to create is a delphi program that can read a floppy... then compress that data and
incorporate the data into a resource file so that you can have a stand-alone exe
that someone can run to re-create the original disk... kind of like that WinImage
program but a free version that only works with 1.44 would be great for sending an image of a disk such as the boot up install disk for Windows 98....

>>WORKS....  :)
of course it works ;-)

>>Did you write that???
er id like to take credit but no i cant :-)
dont know the authors but it came from the swag files originally , and you can use as you wish the code could not really be wrote many other ways so you are not "stealing code" as such..
sadly i think nt needs quite a bit more work :-[
program sounds good idea,best o luck
Regards Barry
should i post a answer?

GwenaAuthor Commented:
ATTN Inthe (Barry)
YES! post an answer... I want you to get my 100 points :-)
You deserve them!
I have already written 2 small proggies that use the code you sent...and they work perfectly!   I could kiss you :)
can I get this example, ;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.