Пример #1
0
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 
Пример #2
0
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 
Пример #3
0
 def test_bcd_inverse(self):
     self.assertEquals(42, vm.bcd_inverse(0x42))