[64DD] Saving support (MAME dump format only)
Replaces the loaded dump file with the new saved content
This commit is contained in:
parent
a00011b0f3
commit
ea5c4abc09
|
@ -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 (...)
|
||||||
{
|
{
|
||||||
|
@ -411,11 +418,11 @@ void CN64System::StartEmulation2(bool NewThread)
|
||||||
StartLog();
|
StartLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Setting up system");
|
WriteTrace(TraceN64System, TraceDebug, "Setting up system");
|
||||||
CInterpreterCPU::BuildCPU();
|
CInterpreterCPU::BuildCPU();
|
||||||
|
|
||||||
uint32_t CpuType = g_Settings->LoadDword(Game_CpuType);
|
uint32_t CpuType = g_Settings->LoadDword(Game_CpuType);
|
||||||
WriteTrace(TraceN64System, TraceDebug, "CpuType = %d",CpuType);
|
WriteTrace(TraceN64System, TraceDebug, "CpuType = %d",CpuType);
|
||||||
if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled))
|
if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled))
|
||||||
{
|
{
|
||||||
g_Settings->SaveDword(Game_CpuType, CPU_Recompiler);
|
g_Settings->SaveDword(Game_CpuType, CPU_Recompiler);
|
||||||
|
@ -440,7 +447,7 @@ void CN64System::StartEmulation2(bool NewThread)
|
||||||
m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation);
|
m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Setting system as active");
|
WriteTrace(TraceN64System, TraceDebug, "Setting system as active");
|
||||||
bool bSetActive = true;
|
bool bSetActive = true;
|
||||||
if (m_SyncCPU)
|
if (m_SyncCPU)
|
||||||
{
|
{
|
||||||
|
@ -454,13 +461,13 @@ void CN64System::StartEmulation2(bool NewThread)
|
||||||
|
|
||||||
if (!bSetActive)
|
if (!bSetActive)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceN64System, TraceWarning, "Failed to set system as active");
|
WriteTrace(TraceN64System, TraceWarning, "Failed to set system as active");
|
||||||
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
|
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
|
||||||
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
|
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Starting emulation thread");
|
WriteTrace(TraceN64System, TraceDebug, "Starting emulation thread");
|
||||||
StartEmulationThead();
|
StartEmulationThead();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,10 +475,10 @@ void CN64System::StartEmulation2(bool NewThread)
|
||||||
{
|
{
|
||||||
//mark the emulation as starting and fix up menus
|
//mark the emulation as starting and fix up menus
|
||||||
g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED);
|
g_Notify->DisplayMessage(5, MSG_EMULATION_STARTED);
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Start Executing CPU");
|
WriteTrace(TraceN64System, TraceDebug, "Start Executing CPU");
|
||||||
ExecuteCPU();
|
ExecuteCPU();
|
||||||
}
|
}
|
||||||
WriteTrace(TraceN64System, TraceDebug, "Done");
|
WriteTrace(TraceN64System, TraceDebug, "Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CN64System::StartEmulation(bool NewThread)
|
void CN64System::StartEmulation(bool NewThread)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue