summaryrefslogtreecommitdiffstats
path: root/src/devices/pic/base/pic_config.h
blob: 6e132103a0db640cc5f748f370d8a6601da5ac50 (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 <tqmap.h>
#include <tqstringlist.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:
    TQString name;
    TQMap<ConfigNameType, TQStringList> configNames;
    BitValue value;
    bool operator <(const Value &cv) const { return value<cv.value; }
    bool isValid() const { return !name.isEmpty(); }
  };

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

  class Word {
  public:
    TQString name;
    TQStringList ignoredCNames;
    BitValue wtqmask, ptqmask, ctqmask; // write, protected, and checksum bits masks
    BitValue bvalue;              // blank value
    TQValueVector<Mask> masks; // ordered from lower to higher
    BitValue usedMask() const;
  };

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

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

private:
  class MapData {
  public:
    MapData() {}
    MapData(int i, int b) : index(i), block(b) {}
    int index, block;
  };
  static TQMap<TQString, MapData> &masks();
  static TQMap<TQString, MapData> *_masks; // tqmask 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 tqmask;
    Type type;
    const NameData values[50];
  };
  static const Data DATA[];

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

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

} //namespace

#endif