diff options
Diffstat (limited to '')
| -rw-r--r-- | src/citra/citra.cpp | 15 | ||||
| -rw-r--r-- | src/citra_qt/main.cpp | 24 | ||||
| -rw-r--r-- | src/citra_qt/main.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 4 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 11 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 9 | ||||
| -rw-r--r-- | src/core/loader/ncch.h | 7 | ||||
| -rw-r--r-- | src/core/system.cpp | 4 | ||||
| -rw-r--r-- | src/core/system.h | 2 |
10 files changed, 67 insertions, 22 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index e47375f88..c742be231 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp | |||
| @@ -129,16 +129,23 @@ int main(int argc, char** argv) { | |||
| 129 | 129 | ||
| 130 | std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>(); | 130 | std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>(); |
| 131 | 131 | ||
| 132 | System::Init(emu_window.get()); | ||
| 133 | SCOPE_EXIT({ System::Shutdown(); }); | ||
| 134 | |||
| 135 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename); | 132 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename); |
| 136 | if (!loader) { | 133 | if (!loader) { |
| 137 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); | 134 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); |
| 138 | return -1; | 135 | return -1; |
| 139 | } | 136 | } |
| 140 | 137 | ||
| 141 | Loader::ResultStatus load_result = loader->Load(); | 138 | u32 system_mode; |
| 139 | Loader::ResultStatus load_result = loader->LoadKernelSystemMode(system_mode); | ||
| 140 | if (Loader::ResultStatus::Success != load_result) { | ||
| 141 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); | ||
| 142 | return -1; | ||
| 143 | } | ||
| 144 | |||
| 145 | System::Init(emu_window.get(), system_mode); | ||
| 146 | SCOPE_EXIT({ System::Shutdown(); }); | ||
| 147 | |||
| 148 | load_result = loader->Load(); | ||
| 142 | if (Loader::ResultStatus::Success != load_result) { | 149 | if (Loader::ResultStatus::Success != load_result) { |
| 143 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); | 150 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); |
| 144 | return -1; | 151 | return -1; |
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0bf9f48d6..9589da4ba 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp | |||
| @@ -253,7 +253,7 @@ void GMainWindow::OnDisplayTitleBars(bool show) { | |||
| 253 | } | 253 | } |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | bool GMainWindow::InitializeSystem() { | 256 | bool GMainWindow::InitializeSystem(u32 system_mode) { |
| 257 | // Shutdown previous session if the emu thread is still active... | 257 | // Shutdown previous session if the emu thread is still active... |
| 258 | if (emu_thread != nullptr) | 258 | if (emu_thread != nullptr) |
| 259 | ShutdownGame(); | 259 | ShutdownGame(); |
| @@ -270,7 +270,7 @@ bool GMainWindow::InitializeSystem() { | |||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | // Initialize the core emulation | 272 | // Initialize the core emulation |
| 273 | System::Result system_result = System::Init(render_window); | 273 | System::Result system_result = System::Init(render_window, system_mode); |
| 274 | if (System::Result::Success != system_result) { | 274 | if (System::Result::Success != system_result) { |
| 275 | switch (system_result) { | 275 | switch (system_result) { |
| 276 | case System::Result::ErrorInitVideoCore: | 276 | case System::Result::ErrorInitVideoCore: |
| @@ -299,8 +299,21 @@ bool GMainWindow::LoadROM(const std::string& filename) { | |||
| 299 | return false; | 299 | return false; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | u32 system_mode; | ||
| 303 | Loader::ResultStatus load_result = app_loader->LoadKernelSystemMode(system_mode); | ||
| 304 | if (Loader::ResultStatus::Success != load_result) { | ||
| 305 | LOG_CRITICAL(Frontend, "Failed to load ROM!", load_result); | ||
| 306 | QMessageBox::critical(this, tr("Error while loading ROM!"), | ||
| 307 | tr("Could not determine the system mode.")); | ||
| 308 | return false; | ||
| 309 | } | ||
| 310 | |||
| 311 | if (!InitializeSystem(system_mode)) | ||
| 312 | return false; | ||
| 313 | |||
| 302 | Loader::ResultStatus result = app_loader->Load(); | 314 | Loader::ResultStatus result = app_loader->Load(); |
| 303 | if (Loader::ResultStatus::Success != result) { | 315 | if (Loader::ResultStatus::Success != result) { |
| 316 | System::Shutdown(); | ||
| 304 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); | 317 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); |
| 305 | 318 | ||
| 306 | switch (result) { | 319 | switch (result) { |
| @@ -338,14 +351,9 @@ void GMainWindow::BootGame(const std::string& filename) { | |||
| 338 | LOG_INFO(Frontend, "Citra starting..."); | 351 | LOG_INFO(Frontend, "Citra starting..."); |
| 339 | StoreRecentFile(filename); // Put the filename on top of the list | 352 | StoreRecentFile(filename); // Put the filename on top of the list |
| 340 | 353 | ||
| 341 | if (!InitializeSystem()) | 354 | if (!LoadROM(filename)) |
| 342 | return; | 355 | return; |
| 343 | 356 | ||
| 344 | if (!LoadROM(filename)) { | ||
| 345 | System::Shutdown(); | ||
| 346 | return; | ||
| 347 | } | ||
| 348 | |||
| 349 | // Create and start the emulation thread | 357 | // Create and start the emulation thread |
| 350 | emu_thread = std::make_unique<EmuThread>(render_window); | 358 | emu_thread = std::make_unique<EmuThread>(render_window); |
| 351 | emit EmulationStarting(emu_thread.get()); | 359 | emit EmulationStarting(emu_thread.get()); |
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 82eb90aae..f87178227 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h | |||
| @@ -60,7 +60,12 @@ signals: | |||
| 60 | void EmulationStopping(); | 60 | void EmulationStopping(); |
| 61 | 61 | ||
| 62 | private: | 62 | private: |
| 63 | bool InitializeSystem(); | 63 | /** |
| 64 | * Initializes the emulation system. | ||
| 65 | * @param system_mode The system mode with which to intialize the kernel. | ||
| 66 | * @returns Whether the system was properly initialized. | ||
| 67 | */ | ||
| 68 | bool InitializeSystem(u32 system_mode); | ||
| 64 | bool LoadROM(const std::string& filename); | 69 | bool LoadROM(const std::string& filename); |
| 65 | void BootGame(const std::string& filename); | 70 | void BootGame(const std::string& filename); |
| 66 | void ShutdownGame(); | 71 | void ShutdownGame(); |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 9e1795927..0c8752670 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -124,13 +124,11 @@ void HandleTable::Clear() { | |||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | /// Initialize the kernel | 126 | /// Initialize the kernel |
| 127 | void Init() { | 127 | void Init(u32 system_mode) { |
| 128 | ConfigMem::Init(); | 128 | ConfigMem::Init(); |
| 129 | SharedPage::Init(); | 129 | SharedPage::Init(); |
| 130 | 130 | ||
| 131 | // TODO(yuriks): The memory type parameter needs to be determined by the ExHeader field instead | 131 | Kernel::MemoryInit(system_mode); |
| 132 | // For now it defaults to the one with a largest allocation to the app | ||
| 133 | Kernel::MemoryInit(2); // Allocates 96MB to the application | ||
| 134 | 132 | ||
| 135 | Kernel::ResourceLimitsInit(); | 133 | Kernel::ResourceLimitsInit(); |
| 136 | Kernel::ThreadingInit(); | 134 | Kernel::ThreadingInit(); |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 6b8dbecff..231cf7b75 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -286,8 +286,8 @@ private: | |||
| 286 | 286 | ||
| 287 | extern HandleTable g_handle_table; | 287 | extern HandleTable g_handle_table; |
| 288 | 288 | ||
| 289 | /// Initialize the kernel | 289 | /// Initialize the kernel with the specified system mode. |
| 290 | void Init(); | 290 | void Init(u32 system_mode); |
| 291 | 291 | ||
| 292 | /// Shutdown the kernel | 292 | /// Shutdown the kernel |
| 293 | void Shutdown(); | 293 | void Shutdown(); |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 9652d7ac5..e62f77b9c 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -96,6 +96,17 @@ public: | |||
| 96 | virtual ResultStatus Load() = 0; | 96 | virtual ResultStatus Load() = 0; |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | * Loads the system mode that this application needs. | ||
| 100 | * This function defaults to 2 (96MB allocated to the application) if it can't read the information. | ||
| 101 | * @param system_mode Out variable where the system mode will be stored. | ||
| 102 | * @returns ResultStatus result of the operation | ||
| 103 | */ | ||
| 104 | virtual ResultStatus LoadKernelSystemMode(u32& system_mode) { | ||
| 105 | system_mode = 2; // 96MB allocated to the application. | ||
| 106 | return ResultStatus::Success; | ||
| 107 | } | ||
| 108 | |||
| 109 | /** | ||
| 99 | * Get the code (typically .code section) of the application | 110 | * Get the code (typically .code section) of the application |
| 100 | * @param buffer Reference to buffer to store data | 111 | * @param buffer Reference to buffer to store data |
| 101 | * @return ResultStatus result of function | 112 | * @return ResultStatus result of function |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index fadd7b16b..6fbaf4036 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -117,6 +117,14 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { | |||
| 117 | return FileType::Error; | 117 | return FileType::Error; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | ResultStatus AppLoader_NCCH::LoadKernelSystemMode(u32& memory_type) { | ||
| 121 | ResultStatus result = LoadExeFS(); | ||
| 122 | if (result != ResultStatus::Success) | ||
| 123 | return result; | ||
| 124 | memory_type = exheader_header.arm11_system_local_caps.system_mode; | ||
| 125 | return ResultStatus::Success; | ||
| 126 | } | ||
| 127 | |||
| 120 | ResultStatus AppLoader_NCCH::LoadExec() { | 128 | ResultStatus AppLoader_NCCH::LoadExec() { |
| 121 | using Kernel::SharedPtr; | 129 | using Kernel::SharedPtr; |
| 122 | using Kernel::CodeSet; | 130 | using Kernel::CodeSet; |
| @@ -277,6 +285,7 @@ ResultStatus AppLoader_NCCH::LoadExeFS() { | |||
| 277 | LOG_DEBUG(Loader, "Core version: %d", core_version); | 285 | LOG_DEBUG(Loader, "Core version: %d", core_version); |
| 278 | LOG_DEBUG(Loader, "Thread priority: 0x%X", priority); | 286 | LOG_DEBUG(Loader, "Thread priority: 0x%X", priority); |
| 279 | LOG_DEBUG(Loader, "Resource limit category: %d", resource_limit_category); | 287 | LOG_DEBUG(Loader, "Resource limit category: %d", resource_limit_category); |
| 288 | LOG_DEBUG(Loader, "System Mode: %d", exheader_header.arm11_system_local_caps.system_mode); | ||
| 280 | 289 | ||
| 281 | if (exheader_header.arm11_system_local_caps.program_id != ncch_header.program_id) { | 290 | if (exheader_header.arm11_system_local_caps.program_id != ncch_header.program_id) { |
| 282 | LOG_ERROR(Loader, "ExHeader Program ID mismatch: the ROM is probably encrypted."); | 291 | LOG_ERROR(Loader, "ExHeader Program ID mismatch: the ROM is probably encrypted."); |
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index f8718d063..63947c28e 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h | |||
| @@ -186,6 +186,13 @@ public: | |||
| 186 | ResultStatus Load() override; | 186 | ResultStatus Load() override; |
| 187 | 187 | ||
| 188 | /** | 188 | /** |
| 189 | * Loads the Exheader and returns the system mode for this application. | ||
| 190 | * @param system_mode Out variable where the system mode will be stored. | ||
| 191 | * @return ResultStatus result of the operation | ||
| 192 | */ | ||
| 193 | ResultStatus LoadKernelSystemMode(u32& system_mode); | ||
| 194 | |||
| 195 | /** | ||
| 189 | * Get the code (typically .code section) of the application | 196 | * Get the code (typically .code section) of the application |
| 190 | * @param buffer Reference to buffer to store data | 197 | * @param buffer Reference to buffer to store data |
| 191 | * @return ResultStatus result of function | 198 | * @return ResultStatus result of function |
diff --git a/src/core/system.cpp b/src/core/system.cpp index 7d54811a0..a5f763805 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp | |||
| @@ -17,12 +17,12 @@ namespace System { | |||
| 17 | 17 | ||
| 18 | static bool is_powered_on{false}; | 18 | static bool is_powered_on{false}; |
| 19 | 19 | ||
| 20 | Result Init(EmuWindow* emu_window) { | 20 | Result 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(); | 25 | Kernel::Init(system_mode); |
| 26 | HLE::Init(); | 26 | HLE::Init(); |
| 27 | if (!VideoCore::Init(emu_window)) { | 27 | if (!VideoCore::Init(emu_window)) { |
| 28 | return Result::ErrorInitVideoCore; | 28 | return Result::ErrorInitVideoCore; |
diff --git a/src/core/system.h b/src/core/system.h index 6d672b1b5..b41fc088a 100644 --- a/src/core/system.h +++ b/src/core/system.h | |||
| @@ -15,7 +15,7 @@ enum class Result { | |||
| 15 | ErrorInitVideoCore, ///< Something went wrong during video core init | 15 | ErrorInitVideoCore, ///< Something went wrong during video core init |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | Result Init(EmuWindow* emu_window); | 18 | Result Init(EmuWindow* emu_window, u32 system_mode); |
| 19 | bool IsPoweredOn(); | 19 | bool IsPoweredOn(); |
| 20 | void Shutdown(); | 20 | void Shutdown(); |
| 21 | } | 21 | } |