trunk/docs/floppy.txt
| r245579 | r245580 | |
| 83 | 83 | A sensor detects when the head is on track 0 and the controller is not |
| 84 | 84 | supposed to try to go past it. In addition physical blocks prevent |
| 85 | 85 | the head from going out of the correct track range. Some systems |
| 86 | | (apple 2, some c64) do not take the track 0 sensor into account and |
| 86 | (Apple II, some C64) do not take the track 0 sensor into account and |
| 87 | 87 | just wham the head against the track 0 physical block, giving a |
| 88 | 88 | well-known crash noise and eventually damaging the head alignment. |
| 89 | 89 | |
| 90 | | Also, some systems (apple 2 and c64 again) have direct access to the |
| 90 | Also, some systems (Apple II and C64 again) have direct access to the |
| 91 | 91 | phases of the head positioning motor, allowing to trick the head into |
| 92 | 92 | going between tracks, in middle or even quarter positions. That was |
| 93 | 93 | not usable to write more tracks, since the head width did not change, |
| r245579 | r245580 | |
| 95 | 95 | it was used for some copy protection systems. |
| 96 | 96 | |
| 97 | 97 | The disk rotates at a fixed speed for a given track. The most usual |
| 98 | | speed is 300rpm for every track, with 360rpm found for HD 5.25" |
| 99 | | floppies and most 8" ones, and a number of different values like 90rpm |
| 100 | | for the earlier floppies or 150rpm for an HD floppy in an amiga. |
| 98 | speed is 300 rpm for every track, with 360 rpm found for HD 5.25" |
| 99 | floppies and most 8" ones, and a number of different values like 90 rpm |
| 100 | for the earlier floppies or 150 rpm for an HD floppy in an Amiga. |
| 101 | 101 | Having a fixed rotational speed for the whole disk is called Constant |
| 102 | 102 | Angular Velocity (CAV, almost everybody) or Zoned Constant Angular |
| 103 | 103 | Velocity (ZCAV, C64) depending on whether the read/write bitrate is |
| 104 | | constant or track-dependant. Some systems (apple 2, mac) varies the |
| 105 | | rotational speed depending on the track (something like 394rpm up to |
| 106 | | 590rpm) to end up with a Constant Linear Velocity (CLV). The idea |
| 104 | constant or track-dependant. Some systems (Apple II, Mac) vary the |
| 105 | rotational speed depending on the track (something like 394 rpm up to |
| 106 | 590 rpm) to end up with a Constant Linear Velocity (CLV). The idea |
| 107 | 107 | behind ZCAV/CLV is to get more bits out of the media by keeping the |
| 108 | 108 | minimal spacing between magnetic orientation transitions close to the |
| 109 | 109 | best the support can do. It seems that the complexity was not deemed |
| r245579 | r245580 | |
| 158 | 158 | 2.3 Floppy controller |
| 159 | 159 | |
| 160 | 160 | The task of the floppy controller is to turn the signals to/from the |
| 161 | | floppy drive into something the main cpu can digest. The level of |
| 161 | floppy drive into something the main CPU can digest. The level of |
| 162 | 162 | support actually done by the controller is extremely variable from one |
| 163 | | device to the other, from pretty much nothing (apple2, c64) through |
| 164 | | minimal (amiga) to complete (western digital chips, upd765 family). |
| 163 | device to the other, from pretty much nothing (Apple II, C64) through |
| 164 | minimal (Amiga) to complete (Western Digital chips, uPD765 family). |
| 165 | 165 | Usual functions include drive selection, motor control, track seeking |
| 166 | 166 | and of course reading and writing data. Of these only the last two |
| 167 | 167 | need to be described, the rest is obvious. |
| r245579 | r245580 | |
| 170 | 170 | or bytes) are encoded on the surface, and how these are grouped in |
| 171 | 171 | individually-addressable sectors. Two standards exist for these, |
| 172 | 172 | called FM and MFM, and in addition a number of systems use their |
| 173 | | home-grown variants. Moreover, some systems such as the amiga use a |
| 174 | | standard bit-level encoding (MFM) but an homegrown sector-level |
| 173 | home-grown variants. Moreover, some systems such as the Amiga use a |
| 174 | standard bit-level encoding (MFM) but a homegrown sector-level |
| 175 | 175 | organisation. |
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | 2.3.1 Bit-level encodings |
| 179 | 179 | 2.3.1.1 Cell organization |
| 180 | 180 | |
| 181 | | All floppy controllers, even the wonkiest like the apple 2 one, start |
| 181 | All floppy controllers, even the wonkiest like the Apple II one, start |
| 182 | 182 | by dividing the track in equally-sized cells. They're angular |
| 183 | 183 | sections in the middle of which a magnetic orientation inversion may |
| 184 | | be present. From an hardware point of view the cells are seen as |
| 184 | be present. From a hardware point of view the cells are seen as |
| 185 | 185 | durations, which combined with the floppy rotation give the section. |
| 186 | 186 | For instance the standard MFM cell size for a 3" double-density floppy |
| 187 | | is 2us, which combined with the also standard 300rpm rotational speed |
| 187 | is 2us, which combined with the also standard 300 rpm rotational speed |
| 188 | 188 | gives an angular size of 1/100000th of a turn. Another way of saying |
| 189 | 189 | it is that there are 100K cells in a 3" DD track. |
| 190 | 190 | |
| r245579 | r245580 | |
| 234 | 234 | same surface, hence its other name of "double density". The cell size |
| 235 | 235 | is set at slightly over half the physical limit, e.g. 2us usually. |
| 236 | 236 | The constraint means that two '1' cells must be separated by at least |
| 237 | | one '0' cell. Each bit is once again encoded on two cells: |
| 237 | one '0' cell. Each bit is once again encoded on two cells: |
| 238 | 238 | |
| 239 | 239 | - the first cell, called the clock bit, is '1' if both the previous |
| 240 | 240 | and current data bits are 0, '0' otherwise |
| r245579 | r245580 | |
| 252 | 252 | Group Coded Recording, or GCR, encodings are a class of encodings |
| 253 | 253 | where strings of bits at least nibble-size are encoded into a given |
| 254 | 254 | cell stream given by a table. It has been used in particular by the |
| 255 | | apple 2, the mac and the c64, and each system has its own table, or |
| 255 | Apple II, the Mac and the C64, and each system has its own table, or |
| 256 | 256 | tables. |
| 257 | 257 | |
| 258 | 258 | 2.3.1.5 Other encodings |
| r245579 | r245580 | |
| 342 | 342 | The crc is a cyclic redundancy check of the data bits starting with |
| 343 | 343 | the mark just after the pulse train using polynom 0x11021. |
| 344 | 344 | |
| 345 | | The western digital-based controllers usually get rid of everything |
| 345 | The Western Digital-based controllers usually get rid of everything |
| 346 | 346 | but some 0xff before the first sector and allow a better use of space |
| 347 | 347 | as a result. |
| 348 | 348 | |
| r245579 | r245580 | |
| 365 | 365 | - MFM-encoded 0xfb, sector data followed by two bytes of crc |
| 366 | 366 | - A number of MFM-encoded 0x4e (usually 84, very variable) |
| 367 | 367 | |
| 368 | | The the track is finished with a stream of MFM-encoded 0x4e. |
| 368 | The track is finished with a stream of MFM-encoded 0x4e. |
| 369 | 369 | |
| 370 | 370 | The 250KHz pulse trains are used to lock the PLL to the signal |
| 371 | 371 | correctly. The cell pattern 4489 does not appear in normal |
| 372 | 372 | MFM-encoded data and is used for clock/data separation. |
| 373 | 373 | |
| 374 | | As for FM, the western digital-based controllers usually get rid of |
| 374 | As for FM, the Western Digital-based controllers usually get rid of |
| 375 | 375 | everything but some 0x4e before the first sector and allow a better |
| 376 | 376 | use of space as a result. |
| 377 | 377 | |
| 378 | 378 | 2.3.2.3 Formatting and write splices |
| 379 | 379 | |
| 380 | | To be usable a floppy must have the sector headers and default sector |
| 380 | To be usable, a floppy must have the sector headers and default sector |
| 381 | 381 | data written on every track before using it. The controller starts |
| 382 | 382 | writing at a given place, often the index pulse but on some systems |
| 383 | 383 | whenever the command is sent, and writes until a complete turn is |
| r245579 | r245580 | |
| 417 | 417 | - 3, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing |
| 418 | 418 | |
| 419 | 419 | The position is in angular units of 1/200,000,000th of a turn. It |
| 420 | | corresponds to one nanosecond when the drive rotates at 300rpm. |
| 420 | corresponds to one nanosecond when the drive rotates at 300 rpm. |
| 421 | 421 | |
| 422 | 422 | The last cell implicit end position is of course 200,000,000. |
| 423 | 423 | |
| r245579 | r245580 | |
| 523 | 523 | int sectdata_size) |
| 524 | 524 | |
| 525 | 525 | Extract standard mfm or fm sectors from a regenerated |
| 526 | | cell stream. Sectors must point to an array of 256 desc_xs. |
| 526 | cell stream. Sectors must point to an array of 256 desc_xs. |
| 527 | 527 | |
| 528 | 528 | An existing sector is recognizable by having ->data non-null. |
| 529 | 529 | Sector data is written in sectdata up to sectdata_size bytes. |
| r245579 | r245580 | |
| 563 | 563 | |
| 564 | 564 | 3.3.1 Control signals |
| 565 | 565 | |
| 566 | | Due to the way they're usually connected to cpus (e.g. directly on an |
| 567 | | i/o port) the controls signals work with physical instead of logical |
| 566 | Due to the way they're usually connected to CPUs (e.g. directly on an |
| 567 | I/O port), the control signals work with physical instead of logical |
| 568 | 568 | values. Which means than in general 0 means active, 1 means inactive. |
| 569 | 569 | Some signals also have a callback associated called when they change. |
| 570 | 570 | |