Floppy Detection? Ports?

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

Floppy Detection? Ports?

Post by gtsphere »

my question is about a specfic piece of code, but it expands out to other questions. This code here:

Code: Select all

void detect_floppy(char *f0, char *f1)
{
   u8bit type;
   char *floppy_type[] = { "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"    };
   
   outportb(0x70, 0x10);    // get floppy type for drive a/b

   type = inportb(0x71);     // get type

   strcpy(f0, floppy_type[(type >> 4)]);
   strcpy(f1, floppy_type[(type & 0xF)]);
}
detects floppys, works well and everything, but what I was wondering is HOW does it know its a floppy and the type? i know this line:
outportb(0x70, 0x10);
does that, but how do we know that 0x70 and 0x10 are the ports to look at? is there a list of these ports? I'm just kinda lost about the whole port thing, any help would be so grateful!
thanks in advance
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Floppy Detection? Ports?

Post by df »

its exactly what you tell it it is in the bIOS. so even you can set it to 2.88 even if there is no drive in the system, or its only a 720kb. if you set it to 2.88, thats what will be returned.

its not very trustworthy :)
-- Stu --
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Floppy Detection? Ports?

Post by Pype.Clicker »

port 70/71 are the ones connected to the CMOS, right ?

they know the floppy-drive informations (what is it able to handle, etc.) as configured in BIOS (so you assume the computer owner knowz what (s)he onwz) ... I guess this is still better than assuming a 1.44MB drive, though :)

Now, if you want to know what kind of DISK is in the drive, i think you must check the Bios Parameters Block on the root sector of that disk ...
Schol-R-LEA

Re:Floppy Detection? Ports?

Post by Schol-R-LEA »

OK, to begin with:

The I/O Addressing Space, better known as the I/O ports, are an 'addressing' mechanism that operates in parallel to the memory addressing (they are not memory addresses, however; they simply work in a somewhat similar fashion). In the x86 I/O adressing is 16 bits wide, giving 65536 possible I/O ports. Each of which could be used to either read a byte of data from a device or write a byte of data to a device (or both, depending on the device in question). In assembly language, the [tt]IN[/tt], [tt]INS[/tt], [tt]OUT[/tt] and [tt]OUTS[/tt] instructions access these I/O ports (the commonly used C functions in the form of inport() and outport() are usually little more than wrappers around this functionality). Any device will have at least one port; many have several (e.g.,the PC speaker uses a single 1-byte port, a COM port uses 8 ports, while certain types of network card use 32).

While the 'standard' peripherals (e.g., floppy disk, hard disk, COM and LPT ports, etc.) have default I/O addresses, many of them are not permanently fixed, and can be reassigned as needed. The reason for this is that some devices, especially early 8-bit ISA devices, often could only work in certain locations, and it was necessary to be able to reassign devices to avoid conflicts. Tables of the default I/O address mappings are available on the web; the PC Guide pages on I/O Addresses have one that is particularly good, if a bit confusing to read. A more conventional table, with a good deal of detailed information, can be seen at this location.

As far as the specific values of ports 0x0070 and 0x0071, they are assigned to the CMOS RAM, and also access the real-time clock, and the NMI enable/disable line. The first floppy drive's ports are at 0x03F0-0x03F7 (yes, there's a conflict with the primary IDE slave; why it is not a problem would take a whole other posting, and I frankly would have to look up the details myself anyway), and also requires the use of the first DMA controller's ports at 0x0000-0x000F.
Post Reply