diff --git a/Utilities/BEType.h b/Utilities/BEType.h index cfd2c4265e..afca12b1f1 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -2,17 +2,14 @@ #include "Utilities/GNU.h" -#define se16(x) const_se_t::value -#define se32(x) const_se_t::value -#define se64(x) const_se_t::value - template struct se_t; template struct se_t { static __forceinline void func(T& dst, const T src) { (u8&)dst = (u8&)src; } }; template struct se_t { static __forceinline void func(T& dst, const T src) { (u16&)dst = _byteswap_ushort((u16&)src); } }; template struct se_t { static __forceinline void func(T& dst, const T src) { (u32&)dst = _byteswap_ulong((u32&)src); } }; template struct se_t { static __forceinline void func(T& dst, const T src) { (u64&)dst = _byteswap_uint64((u64&)src); } }; -template struct const_se_t;; + +template struct const_se_t; template struct const_se_t { static const T value = (T)_value; @@ -52,6 +49,8 @@ class be_t T m_data; public: + typedef T type; + be_t() { } @@ -91,6 +90,20 @@ public: se_t::func(m_data, value); } + static be_t MakeFromLE(const T value) + { + be_t res; + res.FromLE(value); + return res; + } + + static be_t MakeFromBE(const T value) + { + be_t res; + res.FromBE(value); + return res; + } + //template operator const T() const { @@ -154,4 +167,17 @@ public: template bool operator < (const be_t& right) const { return (T1)ToLE() < right.ToLE(); } template bool operator >= (const be_t& right) const { return (T1)ToLE() >= right.ToLE(); } template bool operator <= (const be_t& right) const { return (T1)ToLE() <= right.ToLE(); } + + be_t operator++ (int) { be_t res = *this; *this += 1; return res; } + be_t operator-- (int) { be_t res = *this; *this -= 1; return res; } + be_t& operator++ () { *this += 1; return *this; } + be_t& operator-- () { *this -= 1; return *this; } }; + +template struct _se : public const_se_t {}; +template struct _se, T1, value> : public const_se_t {}; + +#define se(t, x) _se::value +#define se16(x) _se::value +#define se32(x) _se::value +#define se64(x) _se::value diff --git a/Utilities/IdManager.h b/Utilities/IdManager.h index d543769356..fb8529c241 100644 --- a/Utilities/IdManager.h +++ b/Utilities/IdManager.h @@ -35,11 +35,11 @@ public: struct ID { std::string m_name; - u8 m_attr; + u32 m_attr; IDData* m_data; template - ID(const std::string& name, T* data, const u8 attr) + ID(const std::string& name, T* data, const u32 attr) : m_name(name) , m_attr(attr) { @@ -97,7 +97,7 @@ public: } template - ID_TYPE GetNewID(const std::string& name = "", T* data = nullptr, const u8 attr = 0) + ID_TYPE GetNewID(const std::string& name = "", T* data = nullptr, const u32 attr = 0) { std::lock_guard lock(m_mtx_main); diff --git a/rpcs3/Emu/Cell/PPUInterpreter.h b/rpcs3/Emu/Cell/PPUInterpreter.h index 47ab964606..9521bf430d 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.h +++ b/rpcs3/Emu/Cell/PPUInterpreter.h @@ -2349,7 +2349,8 @@ private: if(count == 1) { //RD[32+4*n : 32+4*n+3] = CR[4*n : 4*n+3]; - CPU.GPR[rd] = (u64)CPU.GetCR(7 - n) << (n * 4); + u8 offset = n * 4; + CPU.GPR[rd] = (CPU.GPR[rd] & ~(0xf << offset)) | ((u32)CPU.GetCR(7 - n) << offset); } else CPU.GPR[rd] = 0; diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index a96a62457b..48174ebe77 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -259,6 +259,8 @@ vfsDevice* VFS::GetDeviceLocal(const wxString& local_path, wxString& path) const void VFS::Init(const wxString& path) { + UnMountAll(); + Array entries; SaveLoadDevices(entries, true); diff --git a/rpcs3/Emu/FS/vfsDir.cpp b/rpcs3/Emu/FS/vfsDir.cpp index 7ce119601d..0d165c6ca5 100644 --- a/rpcs3/Emu/FS/vfsDir.cpp +++ b/rpcs3/Emu/FS/vfsDir.cpp @@ -56,7 +56,6 @@ const DirEntryInfo* vfsDir::Read() void vfsDir::Close() { m_stream.reset(); - return vfsDirBase::Close(); } wxString vfsDir::GetPath() const @@ -66,5 +65,5 @@ wxString vfsDir::GetPath() const bool vfsDir::IsOpened() const { - return m_stream && m_stream->IsOpened() && vfsDirBase::IsOpened(); + return m_stream && m_stream->IsOpened(); } diff --git a/rpcs3/Emu/FS/vfsDirBase.cpp b/rpcs3/Emu/FS/vfsDirBase.cpp index c7d1f65fb2..365d1effb6 100644 --- a/rpcs3/Emu/FS/vfsDirBase.cpp +++ b/rpcs3/Emu/FS/vfsDirBase.cpp @@ -13,7 +13,7 @@ vfsDirBase::~vfsDirBase() bool vfsDirBase::Open(const wxString& path) { - if(!IsOpened()) + if(IsOpened()) Close(); if(!IsExists(path)) diff --git a/rpcs3/Emu/FS/vfsDirBase.h b/rpcs3/Emu/FS/vfsDirBase.h index 05a9fb0a87..b6af8e1b62 100644 --- a/rpcs3/Emu/FS/vfsDirBase.h +++ b/rpcs3/Emu/FS/vfsDirBase.h @@ -2,9 +2,9 @@ enum DirEntryFlags { - DirEntry_TypeDir = 0x0, - DirEntry_TypeFile = 0x1, - DirEntry_TypeMask = 0x1, + DirEntry_TypeDir = 0x1, + DirEntry_TypeFile = 0x2, + DirEntry_TypeMask = 0x3, DirEntry_PermWritable = 0x20, DirEntry_PermReadable = 0x40, DirEntry_PermExecutable = 0x80, diff --git a/rpcs3/Emu/FS/vfsLocalDir.cpp b/rpcs3/Emu/FS/vfsLocalDir.cpp index 144e5d46a4..b1a2b84438 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.cpp +++ b/rpcs3/Emu/FS/vfsLocalDir.cpp @@ -23,12 +23,12 @@ bool vfsLocalDir::Open(const wxString& path) wxString name; for(bool is_ok = dir.GetFirst(&name); is_ok; is_ok = dir.GetNext(&name)) { - wxString dir_path = path + wxFILE_SEP_PATH + name; + wxString dir_path = path + name; DirEntryInfo& info = m_entries[m_entries.Move(new DirEntryInfo())]; info.name = name; - info.flags |= wxDirExists(dir_path) ? DirEntry_TypeDir : DirEntry_TypeFile; + info.flags |= dir.Exists(dir_path) ? DirEntry_TypeDir : DirEntry_TypeFile; if(wxIsWritable(dir_path)) info.flags |= DirEntry_PermWritable; if(wxIsReadable(dir_path)) info.flags |= DirEntry_PermReadable; if(wxIsExecutable(dir_path)) info.flags |= DirEntry_PermExecutable; diff --git a/rpcs3/Emu/Memory/Memory.h b/rpcs3/Emu/Memory/Memory.h index d4b5108e1c..ff3f886e65 100644 --- a/rpcs3/Emu/Memory/Memory.h +++ b/rpcs3/Emu/Memory/Memory.h @@ -399,18 +399,18 @@ public: extern MemoryBase Memory; -template +template class mem_base_t { protected: - u32 m_addr; + AT m_addr; public: - mem_base_t(u32 addr) : m_addr(addr) + mem_base_t(AT addr) : m_addr(addr) { } - __forceinline u32 GetAddr() const { return m_addr; } + __forceinline AT GetAddr() const { return m_addr; } __forceinline bool IsGood() const { @@ -433,16 +433,16 @@ public: } }; -template -class mem_ptr_t : public mem_base_t +template +class mem_ptr_t : public mem_base_t { public: - mem_ptr_t(u32 addr) : mem_base_t(addr) + mem_ptr_t(AT addr) : mem_base_t(addr) { } - template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } - template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*this; } + template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } + template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*this; } T* operator -> () { @@ -537,11 +537,11 @@ public: bool operator <= (T* right) const { return (T*)&Memory[this->m_addr] <= right; } }; -template<> -class mem_ptr_t : public mem_base_t +template +class mem_ptr_t : public mem_base_t { public: - mem_ptr_t(u32 addr) : mem_base_t(addr) + mem_ptr_t(AT addr) : mem_base_t(addr) { } @@ -570,10 +570,13 @@ template static bool operator < (T* left, mem_ptr_t right) { retu template static bool operator >= (T* left, mem_ptr_t right) { return left >= (T*)&Memory[right.GetAddr()]; } template static bool operator <= (T* left, mem_ptr_t right) { return left <= (T*)&Memory[right.GetAddr()]; } -template class mem_t : public mem_base_t +template +class mem_beptr_t : public mem_ptr_t> {}; + +template class mem_t : public mem_base_t { public: - mem_t(u32 addr) : mem_base_t(addr) + mem_t(AT addr) : mem_base_t(addr) { } @@ -606,7 +609,7 @@ public: mem_t& operator >>= (T right) { return *this = (*this) >> right; } }; -template class mem_list_ptr_t : public mem_base_t +template class mem_list_ptr_t : public mem_base_t { public: mem_list_ptr_t(u32 addr) : mem_base_t(addr) @@ -687,18 +690,18 @@ struct _func_arg }; template -struct _func_arg> +struct _func_arg> { - __forceinline static u64 get_value(const mem_base_t arg) + __forceinline static u64 get_value(const mem_base_t arg) { return arg.GetAddr(); } }; -template struct _func_arg> : public _func_arg> {}; -template<> struct _func_arg> : public _func_arg> {}; -template struct _func_arg> : public _func_arg> {}; -template struct _func_arg> : public _func_arg> {}; +template struct _func_arg> : public _func_arg> {}; +template<> struct _func_arg> : public _func_arg> {}; +template struct _func_arg> : public _func_arg> {}; +template struct _func_arg> : public _func_arg> {}; template struct _func_arg> @@ -912,10 +915,10 @@ public: return m_ptr; } - T operator [](int index) - { - return *(m_ptr + index); - } + T operator [](int index) + { + return *(m_ptr + index); + } template operator const mem_t() const @@ -935,10 +938,10 @@ public: } }; -typedef mem_t mem8_t; -typedef mem_t mem16_t; -typedef mem_t mem32_t; -typedef mem_t mem64_t; +typedef mem_t mem8_t; +typedef mem_t mem16_t; +typedef mem_t mem32_t; +typedef mem_t mem64_t; /* typedef mem_ptr_t> mem8_ptr_t; @@ -952,7 +955,7 @@ typedef mem_list_ptr_t mem32_lptr_t; typedef mem_list_ptr_t mem64_lptr_t; */ -typedef mem_list_ptr_t mem8_ptr_t; -typedef mem_list_ptr_t mem16_ptr_t; -typedef mem_list_ptr_t mem32_ptr_t; -typedef mem_list_ptr_t mem64_ptr_t; +typedef mem_list_ptr_t mem8_ptr_t; +typedef mem_list_ptr_t mem16_ptr_t; +typedef mem_list_ptr_t mem32_ptr_t; +typedef mem_list_ptr_t mem64_ptr_t; diff --git a/rpcs3/Emu/SysCalls/Modules.h b/rpcs3/Emu/SysCalls/Modules.h index e7e9f28d7f..faef27d9b7 100644 --- a/rpcs3/Emu/SysCalls/Modules.h +++ b/rpcs3/Emu/SysCalls/Modules.h @@ -73,6 +73,18 @@ public: return true; } + + template bool CheckId(u32 id, T*& data, u32& attr) + { + ID* id_data; + + if(!CheckID(id, id_data)) return false; + + data = id_data->m_data->get(); + attr = id_data->m_attr; + + return true; + } bool CheckID(u32 id, ID*& _id) const; template diff --git a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp index fde9c0f339..e688a46d74 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp @@ -4,6 +4,12 @@ extern Module sys_fs; +enum +{ + IDFlag_File = 1, + IDFlag_Dir = 2, +}; + int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) { const wxString& path = Memory.ReadString(path_addr); @@ -75,7 +81,7 @@ int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) return CELL_ENOENT; } - fd = sys_fs.GetNewId(stream, flags); + fd = sys_fs.GetNewId(stream, IDFlag_File); ConLog.Warning("*** cellFsOpen(path=\"%s\"): fd = %d", path.wx_str(), fd.GetValue()); return CELL_OK; @@ -148,7 +154,7 @@ int cellFsOpendir(u32 path_addr, mem32_t fd) return CELL_ENOENT; } - fd = sys_fs.GetNewId(dir); + fd = sys_fs.GetNewId(dir, IDFlag_Dir); return CELL_OK; } @@ -156,7 +162,7 @@ int cellFsReaddir(u32 fd, mem_ptr_t dir, mem64_t nread) { sys_fs.Log("cellFsReaddir(fd=%d, dir_addr=0x%x, nread_addr=0x%x)", fd, dir.GetAddr(), nread.GetAddr()); - vfsLocalDir* directory; + vfsDirBase* directory; if(!sys_fs.CheckId(fd, directory)) return CELL_ESRCH; if(!dir.IsGood() || !nread.IsGood()) @@ -205,56 +211,36 @@ int cellFsStat(const u32 path_addr, mem_ptr_t sb) sb->st_ctime_ = 0; //TODO sb->st_blksize = 4096; - // Check if path is a mount point. (TODO: Add information in sb_addr) - for(u32 i=0; ist_mode |= CELL_FS_S_IFDIR; return CELL_OK; } } - if (path == "/dev_bdvd/PS3_GAME/USRDIR") { - sys_fs.Warning("cellFsStat: /dev_bdvd/PS3_GAME/USRDIR mount point hack"); - sb->st_mode |= CELL_FS_S_IFDIR; - return CELL_OK; - } - - // TODO: Temporary solution until vfsDir is implemented - wxString real_path; - Emu.GetVFS().GetDevice(path, real_path); - struct stat s; - if(stat(real_path.c_str(), &s) == 0) - { - if(s.st_mode & S_IFDIR) + vfsFile f(path); + if(f.IsOpened()) { - sb->st_mode |= CELL_FS_S_IFDIR; - } - else if(s.st_mode & S_IFREG) - { - vfsFile f(path); sb->st_mode |= CELL_FS_S_IFREG; sb->st_size = f.GetSize(); + return CELL_OK; } } - else - { - sys_fs.Warning("cellFsStat: \"%s\" not found.", path.wx_str()); - return CELL_ENOENT; - } - return CELL_OK; + sys_fs.Warning("cellFsStat: \"%s\" not found.", path.wx_str()); + return CELL_ENOENT; } int cellFsFstat(u32 fd, mem_ptr_t sb) { sys_fs.Log("cellFsFstat(fd=%d, sb_addr: 0x%x)", fd, sb.GetAddr()); + u32 attr; vfsStream* file; - if(!sys_fs.CheckId(fd, file)) return CELL_ESRCH; + if(!sys_fs.CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; sb->st_mode = CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | @@ -278,10 +264,12 @@ int cellFsMkdir(u32 path_addr, u32 mode) const wxString& ps3_path = Memory.ReadString(path_addr); sys_fs.Log("cellFsMkdir(path=\"%s\", mode=0x%x)", ps3_path.wx_str(), mode); - wxString localPath; - Emu.GetVFS().GetDevice(ps3_path, localPath); - if(wxDirExists(localPath)) return CELL_EEXIST; - if(!wxMkdir(localPath)) return CELL_EBUSY; + vfsDir dir; + if(dir.IsExists(ps3_path)) + return CELL_EEXIST; + if(!dir.Create(ps3_path)) + return CELL_EBUSY; + return CELL_OK; } @@ -289,16 +277,30 @@ int cellFsRename(u32 from_addr, u32 to_addr) { const wxString& ps3_from = Memory.ReadString(from_addr); const wxString& ps3_to = Memory.ReadString(to_addr); - wxString from; - wxString to; - Emu.GetVFS().GetDevice(ps3_from, from); - Emu.GetVFS().GetDevice(ps3_to, to); - sys_fs.Log("cellFsRename(from=\"%s\", to=\"%s\")", ps3_from.wx_str(), ps3_to.wx_str()); - if(!wxFileExists(from)) return CELL_ENOENT; - if(wxFileExists(to)) return CELL_EEXIST; - if(!wxRenameFile(from, to)) return CELL_EBUSY; // (TODO: RenameFile(a,b) = CopyFile(a,b) + RemoveFile(a), therefore file "a" will not be removed if it is opened) - return CELL_OK; + { + vfsDir dir; + if(dir.IsExists(ps3_from)) + { + if(!dir.Rename(ps3_from, ps3_to)) + return CELL_EBUSY; + + return CELL_OK; + } + } + + { + vfsFile f; + if(f.Exists(ps3_from)) + { + if(!f.Rename(ps3_from, ps3_to)) + return CELL_EBUSY; + + return CELL_OK; + } + } + + return CELL_ENOENT; } int cellFsRmdir(u32 path_addr) @@ -306,10 +308,13 @@ int cellFsRmdir(u32 path_addr) const wxString& ps3_path = Memory.ReadString(path_addr); sys_fs.Log("cellFsRmdir(path=\"%s\")", ps3_path.wx_str()); - wxString localPath; - Emu.GetVFS().GetDevice(ps3_path, localPath); - if(!wxDirExists(localPath)) return CELL_ENOENT; - if(!wxRmdir(localPath)) return CELL_EBUSY; // (TODO: Under certain conditions it is not able to delete the folder) + vfsDir d; + if(!d.IsExists(ps3_path)) + return CELL_ENOENT; + + if(!d.Remove(ps3_path)) + return CELL_EBUSY; + return CELL_OK; } @@ -318,9 +323,9 @@ int cellFsUnlink(u32 path_addr) const wxString& ps3_path = Memory.ReadString(path_addr); sys_fs.Warning("cellFsUnlink(path=\"%s\")", ps3_path.wx_str()); - wxString localPath; - Emu.GetVFS().GetDevice(ps3_path, localPath); - wxRemoveFile(localPath); + //wxString localPath; + //Emu.GetVFS().GetDevice(ps3_path, localPath); + //wxRemoveFile(localPath); return CELL_OK; } @@ -338,8 +343,9 @@ int cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos) return CELL_EINVAL; } + u32 attr; vfsStream* file; - if(!sys_fs.CheckId(fd, file)) return CELL_ESRCH; + if(!sys_fs.CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; pos = file->Seek(offset, seek_mode); return CELL_OK; } @@ -347,8 +353,9 @@ int cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos) int cellFsFtruncate(u32 fd, u64 size) { sys_fs.Log("cellFsFtruncate(fd=%d, size=%lld)", fd, size); + u32 attr; vfsStream* file; - if(!sys_fs.CheckId(fd, file)) return CELL_ESRCH; + if(!sys_fs.CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; u64 initialSize = file->GetSize(); if (initialSize < size) @@ -403,7 +410,10 @@ int cellFsTruncate(u32 path_addr, u64 size) int cellFsFGetBlockSize(u32 fd, mem64_t sector_size, mem64_t block_size) { sys_fs.Log("cellFsFGetBlockSize(fd=%d, sector_size_addr: 0x%x, block_size_addr: 0x%x)", fd, sector_size.GetAddr(), block_size.GetAddr()); - + + vfsStream* file; + if(!sys_fs.CheckId(fd, file)) return CELL_ESRCH; + sector_size = 4096; // ? block_size = 4096; // ? diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Rwlock.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Rwlock.cpp index d8d9daa6fc..29a178f537 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Rwlock.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Rwlock.cpp @@ -12,10 +12,10 @@ int sys_rwlock_create(mem32_t rw_lock_id, mem_ptr_t attr switch (attr->attr_protocol.ToBE()) { - case se32(SYS_SYNC_PRIORITY): sys_rwlock.Warning("TODO: SYS_SYNC_PRIORITY attr"); break; - case se32(SYS_SYNC_RETRY): sys_rwlock.Error("Invalid SYS_SYNC_RETRY attr"); break; - case se32(SYS_SYNC_PRIORITY_INHERIT): sys_rwlock.Warning("TODO: SYS_SYNC_PRIORITY_INHERIT attr"); break; - case se32(SYS_SYNC_FIFO): break; + case se(attr->attr_protocol, SYS_SYNC_PRIORITY): sys_rwlock.Warning("TODO: SYS_SYNC_PRIORITY attr"); break; + case se(attr->attr_protocol, SYS_SYNC_RETRY): sys_rwlock.Error("Invalid SYS_SYNC_RETRY attr"); break; + case se(attr->attr_protocol, SYS_SYNC_PRIORITY_INHERIT): sys_rwlock.Warning("TODO: SYS_SYNC_PRIORITY_INHERIT attr"); break; + case se(attr->attr_protocol, SYS_SYNC_FIFO): break; default: return CELL_EINVAL; } diff --git a/rpcs3/Gui/GameViewer.cpp b/rpcs3/Gui/GameViewer.cpp index c665a39983..26d876bcf6 100644 --- a/rpcs3/Gui/GameViewer.cpp +++ b/rpcs3/Gui/GameViewer.cpp @@ -8,7 +8,7 @@ GameViewer::GameViewer(wxWindow* parent) : wxListView(parent) LoadSettings(); m_columns.Show(this); - m_path = wxGetCwd() + "\\dev_hdd0\\game\\"; //TODO + m_path = "/dev_hdd0/game/"; Connect(GetId(), wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler(GameViewer::DClick)); @@ -27,17 +27,18 @@ void GameViewer::DoResize(wxSize size) void GameViewer::LoadGames() { - if(!wxDirExists(m_path)) return; + vfsDir dir(m_path); + ConLog.Write("path: %s", m_path.wx_str()); + if(!dir.IsOpened()) return; m_games.Clear(); - wxDir dir(m_path); - if(!dir.HasSubDirs()) return; - wxString buf; - for(bool ok = dir.GetFirst(&buf); ok; ok = dir.GetNext(&buf)) + for(const DirEntryInfo* info = dir.Read(); info; info = dir.Read()) { - if(wxDirExists(m_path + buf)) - m_games.Add(buf); + if(info->flags & DirEntry_TypeDir) + { + m_games.Add(info->name); + } } //ConLog.Write("path: %s", m_path.wx_str()); @@ -49,8 +50,8 @@ void GameViewer::LoadPSF() m_game_data.Clear(); for(uint i=0; i