summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/crypto/key_manager.cpp8
-rw-r--r--src/core/crypto/key_manager.h3
-rw-r--r--src/core/device_memory.cpp8
-rw-r--r--src/core/frontend/emu_window.cpp2
-rw-r--r--src/core/frontend/emu_window.h48
-rw-r--r--src/core/frontend/graphics_context.h62
-rw-r--r--src/core/hid/emulated_console.cpp32
-rw-r--r--src/core/hid/emulated_console.h4
-rw-r--r--src/core/hid/emulated_controller.cpp26
-rw-r--r--src/core/hid/emulated_controller.h2
-rw-r--r--src/core/hle/kernel/k_address_space_info.cpp5
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp1
13 files changed, 145 insertions, 57 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index e8bf68866..99602699a 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -142,6 +142,7 @@ add_library(core STATIC
142 frontend/emu_window.h 142 frontend/emu_window.h
143 frontend/framebuffer_layout.cpp 143 frontend/framebuffer_layout.cpp
144 frontend/framebuffer_layout.h 144 frontend/framebuffer_layout.h
145 frontend/graphics_context.h
145 hid/emulated_console.cpp 146 hid/emulated_console.cpp
146 hid/emulated_console.h 147 hid/emulated_console.h
147 hid/emulated_controller.cpp 148 hid/emulated_controller.cpp
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 65a9fe802..4ff2c50e5 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -569,6 +569,10 @@ std::optional<std::pair<Key128, Key128>> ParseTicket(const Ticket& ticket,
569} 569}
570 570
571KeyManager::KeyManager() { 571KeyManager::KeyManager() {
572 ReloadKeys();
573}
574
575void KeyManager::ReloadKeys() {
572 // Initialize keys 576 // Initialize keys
573 const auto yuzu_keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); 577 const auto yuzu_keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir);
574 578
@@ -702,6 +706,10 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti
702 } 706 }
703} 707}
704 708
709bool KeyManager::AreKeysLoaded() const {
710 return !s128_keys.empty() && !s256_keys.empty();
711}
712
705bool KeyManager::BaseDeriveNecessary() const { 713bool KeyManager::BaseDeriveNecessary() const {
706 const auto check_key_existence = [this](auto key_type, u64 index1 = 0, u64 index2 = 0) { 714 const auto check_key_existence = [this](auto key_type, u64 index1 = 0, u64 index2 = 0) {
707 return !HasKey(key_type, index1, index2); 715 return !HasKey(key_type, index1, index2);
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index 673cec463..8c864503b 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -267,6 +267,9 @@ public:
267 bool AddTicketCommon(Ticket raw); 267 bool AddTicketCommon(Ticket raw);
268 bool AddTicketPersonalized(Ticket raw); 268 bool AddTicketPersonalized(Ticket raw);
269 269
270 void ReloadKeys();
271 bool AreKeysLoaded() const;
272
270private: 273private:
271 KeyManager(); 274 KeyManager();
272 275
diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp
index f8b5be2b4..de3f8ef8f 100644
--- a/src/core/device_memory.cpp
+++ b/src/core/device_memory.cpp
@@ -6,9 +6,15 @@
6 6
7namespace Core { 7namespace Core {
8 8
9#ifdef ANDROID
10constexpr size_t VirtualReserveSize = 1ULL << 38;
11#else
12constexpr size_t VirtualReserveSize = 1ULL << 39;
13#endif
14
9DeviceMemory::DeviceMemory() 15DeviceMemory::DeviceMemory()
10 : buffer{Kernel::Board::Nintendo::Nx::KSystemControl::Init::GetIntendedMemorySize(), 16 : buffer{Kernel::Board::Nintendo::Nx::KSystemControl::Init::GetIntendedMemorySize(),
11 1ULL << 39} {} 17 VirtualReserveSize} {}
12DeviceMemory::~DeviceMemory() = default; 18DeviceMemory::~DeviceMemory() = default;
13 19
14} // namespace Core 20} // namespace Core
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index 1be2dccb0..d1f1ca8c9 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -6,8 +6,6 @@
6 6
7namespace Core::Frontend { 7namespace Core::Frontend {
8 8
9GraphicsContext::~GraphicsContext() = default;
10
11EmuWindow::EmuWindow() { 9EmuWindow::EmuWindow() {
12 // TODO: Find a better place to set this. 10 // TODO: Find a better place to set this.
13 config.min_client_area_size = 11 config.min_client_area_size =
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index 1093800f6..a72df034e 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -5,11 +5,14 @@
5 5
6#include <memory> 6#include <memory>
7#include <utility> 7#include <utility>
8
8#include "common/common_types.h" 9#include "common/common_types.h"
9#include "core/frontend/framebuffer_layout.h" 10#include "core/frontend/framebuffer_layout.h"
10 11
11namespace Core::Frontend { 12namespace Core::Frontend {
12 13
14class GraphicsContext;
15
13/// Information for the Graphics Backends signifying what type of screen pointer is in 16/// Information for the Graphics Backends signifying what type of screen pointer is in
14/// WindowInformation 17/// WindowInformation
15enum class WindowSystemType { 18enum class WindowSystemType {
@@ -22,51 +25,6 @@ enum class WindowSystemType {
22}; 25};
23 26
24/** 27/**
25 * Represents a drawing context that supports graphics operations.
26 */
27class GraphicsContext {
28public:
29 virtual ~GraphicsContext();
30
31 /// Inform the driver to swap the front/back buffers and present the current image
32 virtual void SwapBuffers() {}
33
34 /// Makes the graphics context current for the caller thread
35 virtual void MakeCurrent() {}
36
37 /// Releases (dunno if this is the "right" word) the context from the caller thread
38 virtual void DoneCurrent() {}
39
40 class Scoped {
41 public:
42 [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {
43 context.MakeCurrent();
44 }
45 ~Scoped() {
46 if (active) {
47 context.DoneCurrent();
48 }
49 }
50
51 /// In the event that context was destroyed before the Scoped is destroyed, this provides a
52 /// mechanism to prevent calling a destroyed object's method during the deconstructor
53 void Cancel() {
54 active = false;
55 }
56
57 private:
58 GraphicsContext& context;
59 bool active{true};
60 };
61
62 /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value
63 /// ends
64 [[nodiscard]] Scoped Acquire() {
65 return Scoped{*this};
66 }
67};
68
69/**
70 * Abstraction class used to provide an interface between emulation code and the frontend 28 * Abstraction class used to provide an interface between emulation code and the frontend
71 * (e.g. SDL, QGLWidget, GLFW, etc...). 29 * (e.g. SDL, QGLWidget, GLFW, etc...).
72 * 30 *
diff --git a/src/core/frontend/graphics_context.h b/src/core/frontend/graphics_context.h
new file mode 100644
index 000000000..7554c1583
--- /dev/null
+++ b/src/core/frontend/graphics_context.h
@@ -0,0 +1,62 @@
1// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <memory>
7
8#include "common/dynamic_library.h"
9
10namespace Core::Frontend {
11
12/**
13 * Represents a drawing context that supports graphics operations.
14 */
15class GraphicsContext {
16public:
17 virtual ~GraphicsContext() = default;
18
19 /// Inform the driver to swap the front/back buffers and present the current image
20 virtual void SwapBuffers() {}
21
22 /// Makes the graphics context current for the caller thread
23 virtual void MakeCurrent() {}
24
25 /// Releases (dunno if this is the "right" word) the context from the caller thread
26 virtual void DoneCurrent() {}
27
28 /// Gets the GPU driver library (used by Android only)
29 virtual std::shared_ptr<Common::DynamicLibrary> GetDriverLibrary() {
30 return {};
31 }
32
33 class Scoped {
34 public:
35 [[nodiscard]] explicit Scoped(GraphicsContext& context_) : context(context_) {
36 context.MakeCurrent();
37 }
38 ~Scoped() {
39 if (active) {
40 context.DoneCurrent();
41 }
42 }
43
44 /// In the event that context was destroyed before the Scoped is destroyed, this provides a
45 /// mechanism to prevent calling a destroyed object's method during the deconstructor
46 void Cancel() {
47 active = false;
48 }
49
50 private:
51 GraphicsContext& context;
52 bool active{true};
53 };
54
55 /// Calls MakeCurrent on the context and calls DoneCurrent when the scope for the returned value
56 /// ends
57 [[nodiscard]] Scoped Acquire() {
58 return Scoped{*this};
59 }
60};
61
62} // namespace Core::Frontend
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 17d663379..b4afd930e 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -13,7 +13,7 @@ EmulatedConsole::~EmulatedConsole() = default;
13void EmulatedConsole::ReloadFromSettings() { 13void EmulatedConsole::ReloadFromSettings() {
14 // Using first motion device from player 1. No need to assign any unique config at the moment 14 // Using first motion device from player 1. No need to assign any unique config at the moment
15 const auto& player = Settings::values.players.GetValue()[0]; 15 const auto& player = Settings::values.players.GetValue()[0];
16 motion_params = Common::ParamPackage(player.motions[0]); 16 motion_params[0] = Common::ParamPackage(player.motions[0]);
17 17
18 ReloadInput(); 18 ReloadInput();
19} 19}
@@ -74,14 +74,30 @@ void EmulatedConsole::ReloadInput() {
74 // If you load any device here add the equivalent to the UnloadInput() function 74 // If you load any device here add the equivalent to the UnloadInput() function
75 SetTouchParams(); 75 SetTouchParams();
76 76
77 motion_devices = Common::Input::CreateInputDevice(motion_params); 77 motion_params[1] = Common::ParamPackage{"engine:virtual_gamepad,port:8,motion:0"};
78 if (motion_devices) { 78
79 motion_devices->SetCallback({ 79 for (std::size_t index = 0; index < motion_devices.size(); ++index) {
80 motion_devices[index] = Common::Input::CreateInputDevice(motion_params[index]);
81 if (!motion_devices[index]) {
82 continue;
83 }
84 motion_devices[index]->SetCallback({
80 .on_change = 85 .on_change =
81 [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); }, 86 [this](const Common::Input::CallbackStatus& callback) { SetMotion(callback); },
82 }); 87 });
83 } 88 }
84 89
90 // Restore motion state
91 auto& emulated_motion = console.motion_values.emulated;
92 auto& motion = console.motion_state;
93 emulated_motion.ResetRotations();
94 emulated_motion.ResetQuaternion();
95 motion.accel = emulated_motion.GetAcceleration();
96 motion.gyro = emulated_motion.GetGyroscope();
97 motion.rotation = emulated_motion.GetRotations();
98 motion.orientation = emulated_motion.GetOrientation();
99 motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity);
100
85 // Unique index for identifying touch device source 101 // Unique index for identifying touch device source
86 std::size_t index = 0; 102 std::size_t index = 0;
87 for (auto& touch_device : touch_devices) { 103 for (auto& touch_device : touch_devices) {
@@ -100,7 +116,9 @@ void EmulatedConsole::ReloadInput() {
100} 116}
101 117
102void EmulatedConsole::UnloadInput() { 118void EmulatedConsole::UnloadInput() {
103 motion_devices.reset(); 119 for (auto& motion : motion_devices) {
120 motion.reset();
121 }
104 for (auto& touch : touch_devices) { 122 for (auto& touch : touch_devices) {
105 touch.reset(); 123 touch.reset();
106 } 124 }
@@ -133,11 +151,11 @@ void EmulatedConsole::RestoreConfig() {
133} 151}
134 152
135Common::ParamPackage EmulatedConsole::GetMotionParam() const { 153Common::ParamPackage EmulatedConsole::GetMotionParam() const {
136 return motion_params; 154 return motion_params[0];
137} 155}
138 156
139void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { 157void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
140 motion_params = std::move(param); 158 motion_params[0] = std::move(param);
141 ReloadInput(); 159 ReloadInput();
142} 160}
143 161
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index 697ecd2d6..79114bb6d 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -29,10 +29,10 @@ struct ConsoleMotionInfo {
29 MotionInput emulated{}; 29 MotionInput emulated{};
30}; 30};
31 31
32using ConsoleMotionDevices = std::unique_ptr<Common::Input::InputDevice>; 32using ConsoleMotionDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, 2>;
33using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, MaxTouchDevices>; 33using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, MaxTouchDevices>;
34 34
35using ConsoleMotionParams = Common::ParamPackage; 35using ConsoleMotionParams = std::array<Common::ParamPackage, 2>;
36using TouchParams = std::array<Common::ParamPackage, MaxTouchDevices>; 36using TouchParams = std::array<Common::ParamPackage, MaxTouchDevices>;
37 37
38using ConsoleMotionValues = ConsoleMotionInfo; 38using ConsoleMotionValues = ConsoleMotionInfo;
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index bbfea7117..0a7777732 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -193,6 +193,8 @@ void EmulatedController::LoadDevices() {
193 Common::Input::CreateInputDevice); 193 Common::Input::CreateInputDevice);
194 std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(), 194 std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(),
195 Common::Input::CreateInputDevice); 195 Common::Input::CreateInputDevice);
196 std::ranges::transform(virtual_motion_params, virtual_motion_devices.begin(),
197 Common::Input::CreateInputDevice);
196} 198}
197 199
198void EmulatedController::LoadTASParams() { 200void EmulatedController::LoadTASParams() {
@@ -253,6 +255,12 @@ void EmulatedController::LoadVirtualGamepadParams() {
253 for (auto& param : virtual_stick_params) { 255 for (auto& param : virtual_stick_params) {
254 param = common_params; 256 param = common_params;
255 } 257 }
258 for (auto& param : virtual_stick_params) {
259 param = common_params;
260 }
261 for (auto& param : virtual_motion_params) {
262 param = common_params;
263 }
256 264
257 // TODO(german77): Replace this with an input profile or something better 265 // TODO(german77): Replace this with an input profile or something better
258 virtual_button_params[Settings::NativeButton::A].Set("button", 0); 266 virtual_button_params[Settings::NativeButton::A].Set("button", 0);
@@ -284,6 +292,9 @@ void EmulatedController::LoadVirtualGamepadParams() {
284 virtual_stick_params[Settings::NativeAnalog::LStick].Set("range", 1.0f); 292 virtual_stick_params[Settings::NativeAnalog::LStick].Set("range", 1.0f);
285 virtual_stick_params[Settings::NativeAnalog::RStick].Set("deadzone", 0.0f); 293 virtual_stick_params[Settings::NativeAnalog::RStick].Set("deadzone", 0.0f);
286 virtual_stick_params[Settings::NativeAnalog::RStick].Set("range", 1.0f); 294 virtual_stick_params[Settings::NativeAnalog::RStick].Set("range", 1.0f);
295
296 virtual_motion_params[Settings::NativeMotion::MotionLeft].Set("motion", 0);
297 virtual_motion_params[Settings::NativeMotion::MotionRight].Set("motion", 0);
287} 298}
288 299
289void EmulatedController::ReloadInput() { 300void EmulatedController::ReloadInput() {
@@ -463,6 +474,18 @@ void EmulatedController::ReloadInput() {
463 }, 474 },
464 }); 475 });
465 } 476 }
477
478 for (std::size_t index = 0; index < virtual_motion_devices.size(); ++index) {
479 if (!virtual_motion_devices[index]) {
480 continue;
481 }
482 virtual_motion_devices[index]->SetCallback({
483 .on_change =
484 [this, index](const Common::Input::CallbackStatus& callback) {
485 SetMotion(callback, index);
486 },
487 });
488 }
466 turbo_button_state = 0; 489 turbo_button_state = 0;
467} 490}
468 491
@@ -500,6 +523,9 @@ void EmulatedController::UnloadInput() {
500 for (auto& stick : virtual_stick_devices) { 523 for (auto& stick : virtual_stick_devices) {
501 stick.reset(); 524 stick.reset();
502 } 525 }
526 for (auto& motion : virtual_motion_devices) {
527 motion.reset();
528 }
503 for (auto& camera : camera_devices) { 529 for (auto& camera : camera_devices) {
504 camera.reset(); 530 camera.reset();
505 } 531 }
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 88fad2f56..09fe1a0ab 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -568,8 +568,10 @@ private:
568 // Virtual gamepad related variables 568 // Virtual gamepad related variables
569 ButtonParams virtual_button_params; 569 ButtonParams virtual_button_params;
570 StickParams virtual_stick_params; 570 StickParams virtual_stick_params;
571 ControllerMotionParams virtual_motion_params;
571 ButtonDevices virtual_button_devices; 572 ButtonDevices virtual_button_devices;
572 StickDevices virtual_stick_devices; 573 StickDevices virtual_stick_devices;
574 ControllerMotionDevices virtual_motion_devices;
573 575
574 mutable std::mutex mutex; 576 mutable std::mutex mutex;
575 mutable std::mutex callback_mutex; 577 mutable std::mutex callback_mutex;
diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp
index c36eb5dc4..32173e52b 100644
--- a/src/core/hle/kernel/k_address_space_info.cpp
+++ b/src/core/hle/kernel/k_address_space_info.cpp
@@ -25,7 +25,12 @@ constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{
25 { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, }, 25 { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
26 { .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, 26 { .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, },
27 { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, }, 27 { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, },
28#ifdef ANDROID
29 // With Android, we use a 38-bit address space due to memory limitations. This should (safely) truncate ASLR region.
30 { .bit_width = 39, .address = 128_MiB , .size = 256_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
31#else
28 { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, 32 { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
33#endif
29 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall }, 34 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall },
30 { .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, 35 { .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, },
31 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, }, 36 { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, },
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 63fd5bfd6..5542d6cbc 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -46,6 +46,7 @@ ProfileManager::ProfileManager() {
46 // Create an user if none are present 46 // Create an user if none are present
47 if (user_count == 0) { 47 if (user_count == 0) {
48 CreateNewUser(UUID::MakeRandom(), "yuzu"); 48 CreateNewUser(UUID::MakeRandom(), "yuzu");
49 WriteUserSaveFile();
49 } 50 }
50 51
51 auto current = 52 auto current =