1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-01 18:41:32 +00:00

Fix program counter overflow bug in RTS

This commit is contained in:
Mike Naberezny 2014-01-21 15:06:36 -08:00
parent 6b62908285
commit ebd402e4de
3 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,9 @@
0.18-dev (Next Release)
- Fixed a bug in RTS where popping $FFFF off the stack would cause
program counter to overflow to $10000. It now wraps around to
$0000 as it should. Thanks to Gábor Lénárt for reporting it.
0.17 (2013-10-26)
- Added support for Python 3.2 and 3.3 based on work by David Beazley.

View File

@ -61,6 +61,7 @@ class MPU:
self.excycles = 0
self.addcycles = self.extracycles[instructCode]
self.instruct[instructCode](self)
self.pc &= self.addrMask
self.processorCycles += self.cycletime[instructCode] + self.excycles
return self

View File

@ -4329,12 +4329,25 @@ class Common6502Tests:
# $0000 RTS
mpu.memory[0x0000] = 0x60
self._write(mpu.memory, 0x01FE, (0x03, 0xC0)) # PCL, PCH
mpu.pc = 0x0000
mpu.sp = 0xFD
mpu.step()
self.assertEqual(0xC004, mpu.pc)
self.assertEqual(0xFF, mpu.sp)
def test_rts_wraps_around_top_of_memory(self):
mpu = self._make_mpu()
# $0000 RTS
mpu.memory[0x1000] = 0x60
self._write(mpu.memory, 0x01FE, (0xFF, 0xFF)) # PCL, PCH
mpu.pc = 0x1000
mpu.sp = 0xFD
mpu.step()
self.assertEqual(0x0000, mpu.pc)
self.assertEqual(0xFF, mpu.sp)
# SBC Absolute
def test_sbc_abs_all_zeros_and_no_borrow_is_zero(self):