******    .D64 files and the C64 disk format   *****                                                       
                                                                                                           
Sectors are 256 bytes. Sector 0 is at offset $00000 in the .d64 file.                                      
Sector 1 is at offset $00100 in the .d64 file, and so on.                                                  
                                                                                                           
A normal 1541-format disk is divided into 4 'zones' -                                                      
     zone 1 = tracks 1-17 with 21 sectors (numbered 0-20)                                                  
     zone 2 = tracks 18-24 with 19 sectors (numbered 0-18)                                                 
     zone 3 = tracks 25-30 with 18 sectors (numbered 0-17)                                                 
     zone 4 = tracks 31-35 with 17 sectors (numbered 0-16)                                                 
The directory lies on track 18.  The following info is for                                                 
track 18 -                                                                                                 
sector 0 =      Block Availability Map (bytes 00-8f, bitmapped)                                            
                bytes 90-9f = disk name (16 chars, space padded)                                           
                The first 2 bytes are track and sector to the                                              
                first directory block. Usually the first directory                                         
                block is the very next block on the disk                                                   
directory blocks:                                                                                          
                byte 0 = track of next directory block                                                     
                byte 1 = sector of next directory block                                                    
                bytes 2-31 = file entry #1                                                                 
                bytes 32-33 = unused (should be 0)                                                         
                bytes 34-63 = file entry #2                                                                
                bytes 64-65 = unused,  etc etc                                                             
The first byte of a file entry is the type of file ($82 = PRG,                                             
$81 = SEQ, $83 = USR, $80 = DEL, $84 = REL).  The next two bytes                                           
point to the track & sector of the first sector of the file.                                               
The next 16 bytes is the filename (padded).  The last two bytes                                            
(i.e. bytes 30 & 31) gives the block count of the file (in low                                             
byte/high byte format).                                                                                    
                                                                                                           
Each file block has 254 bytes of data, unless it is the last block. The                                    
first 2 bytes of each block are the track and sector of the next block.                                    
If the track is zero then this is the last block, and the sector # really                                  
tells the number of bytes used out of the 254 possible. The use count is                                   
the number of bytes used plus 1--so if the sector # has a $05, then really                                 
only $04 bytes were used out of the last block.                                                            
                                                                                                           
The directory is at offset $16500 in the .d64 files. Tracks references                                     
start at 1. Sector references start at 0. So if the first 2 bytes of a                                     
block are $06 04, the absolute location is at                                                              
    5 * $1500 + 4 * $100.                                                                                  
(5 because that's $06 minus 1. $1500 because at track $06 there are 21                                     
sectors per track, or $1500 bytes. 4 because that is the sector number,                                    
and $100 because that's the number of bytes in a sector.)                                                  
                                                                                                           
The disk has a total of 35 tracks. There are 17 trachs with 21 sectors (357                                
sectors total), 7 tracks with 19 sectors (133 sectors total), 6 tracks                                     
with 18 sectors (108 sectors total), and 5 tracks with 17 sectors (85                                      
sectors total). So total sectors per disk (or .d64 image) is                                               
  357+133+108+85 = 683 total, or 174,848 bytes total, which is the exact                                   
size of the .d64 files.                                                                                    