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.