Hi,
These are your original values (comments added/adjusted for reference purposes):
Code: Select all
fdc_send_command(3); // A: MT, MFM, SK, Read data command
fdc_send_command(0); // B: Head & drive
fdc_send_command(0); // C: Cylinder
fdc_send_command(0); // D: Head again
fdc_send_command(0); // E: Sector Number
fdc_send_command(512); // F: Sector size code
fdc_send_command(1); // G: EOT
fdc_send_command(42); // H: GPL
fdc_send_command(512); // I: DTL Data Length
The read data command (line A) is command 0x06 (not '3' which is the specify command), but it has a few other bits. The MT flag (multi-track) won't matter as you're only reading one sector. The MFM bit should be set for double density media (1440 Kb), and the SK bit should be set to skip deleted sectors.
Lines B, C and D are correct.
Line E is the sector number which should be between 1 and 18, as sector 1 is the first sector (confusing because cylinder 0 is the first cylinder).
Line F is messed up, and I really wish that compilers would give warnings when you try to store large constants in small variables. Basically this "sector size code" is not the number of bytes in the sector (which doesn't fit in a byte), but is a code from this table:
0x00 = 128 byte sectors
0x01 = 256 byte sectors
0x02 = 512 byte sectors
0x03 = 1024 byte sectors
0x04 = 2048 byte sectors
...
0x07 = 16384 byte sectors
You'd want 512 byte sectors, so you should be using 2.
Line H sets the gap length, which should be 0x1B for reading and writing to/from 1440Kb floppies. For formatting you'd use 0x54. Because 42 is lower than 0x54 it'd probably work most of the time..
Line I is used to specify how many bytes to transfer if 128 byte sectors are being used. You're not using 128 bytes sectors, from the manual: "When N [the sector size code] is not zero [or set for 128 bytes], DTL has no meaning and should be set to FF HEX."
So, taking everything above into account:
Code: Select all
fdc_send_command(0x66); // A: MT, MFM, SK, Read data command
fdc_send_command(0); // B: Head & drive
fdc_send_command(0); // C: Cylinder
fdc_send_command(0); // D: Head again
fdc_send_command(1); // E: Sector Number
fdc_send_command(0x02); // F: Sector size code
fdc_send_command(1); // G: EOT
fdc_send_command(0x1B); // H: GPL
fdc_send_command(0xFF); // I: DTL Data Length
Cheers,
Brendan