From 7530f815076316d52307377f2b9292c615fcc7fc Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Wed, 12 Mar 2014 10:02:25 -0700 Subject: [PATCH] Fix 65C02 opcode $D2: CMP Zero Page, Indirect --- CHANGES.txt | 2 ++ py65/devices/mpu65c02.py | 2 +- py65/tests/devices/test_mpu65c02.py | 38 ++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d19fd5b..27ee689 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,7 @@ 0.19-dev (Next Release) + - Fixed 65C02 opcode $D2: CMP Zero Page, Indirect. + - Blocking character input at $F005 has been removed. The I/O area was designed to be compatible with Michal Kowalski's simulator, and it uses this address for another purpose. Examples that depended diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index 9b63890..a2c3b36 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -274,7 +274,7 @@ class MPU(mpu6502.MPU): @instruction(name="CMP", mode='zpi', cycles=5) def inst_0xd2(self): - self.opCPY(self.ZeroPageIndirectAddr) + self.opCMPR(self.ZeroPageIndirectAddr, self.a) self.pc += 1 @instruction(name="SMB5", mode="zpg", cycles=5) diff --git a/py65/tests/devices/test_mpu65c02.py b/py65/tests/devices/test_mpu65c02.py index dd258ce..e2b84fd 100644 --- a/py65/tests/devices/test_mpu65c02.py +++ b/py65/tests/devices/test_mpu65c02.py @@ -13,7 +13,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): # ADC Indirect, Indexed (X) - def test_adc_ind_indexed_has_page_wrap_bug(self): + def test_adc_ind_indexed_does_not_have_wrap_bug(self): mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0xFF @@ -476,9 +476,41 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.BREAK, mpu.p & mpu.BREAK) self.assertEqual(0, mpu.p & mpu.DECIMAL) + # CMP Zero Page, Indirect + + def test_cmp_zpi_sets_z_flag_if_equal(self): + mpu = self._make_mpu() + mpu.a = 0x42 + # $0000 AND ($10) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xd2, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) + mpu.memory[0xABCD] = 0x42 + mpu.step() + self.assertEqual(0x0002, mpu.pc) + self.assertEqual(5, mpu.processorCycles) + self.assertEqual(0x42, mpu.a) + self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.NEGATIVE) + + def test_cmp_zpi_resets_z_flag_if_unequal(self): + mpu = self._make_mpu() + mpu.a = 0x43 + # $0000 AND ($10) + # $0010 Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xd2, 0x10)) + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) + mpu.memory[0xABCD] = 0x42 + mpu.step() + self.assertEqual(0x0002, mpu.pc) + self.assertEqual(5, mpu.processorCycles) + self.assertEqual(0x43, mpu.a) + self.assertEqual(0, mpu.p & mpu.ZERO) + self.assertEqual(0, mpu.p & mpu.NEGATIVE) + # CMP Indirect, Indexed (X) - def test_cmp_ind_x_has_page_wrap_bug(self): + def test_cmp_ind_x_does_not_have_page_wrap_bug(self): mpu = self._make_mpu() mpu.p = 0 mpu.a = 0x42 @@ -944,7 +976,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): # SBC Indirect, Indexed (X) - def test_sbc_ind_x_has_page_wrap_bug(self): + def test_sbc_ind_x_does_not_have_page_wrap_bug(self): mpu = self._make_mpu() mpu.p = mpu.CARRY mpu.a = 0x03