Disc-overing Disc Drives
written by Geoff Jones / SUC/UK
Source: SUC-magazine June 1986, Volume 5, Number 3, pp. 36 - 39
Sharp Users Club - MZ-80K Section - Disk Drive Secrets / 01
The MZ-80K drives are double-sided, single-density, 35 tracks per side. This differs from the industry norm of 40 tracks per side, even though the Sharp drives are Shugart compatible. By this I mean that they can in fact be plugged into almost any computer that uses a Shugart type interface, because the 34-way ribbon cable connector at the rear of the drives is pin-compatible with the Shugart industry standard. I use my Sharp drives for both my MZ-80K and my BBC computer ( sorry to mention that, but I craved for hi-res colour graphics ).
Double-sided means that there are tracks on each side of the disc; 35 on each side in this case, though to the software they are referred to as tracks 0 to 69. Each track is made up of 16 sectors. Single-density means that each of these 16 sectors is 128 bytes long ( double-density would mean that each sector would be 256 bytes long ). The Sharp drives cannot be converted to 40-track on the MZ-80K, as the mechanical bits and pieces inside the drive will move too far. This is because the floppy-disc controller chip and its associated worm drive move the head too far between tracks. I found this out when I had my drives connected to the BBC and tried to format a disc with 40 tracks; the result was horrible grinding noises!! I now use discs formatted to 35 tracks per side on my BBC.
The discs rotate at approximately 300 r.p.m. and when switched on by the software are given about half a second to get up to speed. The heads are lowered onto the discs whenever the drives are started, but only if the drive doors are shut, as the heads are mechanically interlocked with the doors.
In any read or write operation the heads are always driven to the track 0 position to start with; this position is detected by a switch, to enable an accurate starting-point to be set on each occasion. The software then sends the head to the required track. The floppy-disc controller then looks for the index hole that is punched through the disc to obtain an accurate reading for locating the sectors, and then counts up to the sector required.
The format of the discs, that is where the tracks are on the disc and where each sector is located, is determined by the initialization program supplied with the master disc. This program tells the floppy-disc controller to write markers on the disc to number the sectors 00 - 0FH. The tracks are numbered by hardware, as track 0 is at the outside edge of the slot visible in the black protective cover, and track 35 is at the inside edge of this slot; each track is 1 or 2 steps of the motor apart.
The user program space is thus ( 55 tracks ) * ( 16 sectors ) * ( 128 bytes ), which gives a theoretical 112,640 bytes on the master disc. On a slave disc, as there is no Disc Basic, tracks are free from 4 upwards, giving 66 * 16 * 128 or 135,168 theoretical bytes. Both these figures are very slightly reduced in practice by the fact that 2 bytes of each sector are used to store the track and sector number of that particular sector.
The bootstrap loader program contained on track 0 makes a disc a master disc i.e. one that may be booted from the Monitor. When you respond to the BOOT DRIVE prompt on the screen, a jump to F000H is executed by the Monitor program. At this address is a ROM which is part of the disc drive interface card. The program contained in this ROM loads the track 0 program ( known as a bootstrap loader ) into memory locations 9800H upwards, and executes it; this program in turn decides which program on the disc is loaded and executed. On the Sharp master disc it is of course Disc Basic, which is loaded into 1200H upwards.
On the Directory tracks ( 1 - 3 ) there are 64 bytes allocated to each entry. The actual directory format is:-
A file is deleted from the directory by setting the file type byte to 00.
For those of you who like a little excitement in your lives, you can control the discs, without any fear of damage, by writing to the relevant I/O ports. I say without fear of damage because the hardware built into the disc drives and the floppy-disc controller card protect the disc at all times. The only thing that can go seriously wrong is that you might erase or write over a program on a disc in the drives at the time; so make sure you only experiment with duplicate or unwanted discs!! There is one other minor problem, which is not being able to switch the drives off; if this happens, switch off the power to the drives or the I/O box for a few seconds; this will reset the drives to normal working.
Controlling the drives accurately enough to maintain data reliability is a very complex feat of machine-code real-time programming, which means that the commands for actually controlling the drives through the I/O ports cannot be implemented in Basic, but must be done in Assembly language or machine-code direct. The Z80 has special commands for handling the input and output ports, namely IN and OUT. The MZ-80K uses 4 ports to access the floppy-disc drives, these are F8H, F9H, FAH, and FBH. For the brave amongst you here are the commands for switching the drives on and off, moving the heads, reading the floppy-disc-controller registers, and reading and writing to the discs:-
Most of these commands are used whenever you read or write to a disc;
its just a matter of using them in the correct order to perform
the desired function, and testing the registers to ensure that the disc
drive is ready to carry out the next step.