Skip to content

Commit

Permalink
evol(Component): add Nor
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesmadjeri committed Feb 7, 2024
1 parent f743ca6 commit 6799bd4
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/Components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/Component/Elementary/And/And.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
18 changes: 18 additions & 0 deletions src/Component/Elementary/Nor/Nor.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
11 changes: 11 additions & 0 deletions src/Component/Elementary/Nor/Nor.hpp
Original file line number Diff line number Diff line change
@@ -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);
};
}
2 changes: 1 addition & 1 deletion src/Component/Elementary/Not/Not.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
2 changes: 1 addition & 1 deletion src/Component/Elementary/Or/Or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
2 changes: 1 addition & 1 deletion src/Component/Elementary/Xor/Xor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
7 changes: 7 additions & 0 deletions src/Component/Gates/4001/4001.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
#include "4001.hpp"

namespace nts {
void C4001::simulate(std::size_t tick) {
for (auto &pin : _pins)
pin.second.updatePin(tick);
}
}
10 changes: 10 additions & 0 deletions src/Component/Gates/4001/4001.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
#pragma once

#include "../../AComponent.hpp"

namespace nts {
class C4001 : public AComponent {
public:
C4001() : AComponent(14) {};
void simulate(std::size_t tick);
};
}
4 changes: 2 additions & 2 deletions src/Component/Special/False.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 2 additions & 2 deletions src/Component/Special/True.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
6 changes: 4 additions & 2 deletions src/Manager/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 6799bd4

Please sign in to comment.