Skip to content

Commit

Permalink
Make 'trace.py --audio' format delays more conveniently
Browse files Browse the repository at this point in the history
More conveniently for inclusion in a ref file section, that is.
  • Loading branch information
skoolkid committed Nov 8, 2023
1 parent ce99ba7 commit 11bcda8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
4 changes: 3 additions & 1 deletion skoolkit/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# SkoolKit. If not, see <http://www.gnu.org/licenses/>.

import argparse
import textwrap
import time

from skoolkit import ROM48, VERSION, SkoolKitError, get_int_param, integer, read_bin_file
Expand Down Expand Up @@ -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):
Expand Down
39 changes: 34 additions & 5 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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())

Expand All @@ -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())

Expand All @@ -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())

Expand All @@ -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())

Expand Down

0 comments on commit 11bcda8

Please sign in to comment.