system.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "audio_core/audio_core.h"
  5. #include "core/core.h"
  6. #include "core/core_timing.h"
  7. #include "core/gdbstub/gdbstub.h"
  8. #include "core/hle/hle.h"
  9. #include "core/hle/kernel/kernel.h"
  10. #include "core/hle/kernel/memory.h"
  11. #include "core/hw/hw.h"
  12. #include "core/system.h"
  13. #include "video_core/video_core.h"
  14. namespace Core {
  15. /*static*/ System System::s_instance;
  16. System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
  17. Core::Init();
  18. CoreTiming::Init();
  19. Memory::Init();
  20. HW::Init();
  21. Kernel::Init(system_mode);
  22. HLE::Init();
  23. AudioCore::Init();
  24. GDBStub::Init();
  25. if (!VideoCore::Init(emu_window)) {
  26. return ResultStatus::ErrorVideoCore;
  27. }
  28. is_powered_on = true;
  29. return ResultStatus::Success;
  30. }
  31. void System::Shutdown() {
  32. GDBStub::Shutdown();
  33. AudioCore::Shutdown();
  34. VideoCore::Shutdown();
  35. HLE::Shutdown();
  36. Kernel::Shutdown();
  37. HW::Shutdown();
  38. CoreTiming::Shutdown();
  39. Core::Shutdown();
  40. is_powered_on = false;
  41. }
  42. System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) {
  43. state.app_loader = Loader::GetLoader(filepath);
  44. if (!state.app_loader) {
  45. LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str());
  46. return ResultStatus::ErrorGetLoader;
  47. }
  48. boost::optional<u32> system_mode{ state.app_loader->LoadKernelSystemMode() };
  49. if (!system_mode) {
  50. LOG_CRITICAL(Frontend, "Failed to determine system mode!");
  51. return ResultStatus::ErrorSystemMode;
  52. }
  53. ResultStatus init_result{ Init(emu_window, system_mode.get()) };
  54. if (init_result != ResultStatus::Success) {
  55. LOG_CRITICAL(Frontend, "Failed to initialize system (Error %i)!", init_result);
  56. System::Shutdown();
  57. return init_result;
  58. }
  59. const Loader::ResultStatus load_result{ state.app_loader->Load() };
  60. if (Loader::ResultStatus::Success != load_result) {
  61. LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result);
  62. System::Shutdown();
  63. switch (load_result) {
  64. case Loader::ResultStatus::ErrorEncrypted:
  65. return ResultStatus::ErrorLoader_ErrorEncrypted;
  66. case Loader::ResultStatus::ErrorInvalidFormat:
  67. return ResultStatus::ErrorLoader_ErrorInvalidFormat;
  68. default:
  69. return ResultStatus::ErrorLoader;
  70. }
  71. }
  72. return ResultStatus::Success;
  73. }
  74. } // namespace Core