SOFTWARE
The .D64 format - part 1 by Francesco Fiorentini If you have ever used a Commodore 64 emulator, you may be familiar with the D64 format. Using a D64 file in an emulator is quite easy: pick up the file, load it into the emulator and then use it as a normal C64 floppy disk in a real 1541 Disk Drive. The emulator will take care of the file and treat it as a real ‘physical’ C64 floppy disk.
read from) the disk. Every disk is divided in 4 areas with a different clock rate. Without overcomplicating our article with tedious math calculations, the 4 different clock rates do generate 4 different areas containing a number of sectors per track (see Table 1).
Nothing really fancy so far, we are all used to work with emulators… but if you are still reading this article, it means you want to know more about the structure of a D64 file and how it works. Additionally, since a D64 is the physical representation of a 1541’s single-sided disk in a file format, knowing its structure you can easily understand the functionality of a real Commodore 1541 Disk Drive. So let’s start our journey. During the formatting process, the 1541 DOS (Disk Operating System) organizes the disk surface in tracks and sectors. The sectors will be used to store information. The formatting creates a total of 35 concentric tracks, starting from 1 (the outermost one) up to 35 (the innermost one), then each track is divided into a variable number of sectors. Why is there a difference in the number of sectors per track? Does this mean the disk rotates with a different speed based on the header’s position? Not really, the disk always rotates at a constant speed of 300 rpm (round per minutes), the difference is provided by varying the clock rate at which data are written on (or
Table 1: Areas, tracks, sectors and clock rate Doing a quick sum of all the sectors of each area we get to know that the total number of sectors in a disk is 683. Every sector is 256 bytes long and it contains, other than the stored data, a header to identify the sector itself. By multiplying 683*256 we get the value of 174848 bytes which is theoretically the total storage capacity of a diskette formatted with a 1541. By dividing 174848 by 1028 (1k) we get 171KB which is exactly the size of a D64 file as shown by the host file system. But, wait a minute... Why did we use the word ‘theoretically’? Because the 1541 DOS reserves some space for itself. This space will be used to store data regarding the organization and management of the information contained in the disk (for example to keep track of which sectors contain data and which ones are still empty, the disk’s directory name and the amount of free space on the disk, etc.). The 1541 DOS uses the track number 18 to store this information, thus reducing the available space for user data to 169984 bytes, corresponding to 664 tracks (683-19) multiplied by 256 bytes. So, let us have a deeper look at the information stored in the track 18! BAM - Block Availability Map
1. Graphical representation of a 1541 disk (image from the book ‘Inside Commodore DOS’) RETROMAGAZINE ENGLISH YEAR 1 - ISSUE 0
The BAM or Block Availability Map is the place where the 1541 DOS keeps track of the used sectors (the ones that already contain data) and of the free sectors (the ones still available to store new data). The BAM is stored in the Page 11 of 40