yuzu.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. "-h, --help Display this help and exit\n"
  38. "-v, --version Output version information and exit\n";
  39. }
  40. static void PrintVersion() {
  41. std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl;
  42. }
  43. /// Application entry point
  44. int main(int argc, char** argv) {
  45. Config config;
  46. int option_index = 0;
  47. bool use_gdbstub = Settings::values.use_gdbstub;
  48. u32 gdb_port = static_cast<u32>(Settings::values.gdbstub_port);
  49. char* endarg;
  50. #ifdef _WIN32
  51. int argc_w;
  52. auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
  53. if (argv_w == nullptr) {
  54. LOG_CRITICAL(Frontend, "Failed to get command line arguments");
  55. return -1;
  56. }
  57. #endif
  58. std::string filepath;
  59. static struct option long_options[] = {
  60. {"gdbport", required_argument, 0, 'g'},
  61. {"help", no_argument, 0, 'h'},
  62. {"version", no_argument, 0, 'v'},
  63. {0, 0, 0, 0},
  64. };
  65. while (optind < argc) {
  66. char arg = getopt_long(argc, argv, "g:hv", long_options, &option_index);
  67. if (arg != -1) {
  68. switch (arg) {
  69. case 'g':
  70. errno = 0;
  71. gdb_port = strtoul(optarg, &endarg, 0);
  72. use_gdbstub = true;
  73. if (endarg == optarg)
  74. errno = EINVAL;
  75. if (errno != 0) {
  76. perror("--gdbport");
  77. exit(1);
  78. }
  79. break;
  80. case 'h':
  81. PrintHelp(argv[0]);
  82. return 0;
  83. case 'v':
  84. PrintVersion();
  85. return 0;
  86. }
  87. } else {
  88. #ifdef _WIN32
  89. filepath = Common::UTF16ToUTF8(argv_w[optind]);
  90. #else
  91. filepath = argv[optind];
  92. #endif
  93. optind++;
  94. }
  95. }
  96. #ifdef _WIN32
  97. LocalFree(argv_w);
  98. #endif
  99. Log::Filter log_filter(Log::Level::Debug);
  100. Log::SetFilter(&log_filter);
  101. MicroProfileOnThreadCreate("EmuThread");
  102. SCOPE_EXIT({ MicroProfileShutdown(); });
  103. if (filepath.empty()) {
  104. LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
  105. return -1;
  106. }
  107. log_filter.ParseFilterString(Settings::values.log_filter);
  108. // Apply the command line arguments
  109. Settings::values.gdbstub_port = gdb_port;
  110. Settings::values.use_gdbstub = use_gdbstub;
  111. Settings::Apply();
  112. std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>()};
  113. Core::System& system{Core::System::GetInstance()};
  114. SCOPE_EXIT({ system.Shutdown(); });
  115. const Core::System::ResultStatus load_result{system.Load(emu_window.get(), filepath)};
  116. switch (load_result) {
  117. case Core::System::ResultStatus::ErrorGetLoader:
  118. LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str());
  119. return -1;
  120. case Core::System::ResultStatus::ErrorLoader:
  121. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  122. return -1;
  123. case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted:
  124. LOG_CRITICAL(Frontend, "The game that you are trying to load must be decrypted before "
  125. "being used with yuzu. \n\n For more information on dumping and "
  126. "decrypting games, please refer to: "
  127. "https://citra-emu.org/wiki/dumping-game-cartridges/");
  128. return -1;
  129. case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat:
  130. LOG_CRITICAL(Frontend, "Error while loading ROM: The ROM format is not supported.");
  131. return -1;
  132. case Core::System::ResultStatus::ErrorNotInitialized:
  133. LOG_CRITICAL(Frontend, "CPUCore not initialized");
  134. return -1;
  135. case Core::System::ResultStatus::ErrorSystemMode:
  136. LOG_CRITICAL(Frontend, "Failed to determine system mode!");
  137. return -1;
  138. case Core::System::ResultStatus::ErrorVideoCore:
  139. LOG_CRITICAL(Frontend, "VideoCore not initialized");
  140. return -1;
  141. case Core::System::ResultStatus::Success:
  142. break; // Expected case
  143. }
  144. Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "SDL");
  145. while (emu_window->IsOpen()) {
  146. system.RunLoop();
  147. }
  148. return 0;
  149. }