summaryrefslogtreecommitdiffstats
path: root/src/devices/gui/hex_word_editor.h
blob: fad46a8770910ff76d9ac91b4689d282bcdc5fd4 (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
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *   Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr>           *
 *                                                                         *
 *   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 HEX_WORD_EDITOR_H
#define HEX_WORD_EDITOR_H

#include "common/gui/hexword_gui.h"
#include "devices/base/generic_memory.h"

namespace Device
{
//-----------------------------------------------------------------------------
class HexWordEditor : public GenericHexWordEditor
{
Q_OBJECT
  
public:
  HexWordEditor(Memory &memory, uint nbChars, TQWidget *parent);
  void setOffset(int offset);
  int offset() const { return _offset; }

protected:
  Device::Memory &_memory;
  int _offset;

  virtual bool isValid() const { return _offset!=-1; }
  virtual BitValue mask() const = 0;
  virtual BitValue normalizeWord(BitValue value) const = 0;
  virtual BitValue word() const = 0;
  virtual void setWord(BitValue value) = 0;
  virtual BitValue blankValue() const { return BitValue(); }
};

//-----------------------------------------------------------------------------
class RegisterHexWordEditor : public GenericHexWordEditor
{
Q_OBJECT
  
public:
  RegisterHexWordEditor(TQWidget *parent, uint nbChars, BitValue mask);
  void clear() { setValue(BitValue()); }
  void setValue(BitValue word);
  BitValue value() const { return _word; }
  void setColor(TQColor color) { setPaletteForegroundColor(color); }
  void unsetColor() { unsetPalette(); }

private:
  BitValue _mask, _word;

  virtual bool isValid() const { return true; }
  virtual BitValue mask() const { return _mask; }
  virtual BitValue normalizeWord(BitValue value) const { return value.maskWith(_mask); }
  virtual BitValue word() const { return _word; }
  virtual void setWord(BitValue value) { _word = value; }
  virtual BitValue blankValue() const { return BitValue(); }
};

} // namespace

#endif