Page 1 of 1
Can't read sectors after 35
Posted: Fri Dec 09, 2005 12:35 am
by Zioo
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.
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 1:11 am
by Phugoid
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:
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;
}
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.
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 1:53 am
by Candy
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:
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;
}
The last line should be
*sector = (block % (18 * 2)) % 18 + 1;
That's bollocks.
(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;
These are minor changes, but I think the precedence of % might be fooling you. It does so for & in any case, so I expect it to be so for % as well.
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.
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.
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 2:28 am
by Phugoid
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
"Common Subexpression Elimination"
and modular arithmetic.
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 4:20 am
by Candy
Phugoid wrote:
Please don't become condescending - all I have done is made a stupid error late at night. Otherwise, I am perfectly aware of
"Common Subexpression Elimination"
and modular arithmetic.
Sorry, didn't mean to offend you.
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 7:50 am
by Zioo
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" :-\
Re:Can't read sectors after 35
Posted: Fri Dec 09, 2005 7:51 am
by Zioo
#previous
I added it in the seek function..