Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
  • Loading branch information
clecat committed Mar 5, 2017
1 parent 5ed2f90 commit 350caa6
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions include/Create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# include "c4069.hpp"
# include "c4071.hpp"
# include "c4081.hpp"
# include "c4514.hpp"

# include "Output.hpp"

Expand Down
1 change: 1 addition & 0 deletions include/Pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# include <iostream>

#include "IComponent.hpp"
#include "ErrorParser.hpp"

namespace nts
{
Expand Down
23 changes: 23 additions & 0 deletions include/c4514.hpp
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions samples/AND
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions samples/c4514
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/components/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);}
}
4 changes: 2 additions & 2 deletions src/components/c4081.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
87 changes: 87 additions & 0 deletions src/components/c4514.cpp
Original file line number Diff line number Diff line change
@@ -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<unsigned long int> 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)
{
}
}
6 changes: 4 additions & 2 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

bool cmp_icmp(const nts::IComponent *c1, const nts::IComponent *c2)
{
return (dynamic_cast<const nts::AComponent *>(c1)->getName() == dynamic_cast<const nts::AComponent *>(c2)->getName());
return (dynamic_cast<const nts::AComponent *>(c1)->getName().compare(dynamic_cast<const nts::AComponent *>(c2)->getName()));
}

std::vector<nts::IComponent *> map_to_vector(std::map<std::string, nts::IComponent *> &chipsets)
{
std::vector<nts::IComponent *> chipsets_v;
for(std::map<std::string, nts::IComponent *>::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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));}}}
};
Expand Down
1 change: 1 addition & 0 deletions src/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void set_links(std::stringstream &str, std::map<std::string, nts::IComponent *>
{
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])));
Expand Down

0 comments on commit 350caa6

Please sign in to comment.