Floppy Disk Controller: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Added table with more information about different FDCs
m Bot: Replace deprecated source tag with syntaxhighlight
 
(8 intermediate revisions by 3 users not shown)
Line 1:
== Overview and Documentation ==
The Floppy Disk Controller (FDC) is a (legacy) device that controls '''internal''' 3.5/5.25 inch floppy disk drive devices on desktop x86 systems.
There are a range of chips that have been produced for this function which include: 8272A, 82078, 82077SL & 82077AA. The 82077AA is the most
Of these chips, the 82077AA is the most advanced, and has been produced since 1991. For more recent systems, a model of that chip has been embedded in the motherboard chipset.
 
{| {{wikitable}}
|Manufacturer and part number
|Introduced in
|Used in
|-
|NEC µPD765
|1981
|IBM PC original, IBM PC/XT
|-
|Intel 8272A
|1982
|(any system which used µPD765 may use 8272A since they are 100% compatible)
|-
|Intel 82078A
|1994
|IBM PC/AT
|-
|Intel 82077A
|1994
|IBM PS/2
|}
 
Of these chips, the 82077AA is the most advanced, and has been produced since 1991. For more recent systems, a model of that chip has been embedded in the motherboard chipset.
(So pay close attention to that datasheet, below.)
 
Line 93 ⟶ 70:
This can be described in C with the following code:
 
<sourcesyntaxhighlight lang="c">
void lba_2_chs(uint32_t lba, uint16_t* cyl, uint16_t* head, uint16_t* sector)
{
Line 100 ⟶ 77:
*sector = ((lba % (2 * FLOPPY_144_SECTORS_PER_TRACK)) % FLOPPY_144_SECTORS_PER_TRACK + 1);
}
</syntaxhighlight>
</source>
 
You would then send this data to the floppy controller.
Line 178 ⟶ 155:
The basic set of floppy registers can be found in the following enumeration:
 
<sourcesyntaxhighlight lang="c">
enum FloppyRegisters
{
Line 191 ⟶ 168:
CONFIGURATION_CONTROL_REGISTER = 0x3F7 // write-only
};
</syntaxhighlight>
</source>
 
All commands, parameter information, result codes, and disk data transfers go through the FIFO port.
Line 208 ⟶ 185:
They are the following:
 
=== FIFO and Tape Drive Registers ===
FIFO: The FIFO register may not have a 16byte buffer in all modes, but this is a minor difference that does not really affect its operation.
 
=== Tape Drive Register ===
TDR: The Tape Drive Register is identical in all modes, but it is useless (you will never find functional equipment that requires it).
 
TDR: The Tape Drive Register is a R/W register which is identical in all modes. According to the documentation for the Intel 82077AA, the two least significant bits form a number between 1 and 3 (0 is an invalid value, drive 0 may not be selected) that assigns tape support to one particular drive out of four total drives. It is probably irrelevant for modern uses, is not supported by any emulator and is probably not worth implementing support for unless you have all the real hardware to test this functionality on.
 
=== DOR bitflag definitions ===
Line 536 ⟶ 515:
with a * and a comment.
 
<sourcesyntaxhighlight lang="c">
enum FloppyCommands
{
Line 561 ⟶ 540:
SCAN_HIGH_OR_EQUAL = 29
};
</syntaxhighlight>
</source>
 
==== "Deleted sectors" ====
Deleted sectors is a legacy feature, dating back to the 1970s, when IBM data entry terminals stored a single database record in each (128 byte) floppy sector, and a record could be marked as deleted by writing a different address mark before the sector. This feature was almost never used with IBM PC and compatibles – exceptions were occasional abuse by copy protection schemes, and (possibly) hiding bad sectors. Few (if any) emulators emulate this functionality, and many late model FDCs didn't implement it.
 
The "WRITE_DELETED_DATA" command can be used to create a deleted sector, and the "READ_DELETED_DATA" command can be used to read one back.
 
==== Option bits ====
Line 571 ⟶ 555:
===== Bit MF =====
Value = 0x40. "MFM" magnetic encoding mode. Always set it for read/write/format/verify operations.
 
A zero value represents the old "single density" FM format, which (on IBM PCs) was only used by 8-inch floppies (which were extremely rare). Few people ever used FM format, except for data interchange with non-PC systems (such as CP/M or minicomputers). Later model FDCs (e.g. Intel 82078) dropped support for it.
 
===== Bit SK =====
Value = 0x20. Skip mode. IgnoreThis thisskips bit"deleted andsectors" leave(see itexplanation cleared,in unlesssection you have a really good reason not toabove).
 
Ignore this bit and leave it cleared, unless you have a really good reason not to.
 
==== Status Registers ====
Line 817 ⟶ 806:
The following code intentionally contains a common bug that causes an infinite loop (waiting for IRQ6) on most emulators.
 
<sourcesyntaxhighlight lang="c">
volatile byte ReceivedIRQ = false;
 
Line 841 ⟶ 830:
WaitForIRQ();
}
</syntaxhighlight>
</source>
 
Sure this code ''looks'' OK, but some emulators or floppy drives might manage to be faster than your code. What if you've just returned from
Line 847 ⟶ 836:
set it to false again and then infinitely loop, waiting for an IRQ that has already been received. It's usually better to do something like:
 
<sourcesyntaxhighlight lang="c">
volatile byte ReceivedIRQ = false;
 
Line 882 ⟶ 871:
outb(Controller.FIFO, headload_ndma);
}
</syntaxhighlight>
</source>
 
== Related Links ==
Line 904 ⟶ 893:
 
=== Implementations ===
* [httphttps://kodersgithub.com/cFDOS/fid051291340B94EC7F5D1A38EF6843466C0B07627Bkernel/blob/master/drivers/floppy.aspx?s=fdcasm freedosFreeDOS] (C, GPL)
* [http://bos.asmhackers.net/docs/floppy/snippet_9/fdc.c GazOS] (C, GPL)
* [http://bos.asmhackers.net/docs/floppy/snippet_5/FLOPPY.ASM RDOS] (Assembly, GPL)
* [httphttps://wwwgithub.gelato.unsw.edu.aucom/torvalds/linux/lxrblob/sourcemaster/drivers/block/floppy.c Linux] (C, GPL)
 
[[de:Floppy Disk Controller]]