Skip to content

Commit

Permalink
[more convenient] On 'Main memory' window, provides the input complet…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
mb3h committed Feb 3, 2025
1 parent 3558a9c commit efc863d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DebuggerForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ void DebuggerForm::createForm()
// Main memory viewer
connect(this, &DebuggerForm::connected, mainMemoryView, &MainMemoryViewer::refresh);
connect(this, &DebuggerForm::breakStateEntered, mainMemoryView, &MainMemoryViewer::refresh);
connect(this, &DebuggerForm::symbolsChanged, mainMemoryView, &MainMemoryViewer::updateCompleter);

// Slot viewer
connect(this, &DebuggerForm::connected, slotView, &SlotViewer::refresh);
Expand Down Expand Up @@ -718,6 +719,7 @@ void DebuggerForm::createForm()
disasmView->setMemoryLayout(&memLayout);
disasmView->setSymbolTable(&session.symbolTable());
mainMemoryView->setRegsView(regsView);
mainMemoryView->setMemoryLayout(&memLayout);
mainMemoryView->setSymbolTable(&session.symbolTable());
mainMemoryView->setDebuggable("memory", 0x10000);
stackView->setData(mainMemory, 0x10000);
Expand Down
32 changes: 32 additions & 0 deletions src/MainMemoryViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QHBoxLayout>
#include <QLineEdit>
#include <iostream>
#include <cassert>
#include <QCompleter>

static const int linkRegisters[] = {
CpuRegs::REG_BC, CpuRegs::REG_DE, CpuRegs::REG_HL,
Expand Down Expand Up @@ -54,11 +56,15 @@ MainMemoryViewer::MainMemoryViewer(QWidget* parent)
linkedId = 0;
regsViewer = nullptr;
symTable = nullptr;
memLayout = nullptr;
completer = nullptr;

connect(hexView, &HexViewer::locationChanged,
this, &MainMemoryViewer::hexViewChanged);
connect(addressValue, &QLineEdit::returnPressed,
this, &MainMemoryViewer::addressValueChanged);
connect(addressValue, &QLineEdit::textEdited,
this, &MainMemoryViewer::addressValueChanging);
connect(addressSourceList, qOverload<int>(&QComboBox::currentIndexChanged),
this, &MainMemoryViewer::addressSourceListChanged);
}
Expand Down Expand Up @@ -99,6 +105,32 @@ void MainMemoryViewer::hexViewChanged(int addr)
addressValue->setText(hexValue(addr, 4));
}

void MainMemoryViewer::setMemoryLayout(MemoryLayout* ml)
{
memLayout = ml;
}

void MainMemoryViewer::updateCompleter()
{
assert(symTable);
assert(memLayout);
// release the previous
if (completer) {
addressValue->setCompleter(nullptr);
//delete completer; // PENDING: done in setCompleter() above? (not obvious in document)
completer = nullptr; // safety
}
// create address completer
completer = new QCompleter(symTable->labelList(true, memLayout), this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
addressValue->setCompleter(completer);
}

void MainMemoryViewer::addressValueChanging()
{
// PENDING: Needing the color, someone will implement.
}

void MainMemoryViewer::addressValueChanged()
{
auto addr = stringToValue<uint16_t>(addressValue->text());
Expand Down
7 changes: 7 additions & 0 deletions src/MainMemoryViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class CPURegsViewer;
class SymbolTable;
class QComboBox;
class QLineEdit;
class QCompleter;
struct MemoryLayout;

class MainMemoryViewer : public QWidget
{
Expand All @@ -18,23 +20,28 @@ class MainMemoryViewer : public QWidget
void setDebuggable(const QString& name, int size);
void setRegsView(CPURegsViewer* viewer);
void setSymbolTable(SymbolTable* symtable);
void setMemoryLayout(MemoryLayout* ml);

void setLocation(int addr);
void settingsChanged();
void refresh();
void registerChanged(int id, int value);

void hexViewChanged(int addr);
void updateCompleter();
void addressValueChanging();
void addressValueChanged();
void addressSourceListChanged(int index);

private:
HexViewer* hexView;
QComboBox* addressSourceList;
QLineEdit* addressValue;
QCompleter* completer;

CPURegsViewer* regsViewer;
SymbolTable* symTable;
MemoryLayout* memLayout;
int linkedId;
bool isLinked;
};
Expand Down

0 comments on commit efc863d

Please sign in to comment.