make current tick c
This commit is contained in:
parent
cbfc8fd42e
commit
17edf2a782
@ -93,7 +93,7 @@ function Gate.queue(gate, delay)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Gate.gettick(gate)
|
function Gate.gettick(gate)
|
||||||
return GSim.current_tick
|
return GSim.current_tick[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Gate.getdefinition(gate)
|
function Gate.getdefinition(gate)
|
||||||
|
@ -36,11 +36,11 @@ function Port.getconnectionposition(port)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Port.isrising(port)
|
function Port.isrising(port)
|
||||||
return port.group.state[0]==1 and (port.group.update_tick[0] == GSim.current_tick)
|
return port.group.state[0]==1 and (port.group.update_tick[0] == GSim.current_tick[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
function Port.isfalling(port)
|
function Port.isfalling(port)
|
||||||
return port.group.state[0]==0 and (port.group.update_tick[0] == GSim.current_tick)
|
return port.group.state[0]==0 and (port.group.update_tick[0] == GSim.current_tick[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
function Port.getgate(port)
|
function Port.getgate(port)
|
||||||
|
@ -8,14 +8,17 @@ ffi.cdef [[
|
|||||||
|
|
||||||
Simulation = {}
|
Simulation = {}
|
||||||
|
|
||||||
|
local queue_max = 65536
|
||||||
|
|
||||||
function Simulation.new(sim)
|
function Simulation.new(sim)
|
||||||
local o = {
|
local o = {
|
||||||
groupqueue = ffi.new("struct Net*[131072]"),
|
-- Logic Critical
|
||||||
|
groupqueue = ffi.new("struct Net*["..queue_max.."]"),
|
||||||
num_groupqueue = ffi.new("int[1]"),
|
num_groupqueue = ffi.new("int[1]"),
|
||||||
gatequeue = ffi.new("struct Gate*[131072]"),
|
gatequeue = ffi.new("struct Gate*["..queue_max.."]"),
|
||||||
num_gatequeue = ffi.new("int[1]"),
|
num_gatequeue = ffi.new("int[1]"),
|
||||||
|
current_tick = ffi.new("int[1]"),
|
||||||
--groupfxqueue = {},
|
--groupfxqueue = {},
|
||||||
current_tick = 0,
|
|
||||||
|
|
||||||
definitions = {},
|
definitions = {},
|
||||||
wires = {},
|
wires = {},
|
||||||
@ -30,12 +33,12 @@ function Simulation.new(sim)
|
|||||||
inputqueue = nil,
|
inputqueue = nil,
|
||||||
tickqueue = {},
|
tickqueue = {},
|
||||||
callbacks = nil,
|
callbacks = nil,
|
||||||
|
|
||||||
}
|
}
|
||||||
setmetatable(o, sim)
|
setmetatable(o, sim)
|
||||||
sim.__index = sim
|
sim.__index = sim
|
||||||
o.num_groupqueue[0] = 0
|
o.num_groupqueue[0] = 0
|
||||||
o.num_gatequeue[0] = 0
|
o.num_gatequeue[0] = 0
|
||||||
|
o.current_tick[0] = 0
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -256,6 +259,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.queuegate_c(sim, cgate)
|
function Simulation.queuegate_c(sim, cgate)
|
||||||
|
assert(sim.num_gatequeue[0] < queue_max-1)
|
||||||
sim.gatequeue[sim.num_gatequeue[0]] = cgate
|
sim.gatequeue[sim.num_gatequeue[0]] = cgate
|
||||||
sim.num_gatequeue[0] = sim.num_gatequeue[0] + 1
|
sim.num_gatequeue[0] = sim.num_gatequeue[0] + 1
|
||||||
cgate.in_queue[0] = 1
|
cgate.in_queue[0] = 1
|
||||||
@ -274,7 +278,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.queuegatelater(sim, gate, delay)
|
function Simulation.queuegatelater(sim, gate, delay)
|
||||||
local tick = sim.current_tick + delay
|
local tick = sim.current_tick[0] + delay
|
||||||
if sim.tickqueue[tick] == nil then
|
if sim.tickqueue[tick] == nil then
|
||||||
sim.tickqueue[tick] = {}
|
sim.tickqueue[tick] = {}
|
||||||
end
|
end
|
||||||
@ -294,6 +298,7 @@ end
|
|||||||
|
|
||||||
-- Logic Critical
|
-- Logic Critical
|
||||||
function Simulation.queuegroup_c(sim, cnet)
|
function Simulation.queuegroup_c(sim, cnet)
|
||||||
|
assert(sim.num_groupqueue[0] < queue_max-1)
|
||||||
sim.groupqueue[sim.num_groupqueue[0]] = cnet
|
sim.groupqueue[sim.num_groupqueue[0]] = cnet
|
||||||
sim.num_groupqueue[0] = sim.num_groupqueue[0] + 1
|
sim.num_groupqueue[0] = sim.num_groupqueue[0] + 1
|
||||||
cnet.in_queue[0] = 1
|
cnet.in_queue[0] = 1
|
||||||
@ -343,19 +348,19 @@ end
|
|||||||
function Simulation.ticklogic(sim)
|
function Simulation.ticklogic(sim)
|
||||||
for i = 0, sim.num_groupqueue[0]-1 do
|
for i = 0, sim.num_groupqueue[0]-1 do
|
||||||
local cnet = sim.groupqueue[i]
|
local cnet = sim.groupqueue[i]
|
||||||
Group.update_c(cnet, sim.current_tick)
|
Group.update_c(cnet, sim.current_tick[0])
|
||||||
cnet.in_queue[0] = 0
|
cnet.in_queue[0] = 0
|
||||||
sim.groupqueue[i] = nil
|
sim.groupqueue[i] = nil
|
||||||
end
|
end
|
||||||
sim.num_groupqueue[0] = 0
|
sim.num_groupqueue[0] = 0
|
||||||
|
|
||||||
if sim.tickqueue[sim.current_tick] ~= nil then
|
if sim.tickqueue[sim.current_tick[0]] ~= nil then
|
||||||
for i, gate in pairs(sim.tickqueue[sim.current_tick]) do
|
for i, gate in pairs(sim.tickqueue[sim.current_tick[0]]) do
|
||||||
if gate.in_queue[0]==0 then
|
if gate.in_queue[0]==0 then
|
||||||
Simulation.queuegate(sim, gate)
|
Simulation.queuegate(sim, gate)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sim.tickqueue[sim.current_tick] = nil
|
sim.tickqueue[sim.current_tick[0]] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 0, sim.num_gatequeue[0]-1 do
|
for i = 0, sim.num_gatequeue[0]-1 do
|
||||||
@ -367,7 +372,7 @@ function Simulation.ticklogic(sim)
|
|||||||
end
|
end
|
||||||
sim.num_gatequeue[0] = 0
|
sim.num_gatequeue[0] = 0
|
||||||
|
|
||||||
sim.current_tick = sim.current_tick + 1
|
sim.current_tick[0] = sim.current_tick[0] + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function Simulation.tickinit(sim)
|
function Simulation.tickinit(sim)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user