2017-04-23 19:13:23 -04:00
|
|
|
#include "NandGate.h"
|
2017-04-25 10:51:14 -04:00
|
|
|
#include <iostream>
|
2017-04-23 19:13:23 -04:00
|
|
|
|
|
|
|
NandGate::NandGate(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
|
2017-04-23 19:46:37 -04:00
|
|
|
Event NandGate::evaluate(int evTime)
|
2017-04-23 19:13:23 -04:00
|
|
|
{
|
|
|
|
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
2017-04-25 10:36:51 -04:00
|
|
|
return Event(1, evTime + delay, out);
|
2017-04-23 19:13:23 -04:00
|
|
|
}
|
2017-04-25 10:10:07 -04:00
|
|
|
else if (in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1) {
|
2017-04-25 10:36:51 -04:00
|
|
|
return Event(0, evTime + delay, out);
|
2017-04-23 19:13:23 -04:00
|
|
|
}
|
2017-04-25 10:10:07 -04:00
|
|
|
else{
|
2017-04-25 10:36:51 -04:00
|
|
|
return Event(-1, evTime + delay, out);
|
2017-04-25 10:10:07 -04:00
|
|
|
}
|
2017-04-23 19:13:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int NandGate::getDelay()
|
|
|
|
{
|
|
|
|
return delay;
|
|
|
|
}
|