1 #ifndef AVR_REGISTERS_H
2 #define AVR_REGISTERS_H
15 Register(word address
, const std::string
& name
);
19 void init(word address
, const std::string
& name
);
20 unsigned char operator =(unsigned char val
);
21 operator unsigned char() const;
22 void operator =(const Register
& reg
);
25 void set(unsigned char val
);
26 unsigned char get() const;
29 word
getAddress() const { return address
; }
30 const std::string
& getName() const { return name
; }
38 class IORegister
: public Register
{
40 IORegister(word address
, const std::string
& name
,
41 unsigned char initial
= 0);
45 unsigned char operator =(unsigned char val
);
46 void operator |=(unsigned char val
);
47 void operator &=(unsigned char val
);
50 void registerHW(Hardware
*hw
);
53 unsigned char initial
;
59 IORegisters(unsigned int count
);
63 unsigned int size() const { return regs
.size(); }
66 * Reset all registers to their initial value.
71 * Reads a single bytes of raw data from the register memory
72 * at offset \e offset.
74 byte
readByte(unsigned int offset
) const;
77 * Writes a single bytes of raw data to the register memory
78 * at offset \e offset.
80 void writeByte(unsigned int offset
, byte val
);
83 void addReg( word addr
, IORegister
*reg
);
84 IORegister
& getIoreg(unsigned int offset
) const;
85 IORegister
*getIoreg(const std::string
& name
, bool required
= true) const;
88 std::vector
<IORegister
*> regs
;
91 inline Register::Register(word address
, const std::string
& name
) {
92 init( address
, name
);
95 inline void Register::init(word address
, const std::string
& name
) {
96 this->address
= address
;
100 inline IORegister::IORegister(word address
,
101 const std::string
& name
, unsigned char initial
)
102 : Register(address
, name
), initial(initial
), hw(0) {
105 inline void IORegister::reset() {
109 inline void Register::set(unsigned char val
) {
113 inline unsigned char Register::get() const {
117 inline void Register::operator =(const Register
& reg
) {
118 *this = (unsigned char)reg
;
121 inline byte
IORegisters::readByte(unsigned int offset
) const {
122 if( regs
[offset
] != 0 )
123 return (byte
)*regs
[offset
];
128 inline void IORegisters::writeByte(unsigned int offset
, byte val
) {
129 if( regs
[offset
] != 0 )
130 (*regs
[offset
]) = val
;
133 inline IORegister
& IORegisters::getIoreg(unsigned int offset
) const {
134 return *regs
[offset
];
137 inline void IORegister::registerHW(Hardware
*hw
) {
143 #endif /*AVR_REGISTERS_H*/