From 0c24e2e2f78aef0353a417b6e829d45902b84461 Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Fri, 8 Mar 2024 17:24:51 -0400 Subject: [PATCH] Fix how the --stop option of rzxplay.py handles empty frames --- skoolkit/rzxplay.py | 4 ++-- tests/test_rzxplay.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/skoolkit/rzxplay.py b/skoolkit/rzxplay.py index f7844e38..59846c6d 100644 --- a/skoolkit/rzxplay.py +++ b/skoolkit/rzxplay.py @@ -337,7 +337,7 @@ def process_block(block, options, context): prev_scr = [None] * 6912 show_progress = not options.quiet fps = options.fps - stop = options.stop + stop = options.stop or total_frames exec_map = context.exec_map tracefile = context.tracefile if tracefile: @@ -394,7 +394,7 @@ def process_block(block, options, context): if show_progress: p = (context.frame_count / total_frames) * 100 write(f'[{p:5.1f}%]\x08\x08\x08\x08\x08\x08\x08\x08') - if context.frame_count == stop: + if context.frame_count >= stop: context.stop = True break diff --git a/tests/test_rzxplay.py b/tests/test_rzxplay.py index bc35f623..2d65e756 100644 --- a/tests/test_rzxplay.py +++ b/tests/test_rzxplay.py @@ -1215,6 +1215,26 @@ def test_option_stop(self): """ self._test_rzx(rzx, exp_output, '--stop 2 --quiet --no-screen', exp_trace) + def test_option_stop_with_empty_frame(self): + ram = [0] * 0xC000 + pc = 0xE000 + code = ( + 0xAF, # XOR A + 0xA8, # XOR B + 0xA9, # XOR C + ) + ram[pc - 0x4000:pc - 0x4000 + len(code)] = code + registers = {'PC': pc} + z80data = self.write_z80_file(None, ram, registers=registers, ret_data=True) + rzx = RZX() + frames = [(1, 0, []), (0, 0, []), (2, 0, [])] + rzx.add_snapshot(z80data, 'z80', frames) + exp_output = '' + exp_trace = """ + F:0 C:00001 I:00000 $E000 XOR A + """ + self._test_rzx(rzx, exp_output, '--stop 1 --quiet --no-screen', exp_trace) + def test_option_V(self): for option in ('-V', '--version'): output, error = self.run_rzxplay(option, catch_exit=0)