atarijookie/ce-atari

Fix MSA floppy write function

Closed this issue · 4 comments

Related to #156 (Add floppy write support) we need to have support for MSA floppy images writing. The code already has the function for writing the MSA image to file, but it's commented out and not compilable at this moment... The functions I'm talking about are in this file:
https://github.com/atarijookie/ce-atari/blob/master/ce_main_app/floppy/msa.cpp

Things to do here:
1. Make msa.cpp compilable after uncommenting MSA_WriteDisk and MSA_FindRunOfBytes - using some gcc under linux or cygwin under windows

The current compilation issues are:

floppy/msa.cpp: In function bool MSA_WriteDisk(const char*, unsigned char*, int):
floppy/msa.cpp:330:70: error: ‘Floppy_FindDiskDetails’ was not declared in this scope
  Floppy_FindDiskDetails(pBuffer,ImageSize, &nSectorsPerTrack, &nSides);
                                                                      ^
floppy/msa.cpp:369:43: error: ‘do_put_mem_word’ was not declared in this scope
      do_put_mem_word(pMSABuffer, nBytesRun);
                                           ^
floppy/msa.cpp:381:53: error: ‘do_put_mem_word’ was not declared in this scope
     do_put_mem_word(pMSADataLength, nCompressedBytes);
                                                     ^
floppy/msa.cpp:386:51: error: ‘do_put_mem_word’ was not declared in this scope
     do_put_mem_word(pMSADataLength, nBytesPerTrack);
                                                   ^
floppy/msa.cpp:396:81: error: ‘File_Save’ was not declared in this scope
  nRet = File_Save(pszFileName,pMSAImageBuffer, pMSABuffer-pMSAImageBuffer, false);

2. Verify that floppy image saved using that function is the same as the one opened from disk before... The MSA image gets loaded like this:

bool FloppyImageMsa::loadImageIntoMemory(void)
{
    if(!FloppyImage::loadImageIntoMemory()) {
        return false;
    }

    long imageSize = 0;
    BYTE *pDiskBuffer = MSA_UnCompress(image.data, &imageSize);

    free(image.data);                           // free the memory which was used for file reading

    image.data = pDiskBuffer;                   // store pointer to buffer with decompressed image and size
    image.size = imageSize;
    
    if(image.data == NULL) {                    // if the MSA_UnCompress failed, error
        return false;
    }       

    return true;
}

So after that you call MSA_WriteDisk() on the data and see if the output and input file match...
MSA disk image for testing can be found here:
http://www.exxoshost.co.uk/atari/games/automation/files/A_019.zip

write support for MSA image is a bit complex, as the whole file needs to be changed even when only 1 sector is writter, because of the compression.

write support for MSA image is a bit complex, as the whole file needs to be changed even when only 1 sector is writter, because of the compression.

Unless we demand that the user supplies unpacked MSA images.

I will work on it :)

Your pull request has been merged to master, I made a minor changes to the code afterwards, but in general it looks OK.