diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 7107bfc60..11f9d174c 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -30,9 +30,9 @@ void EmuThread::run() { stop_run = false; - // holds whether the cpu was running during the last iteration, + // Holds whether the cpu was running during the last iteration, // so that the DebugModeLeft signal can be emitted before the - // next execution step + // next execution step. bool was_active = false; while (!stop_run) { if (running) { diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index a8e3541cd..c98a8b036 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -174,7 +174,7 @@ void GameList::onTextChanged(const QString& newText) { child_file->data(GameListItemPath::ProgramIdRole).toString().toLower(); // Only items which filename in combination with its title contains all words - // that are in the searchfiel will be visible in the gamelist + // that are in the searchfield will be visible in the gamelist // The search is case insensitive because of toLower() // I decided not to use Qt::CaseInsensitive in containsAllWords to prevent // multiple conversions of edit_filter_text for each game in the gamelist diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 38661adde..45d81e0f5 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include "common/common_types.h" diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 1d1b57df5..6bbcd96fc 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -24,6 +24,9 @@ namespace Service { namespace AM { +constexpr u32 TID_HIGH_UPDATE = 0x0004000E; +constexpr u32 TID_HIGH_DLC = 0x0004008C; + static bool lists_initialized = false; static std::array, 3> am_title_list; @@ -182,7 +185,7 @@ void GetNumPrograms(Service::Interface* self) { } void FindContentInfos(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1002, 4, 2); // 0x10020104 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1002, 4, 4); // 0x10020104 auto media_type = static_cast(rp.Pop()); u64 title_id = rp.Pop(); @@ -225,7 +228,7 @@ void FindContentInfos(Service::Interface* self) { } void ListContentInfos(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1003, 5, 1); // 0x10030142 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1003, 5, 2); // 0x10030142 u32 content_count = rp.Pop(); auto media_type = static_cast(rp.Pop()); u64 title_id = rp.Pop(); @@ -264,7 +267,7 @@ void ListContentInfos(Service::Interface* self) { } void DeleteContents(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1004, 4, 1); // 0x10040102 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1004, 4, 2); // 0x10040102 u8 media_type = rp.Pop(); u64 title_id = rp.Pop(); u32 content_count = rp.Pop(); @@ -278,7 +281,7 @@ void DeleteContents(Service::Interface* self) { } void GetProgramList(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 2, 2, 1); // 0x00020082 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 2, 2, 2); // 0x00020082 u32 count = rp.Pop(); u8 media_type = rp.Pop(); @@ -302,18 +305,9 @@ void GetProgramList(Service::Interface* self) { rb.Push(copied); } -void GetProgramInfos(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 3, 2, 2); // 0x00030084 - - auto media_type = static_cast(rp.Pop()); - u32 title_count = rp.Pop(); - VAddr title_id_list_pointer = rp.PopMappedBuffer(); - VAddr title_info_out = rp.PopMappedBuffer(); - - std::vector title_id_list(title_count); - Memory::ReadBlock(title_id_list_pointer, title_id_list.data(), title_count * sizeof(u64)); - - for (u32 i = 0; i < title_count; i++) { +ResultCode GetTitleInfoFromList(const std::vector& title_id_list, + Service::FS::MediaType media_type, VAddr title_info_out) { + for (u32 i = 0; i < title_id_list.size(); i++) { std::string tmd_path = GetTitleMetadataPath(media_type, title_id_list[i]); TitleInfo title_info = {}; @@ -326,23 +320,113 @@ void GetProgramInfos(Service::Interface* self) { title_info.size = tmd.GetContentSizeByIndex(FileSys::TMDContentIndex::Main); title_info.version = tmd.GetTitleVersion(); title_info.type = tmd.GetTitleType(); + } else { + return ResultCode(ErrorDescription::NotFound, ErrorModule::AM, + ErrorSummary::InvalidState, ErrorLevel::Permanent); } Memory::WriteBlock(title_info_out, &title_info, sizeof(TitleInfo)); title_info_out += sizeof(TitleInfo); } - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(RESULT_SUCCESS); + return RESULT_SUCCESS; } -void GetDataTitleInfos(Service::Interface* self) { - GetProgramInfos(self); +void GetProgramInfos(Service::Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 3, 2, 4); // 0x00030084 - LOG_WARNING(Service_AM, "(STUBBED) called"); + auto media_type = static_cast(rp.Pop()); + u32 title_count = rp.Pop(); + + size_t title_id_list_size, title_info_size; + IPC::MappedBufferPermissions title_id_list_perms, title_info_perms; + VAddr title_id_list_pointer = rp.PopMappedBuffer(&title_id_list_size, &title_id_list_perms); + VAddr title_info_out = rp.PopMappedBuffer(&title_info_size, &title_info_perms); + + std::vector title_id_list(title_count); + Memory::ReadBlock(title_id_list_pointer, title_id_list.data(), title_count * sizeof(u64)); + + ResultCode result = GetTitleInfoFromList(title_id_list, media_type, title_info_out); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); + rb.Push(result); + rb.PushMappedBuffer(title_id_list_pointer, title_id_list_size, title_id_list_perms); + rb.PushMappedBuffer(title_info_out, title_info_size, title_info_perms); +} + +void GetDLCTitleInfos(Service::Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1005, 2, 4); // 0x10050084 + + auto media_type = static_cast(rp.Pop()); + u32 title_count = rp.Pop(); + + size_t title_id_list_size, title_info_size; + IPC::MappedBufferPermissions title_id_list_perms, title_info_perms; + VAddr title_id_list_pointer = rp.PopMappedBuffer(&title_id_list_size, &title_id_list_perms); + VAddr title_info_out = rp.PopMappedBuffer(&title_info_size, &title_info_perms); + + std::vector title_id_list(title_count); + Memory::ReadBlock(title_id_list_pointer, title_id_list.data(), title_count * sizeof(u64)); + + ResultCode result = RESULT_SUCCESS; + + // Validate that DLC TIDs were passed in + for (u32 i = 0; i < title_count; i++) { + u32 tid_high = static_cast(title_id_list[i] >> 32); + if (tid_high != TID_HIGH_DLC) { + result = ResultCode(ErrCodes::InvalidTIDInList, ErrorModule::AM, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); + break; + } + } + + if (result.IsSuccess()) { + result = GetTitleInfoFromList(title_id_list, media_type, title_info_out); + } + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); + rb.Push(result); + rb.PushMappedBuffer(title_id_list_pointer, title_id_list_size, title_id_list_perms); + rb.PushMappedBuffer(title_info_out, title_info_size, title_info_perms); +} + +void GetPatchTitleInfos(Service::Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x100D, 2, 4); // 0x100D0084 + + auto media_type = static_cast(rp.Pop()); + u32 title_count = rp.Pop(); + + size_t title_id_list_size, title_info_size; + IPC::MappedBufferPermissions title_id_list_perms, title_info_perms; + VAddr title_id_list_pointer = rp.PopMappedBuffer(&title_id_list_size, &title_id_list_perms); + VAddr title_info_out = rp.PopMappedBuffer(&title_info_size, &title_info_perms); + + std::vector title_id_list(title_count); + Memory::ReadBlock(title_id_list_pointer, title_id_list.data(), title_count * sizeof(u64)); + + ResultCode result = RESULT_SUCCESS; + + // Validate that update TIDs were passed in + for (u32 i = 0; i < title_count; i++) { + u32 tid_high = static_cast(title_id_list[i] >> 32); + if (tid_high != TID_HIGH_UPDATE) { + result = ResultCode(ErrCodes::InvalidTIDInList, ErrorModule::AM, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); + break; + } + } + + if (result.IsSuccess()) { + result = GetTitleInfoFromList(title_id_list, media_type, title_info_out); + } + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 4); + rb.Push(result); + rb.PushMappedBuffer(title_id_list_pointer, title_id_list_size, title_id_list_perms); + rb.PushMappedBuffer(title_info_out, title_info_size, title_info_perms); } void ListDataTitleTicketInfos(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1007, 4, 1); // 0x10070102 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1007, 4, 4); // 0x10070102 u32 ticket_count = rp.Pop(); u64 title_id = rp.Pop(); u32 start_index = rp.Pop(); @@ -408,7 +492,7 @@ void GetNumTickets(Service::Interface* self) { } void GetTicketList(Service::Interface* self) { - IPC::RequestParser rp(Kernel::GetCommandBuffer(), 9, 2, 1); // 0x00090082 + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 9, 2, 2); // 0x00090082 u32 ticket_list_count = rp.Pop(); u32 ticket_index = rp.Pop(); VAddr ticket_tids_out = rp.PopMappedBuffer(); diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 6ee4908b3..e2270c93c 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -19,6 +19,12 @@ class Interface; namespace AM { +namespace ErrCodes { +enum { + InvalidTIDInList = 60, +}; +} // namespace ErrCodes + /** * Get the .tmd path for a title * @param media_type the media the title exists on @@ -139,8 +145,8 @@ void GetProgramList(Service::Interface* self); void GetProgramInfos(Service::Interface* self); /** - * AM::GetDataTitleInfos service function - * Wrapper for AM::GetProgramInfos + * AM::GetDLCTitleInfos service function + * Wrapper for AM::GetProgramInfos, explicitly checks that TID high value is 0004008C. * Inputs: * 1 : u8 Mediatype * 2 : Total titles @@ -149,7 +155,22 @@ void GetProgramInfos(Service::Interface* self); * Outputs: * 1 : Result, 0 on success, otherwise error code */ -void GetDataTitleInfos(Service::Interface* self); +void GetDLCTitleInfos(Service::Interface* self); + +/** + * AM::GetPatchTitleInfos service function + * Wrapper for AM::GetProgramInfos, explicitly checks that TID high value is 0004000E. + * Inputs: + * 1 : u8 Mediatype + * 2 : Total titles + * 4 : TitleIDList input pointer + * 6 : TitleList output pointer + * Outputs: + * 1 : Result, 0 on success, otherwise error code + * 2 : TitleIDList input pointer + * 4 : TitleList output pointer + */ +void GetPatchTitleInfos(Service::Interface* self); /** * AM::ListDataTitleTicketInfos service function diff --git a/src/core/hle/service/am/am_app.cpp b/src/core/hle/service/am/am_app.cpp index 218375c8f..db85067d0 100644 --- a/src/core/hle/service/am/am_app.cpp +++ b/src/core/hle/service/am/am_app.cpp @@ -13,7 +13,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x10020104, FindContentInfos, "FindContentInfos"}, {0x10030142, ListContentInfos, "ListContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, - {0x10050084, GetDataTitleInfos, "GetDataTitleInfos"}, + {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, {0x10060080, nullptr, "GetNumDataTitleTickets"}, {0x10070102, ListDataTitleTicketInfos, "ListDataTitleTicketInfos"}, {0x100801C2, nullptr, "GetItemRights"}, @@ -21,7 +21,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x100A0000, nullptr, "IsExternalTitleDatabaseInitialized"}, {0x100B00C0, nullptr, "GetNumExistingContentInfos"}, {0x100C0142, nullptr, "ListExistingContentInfos"}, - {0x100D0084, nullptr, "GetPatchTitleInfos"}, + {0x100D0084, GetPatchTitleInfos, "GetPatchTitleInfos"}, }; AM_APP_Interface::AM_APP_Interface() { diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index 5112a6a0d..7787fdfed 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -58,7 +58,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x10020104, FindContentInfos, "FindContentInfos"}, {0x10030142, ListContentInfos, "ListContentInfos"}, {0x10040102, DeleteContents, "DeleteContents"}, - {0x10050084, GetDataTitleInfos, "GetDataTitleInfos"}, + {0x10050084, GetDLCTitleInfos, "GetDLCTitleInfos"}, {0x10060080, nullptr, "GetNumDataTitleTickets"}, {0x10070102, ListDataTitleTicketInfos, "ListDataTitleTicketInfos"}, {0x100801C2, nullptr, "GetItemRights"}, @@ -66,7 +66,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x100A0000, nullptr, "IsExternalTitleDatabaseInitialized"}, {0x100B00C0, nullptr, "GetNumExistingContentInfos"}, {0x100C0142, nullptr, "ListExistingContentInfos"}, - {0x100D0084, nullptr, "GetPatchTitleInfos"}, + {0x100D0084, GetPatchTitleInfos, "GetPatchTitleInfos"}, }; AM_SYS_Interface::AM_SYS_Interface() { diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 7f58be6de..4fc964575 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -393,7 +393,7 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { case PageType::RasterizerCachedMemory: { u8* pointer = GetPointerFromVMA(vaddr & ~PAGE_MASK); if (pointer == nullptr) { - // It's possible that this function has called been while updating the pagetable + // It's possible that this function has been called while updating the pagetable // after unmapping a VMA. In that case the underlying VMA will no longer exist, // and we should just leave the pagetable entry blank. page_type = PageType::Unmapped; diff --git a/src/video_core/swrasterizer/clipper.cpp b/src/video_core/swrasterizer/clipper.cpp index c1ed48398..4ede218e3 100644 --- a/src/video_core/swrasterizer/clipper.cpp +++ b/src/video_core/swrasterizer/clipper.cpp @@ -20,7 +20,6 @@ using Pica::Rasterizer::Vertex; namespace Pica { - namespace Clipper { struct ClippingEdge { @@ -192,6 +191,5 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu } } -} // namespace - -} // namespace +} // namespace Clipper +} // namespace Pica diff --git a/src/video_core/swrasterizer/clipper.h b/src/video_core/swrasterizer/clipper.h index b51af0af9..c9e14e3d7 100644 --- a/src/video_core/swrasterizer/clipper.h +++ b/src/video_core/swrasterizer/clipper.h @@ -5,7 +5,6 @@ #pragma once namespace Pica { - namespace Shader { struct OutputVertex; } @@ -16,6 +15,5 @@ using Shader::OutputVertex; void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const OutputVertex& v2); -} // namespace - -} // namespace +} // namespace Clipper +} // namespace Pica diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 862135614..586587eb8 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -376,8 +376,9 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve if (use_border_s || use_border_t) { auto border_color = texture.config.border_color; - texture_color[i] = {border_color.r, border_color.g, border_color.b, - border_color.a}; + texture_color[i] = Math::MakeVec(border_color.r.Value(), border_color.g.Value(), + border_color.b.Value(), border_color.a.Value()) + .Cast(); } else { // Textures are laid out from bottom to top, hence we invert the t coordinate. // NOTE: This may not be the right place for the inversion. @@ -414,12 +415,12 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve // analogously. Math::Vec4 combiner_output; Math::Vec4 combiner_buffer = {0, 0, 0, 0}; - Math::Vec4 next_combiner_buffer = { - regs.texturing.tev_combiner_buffer_color.r, - regs.texturing.tev_combiner_buffer_color.g, - regs.texturing.tev_combiner_buffer_color.b, - regs.texturing.tev_combiner_buffer_color.a, - }; + Math::Vec4 next_combiner_buffer = + Math::MakeVec(regs.texturing.tev_combiner_buffer_color.r.Value(), + regs.texturing.tev_combiner_buffer_color.g.Value(), + regs.texturing.tev_combiner_buffer_color.b.Value(), + regs.texturing.tev_combiner_buffer_color.a.Value()) + .Cast(); Math::Vec4 primary_fragment_color = {0, 0, 0, 0}; Math::Vec4 secondary_fragment_color = {0, 0, 0, 0}; @@ -473,8 +474,9 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve return combiner_buffer; case Source::Constant: - return {tev_stage.const_r, tev_stage.const_g, tev_stage.const_b, - tev_stage.const_a}; + return Math::MakeVec(tev_stage.const_r.Value(), tev_stage.const_g.Value(), + tev_stage.const_b.Value(), tev_stage.const_a.Value()) + .Cast(); case Source::Previous: return combiner_output; @@ -587,11 +589,10 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve // store the depth etc. Using float for now until we know more // about Pica datatypes if (regs.texturing.fog_mode == TexturingRegs::FogMode::Fog) { - const Math::Vec3 fog_color = { - static_cast(regs.texturing.fog_color.r.Value()), - static_cast(regs.texturing.fog_color.g.Value()), - static_cast(regs.texturing.fog_color.b.Value()), - }; + const Math::Vec3 fog_color = Math::MakeVec(regs.texturing.fog_color.r.Value(), + regs.texturing.fog_color.g.Value(), + regs.texturing.fog_color.b.Value()) + .Cast(); // Get index into fog LUT float fog_index; @@ -743,12 +744,12 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve FramebufferRegs::BlendFactor factor) -> u8 { DEBUG_ASSERT(channel < 4); - const Math::Vec4 blend_const = { - static_cast(output_merger.blend_const.r), - static_cast(output_merger.blend_const.g), - static_cast(output_merger.blend_const.b), - static_cast(output_merger.blend_const.a), - }; + const Math::Vec4 blend_const = + Math::MakeVec(output_merger.blend_const.r.Value(), + output_merger.blend_const.g.Value(), + output_merger.blend_const.b.Value(), + output_merger.blend_const.a.Value()) + .Cast(); switch (factor) { case FramebufferRegs::BlendFactor::Zero: @@ -849,5 +850,4 @@ void ProcessTriangle(const Vertex& v0, const Vertex& v1, const Vertex& v2) { } } // namespace Rasterizer - } // namespace Pica diff --git a/src/video_core/swrasterizer/rasterizer.h b/src/video_core/swrasterizer/rasterizer.h index 66cd6cfd4..0670776a9 100644 --- a/src/video_core/swrasterizer/rasterizer.h +++ b/src/video_core/swrasterizer/rasterizer.h @@ -7,7 +7,6 @@ #include "video_core/shader/shader.h" namespace Pica { - namespace Rasterizer { struct Vertex : Shader::OutputVertex { @@ -44,5 +43,4 @@ struct Vertex : Shader::OutputVertex { void ProcessTriangle(const Vertex& v0, const Vertex& v1, const Vertex& v2); } // namespace Rasterizer - } // namespace Pica diff --git a/src/video_core/swrasterizer/swrasterizer.cpp b/src/video_core/swrasterizer/swrasterizer.cpp index 402b705dd..cda5d52da 100644 --- a/src/video_core/swrasterizer/swrasterizer.cpp +++ b/src/video_core/swrasterizer/swrasterizer.cpp @@ -12,4 +12,5 @@ void SWRasterizer::AddTriangle(const Pica::Shader::OutputVertex& v0, const Pica::Shader::OutputVertex& v2) { Pica::Clipper::ProcessTriangle(v0, v1, v2); } -} + +} // namespace VideoCore diff --git a/src/video_core/swrasterizer/swrasterizer.h b/src/video_core/swrasterizer/swrasterizer.h index 6d42d7409..87e64f8f6 100644 --- a/src/video_core/swrasterizer/swrasterizer.h +++ b/src/video_core/swrasterizer/swrasterizer.h @@ -24,4 +24,5 @@ class SWRasterizer : public RasterizerInterface { void FlushRegion(PAddr addr, u32 size) override {} void FlushAndInvalidateRegion(PAddr addr, u32 size) override {} }; -} + +} // namespace VideoCore