Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Bus.cpp
blobc429ffdfe10b2793860b2c107ed2a9a429c65557
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 "Bus.h"
20 #include "Hardware.h"
21 #include "Util.h"
23 #include "RuntimeException.h"
24 #include "Format.h"
26 namespace avr {
28 Bus::Bus() {
29 irqPending = 0;
30 intVectors.resize( intVectorsSize );
33 Bus::~Bus() {
34 std::for_each( hardware.begin(), hardware.end(), Delete<Hardware>() );
37 void Bus::reset() {
38 clearAll();
40 std::list<Hardware*>::iterator it;
41 for(it = hardware.begin(); it != hardware.end(); ++it) {
42 (*it)->reset();
45 irqPending = 0;
48 bool Bus::isHoldingCPU() {
49 bool holding = false;
51 std::list<Hardware*>::const_iterator it;
52 for(it = hardware.begin(); it != hardware.end(); ++it) {
53 holding = holding || (*it)->isHoldingCPU();
56 return holding;
59 void Bus::addInterrupt(unsigned int vector, unsigned int address,
60 const char *name) {
61 if( vector >= intVectorsSize )
62 throw util::RuntimeException(
63 util::format("Tried to add not existing interrupt %d") % vector );
65 intVectors[vector] = IntVect( address, name );
68 void Bus::claimInterrupt(unsigned int vector, Hardware *hw) {
69 if( vector >= intVectorsSize )
70 throw util::RuntimeException(
71 util::format("Hardware tried to claim not existing interrupt %d") % vector );
73 if( intVectors[vector].hw != 0 )
74 throw util::RuntimeException(
75 util::format("Hardware tried to claim already claimed interrupt %d") % vector );
77 intVectors[vector].hw = hw;
81 void Bus::beforeInvokeInterrupt(unsigned int vector) {
82 clearInterrupt(vector);
84 if( intVectors[vector].hw != 0 )
85 intVectors[vector].hw->beforeInvokeInterrupt(vector);