diff --git a/include/Pin.hpp b/include/Pin.hpp index fafb82e..ceea1d1 100644 --- a/include/Pin.hpp +++ b/include/Pin.hpp @@ -33,10 +33,12 @@ namespace nts void setTarget(std::size_t); void setState(Tristate); void setMode(Mode); + void setCalc(int); bool isLinked() const; IComponent &getComponent() const; std::size_t getTargetPin() const; Tristate getState() const; + int getReset() const; Mode getMode() const; public: @@ -45,6 +47,8 @@ namespace nts private: Mode mode; nts::IComponent *component; + int calculating; + int to_reset; Tristate state; std::size_t target_pin; }; diff --git a/nres b/nres index e69de29..2d2d91e 100644 --- a/nres +++ b/nres @@ -0,0 +1,612 @@ +a=1 +b=0 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j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+d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j=0 +oc=0 diff --git a/result b/result index e69de29..d4af471 100644 --- a/result +++ b/result @@ -0,0 +1,613 @@ +a=1 +b=0 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 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1 +oc=1 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=1 +oc=0 +> > a=1 +b=0 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=1 +b=0 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=1 +c=0 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=1 +cascade=1 +d=0 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=1 +e=0 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=1 +d=0 +e=1 +f=0 +g=0 +h=0 +i=0 +j=0 +oc=0 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j=0 +oc=1 +> > a=0 +b=0 +c=0 +cascade=0 +d=0 +e=0 +f=1 +g=0 +h=0 +i=0 +j=0 +oc=0 +> \ No newline at end of file diff --git a/samples/tmp b/samples/tmp index e69de29..200e528 100644 --- a/samples/tmp +++ b/samples/tmp @@ -0,0 +1,39 @@ +.chipsets: +clock clock +input reset + +output oc + +output a +output b +output c +output d +output e +output f +output g +output h +output i +output j + +output cascade + +4017 johnson + +.links: +clock:1 johnson:14 +reset:1 johnson:15 + +a:1 johnson:3 +b:1 johnson:2 +c:1 johnson:4 +d:1 johnson:7 +e:1 johnson:10 +f:1 johnson:1 +g:1 johnson:5 +h:1 johnson:6 +i:1 johnson:9 +j:1 johnson:11 + +cascade:1 johnson:12 + +clock:1 oc:1 \ No newline at end of file diff --git a/src/components/AComponent.cpp b/src/components/AComponent.cpp index 215eabf..83805cf 100644 --- a/src/components/AComponent.cpp +++ b/src/components/AComponent.cpp @@ -19,7 +19,9 @@ namespace nts size_t i = 0; while (i < this->pins.size()) { - this->pins[i].setState(UNDEFINED); + if (this->pins[i].getReset()) + this->pins[i].setState(UNDEFINED); + this->pins[i].setCalc(0); i++; } return (UNDEFINED); diff --git a/src/components/Pin.cpp b/src/components/Pin.cpp index be66a36..d95b447 100644 --- a/src/components/Pin.cpp +++ b/src/components/Pin.cpp @@ -2,11 +2,11 @@ namespace nts { - Pin::Pin(Mode _mode) : mode(_mode), component(0), state(UNDEFINED), target_pin(0) + Pin::Pin(Mode _mode) : mode(_mode), component(0), calculating(0), to_reset(1), state(UNDEFINED), target_pin(0) { } - Pin::Pin(const Pin &other) : mode(other.getMode()), component(&other.getComponent()), state(other.getState()), target_pin(other.getTargetPin()) + Pin::Pin(const Pin &other) : mode(other.getMode()), component(&other.getComponent()), calculating(0), to_reset(1), state(other.getState()), target_pin(other.getTargetPin()) { } @@ -19,6 +19,8 @@ namespace nts this->component = &other.getComponent(); this->state = other.getState(); this->target_pin = other.getTargetPin(); + this->calculating = 0; + this->to_reset = 1; return (*this); } @@ -30,6 +32,8 @@ namespace nts void Pin::setMode(Mode _mode) {this->mode = _mode;} + void Pin::setCalc(int _calc) {this->calculating = _calc;} + bool Pin::isLinked() const { if (this->component) @@ -41,6 +45,8 @@ namespace nts std::size_t Pin::getTargetPin() const {return (this->target_pin);} + int Pin::getReset() const {return (this->to_reset);} + Tristate Pin::getState() const {return (this->state);} nts::Tristate Pin::compute() @@ -49,7 +55,16 @@ namespace nts return (this->state); if (this->component) { + if (this->calculating) + { + this->calculating = 0; + this->state = UNDEFINED; + to_reset = 0; + return (UNDEFINED); + } + this->calculating = 1; this->state = this->component->Compute(this->target_pin); + this->calculating = 0; return (this->state); } throw Error("Attempt to compute a linkless pin.", "FLEMME DE DIRE OU");