diff options
Diffstat (limited to 'src/core/loader/smdh.cpp')
| -rw-r--r-- | src/core/loader/smdh.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
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 | ||