[Project64] Remove windows.h from Eeprom.cpp

This commit is contained in:
zilmar 2016-01-27 20:39:46 +11:00
parent 26cb3c98c3
commit 94a7f2f8b5
2 changed files with 233 additions and 236 deletions

View File

@ -13,22 +13,15 @@
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64Class.h>
#include <time.h>
#include <Windows.h>
CEeprom::CEeprom(bool ReadOnly) :
m_ReadOnly(ReadOnly),
m_hFile(NULL)
m_ReadOnly(ReadOnly)
{
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
}
CEeprom::~CEeprom()
{
if (m_hFile)
{
CloseHandle(m_hFile);
m_hFile = NULL;
}
}
uint8_t byte2bcd(int32_t n)
@ -59,12 +52,18 @@ void CEeprom::EepromCommand(uint8_t * Command)
{
Command[1] |= 0x40;
if ((Command[1] & 3) > 0)
{
Command[3] = 0x00;
}
if ((Command[1] & 3) > 1)
{
Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0;
}
if ((Command[1] & 3) > 2)
{
Command[5] = 0x00;
}
}
else
{
Command[3] = 0x00;
@ -142,12 +141,9 @@ void CEeprom::EepromCommand(uint8_t * Command)
void CEeprom::LoadEeprom()
{
CPath FileName;
DWORD dwRead;
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
FileName.SetDriveDirectory(g_Settings->LoadStringVal(Directory_NativeSave).c_str());
CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), "");
FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str());
FileName.SetExtension("eep");
@ -156,23 +152,25 @@ void CEeprom::LoadEeprom()
FileName.DirectoryCreate();
}
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)
if (!m_File.Open(FileName, (m_ReadOnly ? CFileBase::modeRead : CFileBase::modeReadWrite) | CFileBase::modeNoTruncate | CFileBase::modeCreate))
{
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d, LastError = %X", (LPCTSTR)FileName, m_ReadOnly, GetLastError());
#ifdef _WIN32
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d, LastError = %X", (const char *)FileName, m_ReadOnly, GetLastError());
#else
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d", (const char *)FileName, m_ReadOnly);
#endif
g_Notify->DisplayError(GS(MSG_FAIL_OPEN_EEPROM));
return;
}
SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN);
ReadFile(m_hFile, m_EEPROM, sizeof(m_EEPROM), &dwRead, NULL);
m_File.SeekToBegin();
m_File.Read(m_EEPROM, sizeof(m_EEPROM));
}
void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line)
{
int32_t i;
if (m_hFile == NULL)
if (!m_File.IsOpen())
{
LoadEeprom();
}
@ -185,10 +183,9 @@ void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line)
void CEeprom::WriteTo(uint8_t * Buffer, int32_t line)
{
DWORD dwWritten;
int32_t i;
if (m_hFile == NULL)
if (!m_File.IsOpen())
{
LoadEeprom();
}
@ -196,7 +193,7 @@ void CEeprom::WriteTo(uint8_t * Buffer, int32_t line)
{
m_EEPROM[line * 8 + i] = Buffer[i];
}
SetFilePointer(m_hFile, line * 8, NULL, FILE_BEGIN);
WriteFile(m_hFile, Buffer, 8, &dwWritten, NULL);
FlushFileBuffers(m_hFile);
m_File.Seek(line * 8, CFile::begin);
m_File.Write(Buffer, 8);
m_File.Flush();
}

View File

@ -31,5 +31,5 @@ private:
uint8_t m_EEPROM[0x800];
bool m_ReadOnly;
void * m_hFile;
CFile m_File;
};