Detecting Floppy Drives

Detecting Floppy Drives

Floppy drives are all most always found on an x86 computer(at least for a few more years anyway, then they will likely dissappear). When it comes to making an OS, you are going to have to need some way of taking data off a floppy disk. That's rather easy if you can use BIOS interrupt 0x13, but you can't use BIOS interrupts in PMode. So you will need to write your own floppy driver. But to use a floppy driver, you will need to know what floppy drives exist on the system, if any. Fortunitly for us, the CMOS finds the floppy drives on bootup. We just have to get the data from the CMOS and decode it.

Getting the Data From the CMOS

To get the data from the CMOS, we must output the correct "index" to the data that we want to read to port 0x70. Once we have done that, we then read port 0x71, which will contain the data we requested. For finding floppy drive information, we need to use "index" 0x10:

unsigned char c;
outportb(0x70, 0x10);
c = inportb(0x71);

Now that "c" contains the data, we just need to decode it!

Decodding the Data

Decodding the data we got from the CMOS is extremely easy. Before we do it though, we need to divide "c" into two parts. The high nibble contains info about the first floppy drive, and the low nibble contains info about the second floppy drive:

a = c >> 4; // get the high nibble
b = c & 0xF; // get the low nibble by ANDing out the high nibble

Now, there are 5 official types of floppy drives that the most CMOSes can detect:

Type of drive: Number the CMOS gives it:
360kb 5.25in 1
1.2mb 5.25in 2
720kb 3.5in 3
1.44mb 3.5in 4
2.88mb 3.5in 5
No drive 0

So, to display what drive(s) are on the system, we can do this:

char *drive_type[5] = { "no floppy drive", "360kb 5.25in floppy drive", "1.2mb 5.25in floppy drive", "720kb 3.5in", "1.44mb 3.5in", "2.88mb 3.5in"};
printf("Floppy drive A is an:\n");
printf("\nFloppy drive B is an:\n");

The full source code for this tutorial may be downloaded here(you will have to supply your own inportb/outportb and printf functions).

This tutorial is Copyright © 2002 by K.J.


Report issues via Bona Fide feedback.

2001 - 2017 © Bona Fide OS Development | The Goal | Contributors | How To Help |