main.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #include <QtGui>
  2. #include <QDesktopWidget>
  3. #include <QFileDialog>
  4. #include "qhexedit.h"
  5. #include "main.hxx"
  6. #include "common/common.h"
  7. #include "common/platform.h"
  8. #include "common/log_manager.h"
  9. #if EMU_PLATFORM == PLATFORM_LINUX
  10. #include <unistd.h>
  11. #endif
  12. #include "bootmanager.hxx"
  13. #include "hotkeys.hxx"
  14. //debugger
  15. #include "debugger/disassembler.hxx"
  16. #include "debugger/registers.hxx"
  17. #include "debugger/callstack.hxx"
  18. #include "debugger/ramview.hxx"
  19. #include "debugger/graphics.hxx"
  20. #include "debugger/graphics_cmdlists.hxx"
  21. #include "core/settings.h"
  22. #include "core/system.h"
  23. #include "core/core.h"
  24. #include "core/loader/loader.h"
  25. #include "core/arm/disassembler/load_symbol_map.h"
  26. #include "citra_qt/config.h"
  27. #include "version.h"
  28. GMainWindow::GMainWindow()
  29. {
  30. LogManager::Init();
  31. Config config;
  32. if (!Settings::values.enable_log)
  33. LogManager::Shutdown();
  34. ui.setupUi(this);
  35. statusBar()->hide();
  36. render_window = new GRenderWindow;
  37. render_window->hide();
  38. disasmWidget = new DisassemblerWidget(this, render_window->GetEmuThread());
  39. addDockWidget(Qt::BottomDockWidgetArea, disasmWidget);
  40. disasmWidget->hide();
  41. registersWidget = new RegistersWidget(this);
  42. addDockWidget(Qt::RightDockWidgetArea, registersWidget);
  43. registersWidget->hide();
  44. callstackWidget = new CallstackWidget(this);
  45. addDockWidget(Qt::RightDockWidgetArea, callstackWidget);
  46. callstackWidget->hide();
  47. graphicsWidget = new GPUCommandStreamWidget(this);
  48. addDockWidget(Qt::RightDockWidgetArea, graphicsWidget);
  49. graphicsWidget ->hide();
  50. graphicsCommandsWidget = new GPUCommandListWidget(this);
  51. addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget);
  52. graphicsCommandsWidget->hide();
  53. QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging"));
  54. debug_menu->addAction(disasmWidget->toggleViewAction());
  55. debug_menu->addAction(registersWidget->toggleViewAction());
  56. debug_menu->addAction(callstackWidget->toggleViewAction());
  57. debug_menu->addAction(graphicsWidget->toggleViewAction());
  58. debug_menu->addAction(graphicsCommandsWidget->toggleViewAction());
  59. // Set default UI state
  60. // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
  61. QDesktopWidget* desktop = ((QApplication*)QApplication::instance())->desktop();
  62. QRect screenRect = desktop->screenGeometry(this);
  63. int x, y, w, h;
  64. w = screenRect.width() * 2 / 3;
  65. h = screenRect.height() / 2;
  66. x = (screenRect.x() + screenRect.width()) / 2 - w / 2;
  67. y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100;
  68. setGeometry(x, y, w, h);
  69. // Restore UI state
  70. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Citra team", "Citra");
  71. restoreGeometry(settings.value("geometry").toByteArray());
  72. restoreState(settings.value("state").toByteArray());
  73. render_window->restoreGeometry(settings.value("geometryRenderWindow").toByteArray());
  74. ui.action_Popout_Window_Mode->setChecked(settings.value("popoutWindowMode", true).toBool());
  75. ToggleWindowMode();
  76. // Setup connections
  77. connect(ui.action_Load_File, SIGNAL(triggered()), this, SLOT(OnMenuLoadFile()));
  78. connect(ui.action_Load_Symbol_Map, SIGNAL(triggered()), this, SLOT(OnMenuLoadSymbolMap()));
  79. connect(ui.action_Start, SIGNAL(triggered()), this, SLOT(OnStartGame()));
  80. connect(ui.action_Pause, SIGNAL(triggered()), this, SLOT(OnPauseGame()));
  81. connect(ui.action_Stop, SIGNAL(triggered()), this, SLOT(OnStopGame()));
  82. connect(ui.action_Popout_Window_Mode, SIGNAL(triggered(bool)), this, SLOT(ToggleWindowMode()));
  83. connect(ui.action_Hotkeys, SIGNAL(triggered()), this, SLOT(OnOpenHotkeysDialog()));
  84. // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
  85. connect(&render_window->GetEmuThread(), SIGNAL(CPUStepped()), disasmWidget, SLOT(OnCPUStepped()), Qt::BlockingQueuedConnection);
  86. connect(&render_window->GetEmuThread(), SIGNAL(CPUStepped()), registersWidget, SLOT(OnCPUStepped()), Qt::BlockingQueuedConnection);
  87. connect(&render_window->GetEmuThread(), SIGNAL(CPUStepped()), callstackWidget, SLOT(OnCPUStepped()), Qt::BlockingQueuedConnection);
  88. // Setup hotkeys
  89. RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
  90. RegisterHotkey("Main Window", "Start Emulation");
  91. LoadHotkeys(settings);
  92. connect(GetHotkey("Main Window", "Load File", this), SIGNAL(activated()), this, SLOT(OnMenuLoadFile()));
  93. connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this, SLOT(OnStartGame()));
  94. setWindowTitle(render_window->GetWindowTitle().c_str());
  95. show();
  96. QStringList args = QApplication::arguments();
  97. if (args.length() >= 2) {
  98. BootGame(args[1].toStdString());
  99. }
  100. }
  101. GMainWindow::~GMainWindow()
  102. {
  103. // will get automatically deleted otherwise
  104. if (render_window->parent() == NULL)
  105. delete render_window;
  106. }
  107. void GMainWindow::BootGame(std::string filename)
  108. {
  109. NOTICE_LOG(MASTER_LOG, "Citra starting...\n");
  110. System::Init(render_window);
  111. if (Core::Init()) {
  112. ERROR_LOG(MASTER_LOG, "Core initialization failed, exiting...");
  113. Core::Stop();
  114. exit(1);
  115. }
  116. // Load a game or die...
  117. if (Loader::ResultStatus::Success != Loader::LoadFile(filename)) {
  118. ERROR_LOG(BOOT, "Failed to load ROM!");
  119. }
  120. disasmWidget->Init();
  121. registersWidget->OnCPUStepped();
  122. callstackWidget->OnCPUStepped();
  123. render_window->GetEmuThread().SetFilename(filename);
  124. render_window->GetEmuThread().start();
  125. render_window->show();
  126. OnStartGame();
  127. }
  128. void GMainWindow::OnMenuLoadFile()
  129. {
  130. QString filename = QFileDialog::getOpenFileName(this, tr("Load file"), QString(), tr("3DS executable (*.elf *.axf *.bin *.cci *.cxi)"));
  131. if (filename.size())
  132. BootGame(filename.toLatin1().data());
  133. }
  134. void GMainWindow::OnMenuLoadSymbolMap() {
  135. QString filename = QFileDialog::getOpenFileName(this, tr("Load symbol map"), QString(), tr("Symbol map (*)"));
  136. if (filename.size())
  137. LoadSymbolMap(filename.toLatin1().data());
  138. }
  139. void GMainWindow::OnStartGame()
  140. {
  141. render_window->GetEmuThread().SetCpuRunning(true);
  142. ui.action_Start->setEnabled(false);
  143. ui.action_Pause->setEnabled(true);
  144. ui.action_Stop->setEnabled(true);
  145. }
  146. void GMainWindow::OnPauseGame()
  147. {
  148. render_window->GetEmuThread().SetCpuRunning(false);
  149. ui.action_Start->setEnabled(true);
  150. ui.action_Pause->setEnabled(false);
  151. ui.action_Stop->setEnabled(true);
  152. }
  153. void GMainWindow::OnStopGame()
  154. {
  155. render_window->GetEmuThread().SetCpuRunning(false);
  156. // TODO: Shutdown core
  157. ui.action_Start->setEnabled(true);
  158. ui.action_Pause->setEnabled(false);
  159. ui.action_Stop->setEnabled(false);
  160. }
  161. void GMainWindow::OnOpenHotkeysDialog()
  162. {
  163. GHotkeysDialog dialog(this);
  164. dialog.exec();
  165. }
  166. void GMainWindow::ToggleWindowMode()
  167. {
  168. bool enable = ui.action_Popout_Window_Mode->isChecked();
  169. if (enable && render_window->parent() != NULL)
  170. {
  171. ui.horizontalLayout->removeWidget(render_window);
  172. render_window->setParent(NULL);
  173. render_window->setVisible(true);
  174. render_window->RestoreGeometry();
  175. }
  176. else if (!enable && render_window->parent() == NULL)
  177. {
  178. render_window->BackupGeometry();
  179. ui.horizontalLayout->addWidget(render_window);
  180. render_window->setVisible(true);
  181. }
  182. }
  183. void GMainWindow::OnConfigure()
  184. {
  185. //GControllerConfigDialog* dialog = new GControllerConfigDialog(controller_ports, this);
  186. }
  187. void GMainWindow::closeEvent(QCloseEvent* event)
  188. {
  189. // Save window layout
  190. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Citra team", "Citra");
  191. settings.setValue("geometry", saveGeometry());
  192. settings.setValue("state", saveState());
  193. settings.setValue("geometryRenderWindow", render_window->saveGeometry());
  194. settings.setValue("popoutWindowMode", ui.action_Popout_Window_Mode->isChecked());
  195. settings.setValue("firstStart", false);
  196. SaveHotkeys(settings);
  197. render_window->close();
  198. QWidget::closeEvent(event);
  199. }
  200. #ifdef main
  201. #undef main
  202. #endif
  203. int __cdecl main(int argc, char* argv[])
  204. {
  205. QApplication::setAttribute(Qt::AA_X11InitThreads);
  206. QApplication app(argc, argv);
  207. GMainWindow main_window;
  208. main_window.show();
  209. return app.exec();
  210. }