-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtl45emu.cpp
More file actions
87 lines (66 loc) · 2.33 KB
/
tl45emu.cpp
File metadata and controls
87 lines (66 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <QShortcut>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QInputDialog>
#include "tl45emu.h"
#include "./ui_tl45emu.h"
TLEmulator::TLEmulator(AbstractEmulatorState *state, QWidget *parent)
: QMainWindow(parent), ui(new Ui::TLEmulator) {
this->machine_state = state;
ui->setupUi(this);
this->registerListModel = new TLEmuRegisterListModel(this->machine_state);
this->memoryModel = new TLEmuMemoryModel(this->machine_state);
this->ui->register_view->setModel(this->registerListModel);
this->ui->memory_view->setModel(memoryModel);
// Setup Toolbar
auto *openFile = new QAction("Load File", this);
connect(openFile, &QAction::triggered, this, &TLEmulator::onMenuItemClick);
this->ui->toolBar->addAction(openFile);
auto *gotoAction = new QAction("Go to", this);
connect(gotoAction, &QAction::triggered, this, &TLEmulator::gotoMemoryClick);
this->ui->toolBar->addAction(gotoAction);
auto *step = new QAction("Step", this);
connect(step, &QAction::triggered, this, [=](bool checked) {
state->step();
registerListModel->registersChanged();
memoryModel->memoryChanged();
});
this->ui->toolBar->addAction(step);
{
auto *step10K = new QAction("Step 10K", this);
connect(step10K, &QAction::triggered, this, [=](bool checked) {
for (int i = 0; i < 10000; i++) {
state->step();
}
registerListModel->registersChanged();
memoryModel->memoryChanged();
});
this->ui->toolBar->addAction(step10K);
}
auto shortcut = new QShortcut(QKeySequence("Ctrl+S"), this);
connect(shortcut, &QShortcut::activated, this, [=]() {
state->step();
registerListModel->registersChanged();
memoryModel->memoryChanged();
});
}
TLEmulator::~TLEmulator() {
delete ui;
delete registerListModel;
delete memoryModel;
}
void TLEmulator::onMenuItemClick(bool checked) {
QString filename = QFileDialog::getOpenFileName(this, tr("Open Binary File"), "",
tr("All Files (*)"));
machine_state->load(filename.toStdString());
}
void TLEmulator::gotoMemoryClick(bool checked) {
bool ok;
QString addr = QInputDialog::getText(this, tr("Enter Address (hex)"), "",
QLineEdit::Normal, "", &ok);
if (!ok) return;
int32_t i = addr.toInt(&ok, 16);
if (!ok) return;
printf("goto %x\n", i);
this->memoryModel->setBaseAddress(i);
}