From ec311c879ea26d0a36cb5b885cc6b28c5dd19584 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Wed, 22 Jan 2014 22:56:02 -0800 Subject: [PATCH] Remove page wrap bug from JMP indirect on 65C02 --- py65/devices/mpu65c02.py | 5 +++++ py65/tests/devices/test_mpu6502.py | 27 ++++++++++++++++----------- py65/tests/devices/test_mpu65c02.py | 11 +++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index ee0b000..ad07605 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -279,6 +279,11 @@ class MPU(mpu6502.MPU): def inst_0x3a(self): self.opDECR(None) + @instruction(name="JMP", mode="ind", cycles=6) + def inst_0x6c(self): + ta = self.WordAt(self.pc) + self.pc = self.WordAt(ta) + @instruction(name="JMP", mode="iax", cycles=6) def inst_0x7c(self): self.pc = self.WordAt(self.IndirectAbsXAddr()) diff --git a/py65/tests/devices/test_mpu6502.py b/py65/tests/devices/test_mpu6502.py index 9c63b12..50270d6 100644 --- a/py65/tests/devices/test_mpu6502.py +++ b/py65/tests/devices/test_mpu6502.py @@ -2648,16 +2648,18 @@ class Common6502Tests: self.assertEqual(0x80, mpu.y) self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) - # JMP + # JMP Absolute - def test_jmp_jumps_to_absolute_address(self): + def test_jmp_abs_jumps_to_absolute_address(self): mpu = self._make_mpu() # $0000 JMP $ABCD self._write(mpu.memory, 0x0000, (0x4C, 0xCD, 0xAB)) mpu.step() self.assertEqual(0xABCD, mpu.pc) - def test_jmp_jumps_to_indirect_address(self): + # JMP Indirect + + def test_jmp_ind_jumps_to_indirect_address(self): mpu = self._make_mpu() # $0000 JMP ($ABCD) self._write(mpu.memory, 0x0000, (0x6C, 0x00, 0x02)) @@ -5669,6 +5671,17 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.BREAK, mpu.p & mpu.BREAK) self.assertEqual(0, mpu.p & mpu.DECIMAL) + # JMP Indirect + + def test_jmp_jumps_to_address_with_page_wrap_bug(self): + mpu = self._make_mpu() + mpu.memory[0x00ff] = 0 + # $0000 JMP ($00) + self._write(mpu.memory, 0, (0x6c, 0xff, 0x00)) + mpu.step() + self.assertEqual(0x6c00, mpu.pc) + self.assertEqual(5, mpu.processorCycles) + # Test page wrapping def test_zeropage_indexed_ind_wrap(self): @@ -5709,14 +5722,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu.step() self.assertEqual(0x31, mpu.a) - def test_indirect_wrap(self): - mpu = self._make_mpu() - mpu.memory[0x00ff] = 0 - # $0000 JMP ($00) - self._write(mpu.memory, 0, (0x6c, 0xff, 0x00)) - mpu.step() - self.assertEqual(0x6c00, mpu.pc) - def _get_target_class(self): return py65.devices.mpu6502.MPU diff --git a/py65/tests/devices/test_mpu65c02.py b/py65/tests/devices/test_mpu65c02.py index 7133801..bd088fe 100644 --- a/py65/tests/devices/test_mpu65c02.py +++ b/py65/tests/devices/test_mpu65c02.py @@ -475,6 +475,17 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.NEGATIVE, mpu.p & mpu.NEGATIVE) self.assertEqual(0, mpu.p & mpu.ZERO) + # JMP Indirect + + def test_jmp_ind_does_not_have_page_wrap_bug(self): + mpu = self._make_mpu() + self._write(mpu.memory, 0x10FF, (0xCD, 0xAB)) + # $0000 JMP ($10FF) + self._write(mpu.memory, 0, (0x6c, 0xFF, 0x10)) + mpu.step() + self.assertEqual(0xABCD, mpu.pc) + self.assertEqual(6, mpu.processorCycles) + # JMP Indirect Absolute X-Indexed def test_jmp_iax_jumps_to_address(self):