From d1b104bd6ebfaef6aa20786cc218e0f0e2e64fa1 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Fri, 1 Oct 2021 12:58:13 +0100 Subject: [PATCH] [#37] Refine __recalc_node_list(). --- tests/z80sim/z80sim.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/z80sim/z80sim.py b/tests/z80sim/z80sim.py index e255e9b..b52b1c0 100755 --- a/tests/z80sim/z80sim.py +++ b/tests/z80sim/z80sim.py @@ -240,17 +240,18 @@ def __recalc_node(self, n, recalc_nodes): for t in n.gates: self.__set_transistor(t, n.state, recalc_nodes) - def __recalc_node_list(self, nodes): - recalc_nodes = [] - for j in range(100): # Loop limiter. - if len(nodes) == 0: - return - - for n in nodes: - self.__recalc_node(n, recalc_nodes) + def __recalc_node_list(self, recalc_nodes): + attempt = 0 + while recalc_nodes: + # Loop limiter. + attempt += 1 + if attempt > 100: + break nodes = recalc_nodes recalc_nodes = [] + for n in nodes: + self.__recalc_node(n, recalc_nodes) def __set_node(self, n, pull): n.pull = pull