diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/game_list_p.h | 53 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 47 | ||||
| -rw-r--r-- | src/core/loader/smdh.cpp | 54 | ||||
| -rw-r--r-- | src/core/loader/smdh.h | 82 |
5 files changed, 149 insertions, 89 deletions
diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index 284f5da81..121f90b0c 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h | |||
| @@ -15,52 +15,21 @@ | |||
| 15 | #include "common/string_util.h" | 15 | #include "common/string_util.h" |
| 16 | #include "common/color.h" | 16 | #include "common/color.h" |
| 17 | 17 | ||
| 18 | #include "core/loader/loader.h" | 18 | #include "core/loader/smdh.h" |
| 19 | 19 | ||
| 20 | #include "video_core/utils.h" | 20 | #include "video_core/utils.h" |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * Tests if data is a valid SMDH by its length and magic number. | ||
| 24 | * @param smdh_data data buffer to test | ||
| 25 | * @return bool test result | ||
| 26 | */ | ||
| 27 | static bool IsValidSMDH(const std::vector<u8>& smdh_data) { | ||
| 28 | if (smdh_data.size() < sizeof(Loader::SMDH)) | ||
| 29 | return false; | ||
| 30 | |||
| 31 | u32 magic; | ||
| 32 | memcpy(&magic, smdh_data.data(), 4); | ||
| 33 | |||
| 34 | return Loader::MakeMagic('S', 'M', 'D', 'H') == magic; | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Gets game icon from SMDH | 23 | * Gets game icon from SMDH |
| 39 | * @param sdmh SMDH data | 24 | * @param sdmh SMDH data |
| 40 | * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24) | 25 | * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24) |
| 41 | * @return QPixmap game icon | 26 | * @return QPixmap game icon |
| 42 | */ | 27 | */ |
| 43 | static QPixmap GetIconFromSMDH(const Loader::SMDH& smdh, bool large) { | 28 | static QPixmap GetQPixmapFromSMDH(const Loader::SMDH& smdh, bool large) { |
| 44 | u32 size; | 29 | std::vector<u16> icon_data = smdh.GetIcon(large); |
| 45 | const u8* icon_data; | 30 | const uchar* data = reinterpret_cast<const uchar*>(icon_data.data()); |
| 46 | 31 | int size = large ? 48 : 24; | |
| 47 | if (large) { | 32 | QImage icon(data, size, size, QImage::Format::Format_RGB16); |
| 48 | size = 48; | ||
| 49 | icon_data = smdh.large_icon.data(); | ||
| 50 | } else { | ||
| 51 | size = 24; | ||
| 52 | icon_data = smdh.small_icon.data(); | ||
| 53 | } | ||
| 54 | |||
| 55 | QImage icon(size, size, QImage::Format::Format_RGB888); | ||
| 56 | for (u32 x = 0; x < size; ++x) { | ||
| 57 | for (u32 y = 0; y < size; ++y) { | ||
| 58 | u32 coarse_y = y & ~7; | ||
| 59 | auto v = Color::DecodeRGB565( | ||
| 60 | icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2); | ||
| 61 | icon.setPixel(x, y, qRgb(v.r(), v.g(), v.b())); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | return QPixmap::fromImage(icon); | 33 | return QPixmap::fromImage(icon); |
| 65 | } | 34 | } |
| 66 | 35 | ||
| @@ -82,8 +51,8 @@ static QPixmap GetDefaultIcon(bool large) { | |||
| 82 | * @param language title language | 51 | * @param language title language |
| 83 | * @return QString short title | 52 | * @return QString short title |
| 84 | */ | 53 | */ |
| 85 | static QString GetShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) { | 54 | static QString GetQStringShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) { |
| 86 | return QString::fromUtf16(smdh.titles[static_cast<int>(language)].short_title.data()); | 55 | return QString::fromUtf16(smdh.GetShortTitle(language).data()); |
| 87 | } | 56 | } |
| 88 | 57 | ||
| 89 | class GameListItem : public QStandardItem { | 58 | class GameListItem : public QStandardItem { |
| @@ -112,7 +81,7 @@ public: | |||
| 112 | { | 81 | { |
| 113 | setData(game_path, FullPathRole); | 82 | setData(game_path, FullPathRole); |
| 114 | 83 | ||
| 115 | if (!IsValidSMDH(smdh_data)) { | 84 | if (!Loader::IsValidSMDH(smdh_data)) { |
| 116 | // SMDH is not valid, set a default icon | 85 | // SMDH is not valid, set a default icon |
| 117 | setData(GetDefaultIcon(true), Qt::DecorationRole); | 86 | setData(GetDefaultIcon(true), Qt::DecorationRole); |
| 118 | return; | 87 | return; |
| @@ -122,10 +91,10 @@ public: | |||
| 122 | memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); | 91 | memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); |
| 123 | 92 | ||
| 124 | // Get icon from SMDH | 93 | // Get icon from SMDH |
| 125 | setData(GetIconFromSMDH(smdh, true), Qt::DecorationRole); | 94 | setData(GetQPixmapFromSMDH(smdh, true), Qt::DecorationRole); |
| 126 | 95 | ||
| 127 | // Get title form SMDH | 96 | // Get title form SMDH |
| 128 | setData(GetShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole); | 97 | setData(GetQStringShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole); |
| 129 | } | 98 | } |
| 130 | 99 | ||
| 131 | QVariant data(int role) const override { | 100 | QVariant data(int role) const override { |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 12080a802..ed80cf0e4 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -121,6 +121,7 @@ set(SRCS | |||
| 121 | loader/elf.cpp | 121 | loader/elf.cpp |
| 122 | loader/loader.cpp | 122 | loader/loader.cpp |
| 123 | loader/ncch.cpp | 123 | loader/ncch.cpp |
| 124 | loader/smdh.cpp | ||
| 124 | tracer/recorder.cpp | 125 | tracer/recorder.cpp |
| 125 | memory.cpp | 126 | memory.cpp |
| 126 | settings.cpp | 127 | settings.cpp |
| @@ -256,6 +257,7 @@ set(HEADERS | |||
| 256 | loader/elf.h | 257 | loader/elf.h |
| 257 | loader/loader.h | 258 | loader/loader.h |
| 258 | loader/ncch.h | 259 | loader/ncch.h |
| 260 | loader/smdh.h | ||
| 259 | tracer/recorder.h | 261 | tracer/recorder.h |
| 260 | tracer/citrace.h | 262 | tracer/citrace.h |
| 261 | memory.h | 263 | memory.h |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 39aedfeeb..77d87afe1 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -10,10 +10,8 @@ | |||
| 10 | #include <string> | 10 | #include <string> |
| 11 | #include <vector> | 11 | #include <vector> |
| 12 | 12 | ||
| 13 | #include "common/common_funcs.h" | ||
| 14 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 15 | #include "common/file_util.h" | 14 | #include "common/file_util.h" |
| 16 | #include "common/swap.h" | ||
| 17 | 15 | ||
| 18 | namespace Kernel { | 16 | namespace Kernel { |
| 19 | struct AddressMapping; | 17 | struct AddressMapping; |
| @@ -80,51 +78,6 @@ constexpr u32 MakeMagic(char a, char b, char c, char d) { | |||
| 80 | return a | b << 8 | c << 16 | d << 24; | 78 | return a | b << 8 | c << 16 | d << 24; |
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | /// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH | ||
| 84 | struct SMDH { | ||
| 85 | u32_le magic; | ||
| 86 | u16_le version; | ||
| 87 | INSERT_PADDING_BYTES(2); | ||
| 88 | |||
| 89 | struct Title { | ||
| 90 | std::array<u16, 0x40> short_title; | ||
| 91 | std::array<u16, 0x80> long_title; | ||
| 92 | std::array<u16, 0x40> publisher; | ||
| 93 | }; | ||
| 94 | std::array<Title, 16> titles; | ||
| 95 | |||
| 96 | std::array<u8, 16> ratings; | ||
| 97 | u32_le region_lockout; | ||
| 98 | u32_le match_maker_id; | ||
| 99 | u64_le match_maker_bit_id; | ||
| 100 | u32_le flags; | ||
| 101 | u16_le eula_version; | ||
| 102 | INSERT_PADDING_BYTES(2); | ||
| 103 | float_le banner_animation_frame; | ||
| 104 | u32_le cec_id; | ||
| 105 | INSERT_PADDING_BYTES(8); | ||
| 106 | |||
| 107 | std::array<u8, 0x480> small_icon; | ||
| 108 | std::array<u8, 0x1200> large_icon; | ||
| 109 | |||
| 110 | /// indicates the language used for each title entry | ||
| 111 | enum class TitleLanguage { | ||
| 112 | Japanese = 0, | ||
| 113 | English = 1, | ||
| 114 | French = 2, | ||
| 115 | German = 3, | ||
| 116 | Italian = 4, | ||
| 117 | Spanish = 5, | ||
| 118 | SimplifiedChinese = 6, | ||
| 119 | Korean= 7, | ||
| 120 | Dutch = 8, | ||
| 121 | Portuguese = 9, | ||
| 122 | Russian = 10, | ||
| 123 | TraditionalChinese = 11 | ||
| 124 | }; | ||
| 125 | }; | ||
| 126 | static_assert(sizeof(SMDH) == 0x36C0, "SMDH structure size is wrong"); | ||
| 127 | |||
| 128 | /// Interface for loading an application | 81 | /// Interface for loading an application |
| 129 | class AppLoader : NonCopyable { | 82 | class AppLoader : NonCopyable { |
| 130 | public: | 83 | public: |
diff --git a/src/core/loader/smdh.cpp b/src/core/loader/smdh.cpp new file mode 100644 index 000000000..2d014054a --- /dev/null +++ b/src/core/loader/smdh.cpp | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 9 | |||
| 10 | #include "core/loader/loader.h" | ||
| 11 | #include "core/loader/smdh.h" | ||
| 12 | |||
| 13 | #include "video_core/utils.h" | ||
| 14 | |||
| 15 | namespace Loader { | ||
| 16 | |||
| 17 | bool IsValidSMDH(const std::vector<u8>& smdh_data) { | ||
| 18 | if (smdh_data.size() < sizeof(Loader::SMDH)) | ||
| 19 | return false; | ||
| 20 | |||
| 21 | u32 magic; | ||
| 22 | memcpy(&magic, smdh_data.data(), sizeof(u32)); | ||
| 23 | |||
| 24 | return Loader::MakeMagic('S', 'M', 'D', 'H') == magic; | ||
| 25 | } | ||
| 26 | |||
| 27 | std::vector<u16> SMDH::GetIcon(bool large) const { | ||
| 28 | u32 size; | ||
| 29 | const u8* icon_data; | ||
| 30 | |||
| 31 | if (large) { | ||
| 32 | size = 48; | ||
| 33 | icon_data = large_icon.data(); | ||
| 34 | } else { | ||
| 35 | size = 24; | ||
| 36 | icon_data = small_icon.data(); | ||
| 37 | } | ||
| 38 | |||
| 39 | std::vector<u16> icon(size * size); | ||
| 40 | for (u32 x = 0; x < size; ++x) { | ||
| 41 | for (u32 y = 0; y < size; ++y) { | ||
| 42 | u32 coarse_y = y & ~7; | ||
| 43 | const u8* pixel = icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2; | ||
| 44 | icon[x + size * y] = (pixel[1] << 8) + pixel[0]; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | return icon; | ||
| 48 | } | ||
| 49 | |||
| 50 | std::array<u16, 0x40> SMDH::GetShortTitle(Loader::SMDH::TitleLanguage language) const { | ||
| 51 | return titles[static_cast<int>(language)].short_title; | ||
| 52 | } | ||
| 53 | |||
| 54 | } // namespace | ||
diff --git a/src/core/loader/smdh.h b/src/core/loader/smdh.h new file mode 100644 index 000000000..2011abda2 --- /dev/null +++ b/src/core/loader/smdh.h | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "common/common_funcs.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "common/swap.h" | ||
| 13 | |||
| 14 | namespace Loader { | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Tests if data is a valid SMDH by its length and magic number. | ||
| 18 | * @param smdh_data data buffer to test | ||
| 19 | * @return bool test result | ||
| 20 | */ | ||
| 21 | bool IsValidSMDH(const std::vector<u8>& smdh_data); | ||
| 22 | |||
| 23 | /// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH | ||
| 24 | struct SMDH { | ||
| 25 | u32_le magic; | ||
| 26 | u16_le version; | ||
| 27 | INSERT_PADDING_BYTES(2); | ||
| 28 | |||
| 29 | struct Title { | ||
| 30 | std::array<u16, 0x40> short_title; | ||
| 31 | std::array<u16, 0x80> long_title; | ||
| 32 | std::array<u16, 0x40> publisher; | ||
| 33 | }; | ||
| 34 | std::array<Title, 16> titles; | ||
| 35 | |||
| 36 | std::array<u8, 16> ratings; | ||
| 37 | u32_le region_lockout; | ||
| 38 | u32_le match_maker_id; | ||
| 39 | u64_le match_maker_bit_id; | ||
| 40 | u32_le flags; | ||
| 41 | u16_le eula_version; | ||
| 42 | INSERT_PADDING_BYTES(2); | ||
| 43 | float_le banner_animation_frame; | ||
| 44 | u32_le cec_id; | ||
| 45 | INSERT_PADDING_BYTES(8); | ||
| 46 | |||
| 47 | std::array<u8, 0x480> small_icon; | ||
| 48 | std::array<u8, 0x1200> large_icon; | ||
| 49 | |||
| 50 | /// indicates the language used for each title entry | ||
| 51 | enum class TitleLanguage { | ||
| 52 | Japanese = 0, | ||
| 53 | English = 1, | ||
| 54 | French = 2, | ||
| 55 | German = 3, | ||
| 56 | Italian = 4, | ||
| 57 | Spanish = 5, | ||
| 58 | SimplifiedChinese = 6, | ||
| 59 | Korean= 7, | ||
| 60 | Dutch = 8, | ||
| 61 | Portuguese = 9, | ||
| 62 | Russian = 10, | ||
| 63 | TraditionalChinese = 11 | ||
| 64 | }; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Gets game icon from SMDH | ||
| 68 | * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24) | ||
| 69 | * @return vector of RGB565 data | ||
| 70 | */ | ||
| 71 | std::vector<u16> GetIcon(bool large) const; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Gets the short game title from SMDH | ||
| 75 | * @param language title language | ||
| 76 | * @return UTF-16 array of the short title | ||
| 77 | */ | ||
| 78 | std::array<u16, 0x40> GetShortTitle(Loader::SMDH::TitleLanguage language) const; | ||
| 79 | }; | ||
| 80 | static_assert(sizeof(SMDH) == 0x36C0, "SMDH structure size is wrong"); | ||
| 81 | |||
| 82 | } // namespace | ||