Skip to content

Commit

Permalink
Fix how the --reg option of trace.py handles 0x-prefixed hex values
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed May 17, 2024
1 parent 5f46816 commit a3479d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions skoolkit/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----------------
Expand Down
31 changes: 31 additions & 0 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit a3479d4

Please sign in to comment.