Hello!
I've discovered a bug in my FDC code, while i wrote my FAT12 driver. My floppy driver is unable to read all sectors after 35, the seek function fails. But whats the difference between eg. sector 35 and 36? ???
Does anyone have a suggestion to what there can be wrong?
Your can find my source here: http://penguinpower.frac.dk/source/fdc.c
It's on line 167 the seek fails.
Btw. It does work in Bochs, it's on a real pc it fails.
Can't read sectors after 35
Re:Can't read sectors after 35
One thing that's special about sector 36 is that it's the first sector on a new double-sided track (multiply tracks by heads to see this). The following code is wrong:
The last line should be
*sector = (block % (18 * 2)) % 18 + 1;
But, in fact, you would be best off with some sort of temporary variable, since the first part of that expression is exactly the same as in the calculation for head.
You should also avoid hardcoding the values as best you can.
Code: Select all
void block2hts(int block,int *head,int *track,int *sector)
{
*head = (block % (18 * 2)) / (18);
*track = block / (18 * 2);
*sector = block % 18 + 1;
}
*sector = (block % (18 * 2)) % 18 + 1;
But, in fact, you would be best off with some sort of temporary variable, since the first part of that expression is exactly the same as in the calculation for head.
You should also avoid hardcoding the values as best you can.
Code: Select all
Re:Can't read sectors after 35
That's bollocks.Phugoid wrote: One thing that's special about sector 36 is that it's the first sector on a new double-sided track (multiply tracks by heads to see this). The following code is wrong:
The last line should beCode: Select all
void block2hts(int block,int *head,int *track,int *sector) { *head = (block % (18 * 2)) / (18); *track = block / (18 * 2); *sector = block % 18 + 1; }
*sector = (block % (18 * 2)) % 18 + 1;
(block % (18*2)) % 18 == block % 18.
But, you are right in thinking it's the edge of cylinders that's causing an error.
Code: Select all
*head = (block / 18) % 2;
*track = block / (36);
*sector = (block % 18) + 1;
That's a job for the compiler, not the user. It's called "Common Subexpression Elimination", and it's been in compiler design text books for at least 30 years. I expect the compiler he's using to know about it.But, in fact, you would be best off with some sort of temporary variable, since the first part of that expression is exactly the same as in the calculation for head.
Re:Can't read sectors after 35
I stand corrected.
Please don't become condescending - all I have done is made a stupid error late at night. Otherwise, I am perfectly aware of
Please don't become condescending - all I have done is made a stupid error late at night. Otherwise, I am perfectly aware of
and modular arithmetic."Common Subexpression Elimination"
Re:Can't read sectors after 35
Sorry, didn't mean to offend you.Phugoid wrote: Please don't become condescending - all I have done is made a stupid error late at night. Otherwise, I am perfectly aware ofand modular arithmetic."Common Subexpression Elimination"
Re:Can't read sectors after 35
Thanks for the answers, but it does still not work.
I've added "vsprintf("fdc_track: %i track: %i\n",fdc_track,track);" and it returns "fdc_track: 0 track: 2" on a real pc, and in bochs where it work does it return "fdc_track: 2 track: 2" :-\
I've added "vsprintf("fdc_track: %i track: %i\n",fdc_track,track);" and it returns "fdc_track: 0 track: 2" on a real pc, and in bochs where it work does it return "fdc_track: 2 track: 2" :-\