Exemplo n.º 1
0
class TestIncrementDecrementOperations(unittest.TestCase):
    def setUp(self):
        self.memory = Memory(use_bus=False)
        self.cpu = CPU(self.memory)

    def test_INC(self):
        self.memory.write_byte(None, 0x1000, 0x00)
        self.cpu.INC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0x01)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.memory.write_byte(None, 0x1000, 0x7F)
        self.cpu.INC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0x80)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.memory.write_byte(None, 0x1000, 0xFF)
        self.cpu.INC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)

    def test_INX(self):
        self.cpu.x_index = 0x00
        self.cpu.INX()
        self.assertEqual(self.cpu.x_index, 0x01)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.x_index = 0x7F
        self.cpu.INX()
        self.assertEqual(self.cpu.x_index, 0x80)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.x_index = 0xFF
        self.cpu.INX()
        self.assertEqual(self.cpu.x_index, 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)

    def test_INY(self):
        self.cpu.y_index = 0x00
        self.cpu.INY()
        self.assertEqual(self.cpu.y_index, 0x01)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.y_index = 0x7F
        self.cpu.INY()
        self.assertEqual(self.cpu.y_index, 0x80)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.y_index = 0xFF
        self.cpu.INY()
        self.assertEqual(self.cpu.y_index, 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)

    def test_DEC(self):
        self.memory.write_byte(None, 0x1000, 0x01)
        self.cpu.DEC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)
        self.memory.write_byte(None, 0x1000, 0x80)
        self.cpu.DEC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0x7F)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.memory.write_byte(None, 0x1000, 0x00)
        self.cpu.DEC(0x1000)
        self.assertEqual(self.memory.read_byte(None, 0x1000), 0xFF)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)

    def test_DEX(self):
        self.cpu.x_index = 0x01
        self.cpu.DEX()
        self.assertEqual(self.cpu.x_index, 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)
        self.cpu.x_index = 0x80
        self.cpu.DEX()
        self.assertEqual(self.cpu.x_index, 0x7F)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.x_index = 0x00
        self.cpu.DEX()
        self.assertEqual(self.cpu.x_index, 0xFF)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)

    def test_DEY(self):
        self.cpu.y_index = 0x01
        self.cpu.DEY()
        self.assertEqual(self.cpu.y_index, 0x00)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 1)
        self.cpu.y_index = 0x80
        self.cpu.DEY()
        self.assertEqual(self.cpu.y_index, 0x7F)
        self.assertEqual(self.cpu.sign_flag, 0)
        self.assertEqual(self.cpu.zero_flag, 0)
        self.cpu.y_index = 0x00
        self.cpu.DEY()
        self.assertEqual(self.cpu.y_index, 0xFF)
        self.assertEqual(self.cpu.sign_flag, 1)
        self.assertEqual(self.cpu.zero_flag, 0)