diff options
| author | 2018-11-09 20:12:12 -0500 | |
|---|---|---|
| committer | 2018-11-18 10:53:47 -0500 | |
| commit | de16c1e45326a5bb587a2c270b9b39042b245f7c (patch) | |
| tree | a40fe3605cab81dd5265687dc341446ee94ea2e9 /src | |
| parent | frontend/applets: Add frontend software keyboard provider and default (diff) | |
| download | yuzu-de16c1e45326a5bb587a2c270b9b39042b245f7c.tar.gz yuzu-de16c1e45326a5bb587a2c270b9b39042b245f7c.tar.xz yuzu-de16c1e45326a5bb587a2c270b9b39042b245f7c.zip | |
am/applets: Add connector between frontend and AM applet classes
Provides a middleman between the Frontend provider class and the expected AM::Applets::Applet class needed by ILibraryAppletAccessor
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.cpp | 71 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/software_keyboard.h | 57 |
3 files changed, 130 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 03ecb2c8c..a355eaca6 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -154,6 +154,8 @@ add_library(core STATIC | |||
| 154 | hle/service/am/applet_oe.h | 154 | hle/service/am/applet_oe.h |
| 155 | hle/service/am/applets/applets.cpp | 155 | hle/service/am/applets/applets.cpp |
| 156 | hle/service/am/applets/applets.h | 156 | hle/service/am/applets/applets.h |
| 157 | hle/service/am/applets/software_keyboard.cpp | ||
| 158 | hle/service/am/applets/software_keyboard.h | ||
| 157 | hle/service/am/idle.cpp | 159 | hle/service/am/idle.cpp |
| 158 | hle/service/am/idle.h | 160 | hle/service/am/idle.h |
| 159 | hle/service/am/omm.cpp | 161 | hle/service/am/omm.cpp |
diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp new file mode 100644 index 000000000..ad1797ef1 --- /dev/null +++ b/src/core/hle/service/am/applets/software_keyboard.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | #include "common/string_util.h" | ||
| 7 | #include "core/frontend/applets/software_keyboard.h" | ||
| 8 | #include "core/hle/service/am/am.h" | ||
| 9 | #include "core/hle/service/am/applets/software_keyboard.h" | ||
| 10 | |||
| 11 | namespace Service::AM::Applets { | ||
| 12 | |||
| 13 | constexpr std::size_t SWKBD_OUTPUT_BUFFER_SIZE = 0x7D8; | ||
| 14 | constexpr std::size_t DEFAULT_MAX_LENGTH = 500; | ||
| 15 | |||
| 16 | static Frontend::SoftwareKeyboardApplet::Parameters ConvertToFrontendParameters( | ||
| 17 | KeyboardConfig config, std::u16string initial_text) { | ||
| 18 | Frontend::SoftwareKeyboardApplet::Parameters params{}; | ||
| 19 | |||
| 20 | params.submit_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( | ||
| 21 | config.submit_text.data(), config.submit_text.size()); | ||
| 22 | params.header_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( | ||
| 23 | config.header_text.data(), config.header_text.size()); | ||
| 24 | params.sub_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.sub_text.data(), | ||
| 25 | config.sub_text.size()); | ||
| 26 | params.guide_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.guide_text.data(), | ||
| 27 | config.guide_text.size()); | ||
| 28 | params.initial_text = initial_text; | ||
| 29 | params.max_length = config.length_limit == 0 ? DEFAULT_MAX_LENGTH : config.length_limit; | ||
| 30 | params.password = static_cast<bool>(config.is_password); | ||
| 31 | params.cursor_at_beginning = static_cast<bool>(config.initial_cursor_position); | ||
| 32 | params.value = static_cast<u8>(config.keyset_disable_bitmask); | ||
| 33 | |||
| 34 | return params; | ||
| 35 | } | ||
| 36 | |||
| 37 | void SoftwareKeyboard::Initialize(std::vector<std::shared_ptr<IStorage>> storage_) { | ||
| 38 | Applet::Initialize(std::move(storage_)); | ||
| 39 | |||
| 40 | ASSERT(storage_stack.size() >= 2); | ||
| 41 | const auto& keyboard_config = storage_stack[1]->GetData(); | ||
| 42 | ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); | ||
| 43 | std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); | ||
| 44 | |||
| 45 | ASSERT_MSG(config.text_check == 0, "Text check software keyboard mode is not implemented!"); | ||
| 46 | |||
| 47 | const auto& work_buffer = storage_stack[2]->GetData(); | ||
| 48 | std::memcpy(initial_text.data(), work_buffer.data() + config.initial_string_offset, | ||
| 49 | config.initial_string_size); | ||
| 50 | } | ||
| 51 | |||
| 52 | IStorage SoftwareKeyboard::Execute() { | ||
| 53 | const auto frontend{GetSoftwareKeyboard()}; | ||
| 54 | ASSERT(frontend != nullptr); | ||
| 55 | |||
| 56 | const auto parameters = ConvertToFrontendParameters(config, initial_text); | ||
| 57 | |||
| 58 | std::u16string text; | ||
| 59 | const auto success = frontend->GetText(parameters, text); | ||
| 60 | |||
| 61 | std::vector<u8> output(SWKBD_OUTPUT_BUFFER_SIZE); | ||
| 62 | |||
| 63 | if (success) { | ||
| 64 | output[0] = 1; | ||
| 65 | std::memcpy(output.data() + 4, text.data(), | ||
| 66 | std::min<std::size_t>(text.size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); | ||
| 67 | } | ||
| 68 | |||
| 69 | return IStorage{output}; | ||
| 70 | } | ||
| 71 | } // namespace Service::AM::Applets | ||
diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h new file mode 100644 index 000000000..9a37ba45f --- /dev/null +++ b/src/core/hle/service/am/applets/software_keyboard.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_funcs.h" | ||
| 8 | #include "core/hle/service/am/applets/applets.h" | ||
| 9 | |||
| 10 | namespace Service::AM::Applets { | ||
| 11 | |||
| 12 | enum class KeysetDisable : u32 { | ||
| 13 | Space = 0x02, | ||
| 14 | Address = 0x04, | ||
| 15 | Percent = 0x08, | ||
| 16 | Slashes = 0x10, | ||
| 17 | Numbers = 0x40, | ||
| 18 | DownloadCode = 0x80, | ||
| 19 | }; | ||
| 20 | |||
| 21 | struct KeyboardConfig { | ||
| 22 | INSERT_PADDING_BYTES(4); | ||
| 23 | std::array<char16_t, 9> submit_text; | ||
| 24 | u16_le left_symbol_key; | ||
| 25 | u16_le right_symbol_key; | ||
| 26 | INSERT_PADDING_BYTES(1); | ||
| 27 | KeysetDisable keyset_disable_bitmask; | ||
| 28 | u32_le initial_cursor_position; | ||
| 29 | std::array<char16_t, 65> header_text; | ||
| 30 | std::array<char16_t, 129> sub_text; | ||
| 31 | std::array<char16_t, 257> guide_text; | ||
| 32 | u32_le length_limit; | ||
| 33 | INSERT_PADDING_BYTES(4); | ||
| 34 | u32_le is_password; | ||
| 35 | INSERT_PADDING_BYTES(6); | ||
| 36 | bool draw_background; | ||
| 37 | u32_le initial_string_offset; | ||
| 38 | u32_le initial_string_size; | ||
| 39 | u32_le user_dictionary_offset; | ||
| 40 | u32_le user_dictionary_size; | ||
| 41 | bool text_check; | ||
| 42 | u64_le text_check_callback; | ||
| 43 | }; | ||
| 44 | static_assert(sizeof(KeyboardConfig) == 0x3E0, "KeyboardConfig has incorrect size."); | ||
| 45 | |||
| 46 | class SoftwareKeyboard final : public Applet { | ||
| 47 | public: | ||
| 48 | void Initialize(std::vector<std::shared_ptr<IStorage>> storage) override; | ||
| 49 | |||
| 50 | IStorage Execute() override; | ||
| 51 | |||
| 52 | private: | ||
| 53 | KeyboardConfig config; | ||
| 54 | std::u16string initial_text; | ||
| 55 | }; | ||
| 56 | |||
| 57 | } // namespace Service::AM::Applets | ||