citra.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // This needs to be included before getopt.h because the latter #defines symbols used by it
  8. #include "common/microprofile.h"
  9. #ifdef _MSC_VER
  10. #include <getopt.h>
  11. #else
  12. #include <unistd.h>
  13. #include <getopt.h>
  14. #endif
  15. #include "common/logging/log.h"
  16. #include "common/logging/backend.h"
  17. #include "common/logging/filter.h"
  18. #include "core/settings.h"
  19. #include "core/system.h"
  20. #include "core/core.h"
  21. #include "core/loader/loader.h"
  22. #include "citra/config.h"
  23. #include "citra/emu_window/emu_window_glfw.h"
  24. #include "video_core/video_core.h"
  25. #include "core/gdbstub/gdbstub.h"
  26. static void PrintHelp()
  27. {
  28. std::cout << "Usage: citra <filename>" << std::endl;
  29. }
  30. /// Application entry point
  31. int main(int argc, char **argv) {
  32. int option_index = 0;
  33. std::string boot_filename;
  34. static struct option long_options[] = {
  35. { "help", no_argument, 0, 'h' },
  36. { 0, 0, 0, 0 }
  37. };
  38. while (optind < argc) {
  39. char arg = getopt_long(argc, argv, ":h", long_options, &option_index);
  40. if (arg != -1) {
  41. switch (arg) {
  42. case 'h':
  43. PrintHelp();
  44. return 0;
  45. }
  46. } else {
  47. boot_filename = argv[optind];
  48. optind++;
  49. }
  50. }
  51. Log::Filter log_filter(Log::Level::Debug);
  52. Log::SetFilter(&log_filter);
  53. MicroProfileOnThreadCreate("EmuThread");
  54. if (boot_filename.empty()) {
  55. LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
  56. return -1;
  57. }
  58. Config config;
  59. log_filter.ParseFilterString(Settings::values.log_filter);
  60. GDBStub::SetServerPort(static_cast<u32>(Settings::values.gdbstub_port));
  61. EmuWindow_GLFW* emu_window = new EmuWindow_GLFW;
  62. VideoCore::g_hw_renderer_enabled = Settings::values.use_hw_renderer;
  63. VideoCore::g_shader_jit_enabled = Settings::values.use_shader_jit;
  64. System::Init(emu_window);
  65. Loader::ResultStatus load_result = Loader::LoadFile(boot_filename);
  66. if (Loader::ResultStatus::Success != load_result) {
  67. LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result);
  68. return -1;
  69. }
  70. while (emu_window->IsOpen()) {
  71. Core::RunLoop();
  72. }
  73. System::Shutdown();
  74. delete emu_window;
  75. MicroProfileShutdown();
  76. return 0;
  77. }