From eac90c6b42c6a7a31c212e08bccb20564d02ad75 Mon Sep 17 00:00:00 2001
From: Ty Lamontagne <amfobes@gmail.com>
Date: Sat, 31 Dec 2022 23:24:39 -0500
Subject: [PATCH] Debugger Disassembly: Add 'NOP Instruction(s)' Context menu
 action

---
 pcsx2-qt/Debugger/DisassemblyWidget.cpp | 13 +++++++++++++
 pcsx2-qt/Debugger/DisassemblyWidget.h   |  1 +
 2 files changed, 14 insertions(+)

diff --git a/pcsx2-qt/Debugger/DisassemblyWidget.cpp b/pcsx2-qt/Debugger/DisassemblyWidget.cpp
index 57afb9612e..e467bcbb58 100644
--- a/pcsx2-qt/Debugger/DisassemblyWidget.cpp
+++ b/pcsx2-qt/Debugger/DisassemblyWidget.cpp
@@ -60,6 +60,8 @@ void DisassemblyWidget::CreateCustomContextMenu()
 	m_contextMenu->addSeparator();
 	m_contextMenu->addAction(action = new QAction(tr("Assemble new Instruction(s)"), this));
 	connect(action, &QAction::triggered, this, &DisassemblyWidget::contextAssembleInstruction);
+	m_contextMenu->addAction(action = new QAction(tr("NOP Instruction(s)"), this));
+	connect(action, &QAction::triggered, this, &DisassemblyWidget::contextNoopInstruction);
 	m_contextMenu->addSeparator();
 	m_contextMenu->addAction(action = new QAction(tr("Run to Cursor"), this));
 	connect(action, &QAction::triggered, this, &DisassemblyWidget::contextRunToCursor);
@@ -136,6 +138,17 @@ void DisassemblyWidget::contextAssembleInstruction()
 	}
 }
 
+void DisassemblyWidget::contextNoopInstruction()
+{
+	Host::RunOnCPUThread([this, start = m_selectedAddressStart, end = m_selectedAddressEnd, cpu = m_cpu] {
+		for (u32 i = start; i <= end; i += 4)
+		{
+			cpu->write32(i, 0x00);
+		}
+		QtHost::RunOnUIThread([this] { VMUpdate(); });
+	});
+}
+
 void DisassemblyWidget::contextRunToCursor()
 {
 	Host::RunOnCPUThread([&] { CBreakPoints::AddBreakPoint(m_cpu->getCpuType(), m_selectedAddressStart); });
diff --git a/pcsx2-qt/Debugger/DisassemblyWidget.h b/pcsx2-qt/Debugger/DisassemblyWidget.h
index 21baccb925..6ab73715be 100644
--- a/pcsx2-qt/Debugger/DisassemblyWidget.h
+++ b/pcsx2-qt/Debugger/DisassemblyWidget.h
@@ -55,6 +55,7 @@ public slots:
 	void contextCopyInstructionHex();
 	void contextCopyInstructionText();
 	void contextAssembleInstruction();
+	void contextNoopInstruction();
 	void contextRunToCursor();
 	void contextJumpToCursor();
 	void contextToggleBreakpoint();