summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorj4ck.fr0st <j4ck.fr0st@gmail.com>2011-01-02 00:01:19 +0000
committerj4ck.fr0st <j4ck.fr0st@gmail.com>2011-01-02 00:01:19 +0000
commit63115ca2ef440de77ab056b4577ba777b87f57e7 (patch)
treeb4d3923c30c9265c01a6b7be15e2d54cb4540662 /Source/Core
parent4bf07838a827cbc62f0d166b30763e7730cf8b4f (diff)
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
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
index 39059ffc4f..f4ffcb478a 100644
--- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
+++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
@@ -114,9 +114,8 @@ bool CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
switch(_Mode)
{
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;
- // 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;
default: PanicAlert("FileIO: Unknown open mode : 0x%02x", _Mode); break;
}
@@ -181,15 +180,22 @@ bool CWII_IPC_HLE_Device_FileIO::Seek(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 Size = Memory::Read_U32(_CommandAddress + 0x10);
if (m_pFileHandle != NULL)
{
- 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);
- if ((ReturnValue != Size) && ferror(m_pFileHandle)) ReturnValue = FS_EACCESS;
+ 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());
+ ReturnValue = (u32)fread(Memory::GetPointer(Address), 1, Size, m_pFileHandle);
+ if ((ReturnValue != Size) && ferror(m_pFileHandle)) ReturnValue = FS_EACCESS;
+ }
}
else
{
@@ -202,7 +208,7 @@ bool CWII_IPC_HLE_Device_FileIO::Read(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 Size = Memory::Read_U32(_CommandAddress + 0x10);
@@ -210,13 +216,20 @@ bool CWII_IPC_HLE_Device_FileIO::Write(u32 _CommandAddress)
if (m_pFileHandle)
{
- size_t Result = fwrite(Memory::GetPointer(Address), Size, 1, 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);
#if MAX_LOGLEVEL >= DEBUG_LEVEL
- _dbg_assert_msg_(WII_IPC_FILEIO, Result == 1, "fwrite failed");
+ _dbg_assert_msg_(WII_IPC_FILEIO, Result == 1, "fwrite failed");
#else
- (void)Result;
+ (void)Result;
#endif
- ReturnValue = (Result == 1) ? Size : FS_EACCESS;
+ ReturnValue = (Result == 1) ? Size : FS_EACCESS;
+ }
}
Memory::Write_U32(ReturnValue, _CommandAddress + 0x4);