class TestStackOperations(unittest.TestCase): def setUp(self): self.memory = Memory(use_bus=False) self.cpu = CPU(self.memory) def test_TSX(self): s = self.cpu.stack_pointer self.cpu.TSX() self.assertEqual(self.cpu.x_index, s) # @@@ check NZ? def test_TXS(self): x = self.cpu.x_index self.cpu.TXS() self.assertEqual(self.cpu.stack_pointer, x) def test_PHA_and_PLA(self): self.cpu.accumulator = 0x00 self.cpu.PHA() self.cpu.accumulator = 0x01 self.cpu.PHA() self.cpu.accumulator = 0xFF self.cpu.PHA() self.assertEqual(self.cpu.accumulator, 0xFF) self.assertEqual(self.cpu.zero_flag, 0) self.assertEqual(self.cpu.sign_flag, 0) self.cpu.PLA() self.assertEqual(self.cpu.accumulator, 0xFF) self.assertEqual(self.cpu.zero_flag, 0) self.assertEqual(self.cpu.sign_flag, 1) self.cpu.PLA() self.assertEqual(self.cpu.accumulator, 0x01) self.assertEqual(self.cpu.zero_flag, 0) self.assertEqual(self.cpu.sign_flag, 0) self.cpu.PLA() self.assertEqual(self.cpu.accumulator, 0x00) self.assertEqual(self.cpu.zero_flag, 1) self.assertEqual(self.cpu.sign_flag, 0) def test_PHP_and_PLP(self): p = self.cpu.status_as_byte() self.cpu.PHP() self.cpu.status_from_byte(0xFF) self.cpu.PLP() self.assertEqual(self.cpu.status_as_byte(), p)