citra.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <string>
  5. #include <thread>
  6. #include <iostream>
  7. #include <memory>
  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 <unistd.h>
  14. #include <getopt.h>
  15. #endif
  16. #include "common/logging/log.h"
  17. #include "common/logging/backend.h"
  18. #include "common/logging/filter.h"
  19. #include "common/scope_exit.h"
  20. #include "core/settings.h"
  21. #include "core/system.h"
  22. #include "core/core.h"
  23. #include "core/gdbstub/gdbstub.h"
  24. #include "core/loader/loader.h"
  25. #include "citra/config.h"
  26. #include "citra/emu_window/emu_window_sdl2.h"
  27. #include "video_core/video_core.h"
  28. static void PrintHelp()
  29. {
  30. std::cout << "Usage: citra [options] <filename>" << std::endl;
  31. std::cout << "--help, -h Display this information" << std::endl;
  32. std::cout << "--gdbport, -g number Enable gdb stub on port number" << std::endl;
  33. }
  34. /// Application entry point
  35. int main(int argc, char **argv) {
  36. Config config;
  37. int option_index = 0;
  38. bool use_gdbstub = Settings::values.use_gdbstub;
  39. u32 gdb_port = static_cast<u32>(Settings::values.gdbstub_port);
  40. char *endarg;
  41. std::string boot_filename;
  42. static struct option long_options[] = {
  43. { "help", no_argument, 0, 'h' },
  44. { "gdbport", required_argument, 0, 'g' },
  45. { 0, 0, 0, 0 }
  46. };
  47. while (optind < argc) {
  48. char arg = getopt_long(argc, argv, ":hg:", long_options, &option_index);
  49. if (arg != -1) {
  50. switch (arg) {
  51. case 'h':
  52. PrintHelp();
  53. return 0;
  54. case 'g':
  55. errno = 0;
  56. gdb_port = strtoul(optarg, &endarg, 0);
  57. use_gdbstub = true;
  58. if (endarg == optarg) errno = EINVAL;
  59. if (errno != 0) {
  60. perror("--gdbport");
  61. exit(1);
  62. }
  63. break;
  64. }
  65. } else {
  66. boot_filename = argv[optind];
  67. optind++;
  68. }
  69. }
  70. Log::Filter log_filter(Log::Level::Debug);
  71. Log::SetFilter(&log_filter);
  72. MicroProfileOnThreadCreate("EmuThread");
  73. SCOPE_EXIT({ MicroProfileShutdown(); });
  74. if (boot_filename.empty()) {
  75. LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
  76. return -1;
  77. }
  78. log_filter.ParseFilterString(Settings::values.log_filter);
  79. // Apply the command line arguments
  80. Settings::values.gdbstub_port = gdb_port;
  81. Settings::values.use_gdbstub = use_gdbstub;
  82. Settings::Apply();
  83. std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>();
  84. System::Init(emu_window.get());
  85. SCOPE_EXIT({ System::Shutdown(); });
  86. Loader::ResultStatus load_result = Loader::LoadFile(boot_filename);
  87. if (Loader::ResultStatus::Success != load_result) {
  88. LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result);
  89. return -1;
  90. }
  91. while (emu_window->IsOpen()) {
  92. Core::RunLoop();
  93. }
  94. return 0;
  95. }