From a3479d4dde77326209dc181a25c3e9d1cad63ed7 Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Fri, 17 May 2024 17:24:43 -0300 Subject: [PATCH] Fix how the --reg option of trace.py handles 0x-prefixed hex values --- skoolkit/trace.py | 4 ++-- sphinx/source/changelog.rst | 2 ++ tests/test_trace.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/skoolkit/trace.py b/skoolkit/trace.py index 9655386f..0d9c52f7 100644 --- a/skoolkit/trace.py +++ b/skoolkit/trace.py @@ -174,10 +174,10 @@ def run(snafile, options, config): simulator_cls = CSimulator or Simulator registers = {} for spec in options.reg: - reg, sep, val = spec.upper().partition('=') + reg, sep, val = spec.partition('=') if sep: try: - registers[reg] = get_int_param(val, True) + registers[reg.upper()] = get_int_param(val, True) except ValueError: raise SkoolKitError("Cannot parse register value: {}".format(spec)) fast = options.verbose == 0 and options.max_operations == 0 and options.max_tstates == 0 diff --git a/sphinx/source/changelog.rst b/sphinx/source/changelog.rst index 243d2b12..a805bc5a 100644 --- a/sphinx/source/changelog.rst +++ b/sphinx/source/changelog.rst @@ -3,6 +3,8 @@ Changelog 9.3b1 ----- +* Fixed the bug that prevents the ``--reg`` option of :ref:`trace.py` from + accepting hexadecimal values prefixed by '0x' 9.2 (2024-05-11) ---------------- diff --git a/tests/test_trace.py b/tests/test_trace.py index 5ed04ee2..bfcc6119 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -1568,6 +1568,37 @@ def test_option_reg_with_snapshot(self): """ self.assertEqual(dedent(exp_output).strip(), output.rstrip()) + def test_option_reg_with_hex_and_binary_values(self): + data = [0x03] # INC BC + binfile = self.write_bin_file(data, suffix='.bin') + start, stop = 32768, 32769 + registers = { + 'A': '0x50', + 'F': '%01000001', + 'BC': '$123f', + 'DE': '0x2345', + 'HL': '$3456', + 'IX': '0x456a', + 'IY': '$5678', + 'I': '0x67', + 'R': '$89', + '^A': '0x98', + '^F': '%10101010', + '^BC': '$8765', + '^DE': '0x7654', + '^HL': '$6543', + 'SP': '0x5432' + } + reg_options = ' '.join(f'--reg {r}={v}' for r, v in registers.items()) + output, error = self.run_trace(f'-n -o {start} -S {stop} -vv {reg_options} {binfile}') + self.assertEqual(error, '') + exp_output = """ + $8000 INC BC A=50 F=01000001 BC=1240 DE=2345 HL=3456 IX=456A IY=5678 + A'=98 F'=10101010 BC'=8765 DE'=7654 HL'=6543 SP=5432 IR=678A + Stopped at $8001 + """ + self.assertEqual(dedent(exp_output).strip(), output.rstrip()) + def test_option_reg_help(self): output, error = self.run_trace('--reg help') self.assertTrue(output.startswith('Usage: --reg name=value\n'))