# Path: MC6809/components/cpu_utils/instruction_caller.py
# def opcode(*opcodes):
#     """A decorator for opcodes"""
#     def decorator(func):
#         setattr(func, "_is_opcode", True)
#         setattr(func, "_opcodes", opcodes)
#         return func
#     return decorator
# 
# Path: MC6809/utils/bits.py
# def get_bit(value, bit):
#     """
#     return 1 or 0 from the bit at the given offset >bit<, e.g.:
# 
#     >>> get_bit(0x01, bit=0) # 00000001
#     1
#     >>> get_bit(0xfd, bit=1) # 11111101
#     0
#     >>> get_bit(int('10000000', 2), bit=7)
#     1
#     >>> get_bit(int('01111111', 2), bit=7)
#     0
#     >>> get_bit(int('1111000011110000', 2), bit=11)
#     0
#     >>> get_bit(int('1111000011110000', 2), bit=12)
#     1
#     """
#     return 0 if value & 2 ** bit == 0 else 1


from MC6809.components.cpu_utils.instruction_caller import opcode
from MC6809.utils.bits import get_bit
    @opcode(0x49, 0x59)  # ROLA / ROLB (inherent)
    def instruction_ROL_register(self, opcode, register):
        """ Rotate accumulator left """
        a = register.value
        r = self.ROL(a)
#        log.debug("$%x ROL %s value $%x << 1 | Carry = $%x" % (
#            self.program_counter,
#            register.name, a, r
#        ))
        register.set(r)

    def ROR(self, a):
        """
        Rotates all bits of the register one place right through the C (carry)
        bit. This is a 9-bit rotation.

        moved the carry flag into bit 8
        moved bit 7 into carry flag

        source code forms: ROR Q; RORA; RORB

        CC bits "HNZVC": -aa-s
        """
        r = (a >> 1) | (self.C << 7)
        self.clear_NZ()
        self.update_NZ_8(r)
        self.C = get_bit(a, bit=0)  # same as: self.C = (a & 1)
        return r

    @opcode(0x6, 0x66, 0x76)  # ROR (direct, indexed, extended)

# Path: MC6809/components/cpu_utils/instruction_caller.py
# def opcode(*opcodes):
#     """A decorator for opcodes"""
#     def decorator(func):
#         setattr(func, "_is_opcode", True)
#         setattr(func, "_opcodes", opcodes)
#         return func
#     return decorator
# 
# Path: MC6809/utils/bits.py
# def get_bit(value, bit):
#     """
#     return 1 or 0 from the bit at the given offset >bit<, e.g.:
# 
#     >>> get_bit(0x01, bit=0) # 00000001
#     1
#     >>> get_bit(0xfd, bit=1) # 11111101
#     0
#     >>> get_bit(int('10000000', 2), bit=7)
#     1
#     >>> get_bit(int('01111111', 2), bit=7)
#     0
#     >>> get_bit(int('1111000011110000', 2), bit=11)
#     0
#     >>> get_bit(int('1111000011110000', 2), bit=12)
#     1
#     """
#     return 0 if value & 2 ** bit == 0 else 1


# Path: MC6809/components/mc6809_ops_logic.py
from MC6809.components.cpu_utils.instruction_caller import opcode
from MC6809.utils.bits import get_bit

    @opcode(0x49, 0x59)  # ROLA / ROLB (inherent)
    def instruction_ROL_register(self, opcode, register):
        """ Rotate accumulator left """
        a = register.value
        r = self.ROL(a)
#        log.debug("$%x ROL %s value $%x << 1 | Carry = $%x" % (
#            self.program_counter,
#            register.name, a, r
#        ))
        register.set(r)

    def ROR(self, a):
        """
        Rotates all bits of the register one place right through the C (carry)
        bit. This is a 9-bit rotation.

        moved the carry flag into bit 8
        moved bit 7 into carry flag

        source code forms: ROR Q; RORA; RORB

        CC bits "HNZVC": -aa-s
        """
        r = (a >> 1) | (self.C << 7)
        self.clear_NZ()
        self.update_NZ_8(r)
        self.C = get_bit(a, bit=0)  # same as: self.C = (a & 1)
        return r

    @opcode(0x6, 0x66, 0x76)  # ROR (direct, indexed, extended)

    def instruction_ROR_memory(self, opcode, ea, m):