From 1836596afc4651cd201ceb392b321161f641d7a1 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Wed, 7 May 2014 21:31:48 -0700 Subject: [PATCH] Revert "Remove page wrap bug from indexed indirect (X) on 65C02" This reverts commit 3c6c631945516d980d5f0c7e35ca743c4753dc7d. Conflicts: py65/tests/devices/test_mpu6502.py py65/tests/devices/test_mpu65c02.py --- py65/devices/mpu65c02.py | 7 +- py65/tests/devices/test_mpu6502.py | 92 ++---------------- py65/tests/devices/test_mpu65c02.py | 140 ---------------------------- 3 files changed, 10 insertions(+), 229 deletions(-) diff --git a/py65/devices/mpu65c02.py b/py65/devices/mpu65c02.py index a2c3b36..c56f7b5 100644 --- a/py65/devices/mpu65c02.py +++ b/py65/devices/mpu65c02.py @@ -26,14 +26,11 @@ class MPU(mpu6502.MPU): # addressing modes - def IndirectXAddr(self): - return self.WordAt(self.ByteAt(self.pc) + self.x) - def ZeroPageIndirectAddr(self): - return self.WordAt(self.ByteAt(self.pc)) + return self.WordAt(255 & (self.ByteAt(self.pc))) def IndirectAbsXAddr(self): - return self.addrMask & (self.WordAt(self.pc) + self.x) + return (self.WordAt(self.pc) + self.x) & self.addrMask # operations diff --git a/py65/tests/devices/test_mpu6502.py b/py65/tests/devices/test_mpu6502.py index bad516a..235adea 100644 --- a/py65/tests/devices/test_mpu6502.py +++ b/py65/tests/devices/test_mpu6502.py @@ -5645,21 +5645,17 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu.step() self.assertEqual(0x84, mpu.a) - # AND Indirect, Indexed (X) + # LDA Zero Page, X-Indexed - def test_and_ind_indexed_x_has_page_wrap_bug(self): + def test_lda_zp_x_indexed_page_wraps(self): mpu = self._make_mpu() - mpu.a = 0x42 + mpu.a = 0x00 mpu.x = 0xFF - # $0000 AND ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x21, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0 - mpu.memory[0xBBBB] = 0xFF + # $0000 LDA $80,X + self._write(mpu.memory, 0x0000, (0xB5, 0x80)) + mpu.memory[0x007F] = 0x42 mpu.step() + self.assertEqual(0x0002, mpu.pc) self.assertEqual(0x42, mpu.a) # AND Indexed, Indirect (Y) @@ -5829,7 +5825,7 @@ class MPUTests(unittest.TestCase, Common6502Tests): # JMP Indirect - def test_jmp_indirect_has_page_wrap_bug(self): + def test_jmp_jumps_to_address_with_page_wrap_bug(self): mpu = self._make_mpu() mpu.memory[0x00ff] = 0 # $0000 JMP ($00) @@ -5838,23 +5834,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x6c00, mpu.pc) self.assertEqual(5, mpu.processorCycles) - # ORA Indirect, Indexed (X) - - def test_ora_ind_indexed_x_has_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0 - mpu.x = 0xFF - # $0000 ORA ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x01, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0 - mpu.memory[0xBBBB] = 0x42 - mpu.step() - self.assertEqual(0x42, mpu.a) - # ORA Indexed, Indirect (Y) def test_ora_indexed_ind_y_has_page_wrap_bug(self): @@ -5874,24 +5853,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu.step() self.assertEqual(0x42, mpu.a) - # SBC Indirect, Indexed (X) - - def test_sbc_ind_x_has_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.p = mpu.CARRY - mpu.a = 0x03 - mpu.x = 0xFF - # $0000 SBC ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0xE1, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x01 - mpu.memory[0xBBBB] = 0x02 - mpu.step() - self.assertEqual(0x01, mpu.a) - # SBC Indexed, Indirect (Y) def test_sbc_indexed_ind_y_has_page_wrap_bug(self): @@ -5912,43 +5873,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu.step() self.assertEqual(0x3f, mpu.a) - # STA Indirect, Indexed (X) - - def test_sta_ind_indexed_x_has_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0x42 - mpu.x = 0xFF - # $0000 STA ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x81, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0 - mpu.memory[0xBBBB] = 0 - mpu.step() - self.assertEqual(0x00, mpu.memory[0xABCD]) - self.assertEqual(0x42, mpu.memory[0xBBBB]) - - # STA Indexed, Indirect (Y) - - def test_sta_indexed_ind_y_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = self._make_mpu() - mpu.pc = 0x1000 - mpu.a = 0x42 - mpu.y = 0x02 - # $1000 STA ($FF),Y - self._write(mpu.memory, 0x1000, (0x91, 0xff)) - # Vector - mpu.memory[0x00ff] = 0x10 # low byte - mpu.memory[0x0100] = 0x20 # high byte if no page wrap - mpu.memory[0x0000] = 0x00 # high byte if page wrapped - # Data - mpu.memory[0x2012] = 0x00 # written if no page wrap - mpu.memory[0x0012] = 0x00 # written if page wrapped - mpu.step() - self.assertEqual(0x42, mpu.memory[0x0012]) - 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 e2b84fd..480323a 100644 --- a/py65/tests/devices/test_mpu65c02.py +++ b/py65/tests/devices/test_mpu65c02.py @@ -11,23 +11,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu = self._make_mpu() self.assertTrue('65C02' in repr(mpu)) - # ADC Indirect, Indexed (X) - - def test_adc_ind_indexed_does_not_have_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0x01 - mpu.x = 0xFF - # $0000 ADC ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x61, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x01 - mpu.memory[0xBBBB] = 0x02 - mpu.step() - self.assertEqual(0x02, mpu.a) - # ADC Zero Page, Indirect def test_adc_bcd_off_zp_ind_carry_clear_in_accumulator_zeroes(self): @@ -166,23 +149,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.OVERFLOW, mpu.p & mpu.OVERFLOW) self.assertEqual(0, mpu.p & mpu.ZERO) - # AND Indirect, Indexed (X) - - def test_and_ind_indexed_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0x42 - mpu.x = 0xFF - # $0000 AND ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x21, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0xFF - mpu.memory[0xBBBB] = 0 - mpu.step() - self.assertEqual(0x42, mpu.a) - # AND Zero Page, Indirect def test_and_zp_ind_all_zeros_setting_zero_flag(self): @@ -508,42 +474,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - # CMP Indirect, Indexed (X) - - def test_cmp_ind_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.p = 0 - mpu.a = 0x42 - mpu.x = 0xFF - # $0000 CMP ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0xC1, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x42 - mpu.memory[0xBBBB] = 0x00 - mpu.step() - self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) - - # EOR Indirect, Indexed (X) - - def test_eor_ind_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.p = 0 - mpu.a = 0xAA - mpu.x = 0xFF - # $0000 EOR ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x41, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0xFF - mpu.memory[0xBBBB] = 0x00 - mpu.step() - self.assertEqual(0x55, mpu.a) - # EOR Zero Page, Indirect def test_eor_zp_ind_flips_bits_over_setting_z_flag(self): @@ -633,23 +563,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(0x1234, mpu.pc) self.assertEqual(6, mpu.processorCycles) - # LDA Indirect, Indexed (X) - - def test_lda_ind_indexed_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0x00 - mpu.x = 0xff - # $0000 LDA ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0xA1, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x42 - mpu.memory[0xBBBB] = 0xFF - mpu.step() - self.assertEqual(0x42, mpu.a) - # LDA Zero Page, Indirect def test_lda_zp_ind_loads_a_sets_n_flag(self): @@ -682,23 +595,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): self.assertEqual(mpu.ZERO, mpu.p & mpu.ZERO) self.assertEqual(0, mpu.p & mpu.NEGATIVE) - # ORA Indirect, Indexed (X) - - def test_ora_ind_indexed_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0 - mpu.x = 0xFF - # $0000 ORA ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x01, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x42 - mpu.memory[0xBBBB] = 0 - mpu.step() - self.assertEqual(0x42, mpu.a) - # ORA Zero Page, Indirect def test_ora_zp_ind_zeroes_or_zeros_sets_z_flag(self): @@ -974,42 +870,6 @@ class MPUTests(unittest.TestCase, Common6502Tests): mpu.step() self.assertEqual(expected, mpu.p) - # SBC Indirect, Indexed (X) - - def test_sbc_ind_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.p = mpu.CARRY - mpu.a = 0x03 - mpu.x = 0xFF - # $0000 SBC ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0xE1, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0x01 - mpu.memory[0xBBBB] = 0x02 - mpu.step() - self.assertEqual(0x02, mpu.a) - - # STA Indirect, Indexed (X) - - def test_sta_ind_indexed_x_does_not_have_page_wrap_bug(self): - mpu = self._make_mpu() - mpu.a = 0x42 - mpu.x = 0xFF - # $0000 STA ($80,X) - # $007f Vector to $BBBB (read if page wrapped) - # $017f Vector to $ABCD (read if no page wrap) - self._write(mpu.memory, 0x0000, (0x81, 0x80)) - self._write(mpu.memory, 0x007f, (0xBB, 0xBB)) - self._write(mpu.memory, 0x017f, (0xCD, 0xAB)) - mpu.memory[0xABCD] = 0 - mpu.memory[0xBBBB] = 0 - mpu.step() - self.assertEqual(0x42, mpu.memory[0xABCD]) - self.assertEqual(0x00, mpu.memory[0xBBBB]) - # STA Zero Page, Indirect def test_sta_zp_ind_stores_a_leaves_a_and_n_flag_unchanged(self):