mii_selector.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include <string>
  6. #include "common/assert.h"
  7. #include "common/logging/log.h"
  8. #include "common/string_util.h"
  9. #include "core/hle/applets/mii_selector.h"
  10. #include "core/hle/kernel/kernel.h"
  11. #include "core/hle/kernel/shared_memory.h"
  12. #include "core/hle/result.h"
  13. #include "video_core/video_core.h"
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////
  15. namespace HLE {
  16. namespace Applets {
  17. ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
  18. if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) {
  19. LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);
  20. UNIMPLEMENTED();
  21. // TODO(Subv): Find the right error code
  22. return ResultCode(-1);
  23. }
  24. // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared memory.
  25. // Create the SharedMemory that will hold the framebuffer data
  26. Service::APT::CaptureBufferInfo capture_info;
  27. ASSERT(sizeof(capture_info) == parameter.buffer.size());
  28. memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info));
  29. using Kernel::MemoryPermission;
  30. // Allocate a heap block of the required size for this applet.
  31. heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
  32. // Create a SharedMemory that directly points to this heap block.
  33. framebuffer_memory = Kernel::SharedMemory::CreateForApplet(heap_memory, 0, heap_memory->size(),
  34. MemoryPermission::ReadWrite, MemoryPermission::ReadWrite,
  35. "MiiSelector Memory");
  36. // Send the response message with the newly created SharedMemory
  37. Service::APT::MessageParameter result;
  38. result.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished);
  39. result.buffer.clear();
  40. result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  41. result.sender_id = static_cast<u32>(id);
  42. result.object = framebuffer_memory;
  43. Service::APT::SendParameter(result);
  44. return RESULT_SUCCESS;
  45. }
  46. ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& parameter) {
  47. started = true;
  48. // TODO(Subv): Set the expected fields in the response buffer before resending it to the application.
  49. // TODO(Subv): Reverse the parameter format for the Mii Selector
  50. memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
  51. // TODO(Subv): Find more about this structure, result code 0 is enough to let most games continue.
  52. MiiResult result;
  53. memset(&result, 0, sizeof(result));
  54. result.result_code = 0;
  55. // Let the application know that we're closing
  56. Service::APT::MessageParameter message;
  57. message.buffer.resize(sizeof(MiiResult));
  58. std::memcpy(message.buffer.data(), &result, message.buffer.size());
  59. message.signal = static_cast<u32>(Service::APT::SignalType::LibAppClosed);
  60. message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  61. message.sender_id = static_cast<u32>(id);
  62. Service::APT::SendParameter(message);
  63. started = false;
  64. return RESULT_SUCCESS;
  65. }
  66. void MiiSelector::Update() {
  67. }
  68. }
  69. } // namespace