controller.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <vector>
  7. #include "common/common_funcs.h"
  8. #include "common/common_types.h"
  9. #include "core/hle/result.h"
  10. #include "core/hle/service/am/applets/applets.h"
  11. namespace Core {
  12. class System;
  13. }
  14. namespace Service::AM::Applets {
  15. using IdentificationColor = std::array<u8, 4>;
  16. using ExplainText = std::array<char, 0x81>;
  17. enum class LibraryAppletVersion : u32_le {
  18. Version3 = 0x3, // 1.0.0 - 2.3.0
  19. Version4 = 0x4, // 3.0.0 - 5.1.0
  20. Version5 = 0x5, // 6.0.0 - 7.0.1
  21. Version7 = 0x7, // 8.0.0+
  22. };
  23. enum class ControllerSupportMode : u8 {
  24. ShowControllerSupport = 0,
  25. ShowControllerStrapGuide = 1,
  26. ShowControllerFirmwareUpdate = 2,
  27. };
  28. enum class ControllerSupportCaller : u8 {
  29. Application = 0,
  30. System = 1,
  31. };
  32. struct ControllerSupportArgPrivate {
  33. u32 arg_private_size{};
  34. u32 arg_size{};
  35. bool flag_0{};
  36. bool flag_1{};
  37. ControllerSupportMode mode{};
  38. ControllerSupportCaller caller{};
  39. u32 style_set{};
  40. u32 joy_hold_type{};
  41. };
  42. static_assert(sizeof(ControllerSupportArgPrivate) == 0x14,
  43. "ControllerSupportArgPrivate has incorrect size.");
  44. struct ControllerSupportArgHeader {
  45. s8 player_count_min{};
  46. s8 player_count_max{};
  47. bool enable_take_over_connection{};
  48. bool enable_left_justify{};
  49. bool enable_permit_joy_dual{};
  50. bool enable_single_mode{};
  51. bool enable_identification_color{};
  52. };
  53. static_assert(sizeof(ControllerSupportArgHeader) == 0x7,
  54. "ControllerSupportArgHeader has incorrect size.");
  55. // LibraryAppletVersion 0x3, 0x4, 0x5
  56. struct ControllerSupportArgOld {
  57. ControllerSupportArgHeader header{};
  58. std::array<IdentificationColor, 4> identification_colors{};
  59. bool enable_explain_text{};
  60. std::array<ExplainText, 4> explain_text{};
  61. };
  62. static_assert(sizeof(ControllerSupportArgOld) == 0x21C,
  63. "ControllerSupportArgOld has incorrect size.");
  64. // LibraryAppletVersion 0x7
  65. struct ControllerSupportArgNew {
  66. ControllerSupportArgHeader header{};
  67. std::array<IdentificationColor, 8> identification_colors{};
  68. bool enable_explain_text{};
  69. std::array<ExplainText, 8> explain_text{};
  70. };
  71. static_assert(sizeof(ControllerSupportArgNew) == 0x430,
  72. "ControllerSupportArgNew has incorrect size.");
  73. struct ControllerSupportResultInfo {
  74. s8 player_count{};
  75. INSERT_PADDING_BYTES(3);
  76. u32 selected_id{};
  77. u32 result{};
  78. };
  79. static_assert(sizeof(ControllerSupportResultInfo) == 0xC,
  80. "ControllerSupportResultInfo has incorrect size.");
  81. class Controller final : public Applet {
  82. public:
  83. explicit Controller(Core::System& system_, const Core::Frontend::ControllerApplet& frontend_);
  84. ~Controller() override;
  85. void Initialize() override;
  86. bool TransactionComplete() const override;
  87. ResultCode GetStatus() const override;
  88. void ExecuteInteractive() override;
  89. void Execute() override;
  90. void ConfigurationComplete();
  91. private:
  92. const Core::Frontend::ControllerApplet& frontend;
  93. LibraryAppletVersion library_applet_version;
  94. ControllerSupportArgPrivate controller_private_arg;
  95. ControllerSupportArgOld controller_user_arg_old;
  96. ControllerSupportArgNew controller_user_arg_new;
  97. bool complete{false};
  98. ResultCode status{RESULT_SUCCESS};
  99. bool is_single_mode{false};
  100. std::vector<u8> out_data;
  101. };
  102. } // namespace Service::AM::Applets