diff --git a/include/Components.hpp b/include/Components.hpp index 1f68d28..7d4dbb5 100644 --- a/include/Components.hpp +++ b/include/Components.hpp @@ -9,4 +9,5 @@ #include "../src/Component/Elementary/And/And.hpp" #include "../src/Component/Elementary/Not/Not.hpp" #include "../src/Component/Elementary/Or/Or.hpp" +#include "../src/Component/Elementary/Nor/Nor.hpp" #include "../src/Component/Elementary/Xor/Xor.hpp" diff --git a/src/Component/Elementary/And/And.hpp b/src/Component/Elementary/And/And.hpp index 3657b28..7298227 100644 --- a/src/Component/Elementary/And/And.hpp +++ b/src/Component/Elementary/And/And.hpp @@ -5,7 +5,7 @@ namespace nts { class And : public AComponent { public: - And() : AComponent(3) {}; + And() : AComponent(3, nts::ComponentType::COMPONENT) {}; void simulate(std::size_t tick); }; } diff --git a/src/Component/Elementary/Nor/Nor.cpp b/src/Component/Elementary/Nor/Nor.cpp new file mode 100644 index 0000000..e136972 --- /dev/null +++ b/src/Component/Elementary/Nor/Nor.cpp @@ -0,0 +1,18 @@ +#include "Nor.hpp" + +namespace nts { + void Nor::simulate(std::size_t tick) { + for (auto &pin : _pins) + pin.second.updatePin(tick); + + if (_pins[1].getState() == Tristate::True || _pins[2].getState() == Tristate::True) { + _pins[3].setState(Tristate::False); + return; + } else if (_pins[1].getState() == Tristate::Undefined || _pins[2].getState() == Tristate::Undefined) { + _pins[3].setState(Tristate::Undefined); + return; + } else { + _pins[3].setState(Tristate::True); + } + } +} diff --git a/src/Component/Elementary/Nor/Nor.hpp b/src/Component/Elementary/Nor/Nor.hpp new file mode 100644 index 0000000..d4a1699 --- /dev/null +++ b/src/Component/Elementary/Nor/Nor.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "../../AComponent.hpp" + +namespace nts { + class Nor : public AComponent { + public: + Nor() : AComponent(3, nts::ComponentType::COMPONENT) {}; + void simulate(std::size_t tick); + }; +} diff --git a/src/Component/Elementary/Not/Not.hpp b/src/Component/Elementary/Not/Not.hpp index 62c76c9..ec60025 100644 --- a/src/Component/Elementary/Not/Not.hpp +++ b/src/Component/Elementary/Not/Not.hpp @@ -5,7 +5,7 @@ namespace nts { class Not : public AComponent { public: - Not() : AComponent(2) {}; + Not() : AComponent(2, nts::ComponentType::COMPONENT) {}; void simulate(std::size_t tick); }; } diff --git a/src/Component/Elementary/Or/Or.hpp b/src/Component/Elementary/Or/Or.hpp index 45f55da..cf2e1d0 100644 --- a/src/Component/Elementary/Or/Or.hpp +++ b/src/Component/Elementary/Or/Or.hpp @@ -5,7 +5,7 @@ namespace nts { class Or : public AComponent { public: - Or() : AComponent(3) {}; + Or() : AComponent(3, nts::ComponentType::COMPONENT) {}; void simulate(std::size_t tick); }; } diff --git a/src/Component/Elementary/Xor/Xor.hpp b/src/Component/Elementary/Xor/Xor.hpp index 7a13de6..3cb211c 100644 --- a/src/Component/Elementary/Xor/Xor.hpp +++ b/src/Component/Elementary/Xor/Xor.hpp @@ -5,7 +5,7 @@ namespace nts { class Xor : public AComponent { public: - Xor() : AComponent(3) {}; + Xor() : AComponent(3, nts::ComponentType::COMPONENT) {}; void simulate(std::size_t tick); }; } diff --git a/src/Component/Gates/4001/4001.cpp b/src/Component/Gates/4001/4001.cpp index 4b5e1f6..f8611d1 100644 --- a/src/Component/Gates/4001/4001.cpp +++ b/src/Component/Gates/4001/4001.cpp @@ -1 +1,8 @@ #include "4001.hpp" + +namespace nts { + void C4001::simulate(std::size_t tick) { + for (auto &pin : _pins) + pin.second.updatePin(tick); + } +} diff --git a/src/Component/Gates/4001/4001.hpp b/src/Component/Gates/4001/4001.hpp index 6f70f09..d3193ec 100644 --- a/src/Component/Gates/4001/4001.hpp +++ b/src/Component/Gates/4001/4001.hpp @@ -1 +1,11 @@ #pragma once + +#include "../../AComponent.hpp" + +namespace nts { + class C4001 : public AComponent { + public: + C4001() : AComponent(14) {}; + void simulate(std::size_t tick); + }; +} diff --git a/src/Component/Special/False.hpp b/src/Component/Special/False.hpp index 348169b..360e690 100644 --- a/src/Component/Special/False.hpp +++ b/src/Component/Special/False.hpp @@ -3,9 +3,9 @@ #include "../AComponent.hpp" namespace nts { - class FalseC : public AComponent { + class CFalse : public AComponent { public: - FalseC() : AComponent(1, nts::ComponentType::INPUT) { + CFalse() : AComponent(1, nts::ComponentType::INPUT) { this->getPin(1).setState(nts::Tristate::False); }; diff --git a/src/Component/Special/True.hpp b/src/Component/Special/True.hpp index 1173568..d3b7cad 100644 --- a/src/Component/Special/True.hpp +++ b/src/Component/Special/True.hpp @@ -3,9 +3,9 @@ #include "../AComponent.hpp" namespace nts { - class TrueC : public AComponent { + class CTrue : public AComponent { public: - TrueC() : AComponent(1, nts::ComponentType::INPUT) { + CTrue() : AComponent(1, nts::ComponentType::INPUT) { this->getPin(1).setState(nts::Tristate::True); }; diff --git a/src/Manager/Manager.cpp b/src/Manager/Manager.cpp index 967f0a4..843be1b 100644 --- a/src/Manager/Manager.cpp +++ b/src/Manager/Manager.cpp @@ -25,15 +25,17 @@ namespace nts { else if (type == "clock") return this->addComponent(label, new nts::Clock()); else if (type == "true") - return this->addComponent(label, new TrueC()); + return this->addComponent(label, new nts::CTrue()); else if (type == "false") - return this->addComponent(label, new FalseC()); + return this->addComponent(label, new nts::CFalse()); else if (type == "and") return this->addComponent(label, new nts::And()); else if (type == "not") return this->addComponent(label, new nts::Not()); else if (type == "or") return this->addComponent(label, new nts::Or()); + else if (type == "nor") + return this->addComponent(label, new nts::Nor()); else if (type == "xor") return this->addComponent(label, new nts::Xor());