149 lines
4.3 KiB
Lua
149 lines
4.3 KiB
Lua
-- Everything is described as if dir=0
|
|
-- z+
|
|
-- /|\ w
|
|
-- | XXX h
|
|
-- +−−−−−−−−−−−> x+
|
|
-- {name,width,height,{cables_left,cables_right,cables_top,cables_bottom}}
|
|
logikraft.components = {
|
|
["and"] = {
|
|
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
|
|
},
|
|
["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,
|
|
ports = {
|
|
left = {"in"},
|
|
right = {"out"},
|
|
top = {"activate",nil}
|
|
},
|
|
inputs = {"in","activate"},
|
|
outputs = {"out"},
|
|
compute = function(inz) if inz["activate"]==1 then return {out = inz["in"]} else return {} end end
|
|
},
|
|
["demux"] = {
|
|
width = 2,
|
|
height = 8,
|
|
ports = {
|
|
left = {nil,nil,nil,nil,nil,"in_3","in_2","in_1"},
|
|
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"},
|
|
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,
|
|
height = 1,
|
|
ports = {
|
|
right = {"out"}
|
|
},
|
|
inputs = {},
|
|
outputs = {"out"}
|
|
},
|
|
["output"] = {
|
|
width = 1,
|
|
height = 1,
|
|
ports = {
|
|
left = {"in"}
|
|
},
|
|
inputs = {"in"},
|
|
outputs = {}
|
|
}
|
|
}
|
|
|
|
for name,cmp in pairs(logikraft.components)
|
|
do
|
|
logikraft.registerComponent(name,cmp)
|
|
end |