mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-19 23:31:03 +00:00
Fix disassembly output when instruction wraps past the top of memory
This commit is contained in:
parent
b2148d72c6
commit
fdf4145b55
@ -18,6 +18,9 @@
|
||||
- Assembling now shows an Overflow Error if the statement won't
|
||||
fit at the top of memory.
|
||||
|
||||
- Fixed a bug in the disassembler where instructions that wrap past
|
||||
the top of memory would not be displayed properly.
|
||||
|
||||
0.13 (2012-11-15)
|
||||
|
||||
- Fixed a bug where negative numbers could be entered
|
||||
|
@ -369,14 +369,23 @@ class Monitor(cmd.Cmd):
|
||||
self._output(self._format_disassembly(address, bytes, disasm))
|
||||
address += bytes
|
||||
|
||||
def _format_disassembly(self, address, bytes, disasm):
|
||||
mem = ''
|
||||
for byte in self._mpu.memory[address:address + bytes]:
|
||||
mem += self.byteFmt % byte + " "
|
||||
def _format_disassembly(self, address, length, disasm):
|
||||
cur_address = address
|
||||
max_address = (2 ** self._mpu.ADDR_WIDTH) - 1
|
||||
|
||||
bytes_remaining = length
|
||||
dump = ''
|
||||
|
||||
while bytes_remaining:
|
||||
if cur_address > max_address:
|
||||
cur_address = 0
|
||||
dump += self.byteFmt % self._mpu.memory[cur_address] + " "
|
||||
cur_address += 1
|
||||
bytes_remaining -= 1
|
||||
|
||||
fieldwidth = 1 + (1 + self.byteWidth / 4) * 3
|
||||
fieldfmt = "%%-%ds" % fieldwidth
|
||||
return "$" + self.addrFmt % address + " " + fieldfmt % mem + disasm
|
||||
return "$" + self.addrFmt % address + " " + fieldfmt % dump + disasm
|
||||
|
||||
def help_disassemble(self):
|
||||
self._output("disassemble <address_range>")
|
||||
|
@ -7,6 +7,19 @@ from py65.utils.addressing import AddressParser
|
||||
|
||||
|
||||
class DisassemblerTests(unittest.TestCase):
|
||||
def test_disassemble_wraps_after_top_of_mem(self):
|
||||
mpu = MPU()
|
||||
mpu.memory[0xFFFF] = 0x20 # JSR
|
||||
mpu.memory[0x0000] = 0xD2 #
|
||||
mpu.memory[0x0001] = 0xFF # $FFD2
|
||||
|
||||
dis = Disassembler(mpu)
|
||||
# length, disasm = dis.instruction_at(0xFFFF)
|
||||
from pprint import pprint as pp
|
||||
# pp(disasm)
|
||||
|
||||
# return disasm.instruction_at(pc)
|
||||
|
||||
def test_disassembles_00(self):
|
||||
length, disasm = self.disassemble([0x00])
|
||||
self.assertEqual(1, length)
|
||||
|
@ -301,6 +301,18 @@ class MonitorTests(unittest.TestCase):
|
||||
disasm = "$c000 ea NOP\n$c001 ea NOP\n"
|
||||
self.assertEqual(out, disasm)
|
||||
|
||||
def test_disassemble_wraps_to_0_after_to_of_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.do_disassemble("ffff")
|
||||
|
||||
out = stdout.getvalue()
|
||||
disasm = "$ffff 20 d2 ff JSR $ffd2\n"
|
||||
self.assertEqual(out, disasm)
|
||||
|
||||
# fill
|
||||
|
||||
def test_shortcut_f_for_fill(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user