[64DD] Saving support (MAME dump format only)

Replaces the loaded dump file with the new saved content
This commit is contained in:
luigiblood 2016-05-24 21:26:05 +02:00
parent a00011b0f3
commit ea5c4abc09
3 changed files with 72 additions and 8 deletions

View File

@ -385,6 +385,13 @@ bool CN64System::EmulationStarting(CThread * thread)
WriteTrace(TraceN64System, TraceDebug, "Game starting"); WriteTrace(TraceN64System, TraceDebug, "Game starting");
g_BaseSystem->StartEmulation2(false); g_BaseSystem->StartEmulation2(false);
WriteTrace(TraceN64System, TraceDebug, "Game Done"); WriteTrace(TraceN64System, TraceDebug, "Game Done");
//PLACE TO ADD 64DD SAVING CODE
if (g_Disk != NULL)
{
g_Disk->SaveDiskImage();
//g_Notify->DisplayError(g_Disk->GetError());
WriteTrace(TraceN64System, TraceDebug, "64DD Save Done");
}
} }
catch (...) catch (...)
{ {

View File

@ -41,6 +41,40 @@ bool CN64Disk::LoadDiskImage(const char * FileLoc)
g_Settings->SaveBool(GameRunning_LoadingInProgress, false); g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
} }
m_FileName = FileLoc;
return true;
}
bool CN64Disk::SaveDiskImage()
{
ForceByteSwapDisk();
if (m_DiskFormat == DiskFormatMAME)
{
//If original file was MAME format, just copy
//SDK format protection
WriteTrace(TraceN64System, TraceDebug, "Trying to open %s", m_FileName);
m_DiskFile.Close();
if (!m_DiskFile.Open(m_FileName.c_str(), CFileBase::modeWrite))
{
WriteTrace(TraceN64System, TraceError, "Failed to open %s", m_FileName);
return false;
}
m_DiskFile.SeekToBegin();
if (!m_DiskFile.Write(m_DiskImage, MameFormatSize))
{
m_DiskFile.Close();
WriteTrace(TraceN64System, TraceError, "Failed to write file");
return false;
}
}
else if (m_DiskFormat == DiskFormatSDK)
{
//If original file was SDK format, we need to convert it back
}
m_DiskFile.Close();
return true; return true;
} }
@ -101,6 +135,7 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
if (DiskFileSize == MameFormatSize) if (DiskFileSize == MameFormatSize)
{ {
//If Disk is MAME Format (size is constant, it should be the same for every file), then continue //If Disk is MAME Format (size is constant, it should be the same for every file), then continue
m_DiskFormat = DiskFormatMAME;
WriteTrace(TraceN64System, TraceDebug, "Disk File is MAME Format"); WriteTrace(TraceN64System, TraceDebug, "Disk File is MAME Format");
if (!AllocateDiskImage(DiskFileSize)) if (!AllocateDiskImage(DiskFileSize))
@ -144,6 +179,8 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
{ {
//If Disk is SDK format (made with SDK based dumpers like LuigiBlood's, or Nintendo's, size is also constant) //If Disk is SDK format (made with SDK based dumpers like LuigiBlood's, or Nintendo's, size is also constant)
//We need to convert it. //We need to convert it.
m_DiskFormat = DiskFormatSDK;
g_Notify->DisplayMessage(5, MSG_LOADING); g_Notify->DisplayMessage(5, MSG_LOADING);
//Allocate supported size //Allocate supported size
@ -193,6 +230,21 @@ void CN64Disk::ByteSwapDisk()
} }
} }
void CN64Disk::ForceByteSwapDisk()
{
uint32_t count;
for (count = 0; count < m_DiskFileSize; count += 4)
{
m_DiskImage[count] ^= m_DiskImage[count + 3];
m_DiskImage[count + 3] ^= m_DiskImage[count];
m_DiskImage[count] ^= m_DiskImage[count + 3];
m_DiskImage[count + 1] ^= m_DiskImage[count + 2];
m_DiskImage[count + 2] ^= m_DiskImage[count + 1];
m_DiskImage[count + 1] ^= m_DiskImage[count + 2];
}
}
void CN64Disk::SetError(LanguageStringID ErrorMsg) void CN64Disk::SetError(LanguageStringID ErrorMsg)
{ {
m_ErrorMsg = ErrorMsg; m_ErrorMsg = ErrorMsg;

View File

@ -18,6 +18,7 @@ public:
~CN64Disk(); ~CN64Disk();
bool LoadDiskImage(const char * FileLoc); bool LoadDiskImage(const char * FileLoc);
bool SaveDiskImage();
static bool IsValidDiskImage(uint8_t Test[4]); static bool IsValidDiskImage(uint8_t Test[4]);
uint8_t * GetDiskAddress() { return m_DiskImage; } uint8_t * GetDiskAddress() { return m_DiskImage; }
uint8_t * GetDiskAddressBuffer() { return m_DiskImage + m_DiskBufAddress; } uint8_t * GetDiskAddressBuffer() { return m_DiskImage + m_DiskBufAddress; }
@ -30,11 +31,14 @@ private:
bool AllocateDiskImage(uint32_t DiskFileSize); bool AllocateDiskImage(uint32_t DiskFileSize);
bool AllocateAndLoadDiskImage(const char * FileLoc); bool AllocateAndLoadDiskImage(const char * FileLoc);
void ByteSwapDisk(); void ByteSwapDisk();
void ForceByteSwapDisk();
void SetError(LanguageStringID ErrorMsg); void SetError(LanguageStringID ErrorMsg);
void ConvertDiskFormat(); void ConvertDiskFormat();
void ConvertDiskFormatBack();
//constant values //constant values
enum { ReadFromRomSection = 0x400000, MameFormatSize = 0x0435B0C0, SDKFormatSize = 0x03DEC800 }; enum { ReadFromRomSection = 0x400000, MameFormatSize = 0x0435B0C0, SDKFormatSize = 0x03DEC800,
DiskFormatMAME = 0x0, DiskFormatSDK = 0x1 };
//class variables //class variables
CFile m_DiskFile; CFile m_DiskFile;
@ -44,6 +48,7 @@ private:
uint32_t m_DiskBufAddress; uint32_t m_DiskBufAddress;
LanguageStringID m_ErrorMsg; LanguageStringID m_ErrorMsg;
stdstr m_FileName, m_DiskIdent; stdstr m_FileName, m_DiskIdent;
uint8_t m_DiskFormat; //0 = MAME, 1 = SDK
//disk convert //disk convert
#define SECTORS_PER_BLOCK 85 #define SECTORS_PER_BLOCK 85