mii_selector.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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::Request)) {
  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
  25. // memory.
  26. // Create the SharedMemory that will hold the framebuffer data
  27. Service::APT::CaptureBufferInfo capture_info;
  28. ASSERT(sizeof(capture_info) == parameter.buffer.size());
  29. memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info));
  30. using Kernel::MemoryPermission;
  31. // Allocate a heap block of the required size for this applet.
  32. heap_memory = std::make_shared<std::vector<u8>>(capture_info.size);
  33. // Create a SharedMemory that directly points to this heap block.
  34. framebuffer_memory = Kernel::SharedMemory::CreateForApplet(
  35. heap_memory, 0, heap_memory->size(), MemoryPermission::ReadWrite,
  36. MemoryPermission::ReadWrite, "MiiSelector Memory");
  37. // Send the response message with the newly created SharedMemory
  38. Service::APT::MessageParameter result;
  39. result.signal = static_cast<u32>(Service::APT::SignalType::Response);
  40. result.buffer.clear();
  41. result.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  42. result.sender_id = static_cast<u32>(id);
  43. result.object = framebuffer_memory;
  44. Service::APT::SendParameter(result);
  45. return RESULT_SUCCESS;
  46. }
  47. ResultCode MiiSelector::StartImpl(const Service::APT::AppletStartupParameter& parameter) {
  48. is_running = true;
  49. // TODO(Subv): Set the expected fields in the response buffer before resending it to the
  50. // application.
  51. // TODO(Subv): Reverse the parameter format for the Mii Selector
  52. memcpy(&config, parameter.buffer.data(), parameter.buffer.size());
  53. // TODO(Subv): Find more about this structure, result code 0 is enough to let most games
  54. // continue.
  55. MiiResult result;
  56. memset(&result, 0, sizeof(result));
  57. result.result_code = 0;
  58. // Let the application know that we're closing
  59. Service::APT::MessageParameter message;
  60. message.buffer.resize(sizeof(MiiResult));
  61. std::memcpy(message.buffer.data(), &result, message.buffer.size());
  62. message.signal = static_cast<u32>(Service::APT::SignalType::WakeupByExit);
  63. message.destination_id = static_cast<u32>(Service::APT::AppletId::Application);
  64. message.sender_id = static_cast<u32>(id);
  65. Service::APT::SendParameter(message);
  66. is_running = false;
  67. return RESULT_SUCCESS;
  68. }
  69. void MiiSelector::Update() {}
  70. }
  71. } // namespace