2018-10-05 16:23:21 +02:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-10-06 05:14:42 +02:00
|
|
|
#include <cstring>
|
2018-10-05 16:23:21 +02:00
|
|
|
#include "common/common_types.h"
|
2021-04-15 01:07:40 +02:00
|
|
|
#include "common/settings.h"
|
2021-09-21 03:31:06 +02:00
|
|
|
#include "core/core.h"
|
2018-10-05 16:23:21 +02:00
|
|
|
#include "core/core_timing.h"
|
2021-09-21 03:31:06 +02:00
|
|
|
#include "core/hid/hid_core.h"
|
|
|
|
#include "core/hid/hid_types.h"
|
2018-10-05 16:23:21 +02:00
|
|
|
#include "core/hle/service/hid/controllers/debug_pad.h"
|
|
|
|
|
|
|
|
namespace Service::HID {
|
2018-10-06 05:14:42 +02:00
|
|
|
|
2018-11-02 03:01:11 +01:00
|
|
|
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
|
2019-10-05 00:57:50 +02:00
|
|
|
[[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff;
|
2018-11-02 03:01:11 +01:00
|
|
|
enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
|
|
|
|
|
2021-09-21 03:31:06 +02:00
|
|
|
Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} {
|
|
|
|
controller = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Other);
|
|
|
|
}
|
|
|
|
|
2018-10-18 02:34:25 +02:00
|
|
|
Controller_DebugPad::~Controller_DebugPad() = default;
|
2018-10-06 05:14:42 +02:00
|
|
|
|
2019-09-22 08:41:34 +02:00
|
|
|
void Controller_DebugPad::OnInit() {}
|
2018-10-06 05:14:42 +02:00
|
|
|
|
2018-10-05 16:23:21 +02:00
|
|
|
void Controller_DebugPad::OnRelease() {}
|
2018-10-06 05:14:42 +02:00
|
|
|
|
2019-02-14 18:42:58 +01:00
|
|
|
void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
|
|
|
|
std::size_t size) {
|
2018-10-05 16:23:21 +02:00
|
|
|
if (!IsControllerActivated()) {
|
2021-09-21 03:31:06 +02:00
|
|
|
debug_pad_lifo.entry_count = 0;
|
|
|
|
debug_pad_lifo.last_entry_index = 0;
|
|
|
|
std::memcpy(data, &debug_pad_lifo, sizeof(debug_pad_lifo));
|
2018-10-05 16:23:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-21 03:31:06 +02:00
|
|
|
const auto& last_entry = debug_pad_lifo.ReadCurrentEntry().state;
|
|
|
|
next_state.sampling_number = last_entry.sampling_number + 1;
|
2018-10-18 13:01:55 +02:00
|
|
|
|
2020-07-16 14:28:49 +02:00
|
|
|
if (Settings::values.debug_pad_enabled) {
|
2021-09-21 03:31:06 +02:00
|
|
|
next_state.attribute.connected.Assign(1);
|
2018-10-18 13:01:55 +02:00
|
|
|
|
2021-09-21 03:31:06 +02:00
|
|
|
const auto& button_state = controller->GetDebugPadButtons();
|
|
|
|
const auto& stick_state = controller->GetSticks();
|
2020-07-16 14:28:49 +02:00
|
|
|
|
2021-09-21 03:31:06 +02:00
|
|
|
next_state.pad_state = button_state;
|
|
|
|
next_state.l_stick = stick_state.left;
|
|
|
|
next_state.r_stick = stick_state.right;
|
2020-07-16 14:28:49 +02:00
|
|
|
}
|
2018-10-05 16:23:21 +02:00
|
|
|
|
2021-09-21 03:31:06 +02:00
|
|
|
debug_pad_lifo.WriteNextEntry(next_state);
|
|
|
|
std::memcpy(data, &debug_pad_lifo, sizeof(debug_pad_lifo));
|
2018-10-05 16:23:21 +02:00
|
|
|
}
|
2018-10-06 05:14:42 +02:00
|
|
|
|
|
|
|
} // namespace Service::HID
|