diff options
| author | 2016-05-18 00:42:45 +0100 | |
|---|---|---|
| committer | 2016-05-21 20:15:42 +0100 | |
| commit | 080a2d719ca825961ec2db5f26ad22e43d456c5a (patch) | |
| tree | e9ee342eb661cfa41895f9cf7ef983b21b3a52b6 /src/core/loader | |
| parent | CitraQt: Simplify the game list loader code (diff) | |
| download | yuzu-080a2d719ca825961ec2db5f26ad22e43d456c5a.tar.gz yuzu-080a2d719ca825961ec2db5f26ad22e43d456c5a.tar.xz yuzu-080a2d719ca825961ec2db5f26ad22e43d456c5a.zip | |
Loader: Split SMDH into its own header and import helpers from QGameList
Also rewrite Qt wrappers to use those.
Diffstat (limited to 'src/core/loader')
| -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 |
3 files changed, 136 insertions, 47 deletions
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 | ||