[Project64] Remove windows.h from Eeprom.cpp
This commit is contained in:
parent
26cb3c98c3
commit
94a7f2f8b5
|
@ -1,202 +1,199 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* *
|
* *
|
||||||
* Project64 - A Nintendo 64 emulator. *
|
* Project64 - A Nintendo 64 emulator. *
|
||||||
* http://www.pj64-emu.com/ *
|
* http://www.pj64-emu.com/ *
|
||||||
* Copyright (C) 2012 Project64. All rights reserved. *
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
||||||
* *
|
* *
|
||||||
* License: *
|
* License: *
|
||||||
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include <Project64-core/N64System/Mips/Eeprom.h>
|
#include <Project64-core/N64System/Mips/Eeprom.h>
|
||||||
#include <Project64-core/N64System/SystemGlobals.h>
|
#include <Project64-core/N64System/SystemGlobals.h>
|
||||||
#include <Project64-core/N64System/N64Class.h>
|
#include <Project64-core/N64System/N64Class.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <Windows.h>
|
|
||||||
|
CEeprom::CEeprom(bool ReadOnly) :
|
||||||
CEeprom::CEeprom(bool ReadOnly) :
|
m_ReadOnly(ReadOnly)
|
||||||
m_ReadOnly(ReadOnly),
|
{
|
||||||
m_hFile(NULL)
|
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
||||||
{
|
}
|
||||||
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
|
||||||
}
|
CEeprom::~CEeprom()
|
||||||
|
{
|
||||||
CEeprom::~CEeprom()
|
}
|
||||||
{
|
|
||||||
if (m_hFile)
|
uint8_t byte2bcd(int32_t n)
|
||||||
{
|
{
|
||||||
CloseHandle(m_hFile);
|
n %= 100;
|
||||||
m_hFile = NULL;
|
return (uint8_t)(((n / 10) << 4) | (n % 10));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void CEeprom::EepromCommand(uint8_t * Command)
|
||||||
uint8_t byte2bcd(int32_t n)
|
{
|
||||||
{
|
time_t curtime_time;
|
||||||
n %= 100;
|
struct tm curtime;
|
||||||
return (uint8_t)(((n / 10) << 4) | (n % 10));
|
|
||||||
}
|
if (g_System->m_SaveUsing == SaveChip_Auto)
|
||||||
|
{
|
||||||
void CEeprom::EepromCommand(uint8_t * Command)
|
g_System->m_SaveUsing = SaveChip_Eeprom_4K;
|
||||||
{
|
}
|
||||||
time_t curtime_time;
|
|
||||||
struct tm curtime;
|
switch (Command[2])
|
||||||
|
{
|
||||||
if (g_System->m_SaveUsing == SaveChip_Auto)
|
case 0: // check
|
||||||
{
|
if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K)
|
||||||
g_System->m_SaveUsing = SaveChip_Eeprom_4K;
|
{
|
||||||
}
|
Command[1] |= 0x80;
|
||||||
|
break;
|
||||||
switch (Command[2])
|
}
|
||||||
{
|
if (Command[1] != 3)
|
||||||
case 0: // check
|
{
|
||||||
if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K)
|
Command[1] |= 0x40;
|
||||||
{
|
if ((Command[1] & 3) > 0)
|
||||||
Command[1] |= 0x80;
|
{
|
||||||
break;
|
Command[3] = 0x00;
|
||||||
}
|
}
|
||||||
if (Command[1] != 3)
|
if ((Command[1] & 3) > 1)
|
||||||
{
|
{
|
||||||
Command[1] |= 0x40;
|
Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0;
|
||||||
if ((Command[1] & 3) > 0)
|
}
|
||||||
Command[3] = 0x00;
|
if ((Command[1] & 3) > 2)
|
||||||
if ((Command[1] & 3) > 1)
|
{
|
||||||
Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0;
|
Command[5] = 0x00;
|
||||||
if ((Command[1] & 3) > 2)
|
}
|
||||||
Command[5] = 0x00;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
Command[3] = 0x00;
|
||||||
Command[3] = 0x00;
|
Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K ? 0x80 : 0xC0;
|
||||||
Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K ? 0x80 : 0xC0;
|
Command[5] = 0x00;
|
||||||
Command[5] = 0x00;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 4: // Read from Eeprom
|
||||||
case 4: // Read from Eeprom
|
if (Command[0] != 2 && bHaveDebugger())
|
||||||
if (Command[0] != 2 && bHaveDebugger())
|
{
|
||||||
{
|
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
||||||
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
}
|
||||||
}
|
if (Command[1] != 8 && bHaveDebugger())
|
||||||
if (Command[1] != 8 && bHaveDebugger())
|
{
|
||||||
{
|
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
||||||
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
}
|
||||||
}
|
ReadFrom(&Command[4], Command[3]);
|
||||||
ReadFrom(&Command[4], Command[3]);
|
break;
|
||||||
break;
|
case 5: //Write to Eeprom
|
||||||
case 5: //Write to Eeprom
|
if (Command[0] != 10 && bHaveDebugger())
|
||||||
if (Command[0] != 10 && bHaveDebugger())
|
{
|
||||||
{
|
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
||||||
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
}
|
||||||
}
|
if (Command[1] != 1 && bHaveDebugger())
|
||||||
if (Command[1] != 1 && bHaveDebugger())
|
{
|
||||||
{
|
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
||||||
g_Notify->DisplayError("What am I meant to do with this Eeprom Command");
|
}
|
||||||
}
|
WriteTo(&Command[4], Command[3]);
|
||||||
WriteTo(&Command[4], Command[3]);
|
break;
|
||||||
break;
|
case 6: //RTC Status query
|
||||||
case 6: //RTC Status query
|
Command[3] = 0x00;
|
||||||
Command[3] = 0x00;
|
Command[4] = 0x10;
|
||||||
Command[4] = 0x10;
|
Command[5] = 0x00;
|
||||||
Command[5] = 0x00;
|
break;
|
||||||
break;
|
case 7: //Read RTC block
|
||||||
case 7: //Read RTC block
|
switch (Command[3])
|
||||||
switch (Command[3])
|
{
|
||||||
{
|
case 0: //Block number
|
||||||
case 0: //Block number
|
Command[4] = 0x00;
|
||||||
Command[4] = 0x00;
|
Command[5] = 0x02;
|
||||||
Command[5] = 0x02;
|
Command[12] = 0x00;
|
||||||
Command[12] = 0x00;
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 1:
|
//read block, Command[2], Unimplemented
|
||||||
//read block, Command[2], Unimplemented
|
break;
|
||||||
break;
|
case 2: //Set RTC Time
|
||||||
case 2: //Set RTC Time
|
time(&curtime_time);
|
||||||
time(&curtime_time);
|
memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix
|
||||||
memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix
|
Command[4] = byte2bcd(curtime.tm_sec);
|
||||||
Command[4] = byte2bcd(curtime.tm_sec);
|
Command[5] = byte2bcd(curtime.tm_min);
|
||||||
Command[5] = byte2bcd(curtime.tm_min);
|
Command[6] = 0x80 + byte2bcd(curtime.tm_hour);
|
||||||
Command[6] = 0x80 + byte2bcd(curtime.tm_hour);
|
Command[7] = byte2bcd(curtime.tm_mday);
|
||||||
Command[7] = byte2bcd(curtime.tm_mday);
|
Command[8] = byte2bcd(curtime.tm_wday);
|
||||||
Command[8] = byte2bcd(curtime.tm_wday);
|
Command[9] = byte2bcd(curtime.tm_mon + 1);
|
||||||
Command[9] = byte2bcd(curtime.tm_mon + 1);
|
Command[10] = byte2bcd(curtime.tm_year);
|
||||||
Command[10] = byte2bcd(curtime.tm_year);
|
Command[11] = byte2bcd(curtime.tm_year / 100);
|
||||||
Command[11] = byte2bcd(curtime.tm_year / 100);
|
Command[12] = 0x00; // status
|
||||||
Command[12] = 0x00; // status
|
break;
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 8:
|
||||||
case 8:
|
//Write RTC, unimplemented
|
||||||
//Write RTC, unimplemented
|
if (g_Settings->LoadDword(Debugger_ShowPifErrors))
|
||||||
if (g_Settings->LoadDword(Debugger_ShowPifErrors))
|
{
|
||||||
{
|
g_Notify->DisplayError("Write RTC, unimplemented");
|
||||||
g_Notify->DisplayError("Write RTC, unimplemented");
|
}
|
||||||
}
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
if (g_Settings->LoadDword(Debugger_ShowPifErrors))
|
||||||
if (g_Settings->LoadDword(Debugger_ShowPifErrors))
|
{
|
||||||
{
|
g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).c_str());
|
||||||
g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).c_str());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void CEeprom::LoadEeprom()
|
||||||
void CEeprom::LoadEeprom()
|
{
|
||||||
{
|
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
||||||
CPath FileName;
|
|
||||||
DWORD dwRead;
|
CPath FileName(g_Settings->LoadStringVal(Directory_NativeSave).c_str(), "");
|
||||||
|
FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str());
|
||||||
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
FileName.SetExtension("eep");
|
||||||
|
|
||||||
FileName.SetDriveDirectory(g_Settings->LoadStringVal(Directory_NativeSave).c_str());
|
if (!FileName.DirectoryExists())
|
||||||
FileName.SetName(g_Settings->LoadStringVal(Game_GameName).c_str());
|
{
|
||||||
FileName.SetExtension("eep");
|
FileName.DirectoryCreate();
|
||||||
|
}
|
||||||
if (!FileName.DirectoryExists())
|
|
||||||
{
|
if (!m_File.Open(FileName, (m_ReadOnly ? CFileBase::modeRead : CFileBase::modeReadWrite) | CFileBase::modeNoTruncate | CFileBase::modeCreate))
|
||||||
FileName.DirectoryCreate();
|
{
|
||||||
}
|
#ifdef _WIN32
|
||||||
|
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d, LastError = %X", (const char *)FileName, m_ReadOnly, GetLastError());
|
||||||
m_hFile = CreateFile(FileName, m_ReadOnly ? GENERIC_READ : GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
|
#else
|
||||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d", (const char *)FileName, m_ReadOnly);
|
||||||
if (m_hFile == INVALID_HANDLE_VALUE)
|
#endif
|
||||||
{
|
g_Notify->DisplayError(GS(MSG_FAIL_OPEN_EEPROM));
|
||||||
WriteTrace(TraceN64System, TraceError, "Failed to open (%s), ReadOnly = %d, LastError = %X", (LPCTSTR)FileName, m_ReadOnly, GetLastError());
|
return;
|
||||||
g_Notify->DisplayError(GS(MSG_FAIL_OPEN_EEPROM));
|
}
|
||||||
return;
|
m_File.SeekToBegin();
|
||||||
}
|
m_File.Read(m_EEPROM, sizeof(m_EEPROM));
|
||||||
SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN);
|
}
|
||||||
ReadFile(m_hFile, m_EEPROM, sizeof(m_EEPROM), &dwRead, NULL);
|
|
||||||
}
|
void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line)
|
||||||
|
{
|
||||||
void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line)
|
int32_t i;
|
||||||
{
|
|
||||||
int32_t i;
|
if (!m_File.IsOpen())
|
||||||
|
{
|
||||||
if (m_hFile == NULL)
|
LoadEeprom();
|
||||||
{
|
}
|
||||||
LoadEeprom();
|
|
||||||
}
|
for (i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
for (i = 0; i < 8; i++)
|
Buffer[i] = m_EEPROM[line * 8 + i];
|
||||||
{
|
}
|
||||||
Buffer[i] = m_EEPROM[line * 8 + i];
|
}
|
||||||
}
|
|
||||||
}
|
void CEeprom::WriteTo(uint8_t * Buffer, int32_t line)
|
||||||
|
{
|
||||||
void CEeprom::WriteTo(uint8_t * Buffer, int32_t line)
|
int32_t i;
|
||||||
{
|
|
||||||
DWORD dwWritten;
|
if (!m_File.IsOpen())
|
||||||
int32_t i;
|
{
|
||||||
|
LoadEeprom();
|
||||||
if (m_hFile == NULL)
|
}
|
||||||
{
|
for (i = 0; i < 8; i++)
|
||||||
LoadEeprom();
|
{
|
||||||
}
|
m_EEPROM[line * 8 + i] = Buffer[i];
|
||||||
for (i = 0; i < 8; i++)
|
}
|
||||||
{
|
m_File.Seek(line * 8, CFile::begin);
|
||||||
m_EEPROM[line * 8 + i] = Buffer[i];
|
m_File.Write(Buffer, 8);
|
||||||
}
|
m_File.Flush();
|
||||||
SetFilePointer(m_hFile, line * 8, NULL, FILE_BEGIN);
|
|
||||||
WriteFile(m_hFile, Buffer, 8, &dwWritten, NULL);
|
|
||||||
FlushFileBuffers(m_hFile);
|
|
||||||
}
|
}
|
|
@ -1,35 +1,35 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* *
|
* *
|
||||||
* Project64 - A Nintendo 64 emulator. *
|
* Project64 - A Nintendo 64 emulator. *
|
||||||
* http://www.pj64-emu.com/ *
|
* http://www.pj64-emu.com/ *
|
||||||
* Copyright (C) 2012 Project64. All rights reserved. *
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
||||||
* *
|
* *
|
||||||
* License: *
|
* License: *
|
||||||
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Project64-core/Settings/DebugSettings.h>
|
#include <Project64-core/Settings/DebugSettings.h>
|
||||||
|
|
||||||
class CEeprom :
|
class CEeprom :
|
||||||
private CDebugSettings
|
private CDebugSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CEeprom(bool ReadOnly);
|
CEeprom(bool ReadOnly);
|
||||||
~CEeprom();
|
~CEeprom();
|
||||||
|
|
||||||
void EepromCommand(uint8_t * Command);
|
void EepromCommand(uint8_t * Command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CEeprom(void); // Disable default constructor
|
CEeprom(void); // Disable default constructor
|
||||||
CEeprom(const CEeprom&); // Disable copy constructor
|
CEeprom(const CEeprom&); // Disable copy constructor
|
||||||
CEeprom& operator=(const CEeprom&); // Disable assignment
|
CEeprom& operator=(const CEeprom&); // Disable assignment
|
||||||
|
|
||||||
void LoadEeprom();
|
void LoadEeprom();
|
||||||
void ReadFrom(uint8_t * Buffer, int32_t line);
|
void ReadFrom(uint8_t * Buffer, int32_t line);
|
||||||
void WriteTo(uint8_t * Buffer, int32_t line);
|
void WriteTo(uint8_t * Buffer, int32_t line);
|
||||||
|
|
||||||
uint8_t m_EEPROM[0x800];
|
uint8_t m_EEPROM[0x800];
|
||||||
bool m_ReadOnly;
|
bool m_ReadOnly;
|
||||||
void * m_hFile;
|
CFile m_File;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue