From ebe02c2dfa0d1ea64bad9240bf02a0bce1115ea1 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Tue, 7 Apr 2009 17:40:35 -0700 Subject: [PATCH] Refactor tests to remove conditional class generation. --- src/py65/tests/test_mpu6502.py | 1517 ++++++++++++++++--------------- src/py65/tests/test_mpu65c02.py | 18 +- 2 files changed, 775 insertions(+), 760 deletions(-) diff --git a/src/py65/tests/test_mpu6502.py b/src/py65/tests/test_mpu6502.py index a8535c7..b87a966 100644 --- a/src/py65/tests/test_mpu6502.py +++ b/src/py65/tests/test_mpu6502.py @@ -1,19 +1,16 @@ import unittest import sys -from py65.mpu6502 import MPU +import py65.mpu6502 -def write(memory, start_address, bytes): - memory[start_address:start_address+len(bytes)] = bytes +class Common6502Tests: + """Tests common to 6502-based microprocessors""" -def make_common_tests(MPU): - class MPUTests(unittest.TestCase): - # ADC Absolute def test_adc_bcd_off_absolute_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 - write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 self.assertEquals(0x10000, len(mpu.memory)) mpu.memory[0xC000] = 0x00 @@ -25,10 +22,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 mpu.memory[0xC000] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -38,9 +35,9 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_absolute_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 - write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 mpu.memory[0xC000] = 0xFE mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -50,9 +47,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 - write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 mpu.memory[0xC000] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -62,9 +59,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 + self._write(mpu.memory, 0x0000, (0x6D, 0x00, 0xC0)) #=> $0000 ADC $C000 mpu.memory[0xC000] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -76,9 +73,9 @@ def make_common_tests(MPU): # ADC Zero Page def test_adc_bcd_off_zp_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 - write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 mpu.memory[0x00B0] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -88,10 +85,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 mpu.memory[0x00B0] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -101,9 +98,9 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_absolute_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 - write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 mpu.memory[0x00B0] = 0xFE mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -113,9 +110,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 - write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 mpu.memory[0x00B0] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -125,9 +122,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_absolute_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 + self._write(mpu.memory, 0x0000, (0x65, 0xB0)) #=> $0000 ADC $00B0 mpu.memory[0x00B0] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -139,9 +136,9 @@ def make_common_tests(MPU): # ADC Immediate def test_adc_bcd_off_immediate_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 - write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.a) @@ -150,10 +147,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_immediate_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 + self._write(mpu.memory, 0x0000, (0x69, 0x00)) #=> $0000 ADC #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x01, mpu.a) @@ -162,9 +159,9 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_immediate_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 - write(mpu.memory, 0x0000, (0x69, 0xFE)) #=> $0000 ADC #$FE + self._write(mpu.memory, 0x0000, (0x69, 0xFE)) #=> $0000 ADC #$FE mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0xFF, mpu.a) @@ -173,9 +170,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_immediate_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 - write(mpu.memory, 0x0000, (0x69, 0xFF)) #=> $0000 ADC #$FF + self._write(mpu.memory, 0x0000, (0x69, 0xFF)) #=> $0000 ADC #$FF mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x01, mpu.a) @@ -184,9 +181,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_immediate_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x69, 0xFF)) #=> $0000 ADC #$FF + self._write(mpu.memory, 0x0000, (0x69, 0xFF)) #=> $0000 ADC #$FF mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0xFE, mpu.a) @@ -197,10 +194,10 @@ def make_common_tests(MPU): # ADC Absolute, X-Indexed def test_adc_bcd_off_abs_x_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X mpu.memory[0xC000 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -210,11 +207,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_x_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X mpu.memory[0xC000 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -224,10 +221,10 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_abs_x_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X mpu.memory[0xC000 + mpu.x] = 0xFE mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -237,10 +234,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_x_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X mpu.memory[0xC000 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -250,10 +247,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_x_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,X mpu.memory[0xC000 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -265,10 +262,10 @@ def make_common_tests(MPU): # ADC Absolute, Y-Indexed def test_adc_bcd_off_abs_y_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y mpu.memory[0xC000 + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -278,11 +275,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_y_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.y = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x7D, 0x00, 0xC0)) #=> $0000 ADC $C000,Y mpu.memory[0xC000 + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -292,10 +289,10 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_abs_y_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y mpu.memory[0xC000 + mpu.y] = 0xFE mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -305,10 +302,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_y_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y mpu.memory[0xC000 + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -318,10 +315,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_abs_y_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y + self._write(mpu.memory, 0x0000, (0x79, 0x00, 0xC0)) #=> $0000 ADC $C000,Y mpu.memory[0xC000 + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -333,10 +330,10 @@ def make_common_tests(MPU): # ADC Zero Page, X-Indexed def test_adc_bcd_off_zp_x_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -346,11 +343,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_zp_x_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -360,10 +357,10 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_zp_x_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X mpu.memory[0x0010 + mpu.x] = 0xFE mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -373,10 +370,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_zp_x_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -386,10 +383,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_zp_x_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X + self._write(mpu.memory, 0x0000, (0x75, 0x10)) #=> $0000 ADC $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -401,11 +398,11 @@ def make_common_tests(MPU): # ADC Indirect, Indexed (X) def test_adc_bcd_off_indirect_indexed_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -415,12 +412,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indirect_indexed_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -430,11 +427,11 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_indirect_indexed_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFE mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -444,11 +441,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indirect_indexed_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -458,11 +455,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indirect_indexed_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -474,11 +471,11 @@ def make_common_tests(MPU): # ADC Indexed, Indirect (Y) def test_adc_bcd_off_indexed_indirect_carry_clear_in_accumulator_zeroes(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -488,12 +485,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indexed_indirect_carry_set_in_accumulator_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0 mpu.y = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -503,11 +500,11 @@ def make_common_tests(MPU): self.assertNotEquals(mpu.CARRY, mpu.flags & mpu.CARRY) def test_adc_bcd_off_indexed_indirect_carry_clear_in_no_carry_clear_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x01 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFE mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -517,11 +514,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indexed_indirect_carry_clear_in_carry_set_out(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x71, 0x10)) #=> $0000 ADC ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -531,11 +528,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_adc_bcd_off_indexed_indirect_indexed_overflow(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x61, 0x10)) #=> $0000 ADC ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -547,9 +544,9 @@ def make_common_tests(MPU): # AND (Absolute) def test_and_absolute_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD + self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -558,9 +555,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_absolute_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD + self._write(mpu.memory, 0x0000, (0x2D, 0xCD, 0xAB)) #=> AND $ABCD mpu.memory[0xABCD] = 0xAA mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -571,9 +568,9 @@ def make_common_tests(MPU): # AND (Absolute) def test_and_zp_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 + self._write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -582,9 +579,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_zp_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 + self._write(mpu.memory, 0x0000, (0x25, 0x10)) #=> AND $0010 mpu.memory[0x0010] = 0xAA mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -595,9 +592,9 @@ def make_common_tests(MPU): # AND (Immediate) def test_and_immediate_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x29, 0x00)) #=> AND #$00 + self._write(mpu.memory, 0x0000, (0x29, 0x00)) #=> AND #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.a) @@ -605,9 +602,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_immediate_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x29, 0xAA)) #=> AND #$AA + self._write(mpu.memory, 0x0000, (0x29, 0xAA)) #=> AND #$AA mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0xAA, mpu.a) @@ -617,10 +614,10 @@ def make_common_tests(MPU): # AND (Absolute, X-Indexed) def test_and_abs_x_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -629,10 +626,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_abs_x_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x3d, 0xCD, 0xAB)) #=> AND $ABCD,X mpu.memory[0xABCD + mpu.x] = 0xAA mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -643,10 +640,10 @@ def make_common_tests(MPU): # AND (Absolute, Y-Indexed) def test_and_abs_y_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -655,10 +652,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_abs_y_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X + self._write(mpu.memory, 0x0000, (0x39, 0xCD, 0xAB)) #=> AND $ABCD,X mpu.memory[0xABCD + mpu.y] = 0xAA mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -669,11 +666,11 @@ def make_common_tests(MPU): # AND Indirect, Indexed (X) def test_and_indirect_indexed_x_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -682,11 +679,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_indirect_indexed_x_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x21, 0x10)) #=> AND ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xAA mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -697,11 +694,11 @@ def make_common_tests(MPU): # AND Indexed, Indirect (Y) def test_and_indexed_indirect_y_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -710,11 +707,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_indexed_indirect_y_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x31, 0x10)) #=> AND ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xAA mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -725,10 +722,10 @@ def make_common_tests(MPU): # AND Zero Page, X-Indexed def test_and_zp_x_all_zeros_setting_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X + self._write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -737,10 +734,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_and_zp_x_all_zeros_and_ones_setting_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X + self._write(mpu.memory, 0x0000, (0x35, 0x10)) #=> AND $0010,X mpu.memory[0x0010 + mpu.x] = 0xAA mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -751,7 +748,7 @@ def make_common_tests(MPU): # ASL Accumulator def test_asl_accumulator_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.memory[0x0000] = 0x0A #=> ASL A mpu.step() @@ -761,7 +758,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_asl_accumulator_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x40 mpu.memory[0x0000] = 0x0A #=> ASL A mpu.step() @@ -771,7 +768,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_asl_accumulator_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x7F mpu.memory[0x0000] = 0x0A #=> ASL A mpu.step() @@ -780,7 +777,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_asl_accumulator_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.memory[0x0000] = 0x0A #=> ASL A mpu.step() @@ -791,8 +788,8 @@ def make_common_tests(MPU): # ASL Absolute def test_asl_absolute_sets_z_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -801,8 +798,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_asl_absolute_sets_n_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -811,9 +808,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_asl_absolute_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD mpu.memory[0xABCD] = 0x7F mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -822,9 +819,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_asl_absolute_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD + self._write(mpu.memory, 0x0000, (0x0E, 0xCD, 0xAB)) #=> ASL $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -835,8 +832,8 @@ def make_common_tests(MPU): # ASL Zero Page def test_asl_zp_sets_z_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -845,8 +842,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_asl_zp_sets_n_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 mpu.memory[0x0010] = 0x40 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -855,9 +852,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_asl_zp_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 mpu.memory[0x0010] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -866,9 +863,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_asl_zp_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 + self._write(mpu.memory, 0x0000, (0x06, 0x10)) #=> ASL $0010 mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -879,9 +876,9 @@ def make_common_tests(MPU): # ASL Absolute, X-Indexed def test_asl_absolute_x_indexed_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -890,9 +887,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_asl_absolute_x_indexed_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x40 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -901,10 +898,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_asl_absolute_x_indexed_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x7F mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -913,10 +910,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_asl_absolute_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAA mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X + self._write(mpu.memory, 0x0000, (0x1E, 0xCD, 0xAB)) #=> ASL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -927,9 +924,9 @@ def make_common_tests(MPU): # ASL Zero Page, X-Indexed def test_asl_zp_x_indexed_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -938,9 +935,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_asl_zp_x_indexed_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X mpu.memory[0x0010 + mpu.x] = 0x40 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -949,10 +946,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_asl_zp_x_indexed_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X mpu.memory[0x0010 + mpu.x] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -961,10 +958,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_asl_zp_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.a = 0xAA - write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X + self._write(mpu.memory, 0x0000, (0x16, 0x10)) #=> ASL $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -975,120 +972,120 @@ def make_common_tests(MPU): # BCC def test_bcc_carry_clear_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 + self._write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bcc_carry_clear_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0x90, rel)) #=> BCC -6 + self._write(mpu.memory, 0x0050, (0x90, rel)) #=> BCC -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bcc_carry_set_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 + self._write(mpu.memory, 0x0000, (0x90, 0x06)) #=> BCC +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BCS def test_bcs_carry_set_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 + self._write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bcs_carry_set_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0xB0, rel)) #=> BCS -6 + self._write(mpu.memory, 0x0050, (0xB0, rel)) #=> BCS -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bcs_carry_clear_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 + self._write(mpu.memory, 0x0000, (0xB0, 0x06)) #=> BCS +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BEQ def test_beq_zero_set_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.ZERO - write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 + self._write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_beq_zero_set_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.ZERO mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0xF0, rel)) #=> BEQ -6 + self._write(mpu.memory, 0x0050, (0xF0, rel)) #=> BEQ -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_beq_zero_clear_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) - write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 + self._write(mpu.memory, 0x0000, (0xF0, 0x06)) #=> BEQ +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BIT (Absolute) def test_bit_abs_copies_bit_7_of_memory_to_n_flag_when_0(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_bit_abs_copies_bit_7_of_memory_to_n_flag_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.NEGATIVE - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_bit_abs_copies_bit_6_of_memory_to_v_flag_when_0(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.OVERFLOW) - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0xFF mpu.a = 0xFF mpu.step() self.assertEquals(mpu.OVERFLOW, mpu.flags & mpu.OVERFLOW) def test_bit_abs_copies_bit_6_of_memory_to_v_flag_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.OVERFLOW - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0x00 mpu.a = 0xFF mpu.step() self.assertEquals(0, mpu.flags & mpu.OVERFLOW) def test_bit_abs_stores_result_of_and_in_z_while_preserving_a_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.ZERO - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() @@ -1097,9 +1094,9 @@ def make_common_tests(MPU): self.assertEquals(0x00, mpu.memory[0xFEED]) def test_bit_abs_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.ZERO - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0x01 mpu.a = 0x01 mpu.step() @@ -1108,9 +1105,9 @@ def make_common_tests(MPU): self.assertEquals(0x01, mpu.memory[0xFEED]) def test_bit_abs_stores_result_of_and_when_zero_in_z_while_preserving_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) - write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED + self._write(mpu.memory, 0x0000, (0x2C, 0xED, 0xFE)) #=> BIT $FEED mpu.memory[0xFEED] = 0x00 mpu.a = 0x01 mpu.step() @@ -1121,45 +1118,45 @@ def make_common_tests(MPU): # BIT (Zero Page) def test_bit_zp_copies_bit_7_of_memory_to_n_flag_when_0(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0xFF mpu.a = 0xFF mpu.step() self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_bit_zp_copies_bit_7_of_memory_to_n_flag_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.NEGATIVE - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0x00 mpu.a = 0xFF mpu.step() self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_bit_zp_copies_bit_6_of_memory_to_v_flag_when_0(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.OVERFLOW) - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0xFF mpu.a = 0xFF mpu.step() self.assertEquals(mpu.OVERFLOW, mpu.flags & mpu.OVERFLOW) def test_bit_zp_copies_bit_6_of_memory_to_v_flag_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.OVERFLOW - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0x00 mpu.a = 0xFF mpu.step() self.assertEquals(0, mpu.flags & mpu.OVERFLOW) def test_bit_zp_stores_result_of_and_in_z_while_preserving_a_when_1(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.ZERO - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0x00 mpu.a = 0x01 mpu.step() @@ -1168,9 +1165,9 @@ def make_common_tests(MPU): self.assertEquals(0x00, mpu.memory[0x0010]) def test_bit_zp_stores_result_of_and_when_nonzero_in_z_while_preserving_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.ZERO - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0x01 mpu.a = 0x01 mpu.step() @@ -1179,9 +1176,9 @@ def make_common_tests(MPU): self.assertEquals(0x01, mpu.memory[0x0010]) def test_bit_zp_stores_result_of_and_when_zero_in_z_while_preserving_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) - write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 + self._write(mpu.memory, 0x0000, (0x24, 0x10)) #=> BIT $0010 mpu.memory[0x0010] = 0x00 mpu.a = 0x01 mpu.step() @@ -1192,84 +1189,84 @@ def make_common_tests(MPU): # BMI def test_bmi_negative_set_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.NEGATIVE - write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BMI +06 + self._write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BMI +06 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bmi_negative_set_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.NEGATIVE mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0x30, rel)) #=> BMI -6 + self._write(mpu.memory, 0x0050, (0x30, rel)) #=> BMI -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bmi_negative_clear_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) - write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BEQ +6 + self._write(mpu.memory, 0x0000, (0x30, 0x06)) #=> BEQ +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BNE def test_bne_zero_clear_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) - write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 + self._write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bne_zero_clear_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0xD0, rel)) #=> BNE -6 + self._write(mpu.memory, 0x0050, (0xD0, rel)) #=> BNE -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bne_zero_set_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.ZERO - write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 + self._write(mpu.memory, 0x0000, (0xD0, 0x06)) #=> BNE +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BPL def test_bpl_negative_clear_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) - write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +06 + self._write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +06 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bpl_negative_clear_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0x10, rel)) #=> BPL -6 + self._write(mpu.memory, 0x0050, (0x10, rel)) #=> BPL -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bpl_negative_set_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.NEGATIVE - write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +6 + self._write(mpu.memory, 0x0000, (0x10, 0x06)) #=> BPL +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BRK def test_brk_pushes_pc_plus_2_and_status_then_sets_pc_to_irq_vector(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = 0x00 - write(mpu.memory, 0xFFFE, (0xCD, 0xAB)) + self._write(mpu.memory, 0xFFFE, (0xCD, 0xAB)) mpu.memory[0xC000] = 0x00 #=> BRK mpu.pc = 0xC000 mpu.step() @@ -1285,57 +1282,57 @@ def make_common_tests(MPU): # BVC def test_bvc_overflow_clear_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.OVERFLOW) - write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 + self._write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bvc_overflow_clear_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.OVERFLOW) mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0x50, rel)) #=> BVC -6 + self._write(mpu.memory, 0x0050, (0x50, rel)) #=> BVC -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bvc_overflow_set_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.OVERFLOW - write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 + self._write(mpu.memory, 0x0000, (0x50, 0x06)) #=> BVC +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # BVS def test_bvs_overflow_set_branches_relative_forward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.OVERFLOW - write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 + self._write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 mpu.step() self.assertEquals(0x0002 + 0x06, mpu.pc) def test_bvs_overflow_set_branches_relative_backward(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.OVERFLOW mpu.pc = 0x0050 rel = (0x06^0xFF + 1) # two's complement of 6 - write(mpu.memory, 0x0050, (0x70, rel)) #=> BVS -6 + self._write(mpu.memory, 0x0050, (0x70, rel)) #=> BVS -6 mpu.step() self.assertEquals(0x0052 + rel, mpu.pc) def test_bvs_overflow_clear_does_not_branch(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.OVERFLOW) - write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 + self._write(mpu.memory, 0x0000, (0x70, 0x06)) #=> BVS +6 mpu.step() self.assertEquals(0x0002, mpu.pc) # CLC def test_clc_clears_carry_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x18 #=> CLC mpu.step() @@ -1345,7 +1342,7 @@ def make_common_tests(MPU): # CLD def test_cld_clears_decimal_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.DECIMAL mpu.memory[0x0000] = 0xD8 #=> CLD mpu.step() @@ -1355,7 +1352,7 @@ def make_common_tests(MPU): # CLI def test_cli_clears_interrupt_mask_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.INTERRUPT mpu.memory[0x0000] = 0x58 #=> CLI mpu.step() @@ -1365,7 +1362,7 @@ def make_common_tests(MPU): # CLV def test_clv_clears_overflow_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.OVERFLOW mpu.memory[0x0000] = 0xB8 #=> CLV mpu.step() @@ -1375,8 +1372,8 @@ def make_common_tests(MPU): # DEC Absolute def test_dec_abs_decrements_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD mpu.memory[0xABCD] = 0x10 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1385,8 +1382,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dec_abs_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1395,8 +1392,8 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_dec_abs_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xCE, 0xCD, 0xAB)) #=> DEC 0xABCD mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1407,8 +1404,8 @@ def make_common_tests(MPU): # DEC Zero Page def test_dec_zp_decrements_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 mpu.memory[0x0010] = 0x10 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1417,8 +1414,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dec_zp_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1427,8 +1424,8 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_dec_zp_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xC6, 0x10)) #=> DEC 0x0010 mpu.memory[0x0010] = 0x01 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1439,8 +1436,8 @@ def make_common_tests(MPU): # DEC Absolute, X-Indexed def test_dec_abs_x_decrements_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X mpu.x = 0x03 mpu.memory[0xABCD + mpu.x] = 0x10 mpu.step() @@ -1450,8 +1447,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dec_abs_x_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1460,8 +1457,8 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_dec_abs_x_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xDE, 0xCD, 0xAB)) #=> DEC 0xABCD,X mpu.memory[0xABCD + mpu.x] = 0x01 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1472,8 +1469,8 @@ def make_common_tests(MPU): # DEC Zero Page, X-Indexed def test_dec_zp_x_decrements_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x10 mpu.step() @@ -1483,8 +1480,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dec_zp_x_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() @@ -1494,8 +1491,8 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_dec_zp_x_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xD6, 0x10)) #=> DEC 0x0010,X mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() @@ -1507,7 +1504,7 @@ def make_common_tests(MPU): # DEX def test_dex_decrements_x(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x10 mpu.memory[0x0000] = 0xCA #=> DEX mpu.step() @@ -1517,7 +1514,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dex_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 mpu.memory[0x0000] = 0xCA #=> DEX mpu.step() @@ -1527,7 +1524,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dex_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x01 mpu.memory[0x0000] = 0xCA #=> DEX mpu.step() @@ -1539,7 +1536,7 @@ def make_common_tests(MPU): # DEY def test_dey_decrements_y(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x10 mpu.memory[0x0000] = 0x88 #=> DEY mpu.step() @@ -1549,7 +1546,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_dey_below_00_rolls_over_and_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 mpu.memory[0x0000] = 0x88 #=> DEY mpu.step() @@ -1558,7 +1555,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_dey_sets_zero_flag_when_decrementing_to_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x01 mpu.memory[0x0000] = 0x88 #=> DEY mpu.step() @@ -1569,9 +1566,9 @@ def make_common_tests(MPU): # EOR Absolute def test_eor_absolute_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x4D, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x4D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1580,9 +1577,9 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_absolute_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x4D, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x4D, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1594,9 +1591,9 @@ def make_common_tests(MPU): # EOR Zero Page def test_eor_zp_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x45, 0x10)) + self._write(mpu.memory, 0x0000, (0x45, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1605,9 +1602,9 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_zp_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x45, 0x10)) + self._write(mpu.memory, 0x0000, (0x45, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1619,18 +1616,18 @@ def make_common_tests(MPU): # EOR Immediate def test_eor_immediate_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x49, 0xFF)) + self._write(mpu.memory, 0x0000, (0x49, 0xFF)) mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.a) self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_immediate_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x49, 0xFF)) + self._write(mpu.memory, 0x0000, (0x49, 0xFF)) mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0xFF, mpu.a) @@ -1640,10 +1637,10 @@ def make_common_tests(MPU): # EOR Absolute, X-Indexed def test_eor_absolute_x_indexed_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x5D, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x5D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1652,10 +1649,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_absolute_x_indexed_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x5D, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x5D, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1667,10 +1664,10 @@ def make_common_tests(MPU): # EOR Absolute, Y-Indexed def test_eor_absolute_y_indexed_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x59, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x59, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1679,10 +1676,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_absolute_y_indexed_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x59, 0xCD, 0xAB)) + self._write(mpu.memory, 0x0000, (0x59, 0xCD, 0xAB)) mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1694,11 +1691,11 @@ def make_common_tests(MPU): # EOR Indirect, Indexed (X) def test_eor_indirect_indexed_x_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1707,11 +1704,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_indirect_indexed_x_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x41, 0x10)) #=> EOR ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1723,11 +1720,11 @@ def make_common_tests(MPU): # EOR Indexed, Indirect (Y) def test_eor_indexed_indirect_y_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1736,11 +1733,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_indexed_indirect_y_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x51, 0x10)) #=> EOR ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1752,10 +1749,10 @@ def make_common_tests(MPU): # EOR Zero Page, X-Indexed def test_eor_zp_x_indexed_flips_bits_over_setting_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x55, 0x10)) + self._write(mpu.memory, 0x0000, (0x55, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1764,10 +1761,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_eor_zp_x_indexed_flips_bits_over_setting_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x55, 0x10)) + self._write(mpu.memory, 0x0000, (0x55, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1779,8 +1776,8 @@ def make_common_tests(MPU): # INC Absolute def test_inc_abs_increments_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x09 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1789,8 +1786,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_abs_increments_memory_rolls_over_and_sets_zero_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1799,8 +1796,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_abs_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xEE, 0xCD, 0xAB)) mpu.memory[0xABCD] = 0x7F mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -1811,8 +1808,8 @@ def make_common_tests(MPU): # INC Zero Page def test_inc_zp_increments_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xE6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xE6, 0x10)) mpu.memory[0x0010] = 0x09 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1821,8 +1818,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_zp_increments_memory_rolls_over_and_sets_zero_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xE6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xE6, 0x10)) mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1831,8 +1828,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_zp_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xE6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xE6, 0x10)) mpu.memory[0x0010] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1843,8 +1840,8 @@ def make_common_tests(MPU): # INC Absolute, X-Indexed def test_inc_abs_x_increments_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) mpu.x = 0x03 mpu.memory[0xABCD + mpu.x] = 0x09 mpu.step() @@ -1854,8 +1851,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_abs_x_increments_memory_rolls_over_and_sets_zero_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) mpu.x = 0x03 mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() @@ -1865,8 +1862,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_abs_x_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xFE, 0xCD, 0xAB)) mpu.x = 0x03 mpu.memory[0xABCD + mpu.x] = 0x7F mpu.step() @@ -1878,8 +1875,8 @@ def make_common_tests(MPU): # INC Zero Page, X-Indexed def test_inc_zp_x_increments_memory(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xF6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xF6, 0x10)) mpu.x = 0x03 mpu.memory[0x0010 + mpu.x] = 0x09 mpu.step() @@ -1889,8 +1886,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_zp_x_increments_memory_rolls_over_and_sets_zero_flag(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xF6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xF6, 0x10)) mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1899,8 +1896,8 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inc_zp_x_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0xF6, 0x10)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0xF6, 0x10)) mpu.memory[0x0010 + mpu.x] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -1911,7 +1908,7 @@ def make_common_tests(MPU): # INX def test_inx_increments_x(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x09 mpu.memory[0x0000] = 0xE8 #=> INX mpu.step() @@ -1921,7 +1918,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_inx_above_FF_rolls_over_and_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF mpu.memory[0x0000] = 0xE8 #=> INX mpu.step() @@ -1930,7 +1927,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_inx_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x7f mpu.memory[0x0000] = 0xE8 #=> INX mpu.step() @@ -1941,7 +1938,7 @@ def make_common_tests(MPU): # INY def test_iny_increments_y(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x09 mpu.memory[0x0000] = 0xC8 #=> INY mpu.step() @@ -1951,7 +1948,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_iny_above_FF_rolls_over_and_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF mpu.memory[0x0000] = 0xC8 #=> INY mpu.step() @@ -1960,7 +1957,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_iny_sets_negative_flag_when_incrementing_above_7F(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x7f mpu.memory[0x0000] = 0xC8 #=> INY mpu.step() @@ -1971,23 +1968,23 @@ def make_common_tests(MPU): # JMP def test_jmp_jumps_to_absolute_address(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x4C, 0xCD, 0xAB)) #=> JMP $ABCD + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x4C, 0xCD, 0xAB)) #=> JMP $ABCD mpu.step() self.assertEquals(0xABCD, mpu.pc) def test_jmp_jumps_to_indirect_address(self): - mpu = MPU() - write(mpu.memory, 0x0000, (0x6C, 0x00, 0x02)) #=> JMP ($ABCD) - write(mpu.memory, 0x0200, (0xCD, 0xAB)) + mpu = self._make_mpu() + self._write(mpu.memory, 0x0000, (0x6C, 0x00, 0x02)) #=> JMP ($ABCD) + self._write(mpu.memory, 0x0200, (0xCD, 0xAB)) mpu.step() self.assertEquals(0xABCD, mpu.pc) # JSR def test_jsr_pushes_pc_plus_2_and_sets_pc(self): - mpu = MPU() - write(mpu.memory, 0xC000, (0x20, 0xD2, 0xFF)) #=> JSR $FFD2 + mpu = self._make_mpu() + self._write(mpu.memory, 0xC000, (0x20, 0xD2, 0xFF)) #=> JSR $FFD2 mpu.pc = 0xC000 mpu.step() self.assertEquals(0xFFD2, mpu.pc) @@ -1998,9 +1995,9 @@ def make_common_tests(MPU): # LDA Absolute def test_lda_absolute_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2009,9 +2006,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_absolute_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2022,9 +2019,9 @@ def make_common_tests(MPU): # LDA Absolute def test_lda_absolute_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2033,9 +2030,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_absolute_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD + self._write(mpu.memory, 0x0000, (0xAD, 0xCD, 0xAB)) #=> LDA $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2046,9 +2043,9 @@ def make_common_tests(MPU): # LDA Zero Page def test_lda_zp_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 + self._write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 mpu.memory[0x0010] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2057,9 +2054,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_zp_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 + self._write(mpu.memory, 0x0000, (0xA5, 0x10)) #=> LDA $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2070,9 +2067,9 @@ def make_common_tests(MPU): # LDA Immediate def test_lda_immediate_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xA9, 0x80)) #=> LDA #$80 + self._write(mpu.memory, 0x0000, (0xA9, 0x80)) #=> LDA #$80 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x80, mpu.a) @@ -2080,9 +2077,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_immediate_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF - write(mpu.memory, 0x0000, (0xA2, 0x00)) #=> LDA #$00 + self._write(mpu.memory, 0x0000, (0xA2, 0x00)) #=> LDA #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.a) @@ -2092,10 +2089,10 @@ def make_common_tests(MPU): # LDA Absolute, X-Indexed def test_lda_absolute_x_indexed_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X + self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2104,10 +2101,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_absolute_x_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X + self._write(mpu.memory, 0x0000, (0xBD, 0xCD, 0xAB)) #=> LDA $ABCD,X mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2118,10 +2115,10 @@ def make_common_tests(MPU): # LDA Absolute, Y-Indexed def test_lda_absolute_y_indexed_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y + self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2130,10 +2127,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_absolute_y_indexed_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y + self._write(mpu.memory, 0x0000, (0xB9, 0xCD, 0xAB)) #=> LDA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2144,11 +2141,11 @@ def make_common_tests(MPU): # LDA Indirect, Indexed (X) def test_lda_indirect_indexed_x_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2157,11 +2154,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_indirect_indexed_x_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xA1, 0x10)) #=> LDA ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2172,11 +2169,11 @@ def make_common_tests(MPU): # LDA Indexed, Indirect (Y) def test_lda_indexed_indirect_y_loads_a_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2185,11 +2182,11 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_indexed_indirect_y_loads_a_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0xB1, 0x10)) #=> LDA ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2200,10 +2197,10 @@ def make_common_tests(MPU): # LDA Zero Page, X-Indexed def test_lda_zp_x_indexed_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X + self._write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X mpu.memory[0x0010 + mpu.x] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2212,10 +2209,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_lda_zp_x_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X + self._write(mpu.memory, 0x0000, (0xB5, 0x10)) #=> LDA $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2226,9 +2223,9 @@ def make_common_tests(MPU): # LDX Absolute def test_ldx_absolute_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 - write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD + self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2237,9 +2234,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_absolute_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF - write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD + self._write(mpu.memory, 0x0000, (0xAE, 0xCD, 0xAB)) #=> LDX $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2250,9 +2247,9 @@ def make_common_tests(MPU): # LDX Zero Page def test_ldx_zp_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 - write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 + self._write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 mpu.memory[0x0010] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2261,9 +2258,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_zp_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF - write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 + self._write(mpu.memory, 0x0000, (0xA6, 0x10)) #=> LDX $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2274,9 +2271,9 @@ def make_common_tests(MPU): # LDX Immediate def test_ldx_immediate_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 - write(mpu.memory, 0x0000, (0xA2, 0x80)) #=> LDX #$80 + self._write(mpu.memory, 0x0000, (0xA2, 0x80)) #=> LDX #$80 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x80, mpu.x) @@ -2284,9 +2281,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_immediate_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF - write(mpu.memory, 0x0000, (0xA2, 0x00)) #=> LDX #$00 + self._write(mpu.memory, 0x0000, (0xA2, 0x00)) #=> LDX #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.x) @@ -2296,10 +2293,10 @@ def make_common_tests(MPU): # LDX Absolute, Y-Indexed def test_ldx_absolute_y_indexed_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y + self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2308,10 +2305,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_absolute_y_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y + self._write(mpu.memory, 0x0000, (0xBE, 0xCD, 0xAB)) #=> LDX $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2322,10 +2319,10 @@ def make_common_tests(MPU): # LDX Zero Page, Y-Indexed def test_ldx_zp_y_indexed_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y + self._write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y mpu.memory[0x0010 + mpu.y] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2334,10 +2331,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldx_zp_y_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y + self._write(mpu.memory, 0x0000, (0xB6, 0x10)) #=> LDX $0010,Y mpu.memory[0x0010 + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2348,9 +2345,9 @@ def make_common_tests(MPU): # LDY Absolute def test_ldy_absolute_loads_y_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 - write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD + self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD mpu.memory[0xABCD] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2359,9 +2356,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldy_absolute_loads_y_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF - write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD + self._write(mpu.memory, 0x0000, (0xAC, 0xCD, 0xAB)) #=> LDY $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2372,9 +2369,9 @@ def make_common_tests(MPU): # LDY Zero Page def test_ldy_zp_loads_y_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 - write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 + self._write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 mpu.memory[0x0010] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2383,9 +2380,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldy_zp_loads_y_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF - write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 + self._write(mpu.memory, 0x0000, (0xA4, 0x10)) #=> LDY $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2396,9 +2393,9 @@ def make_common_tests(MPU): # LDY Immediate def test_ldy_immediate_loads_y_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 - write(mpu.memory, 0x0000, (0xA0, 0x80)) #=> LDY #$80 + self._write(mpu.memory, 0x0000, (0xA0, 0x80)) #=> LDY #$80 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x80, mpu.y) @@ -2406,9 +2403,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldy_immediate_loads_y_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF - write(mpu.memory, 0x0000, (0xA0, 0x00)) #=> LDY #$00 + self._write(mpu.memory, 0x0000, (0xA0, 0x00)) #=> LDY #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.y) @@ -2418,10 +2415,10 @@ def make_common_tests(MPU): # LDY Absolute, X-Indexed def test_ldy_absolute_x_indexed_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X + self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x80 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2430,10 +2427,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldy_absolute_x_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X + self._write(mpu.memory, 0x0000, (0xBC, 0xCD, 0xAB)) #=> LDY $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2444,10 +2441,10 @@ def make_common_tests(MPU): # LDY Zero Page, X-Indexed def test_ldy_zp_x_indexed_loads_x_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X + self._write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X mpu.memory[0x0010 + mpu.x] = 0x80 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2456,10 +2453,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_ldy_zp_x_indexed_loads_x_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X + self._write(mpu.memory, 0x0000, (0xB4, 0x10)) #=> LDY $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2470,7 +2467,7 @@ def make_common_tests(MPU): # LSR Accumulator def test_lsr_accumulator_rotates_in_zero_not_carry(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.memory[0x0000] = (0x4A) #=> LSR A mpu.a = 0x00 @@ -2482,7 +2479,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_accumulator_sets_carry_and_zero_flags_after_rotation(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.memory[0x0000] = (0x4A) #=> LSR A mpu.a = 0x01 @@ -2494,7 +2491,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_accumulator_rotates_bits_right(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.memory[0x0000] = (0x4A) #=> LSR A mpu.a = 0x04 @@ -2508,9 +2505,9 @@ def make_common_tests(MPU): # LSR Absolute def test_lsr_absolute_rotates_in_zero_not_carry(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2520,9 +2517,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_absolute_sets_carry_and_zero_flags_after_rotation(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2532,9 +2529,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_absolute_rotates_bits_right(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD + self._write(mpu.memory, 0x0000, (0x4E, 0xCD, 0xAB)) #=> LSR $ABCD mpu.memory[0xABCD] = 0x04 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2546,9 +2543,9 @@ def make_common_tests(MPU): # LSR Zero Page def test_lsr_zp_rotates_in_zero_not_carry(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2558,9 +2555,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_zp_sets_carry_and_zero_flags_after_rotation(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 mpu.memory[0x0010] = 0x01 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2570,9 +2567,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_zp_rotates_bits_right(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 + self._write(mpu.memory, 0x0000, (0x46, 0x10)) #=> LSR $0010 mpu.memory[0x0010] = 0x04 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2584,10 +2581,10 @@ def make_common_tests(MPU): # LSR Absolute, X-Indexed def test_lsr_absolute_x_indexed_rotates_in_zero_not_carry(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2597,10 +2594,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_absolute_x_indexed_sets_carry_and_zero_flags_after_rotation(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x01 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2610,9 +2607,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_absolute_x_indexed_rotates_bits_right(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY - write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X + self._write(mpu.memory, 0x0000, (0x5E, 0xCD, 0xAB)) #=> LSR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x04 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2624,10 +2621,10 @@ def make_common_tests(MPU): # LSR Zero Page, X-Indexed def test_lsr_zp_x_indexed_rotates_in_zero_not_carry(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2637,10 +2634,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_zp_x_indexed_sets_carry_and_zero_flags_after_rotation(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X mpu.memory[0x0010 + mpu.x] = 0x01 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2650,10 +2647,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_lsr_zp_x_indexed_rotates_bits_right(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= mpu.CARRY mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X + self._write(mpu.memory, 0x0000, (0x56, 0x10)) #=> LSR $0010,X mpu.memory[0x0010 + mpu.x] = 0x04 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2665,7 +2662,7 @@ def make_common_tests(MPU): # NOP def test_nop_does_nothing(self): - mpu = MPU() + mpu = self._make_mpu() mpu.memory[0x0000] = 0xEA #=> NOP mpu.step() self.assertEquals(0x0001, mpu.pc) @@ -2673,10 +2670,10 @@ def make_common_tests(MPU): # ORA Absolute def test_ora_absolute_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD + self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2684,10 +2681,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_absolute_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 - write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD + self._write(mpu.memory, 0x0000, (0x0D, 0xCD, 0xAB)) #=> ORA $ABCD mpu.memory[0xABCD] = 0x82 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2698,10 +2695,10 @@ def make_common_tests(MPU): # ORA Zero Page def test_ora_zp_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 + self._write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2709,10 +2706,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_zp_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 - write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 + self._write(mpu.memory, 0x0000, (0x05, 0x10)) #=> ORA $0010 mpu.memory[0x0010] = 0x82 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2723,20 +2720,20 @@ def make_common_tests(MPU): # ORA Immediate def test_ora_immediate_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x09, 0x00)) #=> ORA #$00 + self._write(mpu.memory, 0x0000, (0x09, 0x00)) #=> ORA #$00 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x00, mpu.a) self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_immediate_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 - write(mpu.memory, 0x0000, (0x09, 0x82)) #=> ORA #$82 + self._write(mpu.memory, 0x0000, (0x09, 0x82)) #=> ORA #$82 mpu.step() self.assertEquals(0x0002, mpu.pc) self.assertEquals(0x83, mpu.a) @@ -2746,11 +2743,11 @@ def make_common_tests(MPU): # ORA Absolute, X def test_ora_absolute_x_indexed_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X + self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2758,11 +2755,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_absolute_x_indexed_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X + self._write(mpu.memory, 0x0000, (0x1D, 0xCD, 0xAB)) #=> ORA $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x82 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2773,11 +2770,11 @@ def make_common_tests(MPU): # ORA Absolute, Y def test_ora_absolute_y_indexed_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2785,11 +2782,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_absolute_y_indexed_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x19, 0xCD, 0xAB)) #=> ORA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x82 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2800,12 +2797,12 @@ def make_common_tests(MPU): # ORA Indirect, Indexed (X) def test_ora_indirect_indexed_x_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($0010,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($0010,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2813,12 +2810,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_indirect_indexed_x_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($ABCD,X) - write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x01, 0x10)) #=> ORA ($ABCD,X) + self._write(mpu.memory, 0x0013, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD] = 0x82 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2829,12 +2826,12 @@ def make_common_tests(MPU): # ORA Indexed, Indirect (Y) def test_ora_indexed_indirect_y_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2842,12 +2839,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_indexed_indirect_y_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y - write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD + self._write(mpu.memory, 0x0000, (0x11, 0x10)) #=> ORA ($0010),Y + self._write(mpu.memory, 0x0010, (0xCD, 0xAB)) #=> Vector to $ABCD mpu.memory[0xABCD + mpu.y] = 0x82 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2858,11 +2855,11 @@ def make_common_tests(MPU): # ORA Zero Page, X def test_ora_zp_x_indexed_zeroes_or_zeros_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X + self._write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2870,11 +2867,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_ora_zp_x_indexed_turns_bits_on_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x03 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X + self._write(mpu.memory, 0x0000, (0x15, 0x10)) #=> ORA $0010,X mpu.memory[0x0010 + mpu.x] = 0x82 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -2885,7 +2882,7 @@ def make_common_tests(MPU): # PHA def test_pha_pushes_a_and_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAB mpu.memory[0x0000] = 0x48 #=> PHA mpu.step() @@ -2897,7 +2894,7 @@ def make_common_tests(MPU): # PHP def test_php_pushes_processor_status_and_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() flags = (mpu.NEGATIVE | mpu.OVERFLOW | mpu.DECIMAL | mpu.ZERO | mpu.CARRY) mpu.flags = flags mpu.memory[0x0000] = 0x08 #=> PHP @@ -2909,7 +2906,7 @@ def make_common_tests(MPU): # PLA def test_pla_pulls_top_byte_from_stack_into_a_and_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() mpu.memory[0x0000] = 0x68 #=> PLA mpu.memory[0x01FF] = 0xAB mpu.sp = 0xFE @@ -2921,7 +2918,7 @@ def make_common_tests(MPU): # PLP def test_plp_pulls_top_byte_from_stack_into_flags_and_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() mpu.memory[0x0000] = 0x28 #=> PLP mpu.memory[0x01FF] = 0xAB mpu.sp = 0xFE @@ -2933,7 +2930,7 @@ def make_common_tests(MPU): # ROL Accumulator def test_rol_accumulator_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags &= ~(mpu.CARRY) mpu.memory[0x0000] = 0x2A #=> ROL A @@ -2944,7 +2941,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_accumulator_zero_and_carry_one_clears_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x2A #=> ROL A @@ -2955,7 +2952,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_accumulator_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x40 mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x2A #=> ROL A @@ -2966,7 +2963,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_rol_accumulator_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x7F mpu.flags &= ~(mpu.CARRY) mpu.memory[0x0000] = 0x0A #=> ROL A @@ -2976,7 +2973,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_rol_accumulator_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xFF mpu.flags &= ~(mpu.CARRY) mpu.memory[0x0000] = 0x2A #=> ROL A @@ -2988,9 +2985,9 @@ def make_common_tests(MPU): # ROL Absolute def test_rol_absolute_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -2999,10 +2996,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_absolute_zero_and_carry_one_clears_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3011,9 +3008,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_absolute_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD mpu.memory[0xABCD] = 0x40 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3022,9 +3019,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_rol_absolute_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD mpu.memory[0xABCD] = 0x7F mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3032,9 +3029,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_rol_absolute_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD + self._write(mpu.memory, 0x0000, (0x2E, 0xCD, 0xAB)) #=> ROL $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3044,9 +3041,9 @@ def make_common_tests(MPU): # ROL Zero Page def test_rol_zp_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3055,10 +3052,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_zp_zero_and_carry_one_clears_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3067,9 +3064,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_zp_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 mpu.memory[0x0010] = 0x40 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3078,9 +3075,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_rol_zp_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 mpu.memory[0x0010] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3088,9 +3085,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_rol_zp_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 + self._write(mpu.memory, 0x0000, (0x26, 0x10)) #=> ROL $0010 mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3100,10 +3097,10 @@ def make_common_tests(MPU): # ROL Absolute, X-Indexed def test_rol_absolute_x_indexed_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3112,10 +3109,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_absolute_x_indexed_zero_and_carry_one_clears_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3124,10 +3121,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_absolute_x_indexed_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x40 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3136,10 +3133,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_rol_absolute_x_indexed_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x7F mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3147,10 +3144,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_rol_absolute_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X + self._write(mpu.memory, 0x0000, (0x3E, 0xCD, 0xAB)) #=> ROL $ABCD,X mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3160,10 +3157,10 @@ def make_common_tests(MPU): # ROL Zero Page, X-Indexed def test_rol_zp_x_indexed_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3172,10 +3169,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_zp_x_indexed_zero_and_carry_one_clears_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3184,10 +3181,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_rol_zp_x_indexed_sets_n_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x40 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3196,10 +3193,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.ZERO) def test_rol_zp_x_indexed_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0x7F mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3207,10 +3204,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_rol_zp_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X + self._write(mpu.memory, 0x0000, (0x36, 0x10)) #=> ROL $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3220,7 +3217,7 @@ def make_common_tests(MPU): # ROR Accumulator def test_ror_accumulator_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags &= ~(mpu.CARRY) mpu.memory[0x0000] = 0x6A #=> ROR A @@ -3231,7 +3228,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_ror_accumulator_zero_and_carry_one_rotates_in_sets_n_flags(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x00 mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x6A #=> ROR A @@ -3242,7 +3239,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_ror_accumulator_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x02 mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x6A #=> ROR A @@ -3252,7 +3249,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_ror_accumulator_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0x03 mpu.flags |= mpu.CARRY mpu.memory[0x0000] = 0x6A #=> ROR A @@ -3264,9 +3261,9 @@ def make_common_tests(MPU): # ROR Absolute def test_ror_absolute_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3275,9 +3272,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_ror_absolute_zero_and_carry_one_rotates_in_sets_n_flags(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3286,9 +3283,9 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_ror_absolute_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD mpu.memory[0xABCD] = 0x02 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3296,9 +3293,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_ror_absolute_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD + self._write(mpu.memory, 0x0000, (0x6E, 0xCD, 0xAB)) #=> ROR $ABCD mpu.memory[0xABCD] = 0x03 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3308,9 +3305,9 @@ def make_common_tests(MPU): # ROR Zero Page def test_ror_zp_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3319,9 +3316,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_ror_zp_zero_and_carry_one_rotates_in_sets_n_flags(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3330,9 +3327,9 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_ror_zp_zero_absolute_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 mpu.memory[0x0010] = 0x02 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3340,9 +3337,9 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_ror_zp_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 + self._write(mpu.memory, 0x0000, (0x66, 0x10)) #=> ROR $0010 mpu.memory[0x0010] = 0x03 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3352,10 +3349,10 @@ def make_common_tests(MPU): # ROR Absolute, X-Indexed def test_ror_absolute_x_indexed_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3364,10 +3361,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_ror_absolute_x_indexed_zero_and_carry_one_rotates_in_sets_n_flags(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3376,10 +3373,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_ror_absolute_x_indexed_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x02 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3387,10 +3384,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_ror_absolute_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X + self._write(mpu.memory, 0x0000, (0x7E, 0xCD, 0xAB)) #=> ROR $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x03 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -3400,10 +3397,10 @@ def make_common_tests(MPU): # ROR Zero Page, X-Indexed def test_ror_zp_x_indexed_zero_and_carry_zero_sets_z_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags &= ~(mpu.CARRY) - write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3412,10 +3409,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_ror_zp_x_indexed_zero_and_carry_one_rotates_in_sets_n_flags(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3424,10 +3421,10 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_ror_zp_x_indexed_zero_absolute_shifts_out_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X mpu.memory[0x0010 + mpu.x] = 0x02 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3435,10 +3432,10 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.CARRY) def test_ror_zp_x_indexed_shifts_out_one(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0x03 mpu.flags |= mpu.CARRY - write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X + self._write(mpu.memory, 0x0000, (0x76, 0x10)) #=> ROR $0010,X mpu.memory[0x0010 + mpu.x] = 0x03 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -3448,9 +3445,9 @@ def make_common_tests(MPU): # RTI def test_rti_restores_status_register_and_program_counter_and_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() mpu.memory[0x0000] = 0x40 #=> RTI - write(mpu.memory, 0x01FD, (0xAB, 0x03, 0xC0)) # Status (P), PCL, PCH + self._write(mpu.memory, 0x01FD, (0xAB, 0x03, 0xC0)) # Status (P), PCL, PCH mpu.sp = 0xFC mpu.step() @@ -3461,9 +3458,9 @@ def make_common_tests(MPU): # RTS def test_rts_restores_program_counter_and_increments_then_updates_sp(self): - mpu = MPU() + mpu = self._make_mpu() mpu.memory[0x0000] = 0x60 #=> RTS - write(mpu.memory, 0x01FE, (0x03, 0xC0)) # PCL, PCH + self._write(mpu.memory, 0x01FE, (0x03, 0xC0)) # PCL, PCH mpu.sp = 0xFD mpu.step() @@ -3473,11 +3470,11 @@ def make_common_tests(MPU): # SBC Absolute def test_sbc_abs_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3486,11 +3483,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD mpu.memory[0xABCD] = 0x01 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3499,11 +3496,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3512,11 +3509,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD + self._write(mpu.memory, 0x0000, (0xED, 0xCD, 0xAB)) #=> SBC $ABCD mpu.memory[0xABCD] = 0x02 mpu.step() self.assertEquals(0x04, mpu.a) @@ -3527,11 +3524,11 @@ def make_common_tests(MPU): # SBC Zero Page def test_sbc_zp_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3540,11 +3537,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 mpu.memory[0x0010] = 0x01 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3553,11 +3550,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3566,11 +3563,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 + self._write(mpu.memory, 0x0000, (0xE5, 0x10)) #=> SBC $10 mpu.memory[0x0010] = 0x02 mpu.step() self.assertEquals(0x04, mpu.a) @@ -3581,11 +3578,11 @@ def make_common_tests(MPU): # SBC Immediate def test_sbc_imm_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 + self._write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 mpu.step() self.assertEquals(0x00, mpu.a) self.assertEquals(0, mpu.flags & mpu.NEGATIVE) @@ -3593,11 +3590,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_imm_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE9, 0x01)) #=> SBC #$01 + self._write(mpu.memory, 0x0000, (0xE9, 0x01)) #=> SBC #$01 mpu.step() self.assertEquals(0x00, mpu.a) self.assertEquals(0, mpu.flags & mpu.NEGATIVE) @@ -3605,11 +3602,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_imm_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 + self._write(mpu.memory, 0x0000, (0xE9, 0x00)) #=> SBC #$00 mpu.step() self.assertEquals(0x00, mpu.a) self.assertEquals(0, mpu.flags & mpu.NEGATIVE) @@ -3617,11 +3614,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_imm_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xE9, 0x02)) #=> SBC #$02 + self._write(mpu.memory, 0x0000, (0xE9, 0x02)) #=> SBC #$02 mpu.step() self.assertEquals(0x04, mpu.a) self.assertEquals(0, mpu.flags & mpu.NEGATIVE) @@ -3631,11 +3628,11 @@ def make_common_tests(MPU): # SBC Absolute, X-Indexed def test_sbc_abs_x_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X mpu.x = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3645,11 +3642,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_x_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X mpu.x = 0x0D mpu.memory[0xFEED] = 0x01 mpu.step() @@ -3659,11 +3656,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_x_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X mpu.x = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3673,11 +3670,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_x_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X + self._write(mpu.memory, 0x0000, (0xFD, 0xE0, 0xFE)) #=> SBC $FEE0,X mpu.x = 0x0D mpu.memory[0xFEED] = 0x02 mpu.step() @@ -3689,11 +3686,11 @@ def make_common_tests(MPU): # SBC Absolute, Y-Indexed def test_sbc_abs_y_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y mpu.y = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3703,11 +3700,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_y_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y mpu.y = 0x0D mpu.memory[0xFEED] = 0x01 mpu.step() @@ -3717,11 +3714,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_y_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y mpu.y = 0x0D mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3731,11 +3728,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_abs_y_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y + self._write(mpu.memory, 0x0000, (0xF9, 0xE0, 0xFE)) #=> SBC $FEE0,Y mpu.y = 0x0D mpu.memory[0xFEED] = 0x02 mpu.step() @@ -3747,12 +3744,12 @@ def make_common_tests(MPU): # SBC Indirect, Indexed (X) def test_sbc_ind_x_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3762,12 +3759,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x01 mpu.step() @@ -3777,12 +3774,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3792,12 +3789,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x02 mpu.step() @@ -3807,12 +3804,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.CARRY, mpu.CARRY) def test_sbc_ind_x_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3822,12 +3819,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x01 mpu.step() @@ -3837,12 +3834,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x00 mpu.step() @@ -3852,12 +3849,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_x_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xE1, 0x10)) #=> SBC ($10,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.x = 0x03 mpu.memory[0xFEED] = 0x02 mpu.step() @@ -3869,13 +3866,13 @@ def make_common_tests(MPU): # SBC Indexed, Indirect (Y) def test_sbc_ind_y_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3884,12 +3881,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_y_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0x01 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3898,12 +3895,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_y_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEquals(0x00, mpu.a) @@ -3912,12 +3909,12 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_ind_y_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y - write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0xF1, 0x10)) #=> SBC ($10),Y + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0x02 mpu.step() self.assertEquals(0x04, mpu.a) @@ -3928,11 +3925,11 @@ def make_common_tests(MPU): # SBC Zero Page, X-Indexed def test_sbc_zp_x_all_zeros_and_no_borrow_is_zero(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x00 - write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X mpu.x = 0x0D mpu.memory[0x001D] = 0x00 mpu.step() @@ -3942,11 +3939,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_x_downto_zero_no_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags |= mpu.CARRY # borrow = 0 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X mpu.x = 0x0D mpu.memory[0x001D] = 0x01 mpu.step() @@ -3956,11 +3953,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_x_downto_zero_with_borrow_sets_z_clears_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x01 - write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X mpu.x = 0x0D mpu.memory[0x001D] = 0x00 mpu.step() @@ -3970,11 +3967,11 @@ def make_common_tests(MPU): self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) def test_sbc_zp_x_downto_four_with_borrow_clears_z_n(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.flags &= ~(mpu.CARRY) # borrow = 1 mpu.a = 0x07 - write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X + self._write(mpu.memory, 0x0000, (0xF5, 0x10)) #=> SBC $10,X mpu.x = 0x0D mpu.memory[0x001D] = 0x02 mpu.step() @@ -3986,7 +3983,7 @@ def make_common_tests(MPU): # SEC def test_sec_sets_carry_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.CARRY) mpu.memory[0x0000] = 0x038 #=> SEC mpu.step() @@ -3996,7 +3993,7 @@ def make_common_tests(MPU): # SED def test_sed_sets_decimal_mode_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.DECIMAL) mpu.memory[0x0000] = 0xF8 #=> SED mpu.step() @@ -4006,7 +4003,7 @@ def make_common_tests(MPU): # SEI def test_sei_sets_interrupt_disable_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.INTERRUPT) mpu.memory[0x0000] = 0x78 #=> SEI mpu.step() @@ -4016,10 +4013,10 @@ def make_common_tests(MPU): # STA Absolute def test_sta_absolute_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD + self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4028,10 +4025,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_absolute_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD + self._write(mpu.memory, 0x0000, (0x8D, 0xCD, 0xAB)) #=> STA $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4042,10 +4039,10 @@ def make_common_tests(MPU): # STA Zero Page def test_sta_zp_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF - write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 + self._write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4054,10 +4051,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_zp_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 - write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 + self._write(mpu.memory, 0x0000, (0x85, 0x10)) #=> STA $0010 mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4068,11 +4065,11 @@ def make_common_tests(MPU): # STA Absolute, X-Indexed def test_sta_absolute_x_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X + self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X mpu.memory[0xABCD + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4081,11 +4078,11 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_absolute_x_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X + self._write(mpu.memory, 0x0000, (0x9D, 0xCD, 0xAB)) #=> STA $ABCD,X mpu.memory[0xABCD + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4096,11 +4093,11 @@ def make_common_tests(MPU): # STA Absolute, Y-Indexed def test_sta_absolute_y_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4109,11 +4106,11 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_absolute_y_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y + self._write(mpu.memory, 0x0000, (0x99, 0xCD, 0xAB)) #=> STA $ABCD,Y mpu.memory[0xABCD + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4124,12 +4121,12 @@ def make_common_tests(MPU): # STA Indirect, Indexed (X) def test_sta_indirect_indexed_x_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4138,12 +4135,12 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_indirect_indexed_x_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) - write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0x81, 0x10)) #=> STA ($0010,X) + self._write(mpu.memory, 0x0013, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4154,12 +4151,12 @@ def make_common_tests(MPU): # STA Indexed, Indirect (Y) def test_sta_indexed_indirect_y_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y - write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4168,12 +4165,12 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_indexed_indirect_y_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y - write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED + self._write(mpu.memory, 0x0000, (0x91, 0x10)) #=> STA ($0010),Y + self._write(mpu.memory, 0x0010, (0xED, 0xFE)) #=> Vector to $FEED mpu.memory[0xFEED + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4184,11 +4181,11 @@ def make_common_tests(MPU): # STA Zero Page, X-Indexed def test_sta_zp_x_indexed_stores_a_leaves_a_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.a = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X + self._write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4197,11 +4194,11 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sta_zp_x_indexed_stores_a_leaves_a_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X + self._write(mpu.memory, 0x0000, (0x95, 0x10)) #=> STA $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4212,10 +4209,10 @@ def make_common_tests(MPU): # STX Absolute def test_stx_absolute_stores_x_leaves_x_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF - write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD + self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4224,10 +4221,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_stx_absolute_stores_x_leaves_x_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 - write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD + self._write(mpu.memory, 0x0000, (0x8E, 0xCD, 0xAB)) #=> STX $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4238,10 +4235,10 @@ def make_common_tests(MPU): # STX Zero Page def test_stx_zp_stores_x_leaves_x_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF - write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 + self._write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4250,10 +4247,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_stx_zp_stores_x_leaves_x_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 - write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 + self._write(mpu.memory, 0x0000, (0x86, 0x10)) #=> STX $0010 mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4264,11 +4261,11 @@ def make_common_tests(MPU): # STX Zero Page, Y-Indexed def test_stx_zp_y_indexed_stores_x_leaves_x_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.x = 0xFF mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y + self._write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y mpu.memory[0x0010 + mpu.y] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4277,11 +4274,11 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_stx_zp_y_indexed_stores_x_leaves_x_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.x = 0x00 mpu.y = 0x03 - write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y + self._write(mpu.memory, 0x0000, (0x96, 0x10)) #=> STX $0010,Y mpu.memory[0x0010 + mpu.y] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4292,10 +4289,10 @@ def make_common_tests(MPU): # STY Absolute def test_sty_absolute_stores_y_leaves_y_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF - write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD + self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD mpu.memory[0xABCD] = 0x00 mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4304,10 +4301,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sty_absolute_stores_y_leaves_y_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 - write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD + self._write(mpu.memory, 0x0000, (0x8C, 0xCD, 0xAB)) #=> STY $ABCD mpu.memory[0xABCD] = 0xFF mpu.step() self.assertEquals(0x0003, mpu.pc) @@ -4318,10 +4315,10 @@ def make_common_tests(MPU): # STY Zero Page def test_sty_zp_stores_y_leaves_y_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF - write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 + self._write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 mpu.memory[0x0010] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4330,10 +4327,10 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sty_zp_stores_y_leaves_y_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 - write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 + self._write(mpu.memory, 0x0000, (0x84, 0x10)) #=> STY $0010 mpu.memory[0x0010] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4344,11 +4341,11 @@ def make_common_tests(MPU): # STY Zero Page, X-Indexed def test_sty_zp_x_indexed_stores_y_leaves_y_and_n_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.NEGATIVE) mpu.y = 0xFF mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X + self._write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X mpu.memory[0x0010 + mpu.x] = 0x00 mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4357,11 +4354,11 @@ def make_common_tests(MPU): self.assertEquals(flags, mpu.flags) def test_sty_zp_x_indexed_stores_y_leaves_y_and_z_flag_unchanged(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags = flags = 0xFF & ~(mpu.ZERO) mpu.y = 0x00 mpu.x = 0x03 - write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X + self._write(mpu.memory, 0x0000, (0x94, 0x10)) #=> STY $0010,X mpu.memory[0x0010 + mpu.x] = 0xFF mpu.step() self.assertEquals(0x0002, mpu.pc) @@ -4372,7 +4369,7 @@ def make_common_tests(MPU): # TAX def test_tax_transfers_accumulator_into_x(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAB mpu.x = 0x00 mpu.memory[0x0000] = 0xAA #=> TAX @@ -4382,7 +4379,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.x) def test_tax_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x80 mpu.x = 0x00 @@ -4394,7 +4391,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_tax_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.x = 0xFF @@ -4408,7 +4405,7 @@ def make_common_tests(MPU): # TAY def test_tay_transfers_accumulator_into_y(self): - mpu = MPU() + mpu = self._make_mpu() mpu.a = 0xAB mpu.y = 0x00 mpu.memory[0x0000] = 0xA8 #=> TAY @@ -4418,7 +4415,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.y) def test_tay_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.a = 0x80 mpu.y = 0x00 @@ -4430,7 +4427,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_tay_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.a = 0x00 mpu.y = 0xFF @@ -4444,7 +4441,7 @@ def make_common_tests(MPU): # TSX def test_tsx_transfers_stack_pointer_into_x(self): - mpu = MPU() + mpu = self._make_mpu() mpu.sp = 0xAB mpu.x = 0x00 mpu.memory[0x0000] = 0xBA #=> TSX @@ -4454,7 +4451,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.x) def test_tsx_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.sp = 0x80 mpu.x = 0x00 @@ -4466,7 +4463,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_tsx_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.sp = 0x00 mpu.y = 0xFF @@ -4480,7 +4477,7 @@ def make_common_tests(MPU): # TXA def test_txa_transfers_x_into_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xAB mpu.a = 0x00 mpu.memory[0x0000] = 0x8A #=> TXA @@ -4490,7 +4487,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.x) def test_txa_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.x = 0x80 mpu.a = 0x00 @@ -4502,7 +4499,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_txa_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.x = 0x00 mpu.a = 0xFF @@ -4516,7 +4513,7 @@ def make_common_tests(MPU): # TXS def test_txs_transfers_x_into_stack_pointer(self): - mpu = MPU() + mpu = self._make_mpu() mpu.x = 0xAB mpu.memory[0x0000] = 0x9A #=> TXS mpu.step() @@ -4525,7 +4522,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.x) def test_txs_does_not_set_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.x = 0x80 mpu.memory[0x0000] = 0x9A #=> TXS @@ -4536,7 +4533,7 @@ def make_common_tests(MPU): self.assertEquals(0, mpu.flags & mpu.NEGATIVE) def test_txs_does_not_set_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.x = 0x00 mpu.memory[0x0000] = 0x9A #=> TXS @@ -4549,7 +4546,7 @@ def make_common_tests(MPU): # TYA def test_tya_transfers_y_into_a(self): - mpu = MPU() + mpu = self._make_mpu() mpu.y = 0xAB mpu.a = 0x00 mpu.memory[0x0000] = 0x98 #=> TYA @@ -4559,7 +4556,7 @@ def make_common_tests(MPU): self.assertEquals(0xAB, mpu.y) def test_tya_sets_negative_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.NEGATIVE) mpu.y = 0x80 mpu.a = 0x00 @@ -4571,7 +4568,7 @@ def make_common_tests(MPU): self.assertEquals(mpu.NEGATIVE, mpu.flags & mpu.NEGATIVE) def test_tya_sets_zero_flag(self): - mpu = MPU() + mpu = self._make_mpu() mpu.flags &= ~(mpu.ZERO) mpu.y = 0x00 mpu.a = 0xFF @@ -4581,22 +4578,36 @@ def make_common_tests(MPU): self.assertEquals(0x00, mpu.y) self.assertEquals(mpu.ZERO, mpu.flags & mpu.ZERO) self.assertEquals(0x0001, mpu.pc) - return MPUTests - -MPUTests = make_common_tests(MPU) + # Test Helpers + + def _write(self, memory, start_address, bytes): + memory[start_address:start_address+len(bytes)] = bytes -class MPU6502SpecificTests(unittest.TestCase): + def _make_mpu(self, *args, **kargs): + klass = self._get_target_class() + return klass(*args, **kargs) + + def _get_target_class(self): + raise NotImplementedError, "Target class not specified" + + +class MPUTests(unittest.TestCase, Common6502Tests): + """ NMOS 6502 (py65.mpu6502) tests """ + def test_repr(self): - mpu = MPU() + mpu = self._make_mpu() self.assertEquals('<6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000>', repr(mpu)) def test_stz_not_supported(self): - mpu = MPU(debug=True) + mpu = self._make_mpu(debug=True) mpu.memory[0x0000] = 0x64 #=> stz (on 65c02) self.assertRaises(NotImplementedError, mpu.step) + def _get_target_class(self): + return py65.mpu6502.MPU + def test_suite(): return unittest.findTestCases(sys.modules[__name__]) diff --git a/src/py65/tests/test_mpu65c02.py b/src/py65/tests/test_mpu65c02.py index 49d14b2..d9decc7 100644 --- a/src/py65/tests/test_mpu65c02.py +++ b/src/py65/tests/test_mpu65c02.py @@ -1,20 +1,19 @@ import unittest import sys -from py65.mpu65c02 import MPU +import py65.mpu65c02 +from py65.tests.test_mpu6502 import Common6502Tests -from test_mpu6502 import make_common_tests -MPUTests = make_common_tests(MPU) - -class MPU65C02SpecificTests(unittest.TestCase): +class MPUTests(unittest.TestCase, Common6502Tests): + """CMOS 65C02 Tests""" def test_repr(self): - mpu = MPU() + mpu = self._make_mpu() self.assertEquals('<65C02: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000>', repr(mpu)) def test_stz_zp_stores_zero(self): - mpu = MPU(debug=True) + mpu = self._make_mpu(debug=True) mpu.memory[0x0032] = 0x88 mpu.memory[0x0000:0x0000+2] = [0x64, 0x32] #=> STZ $32 self.assertEquals(0x88, mpu.memory[0x0032]) @@ -22,6 +21,11 @@ class MPU65C02SpecificTests(unittest.TestCase): self.assertEquals(0x00, mpu.memory[0x0032]) self.assertEquals(3, mpu.processorCycles) + # Test Helpers + + def _get_target_class(self): + return py65.mpu65c02.MPU + def test_suite(): return unittest.findTestCases(sys.modules[__name__])