1541 disk & D64 image layout
Work in progress...
D64 image vs 1541 disk's :
Track and sector layout :
The standard 1541 disk has 35 circular tracks on a disk shapped storage surface with track 1 being on the outer edge of the disk and track 35 being on the inner edge.
Each track on the disk contains sectors with each sector containing 256 8bit bytes of information. Even though the physical size of the sectors decreases while still containg the 256 bytes of data to make up for the tracks being physically shorter and that the speed of the storage media passing by the read/write head increases the closer you get to the centre of the disk the amount of sectors per track varies the closer to the centre of the disk. Here is the track/sector layout -
Tracks 1 to 17 contain 21 sectors.
Tracks 18 to 24 contain 19 sectors.
Tracks 25 to 30 contain 18 sectors.
Tracks 31 to 35 contain 17 sectors.
Tracks 1 to 17 and tracks 19 to 35 tend to contain all the data and track 18 contains the disk's directory and BAM sector. The directory track and BAM sector will be discussed later.
Although the D64 image files doesn't contain physical tracks and sectors the data is set out to replicate the same layout.
The D64 file is a simple binary file containing 174,848 bytes of binary data where the very first byte of bianry data can be considered the start of track 1, sector 1 with the first 256 bytes being sector 1 and the 257th byte being the start of sector 2.
The first 5,376 (256 bytes multiplied by 21 sectors) bytes make up track 1, byte 5,377 is the first byte of the first sector on track 2.
How data is stored in each sector :
When a program is selected for loading etc the track and sector that contain the start of the file is obtained from the directory track
The first two bytes of data in each sector either indicate if the sector needs to link to another sector or if it is the last sector of the programs stored information.
If it has another sector to link to the first byte will contain the track number of the sector to be linked and the second byte will contain the sector number - (Order to be checked)
If it doesn't have a sector to be linked the first byte will contain the amount of bytes to be read in this sector to finish the program and the second byte will be 0 - (Order to be checked)
In the very first sector of the program the 3rd and 4th bytes will contain the memory address in little endian format of whre the program is to be loaded into memory. All other sectors except the first one contain program data except for the first two bytes.
For example, if the first four bytes of the first sector that contains a program read $05, $04, 01, 08 that would indicate that the current sector needs the sector number 4 on track 5 to be linked to this sector and all the data in the current sector is used, it would also indicate that the program should be loaded into memory at address $0801 as indicated by the 3rd and 4th bytes.
Then the linked sector 4 on track 5 might have $01, $00, $EA, $FF as it's first bytes. In this case the 2nd byte equaling $00 tells us that this is the last sector in this program and the 1st byte tells us we need to read one more byte. In this case the the third byte ($EA) is added to the program but the forth byte and any other bytes in the sector are ignored as we only need to read one more byte. If the first byte was $02 then we would read the 4th byte and $FF would be added to the program also.
The directory track :
The BAM sector :