Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Registers.cpp
blobe8b13edc746bdada9e40efff9eb16863f2d1dfcc
1 /*
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"
20 #include "Util.h"
21 #include "Hardware.h"
22 #include <algorithm>
24 #include "Format.h"
25 #include "RuntimeException.h"
27 namespace avr {
29 IORegisters::IORegisters(unsigned int count) {
30 regs.resize( 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 ) {
39 if( regs[addr] != 0 )
40 throw util::RuntimeException(
41 util::format("Register %s shares I/O location with %s")
42 % reg->getName() % regs[addr]->getName() );
44 regs[ addr ] = reg;
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 )
51 break;
54 if( it == regs.end() ) {
55 if( ! required )
56 return 0;
58 throw util::RuntimeException(
59 util::format("Unable to find register %s") % name );
62 return (*it);
65 void IORegisters::reset() {
66 std::for_each( regs.begin(), regs.end(),
67 MethodCall<IORegister>(&IORegister::reset) );
70 IORegister::operator unsigned char() {
71 if( hw != 0 )
72 hw->regAccess( this );
74 return val;
77 unsigned char IORegister::operator =(unsigned char val) {
78 unsigned char ret = Register::operator =(val);
79 if( hw != 0 )
80 hw->regChanged( this );
81 return ret;
84 void IORegister::operator |=(unsigned char val) {
85 this->val |= val;
86 if( hw != 0 )
87 hw->regChanged( this );
90 void IORegister::operator &=(unsigned char val) {
91 this->val &= val;
92 if( hw != 0 )
93 hw->regChanged( this );