diff options
Diffstat (limited to 'src/core/hle/applets')
| -rw-r--r-- | src/core/hle/applets/applet.cpp | 40 | ||||
| -rw-r--r-- | src/core/hle/applets/applet.h | 53 | ||||
| -rw-r--r-- | src/core/hle/applets/swkbd.cpp | 73 | ||||
| -rw-r--r-- | src/core/hle/applets/swkbd.h | 67 |
4 files changed, 233 insertions, 0 deletions
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 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 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/logging/log.h" | ||
| 7 | |||
| 8 | #include "core/hle/applets/applet.h" | ||
| 9 | #include "core/hle/applets/swkbd.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | |||
| 13 | namespace HLE { | ||
| 14 | namespace Applets { | ||
| 15 | |||
| 16 | static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets; | ||
| 17 | |||
| 18 | ResultCode Applet::Create(Service::APT::AppletId id) { | ||
| 19 | switch (id) { | ||
| 20 | case Service::APT::AppletId::SoftwareKeyboard1: | ||
| 21 | case Service::APT::AppletId::SoftwareKeyboard2: | ||
| 22 | applets[id] = std::make_shared<SoftwareKeyboard>(id); | ||
| 23 | break; | ||
| 24 | default: | ||
| 25 | // TODO(Subv): Find the right error code | ||
| 26 | return ResultCode(ErrorDescription::NotFound, ErrorModule::Applet, ErrorSummary::NotSupported, ErrorLevel::Permanent); | ||
| 27 | } | ||
| 28 | |||
| 29 | return RESULT_SUCCESS; | ||
| 30 | } | ||
| 31 | |||
| 32 | std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) { | ||
| 33 | auto itr = applets.find(id); | ||
| 34 | if (itr != applets.end()) | ||
| 35 | return itr->second; | ||
| 36 | return nullptr; | ||
| 37 | } | ||
| 38 | |||
| 39 | } | ||
| 40 | } // 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 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 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_types.h" | ||
| 8 | #include "core/hle/kernel/kernel.h" | ||
| 9 | #include "core/hle/kernel/shared_memory.h" | ||
| 10 | #include "core/hle/service/apt/apt.h" | ||
| 11 | |||
| 12 | namespace HLE { | ||
| 13 | namespace Applets { | ||
| 14 | |||
| 15 | class Applet { | ||
| 16 | public: | ||
| 17 | virtual ~Applet() {}; | ||
| 18 | Applet(Service::APT::AppletId id) : id(id) {}; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Creates an instance of the Applet subclass identified by the parameter | ||
| 22 | * and stores it in a global map. | ||
| 23 | * @param id Id of the applet to create | ||
| 24 | * @returns ResultCode Whether the operation was successful or not | ||
| 25 | */ | ||
| 26 | static ResultCode Create(Service::APT::AppletId id); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Retrieves the Applet instance identified by the specified id | ||
| 30 | * @param id Id of the Applet to retrieve | ||
| 31 | * @returns Requested Applet or nullptr if not found | ||
| 32 | */ | ||
| 33 | static std::shared_ptr<Applet> Get(Service::APT::AppletId id); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Handles a parameter from the application | ||
| 37 | * @param parameter Parameter data to handle | ||
| 38 | * @returns ResultCode Whether the operation was successful or not | ||
| 39 | */ | ||
| 40 | virtual ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) = 0; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Handles the Applet start event, triggered from the application | ||
| 44 | * @param parameter Parameter data to handle | ||
| 45 | * @returns ResultCode Whether the operation was successful or not | ||
| 46 | */ | ||
| 47 | virtual ResultCode Start(Service::APT::AppletStartupParameter const& parameter) = 0; | ||
| 48 | |||
| 49 | Service::APT::AppletId id; ///< Id of this Applet | ||
| 50 | }; | ||
| 51 | |||
| 52 | } | ||
| 53 | } // 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 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 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/logging/log.h" | ||
| 7 | |||
| 8 | #include "core/hle/applets/swkbd.h" | ||
| 9 | |||
| 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 11 | |||
| 12 | namespace HLE { | ||
| 13 | namespace Applets { | ||
| 14 | |||
| 15 | SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id) { | ||
| 16 | // Create the SharedMemory that will hold the framebuffer data | ||
| 17 | // TODO(Subv): What size should we use here? | ||
| 18 | using Kernel::MemoryPermission; | ||
| 19 | framebuffer_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, "SoftwareKeyboard Memory"); | ||
| 20 | } | ||
| 21 | |||
| 22 | ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) { | ||
| 23 | if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) { | ||
| 24 | LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); | ||
| 25 | UNIMPLEMENTED(); | ||
| 26 | // TODO(Subv): Find the right error code | ||
| 27 | return ResultCode(-1); | ||
| 28 | } | ||
| 29 | |||
| 30 | Service::APT::MessageParameter result; | ||
| 31 | // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo | ||
| 32 | result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished); | ||
| 33 | result.data = nullptr; | ||
| 34 | result.buffer_size = 0; | ||
| 35 | result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); | ||
| 36 | result.sender_id = static_cast<u32>(id); | ||
| 37 | result.object = framebuffer_memory; | ||
| 38 | |||
| 39 | Service::APT::SendParameter(result); | ||
| 40 | return RESULT_SUCCESS; | ||
| 41 | } | ||
| 42 | |||
| 43 | ResultCode SoftwareKeyboard::Start(Service::APT::AppletStartupParameter const& parameter) { | ||
| 44 | memcpy(&config, parameter.data, parameter.buffer_size); | ||
| 45 | text_memory = boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(parameter.object); | ||
| 46 | |||
| 47 | // TODO(Subv): Verify if this is the correct behavior | ||
| 48 | memset(text_memory->GetPointer(), 0, text_memory->size); | ||
| 49 | |||
| 50 | // TODO(Subv): Remove this hardcoded text | ||
| 51 | const wchar_t str[] = L"Subv"; | ||
| 52 | memcpy(text_memory->GetPointer(), str, 4 * sizeof(wchar_t)); | ||
| 53 | |||
| 54 | // TODO(Subv): Ask for input and write it to the shared memory | ||
| 55 | // TODO(Subv): Find out what are the possible values for the return code, | ||
| 56 | // some games seem to check for a hardcoded 2 | ||
| 57 | config.return_code = 2; | ||
| 58 | config.text_length = 5; | ||
| 59 | config.text_offset = 0; | ||
| 60 | |||
| 61 | Service::APT::MessageParameter message; | ||
| 62 | message.buffer_size = sizeof(SoftwareKeyboardConfig); | ||
| 63 | message.data = reinterpret_cast<u8*>(&config); | ||
| 64 | message.signal = static_cast<u32>(Service::APT::SignalType::LibAppClosed); | ||
| 65 | message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); | ||
| 66 | message.sender_id = static_cast<u32>(id); | ||
| 67 | Service::APT::SendParameter(message); | ||
| 68 | |||
| 69 | return RESULT_SUCCESS; | ||
| 70 | } | ||
| 71 | |||
| 72 | } | ||
| 73 | } // 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 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 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_types.h" | ||
| 8 | #include "core/hle/applets/applet.h" | ||
| 9 | #include "core/hle/kernel/kernel.h" | ||
| 10 | #include "core/hle/kernel/shared_memory.h" | ||
| 11 | #include "core/hle/service/apt/apt.h" | ||
| 12 | |||
| 13 | namespace HLE { | ||
| 14 | namespace Applets { | ||
| 15 | |||
| 16 | struct SoftwareKeyboardConfig { | ||
| 17 | INSERT_PADDING_WORDS(0x8); | ||
| 18 | |||
| 19 | u16 max_text_length; ///< Maximum length of the input text | ||
| 20 | |||
| 21 | INSERT_PADDING_BYTES(0x6E); | ||
| 22 | |||
| 23 | char16_t display_text[65]; ///< Text to display when asking the user for input | ||
| 24 | |||
| 25 | INSERT_PADDING_BYTES(0xE); | ||
| 26 | |||
| 27 | u32 default_text_offset; ///< Offset of the default text in the output SharedMemory | ||
| 28 | |||
| 29 | INSERT_PADDING_WORDS(0x3); | ||
| 30 | |||
| 31 | u32 shared_memory_size; ///< Size of the SharedMemory | ||
| 32 | |||
| 33 | INSERT_PADDING_WORDS(0x1); | ||
| 34 | |||
| 35 | u32 return_code; ///< Return code of the SoftwareKeyboard, usually 2, other values are unknown | ||
| 36 | |||
| 37 | INSERT_PADDING_WORDS(0x2); | ||
| 38 | |||
| 39 | u32 text_offset; ///< Offset in the SharedMemory where the output text starts | ||
| 40 | u16 text_length; ///< Length in characters of the output text | ||
| 41 | |||
| 42 | INSERT_PADDING_BYTES(0x2B6); | ||
| 43 | }; | ||
| 44 | |||
| 45 | static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Config size is wrong"); | ||
| 46 | |||
| 47 | class SoftwareKeyboard : public Applet { | ||
| 48 | public: | ||
| 49 | SoftwareKeyboard(Service::APT::AppletId id); | ||
| 50 | ~SoftwareKeyboard() {} | ||
| 51 | |||
| 52 | ResultCode ReceiveParameter(Service::APT::MessageParameter const& parameter) override; | ||
| 53 | ResultCode Start(Service::APT::AppletStartupParameter const& parameter) override; | ||
| 54 | |||
| 55 | /// TODO(Subv): Find out what this is actually used for. | ||
| 56 | // It is believed that the application stores the current screen image here. | ||
| 57 | Kernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory; | ||
| 58 | |||
| 59 | /// SharedMemory where the output text will be stored | ||
| 60 | Kernel::SharedPtr<Kernel::SharedMemory> text_memory; | ||
| 61 | |||
| 62 | /// Configuration of this instance of the SoftwareKeyboard, as received from the application | ||
| 63 | SoftwareKeyboardConfig config; | ||
| 64 | }; | ||
| 65 | |||
| 66 | } | ||
| 67 | } // namespace | ||