main.cpp 7.0 KB

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