add undefined logic to all gates

This commit is contained in:
Joel Beckmeyer 2017-04-25 10:10:07 -04:00
parent 93a176884d
commit fb0c023cf4
7 changed files with 25 additions and 5 deletions

View File

@ -16,6 +16,9 @@ Event AndGate::evaluate(int evTime) {
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){ else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
return Event(-1, 1, evTime + delay, out); return Event(-1, 1, evTime + delay, out);
} }
else{
return Event(-1, -1, evTime + delay, out);
}
} }
int AndGate::getDelay() int AndGate::getDelay()

View File

@ -13,9 +13,12 @@ Event NandGate::evaluate(int evTime)
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) { if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
return Event(-1, 1, evTime + delay, out); return Event(-1, 1, evTime + delay, out);
} }
else { else if (in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1) {
return Event(-1, 0, evTime + delay, out); return Event(-1, 0, evTime + delay, out);
} }
else{
return Event(-1, -1, evTime + delay, out);
}
} }
int NandGate::getDelay() int NandGate::getDelay()

View File

@ -16,6 +16,9 @@ Event NorGate::evaluate(int evTime) {
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) { else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
return Event(-1, 1, evTime + delay, out); return Event(-1, 1, evTime + delay, out);
} }
else{
return Event(-1, -1, evTime + delay, out);
}
} }
int NorGate::getDelay() int NorGate::getDelay()

View File

@ -9,11 +9,13 @@ NotGate::NotGate(int d, Wire* wire1, Wire* wire2) {
} }
Event NotGate::evaluate(int evTime) { Event NotGate::evaluate(int evTime) {
if (in1->getValue(evTime) == 0) { if (in1->getValue(evTime) == 1) {
return Event(-1, 0, evTime + delay, out); return Event(-1, 0, evTime + delay, out);
}else if (in1->getValue(evTime) == 0) {
return Event(-1, 1, evTime + delay, out);
} }
else { else {
return Event(-1, 1, evTime + delay, out); return Event(-1, -1, evTime + delay, out);
} }
} }

View File

@ -16,6 +16,9 @@ Event OrGate::evaluate(int evTime) {
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) { else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
return Event(-1, 0, evTime + delay, out); return Event(-1, 0, evTime + delay, out);
} }
else{
return Event(-1, -1, evTime + delay, out);
}
} }
int OrGate::getDelay() int OrGate::getDelay()

View File

@ -18,6 +18,9 @@ Event XnorGate::evaluate(int evTime) {
return Event(-1, 0, evTime + delay, out); return Event(-1, 0, evTime + delay, out);
} }
} }
else {
return Event(-1, -1, evTime + delay, out);
}
} }
int XnorGate::getDelay() int XnorGate::getDelay()

View File

@ -18,6 +18,9 @@ Event XorGate::evaluate(int evTime) {
return Event(-1, 0, evTime + delay, out); return Event(-1, 0, evTime + delay, out);
} }
} }
else {
return Event(-1, -1, evTime + delay, out);
}
} }
int XorGate::getDelay() int XorGate::getDelay()