Issue 24

Nov/Dec 86

Next Article >>

<< Prev Article




For those of you who have gone from the 8-bit Atari computers to the 16-bit ST's there have been many surprises for you in the past few months and there are many (obvious) differences between the two systems. One of the great advantages of the ST is the ability to store 360k of data on a single sided disk. What joy! One of the initial disappointments is that, not knowing how this data is stored, you cannot play around with sector editors and the like as you used to on that old 810. Fear not, in this article we hope to point you in the right direction so that you can begin to understand how to get out of those disk problems that are bound to occur at some stage.


The ST disk is divided into 80 tracks (0 to 79) with 9 sectors per track (1 to 9) and is written in QUAD density (512 bytes per sector). When a disk is formatted, a Boot sector (track 0, sector 1), the File Allocation Table (starting at track 0, sector 2) and the Directory (track 1, sector 3) are established using all 18 sectors in the first two tracks. The remaining sectors (tracks 2 to 79, sectors 1 to 9) are initialised in pairs or by cluster with two sectors equalling one cluster. As a cluster is initialised, the File Allocation Table (F.A.T.) is updated to indicate the status of the cluster. This continues until all 351 data clusters have been completed. If a cluster cannot be formatted or initialised the corresponding entry in F.A.T. is marked 'not-available' and will remain that way until the disk is re-formatted or thrown away. If a cluster is marked as bad, the F.A.T. entry will contain a number between $FFO and $FF7. That range of numbers simply means the cluster is unusable and will never be used to store data.

The ST disk uses track 2, sector 1 through track 79, sector 9 to store any files that you write to the disk and all filenames are listed on the disk directory in the order they are entered. The directory is seven sectors long and has room for 112 entries with each entry being 32 bytes in length. Each entry contains the filename and extension, the files Attributes, the Time the last change was made to the file, the Date the last change was made, the number of the first cluster in the file and the length, in bytes, of the file. In addition there are 10 bytes that have been reserved for future use (Figure 1).

1) Filename 8 bytes bytes 0 to 7 
2) Filename Ext. 3 bytes bytes 8 to 10 
3) Attributes  1 byte byte 11
4) Reserved 10 bytes bytes 12 to 21
5) Time of last change  2 bytes bytes 22 and 23 
6) Date of last change 2 bytes bytes 24 and 25 
7) First Cluster number 2 bytes bytes 26 and 27 
8) File size (in bytes) 4 bytes bytes 28 and 31

Figure 1 ST Directory Fields


The Filename and Extension are the first two fields in each entry of the directory. They take up the first 11 bytes of an entry and follow the same format as the Atari 800 or the IBM PC, with one small exception. If the first character of an entry is $E5, the file has been deleted and is no longer available for your use. If no changes have been made to the disk since the file was deleted, it may be possible to recover it by using one of the many sector editors available.

The Attributes field is one byte long and contains a number that indicates any special or unique characteristics about this entry. There are only five bits of the entry used on the floppies at this time and they are listed in Figure 2. The next field is marked RESERVED and is 10 bytes long. This field will be filled with 00's on all disk entries and no plans for its use are known at this time.

The Time of Last Change field is 2 bytes long and is updated each time you write to a file. This field contains the HOURS, MINUTES and SECONDS of the last change to the file. This field is in the low byte, high byte format and uses all 16 bits. Starting with the highest bit, it uses 5 bits for the hour, 6 bits for the minutes and the last 5 bits for the seconds. The value in the seconds portion of the field must be multiplied by 2 to get the correct seconds count.

Bit 0 Read Only (not set if file is Read/Write)
Bit 1 Hidden
Bit 2 System
Bit 3 Volume Label (Name assigned to the disk)
Bit 4 Sub Directory (Folder name) 
Bit 5 Archive (this will be used on Hard Disks)
Bits 6 & 7  are not used at this time.

Figure 2 File Attributes

The Date of Last Change field is handled almost the same as the previous filed. This field is changed along with the Time of Last Change and is also in the low byte, high byte format. Starting with the highest bit, it uses 7 bits for the year, 4 bits for the month and the last 5 bits for the day. Don't be surprised when the year equals a 5 or 6 (as most files will) because the year stored has 1980 subtracted from it.

The First Cluster field contains the number of the first cluster used for the file. The cluster information is stored in high byte, low byte order and should never go above $15F since there are only 351 clusters.

The File Size field is a value equal to the number of bytes used in the file. This number divided by 1024 (1k) will tell you how many clusters are being used for the file (cluster * 2 = sectors).

The File Allocation Table (F.A.T.) starts on track 0, sector 2 and may be the most important table on the disk. F.A.T. is used to keep track of the sector linkage for all data sectors. It is also used for files listed in Folders (sub-directories, see Attributes). The F.A.T. is five sectors long and is valuable enough to have a duplicate table on the same disk. The location of the second F.A.T. is currently track 0, sector 7 but that is subject to change at any time.

The best way to think of F.A.T. is like a puzzle. Each entry of the F.A.T. is 12 bits long (not bytes) and the values range from $000 to $FFF (see Figure 3). Byte 0 of F.A.T. tells what density the disk is formatted in ($F7 is normal for a single sided disk) and bytes 1 and 2 will be $FF as they are not used. The rest of the table is used as follows. The F.A.T. from Figure 3 will be used for the examples but before beginning it should be pointed out that 12 bits per entry means that 2 entries equal 3 Hex characters (bytes). We will start with bytes 03, 04 and 50 for our first 2 entries (see fig. 3). Byte 03 will be bits 0 to 7 for the first 12 bit entry, and bits 0 to 3 of byte 04 will be bits 8 to 11 of the first entry. As you can see in the first example, the number is $FFF. In F.A.T., if an entry contains $FF8 to $FFF it means that the cluster is the last cluster of the file (EOF). Also, if an entry contains $FFO to $FF7 it means the cluster is not usable for some reason. Now, if you will return to byte 04 you will remember that we have only used 4 bits (0 to 3). Bits 4 to 7 of byte 04 will become bits 0 to 3 of the second entry and byte 05 will be used as bits 4 to 11. This entry indicates that cluster 4 will be the next cluster for this file and it continues in that manner for the rest of the table.


Now you know what cluster to look at, but maybe you want to know which track and sector that is. The quickest way I have come across is one of the following formulas.

a) To convert from Cluster to Track and Sector:

(((cluster + 9) * 2) - 1) /9 = track

(((cluster + 9) * 2) - (track * 9) = sector

b) To convert from Track and Sector to Cluster: (((track * 9) + sector) - 17) /2 = cluster

A brief explanation.

Data sectors start at track 2, sector 1. That means 18 sectors (or 9 clusters) have to be accounted for in the formula. Also there are 2 sectors per cluster so you must multiply by 2 at some point. Here is all there is to it. What cluster is track 22, sector 2?

(((22 * 9) + 3) - 17) /2 = 92

If there had been a remainder, it would have been the second sector in the cluster. That's all there is to it, but just so you can practise a little. a chart is included with some of the clusters marked with the track and sector (Figure 4).

This article appeared in an American newsletter
A.S.T.U.N of 6157 South 700 West, Murray, Utah 84123. 

The author is not credited.

Figure 3 F.A.T.

Figure 4 Tracks and Sectors = Clusters