Added more components

This commit is contained in:
2024-05-20 14:18:52 +02:00
parent a1177efa69
commit a5cbf1d7b2
10 changed files with 90 additions and 2 deletions
+86 -1
View File
@@ -16,6 +16,81 @@ logikraft.components = {
outputs = {"out"},
compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 0 or 1} end
},
["nand"] = {
width = 2,
height = 3,
ports = {
left = {"in_2",nil,"in_1"},
right = {nil,"out",nil}
},
inputs = {"in_1","in_2"},
outputs = {"out"},
compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 1 or 0} end
},
["or"] = {
width = 2,
height = 3,
ports = {
left = {"in_2",nil,"in_1"},
right = {nil,"out",nil}
},
inputs = {"in_1","in_2"},
outputs = {"out"},
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 0 or 1} end
},
["nor"] = {
width = 2,
height = 3,
ports = {
left = {"in_2",nil,"in_1"},
right = {nil,"out",nil}
},
inputs = {"in_1","in_2"},
outputs = {"out"},
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 1 or 0} end
},
["xor"] = {
width = 2,
height = 3,
ports = {
left = {"in_2",nil,"in_1"},
right = {nil,"out",nil}
},
inputs = {"in_1","in_2"},
outputs = {"out"},
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 1) and 1 or 0} end
},
["not"] = {
width = 2,
height = 1,
ports = {
left = {"in"},
right = {"out"}
},
inputs = {"in"},
outputs = {"out"},
compute = function(inz) return {out = 1 - inz["in"]} end
},
["on"] = {
width = 1,
height = 1,
ports = {
right = {"out"}
},
inputs = {},
outputs = {"out"},
compute = function(inz) return {out = 1} end
},
["off"] = {
width = 1,
height = 1,
ports = {
right = {"out"}
},
inputs = {},
outputs = {"out"},
compute = function(inz) return {out = 0} end
},
["switch"] = {
width = 2,
height = 1,
@@ -36,7 +111,17 @@ logikraft.components = {
right = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"}
},
inputs = {"in_1","in_2","in_3"},
outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"}
outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"},
compute = function(inz) return {
out_1 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0,
out_2 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0,
out_3 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0,
out_4 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0,
out_5 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0,
out_6 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0,
out_7 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0,
out_8 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0,
} end
},
["input"] = {
width = 1,