75 lines
1.3 KiB
Lua
75 lines
1.3 KiB
Lua
|
|
Gate = {}
|
|
|
|
function Gate.new(self, objref, definition)
|
|
local o = {
|
|
objref = objref,
|
|
definition = definition,
|
|
ports = {}
|
|
}
|
|
setmetatable(o, self)
|
|
self.__index = self
|
|
return o
|
|
end
|
|
|
|
function Gate.addport(self, port)
|
|
self.ports[#self.ports+1] = port
|
|
Port.setgate(port, self)
|
|
end
|
|
|
|
function Gate.getportstate(self, index)
|
|
return self.ports[index].state
|
|
end
|
|
|
|
function Gate.setportstate(self, index, state)
|
|
Port.setstate(self.ports[index], state)
|
|
end
|
|
|
|
function Gate.initdata(self)
|
|
self.data = {}
|
|
end
|
|
|
|
function Gate.getdata(self)
|
|
return self.data
|
|
end
|
|
|
|
function Gate.getportisrising(self, index)
|
|
return Port.isrising(self.ports[index])
|
|
end
|
|
|
|
function Gate:getportisfalling(index)
|
|
return Port.isfalling(self.ports[index])
|
|
end
|
|
|
|
-- function Gate:cb(...)
|
|
-- local args = {...}
|
|
-- local str = tostring(#args)
|
|
|
|
-- for i, v in ipairs(args) do
|
|
-- v = bool_to_int[v] or tostring(v)
|
|
-- str = str .. "\t" .. tostring(v)
|
|
-- end
|
|
|
|
-- sim:queuecallback(self, str)
|
|
-- end
|
|
|
|
function Gate.cb(self, ...)
|
|
Simulation.queuecallback(sim, self, ...)
|
|
end
|
|
|
|
function Gate.queue(self, delay)
|
|
Simulation.queuegatelater(sim, self, delay)
|
|
end
|
|
|
|
function Gate.testlogic(self, n)
|
|
--local time = os.clock()
|
|
--for i = 1, n do
|
|
-- self.definition.logic(self)
|
|
--end
|
|
--client:send("TEST\t" .. (os.clock()-time) .. "\n")
|
|
end
|
|
|
|
function Gate.gettick(self)
|
|
return sim.currenttick
|
|
end
|