diff options
| author | 2016-11-04 23:14:38 -0400 | |
|---|---|---|
| committer | 2016-12-21 23:29:04 -0500 | |
| commit | 198b6c9bdd58d76303f75a8577303907967a143e (patch) | |
| tree | 0dba084e5c3418f917880fd4fc1efad37f127e9b /src/core/system.cpp | |
| parent | loader: Remove duplicate docstrings. (diff) | |
| download | yuzu-198b6c9bdd58d76303f75a8577303907967a143e.tar.gz yuzu-198b6c9bdd58d76303f75a8577303907967a143e.tar.xz yuzu-198b6c9bdd58d76303f75a8577303907967a143e.zip | |
core: Consolidate top-level system state into a singleton.
Diffstat (limited to 'src/core/system.cpp')
| -rw-r--r-- | src/core/system.cpp | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/src/core/system.cpp b/src/core/system.cpp index a5f763805..fa8bd0317 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp | |||
| @@ -13,33 +13,30 @@ | |||
| 13 | #include "core/system.h" | 13 | #include "core/system.h" |
| 14 | #include "video_core/video_core.h" | 14 | #include "video_core/video_core.h" |
| 15 | 15 | ||
| 16 | namespace System { | 16 | namespace Core { |
| 17 | 17 | ||
| 18 | static bool is_powered_on{false}; | 18 | /*static*/ System System::s_instance; |
| 19 | 19 | ||
| 20 | Result Init(EmuWindow* emu_window, u32 system_mode) { | 20 | System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { |
| 21 | Core::Init(); | 21 | Core::Init(); |
| 22 | CoreTiming::Init(); | 22 | CoreTiming::Init(); |
| 23 | Memory::Init(); | 23 | Memory::Init(); |
| 24 | HW::Init(); | 24 | HW::Init(); |
| 25 | Kernel::Init(system_mode); | 25 | Kernel::Init(system_mode); |
| 26 | HLE::Init(); | 26 | HLE::Init(); |
| 27 | if (!VideoCore::Init(emu_window)) { | ||
| 28 | return Result::ErrorInitVideoCore; | ||
| 29 | } | ||
| 30 | AudioCore::Init(); | 27 | AudioCore::Init(); |
| 31 | GDBStub::Init(); | 28 | GDBStub::Init(); |
| 32 | 29 | ||
| 33 | is_powered_on = true; | 30 | if (!VideoCore::Init(emu_window)) { |
| 31 | return ResultStatus::ErrorVideoCore; | ||
| 32 | } | ||
| 34 | 33 | ||
| 35 | return Result::Success; | 34 | is_powered_on = true; |
| 36 | } | ||
| 37 | 35 | ||
| 38 | bool IsPoweredOn() { | 36 | return ResultStatus::Success; |
| 39 | return is_powered_on; | ||
| 40 | } | 37 | } |
| 41 | 38 | ||
| 42 | void Shutdown() { | 39 | void System::Shutdown() { |
| 43 | GDBStub::Shutdown(); | 40 | GDBStub::Shutdown(); |
| 44 | AudioCore::Shutdown(); | 41 | AudioCore::Shutdown(); |
| 45 | VideoCore::Shutdown(); | 42 | VideoCore::Shutdown(); |
| @@ -52,4 +49,42 @@ void Shutdown() { | |||
| 52 | is_powered_on = false; | 49 | is_powered_on = false; |
| 53 | } | 50 | } |
| 54 | 51 | ||
| 55 | } // namespace | 52 | System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { |
| 53 | state.app_loader = Loader::GetLoader(filepath); | ||
| 54 | |||
| 55 | if (!state.app_loader) { | ||
| 56 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str()); | ||
| 57 | return ResultStatus::ErrorGetLoader; | ||
| 58 | } | ||
| 59 | |||
| 60 | boost::optional<u32> system_mode{ state.app_loader->LoadKernelSystemMode() }; | ||
| 61 | if (!system_mode) { | ||
| 62 | LOG_CRITICAL(Frontend, "Failed to determine system mode!"); | ||
| 63 | return ResultStatus::ErrorSystemMode; | ||
| 64 | } | ||
| 65 | |||
| 66 | ResultStatus init_result{ Init(emu_window, system_mode.get()) }; | ||
| 67 | if (init_result != ResultStatus::Success) { | ||
| 68 | LOG_CRITICAL(Frontend, "Failed to initialize system (Error %i)!", init_result); | ||
| 69 | System::Shutdown(); | ||
| 70 | return init_result; | ||
| 71 | } | ||
| 72 | |||
| 73 | const Loader::ResultStatus load_result{ state.app_loader->Load() }; | ||
| 74 | if (Loader::ResultStatus::Success != load_result) { | ||
| 75 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); | ||
| 76 | System::Shutdown(); | ||
| 77 | |||
| 78 | switch (load_result) { | ||
| 79 | case Loader::ResultStatus::ErrorEncrypted: | ||
| 80 | return ResultStatus::ErrorLoader_ErrorEncrypted; | ||
| 81 | case Loader::ResultStatus::ErrorInvalidFormat: | ||
| 82 | return ResultStatus::ErrorLoader_ErrorInvalidFormat; | ||
| 83 | default: | ||
| 84 | return ResultStatus::ErrorLoader; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | return ResultStatus::Success; | ||
| 88 | } | ||
| 89 | |||
| 90 | } // namespace Core | ||