Skip to content

Commit

Permalink
Make tapinfo.py show the LINE number for 'Program:' header blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Jul 22, 2023
1 parent ffc872d commit d5f47e3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions skoolkit/tapinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,13 @@ def _print_block(index, data, show_data, info=(), block_id=None, header=None):
if data and block_id in (None, 16):
data_type = "Unknown"
name_str = None
line = 0xC000
start = None
if len(data) == 19 and data[0] == 0:
block_type = data[1]
if block_type == 0:
name_str = 'Program'
line = get_word(data, 14)
elif block_type == 1:
name_str = 'Number array'
elif block_type == 2:
Expand All @@ -440,6 +442,8 @@ def _print_block(index, data, show_data, info=(), block_id=None, header=None):
_print_info("Type: {}".format(data_type))
if name_str:
_print_info("{}: {}".format(name_str, name))
if line < 0xC000:
_print_info(f'LINE: {line}')
if start is not None:
_print_info("CODE: {},{}".format(start, size))
if data:
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Changelog
* Added support to :ref:`trace.py` for executing machine code in 128K snapshots
* Added support to :ref:`control directive loops <ctlLoops>` for avoiding
repetition of an ``N`` directive at the start of a loop
* :ref:`tapinfo.py` now shows the LINE number (if present) for 'Program:'
header blocks

8.10 (2023-06-17)
-----------------
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,8 @@ To list the options supported by `tapinfo.py`, run it with no arguments::
+---------+-------------------------------------------------------------------+
| Version | Changes |
+=========+===================================================================+
| 9.0 | Shows the LINE number (if present) for 'Program:' header blocks |
+---------+-------------------------------------------------------------------+
| 8.9 | Shows full info for TZX block types 0x10 and 0x11 |
+---------+-------------------------------------------------------------------+
| 8.3 | Added the ``--data`` option |
Expand Down
28 changes: 16 additions & 12 deletions tests/test_tapinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,36 @@ def test_unrecognised_tape_type(self):
self.assertEqual(cm.exception.args[0], 'Unrecognised tape type')

def test_tap_file(self):
tap_data = create_tap_header_block('program_01', 100, 200, 0)
data = [1, 2, 4]
tap_data = create_tap_header_block('test_tap01', 32768, len(data))
tap_data.extend(create_tap_header_block('test_tap01', 32768, len(data)))
tap_data.extend(create_tap_data_block(data))
tap_data.extend(create_tap_header_block('numbers_01', data_type=1))
tap_data.extend(create_tap_data_block([8, 16, 32]))
tap_data.extend(create_tap_header_block('numbers_01', length=5, data_type=1))
tapfile = self.write_bin_file(tap_data, suffix='.tap')
output, error = self.run_tapinfo(tapfile)
self.assertEqual(error, '')
exp_output = """
1:
Type: Header block
Program: program_01
LINE: 100
Length: 19
Data: 0, 0, 112, 114, 111, 103, 114 ... 200, 0, 100, 0, 200, 0, 78
2:
Type: Header block
Bytes: test_tap01
CODE: 32768,3
Length: 19
Data: 0, 3, 116, 101, 115, 116, 95 ... 3, 0, 0, 128, 0, 0, 173
2:
3:
Type: Data block
Length: 5
Data: 255, 1, 2, 4, 248
3:
4:
Type: Header block
Number array: numbers_01
Length: 19
Data: 0, 1, 110, 117, 109, 98, 101 ... 0, 0, 0, 0, 0, 0, 47
4:
Type: Data block
Length: 5
Data: 255, 8, 16, 32, 199
Data: 0, 1, 110, 117, 109, 98, 101 ... 5, 0, 0, 0, 0, 0, 42
"""
self.assertEqual(dedent(exp_output).lstrip(), output)

Expand Down Expand Up @@ -124,7 +126,7 @@ def test_tap_file_with_missing_bytes(self):

def test_tzx_file(self):
blocks = []
blocks.append(create_tzx_header_block('<TEST_tzx>', data_type=0, pause=1000))
blocks.append(create_tzx_header_block('<TEST_tzx>', start=10, data_type=0, pause=1000))
blocks.append(create_tzx_data_block([1, 4, 16], pause=500))
blocks.append(create_tzx_header_block('characters', data_type=2))
blocks.append(create_tzx_data_block([64, 0]))
Expand All @@ -138,8 +140,9 @@ def test_tzx_file(self):
Pause: 1000ms
Type: Header block
Program: <TEST_tzx>
LINE: 10
Length: 19
Data: 0, 0, 60, 84, 69, 83, 84 ... 0, 0, 0, 0, 0, 0, 61
Data: 0, 0, 60, 84, 69, 83, 84 ... 0, 0, 10, 0, 0, 0, 55
2: Standard speed data (0x10)
Pause: 500ms
Type: Data block
Expand Down Expand Up @@ -724,6 +727,7 @@ def test_option_data_with_tzx_file(self):
Pause: 0ms
Type: Header block
Program: test_tzx02
LINE: 0
Length: 19
0000 00 00 74 65 73 74 5F 74 7A 78 30 32 00 00 00 00 ..test_tzx02....
0010 00 00 3D ..=
Expand Down

0 comments on commit d5f47e3

Please sign in to comment.