本文整理汇总了Python中emulator.Emulator.dispatch方法的典型用法代码示例。如果您正苦于以下问题:Python Emulator.dispatch方法的具体用法?Python Emulator.dispatch怎么用?Python Emulator.dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emulator.Emulator
的用法示例。
在下文中一共展示了Emulator.dispatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInstructions
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import dispatch [as 别名]
class TestInstructions(unittest.TestCase):
def setUp(self):
self.cpu = CPU()
self.emulator = Emulator(self.cpu)
def test_add(self):
""" Sets REG.A to REG.A + REG.B """
self.cpu.registers[REG.A].value = 0x12
self.cpu.registers[REG.B].value = 0x34
# ADD A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.ADD,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0x46, "Add failed")
self.assertTrue(self.cpu.EX.value == 0x0, "Ex flag not reset")
def test_add_overflow(self):
""" Sets REG.A to REG.A + REG.B, overflows """
self.cpu.registers[REG.A].value = 0xffff
self.cpu.registers[REG.B].value = 0x0001
# ADD A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.ADD,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0x0000, "Add failed")
self.assertTrue(self.cpu.EX.value == 0xffff, "Ex flag not reset")
def test_sub(self):
""" Sets REG.A to REG.A - REG.B """
self.cpu.registers[REG.A].value = 0xffff
self.cpu.registers[REG.B].value = 0x0001
# SUB A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SUB,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0xfffe, "Sub failed")
self.assertTrue(self.cpu.EX.value == 0x0, "Ex flag not reset")
def test_sub_underflow(self):
""" Sets REG.A to REG.A - REG.B, underflows """
self.cpu.registers[REG.A].value = 0x0001
self.cpu.registers[REG.B].value = 0x0002
# SUB A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SUB,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0x0001, "Sub failed")
self.assertTrue(self.cpu.EX.value == 0xffff, "Ex flag not set")
def test_mul(self):
""" Sets REG.A to REG.A * REG.B """
self.cpu.registers[REG.A].value = 0x0002
self.cpu.registers[REG.B].value = 0x0003
# MUL A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.MUL,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0x6, "Mul failed")
self.assertTrue(self.cpu.EX.value == 0x0, "Ex flag not reset")
def test_mul_overflows(self):
""" Sets REG.A to REG.A * REG.B, overflows """
self.cpu.registers[REG.A].value = 0xffff
self.cpu.registers[REG.B].value = 0x0002
# MUL A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.MUL,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0xfffe, "Mul failed")
self.assertTrue(self.cpu.EX.value == 0x1, "Ex flag not set")
def test_mli(self):
""" Sets REG.A to REG.A * REG.B, treats A,B as signed """
self.cpu.registers[REG.A].value = -5
self.cpu.registers[REG.B].value = -4
# MLI A, B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.MLI,
a=Value.reg(REG.A),
b=Value.reg(REG.B))
self.emulator.dispatch()
#.........这里部分代码省略.........
示例2: TestValues
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import dispatch [as 别名]
class TestValues(unittest.TestCase):
def setUp(self):
self.cpu = CPU()
self.emulator = Emulator(self.cpu)
def test_set_reg_to_literal(self):
""" Sets a register to a literal """
# SET A, 0x10
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.reg(REG.A),
b=Value.literal(0x10))
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0x10, "Register value error")
def test_set_addr_of_reg(self):
""" Sets ram pointed by REG.I to value of REG.B """
# Arrange
self.cpu.registers[REG.I].value = 0xff
self.cpu.registers[REG.B].value = 0x11
# SET [I] B
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.addr_reg(REG.I),
b=Value.reg(REG.B))
self.emulator.dispatch()
self.assertTrue(self.cpu.ram[0xff].value == 0x11, "Ram not updated correctly")
def test_pop_into_reg(self):
""" Pops from stack into register """
self.cpu.ram[self.cpu.SP.value].value = 0xdead
# SET A POP
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.reg(REG.A),
b=Value.push_pop())
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0xdead, "Stack popping b0rked")
def test_push_from_register(self):
""" Pushed value in register to stack """
self.cpu.registers[REG.A].value = 0xdead
# SET PUSH, A
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.push_pop(),
b=Value.reg(REG.A))
self.emulator.dispatch()
self.assertTrue(self.cpu.ram[self.cpu.SP.value].value == 0xdead, "Stack pushing b0rked")
def test_peek_into_register(self):
""" Pushed value in register to stack """
self.cpu.ram[self.cpu.SP.value].value = 0xbeef
# SET A, PEEK
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.reg(REG.A),
b=Value.peek())
self.emulator.dispatch()
self.assertTrue(self.cpu.registers[REG.A].value == 0xbeef, "Stack peeking b0rked")
def test_set_sp(self):
""" Sets SP """
# SET SP, 0x02
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.sp(),
b=Value.literal(0x02))
self.emulator.dispatch()
self.assertTrue(self.cpu.SP.value == 0x2, "SP Loading failed")
def test_set_pc(self):
""" Sets PC """
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.pc(),
b=Value.literal(0x5))
self.emulator.dispatch()
self.assertEqual(self.cpu.PC.value, 0x5, "PC Loading failed")
def test_read_ex(self):
""" Reads O into register """
self.cpu.EX.value = 0xffff
# SET A, EX
self.cpu.ram[0].value = pack_instruction(op_code=OPCODE.SET,
a=Value.reg(REG.A),
b=Value.reg(REG.EX))
self.emulator.dispatch()
self.assertTrue(self.cpu.EX.value == 0xffff, "O Loading failed")
def test_next_word_register(self):
""" [Next word + register] into register """
#.........这里部分代码省略.........