summaryrefslogtreecommitdiff
path: root/src/core
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
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')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/hle/service/hid/ring_lifo.h54
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
132 frontend/emu_window.h 132 frontend/emu_window.h
133 frontend/framebuffer_layout.cpp 133 frontend/framebuffer_layout.cpp
134 frontend/framebuffer_layout.h 134 frontend/framebuffer_layout.h
135 frontend/input.h
136 hardware_interrupt_manager.cpp 135 hardware_interrupt_manager.cpp
137 hardware_interrupt_manager.h 136 hardware_interrupt_manager.h
138 hid/emulated_console.cpp 137 hid/emulated_console.cpp
@@ -415,6 +414,7 @@ add_library(core STATIC
415 hle/service/hid/hid.h 414 hle/service/hid/hid.h
416 hle/service/hid/irs.cpp 415 hle/service/hid/irs.cpp
417 hle/service/hid/irs.h 416 hle/service/hid/irs.h
417 hle/service/hid/ring_lifo.h
418 hle/service/hid/xcd.cpp 418 hle/service/hid/xcd.cpp
419 hle/service/hid/xcd.h 419 hle/service/hid/xcd.h
420 hle/service/hid/errors.h 420 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 @@
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