xpad.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include "common/common_types.h"
  6. #include "core/core_timing.h"
  7. #include "core/hle/service/hid/controllers/xpad.h"
  8. namespace Service::HID {
  9. constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00;
  10. Controller_XPad::Controller_XPad(Core::System& system_) : ControllerBase{system_} {}
  11. Controller_XPad::~Controller_XPad() = default;
  12. void Controller_XPad::OnInit() {}
  13. void Controller_XPad::OnRelease() {}
  14. void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
  15. std::size_t size) {
  16. for (auto& xpad_entry : shared_memory.shared_memory_entries) {
  17. xpad_entry.header.timestamp = core_timing.GetCPUTicks();
  18. xpad_entry.header.total_entry_count = 17;
  19. if (!IsControllerActivated()) {
  20. xpad_entry.header.entry_count = 0;
  21. xpad_entry.header.last_entry_index = 0;
  22. return;
  23. }
  24. xpad_entry.header.entry_count = 16;
  25. const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index];
  26. xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17;
  27. auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index];
  28. cur_entry.sampling_number = last_entry.sampling_number + 1;
  29. cur_entry.sampling_number2 = cur_entry.sampling_number;
  30. }
  31. // TODO(ogniK): Update xpad states
  32. std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
  33. }
  34. void Controller_XPad::OnLoadInputDevices() {}
  35. } // namespace Service::HID