Skip to content

Commit fef77c7

Browse files
committed
Several ways to draw transistors
Draws transistors in several ways: 0:Active, 1:Single-Flip, 2:Sticky and 3:All Single-Flip highlights transistors that have changed state only once Sticky highlights transistors that have changed state one or more times The option key that cycles the mode is "." The baseline gets tagged with the "T" key to turn transistor view on or off
1 parent dca5b45 commit fef77c7

4 files changed

Lines changed: 69 additions & 22 deletions

File tree

src/ClassVisual.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@
2626
#define VIA_POLY (1 << VIA_POLY_SHIFT)
2727
#define TRANSISTOR (1 << TRANSISTOR_SHIFT)
2828

29+
ClassVisual::ClassVisual()
30+
{
31+
connect(&::controller, &ClassController::onRunStopped, this, &ClassVisual::onRunStopped);
32+
}
33+
34+
void ClassVisual::onRunStopped()
35+
{
36+
// Count the number of times each transistor has changed its state from the base (initial) state
37+
for (uint i = 0; i < MAX_TRANS; i++)
38+
{
39+
bool state = ::controller.getNetlist().isTransOn(i);
40+
bool oldState = (uchar(m_transBaseState[i]) ^ m_transFlipCount[i]) & 1;
41+
if (state != oldState)
42+
m_transFlipCount[i] = (m_transFlipCount[i] + 1) & 0x7F; // Prevents the overflow
43+
}
44+
}
45+
46+
/*
47+
* Single-Flip and Sticky transistor view modes use base state, an array containing each transistor on/off state at the time of
48+
* the start of a test, and another array that counts the number of transitions each time a run stops.
49+
*/
50+
void ClassVisual::armTransFlipCount()
51+
{
52+
memset(m_transFlipCount, 0, sizeof(m_transFlipCount));
53+
for (uint i = 0; i < MAX_TRANS; i++)
54+
m_transBaseState[i] = ::controller.getNetlist().isTransOn(i);
55+
qInfo() << "Transistor flip counter reset";
56+
}
57+
2958
/*
3059
* Attempts to load and generate all chip resource that we expect to have
3160
*/
@@ -1283,10 +1312,10 @@ void ClassVisual::experimental_2()
12831312
}
12841313

12851314
/*
1286-
* Draws all transistors in two shades: yellow for active and gray for inactive
1287-
* with an additional option to highlight all of them irrespective of their state
1315+
* Draws transistors in several ways: 0:Active, 1:Single-Flip, 2:Sticky and 3:All
1316+
* The base colors that are used are yellow for active and gray for inactive transistors.
12881317
*/
1289-
void ClassVisual::expDrawTransistors(QPainter &painter, const QRect &viewport, bool highlightAll)
1318+
void ClassVisual::drawTransistors(QPainter &painter, const QRect &viewport, uint mode)
12901319
{
12911320
const static QBrush brush[2] = { Qt::gray, Qt::yellow };
12921321
const static QPen pens[2] = { QPen(QColor(), 0, Qt::NoPen), QPen(QColor(255, 0, 255), 1, Qt::SolidLine) };
@@ -1296,9 +1325,15 @@ void ClassVisual::expDrawTransistors(QPainter &painter, const QRect &viewport, b
12961325
// Speed up rendering by clipping to the viewport's image rectangle
12971326
if (t.box.intersected(viewport) != QRect())
12981327
{
1299-
bool state = ::controller.getSimZ80().getNetState(t.gatenet);
1328+
bool state = true; // "All" (default)
1329+
if (mode == 0) // "Active"
1330+
state = ::controller.getSimZ80().getNetState(t.gatenet);
1331+
else if (mode == 1) // "Single-Flip"
1332+
state = m_transFlipCount[t.id] == 1;
1333+
else if (mode == 2) // "Sticky"
1334+
state = m_transFlipCount[t.id];
13001335
painter.setPen(pens[state]);
1301-
painter.setBrush(brush[state || highlightAll]);
1336+
painter.setBrush(brush[state]);
13021337
painter.drawPath(t.path);
13031338
}
13041339
}

src/ClassVisual.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ClassVisual: public QObject
4141
Q_OBJECT
4242

4343
public:
44-
ClassVisual() {};
44+
explicit ClassVisual();
4545

4646
bool loadChipResources(QString dir);// Attempts to load all expected chip resources
4747
QImage &getImage(uint img); // Returns a reference to the image by the image index
@@ -58,24 +58,30 @@ class ClassVisual: public QObject
5858
QString getFeaturesAt(int x, int y); // Returns the list of features at the specified image coordinates
5959
bool isLatch(net_t net); // Returns true if a net is part of any latch
6060
void getLatch(net_t net, tran_t &t1, tran_t &t2, net_t &n1, net_t &n2); // Returns latch transistors and nets
61-
62-
public slots:
6361
void detectLatches(); // Detects latches and also loads custom latch definitions
6462
void drawLatches(QPainter &painter, const QRect &viewport);
63+
void drawTransistors(QPainter &painter, const QRect &viewport, uint mode);
64+
void armTransFlipCount();
65+
66+
public slots:
6567
void experimental(int n); // Runs experimental function number n
66-
void expDrawTransistors(QPainter &painter, const QRect &viewport, bool highlightAll);
6768
void expDynamicallyNameNets(QPainter &painter, const QRect &viewport, qreal scale); // Maps nearby net names
6869

70+
private slots:
71+
void onRunStopped();
72+
6973
private:
7074
QVector<transvdef> m_transvdefs; // Array of transistor visual definitions
75+
bool m_transBaseState[MAX_TRANS]; // Base state of each transistor
76+
uchar m_transFlipCount[MAX_TRANS]; // Number of times each transistor changed its state
7177
QHash<net_t, segvdef> m_segvdefs; // Hash of segment visual definitions, key is the segment net number
7278
QHash<net_t, segvdef> m_segvdefs2; // Alternate segment visual definitions
7379
bool use_alt_segdef {false}; // Use alternate segment definitions
7480
QVector<latchdef> m_latches; // Array of latches
7581
QVector<QImage> m_img; // Chip layer images
7682
uint m_sx {}; // X size of all images and maps
7783
uint m_sy {}; // Y size of all images and maps
78-
uint m_mapsize; // Map size in bytes, equals to (m_sx * m_sy)
84+
uint m_mapsize {}; // Map size in bytes, equals to (m_sx * m_sy)
7985
uint16_t *m_p3[3] {}; // Layer map: [0] diffusion, [1] poly, [2] metal
8086
uchar *m_fmap {}; // Feature bitmap
8187

src/WidgetImageView.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ WidgetImageView::~WidgetImageView()
4343
QSettings settings;
4444
settings.setValue("imageViewDrawActiveNets-" + whatsThis(), m_drawActiveNets);
4545
settings.setValue("imageViewDrawAnnotations-" + whatsThis(), m_drawAnnotations);
46-
settings.setValue("imageViewDrawActiveTransistors-" + whatsThis(), m_drawActiveTransistors);
46+
settings.setValue("imageViewDrawTransistors-" + whatsThis(), m_drawTransistors);
4747
settings.setValue("imageViewDrawLatches-" + whatsThis(), m_drawLatches);
4848

4949
QString layers = m_ov->getLayers();
@@ -66,12 +66,12 @@ void WidgetImageView::init(QString sid)
6666
QSettings settings;
6767
m_drawActiveNets = settings.value("imageViewDrawActiveNets-" + whatsThis(), false).toBool();
6868
m_drawAnnotations = settings.value("imageViewDrawAnnotations-" + whatsThis(), true).toBool();
69-
m_drawActiveTransistors = settings.value("imageViewDrawActiveTransistors-" + whatsThis(), true).toBool();
69+
m_drawTransistors = settings.value("imageViewDrawTransistors-" + whatsThis(), true).toBool();
7070
m_drawLatches = settings.value("imageViewDrawLatches-" + whatsThis(), false).toBool();
7171

7272
m_ov->setButton(0, m_drawActiveNets);
7373
m_ov->setButton(1, m_drawAnnotations);
74-
m_ov->setButton(2, m_drawActiveTransistors);
74+
m_ov->setButton(2, m_drawTransistors);
7575
m_ov->setButton(3, m_drawLatches);
7676

7777
m_ov->createImageButtons(::controller.getChip().getImageNames());
@@ -333,10 +333,10 @@ void WidgetImageView::paintEvent(QPaintEvent *)
333333
//------------------------------------------------------------------------
334334
// Draw transistors
335335
//------------------------------------------------------------------------
336-
if ((m_drawActiveTransistors || m_drawAllTransistors) && mouseOff)
336+
if (m_drawTransistors && mouseOff)
337337
{
338338
painter.save();
339-
::controller.getChip().expDrawTransistors(painter, viewportTex, m_drawAllTransistors);
339+
::controller.getChip().drawTransistors(painter, viewportTex, m_drawTransistorMode);
340340
painter.restore();
341341
}
342342
//------------------------------------------------------------------------
@@ -721,12 +721,18 @@ void WidgetImageView::keyPressEvent(QKeyEvent *event)
721721
m_ov->setButton(1, m_drawAnnotations);
722722
break;
723723
case Qt::Key_T:
724-
m_drawActiveTransistors = !m_drawActiveTransistors;
725-
m_drawAllTransistors = false;
726-
m_ov->setButton(2, m_drawActiveTransistors);
724+
m_drawTransistors = !m_drawTransistors;
725+
m_ov->setButton(2, m_drawTransistors);
726+
if (m_drawTransistors) ::controller.getChip().armTransFlipCount();
727727
break;
728728
case Qt::Key_Period:
729-
m_drawAllTransistors = !m_drawAllTransistors; break;
729+
if (m_drawTransistors)
730+
{
731+
if (++m_drawTransistorMode == 4) // 0:Active, 1:Single-Flip, 2:Sticky and 3:All
732+
m_drawTransistorMode = 0;
733+
static const QStringList modes = {"Active", "Single-Flip", "Sticky", "All"};
734+
qInfo() << "Draw transistor mode:" << modes[m_drawTransistorMode];
735+
}
730736
break;
731737
case Qt::Key_L:
732738
m_drawLatches = !m_drawLatches;

src/WidgetImageView.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ private slots:
9191
const QRect *m_highlight_trans {}; // Transistor bounding rectangle to highlight in the current image
9292
QRect m_r; // Rectangle used by the show() scripting command to highlight a rectangle
9393
bool m_drawActiveNets; // Draw active nets
94-
uint m_drawActiveNetsOrder {0}; // The order of drawing active nets bit[0], auto toggle bit[1]
94+
uint m_drawActiveNetsOrder {}; // The order of drawing active nets bit[0], auto toggle bit[1]
9595
bool m_drawAnnotations; // Draw image annotations
96-
bool m_drawActiveTransistors; // Draw currently active transistors
97-
bool m_drawAllTransistors {false}; // Draw all transistors (irrespective of their state)
96+
bool m_drawTransistors; // Draw transistors
97+
uint m_drawTransistorMode {}; // Draw transistors mode
9898
bool m_drawLatches; // Draw latches
9999
bool m_drawNetNames {true}; // Dynamically write nearby net names (experimental)
100100
QString m_dropppedFile; // File name of the file being dropped by a drag-and-drop operation

0 commit comments

Comments
 (0)