29 October 2013, 10:57 | #1 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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. 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? |
29 October 2013, 11:06 | #2 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,182
|
Do you really want to go to all that trouble when you could simply incbin the Rob Northen routines? They're incredibly simple to call, and you just need to hand the function a chip memory buffer of approximately $3300 bytes plus a pointer to your data and tell it what track you want written.
Granted you would learn a lot from writing your own, but if it's simply to save high scores, I would save your effort for the game rather than low level disk I/O routines! |
29 October 2013, 11:15 | #3 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Standard method is to decode all sectors (and check checksums of all sectors), modify data, encode all sectors again, write track. Everyone does it this way.
|
29 October 2013, 12:31 | #4 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Hmmm... yes?
It's really not so much trouble. The trackloader is already working. Making it write tracks is only a small addition. Quote:
Quote:
|
||
29 October 2013, 12:33 | #5 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
And which ADKCON settings do I use for writing? AFAIK I need PRECOMP %00 for cylinders 0 to 39 and PRECOMP %01 for cylinders 40 to 79. Then I also set the FAST bit and... something else? |
|
29 October 2013, 12:48 | #6 | ||
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
IMHO this is the only easy way and there is no point in trying to optimize it. When MFM encoding track, encode it as a single track not as separate sectors: keep last bit of previous sector when starting to encode following sectors. (There are trackwriters that reset MFM encoding state after each sector which works but can result in illegal MFM patterns) Quote:
Remember to disable WORDSYNC when writing. It has undocumented side-effect: Start write with WORDSYNC enabled: Paula starts _reading_ from floppy without storing the data (just like it does when wordsynced read starts), write starts when wordsync register matches with data from disk: If track does not have any old wordsync markers: writing never starts, disk block interrupt never gets set. |
||
29 October 2013, 14:11 | #7 | ||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Maybe it is better in this case to shift MFM data around in the buffer? I will find out... Quote:
Quote:
Also important to know is that I have to set MFMPREC (bit 12) and FAST (bit 8) when writing. Quote:
The HRM made me think that WORDSYNC has no meaning in Write mode. |
||||
29 October 2013, 15:06 | #8 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
IMHO disk support should be as generic as possible, without special cases that are difficult to test. (depends on disk position etc..) |
|
29 October 2013, 15:27 | #9 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
You're right, but it's not performance which concerns me, but the need to store the data of a whole track in a buffer which I don't have.
|
29 October 2013, 15:48 | #10 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
You could do following trick: start short read DMA (just enough to read sector header), check sector number, if not last, repeat read. If last, start normal read, sectors will be in expected order
|
29 October 2013, 16:40 | #11 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
is there really sync words in front of each sector (does trackdisk.device also do this) ? I am pretty sure, I always used the sync to identify the start of the track, not a sector, and then always read/wrote complete tracks..
I must go home and check my old code :-) Last edited by hooverphonique; 29 October 2013 at 16:48. |
29 October 2013, 16:43 | #12 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
|
29 October 2013, 16:58 | #13 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
This is the usual way to read tracks, start long enough wordsynced DMA, first read sector is some random sector, use sector number in header to position decoded data correctly. |
|
29 October 2013, 23:03 | #14 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
yes.. looking at my old code (actually an old non-system loader which fits in the bootblock and loads an OFS amigados file :-), I also first read the whole track, then use the sync word to look for the next sector and decode a single byte to determine if it's the sector I'm looking for..
@phx are you sure you can't dig up the ~12KB chipmem you need for a trackbuffer? :-) the hardware ref manual has this to say about it: "If you have too little memory for track buffering (or for some other reason decide not to read a whole track at once), the disk hardware supports a limited set of sector-searching facilities. There is a register that may be polled to examine the disk input stream." |
30 October 2013, 10:33 | #16 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Ok, I followed the suggestion to recreate the MFM track from scratch.
The 12K Chip RAM for the MFM buffer are not a problem. I already allocated that for the loader. But now I allocated another 5.5K to buffer the 11 sectors for the track to be written. Fortunately that doesn't have to be Chip RAM. Maybe 5.5K doesn't sound that much. But it is just for saving a few bytes of high scores, and I have no other use for it. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom MFM & Dos tracks | BippyM | Coders. General | 25 | 25 January 2008 19:41 |
mfm/custom regs/track loader | snyp | Coders. General | 9 | 06 June 2006 19:42 |
MFM.DEVICE problem with escom floppy drive??? | CFou! | support.Hardware | 7 | 22 May 2006 00:22 |
Blitter MFM decoding | Photon | Coders. General | 14 | 16 March 2006 11:24 |
Winuae+IPF > MFM > Floppy | killergorilla | project.SPS (was CAPS) | 1 | 14 July 2004 13:04 |
|
|