1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-12-28 15:29:40 +00:00

Allow disassembly listings to wrap around memory

This commit is contained in:
Mike Naberezny 2012-11-30 13:24:42 -08:00
parent f25dfe3d04
commit 81906116f3
3 changed files with 48 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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):