Page 1 of 2
FDC again
Posted: Wed Sep 05, 2007 8:20 pm
by xyjamepa
Hi...
I'm trying to start writing FAT12 implementation,any way I wrote a FDC driver
and it works fine on bochs and on real pc and I can write/read to 1.44 floppy using CHS,
but when I tried to write/read using LBA I got two "getbyte time out",and
after that got my data,and all this happen on real pc,but on bochs it
worked fine.
here's my code:
Code: Select all
void floppy_read(word lba)
{
word track = (lba /(18 * 2 ) );
word head = (lba / 18) % 2;
word sector= (lba % 18) + 1;
track=(track & 0xFFF);
head =(head & 0xFFF);
sector=(sector & 0xFFF);
f_read(head,track,sector);
delay(500);
}
void floppy_write(word lba)
{
word track = (lba /(18 * 2 ) );
word head = (lba / 18) % 2;
word sector= (lba % 18) + 1;
track=(track & 0xFFF);
head =(head & 0XFFF);
sector=(sector & 0xFFF);
f_write(head,track,sector);
delay(500);
}
Thanx.
Posted: Wed Sep 05, 2007 8:46 pm
by jerryleecooper
You try writing using lba, but what is "track"?
CHS, cylinder, head, sector. A track is your cylinder? Then your calculation is wrong, (lba/18 )/2 is correct I think.
Posted: Thu Sep 06, 2007 12:42 am
by xyjamepa
jerryleecooper wrote:You try writing using lba, but what is "track"?
CHS, cylinder, head, sector. A track is your cylinder?
You are right,A track is my cylinder
jerryleecooper wrote:
Then your calculation is wrong, (lba/18 )/2 is correct I think.
Also you are right my calculation is wrong,I fixed it, and now it's working .
Thank you.
Posted: Thu Sep 06, 2007 12:45 pm
by Dex
This is why i do not use emulators, it should not of worked on a emulator, like it did not work on real hardware
Posted: Thu Sep 06, 2007 7:30 pm
by xyjamepa
Hi...
Once again I'm having trouble with my fdc as I said above my
floppy driver works fine and I can write/read on bochs and real pc
using CHS,cylinder,head,sector...
But when I'm tring to read/write to 1.44MB floppy using LBA it workes
fine on real pc and bochs,untill LBA>=648 then it works bad and so slow
and I get "get byte time out" on real pc and the my data ,but on bochs it works fine,
here's my code:
Code: Select all
void floppy_read(unsigned int lba)
{
unsigned int track =( (lba /18 )/ 2) ;
unsigned int head = (lba / 18) % 2;
unsigned int sector= (lba % 18) + 1;
f_read(head,track,sector);
}
void floppy_write(unsigned int lba)
{
unsigned int track =( (lba /18 )/ 2) ;
unsigned int head = (lba / 18) % 2;
unsigned int sector= (lba % 18) + 1;
f_write(head,track,sector);
}
Thanx.
Posted: Fri Sep 07, 2007 5:39 pm
by xyjamepa
no one had this problem before
?
Posted: Sun Sep 09, 2007 3:41 pm
by xyjamepa
Maybe I wasn't clear enough so I'll re-explain:
My floppy driver works fine ,and I can read/write on bochs and
on real pc using CHS:cylinder,head,sector,
now I'm tring to use LBA,it worked on bochs fine but on real pc
when LBA is more than 647 I get an error message and then I get my data
so that costs me more time to read/write.
Any advices are welcome...
Thanx.
Posted: Sun Sep 09, 2007 5:52 pm
by pcmattman
Can you, instead of calling the write function, print out your CHS values that you get from the LBA value, eg.
Code: Select all
printf( "LBA: %d, CHS: %d, %d, %d\n", lba, cylinder, head, sector );
And then tell us the results?
[/code]
Posted: Sun Sep 09, 2007 11:41 pm
by xyjamepa
Sure...
LBA is 647
the head is 1
the track is 17
the sector is 18
LBA is 700
the head is 0
the track is 19
the sector is 17
and here's my code to do that:
Code: Select all
void lba_to_chs(unsigned int lba)
{
unsigned int track =( (lba /18 )/ 2) ;
unsigned int head = (lba / 18) % 2;
unsigned int sector= (lba % 18) + 1;
printf("LBA is %d\n",lba);
printf("the head is %d\n",head);
printf("the track is %d\n",track);
printf("the sector is %d\n",sector);
}
Thanx.
Posted: Sun Sep 09, 2007 11:49 pm
by pcmattman
OK:
Code: Select all
Sector = (LBA mod SectorsPerTrack)+1
Cylinder = (LBA/SectorsPerTrack)/NumHeads
Head = (LBA/SectorsPerTrack) mod NumHeads
LBA is 647
the head is 1
the track is 17
the sector is 18
LBA is 700
the head is 0
the track is 19
the sector is 17
647:
C: 17 (actually 17.972 - integer division)
H: 1 (actually 1.944 - integer division)
S: 18
700:
C: 19 (actually 19.444 - integer division)
H: 0 (actually 0.888 - integer division)
S: 17
So your LBA to CHS conversion is working properly, would you be able to post your floppy disk driver code?
Posted: Mon Sep 10, 2007 2:45 pm
by xyjamepa
Okay here's my whole flloppy driver...
Posted: Wed Sep 12, 2007 8:43 pm
by xyjamepa
come on guys I need your advice.
Posted: Wed Sep 12, 2007 9:52 pm
by Dex
I can send you my well commended FDD driver, coded in fasm, so yo can see where yours differs, if you want.
Posted: Thu Sep 13, 2007 1:02 am
by os64dev
maybe it is a bad floppy?
Posted: Thu Sep 13, 2007 5:05 pm
by xyjamepa
I can send you my well commended FDD driver, coded in fasm, so yo can see where yours differs, if you want.
Yes,would please Dex.