|
26 | 26 |
|
27 | 27 | #include <QtWidgets/QToolTip> |
28 | 28 | #include <QtCore/QFileInfo> |
| 29 | +#include <QtCore/QStringList> |
29 | 30 | #include <QtCore/QRegularExpression> |
30 | 31 | #include <QtWidgets/QMessageBox> |
31 | 32 | #include <QtWidgets/QInputDialog> |
|
40 | 41 | #include <QtGui/QWindow> |
41 | 42 | #include <QtGui/QScreen> |
42 | 43 | #include <algorithm> |
| 44 | +#include <ranges> |
43 | 45 |
|
44 | 46 | #ifdef _MSC_VER |
45 | 47 | #include <direct.h> |
@@ -184,6 +186,7 @@ void MainWindow::debugImportFile(const QString &file) { |
184 | 186 |
|
185 | 187 | disasm.map.clear(); |
186 | 188 | disasm.reverse.clear(); |
| 189 | + markDisasmGotoCompletionsDirty(); |
187 | 190 | for (QString &equFile : m_equateFiles) { |
188 | 191 | equatesAddFile(equFile); |
189 | 192 | } |
@@ -1820,6 +1823,7 @@ void MainWindow::updateLabels() { |
1820 | 1823 | void MainWindow::equatesRefresh() { |
1821 | 1824 | disasm.map.clear(); |
1822 | 1825 | disasm.reverse.clear(); |
| 1826 | + markDisasmGotoCompletionsDirty(); |
1823 | 1827 | for (QString &file : m_equateFiles) { |
1824 | 1828 | equatesAddFile(file); |
1825 | 1829 | } |
@@ -1917,11 +1921,14 @@ void MainWindow::equatesAddEquate(const QString &name, uint32_t address) { |
1917 | 1921 | if (!equatesAddEquateInternal(name, address)) { |
1918 | 1922 | return; |
1919 | 1923 | } |
| 1924 | + markDisasmGotoCompletionsDirty(); |
1920 | 1925 | uint8_t *ptr = static_cast<uint8_t *>(phys_mem_ptr(address - 4, 9)); |
1921 | 1926 | if (ptr && ptr[4] == 0xC3 && (ptr[0] == 0xC3 || ptr[8] == 0xC3)) { // jump table? |
1922 | 1927 | uint32_t address2 = ptr[5] | ptr[6] << 8 | ptr[7] << 16; |
1923 | 1928 | if (phys_mem_ptr(address2, 1)) { |
1924 | | - equatesAddEquateInternal(QStringLiteral("_") + name, address2); |
| 1929 | + if (equatesAddEquateInternal(QStringLiteral("_") + name, address2)) { |
| 1930 | + markDisasmGotoCompletionsDirty(); |
| 1931 | + } |
1925 | 1932 | } |
1926 | 1933 | } |
1927 | 1934 | } |
@@ -2081,14 +2088,15 @@ void MainWindow::gotoPressed() { |
2081 | 2088 | m_gotoAddr = m_disasm->getSelectedAddr(); |
2082 | 2089 | } |
2083 | 2090 |
|
2084 | | - GotoDialog dlg(m_gotoAddr, m_disasmGotoHistory, this); |
| 2091 | + GotoDialog dlg(m_gotoAddr, m_disasmGotoHistory, disasmGotoCompletions(), this); |
2085 | 2092 | if (dlg.exec() == QDialog::Accepted) { |
2086 | 2093 | QString typed = dlg.text().trimmed(); |
2087 | 2094 | bool ok = false; |
2088 | 2095 | QString resolved = resolveAddressOrEquate(typed, &ok); |
2089 | 2096 | if (ok) { |
2090 | 2097 | m_gotoAddr = typed; |
2091 | | - disasmUpdateAddr(hex2int(resolved), false); |
| 2098 | + // changes are routed through here to make sure history is updated for fwd and back |
| 2099 | + gotoDisasmAddr(static_cast<uint32_t>(hex2int(resolved))); |
2092 | 2100 |
|
2093 | 2101 | auto &hist = m_disasmGotoHistory; |
2094 | 2102 | std::erase_if(hist, [&](const QString &s){ return s.compare(typed, Qt::CaseInsensitive) == 0; }); |
@@ -2159,6 +2167,44 @@ QAction *MainWindow::gotoMemAction(QMenu *menu, bool vat) const { |
2159 | 2167 | return gotoMem; |
2160 | 2168 | } |
2161 | 2169 |
|
| 2170 | +const QStringList &MainWindow::disasmGotoCompletions() { |
| 2171 | + if (!m_disasmGotoCompletionsDirty) { |
| 2172 | + return m_disasmGotoCompletions; |
| 2173 | + } |
| 2174 | + |
| 2175 | + m_disasmGotoCompletionsDirty = false; |
| 2176 | + |
| 2177 | + QStringList completions; |
| 2178 | + static constexpr std::array kRegisterAliases { |
| 2179 | + "AF", "HL", "DE", "BC", "IX", "IY", |
| 2180 | + "AF'", "HL'", "DE'", "BC'", "SPL", "SPS", "PC" |
| 2181 | + }; |
| 2182 | + |
| 2183 | + completions.reserve(static_cast<int>(disasm.reverse.size() + kRegisterAliases.size())); |
| 2184 | + |
| 2185 | + for (const auto &name : disasm.reverse | std::views::keys) { |
| 2186 | + completions.append(QString::fromStdString(name)); |
| 2187 | + } |
| 2188 | + |
| 2189 | + for (const char *alias : kRegisterAliases) { |
| 2190 | + const QLatin1String aliasStr(alias); |
| 2191 | + if (!completions.contains(aliasStr)) { |
| 2192 | + completions.append(QString::fromLatin1(alias)); |
| 2193 | + } |
| 2194 | + } |
| 2195 | + |
| 2196 | + std::ranges::sort(completions, [](const QString &lhs, const QString &rhs) { |
| 2197 | + return lhs.localeAwareCompare(rhs) < 0; |
| 2198 | + }); |
| 2199 | + |
| 2200 | + m_disasmGotoCompletions = std::move(completions); |
| 2201 | + return m_disasmGotoCompletions; |
| 2202 | +} |
| 2203 | + |
| 2204 | +void MainWindow::markDisasmGotoCompletionsDirty() { |
| 2205 | + m_disasmGotoCompletionsDirty = true; |
| 2206 | +} |
| 2207 | + |
2162 | 2208 | void MainWindow::handleCtrlClickText(QPlainTextEdit *edit) { |
2163 | 2209 | if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) { |
2164 | 2210 | bool ok = true; |
|
0 commit comments