summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar liamwhite2023-12-09 13:41:06 -0500
committerGravatar GitHub2023-12-09 13:41:06 -0500
commitc1924951ad604417a5f7900427bff4ab0c8286a7 (patch)
tree1100f74cd019eabe937e40e921a2b481ca77da69
parentMerge pull request #12320 from liamwhite/debug-fix (diff)
parentservice: hid: Introduce proper AppletResource emulation (diff)
downloadyuzu-c1924951ad604417a5f7900427bff4ab0c8286a7.tar.gz
yuzu-c1924951ad604417a5f7900427bff4ab0c8286a7.tar.xz
yuzu-c1924951ad604417a5f7900427bff4ab0c8286a7.zip
Merge pull request #12289 from german77/aruid
service: hid: Introduce proper AppletResource emulation
Diffstat (limited to '')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/hle/service/hid/controllers/applet_resource.cpp199
-rw-r--r--src/core/hle/service/hid/controllers/applet_resource.h87
-rw-r--r--src/core/hle/service/hid/errors.h5
-rw-r--r--src/core/hle/service/hid/hid.cpp8
-rw-r--r--src/core/hle/service/hid/hid_server.cpp7
-rw-r--r--src/core/hle/service/hid/hid_system_server.cpp136
-rw-r--r--src/core/hle/service/hid/hid_system_server.h6
-rw-r--r--src/core/hle/service/hid/resource_manager.cpp62
-rw-r--r--src/core/hle/service/hid/resource_manager.h27
10 files changed, 526 insertions, 13 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index e2120bdfe..b483fd975 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -543,6 +543,8 @@ add_library(core STATIC
543 hle/service/hid/xcd.cpp 543 hle/service/hid/xcd.cpp
544 hle/service/hid/xcd.h 544 hle/service/hid/xcd.h
545 hle/service/hid/errors.h 545 hle/service/hid/errors.h
546 hle/service/hid/controllers/applet_resource.cpp
547 hle/service/hid/controllers/applet_resource.h
546 hle/service/hid/controllers/console_six_axis.cpp 548 hle/service/hid/controllers/console_six_axis.cpp
547 hle/service/hid/controllers/console_six_axis.h 549 hle/service/hid/controllers/console_six_axis.h
548 hle/service/hid/controllers/controller_base.cpp 550 hle/service/hid/controllers/controller_base.cpp
diff --git a/src/core/hle/service/hid/controllers/applet_resource.cpp b/src/core/hle/service/hid/controllers/applet_resource.cpp
new file mode 100644
index 000000000..ee60d8b44
--- /dev/null
+++ b/src/core/hle/service/hid/controllers/applet_resource.cpp
@@ -0,0 +1,199 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "core/core.h"
5#include "core/hle/kernel/k_shared_memory.h"
6#include "core/hle/service/hid/controllers/applet_resource.h"
7#include "core/hle/service/hid/errors.h"
8
9namespace Service::HID {
10
11AppletResource::AppletResource(Core::System& system_) : system{system_} {}
12
13AppletResource::~AppletResource() = default;
14
15Result AppletResource::CreateAppletResource(u64 aruid) {
16 const u64 index = GetIndexFromAruid(aruid);
17
18 if (index >= AruidIndexMax) {
19 return ResultAruidNotRegistered;
20 }
21
22 if (data[index].flag.is_assigned) {
23 return ResultAruidAlreadyRegistered;
24 }
25
26 // TODO: Here shared memory is created for the process we don't quite emulate this part so
27 // obtain this pointer from system
28 auto& shared_memory = system.Kernel().GetHidSharedMem();
29
30 data[index].shared_memory_handle = &shared_memory;
31 data[index].flag.is_assigned.Assign(true);
32 // TODO: InitializeSixAxisControllerConfig(false);
33 active_aruid = aruid;
34 return ResultSuccess;
35}
36
37Result AppletResource::RegisterAppletResourceUserId(u64 aruid, bool enable_input) {
38 const u64 index = GetIndexFromAruid(aruid);
39
40 if (index < AruidIndexMax) {
41 return ResultAruidAlreadyRegistered;
42 }
43
44 std::size_t data_index = AruidIndexMax;
45 for (std::size_t i = 0; i < AruidIndexMax; i++) {
46 if (!data[i].flag.is_initialized) {
47 data_index = i;
48 break;
49 }
50 }
51
52 if (data_index == AruidIndexMax) {
53 return ResultAruidNoAvailableEntries;
54 }
55
56 AruidData& aruid_data = data[data_index];
57
58 aruid_data.aruid = aruid;
59 aruid_data.flag.is_initialized.Assign(true);
60 if (enable_input) {
61 aruid_data.flag.enable_pad_input.Assign(true);
62 aruid_data.flag.enable_six_axis_sensor.Assign(true);
63 aruid_data.flag.bit_18.Assign(true);
64 aruid_data.flag.enable_touchscreen.Assign(true);
65 }
66
67 data_index = AruidIndexMax;
68 for (std::size_t i = 0; i < AruidIndexMax; i++) {
69 if (registration_list.flag[i] == RegistrationStatus::Initialized) {
70 if (registration_list.aruid[i] != aruid) {
71 continue;
72 }
73 data_index = i;
74 break;
75 }
76 if (registration_list.flag[i] == RegistrationStatus::None) {
77 data_index = i;
78 break;
79 }
80 }
81
82 if (data_index == AruidIndexMax) {
83 return ResultSuccess;
84 }
85
86 registration_list.flag[data_index] = RegistrationStatus::Initialized;
87 registration_list.aruid[data_index] = aruid;
88
89 return ResultSuccess;
90}
91
92void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
93 u64 index = GetIndexFromAruid(aruid);
94
95 if (index < AruidIndexMax) {
96 if (data[index].flag.is_assigned) {
97 data[index].shared_memory_handle = nullptr;
98 data[index].flag.is_assigned.Assign(false);
99 }
100 }
101
102 index = GetIndexFromAruid(aruid);
103 if (index < AruidIndexMax) {
104 DestroySevenSixAxisTransferMemory();
105 data[index].flag.raw = 0;
106 data[index].aruid = 0;
107
108 index = GetIndexFromAruid(aruid);
109 if (index < AruidIndexMax) {
110 registration_list.flag[index] = RegistrationStatus::PendingDelete;
111 }
112 }
113}
114
115u64 AppletResource::GetActiveAruid() {
116 return active_aruid;
117}
118
119Result AppletResource::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
120 u64 index = GetIndexFromAruid(aruid);
121 if (index >= AruidIndexMax) {
122 return ResultAruidNotRegistered;
123 }
124
125 *out_handle = data[index].shared_memory_handle;
126 return ResultSuccess;
127}
128
129u64 AppletResource::GetIndexFromAruid(u64 aruid) {
130 for (std::size_t i = 0; i < AruidIndexMax; i++) {
131 if (registration_list.flag[i] == RegistrationStatus::Initialized &&
132 registration_list.aruid[i] == aruid) {
133 return i;
134 }
135 }
136 return AruidIndexMax;
137}
138
139Result AppletResource::DestroySevenSixAxisTransferMemory() {
140 // TODO
141 return ResultSuccess;
142}
143
144void AppletResource::EnableInput(u64 aruid, bool is_enabled) {
145 const u64 index = GetIndexFromAruid(aruid);
146 if (index >= AruidIndexMax) {
147 return;
148 }
149
150 data[index].flag.enable_pad_input.Assign(is_enabled);
151 data[index].flag.enable_touchscreen.Assign(is_enabled);
152}
153
154void AppletResource::EnableSixAxisSensor(u64 aruid, bool is_enabled) {
155 const u64 index = GetIndexFromAruid(aruid);
156 if (index >= AruidIndexMax) {
157 return;
158 }
159
160 data[index].flag.enable_six_axis_sensor.Assign(is_enabled);
161}
162
163void AppletResource::EnablePadInput(u64 aruid, bool is_enabled) {
164 const u64 index = GetIndexFromAruid(aruid);
165 if (index >= AruidIndexMax) {
166 return;
167 }
168
169 data[index].flag.enable_pad_input.Assign(is_enabled);
170}
171
172void AppletResource::EnableTouchScreen(u64 aruid, bool is_enabled) {
173 const u64 index = GetIndexFromAruid(aruid);
174 if (index >= AruidIndexMax) {
175 return;
176 }
177
178 data[index].flag.enable_touchscreen.Assign(is_enabled);
179}
180
181void AppletResource::SetIsPalmaConnectable(u64 aruid, bool is_connectable) {
182 const u64 index = GetIndexFromAruid(aruid);
183 if (index >= AruidIndexMax) {
184 return;
185 }
186
187 data[index].flag.is_palma_connectable.Assign(is_connectable);
188}
189
190void AppletResource::EnablePalmaBoostMode(u64 aruid, bool is_enabled) {
191 const u64 index = GetIndexFromAruid(aruid);
192 if (index >= AruidIndexMax) {
193 return;
194 }
195
196 data[index].flag.enable_palma_boost_mode.Assign(is_enabled);
197}
198
199} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/applet_resource.h b/src/core/hle/service/hid/controllers/applet_resource.h
new file mode 100644
index 000000000..3dcec2898
--- /dev/null
+++ b/src/core/hle/service/hid/controllers/applet_resource.h
@@ -0,0 +1,87 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/bit_field.h"
9#include "common/common_types.h"
10#include "core/hle/result.h"
11
12namespace Core {
13class System;
14}
15
16namespace Kernel {
17class KSharedMemory;
18}
19
20namespace Service::HID {
21class AppletResource {
22public:
23 explicit AppletResource(Core::System& system_);
24 ~AppletResource();
25
26 Result CreateAppletResource(u64 aruid);
27
28 Result RegisterAppletResourceUserId(u64 aruid, bool enable_input);
29 void UnregisterAppletResourceUserId(u64 aruid);
30
31 u64 GetActiveAruid();
32 Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
33
34 u64 GetIndexFromAruid(u64 aruid);
35
36 Result DestroySevenSixAxisTransferMemory();
37
38 void EnableInput(u64 aruid, bool is_enabled);
39 void EnableSixAxisSensor(u64 aruid, bool is_enabled);
40 void EnablePadInput(u64 aruid, bool is_enabled);
41 void EnableTouchScreen(u64 aruid, bool is_enabled);
42 void SetIsPalmaConnectable(u64 aruid, bool is_connectable);
43 void EnablePalmaBoostMode(u64 aruid, bool is_enabled);
44
45private:
46 static constexpr std::size_t AruidIndexMax = 0x20;
47
48 enum RegistrationStatus : u32 {
49 None,
50 Initialized,
51 PendingDelete,
52 };
53
54 struct DataStatusFlag {
55 union {
56 u32 raw{};
57
58 BitField<0, 1, u32> is_initialized;
59 BitField<1, 1, u32> is_assigned;
60 BitField<16, 1, u32> enable_pad_input;
61 BitField<17, 1, u32> enable_six_axis_sensor;
62 BitField<18, 1, u32> bit_18;
63 BitField<19, 1, u32> is_palma_connectable;
64 BitField<20, 1, u32> enable_palma_boost_mode;
65 BitField<21, 1, u32> enable_touchscreen;
66 };
67 };
68
69 struct AruidRegisterList {
70 std::array<RegistrationStatus, AruidIndexMax> flag{};
71 std::array<u64, AruidIndexMax> aruid{};
72 };
73 static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
74
75 struct AruidData {
76 DataStatusFlag flag{};
77 u64 aruid{};
78 Kernel::KSharedMemory* shared_memory_handle{nullptr};
79 };
80
81 u64 active_aruid{};
82 AruidRegisterList registration_list{};
83 std::array<AruidData, AruidIndexMax> data{};
84
85 Core::System& system;
86};
87} // namespace Service::HID
diff --git a/src/core/hle/service/hid/errors.h b/src/core/hle/service/hid/errors.h
index 9585bdaf0..f00cb831f 100644
--- a/src/core/hle/service/hid/errors.h
+++ b/src/core/hle/service/hid/errors.h
@@ -19,6 +19,11 @@ constexpr Result NpadIsSameType{ErrorModule::HID, 602};
19constexpr Result InvalidNpadId{ErrorModule::HID, 709}; 19constexpr Result InvalidNpadId{ErrorModule::HID, 709};
20constexpr Result NpadNotConnected{ErrorModule::HID, 710}; 20constexpr Result NpadNotConnected{ErrorModule::HID, 710};
21constexpr Result InvalidArraySize{ErrorModule::HID, 715}; 21constexpr Result InvalidArraySize{ErrorModule::HID, 715};
22
23constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
24constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
25constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};
26
22constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302}; 27constexpr Result InvalidPalmaHandle{ErrorModule::HID, 3302};
23 28
24} // namespace Service::HID 29} // namespace Service::HID
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 1b7381d8d..afbcb019f 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -1,6 +1,8 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/hle/kernel/k_process.h"
5#include "core/hle/kernel/kernel.h"
4#include "core/hle/service/hid/hid.h" 6#include "core/hle/service/hid/hid.h"
5#include "core/hle/service/hid/hid_debug_server.h" 7#include "core/hle/service/hid/hid_debug_server.h"
6#include "core/hle/service/hid/hid_firmware_settings.h" 8#include "core/hle/service/hid/hid_firmware_settings.h"
@@ -20,6 +22,12 @@ void LoopProcess(Core::System& system) {
20 std::shared_ptr<HidFirmwareSettings> firmware_settings = 22 std::shared_ptr<HidFirmwareSettings> firmware_settings =
21 std::make_shared<HidFirmwareSettings>(); 23 std::make_shared<HidFirmwareSettings>();
22 24
25 // TODO: Remove this hack until this service is emulated properly.
26 const auto process_list = system.Kernel().GetProcessList();
27 if (!process_list.empty()) {
28 resouce_manager->RegisterAppletResourceUserId(process_list[0]->GetId(), true);
29 }
30
23 server_manager->RegisterNamedService( 31 server_manager->RegisterNamedService(
24 "hid", std::make_shared<IHidServer>(system, resouce_manager, firmware_settings)); 32 "hid", std::make_shared<IHidServer>(system, resouce_manager, firmware_settings));
25 server_manager->RegisterNamedService( 33 server_manager->RegisterNamedService(
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp
index a7d1578d9..e0f4051aa 100644
--- a/src/core/hle/service/hid/hid_server.cpp
+++ b/src/core/hle/service/hid/hid_server.cpp
@@ -224,8 +224,13 @@ void IHidServer::CreateAppletResource(HLERequestContext& ctx) {
224 224
225 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 225 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
226 226
227 Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id);
228 if (result.IsSuccess()) {
229 result = GetResourceManager()->GetNpad()->Activate(applet_resource_user_id);
230 }
231
227 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 232 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
228 rb.Push(ResultSuccess); 233 rb.Push(result);
229 rb.PushIpcInterface<IAppletResource>(system, resource_manager); 234 rb.PushIpcInterface<IAppletResource>(system, resource_manager);
230} 235}
231 236
diff --git a/src/core/hle/service/hid/hid_system_server.cpp b/src/core/hle/service/hid/hid_system_server.cpp
index b56d0347a..4d33456a3 100644
--- a/src/core/hle/service/hid/hid_system_server.cpp
+++ b/src/core/hle/service/hid/hid_system_server.cpp
@@ -3,6 +3,7 @@
3 3
4#include "core/hid/hid_core.h" 4#include "core/hid/hid_core.h"
5#include "core/hle/service/hid/controllers/npad.h" 5#include "core/hle/service/hid/controllers/npad.h"
6#include "core/hle/service/hid/controllers/palma.h"
6#include "core/hle/service/hid/controllers/touchscreen.h" 7#include "core/hle/service/hid/controllers/touchscreen.h"
7#include "core/hle/service/hid/errors.h" 8#include "core/hle/service/hid/errors.h"
8#include "core/hle/service/hid/hid_system_server.h" 9#include "core/hle/service/hid/hid_system_server.h"
@@ -63,13 +64,13 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
63 {329, nullptr, "DetachAbstractedPadAll"}, 64 {329, nullptr, "DetachAbstractedPadAll"},
64 {330, nullptr, "CheckAbstractedPadConnection"}, 65 {330, nullptr, "CheckAbstractedPadConnection"},
65 {500, nullptr, "SetAppletResourceUserId"}, 66 {500, nullptr, "SetAppletResourceUserId"},
66 {501, nullptr, "RegisterAppletResourceUserId"}, 67 {501, &IHidSystemServer::RegisterAppletResourceUserId, "RegisterAppletResourceUserId"},
67 {502, nullptr, "UnregisterAppletResourceUserId"}, 68 {502, &IHidSystemServer::UnregisterAppletResourceUserId, "UnregisterAppletResourceUserId"},
68 {503, nullptr, "EnableAppletToGetInput"}, 69 {503, &IHidSystemServer::EnableAppletToGetInput, "EnableAppletToGetInput"},
69 {504, nullptr, "SetAruidValidForVibration"}, 70 {504, nullptr, "SetAruidValidForVibration"},
70 {505, nullptr, "EnableAppletToGetSixAxisSensor"}, 71 {505, &IHidSystemServer::EnableAppletToGetSixAxisSensor, "EnableAppletToGetSixAxisSensor"},
71 {506, nullptr, "EnableAppletToGetPadInput"}, 72 {506, &IHidSystemServer::EnableAppletToGetPadInput, "EnableAppletToGetPadInput"},
72 {507, nullptr, "EnableAppletToGetTouchScreen"}, 73 {507, &IHidSystemServer::EnableAppletToGetTouchScreen, "EnableAppletToGetTouchScreen"},
73 {510, nullptr, "SetVibrationMasterVolume"}, 74 {510, nullptr, "SetVibrationMasterVolume"},
74 {511, nullptr, "GetVibrationMasterVolume"}, 75 {511, nullptr, "GetVibrationMasterVolume"},
75 {512, nullptr, "BeginPermitVibrationSession"}, 76 {512, nullptr, "BeginPermitVibrationSession"},
@@ -420,6 +421,129 @@ void IHidSystemServer::GetIrSensorState(HLERequestContext& ctx) {
420 IPC::ResponseBuilder rb{ctx, 2}; 421 IPC::ResponseBuilder rb{ctx, 2};
421 rb.Push(ResultSuccess); 422 rb.Push(ResultSuccess);
422} 423}
424void IHidSystemServer::RegisterAppletResourceUserId(HLERequestContext& ctx) {
425 IPC::RequestParser rp{ctx};
426 struct Parameters {
427 bool enable_input;
428 INSERT_PADDING_WORDS_NOINIT(1);
429 u64 applet_resource_user_id;
430 };
431 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
432
433 const auto parameters{rp.PopRaw<Parameters>()};
434
435 LOG_INFO(Service_HID, "called, enable_input={}, applet_resource_user_id={}",
436 parameters.enable_input, parameters.applet_resource_user_id);
437
438 Result result = GetResourceManager()->RegisterAppletResourceUserId(
439 parameters.applet_resource_user_id, parameters.enable_input);
440
441 if (result.IsSuccess()) {
442 // result = GetResourceManager()->GetNpad()->RegisterAppletResourceUserId(
443 // parameters.applet_resource_user_id);
444 }
445
446 IPC::ResponseBuilder rb{ctx, 2};
447 rb.Push(ResultSuccess);
448}
449
450void IHidSystemServer::UnregisterAppletResourceUserId(HLERequestContext& ctx) {
451 IPC::RequestParser rp{ctx};
452 u64 applet_resource_user_id{rp.Pop<u64>()};
453
454 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
455
456 GetResourceManager()->UnregisterAppletResourceUserId(applet_resource_user_id);
457 // GetResourceManager()->GetNpad()->UnregisterAppletResourceUserId(applet_resource_user_id);
458 // GetResourceManager()->GetPalma()->UnregisterAppletResourceUserId(applet_resource_user_id);
459
460 IPC::ResponseBuilder rb{ctx, 2};
461 rb.Push(ResultSuccess);
462}
463
464void IHidSystemServer::EnableAppletToGetInput(HLERequestContext& ctx) {
465 IPC::RequestParser rp{ctx};
466 struct Parameters {
467 bool is_enabled;
468 INSERT_PADDING_WORDS_NOINIT(1);
469 u64 applet_resource_user_id;
470 };
471 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
472
473 const auto parameters{rp.PopRaw<Parameters>()};
474
475 LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
476 parameters.is_enabled, parameters.applet_resource_user_id);
477
478 GetResourceManager()->EnableInput(parameters.applet_resource_user_id, parameters.is_enabled);
479 // GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
480
481 IPC::ResponseBuilder rb{ctx, 2};
482 rb.Push(ResultSuccess);
483}
484
485void IHidSystemServer::EnableAppletToGetSixAxisSensor(HLERequestContext& ctx) {
486 IPC::RequestParser rp{ctx};
487 struct Parameters {
488 bool is_enabled;
489 INSERT_PADDING_WORDS_NOINIT(1);
490 u64 applet_resource_user_id;
491 };
492 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
493
494 const auto parameters{rp.PopRaw<Parameters>()};
495
496 LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
497 parameters.is_enabled, parameters.applet_resource_user_id);
498
499 GetResourceManager()->EnableTouchScreen(parameters.applet_resource_user_id,
500 parameters.is_enabled);
501
502 IPC::ResponseBuilder rb{ctx, 2};
503 rb.Push(ResultSuccess);
504}
505
506void IHidSystemServer::EnableAppletToGetPadInput(HLERequestContext& ctx) {
507 IPC::RequestParser rp{ctx};
508 struct Parameters {
509 bool is_enabled;
510 INSERT_PADDING_WORDS_NOINIT(1);
511 u64 applet_resource_user_id;
512 };
513 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
514
515 const auto parameters{rp.PopRaw<Parameters>()};
516
517 LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
518 parameters.is_enabled, parameters.applet_resource_user_id);
519
520 GetResourceManager()->EnablePadInput(parameters.applet_resource_user_id, parameters.is_enabled);
521 // GetResourceManager()->GetNpad()->EnableInput(parameters.applet_resource_user_id);
522
523 IPC::ResponseBuilder rb{ctx, 2};
524 rb.Push(ResultSuccess);
525}
526
527void IHidSystemServer::EnableAppletToGetTouchScreen(HLERequestContext& ctx) {
528 IPC::RequestParser rp{ctx};
529 struct Parameters {
530 bool is_enabled;
531 INSERT_PADDING_WORDS_NOINIT(1);
532 u64 applet_resource_user_id;
533 };
534 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
535
536 const auto parameters{rp.PopRaw<Parameters>()};
537
538 LOG_INFO(Service_HID, "called, is_enabled={}, applet_resource_user_id={}",
539 parameters.is_enabled, parameters.applet_resource_user_id);
540
541 GetResourceManager()->EnableTouchScreen(parameters.applet_resource_user_id,
542 parameters.is_enabled);
543
544 IPC::ResponseBuilder rb{ctx, 2};
545 rb.Push(ResultSuccess);
546}
423 547
424void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) { 548void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) {
425 LOG_INFO(Service_AM, "(STUBBED) called"); 549 LOG_INFO(Service_AM, "(STUBBED) called");
diff --git a/src/core/hle/service/hid/hid_system_server.h b/src/core/hle/service/hid/hid_system_server.h
index 822d5e5b9..1e623dfc2 100644
--- a/src/core/hle/service/hid/hid_system_server.h
+++ b/src/core/hle/service/hid/hid_system_server.h
@@ -38,6 +38,12 @@ private:
38 void HasLeftRightBattery(HLERequestContext& ctx); 38 void HasLeftRightBattery(HLERequestContext& ctx);
39 void GetUniquePadsFromNpad(HLERequestContext& ctx); 39 void GetUniquePadsFromNpad(HLERequestContext& ctx);
40 void GetIrSensorState(HLERequestContext& ctx); 40 void GetIrSensorState(HLERequestContext& ctx);
41 void RegisterAppletResourceUserId(HLERequestContext& ctx);
42 void UnregisterAppletResourceUserId(HLERequestContext& ctx);
43 void EnableAppletToGetInput(HLERequestContext& ctx);
44 void EnableAppletToGetSixAxisSensor(HLERequestContext& ctx);
45 void EnableAppletToGetPadInput(HLERequestContext& ctx);
46 void EnableAppletToGetTouchScreen(HLERequestContext& ctx);
41 void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx); 47 void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx);
42 void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx); 48 void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx);
43 void GetRegisteredDevices(HLERequestContext& ctx); 49 void GetRegisteredDevices(HLERequestContext& ctx);
diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp
index e76d4eea9..60d4ef71f 100644
--- a/src/core/hle/service/hid/resource_manager.cpp
+++ b/src/core/hle/service/hid/resource_manager.cpp
@@ -9,6 +9,7 @@
9#include "core/hle/service/hid/resource_manager.h" 9#include "core/hle/service/hid/resource_manager.h"
10#include "core/hle/service/ipc_helpers.h" 10#include "core/hle/service/ipc_helpers.h"
11 11
12#include "core/hle/service/hid/controllers/applet_resource.h"
12#include "core/hle/service/hid/controllers/console_six_axis.h" 13#include "core/hle/service/hid/controllers/console_six_axis.h"
13#include "core/hle/service/hid/controllers/debug_pad.h" 14#include "core/hle/service/hid/controllers/debug_pad.h"
14#include "core/hle/service/hid/controllers/gesture.h" 15#include "core/hle/service/hid/controllers/gesture.h"
@@ -33,7 +34,9 @@ constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 10
33constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz) 34constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
34 35
35ResourceManager::ResourceManager(Core::System& system_) 36ResourceManager::ResourceManager(Core::System& system_)
36 : system{system_}, service_context{system_, "hid"} {} 37 : system{system_}, service_context{system_, "hid"} {
38 applet_resource = std::make_shared<AppletResource>(system);
39}
37 40
38ResourceManager::~ResourceManager() = default; 41ResourceManager::~ResourceManager() = default;
39 42
@@ -77,6 +80,11 @@ void ResourceManager::Initialize() {
77 system.HIDCore().ReloadInputDevices(); 80 system.HIDCore().ReloadInputDevices();
78 is_initialized = true; 81 is_initialized = true;
79} 82}
83
84std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const {
85 return applet_resource;
86}
87
80std::shared_ptr<CaptureButton> ResourceManager::GetCaptureButton() const { 88std::shared_ptr<CaptureButton> ResourceManager::GetCaptureButton() const {
81 return capture_button; 89 return capture_button;
82} 90}
@@ -137,6 +145,46 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const {
137 return unique_pad; 145 return unique_pad;
138} 146}
139 147
148Result ResourceManager::CreateAppletResource(u64 aruid) {
149 std::scoped_lock lock{shared_mutex};
150 return applet_resource->CreateAppletResource(aruid);
151}
152
153Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) {
154 std::scoped_lock lock{shared_mutex};
155 return applet_resource->RegisterAppletResourceUserId(aruid, bool_value);
156}
157
158void ResourceManager::UnregisterAppletResourceUserId(u64 aruid) {
159 std::scoped_lock lock{shared_mutex};
160 applet_resource->UnregisterAppletResourceUserId(aruid);
161}
162
163Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid) {
164 std::scoped_lock lock{shared_mutex};
165 return applet_resource->GetSharedMemoryHandle(out_handle, aruid);
166}
167
168void ResourceManager::EnableInput(u64 aruid, bool is_enabled) {
169 std::scoped_lock lock{shared_mutex};
170 applet_resource->EnableInput(aruid, is_enabled);
171}
172
173void ResourceManager::EnableSixAxisSensor(u64 aruid, bool is_enabled) {
174 std::scoped_lock lock{shared_mutex};
175 applet_resource->EnableSixAxisSensor(aruid, is_enabled);
176}
177
178void ResourceManager::EnablePadInput(u64 aruid, bool is_enabled) {
179 std::scoped_lock lock{shared_mutex};
180 applet_resource->EnablePadInput(aruid, is_enabled);
181}
182
183void ResourceManager::EnableTouchScreen(u64 aruid, bool is_enabled) {
184 std::scoped_lock lock{shared_mutex};
185 applet_resource->EnableTouchScreen(aruid, is_enabled);
186}
187
140void ResourceManager::UpdateControllers(std::uintptr_t user_data, 188void ResourceManager::UpdateControllers(std::uintptr_t user_data,
141 std::chrono::nanoseconds ns_late) { 189 std::chrono::nanoseconds ns_late) {
142 auto& core_timing = system.CoreTiming(); 190 auto& core_timing = system.CoreTiming();
@@ -172,14 +220,12 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
172} 220}
173 221
174IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource) 222IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource)
175 : ServiceFramework{system_, "IAppletResource"} { 223 : ServiceFramework{system_, "IAppletResource"}, resource_manager{resource} {
176 static const FunctionInfo functions[] = { 224 static const FunctionInfo functions[] = {
177 {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"}, 225 {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
178 }; 226 };
179 RegisterHandlers(functions); 227 RegisterHandlers(functions);
180 228
181 resource->Initialize();
182
183 // Register update callbacks 229 // Register update callbacks
184 npad_update_event = Core::Timing::CreateEvent( 230 npad_update_event = Core::Timing::CreateEvent(
185 "HID::UpdatePadCallback", 231 "HID::UpdatePadCallback",
@@ -233,9 +279,13 @@ IAppletResource::~IAppletResource() {
233void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { 279void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
234 LOG_DEBUG(Service_HID, "called"); 280 LOG_DEBUG(Service_HID, "called");
235 281
282 Kernel::KSharedMemory* handle;
283 const u64 applet_resource_user_id = resource_manager->GetAppletResource()->GetActiveAruid();
284 const auto result = resource_manager->GetSharedMemoryHandle(&handle, applet_resource_user_id);
285
236 IPC::ResponseBuilder rb{ctx, 2, 1}; 286 IPC::ResponseBuilder rb{ctx, 2, 1};
237 rb.Push(ResultSuccess); 287 rb.Push(result);
238 rb.PushCopyObjects(&system.Kernel().GetHidSharedMem()); 288 rb.PushCopyObjects(handle);
239} 289}
240 290
241} // namespace Service::HID 291} // namespace Service::HID
diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h
index 2b6a9b5e6..a78e2b729 100644
--- a/src/core/hle/service/hid/resource_manager.h
+++ b/src/core/hle/service/hid/resource_manager.h
@@ -6,11 +6,20 @@
6#include "core/hle/service/kernel_helpers.h" 6#include "core/hle/service/kernel_helpers.h"
7#include "core/hle/service/service.h" 7#include "core/hle/service/service.h"
8 8
9namespace Core {
10class System;
11}
12
9namespace Core::Timing { 13namespace Core::Timing {
10struct EventType; 14struct EventType;
11} 15}
12 16
17namespace Kernel {
18class KSharedMemory;
19}
20
13namespace Service::HID { 21namespace Service::HID {
22class AppletResource;
14class Controller_Stubbed; 23class Controller_Stubbed;
15class ConsoleSixAxis; 24class ConsoleSixAxis;
16class DebugPad; 25class DebugPad;
@@ -38,6 +47,7 @@ public:
38 47
39 void Initialize(); 48 void Initialize();
40 49
50 std::shared_ptr<AppletResource> GetAppletResource() const;
41 std::shared_ptr<CaptureButton> GetCaptureButton() const; 51 std::shared_ptr<CaptureButton> GetCaptureButton() const;
42 std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const; 52 std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
43 std::shared_ptr<DebugMouse> GetDebugMouse() const; 53 std::shared_ptr<DebugMouse> GetDebugMouse() const;
@@ -54,6 +64,18 @@ public:
54 std::shared_ptr<TouchScreen> GetTouchScreen() const; 64 std::shared_ptr<TouchScreen> GetTouchScreen() const;
55 std::shared_ptr<UniquePad> GetUniquePad() const; 65 std::shared_ptr<UniquePad> GetUniquePad() const;
56 66
67 Result CreateAppletResource(u64 aruid);
68
69 Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
70 void UnregisterAppletResourceUserId(u64 aruid);
71
72 Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
73
74 void EnableInput(u64 aruid, bool is_enabled);
75 void EnableSixAxisSensor(u64 aruid, bool is_enabled);
76 void EnablePadInput(u64 aruid, bool is_enabled);
77 void EnableTouchScreen(u64 aruid, bool is_enabled);
78
57 void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); 79 void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
58 void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); 80 void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
59 void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); 81 void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
@@ -62,6 +84,9 @@ public:
62private: 84private:
63 bool is_initialized{false}; 85 bool is_initialized{false};
64 86
87 mutable std::mutex shared_mutex;
88 std::shared_ptr<AppletResource> applet_resource = nullptr;
89
65 std::shared_ptr<CaptureButton> capture_button = nullptr; 90 std::shared_ptr<CaptureButton> capture_button = nullptr;
66 std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr; 91 std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
67 std::shared_ptr<DebugMouse> debug_mouse = nullptr; 92 std::shared_ptr<DebugMouse> debug_mouse = nullptr;
@@ -106,6 +131,8 @@ private:
106 std::shared_ptr<Core::Timing::EventType> default_update_event; 131 std::shared_ptr<Core::Timing::EventType> default_update_event;
107 std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event; 132 std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
108 std::shared_ptr<Core::Timing::EventType> motion_update_event; 133 std::shared_ptr<Core::Timing::EventType> motion_update_event;
134
135 std::shared_ptr<ResourceManager> resource_manager;
109}; 136};
110 137
111} // namespace Service::HID 138} // namespace Service::HID