diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/applets/applet.cpp | 130 | ||||
-rw-r--r-- | src/core/hle/applets/applet.h | 83 | ||||
-rw-r--r-- | src/core/hle/applets/erreula.cpp | 72 | ||||
-rw-r--r-- | src/core/hle/applets/erreula.h | 29 | ||||
-rw-r--r-- | src/core/hle/applets/mii_selector.cpp | 86 | ||||
-rw-r--r-- | src/core/hle/applets/mii_selector.h | 78 | ||||
-rw-r--r-- | src/core/hle/applets/mint.cpp | 72 | ||||
-rw-r--r-- | src/core/hle/applets/mint.h | 29 | ||||
-rw-r--r-- | src/core/hle/applets/swkbd.cpp | 118 | ||||
-rw-r--r-- | src/core/hle/applets/swkbd.h | 85 |
10 files changed, 0 insertions, 782 deletions
diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp deleted file mode 100644 index 9c43ed2fd..000000000 --- a/src/core/hle/applets/applet.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include <cstddef> -#include <memory> -#include <type_traits> -#include <unordered_map> -#include "common/assert.h" -#include "common/common_types.h" -#include "core/core_timing.h" -#include "core/hle/applets/applet.h" -#include "core/hle/applets/erreula.h" -#include "core/hle/applets/mii_selector.h" -#include "core/hle/applets/mint.h" -#include "core/hle/applets/swkbd.h" -#include "core/hle/result.h" -#include "core/hle/service/apt/apt.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<Service::APT::AppletId> { - 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<argument_type>::type Type; - return std::hash<Type>()(static_cast<Type>(id_code)); - } -}; -} - -namespace HLE { -namespace Applets { - -static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> 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, 16.6ms -static const u64 applet_update_interval_us = 16666; - -ResultCode Applet::Create(Service::APT::AppletId id) { - switch (id) { - case Service::APT::AppletId::SoftwareKeyboard1: - case Service::APT::AppletId::SoftwareKeyboard2: - applets[id] = std::make_shared<SoftwareKeyboard>(id); - break; - case Service::APT::AppletId::Ed1: - case Service::APT::AppletId::Ed2: - applets[id] = std::make_shared<MiiSelector>(id); - break; - case Service::APT::AppletId::Error: - case Service::APT::AppletId::Error2: - applets[id] = std::make_shared<ErrEula>(id); - break; - case Service::APT::AppletId::Mint: - case Service::APT::AppletId::Mint2: - applets[id] = std::make_shared<Mint>(id); - break; - default: - LOG_ERROR(Service_APT, "Could not create applet %u", id); - // TODO(Subv): Find the right error code - return ResultCode(ErrorDescription::NotFound, ErrorModule::Applet, - ErrorSummary::NotSupported, ErrorLevel::Permanent); - } - - return RESULT_SUCCESS; -} - -std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) { - auto itr = applets.find(id); - if (itr != applets.end()) - return itr->second; - return nullptr; -} - -/// Handles updating the current Applet every time it's called. -static void AppletUpdateEvent(u64 applet_id, int cycles_late) { - Service::APT::AppletId id = static_cast<Service::APT::AppletId>(applet_id); - std::shared_ptr<Applet> applet = Applet::Get(id); - ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id=%08X", id); - - 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<u64>(id)); - return result; -} - -bool Applet::IsRunning() const { - return is_running; -} - -bool IsLibraryAppletRunning() { - // Check the applets map for instances of any applet - for (auto itr = applets.begin(); itr != applets.end(); ++itr) - if (itr->second != nullptr) - return true; - return false; -} - -void Init() { - // Register the applet update callback - applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent); -} - -void Shutdown() { - CoreTiming::RemoveEvent(applet_update_event); -} -} -} // namespace diff --git a/src/core/hle/applets/applet.h b/src/core/hle/applets/applet.h deleted file mode 100644 index ebeed9813..000000000 --- a/src/core/hle/applets/applet.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include <memory> -#include "core/hle/result.h" -#include "core/hle/service/apt/apt.h" - -namespace HLE { -namespace Applets { - -class Applet { -public: - virtual ~Applet() = default; - - /** - * 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<Applet> 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(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. - */ - ResultCode Start(const Service::APT::AppletStartupParameter& parameter); - - /** - * Whether the applet is currently executing instead of the host application or not. - */ - bool IsRunning() const; - - /** - * Handles an update tick for the Applet, lets it update the screen, send commands, etc. - */ - virtual void Update() = 0; - -protected: - explicit Applet(Service::APT::AppletId id) : id(id) {} - - /** - * 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 - std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet - - /// Whether this applet is currently running instead of the host application or not. - bool is_running = false; -}; - -/// Returns whether a library applet is currently running -bool IsLibraryAppletRunning(); - -/// Initializes the HLE applets -void Init(); - -/// Shuts down the HLE applets -void Shutdown(); -} -} // namespace diff --git a/src/core/hle/applets/erreula.cpp b/src/core/hle/applets/erreula.cpp deleted file mode 100644 index 518f371f5..000000000 --- a/src/core/hle/applets/erreula.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "common/string_util.h" -#include "core/hle/applets/erreula.h" -#include "core/hle/service/apt/apt.h" - -namespace HLE { -namespace Applets { - -ResultCode ErrEula::ReceiveParameter(const Service::APT::MessageParameter& parameter) { - if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) { - LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); - UNIMPLEMENTED(); - // TODO(Subv): Find the right error code - return ResultCode(-1); - } - - // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared - // memory. - // Create the SharedMemory that will hold the framebuffer data - Service::APT::CaptureBufferInfo capture_info; - ASSERT(sizeof(capture_info) == parameter.buffer.size()); - - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); - - // TODO: allocated memory never released - using Kernel::MemoryPermission; - // Allocate a heap block of the required size for this applet. - heap_memory = std::make_shared<std::vector<u8>>(capture_info.size); - // Create a SharedMemory that directly points to this heap block. - framebuffer_memory = Kernel::SharedMemory::CreateForApplet( - heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, - "ErrEula Memory"); - - // Send the response message with the newly created SharedMemory - Service::APT::MessageParameter result; - result.signal = static_cast<u32>(Service::APT::SignalType::Response); - result.buffer.clear(); - result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - result.sender_id = static_cast<u32>(id); - result.object = framebuffer_memory; - - Service::APT::SendParameter(result); - return RESULT_SUCCESS; -} - -ResultCode ErrEula::StartImpl(const Service::APT::AppletStartupParameter& parameter) { - is_running = true; - - // TODO(Subv): Set the expected fields in the response buffer before resending it to the - // application. - // TODO(Subv): Reverse the parameter format for the ErrEula applet - - // Let the application know that we're closing - Service::APT::MessageParameter message; - message.buffer.resize(parameter.buffer.size()); - std::fill(message.buffer.begin(), message.buffer.end(), 0); - message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit); - message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - message.sender_id = static_cast<u32>(id); - Service::APT::SendParameter(message); - - is_running = false; - return RESULT_SUCCESS; -} - -void ErrEula::Update() {} - -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/erreula.h b/src/core/hle/applets/erreula.h deleted file mode 100644 index 681bbea0c..000000000 --- a/src/core/hle/applets/erreula.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "core/hle/applets/applet.h" -#include "core/hle/kernel/shared_memory.h" - -namespace HLE { -namespace Applets { - -class ErrEula final : public Applet { -public: - explicit ErrEula(Service::APT::AppletId id) : Applet(id) {} - - ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; - ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; - void Update() override; - -private: - /// This SharedMemory will be created when we receive the LibAppJustStarted message. - /// It holds the framebuffer info retrieved by the application with - /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; -}; - -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/mii_selector.cpp b/src/core/hle/applets/mii_selector.cpp deleted file mode 100644 index f225c23a5..000000000 --- a/src/core/hle/applets/mii_selector.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include <cstring> -#include <string> -#include "common/assert.h" -#include "common/logging/log.h" -#include "common/string_util.h" -#include "core/hle/applets/mii_selector.h" -#include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/shared_memory.h" -#include "core/hle/result.h" - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace HLE { -namespace Applets { - -ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) { - if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) { - LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); - UNIMPLEMENTED(); - // TODO(Subv): Find the right error code - return ResultCode(-1); - } - - // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared - // memory. - // Create the SharedMemory that will hold the framebuffer data - Service::APT::CaptureBufferInfo capture_info; - ASSERT(sizeof(capture_info) == parameter.buffer.size()); - - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); - - using Kernel::MemoryPermission; - // Allocate a heap block of the required size for this applet. - heap_memory = std::make_shared<std::vector<u8>>(capture_info.size); - // Create a SharedMemory that directly points to this heap block. - framebuffer_memory = Kernel::SharedMemory::CreateForApplet( - heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, - "MiiSelector Memory"); - - // Send the response message with the newly created SharedMemory - Service::APT::MessageParameter result; - result.signal = static_cast<u32>(Service::APT::SignalType::Response); - result.buffer.clear(); - result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - result.sender_id = static_cast<u32>(id); - result.object = framebuffer_memory; - - Service::APT::SendParameter(result); - return RESULT_SUCCESS; -} - -ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& parameter) { - is_running = true; - - // TODO(Subv): Set the expected fields in the response buffer before resending it to the - // application. - // TODO(Subv): Reverse the parameter format for the Mii Selector - - memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); - - // TODO(Subv): Find more about this structure, result code 0 is enough to let most games - // continue. - MiiResult result; - memset(&result, 0, sizeof(result)); - result.return_code = 0; - - // Let the application know that we're closing - Service::APT::MessageParameter message; - message.buffer.resize(sizeof(MiiResult)); - std::memcpy(message.buffer.data(), &result, message.buffer.size()); - message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit); - message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - message.sender_id = static_cast<u32>(id); - Service::APT::SendParameter(message); - - is_running = false; - return RESULT_SUCCESS; -} - -void MiiSelector::Update() {} -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/mii_selector.h b/src/core/hle/applets/mii_selector.h deleted file mode 100644 index 136ce8948..000000000 --- a/src/core/hle/applets/mii_selector.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_funcs.h" -#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/result.h" -#include "core/hle/service/apt/apt.h" - -namespace HLE { -namespace Applets { - -struct MiiConfig { - u8 enable_cancel_button; - u8 enable_guest_mii; - u8 show_on_top_screen; - INSERT_PADDING_BYTES(5); - u16 title[0x40]; - INSERT_PADDING_BYTES(4); - u8 show_guest_miis; - INSERT_PADDING_BYTES(3); - u32 initially_selected_mii_index; - u8 guest_mii_whitelist[6]; - u8 user_mii_whitelist[0x64]; - INSERT_PADDING_BYTES(2); - u32 magic_value; -}; -static_assert(sizeof(MiiConfig) == 0x104, "MiiConfig structure has incorrect size"); -#define ASSERT_REG_POSITION(field_name, position) \ - static_assert(offsetof(MiiConfig, field_name) == position, \ - "Field " #field_name " has invalid position") -ASSERT_REG_POSITION(title, 0x08); -ASSERT_REG_POSITION(show_guest_miis, 0x8C); -ASSERT_REG_POSITION(initially_selected_mii_index, 0x90); -ASSERT_REG_POSITION(guest_mii_whitelist, 0x94); -#undef ASSERT_REG_POSITION - -struct MiiResult { - u32 return_code; - u32 is_guest_mii_selected; - u32 selected_guest_mii_index; - // TODO(mailwl): expand to Mii Format structure: https://www.3dbrew.org/wiki/Mii - u8 selected_mii_data[0x5C]; - INSERT_PADDING_BYTES(2); - u16 mii_data_checksum; - u16 guest_mii_name[0xC]; -}; -static_assert(sizeof(MiiResult) == 0x84, "MiiResult structure has incorrect size"); -#define ASSERT_REG_POSITION(field_name, position) \ - static_assert(offsetof(MiiResult, field_name) == position, \ - "Field " #field_name " has invalid position") -ASSERT_REG_POSITION(selected_mii_data, 0x0C); -ASSERT_REG_POSITION(guest_mii_name, 0x6C); -#undef ASSERT_REG_POSITION - -class MiiSelector final : public Applet { -public: - MiiSelector(Service::APT::AppletId id) : Applet(id) {} - - ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; - ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; - void Update() override; - -private: - /// This SharedMemory will be created when we receive the LibAppJustStarted message. - /// It holds the framebuffer info retrieved by the application with - /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; - - MiiConfig config; -}; -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/mint.cpp b/src/core/hle/applets/mint.cpp deleted file mode 100644 index 50d79190b..000000000 --- a/src/core/hle/applets/mint.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "common/string_util.h" -#include "core/hle/applets/mint.h" -#include "core/hle/service/apt/apt.h" - -namespace HLE { -namespace Applets { - -ResultCode Mint::ReceiveParameter(const Service::APT::MessageParameter& parameter) { - if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) { - LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); - UNIMPLEMENTED(); - // TODO(Subv): Find the right error code - return ResultCode(-1); - } - - // The Request message contains a buffer with the size of the framebuffer shared - // memory. - // Create the SharedMemory that will hold the framebuffer data - Service::APT::CaptureBufferInfo capture_info; - ASSERT(sizeof(capture_info) == parameter.buffer.size()); - - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); - - // TODO: allocated memory never released - using Kernel::MemoryPermission; - // Allocate a heap block of the required size for this applet. - heap_memory = std::make_shared<std::vector<u8>>(capture_info.size); - // Create a SharedMemory that directly points to this heap block. - framebuffer_memory = Kernel::SharedMemory::CreateForApplet( - heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, - "Mint Memory"); - - // Send the response message with the newly created SharedMemory - Service::APT::MessageParameter result; - result.signal = static_cast<u32>(Service::APT::SignalType::Response); - result.buffer.clear(); - result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - result.sender_id = static_cast<u32>(id); - result.object = framebuffer_memory; - - Service::APT::SendParameter(result); - return RESULT_SUCCESS; -} - -ResultCode Mint::StartImpl(const Service::APT::AppletStartupParameter& parameter) { - is_running = true; - - // TODO(Subv): Set the expected fields in the response buffer before resending it to the - // application. - // TODO(Subv): Reverse the parameter format for the Mint applet - - // Let the application know that we're closing - Service::APT::MessageParameter message; - message.buffer.resize(parameter.buffer.size()); - std::fill(message.buffer.begin(), message.buffer.end(), 0); - message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit); - message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - message.sender_id = static_cast<u32>(id); - Service::APT::SendParameter(message); - - is_running = false; - return RESULT_SUCCESS; -} - -void Mint::Update() {} - -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/mint.h b/src/core/hle/applets/mint.h deleted file mode 100644 index d23dc40f9..000000000 --- a/src/core/hle/applets/mint.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "core/hle/applets/applet.h" -#include "core/hle/kernel/shared_memory.h" - -namespace HLE { -namespace Applets { - -class Mint final : public Applet { -public: - explicit Mint(Service::APT::AppletId id) : Applet(id) {} - - ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; - ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; - void Update() override; - -private: - /// This SharedMemory will be created when we receive the Request message. - /// It holds the framebuffer info retrieved by the application with - /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; -}; - -} // namespace Applets -} // namespace HLE diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp deleted file mode 100644 index 0bc471a3a..000000000 --- a/src/core/hle/applets/swkbd.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include <cstring> -#include <string> -#include "common/assert.h" -#include "common/logging/log.h" -#include "common/string_util.h" -#include "core/hle/applets/swkbd.h" -#include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/shared_memory.h" -#include "core/hle/result.h" -#include "core/hle/service/gsp_gpu.h" -#include "core/hle/service/hid/hid.h" -#include "core/memory.h" - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace HLE { -namespace Applets { - -ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) { - if (parameter.signal != static_cast<u32>(Service::APT::SignalType::Request)) { - LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); - UNIMPLEMENTED(); - // TODO(Subv): Find the right error code - return ResultCode(-1); - } - - // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared - // memory. - // Create the SharedMemory that will hold the framebuffer data - Service::APT::CaptureBufferInfo capture_info; - ASSERT(sizeof(capture_info) == parameter.buffer.size()); - - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); - - using Kernel::MemoryPermission; - // Allocate a heap block of the required size for this applet. - heap_memory = std::make_shared<std::vector<u8>>(capture_info.size); - // Create a SharedMemory that directly points to this heap block. - framebuffer_memory = Kernel::SharedMemory::CreateForApplet( - heap_memory, 0, capture_info.size, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, - "SoftwareKeyboard Memory"); - - // Send the response message with the newly created SharedMemory - Service::APT::MessageParameter result; - result.signal = static_cast<u32>(Service::APT::SignalType::Response); - result.buffer.clear(); - result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - result.sender_id = static_cast<u32>(id); - result.object = framebuffer_memory; - - Service::APT::SendParameter(result); - return RESULT_SUCCESS; -} - -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.buffer.data(), parameter.buffer.size()); - text_memory = - boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(parameter.object); - - // TODO(Subv): Verify if this is the correct behavior - memset(text_memory->GetPointer(), 0, text_memory->size); - - DrawScreenKeyboard(); - - is_running = true; - return RESULT_SUCCESS; -} - -void SoftwareKeyboard::Update() { - // TODO(Subv): Handle input using the touch events from the HID module - - // TODO(Subv): Remove this hardcoded text - 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 = 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 = Service::GSP::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 - Memory::ZeroBlock(info.address_left, info.stride * 320); - - Service::GSP::SetBufferSwap(1, info); -} - -void SoftwareKeyboard::Finalize() { - // Let the application know that we're closing - Service::APT::MessageParameter message; - message.buffer.resize(sizeof(SoftwareKeyboardConfig)); - std::memcpy(message.buffer.data(), &config, message.buffer.size()); - message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit); - message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); - message.sender_id = static_cast<u32>(id); - Service::APT::SendParameter(message); - - is_running = false; -} -} -} // namespace diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h deleted file mode 100644 index cc92a8f19..000000000 --- a/src/core/hle/applets/swkbd.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_funcs.h" -#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/result.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); -}; - -/** - * 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 final : public Applet { -public: - SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) {} - - ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override; - ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override; - void Update() override; - - /** - * 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(); - -private: - /// This SharedMemory will be created when we receive the LibAppJustStarted message. - /// It holds the framebuffer info retrieved by the application with - /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; - - /// SharedMemory where the output text will be stored - Kernel::SharedPtr<Kernel::SharedMemory> text_memory; - - /// Configuration of this instance of the SoftwareKeyboard, as received from the application - SoftwareKeyboardConfig config; -}; -} -} // namespace |