From 5b95de0c9cbe5185283e36426035798e05555c21 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 9 Nov 2018 20:09:37 -0500 Subject: am/applets: Add Applet superclass to describe a generic applet Adds an Initialize and Execute methods which are used by the ILibraryAppletAccessor to start and control the applet. --- src/core/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/CMakeLists.txt') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 64fdf38cd..698f21a39 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -150,6 +150,8 @@ add_library(core STATIC hle/service/am/applet_ae.h hle/service/am/applet_oe.cpp hle/service/am/applet_oe.h + hle/service/am/applets/applets.cpp + hle/service/am/applets/applets.h hle/service/am/idle.cpp hle/service/am/idle.h hle/service/am/omm.cpp -- cgit v1.2.3 From ae53b84efd5523e2aba3255f9f713d4a1df563b3 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 9 Nov 2018 20:10:58 -0500 Subject: frontend/applets: Add frontend software keyboard provider and default Default implementation will return "yuzu" for any string. GUI clients (or CLI) can implement the Frontend::SoftwareKeyboardApplet class and register an instance to provide functionality. --- src/core/CMakeLists.txt | 2 ++ src/core/frontend/applets/software_keyboard.cpp | 17 ++++++++++ src/core/frontend/applets/software_keyboard.h | 44 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/core/frontend/applets/software_keyboard.cpp create mode 100644 src/core/frontend/applets/software_keyboard.h (limited to 'src/core/CMakeLists.txt') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 698f21a39..03ecb2c8c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -77,6 +77,8 @@ add_library(core STATIC file_sys/vfs_vector.h file_sys/xts_archive.cpp file_sys/xts_archive.h + frontend/applets/software_keyboard.cpp + frontend/applets/software_keyboard.h frontend/emu_window.cpp frontend/emu_window.h frontend/framebuffer_layout.cpp diff --git a/src/core/frontend/applets/software_keyboard.cpp b/src/core/frontend/applets/software_keyboard.cpp new file mode 100644 index 000000000..8cb888a62 --- /dev/null +++ b/src/core/frontend/applets/software_keyboard.cpp @@ -0,0 +1,17 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/logging/backend.h" +#include "core/frontend/applets/software_keyboard.h" + +namespace Frontend { +bool DefaultSoftwareKeyboardApplet::GetText(Parameters parameters, std::u16string& text) { + if (parameters.initial_text.empty()) + text = Common::UTF8ToUTF16("yuzu"); + else + text = parameters.initial_text; + + return true; +} +} // namespace Frontend diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h new file mode 100644 index 000000000..d368385d2 --- /dev/null +++ b/src/core/frontend/applets/software_keyboard.h @@ -0,0 +1,44 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include "common/bit_field.h" +#include "common/common_types.h" + +namespace Frontend { +class SoftwareKeyboardApplet { +public: + struct Parameters { + std::u16string submit_text; + std::u16string header_text; + std::u16string sub_text; + std::u16string guide_text; + std::u16string initial_text; + std::size_t max_length; + bool password; + bool cursor_at_beginning; + + union { + u8 value; + + BitField<1, 1, u8> disable_space; + BitField<2, 1, u8> disable_address; + BitField<3, 1, u8> disable_percent; + BitField<4, 1, u8> disable_slash; + BitField<6, 1, u8> disable_number; + BitField<7, 1, u8> disable_download_code; + }; + }; + + virtual bool GetText(Parameters parameters, std::u16string& text) = 0; + virtual ~SoftwareKeyboardApplet() = default; +}; + +class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet { + bool GetText(Parameters parameters, std::u16string& text) override; +}; + +} // namespace Frontend -- cgit v1.2.3 From de16c1e45326a5bb587a2c270b9b39042b245f7c Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 9 Nov 2018 20:12:12 -0500 Subject: 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 --- src/core/CMakeLists.txt | 2 + .../hle/service/am/applets/software_keyboard.cpp | 71 ++++++++++++++++++++++ .../hle/service/am/applets/software_keyboard.h | 57 +++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 src/core/hle/service/am/applets/software_keyboard.cpp create mode 100644 src/core/hle/service/am/applets/software_keyboard.h (limited to 'src/core/CMakeLists.txt') 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 hle/service/am/applet_oe.h hle/service/am/applets/applets.cpp hle/service/am/applets/applets.h + hle/service/am/applets/software_keyboard.cpp + hle/service/am/applets/software_keyboard.h hle/service/am/idle.cpp hle/service/am/idle.h 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 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "common/string_util.h" +#include "core/frontend/applets/software_keyboard.h" +#include "core/hle/service/am/am.h" +#include "core/hle/service/am/applets/software_keyboard.h" + +namespace Service::AM::Applets { + +constexpr std::size_t SWKBD_OUTPUT_BUFFER_SIZE = 0x7D8; +constexpr std::size_t DEFAULT_MAX_LENGTH = 500; + +static Frontend::SoftwareKeyboardApplet::Parameters ConvertToFrontendParameters( + KeyboardConfig config, std::u16string initial_text) { + Frontend::SoftwareKeyboardApplet::Parameters params{}; + + params.submit_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( + config.submit_text.data(), config.submit_text.size()); + params.header_text = Common::UTF16StringFromFixedZeroTerminatedBuffer( + config.header_text.data(), config.header_text.size()); + params.sub_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.sub_text.data(), + config.sub_text.size()); + params.guide_text = Common::UTF16StringFromFixedZeroTerminatedBuffer(config.guide_text.data(), + config.guide_text.size()); + params.initial_text = initial_text; + params.max_length = config.length_limit == 0 ? DEFAULT_MAX_LENGTH : config.length_limit; + params.password = static_cast(config.is_password); + params.cursor_at_beginning = static_cast(config.initial_cursor_position); + params.value = static_cast(config.keyset_disable_bitmask); + + return params; +} + +void SoftwareKeyboard::Initialize(std::vector> storage_) { + Applet::Initialize(std::move(storage_)); + + ASSERT(storage_stack.size() >= 2); + const auto& keyboard_config = storage_stack[1]->GetData(); + ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); + std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); + + ASSERT_MSG(config.text_check == 0, "Text check software keyboard mode is not implemented!"); + + const auto& work_buffer = storage_stack[2]->GetData(); + std::memcpy(initial_text.data(), work_buffer.data() + config.initial_string_offset, + config.initial_string_size); +} + +IStorage SoftwareKeyboard::Execute() { + const auto frontend{GetSoftwareKeyboard()}; + ASSERT(frontend != nullptr); + + const auto parameters = ConvertToFrontendParameters(config, initial_text); + + std::u16string text; + const auto success = frontend->GetText(parameters, text); + + std::vector output(SWKBD_OUTPUT_BUFFER_SIZE); + + if (success) { + output[0] = 1; + std::memcpy(output.data() + 4, text.data(), + std::min(text.size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); + } + + return IStorage{output}; +} +} // 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 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_funcs.h" +#include "core/hle/service/am/applets/applets.h" + +namespace Service::AM::Applets { + +enum class KeysetDisable : u32 { + Space = 0x02, + Address = 0x04, + Percent = 0x08, + Slashes = 0x10, + Numbers = 0x40, + DownloadCode = 0x80, +}; + +struct KeyboardConfig { + INSERT_PADDING_BYTES(4); + std::array submit_text; + u16_le left_symbol_key; + u16_le right_symbol_key; + INSERT_PADDING_BYTES(1); + KeysetDisable keyset_disable_bitmask; + u32_le initial_cursor_position; + std::array header_text; + std::array sub_text; + std::array guide_text; + u32_le length_limit; + INSERT_PADDING_BYTES(4); + u32_le is_password; + INSERT_PADDING_BYTES(6); + bool draw_background; + u32_le initial_string_offset; + u32_le initial_string_size; + u32_le user_dictionary_offset; + u32_le user_dictionary_size; + bool text_check; + u64_le text_check_callback; +}; +static_assert(sizeof(KeyboardConfig) == 0x3E0, "KeyboardConfig has incorrect size."); + +class SoftwareKeyboard final : public Applet { +public: + void Initialize(std::vector> storage) override; + + IStorage Execute() override; + +private: + KeyboardConfig config; + std::u16string initial_text; +}; + +} // namespace Service::AM::Applets -- cgit v1.2.3