From 3ac4f3a2521e421a625fe1d7dcba05b8441fe056 Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 19 Jun 2022 15:54:21 -0500 Subject: service: irs: Implement clustering processor --- src/core/hle/service/hid/irs_ring_lifo.h | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/core/hle/service/hid/irs_ring_lifo.h (limited to 'src/core/hle/service/hid/irs_ring_lifo.h') diff --git a/src/core/hle/service/hid/irs_ring_lifo.h b/src/core/hle/service/hid/irs_ring_lifo.h new file mode 100644 index 000000000..a31e61037 --- /dev/null +++ b/src/core/hle/service/hid/irs_ring_lifo.h @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include + +#include "common/common_types.h" + +namespace Service::IRS { + +template +struct Lifo { + s64 sampling_number{}; + s64 buffer_count{}; + std::array entries{}; + + const State& ReadCurrentEntry() const { + return entries[GetBufferTail()]; + } + + const State& ReadPreviousEntry() const { + return entries[GetPreviousEntryIndex()]; + } + + s64 GetBufferTail() const { + return sampling_number % max_buffer_size; + } + + std::size_t GetPreviousEntryIndex() const { + return static_cast((GetBufferTail() + max_buffer_size - 1) % max_buffer_size); + } + + std::size_t GetNextEntryIndex() const { + return static_cast((GetBufferTail() + 1) % max_buffer_size); + } + + void WriteNextEntry(const State& new_state) { + if (buffer_count < max_buffer_size) { + buffer_count++; + } + sampling_number++; + entries[GetBufferTail()] = new_state; + } +}; + +} // namespace Service::IRS -- cgit v1.2.3