[Project64] Cleanup FlashRam.cpp

This commit is contained in:
zilmar 2015-12-13 18:10:40 +11:00
parent 29d693ba1f
commit abcfe60a51
2 changed files with 195 additions and 197 deletions

View File

@ -15,15 +15,14 @@
#include <Common/path.h>
#include <Windows.h>
CFlashram::CFlashram(bool ReadOnly):
m_FlashRamPointer(NULL),
m_FlashFlag(FLASHRAM_MODE_NOPES),
m_FlashStatus(0),
m_FlashRAM_Offset(0),
m_ReadOnly(ReadOnly),
m_hFile(NULL)
CFlashram::CFlashram(bool ReadOnly) :
m_FlashRamPointer(NULL),
m_FlashFlag(FLASHRAM_MODE_NOPES),
m_FlashStatus(0),
m_FlashRAM_Offset(0),
m_ReadOnly(ReadOnly),
m_hFile(NULL)
{
}
CFlashram::~CFlashram()
@ -66,12 +65,12 @@ void CFlashram::DmaFromFlashram(uint8_t * dest, int StartOffset, int len)
}
return;
}
memset(FlipBuffer,0,sizeof(FlipBuffer));
memset(FlipBuffer, 0, sizeof(FlipBuffer));
StartOffset = StartOffset << 1;
SetFilePointer(m_hFile,StartOffset,NULL,FILE_BEGIN);
SetFilePointer(m_hFile, StartOffset, NULL, FILE_BEGIN);
DWORD dwRead;
ReadFile(m_hFile,FlipBuffer,len,&dwRead,NULL);
for (count = dwRead; (int)count < len; count ++)
ReadFile(m_hFile, FlipBuffer, len, &dwRead, NULL);
for (count = dwRead; (int)count < len; count++)
{
FlipBuffer[count] = 0xFF;
}
@ -99,7 +98,7 @@ void CFlashram::DmaFromFlashram(uint8_t * dest, int StartOffset, int len)
default:
if (bHaveDebugger())
{
g_Notify->DisplayError(stdstr_f(__FUNCTION__": Start: %X, Offset: %X len: %X",dest - g_MMU->Rdram(),StartOffset,len).ToUTF16().c_str());
g_Notify->DisplayError(stdstr_f(__FUNCTION__": Start: %X, Offset: %X len: %X", dest - g_MMU->Rdram(), StartOffset, len).ToUTF16().c_str());
}
}
}
@ -119,7 +118,6 @@ void CFlashram::DmaToFlashram(uint8_t * Source, int StartOffset, int len)
}
}
uint32_t CFlashram::ReadFromFlashStatus(uint32_t PAddr)
{
switch (PAddr)
@ -139,7 +137,7 @@ bool CFlashram::LoadFlashram()
{
CPath FileName;
FileName.SetDriveDirectory( g_Settings->LoadStringVal(Directory_NativeSave).c_str());
FileName.SetDriveDirectory(g_Settings->LoadStringVal(Directory_NativeSave).c_str());
FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str());
FileName.SetExtension("fla");
@ -148,15 +146,15 @@ bool CFlashram::LoadFlashram()
FileName.DirectoryCreate();
}
m_hFile = CreateFile(FileName,m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,
m_hFile = CreateFile(FileName, m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
if (m_hFile == INVALID_HANDLE_VALUE)
{
WriteTraceF(TraceError,__FUNCTION__ ": Failed to open (%s), ReadOnly = %d, LastError = %X",(LPCTSTR)FileName, m_ReadOnly, GetLastError());
WriteTraceF(TraceError, __FUNCTION__ ": Failed to open (%s), ReadOnly = %d, LastError = %X", (LPCTSTR)FileName, m_ReadOnly, GetLastError());
g_Notify->DisplayError(GS(MSG_FAIL_OPEN_FLASH));
return false;
}
SetFilePointer(m_hFile,0,NULL,FILE_BEGIN);
SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN);
return true;
}
@ -174,15 +172,15 @@ void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
case FLASHRAM_MODE_READ: break;
case FLASHRAM_MODE_STATUS: break;
case FLASHRAM_MODE_ERASE:
memset(EmptyBlock,0xFF,sizeof(EmptyBlock));
memset(EmptyBlock, 0xFF, sizeof(EmptyBlock));
if (m_hFile == NULL) {
if (!LoadFlashram())
{
return;
}
}
SetFilePointer(m_hFile,m_FlashRAM_Offset,NULL,FILE_BEGIN);
WriteFile(m_hFile,EmptyBlock,128,&dwWritten,NULL);
SetFilePointer(m_hFile, m_FlashRAM_Offset, NULL, FILE_BEGIN);
WriteFile(m_hFile, EmptyBlock, 128, &dwWritten, NULL);
break;
case FLASHRAM_MODE_WRITE:
if (m_hFile == NULL) {
@ -196,7 +194,7 @@ void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
register size_t edx;
uint8_t * FlashRamPointer = m_FlashRamPointer;
memset(FlipBuffer,0,sizeof(FlipBuffer));
memset(FlipBuffer, 0, sizeof(FlipBuffer));
for (edx = 0; edx < 128; edx += 4)
{
register uint32_t eax;
@ -206,12 +204,12 @@ void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
*(unsigned __int32 *)(FlipBuffer + edx) = eax;
}
SetFilePointer(m_hFile,m_FlashRAM_Offset,NULL,FILE_BEGIN);
WriteFile(m_hFile,FlipBuffer,128,&dwWritten,NULL);
SetFilePointer(m_hFile, m_FlashRAM_Offset, NULL, FILE_BEGIN);
WriteFile(m_hFile, FlipBuffer, 128, &dwWritten, NULL);
}
break;
default:
g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register\nm_FlashFlag: %d",FlashRAM_Command,m_FlashFlag).ToUTF16().c_str());
g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register\nm_FlashFlag: %d", FlashRAM_Command, m_FlashFlag).ToUTF16().c_str());
}
m_FlashFlag = FLASHRAM_MODE_NOPES;
break;
@ -240,7 +238,7 @@ void CFlashram::WriteToFlashCommand(uint32_t FlashRAM_Command)
default:
if (bHaveDebugger())
{
g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register",FlashRAM_Command).ToUTF16().c_str());
g_Notify->DisplayError(stdstr_f("Writing %X to flash ram command register", FlashRAM_Command).ToUTF16().c_str());
}
}
}

View File

@ -27,10 +27,10 @@ public:
CFlashram(bool ReadOnly);
~CFlashram();
void DmaFromFlashram ( uint8_t * dest, int StartOffset, int len );
void DmaToFlashram ( uint8_t * Source, int StartOffset, int len );
uint32_t ReadFromFlashStatus ( uint32_t PAddr );
void WriteToFlashCommand ( uint32_t Value );
void DmaFromFlashram(uint8_t * dest, int StartOffset, int len);
void DmaToFlashram(uint8_t * Source, int StartOffset, int len);
uint32_t ReadFromFlashStatus(uint32_t PAddr);
void WriteToFlashCommand(uint32_t Value);
private:
bool LoadFlashram();