1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-01-23 04:32:06 +00:00

bugfix: long standing branch bug in assembler and disassembler

This commit is contained in:
BigEd 2011-08-20 22:35:03 +01:00 committed by Mike Naberezny
parent df41a78c9c
commit edd730bb6e
3 changed files with 5 additions and 6 deletions

View File

@ -57,9 +57,8 @@ class Assembler:
# relative branch
absolute = int(''.join(operands), 16)
relative = (absolute - pc) - 2
if (relative < 1):
relative = (relative ^ 0xFF) + 1
operands = [ ('%02x' % relative) ]
relative = relative & 0xFF
operands = [ ("%02x" % relative) ]
elif len(operands) == 2:
# swap bytes

View File

@ -73,8 +73,8 @@ class Disassembler:
elif addressing == 'rel':
opv = self._mpu.ByteAt(pc + 1)
targ = pc + 2
if opv & 128:
targ -= (opv ^ 255) + 1
if opv & (1<<(8-1)):
targ -= (opv ^ 0xFF) + 1
else:
targ += opv
targ &= 0xffff

View File

@ -229,7 +229,7 @@ class Monitor(cmd.Cmd):
return
# assemble into memory
bytes = self._assembler.assemble(line)
bytes = self._assembler.assemble(line, pc=start)
if bytes is None:
self.stdout.write("\r$%04x ???\n" % start)
continue