92 lines
1.7 KiB
Lua
92 lines
1.7 KiB
Lua
|
|
local ffi = FFI
|
|
|
|
Gate = {}
|
|
|
|
function Gate.new(objref, definition)
|
|
local o = {
|
|
in_queue = 0,
|
|
logic = definition.logic,
|
|
ports = {},
|
|
port_nets = {},
|
|
port_states = {},
|
|
|
|
objref = objref,
|
|
definition = definition,
|
|
}
|
|
return o
|
|
end
|
|
|
|
-- Logic Critical
|
|
function Gate.getportstate(gate, index)
|
|
--return gate[index*2].state
|
|
return gate.port_nets[index].state
|
|
end
|
|
|
|
-- Logic Critical
|
|
function Gate.setportstate(gate, index, state)
|
|
--if state ~= gate[index*2+1] then
|
|
if state ~= gate.port_states[index] then
|
|
--local group = gate[index*2]
|
|
local group = gate.port_nets[index]
|
|
--group.state_num = group.state_num - gate[index*2+1] + state
|
|
group.state_num = group.state_num - gate.port_states[index] + state
|
|
--gate[index*2+1] = state
|
|
gate.port_states[index] = state
|
|
|
|
if (group.state_num>0) ~= (group.state==1) and (group.in_queue==0) then
|
|
Simulation.queuegroup(GSim, group)
|
|
end
|
|
end
|
|
end
|
|
|
|
function Gate.preinit(gate)
|
|
|
|
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.current_tick
|
|
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
|