当前位置: 首页>>代码示例>>Python>>正文


Python OpCode.execute方法代码示例

本文整理汇总了Python中emupy6502.opcodes.OpCode.execute方法的典型用法代码示例。如果您正苦于以下问题:Python OpCode.execute方法的具体用法?Python OpCode.execute怎么用?Python OpCode.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emupy6502.opcodes.OpCode的用法示例。


在下文中一共展示了OpCode.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def run(self, cycles):

        while cycles > 0:
            opcode = self.memory_controller.read(self.pc)
            self.registers.pc += 1            
            cycle_count = OpCode.execute(opcode, self.registers, self.memory_controller)
            cycles = cycles - cycle_count
开发者ID:crispg72,项目名称:6502py,代码行数:9,代码来源:cpu6502.py

示例2: Cpu6502

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
class Cpu6502(object):

    def __init__(self, memory_controller = None):

        self.registers = Registers()

        self.memory_controller = memory_controller
        self.opcodes = OpCode()
	
    def run(self, cycles):

        while cycles > 0:
            opcode = self.memory_controller.read(self.pc)
            self.registers.pc += 1            
            cycle_count = OpCode.execute(opcode, self.registers, self.memory_controller)
            cycles = cycles - cycle_count

    def run_until_signalled(self, signal):

        memory_controller = self.memory_controller
        self.total_cycles = 0
        while not signal():
            opcode = memory_controller.read(self.registers.pc)
            self.registers.pc += 1
            self.total_cycles += self.opcodes.execute(opcode, self.registers, self.memory_controller)

        return self.total_cycles
开发者ID:crispg72,项目名称:6502py,代码行数:29,代码来源:cpu6502.py

示例3: test_execute_asl_accumulator_negative

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_asl_accumulator_negative(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = -3

        mock_memory_controller = Mock()

        # we're mocking 0x0A 0x21 
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x0A, registers, mock_memory_controller)
        self.assertEqual(count, 2)
        mock_memory_controller.read.assert_not_called()
        self.assertEqual(registers.pc, 1)
        self.assertEqual(registers.accumulator, 0xfa)
        self.assertFalse(registers.zero_flag)
        self.assertTrue(registers.carry_flag)
        self.assertTrue(registers.negative_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_bitshift_opcodes.py

示例4: test_execute_asl_zeropage

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_asl_zeropage(self):

        opcode = OpCode()
        registers = Registers()
        mock_memory_controller = Mock()

        # we're mocking 0x06 0x30
        mock_memory_controller.read.side_effect = [0x30, 0x20]
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x06, registers, mock_memory_controller)
        self.assertEqual(count, 5)
        self.assertEqual(mock_memory_controller.read.call_count, 2)
        self.assertEqual(mock_memory_controller.read.call_args_list[0], unittest.mock.call(1))
        mock_memory_controller.write.assert_called_with(0x30, 0x40)
        self.assertEqual(registers.pc, 2)
        self.assertFalse(registers.zero_flag)
        self.assertFalse(registers.carry_flag)
        self.assertFalse(registers.negative_flag)        
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_bitshift_opcodes.py

示例5: test_execute_sbc_immediate_borrow_in_no_borrow_out_overflow_positive_result

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_sbc_immediate_borrow_in_no_borrow_out_overflow_positive_result(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 0xd0 #start with negative acc this time

        with patch.object(MemoryController, 'read') as mock_memory_controller:

            # Mocking 0xE9 0x70 so subtracting 0xd0 - 0x70 (-48 - 112 = 96 (overflow))
            mock_memory_controller.read.return_value = 0x70
            registers.pc += 1 #need to fake the cpu reading the opcode
            count = opcode.execute(0xE9, registers, mock_memory_controller)
            self.assertEqual(count, 2)
            self.assertEqual(registers.accumulator, 0x5f)
            self.assertFalse(registers.zero_flag)
            self.assertFalse(registers.negative_flag)
            self.assertTrue(registers.carry_flag)
            self.assertTrue(registers.overflow_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_arithmetic_opcodes.py

示例6: execute_adc_should_set_carry

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def execute_adc_should_set_carry(self, actual_opcode, expected_clocks):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 1
        registers.zero_flag = False
        registers.negative_flag = True    

        with patch.object(MemoryController, 'read') as mock_memory_controller:

            mock_memory_controller.read.return_value = 0xff
            registers.pc += 1 #need to fake the cpu reading the opcode
            count = opcode.execute(actual_opcode, registers, mock_memory_controller)
            self.assertEqual(count, expected_clocks)
            self.assertTrue(registers.accumulator == 0)
            self.assertTrue(registers.zero_flag)
            self.assertFalse(registers.negative_flag)
            self.assertTrue(registers.carry_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_arithmetic_opcodes.py

示例7: test_execute_rol_absolute_carry_clear_sign_clear

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_rol_absolute_carry_clear_sign_clear(self):

        opcode = OpCode()
        registers = Registers()

        mock_memory_controller = Mock()
        mock_memory_controller.read.side_effect = [0x00, 0x30, 3]

        # we're mocking 0x2E 0x30 and [0x3000] = 3
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x2E, registers, mock_memory_controller)
        self.assertEqual(count, 6)
        self.assertEqual(mock_memory_controller.read.call_count, 3)
        mock_memory_controller.write.assert_called_with(0x3000, 6)
        self.assertEqual(registers.pc, 3)
        self.assertFalse(registers.zero_flag)
        self.assertFalse(registers.carry_flag)
        self.assertFalse(registers.negative_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_bitshift_opcodes.py

示例8: test_execute_rol_zeropage_carry_clear_sign_set

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_rol_zeropage_carry_clear_sign_set(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 0xc0

        mock_memory_controller = Mock()
        mock_memory_controller.read.side_effect = [0x30, 0xc0]

        # we're mocking 0x26 0x30 and [0x30] = 0xc0
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x26, registers, mock_memory_controller)
        self.assertEqual(count, 5)
        mock_memory_controller.write.assert_called_with(0x30, 0x80)
        self.assertEqual(registers.pc, 2)
        self.assertFalse(registers.zero_flag)
        self.assertTrue(registers.carry_flag)
        self.assertTrue(registers.negative_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:20,代码来源:test_bitshift_opcodes.py

示例9: test_execute_rol_accumulator_carry_set_sign_clear

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_rol_accumulator_carry_set_sign_clear(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 3
        registers.carry_flag = True

        mock_memory_controller = Mock()

        # we're mocking 0x2A
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x2A, registers, mock_memory_controller)
        self.assertEqual(count, 2)
        mock_memory_controller.read.assert_not_called()
        self.assertEqual(registers.pc, 1)
        self.assertEqual(registers.accumulator, 7)
        self.assertFalse(registers.zero_flag)
        self.assertFalse(registers.carry_flag)
        self.assertFalse(registers.negative_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:21,代码来源:test_bitshift_opcodes.py

示例10: test_execute_sbc_immediate_no_borrow_in_borrow_out_overflow_negative_result

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_sbc_immediate_no_borrow_in_borrow_out_overflow_negative_result(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 0x50
        registers.carry_flag = True

        with patch.object(MemoryController, 'read') as mock_memory_controller:

            # Mocking 0xE9 0xb0 so subtracting 0x50 - 0xb0 (80 - -80)
            mock_memory_controller.read.return_value = 0xb0
            registers.pc += 1 #need to fake the cpu reading the opcode
            count = opcode.execute(0xE9, registers, mock_memory_controller)
            self.assertEqual(count, 2)
            self.assertTrue(registers.accumulator == 0xa0)
            self.assertFalse(registers.zero_flag)
            self.assertTrue(registers.negative_flag)
            self.assertFalse(registers.carry_flag)
            self.assertTrue(registers.overflow_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:21,代码来源:test_arithmetic_opcodes.py

示例11: execute_sbc_borrow_in_borrow_out_no_overflow_positive_result

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def execute_sbc_borrow_in_borrow_out_no_overflow_positive_result(self, actual_opcode, expected_clocks, mock_memory_controller, **kwargs):

        opcode = OpCode()
        registers = Registers()
        setattr(registers,'accumulator',0x50)

        if kwargs:
            for arg in kwargs:
                setattr(registers, arg, kwargs[arg])

        # Mocking 0x150 - 0xf0 (borrow 'in')
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(actual_opcode, registers, mock_memory_controller)
        self.assertEqual(count, expected_clocks)
        self.assertEqual(registers.accumulator, 0x5f)
        self.assertFalse(registers.zero_flag)
        self.assertFalse(registers.negative_flag)
        self.assertFalse(registers.carry_flag)
        self.assertFalse(registers.overflow_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:21,代码来源:test_arithmetic_opcodes.py

示例12: test_execute_adc_absolute

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_adc_absolute(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 5
        registers.zero_flag = True
        registers.negative_flag = True  

        with patch.object(MemoryController, 'read') as mock_memory_controller:

            # we're mocking 0xb5 0x21 0x22 and value at [0x2221] = 1
            mock_memory_controller.read.side_effect = [0x21, 0x22, 1]

            registers.pc += 1 #need to fake the cpu reading the opcode
            count = opcode.execute(0x6D, registers, mock_memory_controller)
            self.assertEqual(count, 4)
            self.assertTrue(registers.accumulator == 6)
            self.assertFalse(registers.zero_flag)
            self.assertFalse(registers.negative_flag)
            self.assertFalse(registers.carry_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:22,代码来源:test_arithmetic_opcodes.py

示例13: test_execute_asl_absolute_x

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_asl_absolute_x(self):

        opcode = OpCode()
        registers = Registers()
        registers.x_index = 3

        mock_memory_controller = Mock()

        # we're mocking 0x1E 0x2100 so write is to [0x2103]
        mock_memory_controller.read.side_effect = [0, 0x21, 0xfe]
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x1E, registers, mock_memory_controller)
        self.assertEqual(count, 7)

        # these are checked more thoroughly in addressing_modes_tests
        self.assertEqual(mock_memory_controller.read.call_count, 3)
        mock_memory_controller.write.assert_called_with(0x2103, 0xfc)
        self.assertEqual(registers.pc, 3)
        self.assertFalse(registers.zero_flag)
        self.assertTrue(registers.carry_flag)
        self.assertTrue(registers.negative_flag)        
开发者ID:crispg72,项目名称:6502py,代码行数:23,代码来源:test_bitshift_opcodes.py

示例14: test_execute_adc_indirect_indexed_y_page_boundary

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_adc_indirect_indexed_y_page_boundary(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 5
        registers.y_index = 3
        registers.zero_flag = True
        registers.negative_flag = True  

        with patch.object(MemoryController, 'read') as mock_memory_controller:

            # we're mocking 0x71 0x2a  memory at 0x2a = [0x28, 0x40], [0x4101] = 3
            mock_memory_controller.read.side_effect = [0x2a, 0xfe, 0x40, 3]

            registers.pc += 1 #need to fake the cpu reading the opcode
            count = opcode.execute(0x71, registers, mock_memory_controller)
            self.assertEqual(count, 6)
            self.assertEqual(mock_memory_controller.read.call_count, 4)
            self.assertTrue(registers.accumulator == 8)
            self.assertFalse(registers.zero_flag)
            self.assertFalse(registers.negative_flag)
            self.assertFalse(registers.carry_flag)
开发者ID:crispg72,项目名称:6502py,代码行数:24,代码来源:test_arithmetic_opcodes.py

示例15: test_execute_asl_absolute

# 需要导入模块: from emupy6502.opcodes import OpCode [as 别名]
# 或者: from emupy6502.opcodes.OpCode import execute [as 别名]
    def test_execute_asl_absolute(self):

        opcode = OpCode()
        registers = Registers()
        registers.accumulator = 0x20

        mock_memory_controller = Mock()

        # we're mocking 0x0E 0x0 0x20 so store to [0x2000]
        mock_memory_controller.read.side_effect = [0, 0x20, 0x21]
        registers.pc += 1 #need to fake the cpu reading the opcode
        count = opcode.execute(0x0E, registers, mock_memory_controller)
        self.assertEqual(count, 6)

        # these are checked more thoroughly in addressing_modes_tests
        self.assertEqual(mock_memory_controller.read.call_count, 3)
        self.assertEqual(mock_memory_controller.read.call_args_list[0], unittest.mock.call(1))
        mock_memory_controller.write.assert_called_with(0x2000, 0x42)
        self.assertEqual(registers.pc, 3)
        self.assertFalse(registers.zero_flag)
        self.assertFalse(registers.carry_flag)
        self.assertFalse(registers.negative_flag)        
开发者ID:crispg72,项目名称:6502py,代码行数:24,代码来源:test_bitshift_opcodes.py


注:本文中的emupy6502.opcodes.OpCode.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。