radec/src/XorGate.cpp

31 lines
586 B
C++
Raw Normal View History

2017-04-23 19:18:11 -04:00
#include "XorGate.h"
using namespace std;
XorGate::XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
delay = d;
in1 = wire1;
in2 = wire2;
out = wire3;
}
2017-04-26 11:20:20 -04:00
// generate an event based on changes in the Gate's inputs
Event XorGate::evaluate(int evTime) {
2017-04-23 19:18:11 -04:00
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
if (in1->getValue(evTime) != in2->getValue(evTime)) {
return Event(1, evTime + delay, out);
2017-04-23 19:18:11 -04:00
}
else {
return Event(0, evTime + delay, out);
2017-04-23 19:18:11 -04:00
}
}
2017-04-25 10:10:07 -04:00
else {
return Event(-1, evTime + delay, out);
2017-04-25 10:10:07 -04:00
}
2017-04-23 19:18:11 -04:00
}
int XorGate::getDelay()
{
return delay;
}