Skip to content

Commit 27c4eb1

Browse files
committed
Fix how tap2sna.py handles 0-length pulses in 0/1 bit encodings
In a PZX DATA block, that is.
1 parent 51a13c0 commit 27c4eb1

3 files changed

Lines changed: 16 additions & 21 deletions

File tree

skoolkit/loadtracer.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022-2025 Richard Dymond (rjdymond@gmail.com)
1+
# © 2022-2026 Richard Dymond (rjdymond@gmail.com)
22
#
33
# This file is part of SkoolKit.
44
#
@@ -118,26 +118,19 @@ def get_edges(blocks, first_edge, polarity, analyse=False):
118118
one = ','.join(str(d) for d in timings.one)
119119
analysis.append(f'{tstates:>10} {ear:>3} Data ({data_len} bytes{bits}; {zero}/{one} T-states)')
120120
start = len(edges) - 1
121-
if 0 in timings.zero and 0 in timings.one and sum(timings.zero) == sum(timings.one):
122-
# This is sample data as opposed to byte values, so an edge
123-
# is the transition between a 0-bit and a 1-bit (or vice versa)
124-
sample_t = sum(timings.zero)
125-
prev_bit = data[0] & 0x80
126-
for k, b in enumerate(data, 1):
127-
for j in range(8 if k < len(data) else timings.used_bits):
128-
if b & 0x80 != prev_bit:
129-
edges.append(tstates)
130-
prev_bit ^= 0x80
131-
tstates += sample_t
132-
b *= 2
133-
edges.append(tstates)
134-
else:
135-
for k, b in enumerate(data, 1):
136-
for j in range(8 if k < len(data) else timings.used_bits):
137-
for d in timings.one if b & 0x80 else timings.zero:
121+
p = q = 0
122+
for k, b in enumerate(data, 1):
123+
for j in range(8 if k < len(data) else timings.used_bits):
124+
for d in timings.one if b & 0x80 else timings.zero:
125+
if d:
138126
tstates += d
139-
edges.append(tstates)
140-
b *= 2
127+
if p == q:
128+
edges.append(tstates)
129+
q = 1 - q
130+
else:
131+
edges[-1] += d
132+
p = 1 - p
133+
b *= 2
141134

142135
# Tail pulse
143136
if timings.tail:

sphinx/source/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Changelog
3434
:ref:`ref-AudioWriter` section
3535
* Fixed the bug in CSimulator that restricts the ``timeout`` simulated load
3636
configuration parameter to a maximum value of 1227 seconds
37+
* Fixed how :ref:`tap2sna.py` handles zero-length pulses in the encodings of 0s
38+
and 1s in a PZX DATA block
3739

3840
9.6 (2025-05-12)
3941
----------------

tests/test_tap2sna.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def test_option_tape_analysis_pzx_file(self):
748748
pzx.add_puls(pulse_counts=((5000, 2168), (1, 430), (1, 870)))
749749
pzx.add_data((11, 12, 13, 14, 15), (570, 570), (1050, 1050), tail=0, used_bits=5, polarity=0)
750750
pzx.add_puls(pulse_counts=((2000, 1234), (2, 500), (1, 1000)))
751-
pzx.add_data((255, 0, 255, 0, 254), (80, 0), (0, 80), tail=0)
751+
pzx.add_data((255, 0, 255, 0, 255), (80, 0), (0, 80), tail=0)
752752
pzx.add_puls(pulses=(0, 1000, 1000, 1000))
753753
pzxfile = self.write_bin_file(pzx.data, suffix='.pzx')
754754
output, error = self.run_tap2sna(f'--tape-analysis {pzxfile}', catch_exit=0)

0 commit comments

Comments
 (0)