Skip to content

Commit

Permalink
🔀Merge pull request #80 from Marius-P1/79-make-the-4515-bonus
Browse files Browse the repository at this point in the history
🔀 79 make the 4515 bonus
  • Loading branch information
6im0n authored Mar 3, 2024
2 parents 10cfa79 + 309bf60 commit ff974a5
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _SRC = Main.cpp \
Components/Advanced/4094.cpp \
Components/Advanced/4512.cpp \
Components/Advanced/4040.cpp \
Components/Advanced/4515.cpp \



Expand Down
76 changes: 76 additions & 0 deletions TestFile/NtsSingle/4515.nts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 4-bits Decoder (4515)
#
# +-11- out_00
# | +-09- out_01
# | | +-10- out_02
# | | | +-08- out_03
# | | | | +-07- out_04
# inhibit -23-+ | | | | | +-06- out_05
# | | | | | | |
# +---4515--------v---^---^---^---^---^---^-------+
# | | | | | | | | |
# in_0 -2->---+---+---+---+---+---+---+---+---+---+---+--->-05- out_06
# | | L | | | |
# in_1 -3->---| A |---| +--->-04- out_07
# | | T | | 4-to-16 DECODER | |
# in_2 -21->---| C |---| +--->-18- out_08
# | | H | | | |
# in_3 -22->---+---+---+-------+---+---+---+---+---+---+--->-17- out_09
# | | ign ign | | | | | | |
# +-----^---+---+-----v---v---v---v---v---v-------+
# | | | | | | | | |
# strobe -1-+ | | | | | | | +-20- out_10
# -12-+ | | | | | +-19- out_11
# -24-+ | | | +-14- out_12
# | | +-13- out_13
# | +-16- out_14
# +-15- out_15

.chipsets:
input in_0
input in_1
input in_2
input in_3
input strobe
input inhibit
output out_00
output out_01
output out_02
output out_03
output out_04
output out_05
output out_06
output out_07
output out_08
output out_09
output out_10
output out_11
output out_12
output out_13
output out_14
output out_15
4515 decoder

.links:
in_0:1 decoder:2
in_1:1 decoder:3
in_2:1 decoder:21
in_3:1 decoder:22
strobe:1 decoder:1
inhibit:1 decoder:23
out_00:1 decoder:11
out_01:1 decoder:9
out_02:1 decoder:10
out_03:1 decoder:8
out_04:1 decoder:7
out_05:1 decoder:6
out_06:1 decoder:5
out_07:1 decoder:4
out_08:1 decoder:18
out_09:1 decoder:17
out_10:1 decoder:20
out_11:1 decoder:19
out_12:1 decoder:14
out_13:1 decoder:13
out_14:1 decoder:16
out_15:1 decoder:15
25 changes: 25 additions & 0 deletions include/Components/Advanced/4515.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
** EPITECH PROJECT, 2024
** MicroTekSpice
** File description:
** 4515
*/

#pragma once

#include "Components/AComponent.hpp"

namespace nts {
class C4515 : public AComponent {
public:
C4515(std::string name = "");
~C4515() = default;
nts::Tristate compute(std::size_t pin) override;
void updateState(void);
void resetState(void);
void initialOutput(void);
private:
std::vector<nts::Tristate> _out;
std::map<size_t, size_t> _pinMap;
};
}
1 change: 1 addition & 0 deletions include/Components/ComponentsInclude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
#include "Components/Advanced/4512.hpp"
#include "Components/Advanced/4094.hpp"
#include "Components/Advanced/4040.hpp"
#include "Components/Advanced/4515.hpp"
102 changes: 102 additions & 0 deletions src/Components/Advanced/4515.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
** EPITECH PROJECT, 2024
** MicroTekSpice
** File description:
** 4515
*/

/*
4-bits Decoder (4515)
+-11- out_00
| +-09- out_01
| | +-10- out_02
| | | +-08- out_03
| | | | +-07- out_04
inhibit -23-+ | | | | | +-06- out_05
| | | | | | |
+---4515--------v---^---^---^---^---^---^-------+
| | | | | | | | |
in_0 -2->---+---+---+---+---+---+---+---+---+---+---+--->-05- out_06
| | L | | | |
in_1 -3->---| A |---| +--->-04- out_07
| | T | | 4-to-16 DECODER | |
in_2 -21->---| C |---| +--->-18- out_08
| | H | | | |
in_3 -22->---+---+---+-------+---+---+---+---+---+---+--->-17- out_09
| | ign ign | | | | | | |
+-----^---+---+-----v---v---v---v---v---v-------+
| | | | | | | | |
strobe -1-+ | | | | | | | +-20- out_10
-12-+ | | | | | +-19- out_11
-24-+ | | | +-14- out_12
| | +-13- out_13
| +-16- out_14
+-15- out_15
*/

#include "Components/Advanced/4515.hpp"

nts::C4515::C4515(std::string name) : AComponent(24, name)
{
this->_out = std::vector<nts::Tristate>(16, nts::Tristate::Undefined);
this->_pinMap = {{11, 0}, {9, 1}, {10, 2}, {8, 3}, {7, 4}, {6, 5}, {5, 6}, {4, 7}, {18, 8}, {17, 9}, {20, 10}, {19, 11}, {14, 12}, {13, 13}, {16, 14}, {15, 15}};
this->initialOutput();
}

nts::Tristate nts::C4515::compute(std::size_t pin)
{
nts::Tristate inhibit = getLink(23);

this->checkIfNotLoop();
if (pin == 0 || pin == 24 || pin == 12 || pin > this->_pins.size())
return nts::Tristate::Undefined;
if (pin == 2 || pin == 3 || pin == 21 || pin == 22 || pin == 23) {
return this->_links[pin]->compute(this->_pins[pin]);
}
this->updateState();
if (inhibit == nts::Tristate::True || inhibit == nts::Tristate::Undefined)
return nts::Tristate::True;
else
return this->_out[this->_pinMap.find(pin)->second];
}

void nts::C4515::initialOutput(void)
{
for (int i = 1; i < 16; i++)
this->_out[i] = nts::Tristate::True;
this->_out[0] = nts::Tristate::False;
}

void nts::C4515::resetState(void)
{
for (int i = 0; i < 16; i++)
this->_out[i] = nts::Tristate::True;
}

void nts::C4515::updateState(void)
{
nts::Tristate strobe = getLink(1);
nts::Tristate in_a = getLink(2);
nts::Tristate in_b = getLink(3);
nts::Tristate in_c = getLink(21);
nts::Tristate in_d = getLink(22);
std::array<nts::Tristate, 4> inputsArray = {in_a, in_b, in_c, in_d};
std::array<bool, 4> inputs = {0, 0, 0, 0};
int binaryValue = 0;

if (strobe == nts::Tristate::False || strobe == nts::Tristate::Undefined) {
return;
}
if (in_a == nts::Tristate::Undefined || in_b == nts::Tristate::Undefined || in_c == nts::Tristate::Undefined || in_d == nts::Tristate::Undefined) {
for (int i = 0; i < 16; i++)
this->_out[i] = nts::Tristate::Undefined;
return;
}
for (int i = 0; i < 4; i++) {
inputs[i] = (inputsArray[i] == nts::Tristate::True) ? 1 : 0;
binaryValue += inputs[i] * (1 << i);
}
this->resetState();
this->_out[binaryValue] = nts::Tristate::False;
}
1 change: 1 addition & 0 deletions src/NanoTekSpice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ std::unique_ptr<nts::IComponent> nts::NanoTekSpice::createComponent(const std::s
{"4512", [](const std::string &name) { return std::make_unique<C4512>( C4512(name)); }},
{"4094", [](const std::string &name) { return std::make_unique<C4094>( C4094(name)); }},
{"4040", [](const std::string &name) { return std::make_unique<C4040>( C4040(name)); }},
{"4515", [](const std::string &name) { return std::make_unique<C4515>( C4515(name)); }},
{"logger", [](const std::string &name) { return std::make_unique<Logger>( Logger(name)); }},
};

Expand Down
106 changes: 106 additions & 0 deletions tests/Components/TestAdvancedComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,109 @@ Test(C4512, TestInput)

cr_assert_eq(c4512->compute(11), nts::Tristate::True);
}
//--------------------------------- 4515 ---------------------------------

Test(C4515, TestWrongPin)
{
nts::C4515 C4515comp("test");

cr_assert_eq(C4515comp.compute(0), nts::Tristate::Undefined);
}

Test(C4515, TestCompute1)
{
nts::IComponent *C4515 = new nts::C4515("test");
nts::IComponent *strobe = new nts::InputComponent("test");
nts::IComponent *inhibit = new nts::InputComponent("test");
nts::IComponent *dataA = new nts::InputComponent("test");
nts::IComponent *dataB = new nts::InputComponent("test");
nts::IComponent *dataC = new nts::InputComponent("test");
nts::IComponent *dataD = new nts::InputComponent("test");

C4515->setLink(1, *strobe, 1);
C4515->setLink(2, *dataA, 1);
C4515->setLink(3, *dataB, 1);
C4515->setLink(21, *dataC, 1);
C4515->setLink(22, *dataD, 1);
C4515->setLink(23, *inhibit, 1);

dataA->setState(nts::Tristate::False);
dataB->setState(nts::Tristate::False);
dataC->setState(nts::Tristate::False);
dataD->setState(nts::Tristate::False);
strobe->setState(nts::Tristate::True);
inhibit->setState(nts::Tristate::False);

cr_assert_eq(C4515->compute(11), nts::Tristate::False);
}

Test(C4515, TestDataUndefined)
{
nts::IComponent *C4515 = new nts::C4515("test");
nts::IComponent *strobe = new nts::InputComponent("test");
nts::IComponent *inhibit = new nts::InputComponent("test");
nts::IComponent *dataA = new nts::InputComponent("test");
nts::IComponent *dataB = new nts::InputComponent("test");
nts::IComponent *dataC = new nts::InputComponent("test");
nts::IComponent *dataD = new nts::InputComponent("test");

C4515->setLink(1, *strobe, 1);
C4515->setLink(2, *dataA, 1);
C4515->setLink(3, *dataB, 1);
C4515->setLink(21, *dataC, 1);
C4515->setLink(22, *dataD, 1);
C4515->setLink(23, *inhibit, 1);

dataA->setState(nts::Tristate::Undefined);
dataB->setState(nts::Tristate::Undefined);
dataC->setState(nts::Tristate::Undefined);
dataD->setState(nts::Tristate::Undefined);
strobe->setState(nts::Tristate::True);
inhibit->setState(nts::Tristate::False);

cr_assert_eq(C4515->compute(11), nts::Tristate::Undefined);
}

Test(C4515, TestInputPin)
{
nts::IComponent *C4515 = new nts::C4515("test");
nts::IComponent *dataA = new nts::InputComponent("test");

C4515->setLink(2, *dataA, 1);

dataA->setState(nts::Tristate::True);

cr_assert_eq(C4515->compute(2), nts::Tristate::True);
}

Test(C4515, TestInhibit)
{
nts::IComponent *C4515 = new nts::C4515("test");
nts::IComponent *strobe = new nts::InputComponent("test");
nts::IComponent *inhibit = new nts::InputComponent("test");

C4515->setLink(1, *strobe, 1);
C4515->setLink(23, *inhibit, 1);


strobe->setState(nts::Tristate::True);
inhibit->setState(nts::Tristate::True);

cr_assert_eq(C4515->compute(11), nts::Tristate::True);
}

Test(C4515, TestInhibit2)
{
nts::IComponent *C4515 = new nts::C4515("test");
nts::IComponent *strobe = new nts::InputComponent("test");
nts::IComponent *inhibit = new nts::InputComponent("test");

C4515->setLink(1, *strobe, 1);
C4515->setLink(23, *inhibit, 1);


strobe->setState(nts::Tristate::True);
inhibit->setState(nts::Tristate::Undefined);

cr_assert_eq(C4515->compute(11), nts::Tristate::True);
}

0 comments on commit ff974a5

Please sign in to comment.