summaryrefslogtreecommitdiffstats
path: root/src/hid_core/resources/debug_pad
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2024-01-05 03:37:43 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2024-01-05 18:41:15 +0100
commitee847f8ff0b1b0aec39c1b78c010bc0c08a0a613 (patch)
tree3b95cbb74be05f0ce7a007353f1f9f95e1ed3901 /src/hid_core/resources/debug_pad
parentMerge pull request #12437 from ameerj/gl-amd-fixes (diff)
downloadyuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.gz
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.bz2
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.lz
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.xz
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.zst
yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.zip
Diffstat (limited to 'src/hid_core/resources/debug_pad')
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad.cpp59
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad.h37
-rw-r--r--src/hid_core/resources/debug_pad/debug_pad_types.h31
3 files changed, 127 insertions, 0 deletions
diff --git a/src/hid_core/resources/debug_pad/debug_pad.cpp b/src/hid_core/resources/debug_pad/debug_pad.cpp
new file mode 100644
index 000000000..1102dad6c
--- /dev/null
+++ b/src/hid_core/resources/debug_pad/debug_pad.cpp
@@ -0,0 +1,59 @@
+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "common/settings.h"
+#include "core/core_timing.h"
+#include "hid_core/frontend/emulated_controller.h"
+#include "hid_core/hid_core.h"
+#include "hid_core/hid_types.h"
+#include "hid_core/resources/applet_resource.h"
+#include "hid_core/resources/debug_pad/debug_pad.h"
+#include "hid_core/resources/shared_memory_format.h"
+
+namespace Service::HID {
+
+DebugPad::DebugPad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
+ controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
+}
+
+DebugPad::~DebugPad() = default;
+
+void DebugPad::OnInit() {}
+
+void DebugPad::OnRelease() {}
+
+void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
+ std::scoped_lock shared_lock{*shared_mutex};
+ const u64 aruid = applet_resource->GetActiveAruid();
+ auto* data = applet_resource->GetAruidData(aruid);
+
+ if (data == nullptr || !data->flag.is_assigned) {
+ return;
+ }
+
+ DebugPadSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_pad;
+
+ if (!IsControllerActivated()) {
+ shared_memory.debug_pad_lifo.buffer_count = 0;
+ shared_memory.debug_pad_lifo.buffer_tail = 0;
+ return;
+ }
+
+ const auto& last_entry = shared_memory.debug_pad_lifo.ReadCurrentEntry().state;
+ next_state.sampling_number = last_entry.sampling_number + 1;
+
+ if (Settings::values.debug_pad_enabled) {
+ next_state.attribute.connected.Assign(1);
+
+ const auto& button_state = controller->GetDebugPadButtons();
+ const auto& stick_state = controller->GetSticks();
+
+ next_state.pad_state = button_state;
+ next_state.l_stick = stick_state.left;
+ next_state.r_stick = stick_state.right;
+ }
+
+ shared_memory.debug_pad_lifo.WriteNextEntry(next_state);
+}
+
+} // namespace Service::HID
diff --git a/src/hid_core/resources/debug_pad/debug_pad.h b/src/hid_core/resources/debug_pad/debug_pad.h
new file mode 100644
index 000000000..73c3d4421
--- /dev/null
+++ b/src/hid_core/resources/debug_pad/debug_pad.h
@@ -0,0 +1,37 @@
+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "hid_core/resources/controller_base.h"
+#include "hid_core/resources/debug_pad/debug_pad_types.h"
+
+namespace Core::HID {
+class HIDCore;
+class EmulatedController;
+} // namespace Core::HID
+
+namespace Core::Timing {
+class CoreTiming;
+}
+
+namespace Service::HID {
+class DebugPad final : public ControllerBase {
+public:
+ explicit DebugPad(Core::HID::HIDCore& hid_core_);
+ ~DebugPad() override;
+
+ // Called when the controller is initialized
+ void OnInit() override;
+
+ // When the controller is released
+ void OnRelease() override;
+
+ // When the controller is requesting an update for the shared memory
+ void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
+
+private:
+ DebugPadState next_state{};
+ Core::HID::EmulatedController* controller = nullptr;
+};
+} // namespace Service::HID
diff --git a/src/hid_core/resources/debug_pad/debug_pad_types.h b/src/hid_core/resources/debug_pad/debug_pad_types.h
new file mode 100644
index 000000000..8b5eb108e
--- /dev/null
+++ b/src/hid_core/resources/debug_pad/debug_pad_types.h
@@ -0,0 +1,31 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include "common/bit_field.h"
+#include "common/common_types.h"
+#include "hid_core/hid_types.h"
+
+namespace Service::HID {
+
+// This is nn::hid::DebugPadAttribute
+struct DebugPadAttribute {
+ union {
+ u32 raw{};
+ BitField<0, 1, u32> connected;
+ };
+};
+static_assert(sizeof(DebugPadAttribute) == 0x4, "DebugPadAttribute is an invalid size");
+
+// This is nn::hid::DebugPadState
+struct DebugPadState {
+ s64 sampling_number{};
+ DebugPadAttribute attribute{};
+ Core::HID::DebugPadButton pad_state{};
+ Core::HID::AnalogStickState r_stick{};
+ Core::HID::AnalogStickState l_stick{};
+};
+static_assert(sizeof(DebugPadState) == 0x20, "DebugPadState is an invalid state");
+
+} // namespace Service::HID