make gates use net state pointers

This commit is contained in:
Redo 2022-11-04 15:50:45 -06:00
parent caa9ed5de3
commit 5aa11f9e43
3 changed files with 20 additions and 4 deletions

View File

@ -11,6 +11,9 @@ function Gate.new(objref, definition)
logic = definition.logic,
ports = {},
port_nets = {},
port_net_state = ffi.new("int*["..(#definition.ports+1).."]"),
port_net_state_num = ffi.new("int*["..(#definition.ports+1).."]"),
port_net_in_queue = ffi.new("int*["..(#definition.ports+1).."]"),
objref = objref,
definition = definition,
@ -20,17 +23,17 @@ end
-- Logic Critical
function Gate.getportstate(gate, index)
return gate.port_nets[index].state[0]
return gate.port_net_state[index][0]
end
-- Logic Critical
function Gate.setportstate(gate, index, state)
if state ~= gate.port_states[index] then
local group = gate.port_nets[index]
group.state_num[0] = group.state_num[0] - gate.port_states[index] + state
gate.port_net_state_num[index][0] = gate.port_net_state_num[index][0] - gate.port_states[index] + state
gate.port_states[index] = state
if ((group.state_num[0]>0) ~= (group.state[0]==1)) and (group.in_queue[0]==0) then
if ((gate.port_net_state_num[index][0]>0) ~= (gate.port_net_state[index][0]==1)) and (gate.port_net_in_queue[index][0]==0) then
local group = gate.port_nets[index]
Simulation.queuegroup(GSim, group)
end
end

View File

@ -104,6 +104,10 @@ function GateDefinition.constructgate(def, objref, position, rotation)
gate.ports[port.idx] = port
gate.port_nets[port.idx] = nil
gate.port_states[port.idx] = 0
gate.port_net_state [port.idx] = ffi.cast("int*", 0)
gate.port_net_state_num[port.idx] = ffi.cast("int*", 0)
gate.port_net_in_queue [port.idx] = ffi.cast("int*", 0)
end
return gate

View File

@ -50,6 +50,15 @@ end
function Port.setgroup(port, group)
port.group = group
Port.getgate(port).port_nets[port.idx] = group
if group then
Port.getgate(port).port_net_state [port.idx] = group.state
Port.getgate(port).port_net_state_num[port.idx] = group.state_num
Port.getgate(port).port_net_in_queue [port.idx] = group.in_queue
else
Port.getgate(port).port_net_state [port.idx] = ffi.cast("int*", 0)
Port.getgate(port).port_net_state_num[port.idx] = ffi.cast("int*", 0)
Port.getgate(port).port_net_in_queue [port.idx] = ffi.cast("int*", 0)
end
end
function Port.getgroup(port)