OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [CpuWidgets/] [RegWidget.cpp] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      CPU' register editor.
6
 */
7
 
8
#include "RegWidget.h"
9
#include "moc_RegWidget.h"
10
 
11
#include <memory>
12
#include <string.h>
13
#include <QtWidgets/QBoxLayout>
14
#include <QtWidgets/QLabel>
15
 
16
namespace debugger {
17
 
18
RegWidget::RegWidget(const char *name, QWidget *parent)
19
    : QWidget(parent) {
20
    value_ = 0;
21
 
22
    regName_.make_string(name);
23
    name_ = QString(name);
24
    while (name_.size() < 3) {
25
        name_ += tr(" ");
26
    }
27
 
28
    std::string t1 = "reg " + std::string(name);
29
    cmdRead_.make_string(t1.c_str());
30
 
31
    QFont font = QFont("Courier");
32
    font.setStyleHint(QFont::Monospace);
33
    font.setPointSize(8);
34
    font.setFixedPitch(true);
35
    setFont(font);
36
    QFontMetrics fm(font);
37
 
38
    QHBoxLayout *pLayout = new QHBoxLayout;
39
    pLayout->setContentsMargins(4, 1, 4, 1);
40
    setLayout(pLayout);
41
 
42
    QLabel *label = new QLabel(this);
43
    QSizePolicy labelSizePolicy(QSizePolicy::Preferred,
44
                                QSizePolicy::Preferred);
45
    labelSizePolicy.setHorizontalStretch(0);
46
    labelSizePolicy.setVerticalStretch(0);
47
    labelSizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
48
    label->setSizePolicy(labelSizePolicy);
49
    label->setText(name_);
50
    label->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
51
    pLayout->addWidget(label);
52
 
53
    edit_ = new QLineEdit(this);
54
    pLayout->addWidget(edit_);
55
    respValue_ = value_ = 0xfeedfaceull;
56
 
57
    char tstr[64];
58
    RISCV_sprintf(tstr, sizeof(tstr), "%016" RV_PRI64 "x", value_);
59
    QString text(tstr);
60
    edit_->setText(text);
61
    edit_->setMaxLength(19);
62
    edit_->setFixedWidth(fm.width(text) + 8);
63
    edit_->setFixedHeight(fm.height() + 2);
64
 
65
    setMinimumWidth(edit_->width() + fm.width(name_) + 16);
66
    setMinimumHeight(edit_->height());
67
 
68
    connect(edit_, SIGNAL(editingFinished()),
69
            this, SLOT(slotEditingFinished()));
70
}
71
 
72
void RegWidget::slotHandleResponse(AttributeType *resp) {
73
    if (!resp->is_dict()) {
74
        return;
75
    }
76
    if (!resp->has_key(regName_.to_string())) {
77
        return;
78
    }
79
    respValue_ = (*resp)[regName_.to_string()].to_uint64();
80
    if (value_ != respValue_) {
81
        char tstr[64];
82
        value_ = respValue_;
83
        RISCV_sprintf(tstr, sizeof(tstr), "%016" RV_PRI64 "x", value_);
84
        QString text(tr(tstr));
85
        edit_->setText(text);
86
    }
87
}
88
 
89
void RegWidget::slotEditingFinished() {
90
    wchar_t wcsConv[128];
91
    char mbsConv[128];
92
    int sz = edit_->text().toWCharArray(wcsConv);
93
    uint64_t new_val;
94
    wcstombs(mbsConv, wcsConv, sz);
95
    mbsConv[sz] = '\0';
96
 
97
    new_val = strtoull(mbsConv, 0, 16);
98
 
99
    if (new_val != value_) {
100
        char tstr[128];
101
        RISCV_sprintf(tstr, sizeof(tstr), "reg %s 0x%s",
102
                      regName_.to_string(), mbsConv);
103
        cmdWrite_.make_string(tstr);
104
 
105
        emit signalChanged(&cmdWrite_);
106
        setFocus();
107
    }
108
}
109
 
110
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.