From 11bcda8a4450a24d5b3a1fe3cfcfd4a0368de7e1 Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Wed, 8 Nov 2023 17:11:25 -0400 Subject: [PATCH] Make 'trace.py --audio' format delays more conveniently More conveniently for inclusion in a ref file section, that is. --- skoolkit/trace.py | 4 +++- tests/test_trace.py | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/skoolkit/trace.py b/skoolkit/trace.py index ccd7e7a9..5b3ea676 100644 --- a/skoolkit/trace.py +++ b/skoolkit/trace.py @@ -15,6 +15,7 @@ # SkoolKit. If not, see . import argparse +import textwrap import time from skoolkit import ROM48, VERSION, SkoolKitError, get_int_param, integer, read_bin_file @@ -232,7 +233,8 @@ def run(snafile, options, config): delays.append(t - tracer.out_times[i]) duration = sum(delays) print('Sound duration: {} T-states ({:.03f}s)'.format(duration, duration / 3500000)) - print('Delays: {}'.format(simplify(delays, options.depth))) + lines = textwrap.wrap(simplify(delays, options.depth), 78) + print('Delays:\n {}'.format('\n '.join(lines))) if options.dump: state = [] if isinstance(memory, Memory): diff --git a/tests/test_trace.py b/tests/test_trace.py index 71f834e5..47f0a4a4 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -709,7 +709,32 @@ def test_option_audio(self): exp_output = """ Stopped at $8008 Sound duration: 62 T-states (0.000s) - Delays: [31]*2 + Delays: + [31]*2 + """ + self.assertEqual(dedent(exp_output).strip(), output.rstrip()) + + def test_option_audio_with_delays_over_multiple_lines(self): + data = ( + 22, 16, # 32768 LD D,16 + 66, # 32770 LD B,D + 211, 254, # 32771 OUT (254),A + 238, 16, # 32773 XOR 16 + 16, 250, # 32775 DJNZ 32771 + 21, # 32777 DEC D + 32, 246, # 32778 JR NZ,32770 + ) + binfile = self.write_bin_file(data, suffix='.bin') + start, stop = 32768, 32780 + output, error = self.run_trace(f'-o {start} -S {stop} --audio {binfile}') + self.assertEqual(error, '') + exp_output = """ + Stopped at $800C + Sound duration: 4410 T-states (0.001s) + Delays: + [31]*15, 46, [31]*14, 46, [31]*13, 46, [31]*12, 46, [31]*11, 46, [31]*10, 46, + [31]*9, 46, [31]*8, 46, [31]*7, 46, [31]*6, 46, [31]*5, 46, [31]*4, 46, + [31]*3, 46, [31]*2, 46, 31, 46 """ self.assertEqual(dedent(exp_output).strip(), output.rstrip()) @@ -810,7 +835,8 @@ def test_option_depth_0(self): exp_output = """ Stopped at $8008 Sound duration: 93 T-states (0.000s) - Delays: 31, 31, 31 + Delays: + 31, 31, 31 """ self.assertEqual(dedent(exp_output).strip(), output.rstrip()) @@ -828,7 +854,8 @@ def test_option_depth_1(self): exp_output = """ Stopped at $8008 Sound duration: 93 T-states (0.000s) - Delays: [31]*3 + Delays: + [31]*3 """ self.assertEqual(dedent(exp_output).strip(), output.rstrip()) @@ -848,7 +875,8 @@ def test_option_depth_2(self): exp_output = """ Stopped at $800C Sound duration: 156 T-states (0.000s) - Delays: [18, 28]*3, 18 + Delays: + [18, 28]*3, 18 """ self.assertEqual(dedent(exp_output).strip(), output.rstrip()) @@ -870,7 +898,8 @@ def test_option_depth_3(self): exp_output = """ Stopped at $8010 Sound duration: 225 T-states (0.000s) - Delays: [18, 15, 31]*3, 18, 15 + Delays: + [18, 15, 31]*3, 18, 15 """ self.assertEqual(dedent(exp_output).strip(), output.rstrip())