Hi,
bubach wrote:Yeah, I have to do much more precise detection in my floppy and future hard disk drivers in the future. I'm investigating right now. But I am getting more and more picky about not assuming stuff, and for floppies I could assume sectors per track and heads based on the CMOS value for 1.44mb, 720kb and so on, but to be even more pedantic there's no guarantee that some low level format didn't change that on individual floppies - right?
For some cases (e.g. different low level format on each track), the best option is not supporting it (e.g. assume all tracks are formatted the same), getting it wrong, and returning whatever error happens first.
bubach wrote:And asking the BIOS just seems like a mess too - so I'm gonna try and see if I can directly talk to the floppy drive and see what information it can provide, been years since I dug into the FDC manuals.
I've done that before. My approach was to have a table containing all the details for each media format the OS supports; then have a series of tests to narrow down the possibilities from "could be anything" to "this is the only option left".
First step is detecting the data rate and sector size - try to read the first sector on the first head on the first track (for each possible combination of data rate and sector size, in order from "most likely" to "least likely") until you successfully read it; then eliminate any formats that don't match.
If there's more than one format left (and they use a different "sectors per track" value), the next step would be trying to read the last sector on the first head on the first track (in order from "largest sectors per track" to "smallest"); then eliminate any formats that don't match.
If there's more than one format left (and they use a different "total heads" value), try to read the first sector on the second head on the first track; then eliminate any formats that don't match.
If there's more than one format left (and they use a different "total tracks" value), try to read the first sector on the first head on the last track (in order from "most total tracks" to "least total tracks"); then eliminate any formats that don't match.
After all that you should know exactly which format the disk uses; unless the disk uses a format that your OS doesn't support anyway.
For an example, the first test might tell you the floppy uses 512-byte sectors and a data rate of 1 Mbps. That narrows it down to 1720 KiB, 1680 KiB and 1440 KiB formats. The second test might tell you there's 21 sectors per track, so you'd be left with 1720 KiB and 1680 KiB formats. The next test won't help because both of these formats are "2 heads" (double sided) so you skip that test. The last test might tell you there's only 80 tracks, so now you know it's a 1680 KiB floppy.
Cheers,
Brendan