radec/src/nandGate.cpp

32 lines
632 B
C++

#include "nandGate.h"
nandGate::nandGate(priority_queue<event> *eQueue, int d, wire * wire1, wire * wire2, wire * wire3)
{
in1 = wire1;
in2 = wire2;
out = wire3;
delay = d;
e = eQueue;
}
void nandGate::evaluate(int evTime)
{
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
if (out->getValue(evTime + delay) != 1) {
e->push(event(e->size, 1, evTime + delay, out));
out->setValue(1, evTime + delay);
}
}
else {
if (out->getValue(evTime + delay) != 0) {
e->push(event(e->size, 0, evTime + delay, out));
out->setValue(0, evTime + delay);
}
}
}
int nandGate::getDelay()
{
return delay;
}