main.cpp 8.1 KB

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