summaryrefslogtreecommitdiffstats
path: root/src/devices/pic/base/pic_config.h
blob: 185a19e1b70e9bee10616a7d265c34cbc127f024 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *   Copyright (C) 2005-2007 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.                                   *
 ***************************************************************************/
#ifndef PIC_CONFIG_H
#define PIC_CONFIG_H

#include <qmap.h>
#include <qstringlist.h>

#include "common/common/bitvalue.h"
#include "pic_protection.h"
#include "pic.h"

namespace Pic
{
class Data;

BEGIN_DECLARE_ENUM(ConfigNameType)
  Default = 0, Extra, SDCC
END_DECLARE_ENUM_STD(ConfigNameType)

class Config
{
public:
  class Value {
  public:
    QString name;
    QMap<ConfigNameType, QStringList> configNames;
    BitValue value;
    bool operator <(const Value &cv) const { return value<cv.value; }
    bool isValid() const { return !name.isEmpty(); }
  };

  class Mask {
  public:
    QString name;
    BitValue value;
    QValueVector<Value> values; // ordered from lower to higher
    bool operator <(const Mask &cm) const { return value<cm.value; }
  };

  class Word {
  public:
    QString name;
    QStringList ignoredCNames;
    BitValue wmask, pmask, cmask; // write, protected, and checksum bits masks
    BitValue bvalue;              // blank value
    QValueVector<Mask> masks; // ordered from lower to higher
    BitValue usedMask() const;
  };

public:
  Config(const Pic::Data &data) : _data(data), _protection(data, *this) {}
  QValueVector<Word> _words;
  const Protection &protection() const { return _protection; }

  const Value *findValue(const QString &mask, const QString &value) const;
  const Mask *findMask(const QString &mask, uint *wordIndex = 0) const;
  static bool hasMaskName(const QString &mask);
  static QString maskLabel(const QString &mask);
  bool checkValueName(const QString &mask, const QString &name) const;
  static QString valueLabel(const QString &mask, const QString &name);

private:
  class MapData {
  public:
    MapData() {}
    MapData(int i, int b) : index(i), block(b) {}
    int index, block;
  };
  static QMap<QString, MapData> &masks();
  static QMap<QString, MapData> *_masks; // mask name -> index in DATA

  struct NameData {
    const char *name, *label;
  };
  enum Type { Fixed, ValueDouble, ValueUInt, Ratio, MemoryRange, Toggle, Pin, Pins };
  class Data {
  public:
    const NameData mask;
    Type type;
    const NameData values[50];
  };
  static const Data DATA[];

private:
  const Pic::Data &_data;
  Protection _protection;
};

QDataStream &operator <<(QDataStream &s, const Config::Value &value);
QDataStream &operator >>(QDataStream &s, Config::Value &value);
QDataStream &operator <<(QDataStream &s, const Config::Mask &mask);
QDataStream &operator >>(QDataStream &s, Config::Mask &mask);
QDataStream &operator <<(QDataStream &s, const Config::Word &word);
QDataStream &operator >>(QDataStream &s, Config::Word &word);
QDataStream &operator <<(QDataStream &s, const Config &config);
QDataStream &operator >>(QDataStream &s, Config &config);

} //namespace

#endif