summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/board
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/board')
-rw-r--r--src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp46
-rw-r--r--src/core/hle/kernel/board/nintendo/nx/k_system_control.h22
2 files changed, 68 insertions, 0 deletions
diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
new file mode 100644
index 000000000..0f41c4110
--- /dev/null
+++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
@@ -0,0 +1,46 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <random>
+
+#include "core/hle/kernel/k_system_control.h"
+
+namespace Kernel::Board::Nintendo::Nx {
+
+bool KSystemControl::Init::ShouldIncreaseThreadResourceLimit() {
+ return true;
+}
+
+namespace {
+template <typename F>
+u64 GenerateUniformRange(u64 min, u64 max, F f) {
+ // Handle the case where the difference is too large to represent.
+ if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) {
+ return f();
+ }
+
+ // Iterate until we get a value in range.
+ const u64 range_size = ((max + 1) - min);
+ const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size;
+ while (true) {
+ if (const u64 rnd = f(); rnd < effective_max) {
+ return min + (rnd % range_size);
+ }
+ }
+}
+
+} // Anonymous namespace
+
+u64 KSystemControl::GenerateRandomU64() {
+ static std::random_device device;
+ static std::mt19937 gen(device());
+ static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
+ return distribution(gen);
+}
+
+u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) {
+ return GenerateUniformRange(min, max, GenerateRandomU64);
+}
+
+} // namespace Kernel::Board::Nintendo::Nx
diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.h b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h
new file mode 100644
index 000000000..3fde61971
--- /dev/null
+++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h
@@ -0,0 +1,22 @@
+// 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"
+
+namespace Kernel::Board::Nintendo::Nx {
+
+class KSystemControl {
+public:
+ class Init {
+ public:
+ static bool ShouldIncreaseThreadResourceLimit();
+ };
+
+ static u64 GenerateRandomRange(u64 min, u64 max);
+ static u64 GenerateRandomU64();
+};
+
+} // namespace Kernel::Board::Nintendo::Nx