mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
Handle FileIO Read/Write more like real hardware.
Fixes Issue 3761. Fixes Issue 1749. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6718 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
4bf07838a8
commit
63115ca2ef
@ -114,9 +114,8 @@ bool CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
|
|||||||
switch(_Mode)
|
switch(_Mode)
|
||||||
{
|
{
|
||||||
case ISFS_OPEN_READ: m_pFileHandle = fopen(m_Filename.c_str(), "rb"); break;
|
case ISFS_OPEN_READ: m_pFileHandle = fopen(m_Filename.c_str(), "rb"); break;
|
||||||
|
// "r+b" is technically wrong, but OPEN_WRITE should not truncate the file as "wb" does.
|
||||||
case ISFS_OPEN_WRITE: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break;
|
case ISFS_OPEN_WRITE: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break;
|
||||||
// MK Wii gets here corrupting its saves (truncating rksys.dat), however using rb+ mode works fine
|
|
||||||
// TODO : figure it properly...
|
|
||||||
case ISFS_OPEN_RW: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break;
|
case ISFS_OPEN_RW: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break;
|
||||||
default: PanicAlert("FileIO: Unknown open mode : 0x%02x", _Mode); break;
|
default: PanicAlert("FileIO: Unknown open mode : 0x%02x", _Mode); break;
|
||||||
}
|
}
|
||||||
@ -181,16 +180,23 @@ bool CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
|
|||||||
|
|
||||||
bool CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
|
bool CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
u32 ReturnValue = 0;
|
u32 ReturnValue = FS_EACCESS;
|
||||||
u32 Address = Memory::Read_U32(_CommandAddress + 0xC); // Read to this memory address
|
u32 Address = Memory::Read_U32(_CommandAddress + 0xC); // Read to this memory address
|
||||||
u32 Size = Memory::Read_U32(_CommandAddress + 0x10);
|
u32 Size = Memory::Read_U32(_CommandAddress + 0x10);
|
||||||
|
|
||||||
if (m_pFileHandle != NULL)
|
if (m_pFileHandle != NULL)
|
||||||
|
{
|
||||||
|
if (m_Mode == ISFS_OPEN_WRITE)
|
||||||
|
{
|
||||||
|
WARN_LOG(WII_IPC_FILEIO, "FileIO: Attempted to read 0x%x bytes to 0x%08x on write-only file %s", Size, Address, m_Name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
INFO_LOG(WII_IPC_FILEIO, "FileIO: Read 0x%x bytes to 0x%08x from %s", Size, Address, m_Name.c_str());
|
INFO_LOG(WII_IPC_FILEIO, "FileIO: Read 0x%x bytes to 0x%08x from %s", Size, Address, m_Name.c_str());
|
||||||
ReturnValue = (u32)fread(Memory::GetPointer(Address), 1, Size, m_pFileHandle);
|
ReturnValue = (u32)fread(Memory::GetPointer(Address), 1, Size, m_pFileHandle);
|
||||||
if ((ReturnValue != Size) && ferror(m_pFileHandle)) ReturnValue = FS_EACCESS;
|
if ((ReturnValue != Size) && ferror(m_pFileHandle)) ReturnValue = FS_EACCESS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ERROR_LOG(WII_IPC_FILEIO, "FileIO: Failed to read from %s (Addr=0x%08x Size=0x%x) - file not open", m_Name.c_str(), Address, Size);
|
ERROR_LOG(WII_IPC_FILEIO, "FileIO: Failed to read from %s (Addr=0x%08x Size=0x%x) - file not open", m_Name.c_str(), Address, Size);
|
||||||
@ -202,13 +208,19 @@ bool CWII_IPC_HLE_Device_FileIO::Read(u32 _CommandAddress)
|
|||||||
|
|
||||||
bool CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
bool CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
u32 ReturnValue = 0;
|
u32 ReturnValue = FS_EACCESS;
|
||||||
u32 Address = Memory::Read_U32(_CommandAddress + 0xC); // Write data from this memory address
|
u32 Address = Memory::Read_U32(_CommandAddress + 0xC); // Write data from this memory address
|
||||||
u32 Size = Memory::Read_U32(_CommandAddress + 0x10);
|
u32 Size = Memory::Read_U32(_CommandAddress + 0x10);
|
||||||
|
|
||||||
INFO_LOG(WII_IPC_FILEIO, "FileIO: Write 0x%04x bytes from 0x%08x to %s", Size, Address, m_Name.c_str());
|
INFO_LOG(WII_IPC_FILEIO, "FileIO: Write 0x%04x bytes from 0x%08x to %s", Size, Address, m_Name.c_str());
|
||||||
|
|
||||||
if (m_pFileHandle)
|
if (m_pFileHandle)
|
||||||
|
{
|
||||||
|
if (m_Mode == ISFS_OPEN_READ)
|
||||||
|
{
|
||||||
|
WARN_LOG(WII_IPC_FILEIO, "FileIO: Attempted to write 0x%x bytes from 0x%08x to read-only file %s", Size, Address, m_Name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
size_t Result = fwrite(Memory::GetPointer(Address), Size, 1, m_pFileHandle);
|
size_t Result = fwrite(Memory::GetPointer(Address), Size, 1, m_pFileHandle);
|
||||||
#if MAX_LOGLEVEL >= DEBUG_LEVEL
|
#if MAX_LOGLEVEL >= DEBUG_LEVEL
|
||||||
@ -218,6 +230,7 @@ bool CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
|
|||||||
#endif
|
#endif
|
||||||
ReturnValue = (Result == 1) ? Size : FS_EACCESS;
|
ReturnValue = (Result == 1) ? Size : FS_EACCESS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
|
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user