diff options
author | german77 <juangerman-13@hotmail.com> | 2021-09-21 03:25:22 +0200 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2021-11-25 03:30:23 +0100 |
commit | db08721dccdec9330b883324e2a99d784c2405fd (patch) | |
tree | c6f2117585caeebccd80aeaa883b8d5995039fa4 /src/core | |
parent | Qt_applets: Use new input (diff) | |
download | yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.gz yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.bz2 yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.lz yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.xz yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.zst yuzu-db08721dccdec9330b883324e2a99d784c2405fd.zip |
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/core/hle/service/hid/ring_lifo.h | 54 |
2 files changed, 55 insertions, 1 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 09163fab9..582c15f7e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -132,7 +132,6 @@ add_library(core STATIC frontend/emu_window.h frontend/framebuffer_layout.cpp frontend/framebuffer_layout.h - frontend/input.h hardware_interrupt_manager.cpp hardware_interrupt_manager.h hid/emulated_console.cpp @@ -415,6 +414,7 @@ add_library(core STATIC hle/service/hid/hid.h hle/service/hid/irs.cpp hle/service/hid/irs.h + hle/service/hid/ring_lifo.h hle/service/hid/xcd.cpp hle/service/hid/xcd.h hle/service/hid/errors.h diff --git a/src/core/hle/service/hid/ring_lifo.h b/src/core/hle/service/hid/ring_lifo.h new file mode 100644 index 000000000..1cc2a194f --- /dev/null +++ b/src/core/hle/service/hid/ring_lifo.h @@ -0,0 +1,54 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included + +#pragma once + +#include "common/common_types.h" +#include "common/swap.h" + +namespace Service::HID { +constexpr std::size_t max_entry_size = 17; + +template <typename State> +struct AtomicStorage { + s64_le sampling_number; + State state; +}; + +template <typename State> +struct Lifo { + s64_le timestamp{}; + s64_le total_entry_count = max_entry_size; + s64_le last_entry_index{}; + s64_le entry_count{}; + std::array<AtomicStorage<State>, max_entry_size> entries{}; + + const AtomicStorage<State>& ReadCurrentEntry() const { + return entries[last_entry_index]; + } + + const AtomicStorage<State>& ReadPreviousEntry() const { + return entries[GetPreviuousEntryIndex()]; + } + + std::size_t GetPreviuousEntryIndex() const { + return (last_entry_index + total_entry_count - 1) % total_entry_count; + } + + std::size_t GetNextEntryIndex() const { + return (last_entry_index + 1) % total_entry_count; + } + + void WriteNextEntry(const State& new_state) { + if (entry_count < total_entry_count - 1) { + entry_count++; + } + last_entry_index = GetNextEntryIndex(); + const auto& previous_entry = ReadPreviousEntry(); + entries[last_entry_index].sampling_number = previous_entry.sampling_number + 1; + entries[last_entry_index].state = new_state; + } +}; + +} // namespace Service::HID |