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 | |
| 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')
| -rw-r--r-- | src/core/system.cpp | 61 | ||||
| -rw-r--r-- | src/core/system.h | 82 |
2 files changed, 120 insertions, 23 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 | ||
diff --git a/src/core/system.h b/src/core/system.h index b41fc088a..192a9c447 100644 --- a/src/core/system.h +++ b/src/core/system.h | |||
| @@ -4,18 +4,80 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | |||
| 9 | #include "core/loader/loader.h" | ||
| 10 | |||
| 7 | class EmuWindow; | 11 | class EmuWindow; |
| 8 | 12 | ||
| 9 | namespace System { | 13 | namespace Core { |
| 14 | |||
| 15 | class System { | ||
| 16 | public: | ||
| 17 | struct State { | ||
| 18 | std::unique_ptr<Loader::AppLoader> app_loader; | ||
| 19 | }; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Gets the instance of the System singleton class. | ||
| 23 | * @returns Reference to the instance of the System singleton class. | ||
| 24 | */ | ||
| 25 | static System& GetInstance() { | ||
| 26 | return s_instance; | ||
| 27 | } | ||
| 28 | |||
| 29 | /// Enumeration representing the return values of the System Initialize and Load process. | ||
| 30 | enum class ResultStatus : u32 { | ||
| 31 | Success, ///< Succeeded | ||
| 32 | ErrorGetLoader, ///< Error finding the correct application loader | ||
| 33 | ErrorSystemMode, ///< Error determining the system mode | ||
| 34 | ErrorLoader, ///< Error loading the specified application | ||
| 35 | ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption | ||
| 36 | ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an invalid format | ||
| 37 | ErrorVideoCore, ///< Error in the video core | ||
| 38 | }; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Initialize the emulated system. | ||
| 42 | * @param emu_window Pointer to the host-system window used for video output and keyboard input. | ||
| 43 | * @param system_mode The system mode. | ||
| 44 | * @returns ResultStatus code, indicating if the operation succeeded. | ||
| 45 | */ | ||
| 46 | ResultStatus Init(EmuWindow* emu_window, u32 system_mode); | ||
| 47 | |||
| 48 | /// Shutdown the emulated system. | ||
| 49 | void Shutdown(); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Load an executable application. | ||
| 53 | * @param emu_window Pointer to the host-system window used for video output and keyboard input. | ||
| 54 | * @param filepath String path to the executable application to load on the host file system. | ||
| 55 | * @returns ResultStatus code, indicating if the operation succeeded. | ||
| 56 | */ | ||
| 57 | ResultStatus Load(EmuWindow* emu_window, const std::string& filepath); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Indicates if the emulated system is powered on (all subsystems initialized and able to run an | ||
| 61 | * application). | ||
| 62 | * @returns True if the emulated system is powered on, otherwise false. | ||
| 63 | */ | ||
| 64 | bool IsPoweredOn() const { | ||
| 65 | return is_powered_on; | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Gets the internal state of the emulated system. | ||
| 70 | * @returns The internal state of the emulated system | ||
| 71 | */ | ||
| 72 | State& GetState() { | ||
| 73 | return state; | ||
| 74 | } | ||
| 75 | |||
| 76 | private: | ||
| 77 | bool is_powered_on{}; | ||
| 78 | State state; | ||
| 10 | 79 | ||
| 11 | enum class Result { | 80 | static System s_instance; |
| 12 | Success, ///< Everything is fine | ||
| 13 | Error, ///< Something went wrong (no module specified) | ||
| 14 | ErrorInitCore, ///< Something went wrong during core init | ||
| 15 | ErrorInitVideoCore, ///< Something went wrong during video core init | ||
| 16 | }; | 81 | }; |
| 17 | 82 | ||
| 18 | Result Init(EmuWindow* emu_window, u32 system_mode); | 83 | } // namespace Core |
| 19 | bool IsPoweredOn(); | ||
| 20 | void Shutdown(); | ||
| 21 | } | ||