diff --git a/Makefile b/Makefile index 20e5107..fb8cfaf 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,8 @@ CMPT = $(CMPT_P)AComponent.cpp \ $(CMPT_P)c4040.cpp \ $(CMPT_P)c4069.cpp \ $(CMPT_P)c4071.cpp \ - $(CMPT_P)c4081.cpp + $(CMPT_P)c4081.cpp \ + $(CMPT_P)c4514.cpp PARSER_P = $(SRC_P)parser/ PARSER = $(PARSER_P)Parser.cpp \ diff --git a/include/Create.hpp b/include/Create.hpp index 98dd42b..de7f36c 100644 --- a/include/Create.hpp +++ b/include/Create.hpp @@ -21,6 +21,7 @@ # include "c4069.hpp" # include "c4071.hpp" # include "c4081.hpp" +# include "c4514.hpp" # include "Output.hpp" diff --git a/include/Pin.hpp b/include/Pin.hpp index 218da5a..1aa92da 100644 --- a/include/Pin.hpp +++ b/include/Pin.hpp @@ -5,6 +5,7 @@ # include #include "IComponent.hpp" +#include "ErrorParser.hpp" namespace nts { diff --git a/include/c4514.hpp b/include/c4514.hpp new file mode 100644 index 0000000..9349e6b --- /dev/null +++ b/include/c4514.hpp @@ -0,0 +1,23 @@ +#ifndef c4514_HPP_ +# define c4514_HPP_ + +# include "AComponent.hpp" + +namespace nts +{ + class c4514 : public AComponent + { + public: + c4514(const std::string & = ""); + virtual nts::Tristate Compute(std::size_t pin_num_this = 1); + virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); + virtual void Dump(void) const; + virtual ~c4514(void); + + private: + int value; + Tristate prevClock; + }; +} + +#endif \ No newline at end of file diff --git a/samples/AND b/samples/AND new file mode 100644 index 0000000..6efb2bc --- /dev/null +++ b/samples/AND @@ -0,0 +1,23 @@ +.chipsets: +input a +input b +input c +input d +input e + +output s +4081 gate + +.links: +a:1 gate:1 +b:1 gate:2 +gate:3 gate:13 + +c:1 gate:5 +d:1 gate:6 +gate:4 gate:12 + +gate:11 gate:9 +e:1 gate:8 + +gate:10 s:1 \ No newline at end of file diff --git a/samples/c4514 b/samples/c4514 new file mode 100644 index 0000000..acac2f1 --- /dev/null +++ b/samples/c4514 @@ -0,0 +1,51 @@ +.chipsets: +input i1 +input i2 +input i3 +input i4 +input iI +input iS + +4514 c4514 + +output o1 +output o2 +output o3 +output o4 +output o5 +output o6 +output o7 +output o8 +output o9 +output o10 +output o11 +output o12 +output o13 +output o14 +output o15 +output o16 + +.links: +o1:1 c4514:11 +o2:1 c4514:9 +o3:1 c4514:10 +o4:1 c4514:8 +o5:1 c4514:7 +o6:1 c4514:6 +o7:1 c4514:5 +o8:1 c4514:4 +o9:1 c4514:18 +o10:1 c4514:17 +o11:1 c4514:20 +o12:1 c4514:19 +o13:1 c4514:14 +o14:1 c4514:13 +o15:1 c4514:16 +o16:1 c4514:15 + +c4514:2 i1:1 +c4514:3 i2:1 +c4514:21 i3:1 +c4514:22 i4:1 +c4514:1 iS:1 +c4514:23 iI:1 \ No newline at end of file diff --git a/src/components/Pin.cpp b/src/components/Pin.cpp index 396bf47..a220cea 100644 --- a/src/components/Pin.cpp +++ b/src/components/Pin.cpp @@ -36,7 +36,12 @@ namespace nts Tristate Pin::getState() const {return (this->state);} - nts::Tristate Pin::compute() {return (this->component->Compute(this->target_pin));} + nts::Tristate Pin::compute() + { + //if (this->component) + return (this->component->Compute(this->target_pin)); + //throw ErrorParser("Attempt to compute a linkless pin.", "FLEMME DE DIRE OU"); + } Pin::Mode Pin::getMode() const {return (this->mode);} } diff --git a/src/components/c4081.cpp b/src/components/c4081.cpp index 97a8bc0..9280f31 100644 --- a/src/components/c4081.cpp +++ b/src/components/c4081.cpp @@ -31,8 +31,8 @@ namespace nts return (this->pins[pin_num_this].compute()); else { - Tristate t1 = this->pins[pin_num_this + ((pin_num_this % 2) ? (1) : (-1))].compute(); - Tristate t2 = this->pins[pin_num_this + ((pin_num_this % 2) ? (2) : (-2))].compute(); + Tristate t1 = this->pins[pin_num_this + ((pin_num_this == 2 || pin_num_this == 9) ? (-1) : (1))].compute(); + Tristate t2 = this->pins[pin_num_this + ((pin_num_this == 2 || pin_num_this == 9) ? (-2) : (2))].compute(); return ((t1 && t2)); } } diff --git a/src/components/c4514.cpp b/src/components/c4514.cpp new file mode 100644 index 0000000..dced142 --- /dev/null +++ b/src/components/c4514.cpp @@ -0,0 +1,87 @@ +#include "c4514.hpp" + +namespace nts +{ + c4514::c4514(const std::string &) : value(0), prevClock(FALSE) + { + this->name = "4514"; + this->type = nts::AComponent::Type::C; + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::VSS}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::O}); + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::I}); + this->pins.push_back(Pin{nts::Pin::VDD}); + } + + nts::Tristate c4514::Compute(std::size_t pin_num_this) + { + if (pin_num_this < 1 || pin_num_this > 23 || pin_num_this == 12) + return (UNDEFINED); + pin_num_this--; + if (this->pins[pin_num_this].getMode() == Pin::I) + return (this->pins[pin_num_this].compute()); + else + { + if (this->pins[22].compute() == TRUE) + return (FALSE); + if (this->pins[22].compute() == UNDEFINED || this->pins[0].compute() == UNDEFINED) + return (FALSE); + if (this->prevClock == TRUE && this->pins[0].compute() == FALSE) + { + if (this->pins[1].compute() == UNDEFINED || this->pins[2].compute() == UNDEFINED || this->pins[20].compute() == UNDEFINED || this->pins[21].compute() == UNDEFINED) + return (UNDEFINED); + this->value = 0; + if (this->pins[1].compute() == TRUE) + this->value += 1; + if (this->pins[2].compute() == TRUE) + this->value += 2; + if (this->pins[20].compute() == TRUE) + this->value += 4; + if (this->pins[21].compute() == TRUE) + this->value += 8; + } + this->prevClock = this->pins[0].compute(); + std::vector values = {{11, 9, 10, 8, 7, 6, 5, 4, 18, 17, 20, 19, 14, 13, 16, 15}}; + if (pin_num_this == values[this->value] - 1) + return (TRUE); + return (FALSE); + } + } + + void c4514::SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target) + { + if (pin_num_this < 1 || pin_num_this > 23 || pin_num_this == 12) + return ; + pin_num_this--; + this->pins[pin_num_this].setComponent(component); + this->pins[pin_num_this].setTarget(pin_num_target); + } + + void c4514::Dump(void) const + { + std::cout << "Chipset " << this->name << std::endl; + } + + c4514::~c4514(void) + { + } +} \ No newline at end of file diff --git a/src/core.cpp b/src/core.cpp index 123cd70..a36a118 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -5,14 +5,16 @@ bool cmp_icmp(const nts::IComponent *c1, const nts::IComponent *c2) { - return (dynamic_cast(c1)->getName() == dynamic_cast(c2)->getName()); + return (dynamic_cast(c1)->getName().compare(dynamic_cast(c2)->getName())); } std::vector map_to_vector(std::map &chipsets) { std::vector chipsets_v; for(std::map::iterator it = chipsets.begin(); it != chipsets.end(); ++it ) - chipsets_v.push_back( it->second ); + { + chipsets_v.push_back(it->second); + } std::sort(chipsets_v.begin(), chipsets_v.end(), cmp_icmp); return (chipsets_v); } diff --git a/src/parser/Create.cpp b/src/parser/Create.cpp index 9f8fa2e..95ca3fd 100644 --- a/src/parser/Create.cpp +++ b/src/parser/Create.cpp @@ -21,7 +21,7 @@ nts::IComponent * Create::createComponent(const std::string &type, const std::st {"4071", {[](const std::string &value) {return (new nts::c4071(value));}}}, {"4081", {[](const std::string &value) {return (new nts::c4081(value));}}}, // {"4094", {[](const std::string &value) {return (new nts::c4094(value));}}}, - // {"4514", {[](const std::string &value) {return (new nts::c4514(value));}}}, + {"4514", {[](const std::string &value) {return (new nts::c4514(value));}}}, // {"4801", {[](const std::string &value) {return (new nts::c4801(value));}}}, // {"2716", {[](const std::string &value) {return (new nts::c2716(value));}}} }; diff --git a/src/parser/Parser.cpp b/src/parser/Parser.cpp index 4cf2d62..fbaf548 100644 --- a/src/parser/Parser.cpp +++ b/src/parser/Parser.cpp @@ -27,6 +27,7 @@ void set_links(std::stringstream &str, std::map { it1->second->SetLink(stoi(match[2]), *(it2->second), stoi(match[4])); it2->second->SetLink(stoi(match[4]), *(it1->second), stoi(match[2])); +// std::cout << "Link set between chipsets \x1b[31m" << match[1] << "\x1b[0m and \x1b[31m" << match[3]<< "\x1b[0m with pins \x1b[32m" << match[2] << "\x1b[0m and \x1b[32m" << match[4] << "\x1b[0m." << std::endl; } else throw ErrorParser("Unknown component name.", ((it1 == chipsets.end()) ? (match[1]) : (match[3])));