yuzu.cpp 5.6 KB

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