From 4f3f006d0dd1691cb1a6fd70ad04fccd4a1a7439 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 25 Apr 2017 14:38:15 -0400 Subject: [PATCH] finish the program and fix when a wire goes undefined --- Radec/Radec/circuit7.txt | 2 +- Radec/Radec/ff.txt | 7 +++++++ Radec/Radec/ff_v.txt | 12 ++++++++++++ circuit/circuit7.txt | 2 +- src/NandGate.cpp | 1 - src/Simulation.cpp | 11 ++++++++--- 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 Radec/Radec/ff.txt create mode 100644 Radec/Radec/ff_v.txt diff --git a/Radec/Radec/circuit7.txt b/Radec/Radec/circuit7.txt index 9ebf271..1176a19 100644 --- a/Radec/Radec/circuit7.txt +++ b/Radec/Radec/circuit7.txt @@ -1,5 +1,5 @@ CIRCUIT DrivesTwo -INPUT A 1DrivesTwo +INPUT A 1 OUTPUT B 3 OUTPUT C 4 NOT 2ns 1 3 diff --git a/Radec/Radec/ff.txt b/Radec/Radec/ff.txt new file mode 100644 index 0000000..d4128dd --- /dev/null +++ b/Radec/Radec/ff.txt @@ -0,0 +1,7 @@ +CIRCUIT flipflop1 +INPUT R 1 +INPUT S 2 +OUTPUT O 3 +NOR 2ns 2 3 4 +NOR 2ns 1 4 3 + diff --git a/Radec/Radec/ff_v.txt b/Radec/Radec/ff_v.txt new file mode 100644 index 0000000..719b800 --- /dev/null +++ b/Radec/Radec/ff_v.txt @@ -0,0 +1,12 @@ +VECTOR flipflop1 +INPUT R 0 1 +INPUT S 0 1 +INPUT R 1 0 +INPUT S 1 0 +INPUT S 2 1 +INPUT S 3 0 +INPUT S 5 1 +INPUT S 6 0 +INPUT R 9 1 +INPUT R 10 0 + diff --git a/circuit/circuit7.txt b/circuit/circuit7.txt index 9ebf271..1176a19 100644 --- a/circuit/circuit7.txt +++ b/circuit/circuit7.txt @@ -1,5 +1,5 @@ CIRCUIT DrivesTwo -INPUT A 1DrivesTwo +INPUT A 1 OUTPUT B 3 OUTPUT C 4 NOT 2ns 1 3 diff --git a/src/NandGate.cpp b/src/NandGate.cpp index 7f428dd..526b7fb 100644 --- a/src/NandGate.cpp +++ b/src/NandGate.cpp @@ -11,7 +11,6 @@ NandGate::NandGate(int d, Wire * wire1, Wire * wire2, Wire * wire3) Event NandGate::evaluate(int evTime) { - cout << evTime << " " << in1->getValue(evTime) << " " << in2->getValue(evTime) << endl; if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) { return Event(1, evTime + delay, out); } diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 3aa9e32..77e772b 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -110,8 +110,8 @@ bool Simulation::parseVector(string fileName) { return false; } - string tmpString; - int timeInt, valInt; + string tmpString, valInt; + int timeInt; Wire *tmpWire = nullptr; // get rid of first line @@ -129,7 +129,12 @@ bool Simulation::parseVector(string fileName) { } } - e.push(Event(valInt, timeInt, tmpWire)); + if (valInt == "X") { + e.push(Event(-1, timeInt, tmpWire)); + } + else { + e.push(Event(atoi(valInt.c_str()), timeInt, tmpWire)); + } } }