Floppy disk read: 224 byte sector?
Posted: Wed Jul 09, 2025 4:03 pm
Hello, I've been working on a tiny floppy disk controller driver to read sector 1 off a floppy, without IRQ 6, however using DMA. I read that the procedure to do this is:
So, I have this:
I know that the seek command has no result phase, but read does, however the results phase for this (retrieved this from FIFO register) is
Then reading like this (I'm 80% sure this is wrong):
All the bytes in the array are 0, however this is not expected behavior, as the floppy disk just has "Hello World" in it.
--------
Why is the results phase giving me a sector size of 224 bytes? Am I reading from the floppy disk right, or is there something else I need to do beforehand?
Thanks in advance!!
Code: Select all
reset controller -> turn on drive for commands -> seek to cylinder 0 -> read sector 1
Code: Select all
void fdc_send_byte(uint8_t byte){
for(;;){
uint8_t msr = inb(MAIN_STATUS_REG);
if(msr & (1<<7)){ // data register is ready
// wait until FIFO expects OUT, not IN
if(!(msr & (1<<6))) {
outb(DATA_REGISTER, byte);
break;
}
}
}
}
Code: Select all
outb(DIGITAL_OUT_REG, 0x00); // Reset controller
outb(DIGITAL_OUT_REG, 0b00011100); // Enable DMA, turn drive A for commands
// seek
fdc_send_byte(0x0F);
fdc_send_byte(0);
fdc_send_byte(0);
fdc_send_byte(0x06);
fdc_send_byte(0); // Bit 0-1: drive, Bit 2: head
fdc_send_byte(0); // Cylinder
fdc_send_byte(0); // Head
fdc_send_byte(1); // Sector 1
fdc_send_byte(2); // spec states 2 -> 512 bytes.
fdc_send_byte(1); // Max sector (only read one sector)
fdc_send_byte(42); // GAP3 length. CMOS states this floppy is a 5 inch, 27 is for 3 inch
fdc_send_byte(0xFF); // DTL -- unused, set to 0xFF
Code: Select all
ST0: 0b00000010
ST1: 0b00000001
ST2: 0b00000000
Cylinder: 0
Head: 0
Sector: 1
Sector Size: 224
Code: Select all
for(uint16_t i = 0; i < 513; i++) buf[i] = inb(DATA_REGISTER);
--------
Why is the results phase giving me a sector size of 224 bytes? Am I reading from the floppy disk right, or is there something else I need to do beforehand?
Thanks in advance!!
