Skip to content

Commit

Permalink
Add Run Until option to BASIC debugger context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
calc84maniac committed Sep 3, 2024
1 parent 6c0c927 commit 592a204
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
48 changes: 48 additions & 0 deletions gui/qt/basicdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void MainWindow::debugBasicInit() {
ui->basicEdit->setFont(QFont(QStringLiteral("TICELarge"), 11));
ui->basicTempEdit->setFont(QFont(QStringLiteral("TICELarge"), 11));

connect(ui->basicEdit, &BasicEditor::customContextMenuRequested, this, &MainWindow::debugBasicContextMenu);
connect(ui->basicTempEdit, &BasicEditor::customContextMenuRequested, this, &MainWindow::debugBasicContextMenu);

m_basicCurrLine.format.setProperty(QTextFormat::FullWidthSelection, true);
debugBasicUpdateDarkMode();
}
Expand Down Expand Up @@ -307,6 +310,51 @@ void MainWindow::debugBasicCreateTokenMap(int idx, const QByteArray &data) {
}
}

void MainWindow::debugBasicContextMenu(const QPoint &pos) {
BasicEditor *editor = static_cast<BasicEditor*>(sender());
bool valid = guiDebug && guiDebugBasic;
int index = 0;
if (editor == ui->basicEdit) {
index = m_basicCodeIndex;
valid &= (index != 0);
} else if (editor == ui->basicTempEdit) {
valid &= m_basicShowTempParser;
} else {
valid = false;
}

QMenu *menu = editor->createStandardContextMenu(pos);
menu->addSeparator();
QAction *runUntil = menu->addAction(ACTION_RUN_UNTIL);
runUntil->setEnabled(false);
uint32_t runUntilRange = 0;

int actualIndex = 0;
if (valid && debugBasicPrgmLookup(false, &actualIndex) != DBG_BASIC_NO_EXECUTING_PRGM && index == actualIndex) {
const auto &tokensMap = m_basicPrgmsTokensMap[index];
const int cursorOffset = editor->cursorForPosition(pos).position();
const auto last = std::make_reverse_iterator(
std::upper_bound(tokensMap.constBegin(), tokensMap.constEnd(), cursorOffset,
[](int offset, const token_highlight_t &posInfo) { return offset < posInfo.offset; }));
if (last != tokensMap.crend()) {
const auto stepField = m_basicShowFetches ? &token_highlight_t::offset : &token_highlight_t::line;
const int currField = (*last).*stepField;
const auto first = std::find_if(last + 1, tokensMap.crend(), [=](const token_highlight_t &posInfo) { return posInfo.*stepField != currField; });
const uint16_t firstOffset = first.base() - tokensMap.constBegin();
const uint16_t lastOffset = last.base() - tokensMap.constBegin() - 1;
runUntilRange = firstOffset | (static_cast<uint32_t>(lastOffset) << 16);
runUntil->setEnabled(true);
}
}
QAction *action = menu->exec(editor->mapToGlobal(pos));
if (action == runUntil && guiDebug && guiDebugBasic &&
debugBasicPrgmLookup(false, &actualIndex) != DBG_BASIC_NO_EXECUTING_PRGM && index == actualIndex) {
debugSync();
debug_step(DBG_BASIC_STEP_NEXT, runUntilRange);
emu.resume();
}
}

void MainWindow::debugBasicStep() {
debugBasicStepInternal(false);
}
Expand Down
3 changes: 2 additions & 1 deletion gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ void MainWindow::translateExtras(int init) {
ACTION_GOTO_DISASM_VIEW = tr("Goto Disasm View");
ACTION_COPY_ADDR = tr("Copy Address");
ACTION_COPY_DATA = tr("Copy Data");
ACTION_RUN_UNTIL = tr("Run Until");

QString __TXT_MEM_DOCK = tr("Memory View");
QString __TXT_VISUALIZER_DOCK = tr("Memory Visualizer");
Expand Down Expand Up @@ -2482,7 +2483,7 @@ void MainWindow::contextDisasm(const QPoint &posa) {
uint32_t addr = static_cast<uint32_t>(hex2int(addrStr));

QMenu menu;
QAction *runUntil = menu.addAction(tr("Run Until"));
QAction *runUntil = menu.addAction(ACTION_RUN_UNTIL);
menu.addSeparator();
QAction *toggleBreak = menu.addAction(ACTION_TOGGLE_BREAK);
QAction *toggleRead = menu.addAction(ACTION_TOGGLE_READ);
Expand Down
4 changes: 3 additions & 1 deletion gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "keyhistorywidget.h"
#include "dockwidget.h"
#include "datawidget.h"
#include "basiccodeviewerwindow.h"
#include "vartablemodel.h"
#include "keypad/qtkeypadbridge.h"
#include "debugger/hexwidget.h"
Expand Down Expand Up @@ -263,7 +264,6 @@ class MainWindow : public QMainWindow {
void debugBasicReconfigure(bool forceUpdate);
void debugBasicInit();
void debugBasicRaise();
void debugBasicToggle();
void debugBasicStep();
void debugBasicStepNext();
void debugBasicStepInternal(bool next);
Expand All @@ -275,6 +275,7 @@ class MainWindow : public QMainWindow {
debug_basic_status_t debugBasicPrgmLookup(bool allowSwitch, int *idx);
void debugBasicCreateTokenMap(int idx, const QByteArray &data);
void debugBasicGuiState(bool state);
void debugBasicContextMenu(const QPoint &pos);
void debugBasicToggleHighlight(bool enabled);
void debugBasicToggleShowFetch(bool enabled);
void debugBasicToggleShowTempParse(bool enabled);
Expand Down Expand Up @@ -859,6 +860,7 @@ class MainWindow : public QMainWindow {
QString ACTION_GOTO_DISASM_VIEW;
QString ACTION_COPY_ADDR;
QString ACTION_COPY_DATA;
QString ACTION_RUN_UNTIL;

QTableWidget *m_breakpoints = Q_NULLPTR;
QTableWidget *m_watchpoints = Q_NULLPTR;
Expand Down
6 changes: 6 additions & 0 deletions gui/qt/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@
<property name="centerOnScroll">
<bool>false</bool>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -391,6 +394,9 @@
<property name="centerOnScroll">
<bool>false</bool>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item>
Expand Down

0 comments on commit 592a204

Please sign in to comment.