trunk/src/osd/sdl/debugqt.c
| r20435 | r20436 | |
| 16 | 16 | |
| 17 | 17 | #include "emu.h" |
| 18 | 18 | #include "osdsdl.h" |
| 19 | #include "config.h" |
| 19 | 20 | #include "debugger.h" |
| 20 | 21 | |
| 21 | 22 | #include "debugqtmainwindow.h" |
| 23 | #include "debugqtmemorywindow.h" |
| 24 | #include "debugqtdasmwindow.h" |
| 25 | #include "debugqtlogwindow.h" |
| 22 | 26 | |
| 23 | 27 | |
| 24 | 28 | //============================================================ |
| r20435 | r20436 | |
| 33 | 37 | |
| 34 | 38 | |
| 35 | 39 | //============================================================ |
| 40 | // XML configuration save/load |
| 41 | //============================================================ |
| 42 | |
| 43 | // Global variable used to feed the xml configuration callbacks |
| 44 | std::vector<WindowQtConfig> xmlConfigurations; |
| 45 | |
| 46 | static void xml_configuration_load(running_machine &machine, int config_type, xml_data_node *parentnode) |
| 47 | { |
| 48 | xml_data_node *wnode; |
| 49 | |
| 50 | // We only care about game files |
| 51 | if (config_type != CONFIG_TYPE_GAME) |
| 52 | return; |
| 53 | |
| 54 | // Might not have any data |
| 55 | if (parentnode == NULL) |
| 56 | return; |
| 57 | |
| 58 | xmlConfigurations.clear(); |
| 59 | |
| 60 | // Configuration load |
| 61 | for (wnode = xml_get_sibling(parentnode->child, "window"); wnode != NULL; wnode = xml_get_sibling(wnode->next, "window")) |
| 62 | { |
| 63 | WindowQtConfig config; |
| 64 | config.m_size.setX(xml_get_attribute_int(wnode, "size_x", config.m_size.x())); |
| 65 | config.m_size.setY(xml_get_attribute_int(wnode, "size_y", config.m_size.y())); |
| 66 | config.m_position.setX(xml_get_attribute_int(wnode, "position_x", config.m_position.x())); |
| 67 | config.m_position.setY(xml_get_attribute_int(wnode, "position_y", config.m_position.y())); |
| 68 | config.m_type = (WindowQtConfig::WindowType)xml_get_attribute_int(wnode, "type", config.m_type); |
| 69 | xmlConfigurations.push_back(config); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | static void xml_configuration_save(running_machine &machine, int config_type, xml_data_node *parentnode) |
| 75 | { |
| 76 | // We only care about game files |
| 77 | if (config_type != CONFIG_TYPE_GAME) |
| 78 | return; |
| 79 | |
| 80 | for (int i = 0; i < xmlConfigurations.size(); i++) |
| 81 | { |
| 82 | // Create an xml node |
| 83 | xml_data_node *debugger_node; |
| 84 | debugger_node = xml_add_child(parentnode, "window", NULL); |
| 85 | if (debugger_node == NULL) |
| 86 | continue; |
| 87 | |
| 88 | xml_set_attribute_int(debugger_node, "type", xmlConfigurations[i].m_type); |
| 89 | xml_set_attribute_int(debugger_node, "position_x", xmlConfigurations[i].m_position.x()); |
| 90 | xml_set_attribute_int(debugger_node, "position_y", xmlConfigurations[i].m_position.y()); |
| 91 | xml_set_attribute_int(debugger_node, "size_x", xmlConfigurations[i].m_size.x()); |
| 92 | xml_set_attribute_int(debugger_node, "size_y", xmlConfigurations[i].m_size.y()); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | |
| 97 | static void gather_save_configurations() |
| 98 | { |
| 99 | xmlConfigurations.clear(); |
| 100 | |
| 101 | // Loop over all the open windows |
| 102 | foreach (QWidget* widget, QApplication::topLevelWidgets()) |
| 103 | { |
| 104 | if (!widget->isVisible()) |
| 105 | continue; |
| 106 | |
| 107 | if (!widget->isWindow() || widget->windowType() != Qt::Window) |
| 108 | continue; |
| 109 | |
| 110 | // Figure out its type |
| 111 | WindowQtConfig::WindowType type = WindowQtConfig::WIN_TYPE_UNKNOWN; |
| 112 | if (dynamic_cast<MainWindow*>(widget)) |
| 113 | type = WindowQtConfig::WIN_TYPE_MAIN; |
| 114 | else if (dynamic_cast<MemoryWindow*>(widget)) |
| 115 | type = WindowQtConfig::WIN_TYPE_MEMORY; |
| 116 | else if (dynamic_cast<DasmWindow*>(widget)) |
| 117 | type = WindowQtConfig::WIN_TYPE_DISASM; |
| 118 | else if (dynamic_cast<LogWindow*>(widget)) |
| 119 | type = WindowQtConfig::WIN_TYPE_LOG; |
| 120 | |
| 121 | WindowQtConfig config; |
| 122 | config.m_type = type; |
| 123 | config.m_position.setX(widget->geometry().topLeft().x()); |
| 124 | config.m_position.setY(widget->geometry().topLeft().y()); |
| 125 | config.m_size.setX(widget->size().width()); |
| 126 | config.m_size.setY(widget->size().height()); |
| 127 | xmlConfigurations.push_back(config); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | //============================================================ |
| 133 | // Utilities |
| 134 | //============================================================ |
| 135 | |
| 136 | static void load_and_clear_main_window_config(std::vector<WindowQtConfig>& configs) |
| 137 | { |
| 138 | if (configs.size() == 0) |
| 139 | return; |
| 140 | |
| 141 | int i = 0; |
| 142 | for (i = 0; i < configs.size(); i++) |
| 143 | { |
| 144 | if (configs[i].m_type == WindowQtConfig::WIN_TYPE_MAIN) |
| 145 | { |
| 146 | mainQtWindow->setGeometry(configs[i].m_position.x(), configs[i].m_position.y(), |
| 147 | configs[i].m_size.x(), configs[i].m_size.y()); |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | configs.erase(configs.begin()+i); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | static void setup_additional_startup_windows(running_machine& machine, std::vector<WindowQtConfig>& configs) |
| 156 | { |
| 157 | for (int i = 0; i < configs.size(); i++) |
| 158 | { |
| 159 | WindowQt* foo = NULL; |
| 160 | switch (configs[i].m_type) |
| 161 | { |
| 162 | case WindowQtConfig::WIN_TYPE_MEMORY: |
| 163 | foo = new MemoryWindow(&machine); break; |
| 164 | case WindowQtConfig::WIN_TYPE_DISASM: |
| 165 | foo = new DasmWindow(&machine); break; |
| 166 | case WindowQtConfig::WIN_TYPE_LOG: |
| 167 | foo = new LogWindow(&machine); break; |
| 168 | default: break; |
| 169 | } |
| 170 | foo->setGeometry(configs[i].m_position.x(), configs[i].m_position.y(), |
| 171 | configs[i].m_size.x(), configs[i].m_size.y()); |
| 172 | foo->show(); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | static void bring_main_window_to_front() |
| 178 | { |
| 179 | foreach (QWidget* widget, QApplication::topLevelWidgets()) |
| 180 | { |
| 181 | if (!dynamic_cast<MainWindow*>(widget)) |
| 182 | continue; |
| 183 | widget->activateWindow(); |
| 184 | widget->raise(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | //============================================================ |
| 36 | 190 | // Core functionality |
| 37 | 191 | //============================================================ |
| 38 | 192 | |
| 39 | 193 | void sdl_osd_interface::init_debugger() |
| 40 | 194 | { |
| 41 | | // QT is a magical thing |
| 42 | | new QApplication(qtArgc, qtArgv); |
| 195 | if (qApp == NULL) |
| 196 | { |
| 197 | // If you're starting from scratch, create a new qApp |
| 198 | new QApplication(qtArgc, qtArgv); |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | // If you're doing a hard reset, clear out existing widgets & get ready for re-init |
| 203 | foreach (QWidget* widget, QApplication::topLevelWidgets()) |
| 204 | { |
| 205 | if (!widget->isWindow() || widget->windowType() != Qt::Window) |
| 206 | continue; |
| 207 | delete widget; |
| 208 | } |
| 209 | oneShot = true; |
| 210 | } |
| 211 | |
| 212 | // Setup the configuration XML saving and loading |
| 213 | config_register(machine(), |
| 214 | "debugger", |
| 215 | config_saveload_delegate(FUNC(xml_configuration_load), &machine()), |
| 216 | config_saveload_delegate(FUNC(xml_configuration_save), &machine())); |
| 43 | 217 | } |
| 44 | 218 | |
| 45 | 219 | |
| r20435 | r20436 | |
| 49 | 223 | |
| 50 | 224 | void sdl_osd_interface::wait_for_debugger(device_t &device, bool firststop) |
| 51 | 225 | { |
| 226 | // Dialog initialization |
| 52 | 227 | if (oneShot) |
| 53 | 228 | { |
| 54 | | mainQtWindow = new MainWindow(&device, &machine()); |
| 229 | mainQtWindow = new MainWindow(&machine()); |
| 230 | load_and_clear_main_window_config(xmlConfigurations); |
| 231 | setup_additional_startup_windows(machine(), xmlConfigurations); |
| 55 | 232 | mainQtWindow->show(); |
| 56 | 233 | oneShot = false; |
| 57 | 234 | } |
| 58 | 235 | |
| 59 | | // Make sure the main window displays the proper cpu |
| 236 | // Insure all top level widgets are visible & bring main window to front |
| 237 | foreach (QWidget* widget, QApplication::topLevelWidgets()) |
| 238 | { |
| 239 | if (!widget->isWindow() || widget->windowType() != Qt::Window) |
| 240 | continue; |
| 241 | widget->show(); |
| 242 | } |
| 243 | bring_main_window_to_front(); |
| 244 | |
| 245 | // Set the main window to display the proper cpu |
| 60 | 246 | mainQtWindow->setProcessor(&device); |
| 61 | 247 | |
| 62 | 248 | // Run our own QT event loop |
| r20435 | r20436 | |
| 73 | 259 | mainQtWindow->clearRefreshFlag(); |
| 74 | 260 | } |
| 75 | 261 | |
| 76 | | // Exit if the machine has been instructed to do so |
| 77 | | if (machine().exit_pending()) |
| 262 | // Hide all top level widgets if requested |
| 263 | if (mainQtWindow->wantsHide()) |
| 78 | 264 | { |
| 265 | foreach (QWidget* widget, QApplication::topLevelWidgets()) |
| 266 | { |
| 267 | if (!widget->isWindow() || widget->windowType() != Qt::Window) |
| 268 | continue; |
| 269 | widget->hide(); |
| 270 | } |
| 271 | mainQtWindow->clearHideFlag(); |
| 272 | } |
| 273 | |
| 274 | // Exit if the machine has been instructed to do so (scheduled event == exit || hard_reset) |
| 275 | if (machine().scheduled_event_pending()) |
| 276 | { |
| 277 | // Keep a list of windows we want to save. |
| 278 | // We need to do this here because by the time xml_configuration_save gets called |
| 279 | // all the QT windows are already gone. |
| 280 | gather_save_configurations(); |
| 79 | 281 | break; |
| 80 | 282 | } |
| 81 | 283 | } |
trunk/src/osd/sdl/debugqtmainwindow.c
| r20435 | r20436 | |
| 4 | 4 | #include "debug/dvdisasm.h" |
| 5 | 5 | |
| 6 | 6 | |
| 7 | | MainWindow::MainWindow(device_t* processor, |
| 8 | | running_machine* machine, |
| 9 | | QWidget* parent) : |
| 7 | MainWindow::MainWindow(running_machine* machine, QWidget* parent) : |
| 10 | 8 | WindowQt(machine, parent), |
| 11 | 9 | m_historyIndex(0), |
| 12 | 10 | m_inputHistory() |
| r20435 | r20436 | |
| 100 | 98 | |
| 101 | 99 | addDockWidget(Qt::TopDockWidgetArea, dasmDock); |
| 102 | 100 | dockMenu->addAction(dasmDock->toggleViewAction()); |
| 103 | | |
| 104 | | // Window title |
| 105 | | astring title; |
| 106 | | title.printf("Debug: %s - %s '%s'", m_machine->system().name, processor->name(), processor->tag()); |
| 107 | | setWindowTitle(title.cstr()); |
| 108 | 101 | } |
| 109 | 102 | |
| 110 | 103 | |
| r20435 | r20436 | |
| 261 | 254 | |
| 262 | 255 | void MainWindow::executeCommand(bool withClear) |
| 263 | 256 | { |
| 264 | | if (m_inputEdit->text() == "") |
| 257 | QString command = m_inputEdit->text(); |
| 258 | |
| 259 | // A blank command is a "silent step" |
| 260 | if (command == "") |
| 265 | 261 | { |
| 266 | 262 | debug_cpu_get_visible_cpu(*m_machine)->debug()->single_step(); |
| 267 | 263 | return; |
| 268 | 264 | } |
| 269 | 265 | |
| 266 | // If the user asked for help on a specific command, enhance the call |
| 267 | if (command.trimmed().startsWith("help", Qt::CaseInsensitive)) |
| 268 | { |
| 269 | if (command.split(" ", QString::SkipEmptyParts).length() == 2) |
| 270 | { |
| 271 | const int width = m_consoleView->view()->visible_size().x; |
| 272 | command.append(QString(", %1").arg(width, 1, 16)); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // Send along the command |
| 270 | 277 | debug_console_execute_command(*m_machine, |
| 271 | | m_inputEdit->text().toLocal8Bit().data(), |
| 278 | command.toLocal8Bit().data(), |
| 272 | 279 | true); |
| 273 | 280 | |
| 274 | 281 | // Add history & set the index to be the top of the stack |
| 275 | | addToHistory(m_inputEdit->text()); |
| 282 | addToHistory(command); |
| 276 | 283 | |
| 277 | 284 | // Clear out the text and reset the history pointer only if asked |
| 278 | 285 | if (withClear) |
| r20435 | r20436 | |
| 288 | 295 | } |
| 289 | 296 | |
| 290 | 297 | |
| 298 | void MainWindow::debugActClose() |
| 299 | { |
| 300 | m_machine->schedule_exit(); |
| 301 | } |
| 302 | |
| 303 | |
| 291 | 304 | void MainWindow::addToHistory(const QString& command) |
| 292 | 305 | { |
| 293 | 306 | if (command == "") |