yuzu.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <iostream>
  5. #include <memory>
  6. #include <string>
  7. #include <thread>
  8. #include "common/logging/backend.h"
  9. #include "common/logging/filter.h"
  10. #include "common/logging/log.h"
  11. #include "common/microprofile.h"
  12. #include "common/scm_rev.h"
  13. #include "common/scope_exit.h"
  14. #include "common/string_util.h"
  15. #include "core/core.h"
  16. #include "core/gdbstub/gdbstub.h"
  17. #include "core/loader/loader.h"
  18. #include "core/settings.h"
  19. #include "yuzu_cmd/config.h"
  20. #include "yuzu_cmd/emu_window/emu_window_sdl2.h"
  21. #ifdef _MSC_VER
  22. #include <getopt.h>
  23. #else
  24. #include <getopt.h>
  25. #include <unistd.h>
  26. #endif
  27. #ifdef _WIN32
  28. // windows.h needs to be included before shellapi.h
  29. #include <windows.h>
  30. #include <shellapi.h>
  31. #endif
  32. #ifdef _WIN32
  33. extern "C" {
  34. // tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
  35. // graphics
  36. __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
  37. __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
  38. }
  39. #endif
  40. static void PrintHelp(const char* argv0) {
  41. std::cout << "Usage: " << argv0
  42. << " [options] <filename>\n"
  43. "-g, --gdbport=NUMBER Enable gdb stub on port NUMBER\n"
  44. "-f, --fullscreen Start in fullscreen mode\n"
  45. "-h, --help Display this help and exit\n"
  46. "-v, --version Output version information and exit\n";
  47. }
  48. static void PrintVersion() {
  49. std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl;
  50. }
  51. /// Application entry point
  52. int main(int argc, char** argv) {
  53. Config config;
  54. int option_index = 0;
  55. bool use_gdbstub = Settings::values.use_gdbstub;
  56. u32 gdb_port = static_cast<u32>(Settings::values.gdbstub_port);
  57. char* endarg;
  58. #ifdef _WIN32
  59. int argc_w;
  60. auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
  61. if (argv_w == nullptr) {
  62. NGLOG_CRITICAL(Frontend, "Failed to get command line arguments");
  63. return -1;
  64. }
  65. #endif
  66. std::string filepath;
  67. bool fullscreen = false;
  68. static struct option long_options[] = {
  69. {"gdbport", required_argument, 0, 'g'},
  70. {"fullscreen", no_argument, 0, 'f'},
  71. {"help", no_argument, 0, 'h'},
  72. {"version", no_argument, 0, 'v'},
  73. {0, 0, 0, 0},
  74. };
  75. while (optind < argc) {
  76. char arg = getopt_long(argc, argv, "g:fhv", long_options, &option_index);
  77. if (arg != -1) {
  78. switch (arg) {
  79. case 'g':
  80. errno = 0;
  81. gdb_port = strtoul(optarg, &endarg, 0);
  82. use_gdbstub = true;
  83. if (endarg == optarg)
  84. errno = EINVAL;
  85. if (errno != 0) {
  86. perror("--gdbport");
  87. exit(1);
  88. }
  89. break;
  90. case 'f':
  91. fullscreen = true;
  92. NGLOG_INFO(Frontend, "Starting in fullscreen mode...");
  93. break;
  94. case 'h':
  95. PrintHelp(argv[0]);
  96. return 0;
  97. case 'v':
  98. PrintVersion();
  99. return 0;
  100. }
  101. } else {
  102. #ifdef _WIN32
  103. filepath = Common::UTF16ToUTF8(argv_w[optind]);
  104. #else
  105. filepath = argv[optind];
  106. #endif
  107. optind++;
  108. }
  109. }
  110. #ifdef _WIN32
  111. LocalFree(argv_w);
  112. #endif
  113. Log::Filter log_filter(Log::Level::Debug);
  114. Log::SetFilter(&log_filter);
  115. MicroProfileOnThreadCreate("EmuThread");
  116. SCOPE_EXIT({ MicroProfileShutdown(); });
  117. if (filepath.empty()) {
  118. NGLOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
  119. return -1;
  120. }
  121. log_filter.ParseFilterString(Settings::values.log_filter);
  122. // Apply the command line arguments
  123. Settings::values.gdbstub_port = gdb_port;
  124. Settings::values.use_gdbstub = use_gdbstub;
  125. Settings::Apply();
  126. std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)};
  127. Core::System& system{Core::System::GetInstance()};
  128. SCOPE_EXIT({ system.Shutdown(); });
  129. const Core::System::ResultStatus load_result{system.Load(emu_window.get(), filepath)};
  130. switch (load_result) {
  131. case Core::System::ResultStatus::ErrorGetLoader:
  132. NGLOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str());
  133. return -1;
  134. case Core::System::ResultStatus::ErrorLoader:
  135. NGLOG_CRITICAL(Frontend, "Failed to load ROM!");
  136. return -1;
  137. case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted:
  138. NGLOG_CRITICAL(Frontend, "The game that you are trying to load must be decrypted before "
  139. "being used with yuzu. \n\n For more information on dumping and "
  140. "decrypting games, please refer to: "
  141. "https://yuzu-emu.org/wiki/dumping-game-cartridges/");
  142. return -1;
  143. case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat:
  144. NGLOG_CRITICAL(Frontend, "Error while loading ROM: The ROM format is not supported.");
  145. return -1;
  146. case Core::System::ResultStatus::ErrorNotInitialized:
  147. NGLOG_CRITICAL(Frontend, "CPUCore not initialized");
  148. return -1;
  149. case Core::System::ResultStatus::ErrorSystemMode:
  150. NGLOG_CRITICAL(Frontend, "Failed to determine system mode!");
  151. return -1;
  152. case Core::System::ResultStatus::ErrorVideoCore:
  153. NGLOG_CRITICAL(Frontend, "VideoCore not initialized");
  154. return -1;
  155. case Core::System::ResultStatus::Success:
  156. break; // Expected case
  157. }
  158. Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "SDL");
  159. while (emu_window->IsOpen()) {
  160. system.RunLoop();
  161. }
  162. return 0;
  163. }