View Single Post
Old 29 October 2013, 10:57   #1
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Encoding and writing an MFM track

I'm currently thinking about implementing a disk-write routine for my game project, to be able to save highscores.

I will probably reserve a whole track for the highscores, to minimize the risk that any game data is damaged by write operations. My first plan was the following:

1. Read the track into the MFM buffer and save pointers to each of the 11 MFM sectors in a table (this already works in the loader).
2. Update the sectors I want to change in the MFM buffer.
3. Recalculate the number of sectors until the gap in each sector header.
4. Update header checksum and data checksum of all sectors.
5. Make sure there is a gap of 256 $aaaa words at the beginning and at the start of the track. Write the MFM buffer with DSKLEN = $1900 words.

When I thought about that some longer I realized that the track-gap could be a problem. Usually an MFM track has the following layout:
Code:
For each of the 11 sectors:
     4 Bytes with two $4489 sync words
    56 Bytes for the header (info field, label, checksums)
  1024 Bytes data
     4 Bytes sector gap ($aaaa, $aaaa)
It follows a gap with $aaaa words of variable length until the end of the track.
When I read a track the DMA starts at the first $4489 sync-word found, which can be any sector. This means that the gap could be somewhere in the middle of my MFM buffer. When I write the track back, with a gap at the beginning and end of the buffer, I will have two gaps and the track might become too large, right?

What is the recommended practice to write such a track? To reconstruct it from scratch? Or by shifting the sector data inside the MFM buffer to eliminate the gap?
phx is offline  
 
Page generated in 0.06880 seconds with 11 queries