summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar Feng Chen2021-12-18 13:57:14 +0800
committerGravatar GitHub2021-12-18 13:57:14 +0800
commite49184e6069a9d791d2df3c1958f5c4b1187e124 (patch)
treeb776caf722e0be0e680f67b0ad0842628162ef1c /src/common
parentImplement convert legacy to generic (diff)
parentMerge pull request #7570 from ameerj/favorites-expanded (diff)
downloadyuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/bit_util.h7
-rw-r--r--src/common/host_memory.cpp4
-rw-r--r--src/common/input.h366
-rw-r--r--src/common/logging/filter.cpp1
-rw-r--r--src/common/logging/types.h1
-rw-r--r--src/common/settings.cpp1
-rw-r--r--src/common/settings.h15
-rw-r--r--src/common/settings_input.h70
-rw-r--r--src/common/x64/cpu_detect.cpp12
-rw-r--r--src/common/x64/native_clock.cpp36
11 files changed, 453 insertions, 61 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 23d43a394..919da4a53 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -73,6 +73,7 @@ add_library(common STATIC
73 hex_util.h 73 hex_util.h
74 host_memory.cpp 74 host_memory.cpp
75 host_memory.h 75 host_memory.h
76 input.h
76 intrusive_red_black_tree.h 77 intrusive_red_black_tree.h
77 literals.h 78 literals.h
78 logging/backend.cpp 79 logging/backend.cpp
diff --git a/src/common/bit_util.h b/src/common/bit_util.h
index 64520ca4e..eef8c1c5a 100644
--- a/src/common/bit_util.h
+++ b/src/common/bit_util.h
@@ -7,6 +7,7 @@
7#include <bit> 7#include <bit>
8#include <climits> 8#include <climits>
9#include <cstddef> 9#include <cstddef>
10#include <type_traits>
10 11
11#include "common/common_types.h" 12#include "common/common_types.h"
12 13
@@ -44,4 +45,10 @@ template <typename T>
44 return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); 45 return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL));
45} 46}
46 47
48template <typename T>
49requires std::is_integral_v<T>
50[[nodiscard]] T NextPow2(T value) {
51 return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U)));
52}
53
47} // namespace Common 54} // namespace Common
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index b44a44949..28949fe5e 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -1,3 +1,7 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
1#ifdef _WIN32 5#ifdef _WIN32
2 6
3#include <iterator> 7#include <iterator>
diff --git a/src/common/input.h b/src/common/input.h
new file mode 100644
index 000000000..f775a4c01
--- /dev/null
+++ b/src/common/input.h
@@ -0,0 +1,366 @@
1// Copyright 2017 Citra 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 <functional>
8#include <memory>
9#include <string>
10#include <unordered_map>
11#include <utility>
12#include "common/logging/log.h"
13#include "common/param_package.h"
14#include "common/uuid.h"
15
16namespace Common::Input {
17
18// Type of data that is expected to recieve or send
19enum class InputType {
20 None,
21 Battery,
22 Button,
23 Stick,
24 Analog,
25 Trigger,
26 Motion,
27 Touch,
28 Color,
29 Vibration,
30 Nfc,
31 Ir,
32};
33
34// Internal battery charge level
35enum class BatteryLevel : u32 {
36 None,
37 Empty,
38 Critical,
39 Low,
40 Medium,
41 Full,
42 Charging,
43};
44
45enum class PollingMode {
46 // Constant polling of buttons, analogs and motion data
47 Active,
48 // Only update on button change, digital analogs
49 Pasive,
50 // Enable near field communication polling
51 NFC,
52 // Enable infrared camera polling
53 IR,
54};
55
56// Vibration reply from the controller
57enum class VibrationError {
58 None,
59 NotSupported,
60 Disabled,
61 Unknown,
62};
63
64// Polling mode reply from the controller
65enum class PollingError {
66 None,
67 NotSupported,
68 Unknown,
69};
70
71// Hint for amplification curve to be used
72enum class VibrationAmplificationType {
73 Linear,
74 Exponential,
75};
76
77// Analog properties for calibration
78struct AnalogProperties {
79 // Anything below this value will be detected as zero
80 float deadzone{};
81 // Anyting above this values will be detected as one
82 float range{1.0f};
83 // Minimum value to be detected as active
84 float threshold{0.5f};
85 // Drift correction applied to the raw data
86 float offset{};
87 // Invert direction of the sensor data
88 bool inverted{};
89};
90
91// Single analog sensor data
92struct AnalogStatus {
93 float value{};
94 float raw_value{};
95 AnalogProperties properties{};
96};
97
98// Button data
99struct ButtonStatus {
100 Common::UUID uuid{};
101 bool value{};
102 bool inverted{};
103 bool toggle{};
104 bool locked{};
105};
106
107// Internal battery data
108using BatteryStatus = BatteryLevel;
109
110// Analog and digital joystick data
111struct StickStatus {
112 Common::UUID uuid{};
113 AnalogStatus x{};
114 AnalogStatus y{};
115 bool left{};
116 bool right{};
117 bool up{};
118 bool down{};
119};
120
121// Analog and digital trigger data
122struct TriggerStatus {
123 Common::UUID uuid{};
124 AnalogStatus analog{};
125 ButtonStatus pressed{};
126};
127
128// 3D vector representing motion input
129struct MotionSensor {
130 AnalogStatus x{};
131 AnalogStatus y{};
132 AnalogStatus z{};
133};
134
135// Motion data used to calculate controller orientation
136struct MotionStatus {
137 // Gyroscope vector measurement in radians/s.
138 MotionSensor gyro{};
139 // Acceleration vector measurement in G force
140 MotionSensor accel{};
141 // Time since last measurement in microseconds
142 u64 delta_timestamp{};
143 // Request to update after reading the value
144 bool force_update{};
145};
146
147// Data of a single point on a touch screen
148struct TouchStatus {
149 ButtonStatus pressed{};
150 AnalogStatus x{};
151 AnalogStatus y{};
152 int id{};
153};
154
155// Physical controller color in RGB format
156struct BodyColorStatus {
157 u32 body{};
158 u32 buttons{};
159};
160
161// HD rumble data
162struct VibrationStatus {
163 f32 low_amplitude{};
164 f32 low_frequency{};
165 f32 high_amplitude{};
166 f32 high_frequency{};
167 VibrationAmplificationType type;
168};
169
170// Physical controller LED pattern
171struct LedStatus {
172 bool led_1{};
173 bool led_2{};
174 bool led_3{};
175 bool led_4{};
176};
177
178// List of buttons to be passed to Qt that can be translated
179enum class ButtonNames {
180 Undefined,
181 Invalid,
182 // This will display the engine name instead of the button name
183 Engine,
184 // This will display the button by value instead of the button name
185 Value,
186 ButtonLeft,
187 ButtonRight,
188 ButtonDown,
189 ButtonUp,
190 TriggerZ,
191 TriggerR,
192 TriggerL,
193 ButtonA,
194 ButtonB,
195 ButtonX,
196 ButtonY,
197 ButtonStart,
198
199 // DS4 button names
200 L1,
201 L2,
202 L3,
203 R1,
204 R2,
205 R3,
206 Circle,
207 Cross,
208 Square,
209 Triangle,
210 Share,
211 Options,
212};
213
214// Callback data consisting of an input type and the equivalent data status
215struct CallbackStatus {
216 InputType type{InputType::None};
217 ButtonStatus button_status{};
218 StickStatus stick_status{};
219 AnalogStatus analog_status{};
220 TriggerStatus trigger_status{};
221 MotionStatus motion_status{};
222 TouchStatus touch_status{};
223 BodyColorStatus color_status{};
224 BatteryStatus battery_status{};
225 VibrationStatus vibration_status{};
226};
227
228// Triggered once every input change
229struct InputCallback {
230 std::function<void(const CallbackStatus&)> on_change;
231};
232
233/// An abstract class template for an input device (a button, an analog input, etc.).
234class InputDevice {
235public:
236 virtual ~InputDevice() = default;
237
238 // Request input device to update if necessary
239 virtual void SoftUpdate() {}
240
241 // Force input device to update data regardless of the current state
242 virtual void ForceUpdate() {}
243
244 // Sets the function to be triggered when input changes
245 void SetCallback(InputCallback callback_) {
246 callback = std::move(callback_);
247 }
248
249 // Triggers the function set in the callback
250 void TriggerOnChange(const CallbackStatus& status) {
251 if (callback.on_change) {
252 callback.on_change(status);
253 }
254 }
255
256private:
257 InputCallback callback;
258};
259
260/// An abstract class template for an output device (rumble, LED pattern, polling mode).
261class OutputDevice {
262public:
263 virtual ~OutputDevice() = default;
264
265 virtual void SetLED([[maybe_unused]] const LedStatus& led_status) {}
266
267 virtual VibrationError SetVibration([[maybe_unused]] const VibrationStatus& vibration_status) {
268 return VibrationError::NotSupported;
269 }
270
271 virtual PollingError SetPollingMode([[maybe_unused]] PollingMode polling_mode) {
272 return PollingError::NotSupported;
273 }
274};
275
276/// An abstract class template for a factory that can create input devices.
277template <typename InputDeviceType>
278class Factory {
279public:
280 virtual ~Factory() = default;
281 virtual std::unique_ptr<InputDeviceType> Create(const Common::ParamPackage&) = 0;
282};
283
284namespace Impl {
285
286template <typename InputDeviceType>
287using FactoryListType = std::unordered_map<std::string, std::shared_ptr<Factory<InputDeviceType>>>;
288
289template <typename InputDeviceType>
290struct FactoryList {
291 static FactoryListType<InputDeviceType> list;
292};
293
294template <typename InputDeviceType>
295FactoryListType<InputDeviceType> FactoryList<InputDeviceType>::list;
296
297} // namespace Impl
298
299/**
300 * Registers an input device factory.
301 * @tparam InputDeviceType the type of input devices the factory can create
302 * @param name the name of the factory. Will be used to match the "engine" parameter when creating
303 * a device
304 * @param factory the factory object to register
305 */
306template <typename InputDeviceType>
307void RegisterFactory(const std::string& name, std::shared_ptr<Factory<InputDeviceType>> factory) {
308 auto pair = std::make_pair(name, std::move(factory));
309 if (!Impl::FactoryList<InputDeviceType>::list.insert(std::move(pair)).second) {
310 LOG_ERROR(Input, "Factory '{}' already registered", name);
311 }
312}
313
314/**
315 * Unregisters an input device factory.
316 * @tparam InputDeviceType the type of input devices the factory can create
317 * @param name the name of the factory to unregister
318 */
319template <typename InputDeviceType>
320void UnregisterFactory(const std::string& name) {
321 if (Impl::FactoryList<InputDeviceType>::list.erase(name) == 0) {
322 LOG_ERROR(Input, "Factory '{}' not registered", name);
323 }
324}
325
326/**
327 * Create an input device from given paramters.
328 * @tparam InputDeviceType the type of input devices to create
329 * @param params a serialized ParamPackage string that contains all parameters for creating the
330 * device
331 */
332template <typename InputDeviceType>
333std::unique_ptr<InputDeviceType> CreateDeviceFromString(const std::string& params) {
334 const Common::ParamPackage package(params);
335 const std::string engine = package.Get("engine", "null");
336 const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
337 const auto pair = factory_list.find(engine);
338 if (pair == factory_list.end()) {
339 if (engine != "null") {
340 LOG_ERROR(Input, "Unknown engine name: {}", engine);
341 }
342 return std::make_unique<InputDeviceType>();
343 }
344 return pair->second->Create(package);
345}
346
347/**
348 * Create an input device from given paramters.
349 * @tparam InputDeviceType the type of input devices to create
350 * @param A ParamPackage that contains all parameters for creating the device
351 */
352template <typename InputDeviceType>
353std::unique_ptr<InputDeviceType> CreateDevice(const Common::ParamPackage package) {
354 const std::string engine = package.Get("engine", "null");
355 const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
356 const auto pair = factory_list.find(engine);
357 if (pair == factory_list.end()) {
358 if (engine != "null") {
359 LOG_ERROR(Input, "Unknown engine name: {}", engine);
360 }
361 return std::make_unique<InputDeviceType>();
362 }
363 return pair->second->Create(package);
364}
365
366} // namespace Common::Input
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index 42744c994..b898a652c 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -114,6 +114,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
114 SUB(Service, NGCT) \ 114 SUB(Service, NGCT) \
115 SUB(Service, NIFM) \ 115 SUB(Service, NIFM) \
116 SUB(Service, NIM) \ 116 SUB(Service, NIM) \
117 SUB(Service, NOTIF) \
117 SUB(Service, NPNS) \ 118 SUB(Service, NPNS) \
118 SUB(Service, NS) \ 119 SUB(Service, NS) \
119 SUB(Service, NVDRV) \ 120 SUB(Service, NVDRV) \
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index 2d21fc483..9ed0c7ad6 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -82,6 +82,7 @@ enum class Class : u8 {
82 Service_NGCT, ///< The NGCT (No Good Content for Terra) service 82 Service_NGCT, ///< The NGCT (No Good Content for Terra) service
83 Service_NIFM, ///< The NIFM (Network interface) service 83 Service_NIFM, ///< The NIFM (Network interface) service
84 Service_NIM, ///< The NIM service 84 Service_NIM, ///< The NIM service
85 Service_NOTIF, ///< The NOTIF (Notification) service
85 Service_NPNS, ///< The NPNS service 86 Service_NPNS, ///< The NPNS service
86 Service_NS, ///< The NS services 87 Service_NS, ///< The NS services
87 Service_NVDRV, ///< The NVDRV (Nvidia driver) service 88 Service_NVDRV, ///< The NVDRV (Nvidia driver) service
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 3bcaa072f..6964a8273 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -183,6 +183,7 @@ void RestoreGlobalState(bool is_powered_on) {
183 values.max_anisotropy.SetGlobal(true); 183 values.max_anisotropy.SetGlobal(true);
184 values.use_speed_limit.SetGlobal(true); 184 values.use_speed_limit.SetGlobal(true);
185 values.speed_limit.SetGlobal(true); 185 values.speed_limit.SetGlobal(true);
186 values.fps_cap.SetGlobal(true);
186 values.use_disk_shader_cache.SetGlobal(true); 187 values.use_disk_shader_cache.SetGlobal(true);
187 values.gpu_accuracy.SetGlobal(true); 188 values.gpu_accuracy.SetGlobal(true);
188 values.use_asynchronous_gpu_emulation.SetGlobal(true); 189 values.use_asynchronous_gpu_emulation.SetGlobal(true);
diff --git a/src/common/settings.h b/src/common/settings.h
index 42f8b4a7d..313f1fa7f 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -6,7 +6,6 @@
6 6
7#include <algorithm> 7#include <algorithm>
8#include <array> 8#include <array>
9#include <atomic>
10#include <map> 9#include <map>
11#include <optional> 10#include <optional>
12#include <string> 11#include <string>
@@ -525,7 +524,7 @@ struct Values {
525 Setting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; 524 Setting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"};
526 Setting<bool> accelerate_astc{true, "accelerate_astc"}; 525 Setting<bool> accelerate_astc{true, "accelerate_astc"};
527 Setting<bool> use_vsync{true, "use_vsync"}; 526 Setting<bool> use_vsync{true, "use_vsync"};
528 BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; 527 RangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"};
529 BasicSetting<bool> disable_fps_limit{false, "disable_fps_limit"}; 528 BasicSetting<bool> disable_fps_limit{false, "disable_fps_limit"};
530 RangedSetting<ShaderBackend> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL, 529 RangedSetting<ShaderBackend> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL,
531 ShaderBackend::SPIRV, "shader_backend"}; 530 ShaderBackend::SPIRV, "shader_backend"};
@@ -560,25 +559,19 @@ struct Values {
560 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"}; 559 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
561 560
562 Setting<bool> motion_enabled{true, "motion_enabled"}; 561 Setting<bool> motion_enabled{true, "motion_enabled"};
563 BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01",
564 "motion_device"};
565 BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"}; 562 BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"};
563 BasicSetting<bool> enable_udp_controller{false, "enable_udp_controller"};
566 564
567 BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"}; 565 BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"};
568 BasicSetting<bool> tas_enable{false, "tas_enable"}; 566 BasicSetting<bool> tas_enable{false, "tas_enable"};
569 BasicSetting<bool> tas_loop{false, "tas_loop"}; 567 BasicSetting<bool> tas_loop{false, "tas_loop"};
570 BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"};
571 568
572 BasicSetting<bool> mouse_panning{false, "mouse_panning"}; 569 BasicSetting<bool> mouse_panning{false, "mouse_panning"};
573 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; 570 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};
574 BasicSetting<bool> mouse_enabled{false, "mouse_enabled"}; 571 BasicSetting<bool> mouse_enabled{false, "mouse_enabled"};
575 std::string mouse_device;
576 MouseButtonsRaw mouse_buttons;
577 572
578 BasicSetting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"}; 573 BasicSetting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"};
579 BasicSetting<bool> keyboard_enabled{false, "keyboard_enabled"}; 574 BasicSetting<bool> keyboard_enabled{false, "keyboard_enabled"};
580 KeyboardKeysRaw keyboard_keys;
581 KeyboardModsRaw keyboard_mods;
582 575
583 BasicSetting<bool> debug_pad_enabled{false, "debug_pad_enabled"}; 576 BasicSetting<bool> debug_pad_enabled{false, "debug_pad_enabled"};
584 ButtonsRaw debug_pad_buttons; 577 ButtonsRaw debug_pad_buttons;
@@ -586,14 +579,11 @@ struct Values {
586 579
587 TouchscreenInput touchscreen; 580 TouchscreenInput touchscreen;
588 581
589 BasicSetting<bool> use_touch_from_button{false, "use_touch_from_button"};
590 BasicSetting<std::string> touch_device{"min_x:100,min_y:50,max_x:1800,max_y:850", 582 BasicSetting<std::string> touch_device{"min_x:100,min_y:50,max_x:1800,max_y:850",
591 "touch_device"}; 583 "touch_device"};
592 BasicSetting<int> touch_from_button_map_index{0, "touch_from_button_map"}; 584 BasicSetting<int> touch_from_button_map_index{0, "touch_from_button_map"};
593 std::vector<TouchFromButtonMap> touch_from_button_maps; 585 std::vector<TouchFromButtonMap> touch_from_button_maps;
594 586
595 std::atomic_bool is_device_reload_pending{true};
596
597 // Data Storage 587 // Data Storage
598 BasicSetting<bool> use_virtual_sd{true, "use_virtual_sd"}; 588 BasicSetting<bool> use_virtual_sd{true, "use_virtual_sd"};
599 BasicSetting<bool> gamecard_inserted{false, "gamecard_inserted"}; 589 BasicSetting<bool> gamecard_inserted{false, "gamecard_inserted"};
@@ -614,6 +604,7 @@ struct Values {
614 BasicSetting<bool> extended_logging{false, "extended_logging"}; 604 BasicSetting<bool> extended_logging{false, "extended_logging"};
615 BasicSetting<bool> use_debug_asserts{false, "use_debug_asserts"}; 605 BasicSetting<bool> use_debug_asserts{false, "use_debug_asserts"};
616 BasicSetting<bool> use_auto_stub{false, "use_auto_stub"}; 606 BasicSetting<bool> use_auto_stub{false, "use_auto_stub"};
607 BasicSetting<bool> enable_all_controllers{false, "enable_all_controllers"};
617 608
618 // Miscellaneous 609 // Miscellaneous
619 BasicSetting<std::string> log_filter{"*:Info", "log_filter"}; 610 BasicSetting<std::string> log_filter{"*:Info", "log_filter"};
diff --git a/src/common/settings_input.h b/src/common/settings_input.h
index 609600582..4ff37e186 100644
--- a/src/common/settings_input.h
+++ b/src/common/settings_input.h
@@ -62,11 +62,22 @@ enum Values : int {
62 62
63constexpr int STICK_HID_BEGIN = LStick; 63constexpr int STICK_HID_BEGIN = LStick;
64constexpr int STICK_HID_END = NumAnalogs; 64constexpr int STICK_HID_END = NumAnalogs;
65constexpr int NUM_STICKS_HID = NumAnalogs;
66 65
67extern const std::array<const char*, NumAnalogs> mapping; 66extern const std::array<const char*, NumAnalogs> mapping;
68} // namespace NativeAnalog 67} // namespace NativeAnalog
69 68
69namespace NativeTrigger {
70enum Values : int {
71 LTrigger,
72 RTrigger,
73
74 NumTriggers,
75};
76
77constexpr int TRIGGER_HID_BEGIN = LTrigger;
78constexpr int TRIGGER_HID_END = NumTriggers;
79} // namespace NativeTrigger
80
70namespace NativeVibration { 81namespace NativeVibration {
71enum Values : int { 82enum Values : int {
72 LeftVibrationDevice, 83 LeftVibrationDevice,
@@ -115,10 +126,20 @@ constexpr int NUM_MOUSE_HID = NumMouseButtons;
115extern const std::array<const char*, NumMouseButtons> mapping; 126extern const std::array<const char*, NumMouseButtons> mapping;
116} // namespace NativeMouseButton 127} // namespace NativeMouseButton
117 128
129namespace NativeMouseWheel {
130enum Values {
131 X,
132 Y,
133
134 NumMouseWheels,
135};
136
137extern const std::array<const char*, NumMouseWheels> mapping;
138} // namespace NativeMouseWheel
139
118namespace NativeKeyboard { 140namespace NativeKeyboard {
119enum Keys { 141enum Keys {
120 None, 142 None,
121 Error,
122 143
123 A = 4, 144 A = 4,
124 B, 145 B,
@@ -156,22 +177,22 @@ enum Keys {
156 N8, 177 N8,
157 N9, 178 N9,
158 N0, 179 N0,
159 Enter, 180 Return,
160 Escape, 181 Escape,
161 Backspace, 182 Backspace,
162 Tab, 183 Tab,
163 Space, 184 Space,
164 Minus, 185 Minus,
165 Equal, 186 Plus,
166 LeftBrace, 187 OpenBracket,
167 RightBrace, 188 CloseBracket,
168 Backslash, 189 Pipe,
169 Tilde, 190 Tilde,
170 Semicolon, 191 Semicolon,
171 Apostrophe, 192 Quote,
172 Grave, 193 Backquote,
173 Comma, 194 Comma,
174 Dot, 195 Period,
175 Slash, 196 Slash,
176 CapsLockKey, 197 CapsLockKey,
177 198
@@ -188,7 +209,7 @@ enum Keys {
188 F11, 209 F11,
189 F12, 210 F12,
190 211
191 SystemRequest, 212 PrintScreen,
192 ScrollLockKey, 213 ScrollLockKey,
193 Pause, 214 Pause,
194 Insert, 215 Insert,
@@ -257,8 +278,18 @@ enum Keys {
257 ScrollLockActive, 278 ScrollLockActive,
258 KPComma, 279 KPComma,
259 280
260 KPLeftParenthesis, 281 Ro = 0x87,
261 KPRightParenthesis, 282 KatakanaHiragana,
283 Yen,
284 Henkan,
285 Muhenkan,
286 NumPadCommaPc98,
287
288 HangulEnglish = 0x90,
289 Hanja,
290 KatakanaKey,
291 HiraganaKey,
292 ZenkakuHankaku,
262 293
263 LeftControlKey = 0xE0, 294 LeftControlKey = 0xE0,
264 LeftShiftKey, 295 LeftShiftKey,
@@ -307,6 +338,8 @@ enum Modifiers {
307 CapsLock, 338 CapsLock,
308 ScrollLock, 339 ScrollLock,
309 NumLock, 340 NumLock,
341 Katakana,
342 Hiragana,
310 343
311 NumKeyboardMods, 344 NumKeyboardMods,
312}; 345};
@@ -324,11 +357,6 @@ constexpr int NUM_KEYBOARD_MODS_HID = NumKeyboardMods;
324using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>; 357using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>;
325using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>; 358using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>;
326using MotionsRaw = std::array<std::string, NativeMotion::NumMotions>; 359using MotionsRaw = std::array<std::string, NativeMotion::NumMotions>;
327using VibrationsRaw = std::array<std::string, NativeVibration::NumVibrations>;
328
329using MouseButtonsRaw = std::array<std::string, NativeMouseButton::NumMouseButtons>;
330using KeyboardKeysRaw = std::array<std::string, NativeKeyboard::NumKeyboardKeys>;
331using KeyboardModsRaw = std::array<std::string, NativeKeyboard::NumKeyboardMods>;
332 360
333constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; 361constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28;
334constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; 362constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A;
@@ -342,6 +370,11 @@ enum class ControllerType {
342 RightJoycon, 370 RightJoycon,
343 Handheld, 371 Handheld,
344 GameCube, 372 GameCube,
373 Pokeball,
374 NES,
375 SNES,
376 N64,
377 SegaGenesis,
345}; 378};
346 379
347struct PlayerInput { 380struct PlayerInput {
@@ -349,7 +382,6 @@ struct PlayerInput {
349 ControllerType controller_type; 382 ControllerType controller_type;
350 ButtonsRaw buttons; 383 ButtonsRaw buttons;
351 AnalogsRaw analogs; 384 AnalogsRaw analogs;
352 VibrationsRaw vibrations;
353 MotionsRaw motions; 385 MotionsRaw motions;
354 386
355 bool vibration_enabled; 387 bool vibration_enabled;
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp
index fccd2eee5..fbeacc7e2 100644
--- a/src/common/x64/cpu_detect.cpp
+++ b/src/common/x64/cpu_detect.cpp
@@ -71,9 +71,6 @@ static CPUCaps Detect() {
71 else 71 else
72 caps.manufacturer = Manufacturer::Unknown; 72 caps.manufacturer = Manufacturer::Unknown;
73 73
74 u32 family = {};
75 u32 model = {};
76
77 __cpuid(cpu_id, 0x80000000); 74 __cpuid(cpu_id, 0x80000000);
78 75
79 u32 max_ex_fn = cpu_id[0]; 76 u32 max_ex_fn = cpu_id[0];
@@ -84,15 +81,6 @@ static CPUCaps Detect() {
84 // Detect family and other miscellaneous features 81 // Detect family and other miscellaneous features
85 if (max_std_fn >= 1) { 82 if (max_std_fn >= 1) {
86 __cpuid(cpu_id, 0x00000001); 83 __cpuid(cpu_id, 0x00000001);
87 family = (cpu_id[0] >> 8) & 0xf;
88 model = (cpu_id[0] >> 4) & 0xf;
89 if (family == 0xf) {
90 family += (cpu_id[0] >> 20) & 0xff;
91 }
92 if (family >= 6) {
93 model += ((cpu_id[0] >> 16) & 0xf) << 4;
94 }
95
96 if ((cpu_id[3] >> 25) & 1) 84 if ((cpu_id[3] >> 25) & 1)
97 caps.sse = true; 85 caps.sse = true;
98 if ((cpu_id[3] >> 26) & 1) 86 if ((cpu_id[3] >> 26) & 1)
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 87de40624..82ee2c8a1 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -15,26 +15,26 @@
15namespace Common { 15namespace Common {
16 16
17u64 EstimateRDTSCFrequency() { 17u64 EstimateRDTSCFrequency() {
18 const auto milli_10 = std::chrono::milliseconds{10}; 18 // Discard the first result measuring the rdtsc.
19 // get current time
20 _mm_mfence(); 19 _mm_mfence();
21 const u64 tscStart = __rdtsc(); 20 __rdtsc();
22 const auto startTime = std::chrono::high_resolution_clock::now(); 21 std::this_thread::sleep_for(std::chrono::milliseconds{1});
23 // wait roughly 3 seconds 22 _mm_mfence();
24 while (true) { 23 __rdtsc();
25 auto milli = std::chrono::duration_cast<std::chrono::milliseconds>( 24
26 std::chrono::high_resolution_clock::now() - startTime); 25 // Get the current time.
27 if (milli.count() >= 3000) 26 const auto start_time = std::chrono::steady_clock::now();
28 break; 27 _mm_mfence();
29 std::this_thread::sleep_for(milli_10); 28 const u64 tsc_start = __rdtsc();
30 } 29 // Wait for 200 milliseconds.
31 const auto endTime = std::chrono::high_resolution_clock::now(); 30 std::this_thread::sleep_for(std::chrono::milliseconds{200});
31 const auto end_time = std::chrono::steady_clock::now();
32 _mm_mfence(); 32 _mm_mfence();
33 const u64 tscEnd = __rdtsc(); 33 const u64 tsc_end = __rdtsc();
34 // calculate difference 34 // Calculate differences.
35 const u64 timer_diff = 35 const u64 timer_diff = static_cast<u64>(
36 std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count(); 36 std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
37 const u64 tsc_diff = tscEnd - tscStart; 37 const u64 tsc_diff = tsc_end - tsc_start;
38 const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff); 38 const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff);
39 return tsc_freq; 39 return tsc_freq;
40} 40}