-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀Merge pull request #80 from Marius-P1/79-make-the-4515-bonus
🔀 79 make the 4515 bonus
- Loading branch information
Showing
7 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters