summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
authorGravatar german772021-09-20 20:25:22 -0500
committerGravatar Narr the Reg2021-11-24 20:30:23 -0600
commitdb08721dccdec9330b883324e2a99d784c2405fd (patch)
treec6f2117585caeebccd80aeaa883b8d5995039fa4 /src/core/hle
parentQt_applets: Use new input (diff)
downloadyuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.gz
yuzu-db08721dccdec9330b883324e2a99d784c2405fd.tar.xz
yuzu-db08721dccdec9330b883324e2a99d784c2405fd.zip
service/hid: Create ring LIFO
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/service/hid/ring_lifo.h54
1 files changed, 54 insertions, 0 deletions
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 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included
4
5#pragma once
6
7#include "common/common_types.h"
8#include "common/swap.h"
9
10namespace Service::HID {
11constexpr std::size_t max_entry_size = 17;
12
13template <typename State>
14struct AtomicStorage {
15 s64_le sampling_number;
16 State state;
17};
18
19template <typename State>
20struct Lifo {
21 s64_le timestamp{};
22 s64_le total_entry_count = max_entry_size;
23 s64_le last_entry_index{};
24 s64_le entry_count{};
25 std::array<AtomicStorage<State>, max_entry_size> entries{};
26
27 const AtomicStorage<State>& ReadCurrentEntry() const {
28 return entries[last_entry_index];
29 }
30
31 const AtomicStorage<State>& ReadPreviousEntry() const {
32 return entries[GetPreviuousEntryIndex()];
33 }
34
35 std::size_t GetPreviuousEntryIndex() const {
36 return (last_entry_index + total_entry_count - 1) % total_entry_count;
37 }
38
39 std::size_t GetNextEntryIndex() const {
40 return (last_entry_index + 1) % total_entry_count;
41 }
42
43 void WriteNextEntry(const State& new_state) {
44 if (entry_count < total_entry_count - 1) {
45 entry_count++;
46 }
47 last_entry_index = GetNextEntryIndex();
48 const auto& previous_entry = ReadPreviousEntry();
49 entries[last_entry_index].sampling_number = previous_entry.sampling_number + 1;
50 entries[last_entry_index].state = new_state;
51 }
52};
53
54} // namespace Service::HID