FDD Read not reading correct sectors
Posted: Wed Dec 24, 2008 1:08 am
I have basically finished my Floppy driver. Everything works fine except the data it is reading is not what is really on the disk. When I read the 1st sector (Boot Sector) The first byte should be EB however I am getting a different value. I have checked my code against various sources but all seems to be fine. My transfer code is
The other problem I am experiencing is that the Driver won't write to a floppy. In Bochs I get a "Cannot write() to floppy image" exception but on real hardware nothing gets written. My read and write codes are as follow:
Ignore those IF Then statements. I have to different read algorithms. But I am only using "FloppyDoTrackLBA" at the moment. The other one is an experimental thing.
Is there something I am missing that makes it possible to write to a floppy? I will post more code if you need.
Code: Select all
function FloppyDoTrackLBA(Drive : byte; LBA : byte; dir : byte; NoSectors : byte) : byte;
var
cmd, i, st0, st1, st2, rcy, rhe, rse, bps, error : byte;
cyl, head, sec : byte;
begin
error := 0;
case dir of
1 : cmd := FloppyCmd[5] ;//or $C0; //Read
2 : cmd := FloppyCmd[4] ;//or $C0; //Write
end;
LBA2CHS(LBA, cyl, head, sec);
Size := NoSectors * 512;
if (Seek(Drive, cyl, head)) = -1 then
begin
FloppyDoTrackLBA := -1;
Exit;
end;
for i := 1 to 20 do
begin
Motor(Drive, 1);
FloppyDMAInit(dir, Size);
Delay(10);
FloppyWriteCmd(Drive, cmd);
FloppyWriteCmd(Drive, ((head shl 2) or Drive));
FloppyWriteCmd(Drive, cyl);
FloppyWriteCmd(Drive, head);
FloppyWriteCmd(Drive, sec);
FloppyWriteCmd(Drive, 2);
FloppyWriteCmd(Drive, 0);
FloppyWriteCmd(Drive, 0);
FloppyWriteCmd(Drive, $FF);
IRQWait(6);
st0 := FloppyReadCmd(Drive);
st1 := FloppyReadCmd(Drive);
st2 := FloppyReadCmd(Drive);
//Read Cylinder, Head, Sector
rcy := FloppyReadCmd(Drive);
rhe := FloppyReadCmd(Drive);
rse := FloppyReadCmd(Drive);
bps := FloppyReadCmd(Drive);
if error = 0 then
begin
Motor(Drive, 0);
FloppyDoTrackLBA := 0;
Exit;
end;
if error >= 1 then
begin
PrintString(#10'Floppy Read Write Fail.. Quiiting');
Motor(Drive, 0);
FloppyDoTrackLBA := -2;
Exit;
end;
end;
PrintString(#10'Floppy Read Write Timeout');
Motor(Drive, 0);
FloppyDoTrackLBA := -1;
end;
Code: Select all
function FloppyRead(Drive : byte; Data : byte; LBA : boolean; NoSec : byte) : byte;
begin
if LBA = false then
FloppyRead := FloppyDoTrack(Drive, Data, 1);
if LBA = true then
FloppyRead := FloppyDoTrackLBA(Drive, Data, 1, NoSec);
end;
//Drive to be used, Starting Sector, Uses LBA (T/F), Number of sectors to read
function FloppyWrite(Drive : byte; Data : byte; LBA : boolean; NoSec : byte) : byte;
begin
if LBA = false then
FloppyWrite := FloppyDoTrack(Drive, Data, 2);
if LBA = true then
FloppyWrite := FloppyDoTrackLBA(Drive, Data, 2, NoSec);
end;
Ignore those IF Then statements. I have to different read algorithms. But I am only using "FloppyDoTrackLBA" at the moment. The other one is an experimental thing.
Is there something I am missing that makes it possible to write to a floppy? I will post more code if you need.