summaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2022-09-10 01:48:15 -0700
committerGravatar bunnei2022-10-18 19:13:35 -0700
commita4d11f4427859cbe82fc825f8493844e17bb668f (patch)
treed1844e8ad7bcfd3c9467cad75091bc207fba7103 /src/core/core.cpp
parentcore: hle: kernel: Fix InitializePreemption order. (diff)
downloadyuzu-a4d11f4427859cbe82fc825f8493844e17bb668f.tar.gz
yuzu-a4d11f4427859cbe82fc825f8493844e17bb668f.tar.xz
yuzu-a4d11f4427859cbe82fc825f8493844e17bb668f.zip
core: Partially persist emulation state across game boots.
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 1deeee154..2c4c0dbe4 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -133,6 +133,30 @@ struct System::Impl {
133 : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{}, 133 : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
134 cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {} 134 cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {}
135 135
136 void Initialize(System& system) {
137 device_memory = std::make_unique<Core::DeviceMemory>();
138
139 is_multicore = Settings::values.use_multi_core.GetValue();
140
141 core_timing.SetMulticore(is_multicore);
142 core_timing.Initialize([&system]() { system.RegisterHostThread(); });
143
144 const auto posix_time = std::chrono::system_clock::now().time_since_epoch();
145 const auto current_time =
146 std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
147 Settings::values.custom_rtc_differential =
148 Settings::values.custom_rtc.value_or(current_time) - current_time;
149
150 // Create a default fs if one doesn't already exist.
151 if (virtual_filesystem == nullptr)
152 virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();
153 if (content_provider == nullptr)
154 content_provider = std::make_unique<FileSys::ContentProviderUnion>();
155
156 // Create default implementations of applets if one is not provided.
157 applet_manager.SetDefaultAppletsIfMissing();
158 }
159
136 SystemResultStatus Run() { 160 SystemResultStatus Run() {
137 std::unique_lock<std::mutex> lk(suspend_guard); 161 std::unique_lock<std::mutex> lk(suspend_guard);
138 status = SystemResultStatus::Success; 162 status = SystemResultStatus::Success;
@@ -178,37 +202,17 @@ struct System::Impl {
178 debugger = std::make_unique<Debugger>(system, port); 202 debugger = std::make_unique<Debugger>(system, port);
179 } 203 }
180 204
181 SystemResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { 205 SystemResultStatus SetupForMainProcess(System& system, Frontend::EmuWindow& emu_window) {
182 LOG_DEBUG(Core, "initialized OK"); 206 LOG_DEBUG(Core, "initialized OK");
183 207
184 device_memory = std::make_unique<Core::DeviceMemory>();
185
186 is_multicore = Settings::values.use_multi_core.GetValue();
187 is_async_gpu = Settings::values.use_asynchronous_gpu_emulation.GetValue(); 208 is_async_gpu = Settings::values.use_asynchronous_gpu_emulation.GetValue();
188 209
189 kernel.SetMulticore(is_multicore); 210 kernel.SetMulticore(is_multicore);
190 cpu_manager.SetMulticore(is_multicore); 211 cpu_manager.SetMulticore(is_multicore);
191 cpu_manager.SetAsyncGpu(is_async_gpu); 212 cpu_manager.SetAsyncGpu(is_async_gpu);
192 core_timing.SetMulticore(is_multicore);
193 213
194 kernel.Initialize(); 214 kernel.Initialize();
195 cpu_manager.Initialize(); 215 cpu_manager.Initialize();
196 core_timing.Initialize([&system]() { system.RegisterHostThread(); });
197
198 const auto posix_time = std::chrono::system_clock::now().time_since_epoch();
199 const auto current_time =
200 std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
201 Settings::values.custom_rtc_differential =
202 Settings::values.custom_rtc.value_or(current_time) - current_time;
203
204 // Create a default fs if one doesn't already exist.
205 if (virtual_filesystem == nullptr)
206 virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();
207 if (content_provider == nullptr)
208 content_provider = std::make_unique<FileSys::ContentProviderUnion>();
209
210 /// Create default implementations of applets if one is not provided.
211 applet_manager.SetDefaultAppletsIfMissing();
212 216
213 /// Reset all glue registrations 217 /// Reset all glue registrations
214 arp_manager.ResetAll(); 218 arp_manager.ResetAll();
@@ -253,11 +257,11 @@ struct System::Impl {
253 return SystemResultStatus::ErrorGetLoader; 257 return SystemResultStatus::ErrorGetLoader;
254 } 258 }
255 259
256 SystemResultStatus init_result{Init(system, emu_window)}; 260 SystemResultStatus init_result{SetupForMainProcess(system, emu_window)};
257 if (init_result != SystemResultStatus::Success) { 261 if (init_result != SystemResultStatus::Success) {
258 LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", 262 LOG_CRITICAL(Core, "Failed to initialize system (Error {})!",
259 static_cast<int>(init_result)); 263 static_cast<int>(init_result));
260 Shutdown(); 264 ShutdownMainProcess();
261 return init_result; 265 return init_result;
262 } 266 }
263 267
@@ -276,7 +280,7 @@ struct System::Impl {
276 const auto [load_result, load_parameters] = app_loader->Load(*main_process, system); 280 const auto [load_result, load_parameters] = app_loader->Load(*main_process, system);
277 if (load_result != Loader::ResultStatus::Success) { 281 if (load_result != Loader::ResultStatus::Success) {
278 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); 282 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
279 Shutdown(); 283 ShutdownMainProcess();
280 284
281 return static_cast<SystemResultStatus>( 285 return static_cast<SystemResultStatus>(
282 static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); 286 static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
@@ -335,7 +339,7 @@ struct System::Impl {
335 return status; 339 return status;
336 } 340 }
337 341
338 void Shutdown() { 342 void ShutdownMainProcess() {
339 SetShuttingDown(true); 343 SetShuttingDown(true);
340 344
341 // Log last frame performance stats if game was loded 345 // Log last frame performance stats if game was loded
@@ -369,7 +373,7 @@ struct System::Impl {
369 cheat_engine.reset(); 373 cheat_engine.reset();
370 telemetry_session.reset(); 374 telemetry_session.reset();
371 time_manager.Shutdown(); 375 time_manager.Shutdown();
372 core_timing.Shutdown(); 376 core_timing.ClearPendingEvents();
373 app_loader.reset(); 377 app_loader.reset();
374 audio_core.reset(); 378 audio_core.reset();
375 gpu_core.reset(); 379 gpu_core.reset();
@@ -377,7 +381,6 @@ struct System::Impl {
377 perf_stats.reset(); 381 perf_stats.reset();
378 kernel.Shutdown(); 382 kernel.Shutdown();
379 memory.Reset(); 383 memory.Reset();
380 applet_manager.ClearAll();
381 384
382 if (auto room_member = room_network.GetRoomMember().lock()) { 385 if (auto room_member = room_network.GetRoomMember().lock()) {
383 Network::GameInfo game_info{}; 386 Network::GameInfo game_info{};
@@ -520,6 +523,10 @@ const CpuManager& System::GetCpuManager() const {
520 return impl->cpu_manager; 523 return impl->cpu_manager;
521} 524}
522 525
526void System::Initialize() {
527 impl->Initialize(*this);
528}
529
523SystemResultStatus System::Run() { 530SystemResultStatus System::Run() {
524 return impl->Run(); 531 return impl->Run();
525} 532}
@@ -540,8 +547,8 @@ void System::InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size) {
540 impl->kernel.InvalidateCpuInstructionCacheRange(addr, size); 547 impl->kernel.InvalidateCpuInstructionCacheRange(addr, size);
541} 548}
542 549
543void System::Shutdown() { 550void System::ShutdownMainProcess() {
544 impl->Shutdown(); 551 impl->ShutdownMainProcess();
545} 552}
546 553
547bool System::IsShuttingDown() const { 554bool System::IsShuttingDown() const {