コード例 #1
0
ファイル: executors.py プロジェクト: blackchip-org/mach8-py
def sub(cpu, oper, mode):
    """
    See :data:`~mach8.operations.SBC`, 
    """
    operand = _load_am(cpu, mode) 
    carry = 0 if cpu.c else 1
    if cpu.d: 
        b1 = vm.bcd_inverse(cpu.a) 
        b2 = vm.bcd_inverse(operand) 
        value = b1 - b2 - carry 
        cpu.c = not value < 0 
        if value < 0: 
            value += 100
        result = vm.bcd_forward(value) & vm.BITS8 
    else: 
        value = cpu.a - operand - carry 
        cpu.c = not value < 0 
        result = value & vm.BITS8 
    signed = vm.twos_inverse(cpu.a) - vm.twos_inverse(operand)
    cpu.v = signed > vm.SBYTE_MAX or signed < vm.SBYTE_MIN
    _flags(cpu, result)
    cpu.a = result 
コード例 #2
0
ファイル: executors.py プロジェクト: blackchip-org/mach8-py
def add(cpu, oper, mode):
    """
    See :data:`~mach8.operations.ADC`.
    """
    operand = _load_am(cpu, mode) 
    carry = 1 if cpu.c else 0 
    if cpu.d: 
        b1 = vm.bcd_inverse(cpu.a) 
        b2 = vm.bcd_inverse(operand) 
        bcd = b1 + b2 + carry 
        cpu.c = bcd > vm.DIGITS2
        if bcd > vm.DIGITS2: 
            bcd -= vm.DIGITS2 + 1
        result = vm.bcd_forward(bcd) & vm.BITS8
    else:
        value = cpu.a + operand + carry 
        cpu.c = value > vm.BITS8 
        result = value & vm.BITS8 
    signed = vm.twos_inverse(cpu.a) + vm.twos_inverse(operand)
    cpu.v = signed > vm.SBYTE_MAX or signed < vm.SBYTE_MIN
    _flags(cpu, result)
    cpu.a = result 
コード例 #3
0
ファイル: test_vm.py プロジェクト: blackchip-org/mach8-py
 def test_bcd_invalid(self):
     self.assertRaises(TypeError, vm.bcd_forward(0x0a))
コード例 #4
0
ファイル: test_vm.py プロジェクト: blackchip-org/mach8-py
 def test_bcd_forward(self):
     self.assertEquals(0x42, vm.bcd_forward(42))