diff options
49 files changed, 353 insertions, 200 deletions
diff --git a/.travis-deps.sh b/.travis-deps.sh index d10973410..5c530dcb9 100755 --- a/.travis-deps.sh +++ b/.travis-deps.sh @@ -24,7 +24,7 @@ if [ "$TRAVIS_OS_NAME" = "linux" -o -z "$TRAVIS_OS_NAME" ]; then ) elif [ "$TRAVIS_OS_NAME" = "osx" ]; then - brew tap homebrew/versions + brew update > /dev/null # silence the very verbose output brew install qt5 glfw3 pkgconfig gem install xcpretty fi @@ -7,7 +7,7 @@ Citra is an experimental open-source Nintendo 3DS emulator/debugger written in C Citra is licensed under the GPLv2 (or any later version). Refer to the license.txt file included. Please read the [FAQ](https://github.com/citra-emu/citra/wiki/FAQ) before getting started with the project. -For development discussion, please join us @ #citra on [freenode](http://webchat.freenode.net/?channels=citra). +For development discussion, please join us @ #citra on freenode. ### Development diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index cabf5fe07..392ff570b 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <QApplication> +#include <QClipboard> #include <QLabel> #include <QListView> #include <QMainWindow> @@ -74,7 +76,7 @@ TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo format_choice->addItem(tr("I8")); format_choice->addItem(tr("A8")); format_choice->addItem(tr("IA4")); - format_choice->addItem(tr("UNK10")); + format_choice->addItem(tr("I4")); format_choice->addItem(tr("A4")); format_choice->addItem(tr("ETC1")); format_choice->addItem(tr("ETC1A4")); @@ -304,16 +306,24 @@ GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pi this, SLOT(OnCommandDoubleClicked(const QModelIndex&))); toggle_tracing = new QPushButton(tr("Start Tracing")); + QPushButton* copy_all = new QPushButton(tr("Copy All")); connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); + connect(copy_all, SIGNAL(clicked()), this, SLOT(CopyAllToClipboard())); + command_info_widget = new QWidget; QVBoxLayout* main_layout = new QVBoxLayout; main_layout->addWidget(list_widget); - main_layout->addWidget(toggle_tracing); + { + QHBoxLayout* sub_layout = new QHBoxLayout; + sub_layout->addWidget(toggle_tracing); + sub_layout->addWidget(copy_all); + main_layout->addLayout(sub_layout); + } main_layout->addWidget(command_info_widget); main_widget->setLayout(main_layout); @@ -330,3 +340,21 @@ void GPUCommandListWidget::OnToggleTracing() { toggle_tracing->setText(tr("Start Tracing")); } } + +void GPUCommandListWidget::CopyAllToClipboard() { + QClipboard* clipboard = QApplication::clipboard(); + QString text; + + QAbstractItemModel* model = static_cast<QAbstractListModel*>(list_widget->model()); + + for (int row = 0; row < model->rowCount({}); ++row) { + for (int col = 0; col < model->columnCount({}); ++col) { + QModelIndex index = model->index(row, col); + text += model->data(index).value<QString>(); + text += '\t'; + } + text += '\n'; + } + + clipboard->setText(text); +} diff --git a/src/citra_qt/debugger/graphics_cmdlists.h b/src/citra_qt/debugger/graphics_cmdlists.h index a465d044c..4859b6ec8 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.h +++ b/src/citra_qt/debugger/graphics_cmdlists.h @@ -49,6 +49,8 @@ public slots: void SetCommandInfo(const QModelIndex&); + void CopyAllToClipboard(); + signals: void TracingFinished(const Pica::DebugUtils::PicaTrace&); diff --git a/src/common/file_util.h b/src/common/file_util.h index 9637d1b85..d0dccdf69 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -116,9 +116,6 @@ bool SetCurrentDir(const std::string &directory); // directory. To be used in "multi-user" mode (that is, installed). const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath=""); -// probably doesn't belong here -//std::string GetThemeDir(const std::string& theme_name); - // Returns the path to where the sys file are std::string GetSysDirectory(); diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp index b00eb49a9..785f39566 100644 --- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp +++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp @@ -4144,11 +4144,13 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) { if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) { bx_inst* const inst_cream = (bx_inst*)inst_base->component; + u32 address = RM; + if (inst_cream->Rm == 15) - LOG_WARNING(Core_ARM11, "BX at pc %x: use of Rm = R15 is discouraged", cpu->Reg[15]); + address += 2 * GET_INST_SIZE(cpu); - cpu->TFlag = cpu->Reg[inst_cream->Rm] & 0x1; - cpu->Reg[15] = cpu->Reg[inst_cream->Rm] & 0xfffffffe; + cpu->TFlag = address & 1; + cpu->Reg[15] = address & 0xfffffffe; INC_PC(sizeof(bx_inst)); goto DISPATCH; } @@ -5695,7 +5697,7 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) { const s16 operand2 = (high) ? ((rm_val >> 16) & 0xFFFF) : (rm_val & 0xFFFF); const s64 result = (s64)(s32)rn_val * (s64)(s32)operand2 + ((s64)(s32)ra_val << 16); - RD = (result & (0xFFFFFFFFFFFFFFFFLL >> 15)) >> 16; + RD = BITS(result, 16, 47); if ((result >> 16) != (s32)RD) cpu->Cpsr |= (1 << 27); @@ -6246,7 +6248,8 @@ unsigned InterpreterMainLoop(ARMul_State* cpu) { SWI_INST: { if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) { - SVC::CallSVC(Memory::Read32(cpu->Reg[15])); + swi_inst* const inst_cream = (swi_inst*)inst_base->component; + SVC::CallSVC(inst_cream->num & 0xFFFF); } cpu->Reg[15] += GET_INST_SIZE(cpu); diff --git a/src/core/arm/dyncom/arm_dyncom_thumb.cpp b/src/core/arm/dyncom/arm_dyncom_thumb.cpp index 3e79c44c0..f10a5b70f 100644 --- a/src/core/arm/dyncom/arm_dyncom_thumb.cpp +++ b/src/core/arm/dyncom/arm_dyncom_thumb.cpp @@ -130,14 +130,13 @@ tdstate thumb_translate(u32 addr, u32 instr, u32* ainstr, u32* inst_size) { } } else { ARMword Rd = ((tinstr & 0x0007) >> 0); - ARMword Rs = ((tinstr & 0x0038) >> 3); + ARMword Rs = ((tinstr & 0x0078) >> 3); if (tinstr & (1 << 7)) Rd += 8; - if (tinstr & (1 << 6)) - Rs += 8; switch ((tinstr & 0x03C0) >> 6) { + case 0x0: // ADD Rd,Rd,Rs case 0x1: // ADD Rd,Rd,Hs case 0x2: // ADD Hd,Hd,Rs case 0x3: // ADD Hd,Hd,Hs @@ -146,19 +145,19 @@ tdstate thumb_translate(u32 addr, u32 instr, u32* ainstr, u32* inst_size) { |(Rd << 12) // Rd |(Rs << 0); // Rm break; + case 0x4: // CMP Rd,Rs case 0x5: // CMP Rd,Hs case 0x6: // CMP Hd,Rs case 0x7: // CMP Hd,Hs *ainstr = 0xE1500000 // base | (Rd << 16) // Rn - |(Rd << 12) // Rd |(Rs << 0); // Rm break; + case 0x8: // MOV Rd,Rs case 0x9: // MOV Rd,Hs case 0xA: // MOV Hd,Rs case 0xB: // MOV Hd,Hs *ainstr = 0xE1A00000 // base - | (Rd << 16) // Rn |(Rd << 12) // Rd |(Rs << 0); // Rm break; @@ -167,11 +166,6 @@ tdstate thumb_translate(u32 addr, u32 instr, u32* ainstr, u32* inst_size) { *ainstr = 0xE12FFF10 // base | ((tinstr & 0x0078) >> 3); // Rd break; - case 0x0: // UNDEFINED - case 0x4: // UNDEFINED - case 0x8: // UNDEFINED - valid = t_undefined; - break; case 0xE: // BLX case 0xF: // BLX *ainstr = 0xE1200030 // base diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index c1e45dfeb..696b51a94 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp @@ -17,16 +17,15 @@ namespace FileSys { -ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader) - : romfs_data(std::make_shared<std::vector<u8>>()) { +ArchiveFactory_RomFS::ArchiveFactory_RomFS(Loader::AppLoader& app_loader) { // Load the RomFS from the app - if (Loader::ResultStatus::Success != app_loader.ReadRomFS(*romfs_data)) { + if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) { LOG_ERROR(Service_FS, "Unable to read RomFS!"); } } ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) { - auto archive = Common::make_unique<IVFCArchive>(romfs_data); + auto archive = Common::make_unique<IVFCArchive>(romfs_file, data_offset, data_size); return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index c69ff91c3..2bedfa9c6 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h @@ -22,14 +22,16 @@ namespace FileSys { /// File system interface to the RomFS archive class ArchiveFactory_RomFS final : public ArchiveFactory { public: - ArchiveFactory_RomFS(const Loader::AppLoader& app_loader); + ArchiveFactory_RomFS(Loader::AppLoader& app_loader); std::string GetName() const override { return "RomFS"; } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path) override; private: - std::shared_ptr<std::vector<u8>> romfs_data; + std::shared_ptr<FileUtil::IOFile> romfs_file; + u64 data_offset; + u64 data_size; }; } // namespace FileSys diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index dec838cae..ea1dfe2c7 100644 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ b/src/core/file_sys/archive_savedatacheck.cpp @@ -37,17 +37,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co auto vec = path.AsBinary(); const u32* data = reinterpret_cast<u32*>(vec.data()); std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]); - FileUtil::IOFile file(file_path, "rb"); + auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb"); - if (!file.IsOpen()) { + if (!file->IsOpen()) { return ResultCode(-1); // TODO(Subv): Find the right error code } - auto size = file.GetSize(); - auto raw_data = std::make_shared<std::vector<u8>>(size); - file.ReadBytes(raw_data->data(), size); - file.Close(); + auto size = file->GetSize(); - auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data)); + auto archive = Common::make_unique<IVFCArchive>(file, 0, size); return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 85151a311..1096fd34d 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -105,12 +105,12 @@ bool DiskFile::Open() { return true; } -size_t DiskFile::Read(const u64 offset, const u32 length, u8* buffer) const { +size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { file->Seek(offset, SEEK_SET); return file->ReadBytes(buffer, length); } -size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { +size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { file->Seek(offset, SEEK_SET); size_t written = file->WriteBytes(buffer, length); if (flush) @@ -118,8 +118,8 @@ size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, cons return written; } -size_t DiskFile::GetSize() const { - return static_cast<size_t>(file->GetSize()); +u64 DiskFile::GetSize() const { + return file->GetSize(); } bool DiskFile::SetSize(const u64 size) const { diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h index 5cfcddf6c..c5da07508 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h @@ -55,10 +55,10 @@ public: DiskFile(const DiskArchive& archive, const Path& path, const Mode mode); bool Open() override; - size_t Read(const u64 offset, const u32 length, u8* buffer) const override; - size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; - size_t GetSize() const override; - bool SetSize(const u64 size) const override; + size_t Read(u64 offset, size_t length, u8* buffer) const override; + size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; + u64 GetSize() const override; + bool SetSize(u64 size) const override; bool Close() const override; void Flush() const override { diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index f5f72c722..df7165df3 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h @@ -31,7 +31,7 @@ public: * @param buffer Buffer to read data into * @return Number of bytes read */ - virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; + virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0; /** * Write data to the file @@ -41,20 +41,20 @@ public: * @param buffer Buffer to read data from * @return Number of bytes written */ - virtual size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const = 0; + virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; /** * Get the size of the file in bytes * @return Size of the file in bytes */ - virtual size_t GetSize() const = 0; + virtual u64 GetSize() const = 0; /** * Set the size of the file in bytes * @param size New size of the file * @return true if successful */ - virtual bool SetSize(const u64 size) const = 0; + virtual bool SetSize(u64 size) const = 0; /** * Close the file diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index c88b39bcd..e16aa1491 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -16,15 +16,12 @@ namespace FileSys { -IVFCArchive::IVFCArchive(std::shared_ptr<const std::vector<u8>> data) : data(data) { -} - std::string IVFCArchive::GetName() const { return "IVFC"; } std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { - return Common::make_unique<IVFCFile>(data); + return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size); } bool IVFCArchive::DeleteFile(const Path& path) const { @@ -64,19 +61,21 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c //////////////////////////////////////////////////////////////////////////////////////////////////// -size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const { +size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); - memcpy(buffer, data->data() + offset, length); - return length; + romfs_file->Seek(data_offset + offset, SEEK_SET); + size_t read_length = (size_t)std::min((u64)length, data_size - offset); + + return romfs_file->ReadBytes(buffer, read_length); } -size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { +size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); return 0; } -size_t IVFCFile::GetSize() const { - return sizeof(u8) * data->size(); +u64 IVFCFile::GetSize() const { + return data_size; } bool IVFCFile::SetSize(const u64 size) const { diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index 1850b3b17..c15a6c4ae 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h @@ -10,6 +10,7 @@ #include <vector> #include "common/common_types.h" +#include "common/file_util.h" #include "core/file_sys/archive_backend.h" #include "core/file_sys/directory_backend.h" @@ -28,7 +29,8 @@ namespace FileSys { */ class IVFCArchive : public ArchiveBackend { public: - IVFCArchive(std::shared_ptr<const std::vector<u8>> data); + IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) + : romfs_file(file), data_offset(offset), data_size(size) {} std::string GetName() const override; @@ -42,23 +44,28 @@ public: std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; protected: - std::shared_ptr<const std::vector<u8>> data; + std::shared_ptr<FileUtil::IOFile> romfs_file; + u64 data_offset; + u64 data_size; }; class IVFCFile : public FileBackend { public: - IVFCFile(std::shared_ptr<const std::vector<u8>> data) : data(data) {} + IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) + : romfs_file(file), data_offset(offset), data_size(size) {} bool Open() override { return true; } - size_t Read(const u64 offset, const u32 length, u8* buffer) const override; - size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; - size_t GetSize() const override; - bool SetSize(const u64 size) const override; + size_t Read(u64 offset, size_t length, u8* buffer) const override; + size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; + u64 GetSize() const override; + bool SetSize(u64 size) const override; bool Close() const override { return false; } void Flush() const override { } private: - std::shared_ptr<const std::vector<u8>> data; + std::shared_ptr<FileUtil::IOFile> romfs_file; + u64 data_offset; + u64 data_size; }; class IVFCDirectory : public DirectoryBackend { diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 5949cb470..9294789ec 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -87,8 +87,28 @@ template<ResultCode func(u32, s64)> void Wrap() { } } -template<ResultCode func(void*, void*, u32)> void Wrap(){ - FuncReturn(func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2)).raw); +template<ResultCode func(MemoryInfo*, PageInfo*, u32)> void Wrap() { + MemoryInfo memory_info = {}; + PageInfo page_info = {}; + u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; + Core::g_app_core->SetReg(1, memory_info.base_address); + Core::g_app_core->SetReg(2, memory_info.size); + Core::g_app_core->SetReg(3, memory_info.permission); + Core::g_app_core->SetReg(4, memory_info.state); + Core::g_app_core->SetReg(5, page_info.flags); + FuncReturn(retval); +} + +template<ResultCode func(MemoryInfo*, PageInfo*, Handle, u32)> void Wrap() { + MemoryInfo memory_info = {}; + PageInfo page_info = {}; + u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw; + Core::g_app_core->SetReg(1, memory_info.base_address); + Core::g_app_core->SetReg(2, memory_info.size); + Core::g_app_core->SetReg(3, memory_info.permission); + Core::g_app_core->SetReg(4, memory_info.state); + Core::g_app_core->SetReg(5, page_info.flags); + FuncReturn(retval); } template<ResultCode func(s32*, u32)> void Wrap(){ diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 4729a7fe0..64166ab99 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -37,6 +37,10 @@ void Thread::Acquire() { ASSERT_MSG(!ShouldWait(), "object unavailable!"); } +// TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, allowing +// us to simply use a pool index or similar. +static Kernel::HandleTable wakeup_callback_handle_table; + // Lists all thread ids that aren't deleted/etc. static std::vector<SharedPtr<Thread>> thread_list; @@ -93,6 +97,8 @@ void Thread::Stop() { // Cancel any outstanding wakeup events for this thread CoreTiming::UnscheduleEvent(ThreadWakeupEventType, callback_handle); + wakeup_callback_handle_table.Close(callback_handle); + callback_handle = 0; // Clean up thread from ready queue // This is only needed when the thread is termintated forcefully (SVC TerminateProcess) @@ -108,6 +114,7 @@ void Thread::Stop() { for (auto& wait_object : wait_objects) { wait_object->RemoveWaitingThread(this); } + wait_objects.clear(); Kernel::g_current_process->used_tls_slots[tls_index] = false; @@ -268,10 +275,6 @@ void WaitCurrentThread_ArbitrateAddress(VAddr wait_address) { thread->status = THREADSTATUS_WAIT_ARB; } -// TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, allowing -// us to simply use a pool index or similar. -static Kernel::HandleTable wakeup_callback_handle_table; - /** * Callback that will wake up the thread it was scheduled for * @param thread_handle The handle of the thread that's been awoken @@ -503,12 +506,16 @@ void ThreadingInit() { current_thread = nullptr; next_thread_id = 1; - - thread_list.clear(); - ready_queue.clear(); } void ThreadingShutdown() { + current_thread = nullptr; + + for (auto& t : thread_list) { + t->Stop(); + } + thread_list.clear(); + ready_queue.clear(); } } // namespace diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index b364beed9..7b6ab4ce0 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -406,6 +406,9 @@ void Shutdown() { lock = nullptr; notification_event = nullptr; parameter_event = nullptr; + + next_parameter.object = nullptr; + HLE::Applets::Shutdown(); } diff --git a/src/core/hle/service/cfg/cfg_s.cpp b/src/core/hle/service/cfg/cfg_s.cpp index af4adba84..a329514a6 100644 --- a/src/core/hle/service/cfg/cfg_s.cpp +++ b/src/core/hle/service/cfg/cfg_s.cpp @@ -11,7 +11,9 @@ namespace CFG { const Interface::FunctionInfo FunctionTable[] = { {0x00010082, GetConfigInfoBlk2, "GetConfigInfoBlk2"}, - {0x00020000, nullptr, "SecureInfoGetRegion"}, + {0x00020000, SecureInfoGetRegion, "SecureInfoGetRegion"}, + {0x00030040, GenHashConsoleUnique, "GenHashConsoleUnique"}, + {0x00050000, GetSystemModel, "GetSystemModel"}, {0x04010082, GetConfigInfoBlk8, "GetConfigInfoBlk8"}, {0x04020082, nullptr, "SetConfigInfoBlk4"}, {0x04030000, UpdateConfigNANDSavegame, "UpdateConfigNANDSavegame"}, diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index fafb43a2f..a8cb15d60 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -310,4 +310,9 @@ Interface::Interface() { Register(FunctionTable); } +Interface::~Interface() { + semaphore_event = nullptr; + interrupt_event = nullptr; +} + } // namespace diff --git a/src/core/hle/service/dsp_dsp.h b/src/core/hle/service/dsp_dsp.h index 54109b2a9..b6f611db5 100644 --- a/src/core/hle/service/dsp_dsp.h +++ b/src/core/hle/service/dsp_dsp.h @@ -16,6 +16,7 @@ namespace DSP_DSP { class Interface : public Service::Interface { public: Interface(); + ~Interface() override; std::string GetPortName() const override { return "dsp::DSP"; diff --git a/src/core/hle/service/frd/frd_u.cpp b/src/core/hle/service/frd/frd_u.cpp index 439c7282e..3a5897d06 100644 --- a/src/core/hle/service/frd/frd_u.cpp +++ b/src/core/hle/service/frd/frd_u.cpp @@ -10,15 +10,26 @@ namespace Service { namespace FRD { const Interface::FunctionInfo FunctionTable[] = { + {0x00010000, nullptr, "HasLoggedIn"}, + {0x00030000, nullptr, "Login"}, + {0x00040000, nullptr, "Logout"}, {0x00050000, nullptr, "GetFriendKey"}, {0x00080000, nullptr, "GetMyPresence"}, + {0x00090000, nullptr, "GetMyScreenName"}, {0x00100040, nullptr, "GetPassword"}, + {0x00110080, nullptr, "GetFriendKeyList"}, {0x00190042, nullptr, "GetFriendFavoriteGame"}, {0x001A00C4, nullptr, "GetFriendInfo"}, {0x001B0080, nullptr, "IsOnFriendList"}, {0x001C0042, nullptr, "DecodeLocalFriendCode"}, {0x001D0002, nullptr, "SetCurrentlyPlayingText"}, - {0x00320042, nullptr, "SetClientSdkVersion"} + {0x00230000, nullptr, "GetLastResponseResult"}, + {0x00270040, nullptr, "ResultToErrorCode"}, + {0x00280244, nullptr, "RequestGameAuthentication"}, + {0x00290000, nullptr, "GetGameAuthenticationData"}, + {0x002A0204, nullptr, "RequestServiceLocator"}, + {0x002B0000, nullptr, "GetServiceLocatorData"}, + {0x00320042, nullptr, "SetClientSdkVersion"}, }; FRD_U_Interface::FRD_U_Interface() { diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index ba272f05f..6c0df67c3 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -116,7 +116,7 @@ ResultVal<bool> File::SyncRequest() { u32 address = cmd_buff[6]; LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x", GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush); - cmd_buff[2] = static_cast<u32>(backend->Write(offset, length, flush, Memory::GetPointer(address))); + cmd_buff[2] = static_cast<u32>(backend->Write(offset, length, flush != 0, Memory::GetPointer(address))); break; } diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp index 3910d0227..8b40ba376 100644 --- a/src/core/hle/service/gsp_gpu.cpp +++ b/src/core/hle/service/gsp_gpu.cpp @@ -584,7 +584,7 @@ const Interface::FunctionInfo FunctionTable[] = { Interface::Interface() { Register(FunctionTable); - g_interrupt_event = 0; + g_interrupt_event = nullptr; using Kernel::MemoryPermission; g_shared_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, @@ -593,4 +593,9 @@ Interface::Interface() { g_thread_id = 0; } +Interface::~Interface() { + g_interrupt_event = nullptr; + g_shared_memory = nullptr; +} + } // namespace diff --git a/src/core/hle/service/gsp_gpu.h b/src/core/hle/service/gsp_gpu.h index 268089fdd..c89d0a467 100644 --- a/src/core/hle/service/gsp_gpu.h +++ b/src/core/hle/service/gsp_gpu.h @@ -161,6 +161,7 @@ static_assert(sizeof(CommandBuffer) == 0x200, "CommandBuffer struct has incorrec class Interface : public Service::Interface { public: Interface(); + ~Interface() override; std::string GetPortName() const override { return "gsp::Gpu"; diff --git a/src/core/hle/service/nwm_uds.cpp b/src/core/hle/service/nwm_uds.cpp index 25b01860e..18b22956f 100644 --- a/src/core/hle/service/nwm_uds.cpp +++ b/src/core/hle/service/nwm_uds.cpp @@ -125,4 +125,8 @@ Interface::Interface() { Register(FunctionTable); } +Interface::~Interface() { + handle_event = nullptr; +} + } // namespace diff --git a/src/core/hle/service/nwm_uds.h b/src/core/hle/service/nwm_uds.h index 82abdff28..0ced2359c 100644 --- a/src/core/hle/service/nwm_uds.h +++ b/src/core/hle/service/nwm_uds.h @@ -16,6 +16,7 @@ namespace NWM_UDS { class Interface : public Service::Interface { public: Interface(); + ~Interface() override; std::string GetPortName() const override { return "nwm::UDS"; diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index d681cc3dc..0de0b13a3 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -54,7 +54,7 @@ static std::string MakeFunctionString(const char* name, const char* port_name, c std::string function_string = Common::StringFromFormat("function '%s': port=%s", name, port_name); for (int i = 1; i <= num_params; ++i) { - function_string += Common::StringFromFormat(", cmd_buff[%i]=%u", i, cmd_buff[i]); + function_string += Common::StringFromFormat(", cmd_buff[%i]=0x%X", i, cmd_buff[i]); } return function_string; } diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 6c49fa6cf..3b8c7c0e4 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -68,4 +68,8 @@ Interface::Interface() { Register(FunctionTable); } +Interface::~Interface() { + event_handle = nullptr; +} + } // namespace diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h index 653aba5cb..96c89b025 100644 --- a/src/core/hle/service/srv.h +++ b/src/core/hle/service/srv.h @@ -13,6 +13,7 @@ namespace SRV { class Interface : public Service::Interface { public: Interface(); + ~Interface() override; std::string GetPortName() const override { return "srv:"; diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index e121a54e3..6e7dafaad 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -410,4 +410,8 @@ Interface::Interface() { Register(FunctionTable); } +Interface::~Interface() { + completion_event = nullptr; +} + } // namespace diff --git a/src/core/hle/service/y2r_u.h b/src/core/hle/service/y2r_u.h index 9454e5aab..3965a5545 100644 --- a/src/core/hle/service/y2r_u.h +++ b/src/core/hle/service/y2r_u.h @@ -112,6 +112,7 @@ struct ConversionConfiguration { class Interface : public Service::Interface { public: Interface(); + ~Interface() override; std::string GetPortName() const override { return "y2r:u"; diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 6cde4fc87..bdede964e 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -22,6 +22,7 @@ #include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/thread.h" #include "core/hle/kernel/timer.h" +#include "core/hle/kernel/vm_manager.h" #include "core/hle/function_wrappers.h" #include "core/hle/result.h" @@ -529,12 +530,33 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) return RESULT_SUCCESS; } -/// Query memory -static ResultCode QueryMemory(void* info, void* out, u32 addr) { - LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr); +/// Query process memory +static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, Handle process_handle, u32 addr) { + using Kernel::Process; + Kernel::SharedPtr<Process> process = Kernel::g_handle_table.Get<Process>(process_handle); + if (process == nullptr) + return ERR_INVALID_HANDLE; + + auto vma = process->address_space->FindVMA(addr); + + if (vma == process->address_space->vma_map.end()) + return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); + + memory_info->base_address = vma->second.base; + memory_info->permission = static_cast<u32>(vma->second.permissions); + memory_info->size = vma->second.size; + memory_info->state = static_cast<u32>(vma->second.meminfo_state); + + page_info->flags = 0; + LOG_TRACE(Kernel_SVC, "called process=0x%08X addr=0x%08X", process_handle, addr); return RESULT_SUCCESS; } +/// Query memory +static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32 addr) { + return QueryProcessMemory(memory_info, page_info, Kernel::CurrentProcess, addr); +} + /// Create an event static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { using Kernel::Event; @@ -806,13 +828,12 @@ static const FunctionDef SVC_Table[] = { {0x7A, nullptr, "AddCodeSegment"}, {0x7B, nullptr, "Backdoor"}, {0x7C, nullptr, "KernelSetState"}, - {0x7D, nullptr, "QueryProcessMemory"}, + {0x7D, HLE::Wrap<QueryProcessMemory>, "QueryProcessMemory"}, }; Common::Profiling::TimingCategory profiler_svc("SVC Calls"); -static const FunctionDef* GetSVCInfo(u32 opcode) { - u32 func_num = opcode & 0xFFFFFF; // 8 bits +static const FunctionDef* GetSVCInfo(u32 func_num) { if (func_num >= ARRAY_SIZE(SVC_Table)) { LOG_ERROR(Kernel_SVC, "unknown svc=0x%02X", func_num); return nullptr; @@ -820,10 +841,10 @@ static const FunctionDef* GetSVCInfo(u32 opcode) { return &SVC_Table[func_num]; } -void CallSVC(u32 opcode) { +void CallSVC(u32 immediate) { Common::Profiling::ScopeTimer timer_svc(profiler_svc); - const FunctionDef *info = GetSVCInfo(opcode); + const FunctionDef* info = GetSVCInfo(immediate); if (info) { if (info->func) { info->func(); diff --git a/src/core/hle/svc.h b/src/core/hle/svc.h index 4389aa73d..12de9ffbe 100644 --- a/src/core/hle/svc.h +++ b/src/core/hle/svc.h @@ -41,6 +41,6 @@ enum ArbitrationType { namespace SVC { -void CallSVC(u32 opcode); +void CallSVC(u32 immediate); } // namespace diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index a3a7d128f..2a338e8fc 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -217,19 +217,37 @@ inline void Write(u32 addr, const T data) { u32 dst_offset; if (config.output_tiled) { - // Interpret the input as linear and the output as tiled - u32 coarse_y = y & ~7; - u32 stride = output_width * dst_bytes_per_pixel; - - src_offset = (input_x + input_y * config.input_width) * src_bytes_per_pixel; - dst_offset = VideoCore::GetMortonOffset(x, y, dst_bytes_per_pixel) + coarse_y * stride; + if (!config.dont_swizzle) { + // Interpret the input as linear and the output as tiled + u32 coarse_y = y & ~7; + u32 stride = output_width * dst_bytes_per_pixel; + + src_offset = (input_x + input_y * config.input_width) * src_bytes_per_pixel; + dst_offset = VideoCore::GetMortonOffset(x, y, dst_bytes_per_pixel) + coarse_y * stride; + } else { + // Both input and output are linear + src_offset = (input_x + input_y * config.input_width) * src_bytes_per_pixel; + dst_offset = (x + y * output_width) * dst_bytes_per_pixel; + } } else { - // Interpret the input as tiled and the output as linear - u32 coarse_y = input_y & ~7; - u32 stride = config.input_width * src_bytes_per_pixel; - - src_offset = VideoCore::GetMortonOffset(input_x, input_y, src_bytes_per_pixel) + coarse_y * stride; - dst_offset = (x + y * output_width) * dst_bytes_per_pixel; + if (!config.dont_swizzle) { + // Interpret the input as tiled and the output as linear + u32 coarse_y = input_y & ~7; + u32 stride = config.input_width * src_bytes_per_pixel; + + src_offset = VideoCore::GetMortonOffset(input_x, input_y, src_bytes_per_pixel) + coarse_y * stride; + dst_offset = (x + y * output_width) * dst_bytes_per_pixel; + } else { + // Both input and output are tiled + u32 out_coarse_y = y & ~7; + u32 out_stride = output_width * dst_bytes_per_pixel; + + u32 in_coarse_y = input_y & ~7; + u32 in_stride = config.input_width * src_bytes_per_pixel; + + src_offset = VideoCore::GetMortonOffset(input_x, input_y, src_bytes_per_pixel) + in_coarse_y * in_stride; + dst_offset = VideoCore::GetMortonOffset(x, y, dst_bytes_per_pixel) + out_coarse_y * out_stride; + } } const u8* src_pixel = src_pointer + src_offset; diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 5b8c43f8b..daad506fe 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h @@ -203,6 +203,7 @@ struct Regs { BitField< 0, 1, u32> flip_vertically; // flips input data vertically BitField< 1, 1, u32> output_tiled; // Converts from linear to tiled format BitField< 3, 1, u32> raw_copy; // Copies the data without performing any processing + BitField< 5, 1, u32> dont_swizzle; BitField< 8, 3, PixelFormat> input_format; BitField<12, 3, PixelFormat> output_format; diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 055661363..d043fa9bd 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -246,11 +246,11 @@ ResultStatus AppLoader_THREEDSX::Load() { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; - if (!file->IsOpen()) + if (!file.IsOpen()) return ResultStatus::Error; SharedPtr<CodeSet> codeset; - if (Load3DSXFile(*file, Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE) + if (Load3DSXFile(file, Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE) return ResultStatus::Error; codeset->name = filename; diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index 096b3ec20..a0aa0c533 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h @@ -17,7 +17,7 @@ namespace Loader { /// Loads an 3DSX file class AppLoader_THREEDSX final : public AppLoader { public: - AppLoader_THREEDSX(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename) + AppLoader_THREEDSX(FileUtil::IOFile&& file, std::string filename) : AppLoader(std::move(file)), filename(std::move(filename)) {} /** diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index ca3c18a9f..5d7264f12 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -273,7 +273,6 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { LOG_DEBUG(Loader, "%i segments:", header->e_phnum); // First pass : Get the bits into RAM - u32 segment_addr[32]; u32 base_addr = relocate ? vaddr : 0; u32 total_image_size = 0; @@ -392,15 +391,15 @@ ResultStatus AppLoader_ELF::Load() { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; - if (!file->IsOpen()) + if (!file.IsOpen()) return ResultStatus::Error; // Reset read pointer in case this file has been read before. - file->Seek(0, SEEK_SET); + file.Seek(0, SEEK_SET); - u32 size = static_cast<u32>(file->GetSize()); + size_t size = file.GetSize(); std::unique_ptr<u8[]> buffer(new u8[size]); - if (file->ReadBytes(&buffer[0], size) != size) + if (file.ReadBytes(&buffer[0], size) != size) return ResultStatus::Error; ElfReader elf_reader(&buffer[0]); diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 32841606a..c6a5ebe99 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -17,7 +17,7 @@ namespace Loader { /// Loads an ELF/AXF file class AppLoader_ELF final : public AppLoader { public: - AppLoader_ELF(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename) + AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) : AppLoader(std::move(file)), filename(std::move(filename)) { } /** diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 2e450fce4..9ef2f8900 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -90,8 +90,8 @@ static const char* GetFileTypeString(FileType type) { } ResultStatus LoadFile(const std::string& filename) { - std::unique_ptr<FileUtil::IOFile> file(new FileUtil::IOFile(filename, "rb")); - if (!file->IsOpen()) { + FileUtil::IOFile file(filename, "rb"); + if (!file.IsOpen()) { LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); return ResultStatus::Error; } @@ -99,7 +99,7 @@ ResultStatus LoadFile(const std::string& filename) { std::string filename_filename, filename_extension; Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); - FileType type = IdentifyFile(*file); + FileType type = IdentifyFile(file); FileType filename_type = GuessFromExtension(filename_extension); if (type != filename_type) { @@ -124,7 +124,7 @@ ResultStatus LoadFile(const std::string& filename) { case FileType::CXI: case FileType::CCI: { - AppLoader_NCCH app_loader(std::move(file)); + AppLoader_NCCH app_loader(std::move(file), filename); // Load application and RomFS if (ResultStatus::Success == app_loader.Load()) { diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 52bbf35b8..a37d3348c 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -52,7 +52,7 @@ static inline u32 MakeMagic(char a, char b, char c, char d) { /// Interface for loading an application class AppLoader : NonCopyable { public: - AppLoader(std::unique_ptr<FileUtil::IOFile>&& file) : file(std::move(file)) { } + AppLoader(FileUtil::IOFile&& file) : file(std::move(file)) { } virtual ~AppLoader() { } /** @@ -66,7 +66,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadCode(std::vector<u8>& buffer) const { + virtual ResultStatus ReadCode(std::vector<u8>& buffer) { return ResultStatus::ErrorNotImplemented; } @@ -75,7 +75,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadIcon(std::vector<u8>& buffer) const { + virtual ResultStatus ReadIcon(std::vector<u8>& buffer) { return ResultStatus::ErrorNotImplemented; } @@ -84,7 +84,7 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadBanner(std::vector<u8>& buffer) const { + virtual ResultStatus ReadBanner(std::vector<u8>& buffer) { return ResultStatus::ErrorNotImplemented; } @@ -93,22 +93,25 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - virtual ResultStatus ReadLogo(std::vector<u8>& buffer) const { + virtual ResultStatus ReadLogo(std::vector<u8>& buffer) { return ResultStatus::ErrorNotImplemented; } /** * Get the RomFS of the application - * @param buffer Reference to buffer to store data + * Since the RomFS can be huge, we return a file reference instead of copying to a buffer + * @param romfs_file The file containing the RomFS + * @param offset The offset the romfs begins on + * @param size The size of the romfs * @return ResultStatus result of function */ - virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const { + virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) { return ResultStatus::ErrorNotImplemented; } protected: - std::unique_ptr<FileUtil::IOFile> file; - bool is_loaded = false; + FileUtil::IOFile file; + bool is_loaded = false; }; /** diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 87603d198..094d74100 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -117,7 +117,7 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_NCCH::LoadExec() const { +ResultStatus AppLoader_NCCH::LoadExec() { using Kernel::SharedPtr; using Kernel::CodeSet; @@ -171,8 +171,8 @@ ResultStatus AppLoader_NCCH::LoadExec() const { return ResultStatus::Error; } -ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const { - if (!file->IsOpen()) +ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) { + if (!file.IsOpen()) return ResultStatus::Error; LOG_DEBUG(Loader, "%d sections:", kMaxSections); @@ -186,7 +186,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& section.offset, section.size, section.name); s64 section_offset = (section.offset + exefs_offset + sizeof(ExeFs_Header) + ncch_offset); - file->Seek(section_offset, SEEK_SET); + file.Seek(section_offset, SEEK_SET); if (is_compressed) { // Section is compressed, read compressed .code section... @@ -197,7 +197,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& return ResultStatus::ErrorMemoryAllocationFailed; } - if (file->ReadBytes(&temp_buffer[0], section.size) != section.size) + if (file.ReadBytes(&temp_buffer[0], section.size) != section.size) return ResultStatus::Error; // Decompress .code section... @@ -208,7 +208,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& } else { // Section is uncompressed... buffer.resize(section.size); - if (file->ReadBytes(&buffer[0], section.size) != section.size) + if (file.ReadBytes(&buffer[0], section.size) != section.size) return ResultStatus::Error; } return ResultStatus::Success; @@ -221,21 +221,21 @@ ResultStatus AppLoader_NCCH::Load() { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; - if (!file->IsOpen()) + if (!file.IsOpen()) return ResultStatus::Error; // Reset read pointer in case this file has been read before. - file->Seek(0, SEEK_SET); + file.Seek(0, SEEK_SET); - if (file->ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header)) + if (file.ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header)) return ResultStatus::Error; // Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)... if (MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) { LOG_WARNING(Loader, "Only loading the first (bootable) NCCH within the NCSD file!"); ncch_offset = 0x4000; - file->Seek(ncch_offset, SEEK_SET); - file->ReadBytes(&ncch_header, sizeof(NCCH_Header)); + file.Seek(ncch_offset, SEEK_SET); + file.ReadBytes(&ncch_header, sizeof(NCCH_Header)); } // Verify we are loading the correct file type... @@ -244,7 +244,7 @@ ResultStatus AppLoader_NCCH::Load() { // Read ExHeader... - if (file->ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != sizeof(ExHeader_Header)) + if (file.ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != sizeof(ExHeader_Header)) return ResultStatus::Error; is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; @@ -274,8 +274,8 @@ ResultStatus AppLoader_NCCH::Load() { LOG_DEBUG(Loader, "ExeFS offset: 0x%08X", exefs_offset); LOG_DEBUG(Loader, "ExeFS size: 0x%08X", exefs_size); - file->Seek(exefs_offset + ncch_offset, SEEK_SET); - if (file->ReadBytes(&exefs_header, sizeof(ExeFs_Header)) != sizeof(ExeFs_Header)) + file.Seek(exefs_offset + ncch_offset, SEEK_SET); + if (file.ReadBytes(&exefs_header, sizeof(ExeFs_Header)) != sizeof(ExeFs_Header)) return ResultStatus::Error; is_loaded = true; // Set state to loaded @@ -283,24 +283,24 @@ ResultStatus AppLoader_NCCH::Load() { return LoadExec(); // Load the executable into memory for booting } -ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) const { +ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) { return LoadSectionExeFS(".code", buffer); } -ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) const { +ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) { return LoadSectionExeFS("icon", buffer); } -ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) const { +ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) { return LoadSectionExeFS("banner", buffer); } -ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const { +ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) { return LoadSectionExeFS("logo", buffer); } -ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { - if (!file->IsOpen()) +ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) { + if (!file.IsOpen()) return ResultStatus::Error; // Check if the NCCH has a RomFS... @@ -311,12 +311,17 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const { LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset); LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size); - buffer.resize(romfs_size); + if (file.GetSize () < romfs_offset + romfs_size) + return ResultStatus::Error; - file->Seek(romfs_offset, SEEK_SET); - if (file->ReadBytes(&buffer[0], romfs_size) != romfs_size) + // We reopen the file, to allow its position to be independent from file's + romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb"); + if (!romfs_file->IsOpen()) return ResultStatus::Error; + offset = romfs_offset; + size = romfs_size; + return ResultStatus::Success; } LOG_DEBUG(Loader, "NCCH has no RomFS"); diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 29e39d2c0..b4374a476 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -163,7 +163,8 @@ namespace Loader { /// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI) class AppLoader_NCCH final : public AppLoader { public: - AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { } + AppLoader_NCCH(FileUtil::IOFile&& file, const std::string& filepath) + : AppLoader(std::move(file)), filepath(filepath) { } /** * Returns the type of the file @@ -183,35 +184,35 @@ public: * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadCode(std::vector<u8>& buffer) const override; + ResultStatus ReadCode(std::vector<u8>& buffer) override; /** * Get the icon (typically icon section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadIcon(std::vector<u8>& buffer) const override; + ResultStatus ReadIcon(std::vector<u8>& buffer) override; /** * Get the banner (typically banner section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadBanner(std::vector<u8>& buffer) const override; + ResultStatus ReadBanner(std::vector<u8>& buffer) override; /** * Get the logo (typically logo section) of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadLogo(std::vector<u8>& buffer) const override; + ResultStatus ReadLogo(std::vector<u8>& buffer) override; /** * Get the RomFS of the application * @param buffer Reference to buffer to store data * @return ResultStatus result of function */ - ResultStatus ReadRomFS(std::vector<u8>& buffer) const override; + ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) override; private: @@ -221,13 +222,13 @@ private: * @param buffer Vector to read data into * @return ResultStatus result of function */ - ResultStatus LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const; + ResultStatus LoadSectionExeFS(const char* name, std::vector<u8>& buffer); /** * Loads .code section into memory for booting * @return ResultStatus result of function */ - ResultStatus LoadExec() const; + ResultStatus LoadExec(); bool is_compressed = false; @@ -244,6 +245,8 @@ private: NCCH_Header ncch_header; ExeFs_Header exefs_header; ExHeader_Header exheader_header; + + std::string filepath; }; } // namespace Loader diff --git a/src/video_core/clipper.cpp b/src/video_core/clipper.cpp index 224132d71..558b49d60 100644 --- a/src/video_core/clipper.cpp +++ b/src/video_core/clipper.cpp @@ -153,7 +153,7 @@ void ProcessTriangle(OutputVertex &v0, OutputVertex &v1, OutputVertex &v2) { "Triangle %lu/%lu at position (%.3f, %.3f, %.3f, %.3f), " "(%.3f, %.3f, %.3f, %.3f), (%.3f, %.3f, %.3f, %.3f) and " "screen position (%.2f, %.2f, %.2f), (%.2f, %.2f, %.2f), (%.2f, %.2f, %.2f)", - i, output_list->size(), + i + 1, output_list->size() - 2, vtx0.pos.x.ToFloat32(), vtx0.pos.y.ToFloat32(), vtx0.pos.z.ToFloat32(), vtx0.pos.w.ToFloat32(), vtx1.pos.x.ToFloat32(), vtx1.pos.y.ToFloat32(), vtx1.pos.z.ToFloat32(), vtx1.pos.w.ToFloat32(), vtx2.pos.x.ToFloat32(), vtx2.pos.y.ToFloat32(), vtx2.pos.z.ToFloat32(), vtx2.pos.w.ToFloat32(), diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 668127055..8b10d7340 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp @@ -60,6 +60,46 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::P3D); break; + // Load default vertex input attributes + case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[0], 0x233): + case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[1], 0x234): + case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[2], 0x235): + { + // TODO: Does actual hardware indeed keep an intermediate buffer or does + // it directly write the values? + default_attr_write_buffer[default_attr_counter++] = value; + + // Default attributes are written in a packed format such that four float24 values are encoded in + // three 32-bit numbers. We write to internal memory once a full such vector is + // written. + if (default_attr_counter >= 3) { + default_attr_counter = 0; + + auto& setup = regs.vs_default_attributes_setup; + + if (setup.index >= 16) { + LOG_ERROR(HW_GPU, "Invalid VS default attribute index %d", (int)setup.index); + break; + } + + Math::Vec4<float24>& attribute = g_state.vs.default_attributes[setup.index]; + + // NOTE: The destination component order indeed is "backwards" + attribute.w = float24::FromRawFloat24(default_attr_write_buffer[0] >> 8); + attribute.z = float24::FromRawFloat24(((default_attr_write_buffer[0] & 0xFF) << 16) | ((default_attr_write_buffer[1] >> 16) & 0xFFFF)); + attribute.y = float24::FromRawFloat24(((default_attr_write_buffer[1] & 0xFFFF) << 8) | ((default_attr_write_buffer[2] >> 24) & 0xFF)); + attribute.x = float24::FromRawFloat24(default_attr_write_buffer[2] & 0xFFFFFF); + + LOG_TRACE(HW_GPU, "Set default VS attribute %x to (%f %f %f %f)", (int)setup.index, + attribute.x.ToFloat32(), attribute.y.ToFloat32(), attribute.z.ToFloat32(), + attribute.w.ToFloat32()); + + // TODO: Verify that this actually modifies the register! + setup.index = setup.index + 1; + } + break; + } + case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[0], 0x23c): case PICA_REG_INDEX_WORKAROUND(command_buffer.trigger[1], 0x23d): { @@ -351,46 +391,6 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { break; } - // Load default vertex input attributes - case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[0], 0x233): - case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[1], 0x234): - case PICA_REG_INDEX_WORKAROUND(vs_default_attributes_setup.set_value[2], 0x235): - { - // TODO: Does actual hardware indeed keep an intermediate buffer or does - // it directly write the values? - default_attr_write_buffer[default_attr_counter++] = value; - - // Default attributes are written in a packed format such that four float24 values are encoded in - // three 32-bit numbers. We write to internal memory once a full such vector is - // written. - if (default_attr_counter >= 3) { - default_attr_counter = 0; - - auto& setup = regs.vs_default_attributes_setup; - - if (setup.index >= 16) { - LOG_ERROR(HW_GPU, "Invalid VS default attribute index %d", (int)setup.index); - break; - } - - Math::Vec4<float24>& attribute = g_state.vs.default_attributes[setup.index]; - - // NOTE: The destination component order indeed is "backwards" - attribute.w = float24::FromRawFloat24(default_attr_write_buffer[0] >> 8); - attribute.z = float24::FromRawFloat24(((default_attr_write_buffer[0] & 0xFF) << 16) | ((default_attr_write_buffer[1] >> 16) & 0xFFFF)); - attribute.y = float24::FromRawFloat24(((default_attr_write_buffer[1] & 0xFFFF) << 8) | ((default_attr_write_buffer[2] >> 24) & 0xFF)); - attribute.x = float24::FromRawFloat24(default_attr_write_buffer[2] & 0xFFFFFF); - - LOG_TRACE(HW_GPU, "Set default VS attribute %x to (%f %f %f %f)", (int)setup.index, - attribute.x.ToFloat32(), attribute.y.ToFloat32(), attribute.z.ToFloat32(), - attribute.w.ToFloat32()); - - // TODO: Verify that this actually modifies the register! - setup.index = setup.index + 1; - } - break; - } - // Load shader program code case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[0], 0x2cc): case PICA_REG_INDEX_WORKAROUND(vs.program.set_word[1], 0x2cd): diff --git a/src/video_core/pica.h b/src/video_core/pica.h index b32db76eb..5da182794 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -132,8 +132,8 @@ struct Regs { }; union { - BitField< 8, 2, WrapMode> wrap_s; - BitField<12, 2, WrapMode> wrap_t; + BitField< 8, 2, WrapMode> wrap_t; + BitField<12, 2, WrapMode> wrap_s; }; INSERT_PADDING_WORDS(0x1); @@ -200,6 +200,7 @@ struct Regs { case TextureFormat::IA8: return 4; + case TextureFormat::I4: case TextureFormat::A4: return 1; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 935a9f281..2db845da6 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -816,12 +816,16 @@ void RasterizerOpenGL::ReloadColorBuffer() { } void RasterizerOpenGL::ReloadDepthBuffer() { + PAddr depth_buffer_addr = Pica::g_state.regs.framebuffer.GetDepthBufferPhysicalAddress(); + + if (depth_buffer_addr == 0) + return; + // TODO: Appears to work, but double-check endianness of depth values and order of depth-stencil - u8* depth_buffer = Memory::GetPhysicalPointer(Pica::g_state.regs.framebuffer.GetDepthBufferPhysicalAddress()); + u8* depth_buffer = Memory::GetPhysicalPointer(depth_buffer_addr); - if (depth_buffer == nullptr) { + if (depth_buffer == nullptr) return; - } u32 bytes_per_pixel = Pica::Regs::BytesPerDepthPixel(fb_depth_texture.format); diff --git a/src/video_core/vertex_shader.cpp b/src/video_core/vertex_shader.cpp index c00f0c10b..b77503806 100644 --- a/src/video_core/vertex_shader.cpp +++ b/src/video_core/vertex_shader.cpp @@ -221,7 +221,7 @@ static void ProcessShaderCode(VertexShaderState& state) { for (int i = 0; i < num_components; ++i) dot = dot + src1[i] * src2[i]; - for (int i = 0; i < num_components; ++i) { + for (int i = 0; i < 4; ++i) { if (!swizzle.DestComponentEnabled(i)) continue; |