add net and wire struct; move net update into its file
This commit is contained in:
parent
8561940777
commit
d151ab688c
@ -2,12 +2,6 @@
|
||||
local ffi = FFI or require("ffi")
|
||||
Simulation = Simulation or {}
|
||||
|
||||
ffi.cdef([[
|
||||
struct Net {
|
||||
|
||||
};
|
||||
]])
|
||||
|
||||
function Simulation.compile(sim)
|
||||
-- assemble a list of all nets
|
||||
local all_nets = {}
|
||||
|
@ -1,6 +1,19 @@
|
||||
|
||||
Group = {}
|
||||
|
||||
FFI.cdef[[
|
||||
struct Port;
|
||||
struct Net {
|
||||
bool state;
|
||||
bool fxstate;
|
||||
int updatetick;
|
||||
int internal_ref;
|
||||
int state_num;
|
||||
int num_in_ports_update;
|
||||
struct Port* in_ports_update[1];
|
||||
};
|
||||
]]
|
||||
|
||||
function Group.new(self, sim)
|
||||
local o = {
|
||||
state = false,
|
||||
@ -9,6 +22,8 @@ function Group.new(self, sim)
|
||||
wires = {},
|
||||
out_ports = {},
|
||||
in_ports = {},
|
||||
|
||||
state_num = 0,
|
||||
|
||||
nwires = 0,
|
||||
nout_ports = 0,
|
||||
@ -154,3 +169,15 @@ end
|
||||
function Group.getsim(group)
|
||||
return group.sim
|
||||
end
|
||||
|
||||
function Group.update(group)
|
||||
local newstate = false
|
||||
for j, port in pairs(group.out_ports) do
|
||||
newstate = newstate or Port.getstate(port)
|
||||
if newstate then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Group.setstate(group, newstate)
|
||||
end
|
||||
|
@ -17,6 +17,7 @@ Port = {}
|
||||
|
||||
FFI.cdef[[
|
||||
struct Gate;
|
||||
struct Net;
|
||||
struct Port {
|
||||
bool state;
|
||||
char type;
|
||||
|
@ -266,15 +266,7 @@ end
|
||||
|
||||
function Simulation.tick(self)
|
||||
for k, group in pairs(self.groupqueue) do
|
||||
local newstate = false
|
||||
for j, port in pairs(group.out_ports) do
|
||||
newstate = newstate or Port.getstate(port)
|
||||
if newstate then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Group.setstate(group, newstate)
|
||||
Group.update(group)
|
||||
end
|
||||
self.groupqueue = {}
|
||||
|
||||
|
@ -1,6 +1,15 @@
|
||||
|
||||
Wire = {}
|
||||
|
||||
FFI.cdef[[
|
||||
struct Wire {
|
||||
int objref;
|
||||
int layer;
|
||||
struct Net* group;
|
||||
int bounds[6];
|
||||
};
|
||||
]]
|
||||
|
||||
function Wire.new(self, objref, layer, bounds, sim)
|
||||
local o = {
|
||||
objref = objref,
|
||||
|
Loading…
x
Reference in New Issue
Block a user