From c6f7008977819d78bf4ae9b69f351606fa963278 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Fri, 7 Oct 2022 22:57:50 +0100 Subject: [PATCH] [Sim][#50] Fix symbolising the instrution latch. --- tests/z80sim/z80sim.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/z80sim/z80sim.py b/tests/z80sim/z80sim.py index 42901e7..5a72d79 100755 --- a/tests/z80sim/z80sim.py +++ b/tests/z80sim/z80sim.py @@ -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 @@ -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) @@ -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): @@ -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')