FDC again

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

FDC again

Post 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.
User avatar
jerryleecooper
Member
Member
Posts: 233
Joined: Mon Aug 06, 2007 6:32 pm
Location: Canada

Post by jerryleecooper »

You try writing using lba, but what is "track"? :wink:
CHS, cylinder, head, sector. A track is your cylinder? Then your calculation is wrong, (lba/18 )/2 is correct I think.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

jerryleecooper wrote:You try writing using lba, but what is "track"? :wink:
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.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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 :wink:
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

no one had this problem before :( ?
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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]
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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?
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

Okay here's my whole flloppy driver...
Attachments
fdc.c
(8.02 KiB) Downloaded 35 times
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

come on guys I need your advice.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

I can send you my well commended FDD driver, coded in fasm, so yo can see where yours differs, if you want.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

maybe it is a bad floppy?
Author of COBOS
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
Post Reply