Skip to content

Commit

Permalink
[#37] Represent ground and power lines directly as nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Sep 29, 2021
1 parent 451e371 commit cbe4587
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __load_transistors(self):
continue

# TODO: Why the original source does this?
if c1 in (self.__ngnd, self.__npwr):
if self.__nodes[c1] in (self.__gnd, self.__pwr):
c1, c2 = c2, c1

t = Transistor(id, gate, c1, c2)
Expand All @@ -123,8 +123,8 @@ def __load_defs(self):
self.__load_node_names()
self.__load_nodes()

self.__ngnd = self.__node_ids['vss']
self.__npwr = self.__node_ids['vcc']
self.__gnd = self.__nodes[self.__node_ids['vss']]
self.__pwr = self.__nodes[self.__node_ids['vcc']]

self.__nclk = self.__node_ids['~clk']

Expand All @@ -144,7 +144,7 @@ def __load_defs(self):
def __all_nodes(self):
res = []
for i in self.__nodes:
if i != self.__npwr and i != self.__ngnd:
if i != self.__pwr.id and i != self.__gnd.id:
res.append(i)
return res

Expand All @@ -153,9 +153,7 @@ def __add_node_to_group(self, i):
return

self.__group.append(i)
if i == self.__ngnd:
return
if i == self.__npwr:
if self.__nodes[i] in (self.__gnd, self.__pwr):
return
for t in self.__nodes[i].c1c2s:
if not t.on:
Expand All @@ -173,9 +171,9 @@ def __get_node_group(self, i):

def __get_node_value(self):
# 1. deal with power connections first
if self.__ngnd in self.__group:
if self.__gnd.id in self.__group:
return False
if self.__npwr in self.__group:
if self.__pwr.id in self.__group:
return True

# 2. deal with pullup/pulldowns next
Expand Down Expand Up @@ -206,9 +204,7 @@ def __get_node_value(self):
return max_state

def __add_recalc_node(self, nn):
if nn == self.__ngnd:
return
if nn == self.__npwr:
if self.__nodes[nn] in (self.__gnd, self.__pwr):
return
if nn in self.__recalc_hash:
return
Expand All @@ -230,9 +226,7 @@ def __turn_transistor_off(self, t):
self.__add_recalc_node(t.c2)

def __recalc_node(self, node):
if node == self.__ngnd:
return
if node == self.__npwr:
if self.__nodes[node] in (self.__gnd, self.__pwr):
return

self.__get_node_group(node)
Expand Down Expand Up @@ -300,8 +294,8 @@ def __init_chip(self):
for n in self.__nodes.values():
n.state = False

self.__nodes[self.__ngnd].state = False
self.__nodes[self.__npwr].state = True
self.__gnd.state = False
self.__pwr.state = True

for t in self.__trans.values():
t.on = False
Expand Down

0 comments on commit cbe4587

Please sign in to comment.