2017-04-23 19:13:23 -04:00
|
|
|
#include "AndGate.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-04-23 19:20:29 -04:00
|
|
|
AndGate::AndGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
2017-04-23 19:13:23 -04:00
|
|
|
delay = d;
|
|
|
|
in1 = wire1;
|
|
|
|
in2 = wire2;
|
|
|
|
out = wire3;
|
|
|
|
}
|
|
|
|
int AndGate::evaluate(int evTime) {
|
|
|
|
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
|
|
|
if (out->getValue(evTime + delay) != 0) {
|
2017-04-23 19:20:29 -04:00
|
|
|
e->push(Event(e->size, 0, evTime + delay, out));
|
2017-04-23 19:13:23 -04:00
|
|
|
out->setValue(0, evTime + delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
|
|
|
|
if (out->getValue(evTime + delay) != 1) {
|
2017-04-23 19:20:29 -04:00
|
|
|
e->push(Event(e->size, 1, evTime + delay, out));
|
2017-04-23 19:13:23 -04:00
|
|
|
out->setValue(1, evTime + delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int AndGate::getDelay()
|
|
|
|
{
|
|
|
|
return delay;
|
|
|
|
}
|