Skip to content

Commit

Permalink
[Sim][#50] Fix symbolising the instrution latch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Oct 8, 2022
1 parent 24bb4dd commit c6f7008
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,8 +1687,14 @@ def pc(self):
hi = self.read_nodes('reg_pch')
return (hi << 8) | lo

def set_node_state(self, pin, state):
self.__nodes_by_name[pin].state = Bool.cast(state)
def set_node_state(self, n, state):
self.__nodes_by_name[n].state = Bool.cast(state)

def set_latch_state(self, a, b, state):
self.set_node_state(a, state)
self.set_node_state(b, ~state)
self.__update_nodes([self.__nodes_by_name[a],
self.__nodes_by_name[b]])

def set_pin_pull(self, pin, pull):
assert pin in _PINS
Expand Down Expand Up @@ -1876,8 +1882,11 @@ def __apply_step(self, sim, step):
_, _, = step
sim.clear_state()
elif kind == 'set_node_state':
_, _, pin, state = step
sim.set_node_state(pin, state)
_, _, n, state = step
sim.set_node_state(n, state)
elif kind == 'set_latch_state':
_, _, a, b, state = step
sim.set_latch_state(a, b, state)
elif kind == 'set_pin_pull':
_, _, pin, pull = step
sim.set_pin_pull(pin, pull)
Expand Down Expand Up @@ -1908,8 +1917,12 @@ def __add_step(self, step):
def clear_state(self):
self.__add_step(('clear_state',))

def set_node_state(self, pin, state):
step = 'set_node_state', pin, Bool.cast(state)
def set_node_state(self, n, state):
step = 'set_node_state', n, Bool.cast(state)
self.__add_step(step)

def set_latch_state(self, a, b, state):
step = 'set_latch_state', a, b, Bool.cast(state)
self.__add_step(step)

def set_pin_pull(self, pin, pull):
Expand Down Expand Up @@ -2882,14 +2895,14 @@ def rev(bits):
s.set_db_and_wait(d, ticks)
s.cache(intermediate=True)

# Symbolise the instruction latch.
instr = Bits('instr', width=8)
is_prefix = ((instr == 0xcb) | (instr == 0xed) |
(instr == 0xdd) | (instr == 0xfd))
instr = Bits(b & ~is_prefix for b in instr)
with s.status('symbolise instruction latch'):
instr = Bits('instr', width=8)
is_prefix = ((instr == 0xcb) | (instr == 0xed) |
(instr == 0xdd) | (instr == 0xfd))
instr = Bits(b & ~is_prefix for b in instr)

for i in range(8):
s.set_node_state(f'instr{i}', instr[i])
for i in range(8):
s.set_latch_state(f'instr{i}', f'~instr{i}', instr[i])

s.cache()
s.report('after-symbolising')
Expand Down

0 comments on commit c6f7008

Please sign in to comment.