#1 Add a Refresh Disassembly action to the View menu, shortcut Ctrl+L

Open
pgimeno wants to merge 1 commits from pgimeno/pg-add-disasm-refresh into pgimeno/master
4 changed files with 61 additions and 37 deletions
  1. 12 0
      src/DebuggerForm.cpp
  2. 2 0
      src/DebuggerForm.h
  3. 46 37
      src/DisasmViewer.cpp
  4. 1 0
      src/DisasmViewer.h

+ 12 - 0
src/DebuggerForm.cpp

@@ -276,6 +276,9 @@ void DebuggerForm::createActions()
 
 	viewDebuggableViewerAction = new QAction(tr("Add debuggable viewer"), this);
 	viewDebuggableViewerAction->setStatusTip(tr("Add a hex viewer for debuggables"));
+	refreshDisasmAction = new QAction(tr("Refresh disassembly"), this);
+	refreshDisasmAction->setShortcut(QKeySequence(tr("Ctrl+L")));
+	refreshDisasmAction->setStatusTip(tr("Refresh the memory used for the disassembly and update the disassembly"));
 
 	viewVDPStatusRegsAction = new QAction(tr("Status Registers"), this);
 	viewVDPStatusRegsAction->setStatusTip(tr("The VDP status registers interpreted"));
@@ -364,6 +367,7 @@ void DebuggerForm::createActions()
 	connect(viewSlotsAction, SIGNAL(triggered()), this, SLOT(toggleSlotsDisplay()));
 	connect(viewMemoryAction, SIGNAL(triggered()), this, SLOT(toggleMemoryDisplay()));
 	connect(viewDebuggableViewerAction, SIGNAL(triggered()), this, SLOT(addDebuggableViewer()));
+	connect(refreshDisasmAction, SIGNAL(triggered()), this, SLOT(refreshDisasm()));
 	connect(viewBitMappedAction, SIGNAL(triggered()), this, SLOT(toggleBitMappedDisplay()));
 	connect(viewVDPRegsAction, SIGNAL(triggered()), this, SLOT(toggleVDPRegsDisplay()));
 	connect(viewVDPCommandRegsAction, SIGNAL(triggered()), this, SLOT(toggleVDPCommandRegsDisplay()));
@@ -423,6 +427,7 @@ void DebuggerForm::createMenus()
 	viewVDPDialogsMenu = viewMenu->addMenu("VDP");
 	viewMenu->addSeparator();
 	viewMenu->addAction(viewDebuggableViewerAction);
+	viewMenu->addAction(refreshDisasmAction);
 	connect(viewMenu, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu()));
 
 	// create VDP dialogs menu
@@ -1336,6 +1341,13 @@ void DebuggerForm::addDebuggableViewer()
 	viewer->setEnabled(disasmView->isEnabled());
 }
 
+void DebuggerForm::refreshDisasm()
+{
+	if (disasmView) {
+		disasmView->refresh();
+	}
+}
+
 void DebuggerForm::dockWidgetVisibilityChanged(DockableWidget* w)
 {
 	dockMan.visibilityChanged(w);

+ 2 - 0
src/DebuggerForm.h

@@ -93,6 +93,7 @@ private:
 	QAction* viewSlotsAction;
 	QAction* viewMemoryAction;
 	QAction* viewDebuggableViewerAction;
+	QAction* refreshDisasmAction;
 
 	QAction* viewBitMappedAction;
 	QAction* viewVDPStatusRegsAction;
@@ -157,6 +158,7 @@ private slots:
 	void toggleVDPStatusRegsDisplay();
 	void toggleVDPCommandRegsDisplay();
 	void addDebuggableViewer();
+	void refreshDisasm();
 	void executeBreak();
 	void executeRun();
 	void executeStep();

+ 46 - 37
src/DisasmViewer.cpp

@@ -282,6 +282,49 @@ void DisasmViewer::setCursorAddress(quint16 addr, int infoLine, int method)
 	setAddress(addr, infoLine, method);
 }
 
+void DisasmViewer::refresh(int addr, int infoLine, int method)
+{
+	if (addr == -1) {
+		addr = cursorAddr;
+	}
+
+	// determine disasm bounds
+	int disasmStart;
+	int disasmEnd;
+	int extra = 4 * (visibleLines > 9 ? visibleLines+partialBottomLine : 10);
+	switch (method) {
+	case Middle:
+	case MiddleAlways:
+		disasmStart = addr - 3 * extra / 2;
+		disasmEnd   = addr + 3 * extra / 2;
+		break;
+	case Bottom:
+	case BottomAlways:
+		disasmStart = addr - 2 * extra;
+		disasmEnd   = addr +     extra;
+		break;
+	default:
+		disasmStart = addr -     extra;
+		disasmEnd   = addr + 2 * extra;
+	}
+	disasmStart = std::max(disasmStart, 0);
+	disasmEnd   = std::min(disasmEnd,   0xFFFF);
+
+	CommMemoryRequest* req = new CommMemoryRequest(
+		disasmStart, disasmEnd - disasmStart + 1, &memory[disasmStart], *this);
+	req->address = addr;
+	req->line = infoLine;
+	req->method = method;
+
+	if (waitingForData) {
+		delete nextRequest;
+		nextRequest = req;
+	} else {
+		waitingForData = true;
+		CommClient::instance().sendCommand(req);
+	}
+}
+
 void DisasmViewer::setAddress(quint16 addr, int infoLine, int method)
 {
 	int line = findDisasmLine(addr, infoLine);
@@ -347,41 +390,7 @@ void DisasmViewer::setAddress(quint16 addr, int infoLine, int method)
 	// This means that a new block of memory must be transfered from
 	// openMSX and disassembled.
 
-	// determine disasm bounds
-	int disasmStart;
-	int disasmEnd;
-	int extra = 4 * (visibleLines > 9 ? visibleLines+partialBottomLine : 10);
-	switch (method) {
-	case Middle:
-	case MiddleAlways:
-		disasmStart = addr - 3 * extra / 2;
-		disasmEnd   = addr + 3 * extra / 2;
-		break;
-	case Bottom:
-	case BottomAlways:
-		disasmStart = addr - 2 * extra;
-		disasmEnd   = addr +     extra;
-		break;
-	default:
-		disasmStart = addr -     extra;
-		disasmEnd   = addr + 2 * extra;
-	}
-	disasmStart = std::max(disasmStart, 0);
-	disasmEnd   = std::min(disasmEnd,   0xFFFF);
-
-	CommMemoryRequest* req = new CommMemoryRequest(
-		disasmStart, disasmEnd - disasmStart + 1, &memory[disasmStart], *this);
-	req->address = addr;
-	req->line = infoLine;
-	req->method = method;
-
-	if (waitingForData) {
-		delete nextRequest;
-		nextRequest = req;
-	} else {
-		waitingForData = true;
-		CommClient::instance().sendCommand(req);
-	}
+	refresh(addr, infoLine, method);
 }
 
 void DisasmViewer::memoryUpdated(CommMemoryRequest* req)
@@ -458,9 +467,9 @@ int DisasmViewer::findDisasmLine(quint16 lineAddr, int infoLine)
 	int line = disasmLines.size() - 1;
 	while( line >= 0 ) {
 		if( lineAddr >= disasmLines[line].addr ) {
-			if( infoLine == 0 ) 
+			if( infoLine == 0 )
 				return line;
-			if (infoLine == LAST_INFO_LINE) 
+			if (infoLine == LAST_INFO_LINE)
 				return line-1;
 			while (disasmLines[line].infoLine != infoLine && disasmLines[line].addr == lineAddr) {
 				line--;

+ 1 - 0
src/DisasmViewer.h

@@ -38,6 +38,7 @@ public slots:
 	void scrollBarChanged(int value);
 	void settingsChanged();
 	void symbolsChanged();
+	void refresh(int addr = -1, int infoLine = FIRST_INFO_LINE, int method = Middle);
 
 private:
 	void resizeEvent(QResizeEvent* e);