mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-02 03:29:26 +00:00
Allow disassembly listings to wrap around memory
This commit is contained in:
parent
f25dfe3d04
commit
81906116f3
@ -1,5 +1,8 @@
|
|||||||
0.15-dev (Next Release)
|
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)
|
0.14 (2012-11-30)
|
||||||
|
|
||||||
- Assembling now detects syntax errors, overflows, and bad labels
|
- Assembling now detects syntax errors, overflows, and bad labels
|
||||||
|
@ -355,19 +355,38 @@ class Monitor(cmd.Cmd):
|
|||||||
self.stdout.write("\r$%s ?Syntax\n" % addr)
|
self.stdout.write("\r$%s ?Syntax\n" % addr)
|
||||||
|
|
||||||
def do_disassemble(self, args):
|
def do_disassemble(self, args):
|
||||||
split = shlex.split(args)
|
splitted = shlex.split(args)
|
||||||
if len(split) != 1:
|
if len(splitted) != 1:
|
||||||
return self.help_disassemble()
|
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:
|
if start == end:
|
||||||
end += 1
|
end += 1
|
||||||
|
if end > max_address:
|
||||||
|
end = 0
|
||||||
|
|
||||||
address = start
|
cur_address = start
|
||||||
while address < end:
|
needs_wrap = start > end
|
||||||
bytes, disasm = self._disassembler.instruction_at(address)
|
|
||||||
self._output(self._format_disassembly(address, bytes, disasm))
|
while needs_wrap or cur_address < end:
|
||||||
address += bytes
|
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):
|
def _format_disassembly(self, address, length, disasm):
|
||||||
cur_address = address
|
cur_address = address
|
||||||
|
@ -301,7 +301,7 @@ class MonitorTests(unittest.TestCase):
|
|||||||
disasm = "$c000 ea NOP\n$c001 ea NOP\n"
|
disasm = "$c000 ea NOP\n$c001 ea NOP\n"
|
||||||
self.assertEqual(out, disasm)
|
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()
|
stdout = StringIO()
|
||||||
mon = Monitor(stdout=stdout)
|
mon = Monitor(stdout=stdout)
|
||||||
mon._mpu.memory[0xffff] = 0x20 # => JSR
|
mon._mpu.memory[0xffff] = 0x20 # => JSR
|
||||||
@ -313,6 +313,23 @@ class MonitorTests(unittest.TestCase):
|
|||||||
disasm = "$ffff 20 d2 ff JSR $ffd2\n"
|
disasm = "$ffff 20 d2 ff JSR $ffd2\n"
|
||||||
self.assertEqual(out, disasm)
|
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
|
# fill
|
||||||
|
|
||||||
def test_shortcut_f_for_fill(self):
|
def test_shortcut_f_for_fill(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user