[Project64] Use standard types in Eeprom.cpp
This commit is contained in:
parent
64e0dae30f
commit
d740aaf350
|
@ -9,13 +9,16 @@
|
|||
* *
|
||||
****************************************************************************/
|
||||
#include "stdafx.h"
|
||||
#include "Eeprom.h"
|
||||
#include <Project64\N64 System\System Globals.h>
|
||||
#include <Project64\N64 System\N64 Class.h>
|
||||
#include <time.h>
|
||||
|
||||
CEeprom::CEeprom(bool ReadOnly):
|
||||
m_ReadOnly(ReadOnly),
|
||||
m_hFile(NULL)
|
||||
CEeprom::CEeprom(bool ReadOnly) :
|
||||
m_ReadOnly(ReadOnly),
|
||||
m_hFile(NULL)
|
||||
{
|
||||
memset(m_EEPROM,0xFF,sizeof(m_EEPROM));
|
||||
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
||||
}
|
||||
|
||||
CEeprom::~CEeprom()
|
||||
|
@ -27,13 +30,13 @@ CEeprom::~CEeprom()
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char byte2bcd(int n)
|
||||
uint8_t byte2bcd(int32_t n)
|
||||
{
|
||||
n %= 100;
|
||||
return (unsigned char)(((n / 10) << 4) | (n % 10));
|
||||
return (uint8_t)(((n / 10) << 4) | (n % 10));
|
||||
}
|
||||
|
||||
void CEeprom::EepromCommand ( BYTE * Command)
|
||||
void CEeprom::EepromCommand(uint8_t * Command)
|
||||
{
|
||||
time_t curtime_time;
|
||||
struct tm curtime;
|
||||
|
@ -64,7 +67,7 @@ void CEeprom::EepromCommand ( BYTE * Command)
|
|||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
@ -77,7 +80,7 @@ void CEeprom::EepromCommand ( BYTE * Command)
|
|||
{
|
||||
g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command");
|
||||
}
|
||||
ReadFrom(&Command[4],Command[3]);
|
||||
ReadFrom(&Command[4], Command[3]);
|
||||
break;
|
||||
case 5: //Write to Eeprom
|
||||
if (Command[0] != 10 && bHaveDebugger())
|
||||
|
@ -88,7 +91,7 @@ void CEeprom::EepromCommand ( BYTE * Command)
|
|||
{
|
||||
g_Notify->DisplayError(L"What am I meant to do with this Eeprom Command");
|
||||
}
|
||||
WriteTo(&Command[4],Command[3]);
|
||||
WriteTo(&Command[4], Command[3]);
|
||||
break;
|
||||
case 6: //RTC Status query
|
||||
Command[3] = 0x00;
|
||||
|
@ -131,7 +134,7 @@ void CEeprom::EepromCommand ( BYTE * Command)
|
|||
default:
|
||||
if (g_Settings->LoadDword(Debugger_ShowPifErrors))
|
||||
{
|
||||
g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d",Command[2]).ToUTF16().c_str());
|
||||
g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).ToUTF16().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,9 +144,9 @@ void CEeprom::LoadEeprom()
|
|||
CPath FileName;
|
||||
DWORD dwRead;
|
||||
|
||||
memset(m_EEPROM,0xFF,sizeof(m_EEPROM));
|
||||
memset(m_EEPROM, 0xFF, sizeof(m_EEPROM));
|
||||
|
||||
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("eep");
|
||||
|
||||
|
@ -152,47 +155,47 @@ 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,
|
||||
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_EEPROM));
|
||||
return;
|
||||
}
|
||||
SetFilePointer(m_hFile,0,NULL,FILE_BEGIN);
|
||||
ReadFile(m_hFile,m_EEPROM,sizeof(m_EEPROM),&dwRead,NULL);
|
||||
SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN);
|
||||
ReadFile(m_hFile, m_EEPROM, sizeof(m_EEPROM), &dwRead, NULL);
|
||||
}
|
||||
|
||||
void CEeprom::ReadFrom(BYTE * Buffer, int line)
|
||||
void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line)
|
||||
{
|
||||
int i;
|
||||
int32_t i;
|
||||
|
||||
if (m_hFile == NULL)
|
||||
{
|
||||
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(BYTE * Buffer, int line)
|
||||
void CEeprom::WriteTo(uint8_t * Buffer, int32_t line)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
int i;
|
||||
int32_t i;
|
||||
|
||||
if (m_hFile == NULL)
|
||||
{
|
||||
LoadEeprom();
|
||||
}
|
||||
for (i=0;i<8;i++)
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
m_EEPROM[line*8+i]=Buffer[i];
|
||||
m_EEPROM[line * 8 + i] = Buffer[i];
|
||||
}
|
||||
SetFilePointer(m_hFile,line*8,NULL,FILE_BEGIN);
|
||||
WriteFile( m_hFile,Buffer,8,&dwWritten,NULL );
|
||||
SetFilePointer(m_hFile, line * 8, NULL, FILE_BEGIN);
|
||||
WriteFile(m_hFile, Buffer, 8, &dwWritten, NULL);
|
||||
FlushFileBuffers(m_hFile);
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
* *
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
#include <Project64-core/Settings/Debug Settings.h>
|
||||
|
||||
class CEeprom :
|
||||
private CDebugSettings
|
||||
|
@ -17,14 +18,18 @@ public:
|
|||
CEeprom ( bool ReadOnly );
|
||||
~CEeprom();
|
||||
|
||||
void EepromCommand ( BYTE * Command );
|
||||
void EepromCommand ( uint8_t * Command );
|
||||
|
||||
private:
|
||||
void LoadEeprom ();
|
||||
void ReadFrom ( BYTE * Buffer, int line );
|
||||
void WriteTo ( BYTE * Buffer, int line );
|
||||
CEeprom(void); // Disable default constructor
|
||||
CEeprom(const CEeprom&); // Disable copy constructor
|
||||
CEeprom& operator=(const CEeprom&); // Disable assignment
|
||||
|
||||
BYTE m_EEPROM[0x800];
|
||||
void LoadEeprom ();
|
||||
void ReadFrom ( uint8_t * Buffer, int32_t line );
|
||||
void WriteTo ( uint8_t * Buffer, int32_t line );
|
||||
|
||||
uint8_t m_EEPROM[0x800];
|
||||
bool m_ReadOnly;
|
||||
HANDLE m_hFile;
|
||||
void * m_hFile;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue