2 * avr-sim: An atmel AVR simulator
3 * Copyright (C) 2008 Tom Haber
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "Registers.h"
25 #include "RuntimeException.h"
29 IORegisters::IORegisters(unsigned int count
) {
31 setEach( regs
.begin(), regs
.end(), (IORegister
*)0 );
34 IORegisters::~IORegisters() {
35 std::for_each( regs
.begin(), regs
.end(), Delete
<IORegister
>() );
38 void IORegisters::addReg( word addr
, IORegister
*reg
) {
40 throw util::RuntimeException(
41 util::format("Register %s shares I/O location with %s")
42 % reg
->getName() % regs
[addr
]->getName() );
47 IORegister
*IORegisters::getIoreg(const std::string
& name
, bool required
) const {
48 std::vector
<IORegister
*>::const_iterator it
;
49 for(it
= regs
.begin(); it
!= regs
.end(); ++it
) {
50 if( ((*it
) != 0) && (*it
)->getName() == name
)
54 if( it
== regs
.end() ) {
58 throw util::RuntimeException(
59 util::format("Unable to find register %s") % name
);
65 void IORegisters::reset() {
66 std::for_each( regs
.begin(), regs
.end(),
67 MethodCall
<IORegister
>(&IORegister::reset
) );
70 IORegister::operator unsigned char() {
72 hw
->regAccess( this );
77 unsigned char IORegister::operator =(unsigned char val
) {
78 unsigned char ret
= Register::operator =(val
);
80 hw
->regChanged( this );
84 void IORegister::operator |=(unsigned char val
) {
87 hw
->regChanged( this );
90 void IORegister::operator &=(unsigned char val
) {
93 hw
->regChanged( this );