I need to read a floppy from a pre OS state and I have a function to read, but it cannot seem to read past the 4th sector...
void get_block(blk, buf) int blk; char buf[]
{
int cyl, head, sector;
cyl = ((blk*2) / 18) / 2;
head = ((blk*2) / 18) % 2;
sector = (blk*2) % 18;
// Read first sector <<Dies here if blk > 2>>
diskr(cyl, head, sector, buf);
// Increment
if ((sector = (++sector % 18)) == 0)
if ((head = (++head % 2)) == 0)
cyl++;
// Read second sector <<Dies here if blk == 2>>
diskr(cyl, head, sector, buf+512);
}
Any idea why? Am I converting from blocks incorrectly?
No, assuming your disk is a 1.44M "floppy" (80 cylinders, 2 heads/cylinder, 18 sectors/head, 512 bytes/sector), those calculations should be okay, as shown with the following program:
the output of which is:
I'm a little concerned about the undefined behavior nature of:
construct, preferring something like:
but, if it gives you the right values, it should be okay. However, you need to check that it does give you the right values in the environment where you're running. That fact that it does in my version of
gcc
doesn't mean it will in your case.Or you could just use the suggested form above which is defined.
The failure point that you have is nowhere near the switch-over between heads or cylinders, so I don't think it's a wrapping issue, but you should print out the values in your environment if possible.
When you say you "can't read past the 4th sector", you should specify exactly what that means? Does the machine freeze, do you get a disk error, does it return what you think is rubbish?
There is the possibility that the disk is not formatted correctly, or that it's faulty, there's also the possibility that it just doesn't have the data there that you expect to see. It may be worthwhile formatting a floppy with DOS/Windows/whatever and checking what that does in your program.