-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTLEmuMemoryModel.cpp
94 lines (81 loc) · 2.57 KB
/
TLEmuMemoryModel.cpp
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
87
88
89
90
91
92
93
94
//
// Created by codetector on 12/5/19.
//
#include <fmt/format.h>
#include <iostream>
#include <QtGui/QColor>
#include "TLEmuMemoryModel.h"
#include "tl45/tl45_isa.h"
std::string TLEmuMemoryModel::formatMemoryValue(uint64_t addr) const {
auto dataWidth = state->getMemoryDataWidth();
switch(state->getMemoryMapping(addr)) {
default:
return "";
case MemoryMapping::IO_MEMORY:
case MemoryMapping::STANDARD_MEMORY: {
// uint64_t value = 0;
std::string hexdump = "";
for (int i = 0; i < itemWidth; i++) {
// value <<= 8;
// value |= state->getMemoryValue(addr + i);
hexdump += fmt::format("{:02X} ", state->getMemoryValue(addr + i));
}
dataWidth *= itemWidth;
if (dataWidth <= 4) {
return fmt::format("0x{:04X}\t{}\t", addr, hexdump);
} else if (dataWidth <= 8) {
return fmt::format("0x{:04X}\t{}\t\t{}", addr, hexdump, state->getMemoryDisassembly(addr));
} else if (dataWidth <= 16) {
return fmt::format("0x{:04X}\t{}\t", addr, hexdump);
} else if (dataWidth <= 32) {
return fmt::format("0x{:04X}\t{}\t\t{}", addr, hexdump, state->getMemoryDisassembly(addr));
} else {
return fmt::format("0x{:04X}\t{}}\t", addr, hexdump);
}
}
}
}
void TLEmuMemoryModel::getDisplayLimits(uint64_t &min, uint64_t &max) const {
min = 0;
if (baseAddress > 1000 * itemWidth) {
min = baseAddress - 1000 * itemWidth;
}
max = (1ULL << state->getMemoryAddrWidth()) - 1;
if (max - 1000 * itemWidth > baseAddress) {
max = baseAddress + 1000 * itemWidth;
}
}
int TLEmuMemoryModel::rowCount(const QModelIndex &parent) const {
uint64_t min, max;
getDisplayLimits(min, max);
return (int) (max - min + 1);
}
QVariant TLEmuMemoryModel::data(const QModelIndex &index, int role) const {
static const QColor white = QColor(Qt::white);
static const QColor blue = QColor::fromRgb(56, 192, 255);
auto row = index.row();
uint64_t min, max;
getDisplayLimits(min, max);
uint64_t addr = min + row * itemWidth;
if (role == Qt::DisplayRole) {
return QString::fromStdString(formatMemoryValue(addr));
}
if (addr == state->getProgramCounterValue()) {
if (role == Qt::TextColorRole) {
return white;
}
if (role == Qt::BackgroundColorRole) {
return blue;
}
}
return QVariant();
}
void TLEmuMemoryModel::memoryChanged() {
emit dataChanged(index(0), index(rowCount(QModelIndex()) - 1));
}
void TLEmuMemoryModel::setBaseAddress(uint64_t p) {
baseAddress = p;
}
uint64_t TLEmuMemoryModel::getBaseAddress() {
return baseAddress;
}