From 2a6ebadf66051362cdcf07d722f7e2d3cee14c82 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 25 May 2015 23:30:20 -0500 Subject: HLE/APT: Initial HLE support for applets. Currently only the SWKBD is emulated, and there's currently no way to ask the user for input, so it always returns "Subv" as the text. --- src/core/hle/applets/applet.cpp | 40 ++++++++++++++++++++++ src/core/hle/applets/applet.h | 53 ++++++++++++++++++++++++++++++ src/core/hle/applets/swkbd.cpp | 73 +++++++++++++++++++++++++++++++++++++++++ src/core/hle/applets/swkbd.h | 67 +++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 src/core/hle/applets/applet.cpp create mode 100644 src/core/hle/applets/applet.h create mode 100644 src/core/hle/applets/swkbd.cpp create mode 100644 src/core/hle/applets/swkbd.h (limited to 'src/core/hle/applets') diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp new file mode 100644 index 000000000..1f447e5fc --- /dev/null +++ b/src/core/hle/applets/applet.cpp @@ -0,0 +1,40 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "common/logging/log.h" + +#include "core/hle/applets/applet.h" +#include "core/hle/applets/swkbd.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace HLE { +namespace Applets { + +static std::unordered_map> applets; + +ResultCode Applet::Create(Service::APT::AppletId id) { + switch (id) { + case Service::APT::AppletId::SoftwareKeyboard1: + case Service::APT::AppletId::SoftwareKeyboard2: + applets[id] = std::make_shared(id); + break; + default: + // TODO(Subv): Find the right error code + return ResultCode(ErrorDescription::NotFound, ErrorModule::Applet, ErrorSummary::NotSupported, ErrorLevel::Permanent); + } + + return RESULT_SUCCESS; +} + +std::shared_ptr Applet::Get(Service::APT::AppletId id) { + auto itr = applets.find(id); + if (itr != applets.end()) + return itr->second; + return nullptr; +} + +} +} // namespace diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h new file mode 100644 index 000000000..221348d9c --- /dev/null +++ b/src/core/hle/applets/applet.h @@ -0,0 +1,53 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/shared_memory.h" +#include "core/hle/service/apt/apt.h" + +namespace HLE { +namespace Applets { + +class Applet { +public: + virtual ~Applet() {}; + Applet(Service::APT::AppletId id) : id(id) {}; + + /** + * Creates an instance of the Applet subclass identified by the parameter + * and stores it in a global map. + * @param id Id of the applet to create + * @returns ResultCode Whether the operation was successful or not + */ + static ResultCode Create(Service::APT::AppletId id); + + /** + * Retrieves the Applet instance identified by the specified id + * @param id Id of the Applet to retrieve + * @returns Requested Applet or nullptr if not found + */ + static std::shared_ptr Get(Service::APT::AppletId id); + + /** + * Handles a parameter from the application + * @param parameter Parameter data to handle + * @returns ResultCode Whether the operation was successful or not + */ + virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; + + /** + * Handles the Applet start event, triggered from the application + * @param parameter Parameter data to handle + * @returns ResultCode Whether the operation was successful or not + */ + virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; + + Service::APT::AppletId id; ///< Id of this Applet +}; + +} +} // namespace diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp new file mode 100644 index 000000000..224aeb096 --- /dev/null +++ b/src/core/hle/applets/swkbd.cpp @@ -0,0 +1,73 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "common/logging/log.h" + +#include "core/hle/applets/swkbd.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace HLE { +namespace Applets { + +SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) { + // Create the SharedMemory that will hold the framebuffer data + // TODO(Subv): What size should we use here? + using Kernel::MemoryPermission; + framebuffer_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, "SoftwareKeyboard Memory"); +} + +ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) { + if (parameter.signal != static_cast(Service::APT::SignalType::LibAppJustStarted)) { + LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); + UNIMPLEMENTED(); + // TODO(Subv): Find the right error code + return ResultCode(-1); + } + + Service::APT::MessageParameter result; + // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo + result.signal = static_cast(Service::APT::SignalType::LibAppFinished); + result.data = nullptr; + result.buffer_size = 0; + result.destination_id = static_cast(Service::APT::AppletId::Application); + result.sender_id = static_cast(id); + result.object = framebuffer_memory; + + Service::APT::SendParameter(result); + return RESULT_SUCCESS; +} + +ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& parameter) { + memcpy(&config, parameter.data, parameter.buffer_size); + text_memory = boost::static_pointer_cast(parameter.object); + + // TODO(Subv): Verify if this is the correct behavior + memset(text_memory->GetPointer(), 0, text_memory->size); + + // TODO(Subv): Remove this hardcoded text + const wchar_t str[] = L"Subv"; + memcpy(text_memory->GetPointer(), str, 4 * sizeof(wchar_t)); + + // TODO(Subv): Ask for input and write it to the shared memory + // TODO(Subv): Find out what are the possible values for the return code, + // some games seem to check for a hardcoded 2 + config.return_code = 2; + config.text_length = 5; + config.text_offset = 0; + + Service::APT::MessageParameter message; + message.buffer_size = sizeof(SoftwareKeyboardConfig); + message.data = reinterpret_cast(&config); + message.signal = static_cast(Service::APT::SignalType::LibAppClosed); + message.destination_id = static_cast(Service::APT::AppletId::Application); + message.sender_id = static_cast(id); + Service::APT::SendParameter(message); + + return RESULT_SUCCESS; +} + +} +} // namespace diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h new file mode 100644 index 000000000..d7199690c --- /dev/null +++ b/src/core/hle/applets/swkbd.h @@ -0,0 +1,67 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" +#include "core/hle/applets/applet.h" +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/shared_memory.h" +#include "core/hle/service/apt/apt.h" + +namespace HLE { +namespace Applets { + +struct SoftwareKeyboardConfig { + INSERT_PADDING_WORDS(0x8); + + u16 max_text_length; ///< Maximum length of the input text + + INSERT_PADDING_BYTES(0x6E); + + char16_t display_text[65]; ///< Text to display when asking the user for input + + INSERT_PADDING_BYTES(0xE); + + u32 default_text_offset; ///< Offset of the default text in the output SharedMemory + + INSERT_PADDING_WORDS(0x3); + + u32 shared_memory_size; ///< Size of the SharedMemory + + INSERT_PADDING_WORDS(0x1); + + u32 return_code; ///< Return code of the SoftwareKeyboard, usually 2, other values are unknown + + INSERT_PADDING_WORDS(0x2); + + u32 text_offset; ///< Offset in the SharedMemory where the output text starts + u16 text_length; ///< Length in characters of the output text + + INSERT_PADDING_BYTES(0x2B6); +}; + +static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong"); + +class SoftwareKeyboard : public Applet { +public: + SoftwareKeyboard(Service::APT::AppletId id); + ~SoftwareKeyboard() {} + + ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; + ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; + + /// TODO(Subv): Find out what this is actually used for. + // It is believed that the application stores the current screen image here. + Kernel::SharedPtr framebuffer_memory; + + /// SharedMemory where the output text will be stored + Kernel::SharedPtr text_memory; + + /// Configuration of this instance of the SoftwareKeyboard, as received from the application + SoftwareKeyboardConfig config; +}; + +} +} // namespace -- cgit v1.2.3 From 621ee10eae0546d4ec3f9e911e113aa9ee609c22 Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 26 May 2015 11:00:26 -0500 Subject: Applets: Add infrastructure to allow custom drawing and input handling in Applets. --- src/core/hle/applets/applet.cpp | 38 ++++++++++++++++++++++++++++++++++ src/core/hle/applets/applet.h | 43 +++++++++++++++++++++++++++------------ src/core/hle/applets/swkbd.cpp | 45 +++++++++++++++++++++++++++++++++++------ src/core/hle/applets/swkbd.h | 16 +++++++++++++++ 4 files changed, 123 insertions(+), 19 deletions(-) (limited to 'src/core/hle/applets') diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp index 1f447e5fc..689f5adc8 100644 --- a/src/core/hle/applets/applet.cpp +++ b/src/core/hle/applets/applet.cpp @@ -5,15 +5,35 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "core/core_timing.h" #include "core/hle/applets/applet.h" #include "core/hle/applets/swkbd.h" //////////////////////////////////////////////////////////////////////////////////////////////////// +// Specializes std::hash for AppletId, so that we can use it in std::unordered_map. +// Workaround for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970 +namespace std { + template <> + struct hash { + typedef Service::APT::AppletId argument_type; + typedef std::size_t result_type; + + result_type operator()(const argument_type& id_code) const { + typedef std::underlying_type::type Type; + return std::hash()(static_cast(id_code)); + } + }; +} + namespace HLE { namespace Applets { static std::unordered_map> applets; +static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback. +/// The interval at which the Applet update callback will be called. +static const u64 applet_update_interval_microseconds = 16666; +std::shared_ptr g_current_applet = nullptr; ///< The applet that is currently executing ResultCode Applet::Create(Service::APT::AppletId id) { switch (id) { @@ -36,5 +56,23 @@ std::shared_ptr Applet::Get(Service::APT::AppletId id) { return nullptr; } +/// Handles updating the current Applet every time it's called. +static void AppletUpdateEvent(u64, int cycles_late) { + if (g_current_applet && g_current_applet->IsRunning()) + g_current_applet->Update(); + + CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late, + applet_update_event); +} + +void Init() { + applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent); + CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event); +} + +void Shutdown() { + CoreTiming::UnscheduleEvent(applet_update_event, 0); +} + } } // namespace diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h index 221348d9c..f50f7d604 100644 --- a/src/core/hle/applets/applet.h +++ b/src/core/hle/applets/applet.h @@ -12,42 +12,59 @@ namespace HLE { namespace Applets { -class Applet { +class Applet : public std::enable_shared_from_this { public: virtual ~Applet() {}; Applet(Service::APT::AppletId id) : id(id) {}; /** - * Creates an instance of the Applet subclass identified by the parameter + * Creates an instance of the Applet subclass identified by the parameter. * and stores it in a global map. - * @param id Id of the applet to create - * @returns ResultCode Whether the operation was successful or not + * @param id Id of the applet to create. + * @returns ResultCode Whether the operation was successful or not. */ static ResultCode Create(Service::APT::AppletId id); /** - * Retrieves the Applet instance identified by the specified id - * @param id Id of the Applet to retrieve - * @returns Requested Applet or nullptr if not found + * Retrieves the Applet instance identified by the specified id. + * @param id Id of the Applet to retrieve. + * @returns Requested Applet or nullptr if not found. */ static std::shared_ptr Get(Service::APT::AppletId id); /** - * Handles a parameter from the application - * @param parameter Parameter data to handle - * @returns ResultCode Whether the operation was successful or not + * Handles a parameter from the application. + * @param parameter Parameter data to handle. + * @returns ResultCode Whether the operation was successful or not. */ virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; /** - * Handles the Applet start event, triggered from the application - * @param parameter Parameter data to handle - * @returns ResultCode Whether the operation was successful or not + * Handles the Applet start event, triggered from the application. + * @param parameter Parameter data to handle. + * @returns ResultCode Whether the operation was successful or not. */ virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; + /** + * Whether the applet is currently executing instead of the host application or not. + */ + virtual bool IsRunning() = 0; + + /** + * Handles an update tick for the Applet, lets it update the screen, send commands, etc. + */ + virtual void Update() = 0; + Service::APT::AppletId id; ///< Id of this Applet }; +/// Initializes the HLE applets +void Init(); + +/// Shuts down the HLE applets +void Shutdown(); + +extern std::shared_ptr g_current_applet; ///< Applet that is currently executing } } // namespace diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index 224aeb096..b800e0eb4 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -6,13 +6,16 @@ #include "common/logging/log.h" #include "core/hle/applets/swkbd.h" +#include "core/hle/service/hid/hid.h" +#include "core/hle/service/gsp_gpu.h" +#include "video_core/video_core.h" //////////////////////////////////////////////////////////////////////////////////////////////////// namespace HLE { namespace Applets { -SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) { +SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) { // Create the SharedMemory that will hold the framebuffer data // TODO(Subv): What size should we use here? using Kernel::MemoryPermission; @@ -47,17 +50,45 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p // TODO(Subv): Verify if this is the correct behavior memset(text_memory->GetPointer(), 0, text_memory->size); + DrawScreenKeyboard(); + + // Update the current applet so we can get update events + started = true; + g_current_applet = shared_from_this(); + return RESULT_SUCCESS; +} + +void SoftwareKeyboard::Update() { + // TODO(Subv): Handle input using the touch events from the HID module + // TODO(Subv): Remove this hardcoded text - const wchar_t str[] = L"Subv"; - memcpy(text_memory->GetPointer(), str, 4 * sizeof(wchar_t)); - + std::u16string text = Common::UTF8ToUTF16("Citra"); + memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t)); + // TODO(Subv): Ask for input and write it to the shared memory // TODO(Subv): Find out what are the possible values for the return code, // some games seem to check for a hardcoded 2 config.return_code = 2; - config.text_length = 5; + config.text_length = 6; config.text_offset = 0; + // TODO(Subv): We're finalizing the applet immediately after it's started, + // but we should defer this call until after all the input has been collected. + Finalize(); +} + +void SoftwareKeyboard::DrawScreenKeyboard() { + auto bottom_screen = GSP_GPU::GetFrameBufferInfo(0, 1); + auto info = bottom_screen->framebuffer_info[bottom_screen->index]; + + // TODO(Subv): Draw the HLE keyboard, for now just zero-fill the framebuffer + memset(Memory::GetPointer(info.address_left), 0, info.stride * 320); + + GSP_GPU::SetBufferSwap(1, info); +} + +void SoftwareKeyboard::Finalize() { + // Let the application know that we're closing Service::APT::MessageParameter message; message.buffer_size = sizeof(SoftwareKeyboardConfig); message.data = reinterpret_cast(&config); @@ -66,7 +97,9 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p message.sender_id = static_cast(id); Service::APT::SendParameter(message); - return RESULT_SUCCESS; + started = false; + // Unset the current applet, we are not running anymore + g_current_applet = nullptr; } } diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h index d7199690c..5970390c6 100644 --- a/src/core/hle/applets/swkbd.h +++ b/src/core/hle/applets/swkbd.h @@ -51,6 +51,19 @@ public: ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; + void Update() override; + bool IsRunning() override { return started; } + + /** + * Draws a keyboard to the current bottom screen framebuffer. + */ + void DrawScreenKeyboard(); + + /** + * Sends the LibAppletClosing signal to the application, + * along with the relevant data buffers. + */ + void Finalize(); /// TODO(Subv): Find out what this is actually used for. // It is believed that the application stores the current screen image here. @@ -61,6 +74,9 @@ public: /// Configuration of this instance of the SoftwareKeyboard, as received from the application SoftwareKeyboardConfig config; + + /// Whether this applet is currently running instead of the host application or not. + bool started; }; } -- cgit v1.2.3 From 725d5eea7879fa152c51f15fd76003d3c6bc44ed Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 27 May 2015 15:21:06 -0500 Subject: Applets: Reworked how the Applet update event is handled. Applets are now cleaned up in AppletUpdateEvent after calling their respective Update method. --- src/core/hle/applets/applet.cpp | 36 ++++++++++++++++++++++++++---------- src/core/hle/applets/applet.h | 21 ++++++++++++++------- src/core/hle/applets/swkbd.cpp | 13 ++++++------- src/core/hle/applets/swkbd.h | 18 +++++++++++------- 4 files changed, 57 insertions(+), 31 deletions(-) (limited to 'src/core/hle/applets') diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp index 689f5adc8..4dcce729a 100644 --- a/src/core/hle/applets/applet.cpp +++ b/src/core/hle/applets/applet.cpp @@ -31,9 +31,8 @@ namespace Applets { static std::unordered_map> applets; static u32 applet_update_event = -1; ///< The CoreTiming event identifier for the Applet update callback. -/// The interval at which the Applet update callback will be called. -static const u64 applet_update_interval_microseconds = 16666; -std::shared_ptr g_current_applet = nullptr; ///< The applet that is currently executing +/// The interval at which the Applet update callback will be called, 16.6ms +static const u64 applet_update_interval_us = 16666; ResultCode Applet::Create(Service::APT::AppletId id) { switch (id) { @@ -57,21 +56,38 @@ std::shared_ptr Applet::Get(Service::APT::AppletId id) { } /// Handles updating the current Applet every time it's called. -static void AppletUpdateEvent(u64, int cycles_late) { - if (g_current_applet && g_current_applet->IsRunning()) - g_current_applet->Update(); +static void AppletUpdateEvent(u64 applet_id, int cycles_late) { + Service::APT::AppletId id = static_cast(applet_id); + std::shared_ptr applet = Applet::Get(id); + ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id=%08X", id); - CoreTiming::ScheduleEvent(usToCycles(applet_update_interval) - cycles_late, - applet_update_event); + applet->Update(); + + // If the applet is still running after the last update, reschedule the event + if (applet->IsRunning()) { + CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us) - cycles_late, + applet_update_event, applet_id); + } else { + // Otherwise the applet has terminated, in which case we should clean it up + applets[id] = nullptr; + } +} + +ResultCode Applet::Start(const Service::APT::AppletStartupParameter& parameter) { + ResultCode result = StartImpl(parameter); + if (result.IsError()) + return result; + // Schedule the update event + CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us), applet_update_event, static_cast(id)); + return result; } void Init() { + // Register the applet update callback applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent); - CoreTiming::ScheduleEvent(usToCycles(applet_update_interval), applet_update_event); } void Shutdown() { - CoreTiming::UnscheduleEvent(applet_update_event, 0); } } diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h index f50f7d604..fe537e70d 100644 --- a/src/core/hle/applets/applet.h +++ b/src/core/hle/applets/applet.h @@ -12,10 +12,10 @@ namespace HLE { namespace Applets { -class Applet : public std::enable_shared_from_this { +class Applet { public: - virtual ~Applet() {}; - Applet(Service::APT::AppletId id) : id(id) {}; + virtual ~Applet() { } + Applet(Service::APT::AppletId id) : id(id) { } /** * Creates an instance of the Applet subclass identified by the parameter. @@ -37,25 +37,33 @@ public: * @param parameter Parameter data to handle. * @returns ResultCode Whether the operation was successful or not. */ - virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; + virtual ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) = 0; /** * Handles the Applet start event, triggered from the application. * @param parameter Parameter data to handle. * @returns ResultCode Whether the operation was successful or not. */ - virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; + ResultCode Start(const Service::APT::AppletStartupParameter& parameter); /** * Whether the applet is currently executing instead of the host application or not. */ - virtual bool IsRunning() = 0; + virtual bool IsRunning() const = 0; /** * Handles an update tick for the Applet, lets it update the screen, send commands, etc. */ virtual void Update() = 0; +protected: + /** + * Handles the Applet start event, triggered from the application. + * @param parameter Parameter data to handle. + * @returns ResultCode Whether the operation was successful or not. + */ + virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0; + Service::APT::AppletId id; ///< Id of this Applet }; @@ -65,6 +73,5 @@ void Init(); /// Shuts down the HLE applets void Shutdown(); -extern std::shared_ptr g_current_applet; ///< Applet that is currently executing } } // namespace diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index b800e0eb4..7431ebcf8 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -4,6 +4,7 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "common/string_util.h" #include "core/hle/applets/swkbd.h" #include "core/hle/service/hid/hid.h" @@ -33,7 +34,7 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con Service::APT::MessageParameter result; // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo result.signal = static_cast(Service::APT::SignalType::LibAppFinished); - result.data = nullptr; + result.data = nullptr; result.buffer_size = 0; result.destination_id = static_cast(Service::APT::AppletId::Application); result.sender_id = static_cast(id); @@ -43,7 +44,9 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con return RESULT_SUCCESS; } -ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& parameter) { +ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter const& parameter) { + ASSERT_MSG(parameter.buffer_size == sizeof(config), "The size of the parameter (SoftwareKeyboardConfig) is wrong"); + memcpy(&config, parameter.data, parameter.buffer_size); text_memory = boost::static_pointer_cast(parameter.object); @@ -52,9 +55,7 @@ ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& p DrawScreenKeyboard(); - // Update the current applet so we can get update events started = true; - g_current_applet = shared_from_this(); return RESULT_SUCCESS; } @@ -72,7 +73,7 @@ void SoftwareKeyboard::Update() { config.text_length = 6; config.text_offset = 0; - // TODO(Subv): We're finalizing the applet immediately after it's started, + // TODO(Subv): We're finalizing the applet immediately after it's started, // but we should defer this call until after all the input has been collected. Finalize(); } @@ -98,8 +99,6 @@ void SoftwareKeyboard::Finalize() { Service::APT::SendParameter(message); started = false; - // Unset the current applet, we are not running anymore - g_current_applet = nullptr; } } diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h index 5970390c6..98e81c48a 100644 --- a/src/core/hle/applets/swkbd.h +++ b/src/core/hle/applets/swkbd.h @@ -42,17 +42,21 @@ struct SoftwareKeyboardConfig { INSERT_PADDING_BYTES(0x2B6); }; +/** + * The size of this structure (0x400) has been verified via reverse engineering of multiple games + * that use the software keyboard. + */ static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong"); -class SoftwareKeyboard : public Applet { +class SoftwareKeyboard final : public Applet { public: SoftwareKeyboard(Service::APT::AppletId id); ~SoftwareKeyboard() {} - ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; - ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; + ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; + ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; void Update() override; - bool IsRunning() override { return started; } + bool IsRunning() const override { return started; } /** * Draws a keyboard to the current bottom screen framebuffer. @@ -65,13 +69,13 @@ public: */ void Finalize(); - /// TODO(Subv): Find out what this is actually used for. - // It is believed that the application stores the current screen image here. + /// TODO(Subv): Find out what this is actually used for. + /// It is believed that the application stores the current screen image here. Kernel::SharedPtr framebuffer_memory; /// SharedMemory where the output text will be stored Kernel::SharedPtr text_memory; - + /// Configuration of this instance of the SoftwareKeyboard, as received from the application SoftwareKeyboardConfig config; -- cgit v1.2.3