Stevo14 wrote:It would help if we could see some code. Specifically the part where you send the read command. Also, if you haven't already, take a look at one of the floppy controller data sheets
here.
Here is the floppy reading code. READ_TRACK is defined to 0x42, device is 0, DRIVE_BASE(device) is 0x3f0 (in this case). floppy_drives[device].cylinder is the last cylinder picked up from a sense interrupt or other command result (in this case, the seek), and is equal to zero. The floppy_info structure was read from the BIOS data at 0x000fefc7 in physical memory.
Code: Select all
write_floppy_command(DRIVE_BASE(device), READ_TRACK);
write_floppy_command(DRIVE_BASE(device), device);
write_floppy_command(DRIVE_BASE(device), floppy_drives[device].cylinder);
write_floppy_command(DRIVE_BASE(device), 0); // head
write_floppy_command(DRIVE_BASE(device), 1); // sector
write_floppy_command(DRIVE_BASE(device), floppy_info.bytes_per_sector); // sector size = 128*2^size
write_floppy_command(DRIVE_BASE(device), floppy_info.sectors_per_track); // last sector
write_floppy_command(DRIVE_BASE(device), floppy_info.gap_length);
write_floppy_command(DRIVE_BASE(device), floppy_info.data_length);
wait_for_interrupt();
wait_floppy_data(DRIVE_BASE(device));
floppy_drives[device].st0 = inb(DRIVE_BASE(device) + DATA_REGISTER); // ST0
inb(DRIVE_BASE(device) + DATA_REGISTER); // ST1
inb(DRIVE_BASE(device) + DATA_REGISTER); // ST2
floppy_drives[device].cylinder = inb(DRIVE_BASE(device) + DATA_REGISTER); // cylinder
inb(DRIVE_BASE(device) + DATA_REGISTER); // head
inb(DRIVE_BASE(device) + DATA_REGISTER); // sector
inb(DRIVE_BASE(device) + DATA_REGISTER); // sector size
Note that I've tried the sector number being 0 and 1, and I get the same result.
kmtdk wrote:Well, the best thing would be to test it on a real floppy, so you can be sure about the error. Secound how have you set the dma ???
I have yet to locate an actual floppy disk in my house. I may have to go to my parents house to grab one from my younger days...

But I intend to do that as soon as I can. I also only have one (of four) computer that actually has a floppy drive -- luckily it's the one I'm running VMware on.
As far the the DMA... In the floppy's initialization I have this:
And at the beginning of the read function, I have this:
Code: Select all
prepare_dma(DMA_MODE_READ | DMA_MODE_AUTO | DMA_MODE_SINGLE, 2);
These are defined as follows. Helpful things for reading this code: dma_first_page is set to 16 (the 1 MB mark). This is where I begin my DMA stuff. I have 64 KB allocated for the first three usable channels and 128 KB for the other three usable channels. So here, when we're using channel 2, we should be getting page 17, which should be at 0x00110000 (physical).
Code: Select all
int map_dma(int channel_num, uint32 bytes)
{
if (dma_channels[channel_num].mapped || !dma_channels[channel_num].valid)
{
return 0;
}
int controller = dma_channels[channel_num].controller;
uint8 address = dma_channels[channel_num].address_reg;
uint8 counter = dma_channels[channel_num].count_reg;
uint8 page = dma_channels[channel_num].page_reg;
uint8 relchan = channel_num;
if (controller == 1)
{
relchan -= 4;
}
// Turn off the channel...
outb(controller == 0 ? 0x0A : 0xD4, 0x4 + relchan);
reset_flipflop();
outb(address, 0); // address low byte
outb(address, 0); // address high byte
reset_flipflop();
outb(counter, (bytes - 1) & 0xFF); // count low byte
outb(counter, ((bytes - 1) & 0xFF00) >> 2); // count high byte
outb(page, dma_channels[channel_num].page + dma_first_page);
// Turn the channel back on...
outb(controller == 0 ? 0x0A : 0xD4, relchan);
return 1; // all good
}
int prepare_dma(int channel_num, uint8 modes)
{
int controller = dma_channels[channel_num].controller;
uint8 relchan = channel_num;
if (controller == 1)
{
relchan -= 4;
}
outb(controller == 0 ? 0x0A : 0xD4, 0x4 + relchan);
outb(controller == 0 ? 0x0B : 0xD6, modes | relchan);
outb(controller == 0 ? 0x0A : 0xD4, relchan);
return 1;
}
Let me know if there's anything else I can provide that would be helpful (other than ALL of the code... I don't really want to do that).
I will be trying a real floppy if I can and let you know how that goes.
Thanks guys,
Tyrel