/*************************************************************************** * Copyright (C) 2005 Nicolas Hadacek * * Copyright (C) 2003-2004 Alain Gibaud * * * * 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_MEMORY_EDITOR_H #define PIC_MEMORY_EDITOR_H #include #include class KToggleAction; #include "devices/gui/memory_editor.h" #include "devices/gui/hex_word_editor.h" #include "devices/pic/pic/pic_memory.h" class PopupButton; namespace Pic { class HexView; //----------------------------------------------------------------------------- class MemoryCaster { public: MemoryCaster(MemoryRangeType type, Device::Memory &memory) : _type(type), _memory(memory) {} MemoryRangeType type() const { return _type; } const Data &device() const { return static_cast(_memory.device()); } const Memory &memory() const { return static_cast(_memory); } Memory &memory() { return static_cast(_memory); } private: MemoryRangeType _type; Device::Memory &_memory; }; //----------------------------------------------------------------------------- class MemoryEditor : public Device::MemoryEditor, public MemoryCaster { Q_OBJECT TQ_OBJECT public: MemoryEditor(MemoryRangeType type, Memory &memory, TQWidget *tqparent, const char *name) : Device::MemoryEditor(&memory, tqparent, name), MemoryCaster(type, memory) {} }; //----------------------------------------------------------------------------- class MemoryEditorLegend : public MemoryEditor { Q_OBJECT TQ_OBJECT public: MemoryEditorLegend(MemoryRangeType type, Memory &memory, TQWidget *tqparent); virtual void setReadOnly(bool) {} static TQColor protectedColor() { return TQColor("#FF8888"); } static TQColor bootColor() { return TQColor("#8888FF"); } static TQColor blockColor(uint i) { return TQColor(BLOCK_COLORS[i]); } signals: void setStartWord(int i); void setEndWord(int i); public slots: virtual void updateDisplay(); private slots: void gotoStart(); void gotoEnd(); private: class Data { public: Data() : button(0), label(0) {} Data(const TQString &text, TQWidget *tqparent); void setProtected(bool on); bool hasAction(const KAction *action) const; PopupButton *button; TQLabel *label; TQValueVector actions; }; Data _boot; TQValueVector _blocks; static const char * const BLOCK_COLORS[Protection::MAX_NB_BLOCKS]; }; //----------------------------------------------------------------------------- class HexWordEditor : public Device::HexWordEditor, public MemoryCaster { Q_OBJECT TQ_OBJECT public: HexWordEditor(MemoryRangeType type, Memory &memory, TQWidget *tqparent); private: virtual BitValue tqmask() const { return memory().device().tqmask(type()); } virtual BitValue normalizeWord(BitValue value) const { return memory().normalizeWord(type(), _offset, value); } virtual BitValue word() const { return memory().word(type(), _offset); } virtual void setWord(BitValue value); }; //----------------------------------------------------------------------------- class MemoryRangeEditor : public Device::MemoryRangeEditor, public MemoryCaster { Q_OBJECT TQ_OBJECT public: MemoryRangeEditor(MemoryRangeType type, Memory &memory, uint nbLines, uint nbCols, uint wordOffset, int nbWords, TQWidget *tqparent); public slots: virtual void updateDisplay(); private: MemoryEditorLegend *_legend; AddressRange _bootRange; AddressRangeVector _blockRanges; AddressRangeVector _codeProtected; virtual uint nbWords() const { return device().nbWords(type()); } virtual uint addressIncrement() const { return device().addressIncrement(type()); } virtual Address startAddress() const { return device().range(type()).start; } virtual Device::HexWordEditor *createHexWordEditor(TQWidget *tqparent); virtual void updateAddressColor(uint i, Address address); virtual bool isRangeReadOnly() const; virtual void addLegend(TQVBoxLayout *vbox); }; //----------------------------------------------------------------------------- class MemoryTypeEditor : public Device::MemoryTypeEditor, public MemoryCaster { Q_OBJECT TQ_OBJECT public: MemoryTypeEditor(const HexView *hexview, MemoryRangeType type, Memory &memory, TQWidget *tqparent, const char *name); virtual void init(bool first); private: virtual bool internalDoAction(Device::Action action); }; //----------------------------------------------------------------------------- class MemoryTypeRangeEditor : public MemoryTypeEditor { Q_OBJECT TQ_OBJECT public: MemoryTypeRangeEditor(const HexView *hexview, MemoryRangeType type, Memory &memory, TQWidget *tqparent); virtual void init(bool first); protected: MemoryRangeEditor *_mre; }; //----------------------------------------------------------------------------- class MemoryUserIdEditor : public MemoryTypeRangeEditor { Q_OBJECT TQ_OBJECT public: MemoryUserIdEditor(const HexView *hexview, Memory &memory, TQWidget *tqparent); virtual void init(bool first); virtual void setReadOnly(bool readOnly); public slots: virtual void updateDisplay(); private slots: void toggleSetToChecksum(); private: bool _saveReadOnly; KToggleAction *_setToChecksum; }; //----------------------------------------------------------------------------- class MemoryCalibrationEditor : public MemoryTypeEditor { Q_OBJECT TQ_OBJECT public: MemoryCalibrationEditor(const HexView *hexview, Memory &memory, TQWidget *tqparent); virtual void init(bool first); private: virtual bool hasAction(Device::Action action) const; virtual bool internalDoAction(Device::Action action); }; } // namespace #endif