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 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/*
2
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15 3 sergeykhbr
 */
16
 
17
#include "RegWidget.h"
18
#include "moc_RegWidget.h"
19
 
20
#include <memory>
21
#include <string.h>
22
#include <QtWidgets/QBoxLayout>
23
#include <QtWidgets/QLabel>
24
 
25
namespace debugger {
26
 
27 4 sergeykhbr
RegWidget::RegWidget(const char *name, int bytes, QWidget *parent)
28 3 sergeykhbr
    : QWidget(parent) {
29
    value_ = 0;
30
 
31
    regName_.make_string(name);
32
    name_ = QString(name);
33
    while (name_.size() < 3) {
34
        name_ += tr(" ");
35
    }
36
 
37
    std::string t1 = "reg " + std::string(name);
38
    cmdRead_.make_string(t1.c_str());
39
 
40
    QFont font = QFont("Courier");
41
    font.setStyleHint(QFont::Monospace);
42
    font.setPointSize(8);
43
    font.setFixedPitch(true);
44
    setFont(font);
45
    QFontMetrics fm(font);
46
 
47
    QHBoxLayout *pLayout = new QHBoxLayout;
48
    pLayout->setContentsMargins(4, 1, 4, 1);
49
    setLayout(pLayout);
50
 
51
    QLabel *label = new QLabel(this);
52
    QSizePolicy labelSizePolicy(QSizePolicy::Preferred,
53
                                QSizePolicy::Preferred);
54
    labelSizePolicy.setHorizontalStretch(0);
55
    labelSizePolicy.setVerticalStretch(0);
56
    labelSizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
57
    label->setSizePolicy(labelSizePolicy);
58
    label->setText(name_);
59
    label->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
60
    pLayout->addWidget(label);
61
 
62
    edit_ = new QLineEdit(this);
63
    pLayout->addWidget(edit_);
64 4 sergeykhbr
    RISCV_sprintf(fmtValue_, sizeof(fmtValue_), "%%0%d" RV_PRI64 "x", 2*bytes);
65 3 sergeykhbr
    respValue_ = value_ = 0xfeedfaceull;
66
 
67
    char tstr[64];
68 4 sergeykhbr
    RISCV_sprintf(tstr, sizeof(tstr), fmtValue_, value_);
69
 
70 3 sergeykhbr
    QString text(tstr);
71
    edit_->setText(text);
72
    edit_->setMaxLength(19);
73
    edit_->setFixedWidth(fm.width(text) + 8);
74
    edit_->setFixedHeight(fm.height() + 2);
75
 
76
    setMinimumWidth(edit_->width() + fm.width(name_) + 16);
77
    setMinimumHeight(edit_->height());
78
 
79
    connect(edit_, SIGNAL(editingFinished()),
80
            this, SLOT(slotEditingFinished()));
81
}
82
 
83
void RegWidget::slotHandleResponse(AttributeType *resp) {
84
    if (!resp->is_dict()) {
85
        return;
86
    }
87
    if (!resp->has_key(regName_.to_string())) {
88
        return;
89
    }
90
    respValue_ = (*resp)[regName_.to_string()].to_uint64();
91
    if (value_ != respValue_) {
92
        char tstr[64];
93
        value_ = respValue_;
94 4 sergeykhbr
        RISCV_sprintf(tstr, sizeof(tstr), fmtValue_, value_);
95 3 sergeykhbr
        QString text(tr(tstr));
96
        edit_->setText(text);
97
    }
98
}
99
 
100
void RegWidget::slotEditingFinished() {
101
    wchar_t wcsConv[128];
102
    char mbsConv[128];
103
    int sz = edit_->text().toWCharArray(wcsConv);
104
    uint64_t new_val;
105
    wcstombs(mbsConv, wcsConv, sz);
106
    mbsConv[sz] = '\0';
107
 
108
    new_val = strtoull(mbsConv, 0, 16);
109
 
110
    if (new_val != value_) {
111
        char tstr[128];
112
        RISCV_sprintf(tstr, sizeof(tstr), "reg %s 0x%s",
113
                      regName_.to_string(), mbsConv);
114
        cmdWrite_.make_string(tstr);
115
 
116
        emit signalChanged(&cmdWrite_);
117
        setFocus();
118
    }
119
}
120
 
121
}  // namespace debugger

powered by: WebSVN 2.1.0

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