Exemplo n.º 1
0
class TestSystemFunctionOperations(unittest.TestCase):
    
    def setUp(self):
        self.memory = Memory()
        self.cpu = CPU(self.memory)
    
    def test_BRK(self):
        self.cpu.program_counter = 0x1000
        self.memory.rom.load(0xFFFE, [0x00, 0x20])
        status = self.cpu.status_as_byte()
        self.cpu.BRK()
        self.assertEqual(self.cpu.program_counter, 0x2000)
        self.assertEqual(self.cpu.break_flag, 1)
        self.assertEqual(self.memory.read_byte(self.cpu.STACK_PAGE + self.cpu.stack_pointer + 1), status)
        self.assertEqual(self.memory.read_byte(self.cpu.STACK_PAGE + self.cpu.stack_pointer + 2), 0x01)
        self.assertEqual(self.memory.read_byte(self.cpu.STACK_PAGE + self.cpu.stack_pointer + 3), 0x10)
    
    def test_RTI(self):
        self.memory.write_byte(self.cpu.STACK_PAGE + 0xFF, 0x12)
        self.memory.write_byte(self.cpu.STACK_PAGE + 0xFE, 0x33)
        self.memory.write_byte(self.cpu.STACK_PAGE + 0xFD, 0x20)
        self.cpu.stack_pointer = 0xFC
        self.cpu.RTI()
        self.assertEqual(self.cpu.program_counter, 0x1233)
        self.assertEqual(self.cpu.status_as_byte(), 0x20)
    
    def test_NOP(self):
        self.cpu.NOP()
Exemplo n.º 2
0
class TestStackOperations(unittest.TestCase):
    
    def setUp(self):
        self.memory = Memory()
        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)