summaryrefslogtreecommitdiffstats
path: root/src/devices/pic/gui/pic_group_ui.cpp
blob: d2ff2f4fa3bb772ad5d5facb290c2bd7f0cdec2d (plain)
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
/***************************************************************************
 *   Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "pic_group_ui.h"

#include <kaction.h>

#include "libgui/main_global.h"
#include "pic_hex_view.h"
#include "pic_register_view.h"
#include "pic_config_editor.h"
#include "coff/base/text_coff.h"
#include "libgui/gui_debug_manager.h"
#include "common/gui/list_container.h"

Device::HexView *Pic::GroupUI::createHexView(const HexEditor &editor, TQWidget *parent) const
{
  return new HexView(editor, parent);
}

Register::View *Pic::GroupUI::createRegisterView(TQWidget *parent) const
{
  return new RegisterView(parent);
}

Device::MemoryEditor *Pic::GroupUI::createConfigEditor(Device::Memory &memory, TQWidget *parent) const
{
  return new MemoryConfigEditorWidget(static_cast<Memory &>(memory), false, parent);
}

void Pic::GroupUI::fillWatchListContainer(ListContainer *container, TQValueVector<Register::TypeData> &ids) const
{
  ids.clear();
  const Pic::Data &data = static_cast<const Pic::Data &>(*Main::deviceData());
  const Pic::RegistersData &rdata = data.registersData();
  ListContainer *branch = container->appendBranch(i18n("SFRs"));
  TQValueVector<Pic::RegisterNameData> list = Pic::sfrList(data);
  for (uint i=0; i<list.count(); i++) {
    branch->appendItem(list[i].label(), ids.count(), ListContainer::UnChecked);
    ids.append(list[i].data());
  }
  branch = container->appendBranch(i18n("I/Os"));
  for (uint i=0; i<Device::MAX_NB_PORTS; i++) {
    if ( !rdata.hasPort(i) ) continue;
    TQString name = rdata.portName(i);
    branch->appendItem(name, ids.count(), ListContainer::UnChecked);
    ids.append(Register::TypeData(rdata.sfrs[name].address, rdata.nbChars()));
  }
  branch = container->appendBranch(i18n("GPRs"));
  const Coff::Object *coff = Debugger::manager->coff();
  list = Pic::gprList(data, coff);
  for (uint k=0; k<rdata.nbBanks; k++) {
    if ( !rdata.isBankUsed(k) ) continue;
    ListContainer *bbranch = (rdata.nbBanks==1 ? branch : branch->appendBranch(i18n("Bank %1").arg(k)));
    uint nb = 0;
    for (uint i=0; i<list.count(); i++) {
      if ( rdata.bankFromAddress(list[i].data().address())!=k ) continue;
      bbranch->appendItem(list[i].label(), ids.count(), ListContainer::UnChecked);
      ids.append(list[i].data());
      nb++;
    }
  }
  branch = container->appendBranch(i18n("Variables"));
  if (coff) {
    list = Pic::variableList(data, *coff);
    if ( list.count()==0 ) {
      branch->appendItem(i18n("No variable"), ids.count(), ListContainer::Disabled);
      ids.append(Register::TypeData());
    } else for (uint i=0; i<list.count(); i++) {
      branch->appendItem(list[i].label(), ids.count(), ListContainer::UnChecked);
      ids.append(list[i].data());
    }
  } else {
    branch->appendItem(i18n("Please compile the current project"), ids.count(), ListContainer::Disabled);
    ids.append(Register::TypeData());
  }
}

Register::ListViewItem *Pic::GroupUI::createWatchItem(const Register::TypeData &data, KListViewItem *parent) const
{
  return new Pic::RegisterListViewItem(data, parent);
}