-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmemoryviewer.cpp
More file actions
90 lines (79 loc) · 2.35 KB
/
memoryviewer.cpp
File metadata and controls
90 lines (79 loc) · 2.35 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
87
88
89
90
#include "memoryviewer.h"
MemoryViewer::MemoryViewer(QWidget *parent) : QWidget(parent),
m_lineWidth(0x40),
currentAddress(0x0000)
{
reset();
}
void MemoryViewer::poke(int startAddress, int endAddress, QColor color)
{
for(int i=startAddress;i<endAddress;i++)
{
memory[i] = true;
memoryColor[i] = color;
}
update();
}
void MemoryViewer::reset()
{
for(int i=0;i<ADRCOUNT;i++)
{
memory[i] = false;
memoryColor[i] = QColor(0xff, 0xff, 0xff);
}
update();
}
void MemoryViewer::setLineWidth(int lineWidth)
{
m_lineWidth = lineWidth;
setFixedHeight(ADRCOUNT/lineWidth + 2);
update();
}
QString MemoryViewer::getCurrentAddressString()
{
return QString("$%1").arg(currentAddress,4,16, QLatin1Char('0'));
}
int MemoryViewer::getCurrentAddress()
{
return currentAddress;
}
void MemoryViewer::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
// frame
painter.setPen(QPen(Qt::darkGray));
painter.drawLine(0,0,m_lineWidth+1,0);
painter.drawLine(m_lineWidth+1,0,m_lineWidth+1,ADRCOUNT/m_lineWidth+1);
painter.drawLine(m_lineWidth+1,ADRCOUNT/m_lineWidth+1,0,ADRCOUNT/m_lineWidth+1);
painter.drawLine(0,ADRCOUNT/m_lineWidth+1,0,0);
painter.setFont(QFont(font().family(),8));
for(int y=m_lineWidth*16;y<ADRCOUNT;y+=m_lineWidth*16)
{
painter.drawLine(m_lineWidth+1,y/m_lineWidth+1,m_lineWidth+8,y/m_lineWidth+1);
painter.drawText(m_lineWidth+10,y/m_lineWidth+1+painter.fontMetrics().height()/4,QString("%1-%2").arg(y,4,16, QLatin1Char('0')).arg(y+m_lineWidth-1,4,16, QLatin1Char('0')).toUpper());
}
// memory
for(int i=0;i<ADRCOUNT;i++)
{
if(memory[i])
{
painter.setPen(QPen(memoryColor[i]));
painter.drawPoint(i % m_lineWidth+1, i/m_lineWidth+1);
}
}
}
void MemoryViewer::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
int mx = event->x();
int my = event->y();
emit currentCoordinateChanged(mx, my);
if ((my<1)||(my>ADRCOUNT/m_lineWidth)||(mx<1)||(mx > m_lineWidth)) return;
mx--;
my--;
currentAddress = my*m_lineWidth+mx;
emit currentAddressChanged(currentAddress);
}
}