From 81906116f3108e0c424447e9ba89b43364dd0111 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Fri, 30 Nov 2012 13:24:42 -0800 Subject: [PATCH] Allow disassembly listings to wrap around memory --- CHANGES.txt | 3 +++ py65/monitor.py | 35 +++++++++++++++++++++++++++-------- py65/tests/test_monitor.py | 19 ++++++++++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index dd8de95..d3d8677 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,8 @@ 0.15-dev (Next Release) + - Disassembling can now wrap around memory if the start address + given is greater than the end address. + 0.14 (2012-11-30) - Assembling now detects syntax errors, overflows, and bad labels diff --git a/py65/monitor.py b/py65/monitor.py index 830b015..6e11e05 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -355,19 +355,38 @@ class Monitor(cmd.Cmd): self.stdout.write("\r$%s ?Syntax\n" % addr) def do_disassemble(self, args): - split = shlex.split(args) - if len(split) != 1: + splitted = shlex.split(args) + if len(splitted) != 1: return self.help_disassemble() - start, end = self._address_parser.range(split[0]) + address_parts = splitted[0].split(":") + start = self._address_parser.number(address_parts[0]) + if len(address_parts) > 1: + end = self._address_parser.number(address_parts[1]) + else: + end = start + + max_address = (2 ** self._mpu.ADDR_WIDTH) - 1 + if start == end: end += 1 + if end > max_address: + end = 0 - address = start - while address < end: - bytes, disasm = self._disassembler.instruction_at(address) - self._output(self._format_disassembly(address, bytes, disasm)) - address += bytes + cur_address = start + needs_wrap = start > end + + while needs_wrap or cur_address < end: + length, disasm = self._disassembler.instruction_at(cur_address) + self._output(self._format_disassembly(cur_address, length, disasm)) + + remaining = length + while remaining: + remaining -= 1 + cur_address += 1 + if cur_address > max_address: + needs_wrap = False + cur_address = 0 def _format_disassembly(self, address, length, disasm): cur_address = address diff --git a/py65/tests/test_monitor.py b/py65/tests/test_monitor.py index 6115462..5147722 100644 --- a/py65/tests/test_monitor.py +++ b/py65/tests/test_monitor.py @@ -301,7 +301,7 @@ class MonitorTests(unittest.TestCase): disasm = "$c000 ea NOP\n$c001 ea NOP\n" self.assertEqual(out, disasm) - def test_disassemble_wraps_to_0_after_top_of_memory(self): + def test_disassemble_wraps_an_instruction_around_memory(self): stdout = StringIO() mon = Monitor(stdout=stdout) mon._mpu.memory[0xffff] = 0x20 # => JSR @@ -313,6 +313,23 @@ class MonitorTests(unittest.TestCase): disasm = "$ffff 20 d2 ff JSR $ffd2\n" self.assertEqual(out, disasm) + def test_disassemble_wraps_disassembly_list_around_memory(self): + stdout = StringIO() + mon = Monitor(stdout=stdout) + mon._mpu.memory[0xffff] = 0x20 # => JSR + mon._mpu.memory[0x0000] = 0xD2 + mon._mpu.memory[0x0001] = 0xFF # => $FFD2 + mon._mpu.memory[0x0002] = 0x20 # => JSR + mon._mpu.memory[0x0003] = 0xE4 + mon._mpu.memory[0x0004] = 0xFF # => $FFE4 + mon._mpu.memory[0x0005] = 0xEA # => NOP + mon.do_disassemble("ffff:6") + out = stdout.getvalue() + disasm = ("$ffff 20 d2 ff JSR $ffd2\n" + "$0002 20 e4 ff JSR $ffe4\n" + "$0005 ea NOP\n") + self.assertEqual(out, disasm) + # fill def test_shortcut_f_for_fill(self):