Floppy only reads Cylinder 0
Posted: Fri Feb 20, 2015 5:04 pm
Hi there
I have a problem seeking the floppy disk. I am using a floppy image (floppy.img) in Oracle Virtual Box. The floppy driver is started correctly and I can read the FAT12 table and list the root directory alright. In fact any file/folder that is present on Cylinder 0 will read correctly. But whenever I access any higher Cylinder (starting from Cyl 1) the FDC doesn't seek into the correct address, and the results I get from the "Sense Interrupt" command are: st0: 0x24 (sometimes 0x20), st1 & st2 & cylinder & head are all zero, which means I didn't get to the correct cylinder (e.g. I am accessing a file at LBA 60, which is C1 H1 S7, but it ALWAYS fails). The function code is as follows:
The hidden function _floppy_read_sector() does the actual DMA reading. The floppy_cmd_send() and floppy_read_data() functions simply wait for DR to be ready before sending (or reading) data from port 0x3F5. I didn't list those as the problem is here in this reading function: I never get beyond the check if(cylinder == cyl) if cylinder is > 0. If cylinder is zero, everything is fine.
Any ideas?
Thanx a lot folks
I have a problem seeking the floppy disk. I am using a floppy image (floppy.img) in Oracle Virtual Box. The floppy driver is started correctly and I can read the FAT12 table and list the root directory alright. In fact any file/folder that is present on Cylinder 0 will read correctly. But whenever I access any higher Cylinder (starting from Cyl 1) the FDC doesn't seek into the correct address, and the results I get from the "Sense Interrupt" command are: st0: 0x24 (sometimes 0x20), st1 & st2 & cylinder & head are all zero, which means I didn't get to the correct cylinder (e.g. I am accessing a file at LBA 60, which is C1 H1 S7, but it ALWAYS fails). The function code is as follows:
Code: Select all
int floppy_read_sector(long lba)
{
if(_cur_floppy_drive >= 4)
return 0;
unsigned int cylinder = 0, head = 0, sector = 1;
LBA_to_CHS(lba, &cylinder, &head, §or, _cur_floppy_drive);
/* turn motor on */
floppy_control_motor(1);
/* seek to the CHS */
uint32_t st1 = 0, cyl = 0;
for(int i = 0; i < 10; i++)
{
floppy_cmd_send(0x0F); //'Seek' command
floppy_cmd_send((head << 2) | _cur_floppy_drive);
floppy_cmd_send(cyl);
floppy_wait_on_irq();
/* tell FDC we handled the interrupt */
floppy_cmd_send(0x08); //'check interrupt' command
cyl = floppy_read_data(); //st0
st1 = floppy_read_data(); //st1
cyl = floppy_read_data(); //st2
cyl = floppy_read_data();
printf("cyl: %u ", (unsigned)cyl);
/* found cylinder? */
if(cylinder == cyl)
goto read_sector;
}
printf("Failed to read floppy\n");
return 0;
read_sector:
_floppy_read_sector((uint8_t)cylinder, (uint8_t)head, (uint8_t)sector);
floppy_control_motor(0);
return 1;
}
Any ideas?
Thanx a lot folks