Using floppy disc

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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Using floppy disc

Post by Brendan »

Hi,
Brandon wrote: Brendan:
Whats the CSH? And if I chose not to use DMA, how do I read the "next byte". I send a read command, wait for an IRC, but how do I recieve the next byte?
CHS = Cylinder, Head, Sector (where cylinder is 0 to ?, head is 0 to ? and sector is 1 to ?). To find a sector on a disk the hardware normally uses CHS, while most OSs use logical block addressing (LBA). This means that software that uses the floppy driver may request LBA sectors 0 to 33, which the device driver will need to convert into CHS format. My OS actually goes one step further and gets rid of blocks/sectors, so that software may ask the device driver for 3 bytes starting at any 64 bit logical offset between 0 and 1474556 (assuming a 1440 Kb floppy).

Brandon wrote: Can I only park the head at a cylinder and not "closer" to where I want?
As the disk spins every sector on both sides of the disk that is within the selected cylinder passes the heads. Half of the sectors pass by the top head, and the other half of them pass by the bottom head. It would be physically impossible to get the heads closer, unless you clamp the disk in between them (like the front brakes on a bicycle), which would scratch/destroy the data.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Brandon

Re:Using floppy disc

Post by Brandon »

thanks ;D
How do I read the data? From which port and so on..

One thing I thougut about.. If I have a multitasking system, and I got three different programs reading from a floppy(multitasking)? How do I do that? (there is not 3 heads). Do I manage that? Do I have to do a seek when the first programs starts, read a little bit, do another seek when the other programs run, and then move the head back to where it was and continue reading and so on...
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Using floppy disc

Post by Neo »

You could use a queue for each device and just queue up the requests for that device there then service them according to some priority.
Only Human
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Using floppy disc

Post by Brendan »

Hi,
Neo wrote: You could use a queue for each device and just queue up the requests for that device there then service them according to some priority.
A queue would be good as it also allows you to do the requests out of order (to minimize seek times, etc).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Brandon

Re:Using floppy disc

Post by Brandon »

Do you guys know anyplace where I can find how to read/write to the floppy? The initialization/ start the motor / seek / works now... Just need to read/write (and I?m not very familiar with DMA)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Using floppy disc

Post by Brendan »

Hi,
Brandon wrote: Do you guys know anyplace where I can find how to read/write to the floppy? The initialization/ start the motor / seek / works now... Just need to read/write (and I?m not very familiar with DMA)
Download the 82078 FDC datasheet from here (scroll down to the floppy section):
http://www.o3one.org/hwdocs_.html

Once you've downloaded it read it from start to finish (except the pinouts and electrical timing stuff).


Read and write are very similar - the only differences are the direction of the DMA transfer and the command used to start them:

Set data rate (if not already set)
Send the specify command (if necessary)
Clear the time that the "motor off" delay should expire
Start the floppy motor (if not already running)
Seek to correct track/cylinder (if not already there)
Setup DMA transfer using "single mode", autoinitialization disabled and DMA channel 2
Send the command:
The command byte (read/write, multi-track or not, MFM usually set to 1, SK usually set to 1)
Head/drive
Starting Cylinder
Starting Head (again)
Starting Sector
Bytes per sector code (where 2 = 512 bytes)
Sectors per track (18 for 1440 Kb floppy)
Intersector gap length (more on this later)
Sector size (set to 0xFF unless you use 128 byte sectors)
Wait for an IRQ (sent when the DMA transfer is complete)
Read the 7 status bytes and check if everything worked
Set the time that the "motor off" delay should expire

For everything you find confusing in the list above, refer to the 82078 FDC datasheet. The only things that the datasheet won't explain too well is the "Intersector gap length", and the values used for the specify command (SRT, HUT, HLT).

When a sector of data is stored on the disk there's several different components, which are seperated by several different gaps. There's a gap between sectors, a sector start marker, another gap, then some sector addressing data (cylinder, head, sector, etc) used by the hardware to check if it's in the right place, then there's another gap followed by the actual data (then a CRC and the intersector gap again). It looks a bit like this:

...intersector gap | marker | gap1 | preamble | gap2 | data | intersector gap..

Now, when you are formatting a track you specify how long the intersector gap (or the amount of space between sectors) should be, called gap3. This value can be taken from Table 6-8 on page 37 of the 82078 FDC datasheet (in the GPL2 column). When data is being read or written the intersector gap is also needed, but you tell it something shorter so that the floppy drive starts looking for the start of sector marker before it's too late. For this use the GPL1 column in Table 6-8. As these gaps waste space it's possible to reduce the size of the gap in order to squeeze a few extra sectors in (if the floppy is quick enough to handle it. Using this method it's possible to format a 1440 Kb disk as 1680 Kb by squeezing in 21 sectors instead of 18 (all standard warnings apply).

That only leaves the specifiy command. The values you'd need to figure out are:
SRT - Step Rate Time
HUT - Head Unload Time
HLT - Head Load Time

The SRT is the amount of time that should be allowed for the head to move from one track to another (usually around 8 mS). The HUT is the amount of time it takes to unload the head after reading/writing (usually 250 mS). The HLT is the amount of time it takes to get the head ready to start a reading/writing (usually 16 mS). Unfortunately all of these times are based on the frequency of the data rate, so every time the data rate changes these values would also need to be changed. There are some little tables (Table 6-14 and Table 6-15 on page 41), but they don't give enough detail, so here's my magic formulas to convert SRT, HLT & HUT into actual delays (in mS):

STEPmS = 500*(16 - SRT)/DataRate

if(HUT == 0) HUTtemp = 16
else HUTtemp = HUT
HUTmS = 8000*HUTtemp/DataRate

if(HLT == 0) HLTtemp = 128
else HLTtemp = HLT
HLTmS = 1000*HLTtemp/DataRate

Use these formulas (spreadsheets are good) to find the values that are closest to the delay you want.

I generally send the specify command each time I change the data rate, for e.g.:

setDataRate(rate) {
if(currentRate != rate) {
..set the data rate..
..send the specify command..
}
}

This makes it easier to support multiple floppy drives attached to the same controller, where the data rates might be different for each. Also, if you will be supporting multiple disk formats it's good to have a table/structure containing all the details for each format (name string, data rate, heads, sectors per track, tracks, gap lengths, total size, etc).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Brandon

Re:Using floppy disc

Post by Brandon »

thank you :) understand it much better now.. I suppose it?ll do if I set the data rate to 500 by sending a zero to the CCR?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Using floppy disc

Post by Brendan »

Hi,
Brandon wrote: I suppose it?ll do if I set the data rate to 500 by sending a zero to the CCR?
If you only want to support 1440 Kb and 1200 Kb floppy formats, then you could set the data rate to 500 and forget about it. If you want to support smaller floppy formats and/or 2880 Kb floppies (when the disk drive can handle the larger media) then you'd need to set the data rate according to what the disk media needs, and take care of the case where there's 2 floppy drives with different media/data rates.

I tend to support the smaller floppy formats as I find the 1440 Kb floppies aren't very reliable when formatted as 1440 Kb floppies.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply