5. Step 2: Seek

bool SeekCylinder(byte Head, byte Cylinder);

SeekCylinder tells the floppy drive to position the head specified by Head over the cylinder specified by Cylinder. A floppy drive cannot read a sector if the head for that sector is not positioned over the correct cylinder. It may take several tries before the seek command succeeds.


Code

bool Floppy::SeekCylinder(byte Head, byte Cylinder) {
	unsigned int Tries = 0;

	while ((Tries < MaximumSeekTries) && (AtCylinder != Cylinder)) {
		PendingInterrupt = true;

		if (SendData(cmdSeek)) {
			if (SendData((Head << cmdHeadShift) | DriveIndex)) {
				if (SendData(Cylinder)) {
					while(PendingInterrupt);

					if (!ReadStatus()) {
						AtCylinder = 255;		// Make sure we don't assume the cylinder is correct, since ReadStatus failed.
					}
				}
			}
		}

		Tries++;
	}

	return AtCylinder == Cylinder;
}