diff options
Diffstat (limited to 'src/core/hle/applets/swkbd.cpp')
| -rw-r--r-- | src/core/hle/applets/swkbd.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp new file mode 100644 index 000000000..7431ebcf8 --- /dev/null +++ b/src/core/hle/applets/swkbd.cpp | |||
| @@ -0,0 +1,105 @@ | |||
| 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 | #include "common/string_util.h" | ||
| 8 | |||
| 9 | #include "core/hle/applets/swkbd.h" | ||
| 10 | #include "core/hle/service/hid/hid.h" | ||
| 11 | #include "core/hle/service/gsp_gpu.h" | ||
| 12 | #include "video_core/video_core.h" | ||
| 13 | |||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | |||
| 16 | namespace HLE { | ||
| 17 | namespace Applets { | ||
| 18 | |||
| 19 | SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) { | ||
| 20 | // Create the SharedMemory that will hold the framebuffer data | ||
| 21 | // TODO(Subv): What size should we use here? | ||
| 22 | using Kernel::MemoryPermission; | ||
| 23 | framebuffer_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, "SoftwareKeyboard Memory"); | ||
| 24 | } | ||
| 25 | |||
| 26 | ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) { | ||
| 27 | if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) { | ||
| 28 | LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal); | ||
| 29 | UNIMPLEMENTED(); | ||
| 30 | // TODO(Subv): Find the right error code | ||
| 31 | return ResultCode(-1); | ||
| 32 | } | ||
| 33 | |||
| 34 | Service::APT::MessageParameter result; | ||
| 35 | // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInfo | ||
| 36 | result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished); | ||
| 37 | result.data = nullptr; | ||
| 38 | result.buffer_size = 0; | ||
| 39 | result.destination_id = static_cast<u32>(Service::APT::AppletId::Application); | ||
| 40 | result.sender_id = static_cast<u32>(id); | ||
| 41 | result.object = framebuffer_memory; | ||
| 42 | |||
| 43 | Service::APT::SendParameter(result); | ||
| 44 | return RESULT_SUCCESS; | ||
| 45 | } | ||
| 46 | |||
| 47 | ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter const& parameter) { | ||
| 48 | ASSERT_MSG(parameter.buffer_size == sizeof(config), "The size of the parameter (SoftwareKeyboardConfig) is wrong"); | ||
| 49 | |||
| 50 | memcpy(&config, parameter.data, parameter.buffer_size); | ||
| 51 | text_memory = boost::static_pointer_cast<Kernel::SharedMemory, Kernel::Object>(parameter.object); | ||
| 52 | |||
| 53 | // TODO(Subv): Verify if this is the correct behavior | ||
| 54 | memset(text_memory->GetPointer(), 0, text_memory->size); | ||
| 55 | |||
| 56 | DrawScreenKeyboard(); | ||
| 57 | |||
| 58 | started = true; | ||
| 59 | return RESULT_SUCCESS; | ||
| 60 | } | ||
| 61 | |||
| 62 | void SoftwareKeyboard::Update() { | ||
| 63 | // TODO(Subv): Handle input using the touch events from the HID module | ||
| 64 | |||
| 65 | // TODO(Subv): Remove this hardcoded text | ||
| 66 | std::u16string text = Common::UTF8ToUTF16("Citra"); | ||
| 67 | memcpy(text_memory->GetPointer(), text.c_str(), text.length() * sizeof(char16_t)); | ||
| 68 | |||
| 69 | // TODO(Subv): Ask for input and write it to the shared memory | ||
| 70 | // TODO(Subv): Find out what are the possible values for the return code, | ||
| 71 | // some games seem to check for a hardcoded 2 | ||
| 72 | config.return_code = 2; | ||
| 73 | config.text_length = 6; | ||
| 74 | config.text_offset = 0; | ||
| 75 | |||
| 76 | // TODO(Subv): We're finalizing the applet immediately after it's started, | ||
| 77 | // but we should defer this call until after all the input has been collected. | ||
| 78 | Finalize(); | ||
| 79 | } | ||
| 80 | |||
| 81 | void SoftwareKeyboard::DrawScreenKeyboard() { | ||
| 82 | auto bottom_screen = GSP_GPU::GetFrameBufferInfo(0, 1); | ||
| 83 | auto info = bottom_screen->framebuffer_info[bottom_screen->index]; | ||
| 84 | |||
| 85 | // TODO(Subv): Draw the HLE keyboard, for now just zero-fill the framebuffer | ||
| 86 | memset(Memory::GetPointer(info.address_left), 0, info.stride * 320); | ||
| 87 | |||
| 88 | GSP_GPU::SetBufferSwap(1, info); | ||
| 89 | } | ||
| 90 | |||
| 91 | void SoftwareKeyboard::Finalize() { | ||
| 92 | // Let the application know that we're closing | ||
| 93 | Service::APT::MessageParameter message; | ||
| 94 | message.buffer_size = sizeof(SoftwareKeyboardConfig); | ||
| 95 | message.data = reinterpret_cast<u8*>(&config); | ||
| 96 | message.signal = static_cast<u32>(Service::APT::SignalType::LibAppClosed); | ||
| 97 | message.destination_id = static_cast<u32>(Service::APT::AppletId::Application); | ||
| 98 | message.sender_id = static_cast<u32>(id); | ||
| 99 | Service::APT::SendParameter(message); | ||
| 100 | |||
| 101 | started = false; | ||
| 102 | } | ||
| 103 | |||
| 104 | } | ||
| 105 | } // namespace | ||