84 lines
1.4 KiB
Lua
84 lines
1.4 KiB
Lua
|
|
Gate = {}
|
|
|
|
FFI.cdef[[
|
|
struct Gate {
|
|
int objref;
|
|
int definition_objref;
|
|
bool in_queue;
|
|
struct Port ports[1];
|
|
};
|
|
]]
|
|
|
|
function Gate.new(self, objref, definition)
|
|
local o = {
|
|
objref = objref,
|
|
definition = definition,
|
|
ports = {},
|
|
in_queue = false,
|
|
logic = definition.logic,
|
|
}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
function Gate.addport(gate, port)
|
|
gate.ports[#gate.ports+1] = port
|
|
Port.setgate(port, gate)
|
|
end
|
|
|
|
function Gate.getportstate(gate, index)
|
|
return gate.ports[index].group.state
|
|
end
|
|
|
|
function Gate.setportstate(gate, index, state)
|
|
Port.setstate(gate.ports[index], state)
|
|
end
|
|
|
|
function Gate.initdata(gate)
|
|
gate.data = {}
|
|
end
|
|
|
|
function Gate.getdata(gate)
|
|
return gate.data
|
|
end
|
|
|
|
function Gate.getportisrising(gate, index)
|
|
return Port.isrising(gate.ports[index])
|
|
end
|
|
|
|
function Gate.getportisfalling(gate, index)
|
|
return Port.isfalling(gate.ports[index])
|
|
end
|
|
|
|
function Gate.cb(gate, ...)
|
|
Simulation.queuecallback(GSim, gate, ...)
|
|
end
|
|
|
|
function Gate.queue(gate, delay)
|
|
Simulation.queuegatelater(GSim, gate, delay)
|
|
end
|
|
|
|
function Gate.gettick(gate)
|
|
return GSim.currenttick
|
|
end
|
|
|
|
function Gate.getdefinition(gate)
|
|
return gate.definition
|
|
end
|
|
|
|
-- Logic functions
|
|
|
|
function Gate.init(gate)
|
|
Gate.getdefinition(gate).init(gate)
|
|
end
|
|
|
|
function Gate.logic(gate)
|
|
gate.logic(gate)
|
|
end
|
|
|
|
function Gate.input(gate, argv)
|
|
Gate.getdefinition(gate).input(gate, argv)
|
|
end
|