Floppy Disk Controller: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Adding one more reference |
m Added LBA to CHS and vice versa equations |
||
Line 53: | Line 53: | ||
numbers are typically 0 to 79 inclusive, heads are 0 or 1, and sector numbers are 1 to 18 inclusive. Asking for sector number 0 |
numbers are typically 0 to 79 inclusive, heads are 0 or 1, and sector numbers are 1 to 18 inclusive. Asking for sector number 0 |
||
is always highly illegal and this is a major source of errors in prototype driver code. |
is always highly illegal and this is a major source of errors in prototype driver code. |
||
It is, however, much more logical to address things in LBA (Logical Block Addressing), as the first sector is at 0 (like an array). |
|||
Conversion between the two is rather simple. The equations are as follows: |
|||
''CYL = LBA / (HPC * SPT)'' |
|||
''HEAD = (LBA % (HPC * SPT)) / SPT'' |
|||
''SECT = (LBA % (HPC * SPT)) % SPT + 1'' |
|||
''LBA = ( ( CYL * HPC + HEAD ) * SPT ) + SECT - 1'' |
|||
This can be described in C with the following code: |
|||
<source lang="c"> |
|||
void lba_2_chs(uint32_t lba, uint16_t* cyl, uint16_t* head, uint16_t* sector) |
|||
{ |
|||
*cyl = lba / (2 * FLOPPY_144_SECTORS_PER_TRACK); |
|||
*head = ((lba % (2 * FLOPPY_144_SECTORS_PER_TRACK)) / FLOPPY_144_SECTORS_PER_TRACK); |
|||
*sector = ((lba % (2 * FLOPPY_144_SECTORS_PER_TRACK)) % FLOPPY_144_SECTORS_PER_TRACK + 1); |
|||
} |
|||
</source> |
|||
You would then send this data to the floppy controller. |
|||
=== DMA Data Transfers === |
=== DMA Data Transfers === |