# Path: MC6809/tests/test_base.py
# class BaseCPUTestCase(BaseTestCase):
#     UNITTEST_CFG_DICT = {
#         "verbosity": None,
#         "display_cycle": False,
#         "trace": None,
#         "bus_socket_host": None,
#         "bus_socket_port": None,
#         "ram": None,
#         "rom": None,
#         "max_ops": None,
#         "use_bus": False,
#     }
# 
#     def setUp(self):
#         cfg = TestCfg(self.UNITTEST_CFG_DICT)
#         memory = Memory(cfg)
#         self.cpu = CPU(memory, cfg)
# 
#     def cpu_test_run(self, start, end, mem):
#         for cell in mem:
#             self.assertLess(-1, cell, f"${cell:x} < 0")
#             self.assertGreater(0x100, cell, f"${cell:x} > 0xff")
#         log.debug("memory load at $%x: %s", start,
#                   ", ".join("$%x" % i for i in mem)
#                   )
#         self.cpu.memory.load(start, mem)
#         if end is None:
#             end = start + len(mem)
#         self.cpu.test_run(start, end)
#     cpu_test_run.__test__ = False  # Exclude from nose
# 
#     def cpu_test_run2(self, start, count, mem):
#         for cell in mem:
#             self.assertLess(-1, cell, f"${cell:x} < 0")
#             self.assertGreater(0x100, cell, f"${cell:x} > 0xff")
#         self.cpu.memory.load(start, mem)
#         self.cpu.test_run2(start, count)
#     cpu_test_run2.__test__ = False  # Exclude from nose
# 
#     def assertMemory(self, start, mem):
#         for index, should_byte in enumerate(mem):
#             address = start + index
#             is_byte = self.cpu.memory.read_byte(address)
# 
#             msg = f"${is_byte:02x} is not ${should_byte:02x} at address ${address:04x} (index: {index:d})"
#             self.assertEqual(is_byte, should_byte, msg)
# 
# 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
# 
# def is_bit_set(value, bit):
#     """
#     Return True/False if the bit at offset >bit< is 1 or 0 in given value.
# 
#     bit 7 |      | bit 0
#        ...10111101
# 
#     e.g.:
# 
#     >>> is_bit_set(0x01, bit=0) # 00000001
#     True
#     >>> is_bit_set(0xfd, bit=1) # 11111101
#     False
#     >>> is_bit_set(int('10000000', 2), bit=7)
#     True
#     >>> is_bit_set(int('01111111', 2), bit=7)
#     False
#     >>> is_bit_set(int('1111000011110000', 2), bit=11)
#     False
#     >>> is_bit_set(int('1111000011110000', 2), bit=12)
#     True
#     """
#     return False if value & 2 ** bit == 0 else True


import logging
import sys
import unittest
from MC6809.tests.test_base import BaseCPUTestCase
from MC6809.utils.bits import get_bit, is_bit_set
                excpeted_bits = f"1{src_bit_str[:-1]}"
            else:
                excpeted_bits = f"0{src_bit_str[:-1]}"

            # test ASRB/LSRB result
            self.assertEqual(dst_bit_str, excpeted_bits)

            # test negative
            if 128 <= dst <= 255:
                self.assertEqual(self.cpu.N, 1)
            else:
                self.assertEqual(self.cpu.N, 0)

            # test zero
            if dst == 0:
                self.assertEqual(self.cpu.Z, 1)
            else:
                self.assertEqual(self.cpu.Z, 0)

            # test overflow (is uneffected!)
            self.assertEqual(self.cpu.V, 0)

            # test carry
            source_bit0 = is_bit_set(src, bit=0)
            if source_bit0:
                self.assertEqual(self.cpu.C, 1)
            else:
                self.assertEqual(self.cpu.C, 0)



# Path: MC6809/tests/test_base.py
# class BaseCPUTestCase(BaseTestCase):
#     UNITTEST_CFG_DICT = {
#         "verbosity": None,
#         "display_cycle": False,
#         "trace": None,
#         "bus_socket_host": None,
#         "bus_socket_port": None,
#         "ram": None,
#         "rom": None,
#         "max_ops": None,
#         "use_bus": False,
#     }
# 
#     def setUp(self):
#         cfg = TestCfg(self.UNITTEST_CFG_DICT)
#         memory = Memory(cfg)
#         self.cpu = CPU(memory, cfg)
# 
#     def cpu_test_run(self, start, end, mem):
#         for cell in mem:
#             self.assertLess(-1, cell, f"${cell:x} < 0")
#             self.assertGreater(0x100, cell, f"${cell:x} > 0xff")
#         log.debug("memory load at $%x: %s", start,
#                   ", ".join("$%x" % i for i in mem)
#                   )
#         self.cpu.memory.load(start, mem)
#         if end is None:
#             end = start + len(mem)
#         self.cpu.test_run(start, end)
#     cpu_test_run.__test__ = False  # Exclude from nose
# 
#     def cpu_test_run2(self, start, count, mem):
#         for cell in mem:
#             self.assertLess(-1, cell, f"${cell:x} < 0")
#             self.assertGreater(0x100, cell, f"${cell:x} > 0xff")
#         self.cpu.memory.load(start, mem)
#         self.cpu.test_run2(start, count)
#     cpu_test_run2.__test__ = False  # Exclude from nose
# 
#     def assertMemory(self, start, mem):
#         for index, should_byte in enumerate(mem):
#             address = start + index
#             is_byte = self.cpu.memory.read_byte(address)
# 
#             msg = f"${is_byte:02x} is not ${should_byte:02x} at address ${address:04x} (index: {index:d})"
#             self.assertEqual(is_byte, should_byte, msg)
# 
# 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
# 
# def is_bit_set(value, bit):
#     """
#     Return True/False if the bit at offset >bit< is 1 or 0 in given value.
# 
#     bit 7 |      | bit 0
#        ...10111101
# 
#     e.g.:
# 
#     >>> is_bit_set(0x01, bit=0) # 00000001
#     True
#     >>> is_bit_set(0xfd, bit=1) # 11111101
#     False
#     >>> is_bit_set(int('10000000', 2), bit=7)
#     True
#     >>> is_bit_set(int('01111111', 2), bit=7)
#     False
#     >>> is_bit_set(int('1111000011110000', 2), bit=11)
#     False
#     >>> is_bit_set(int('1111000011110000', 2), bit=12)
#     True
#     """
#     return False if value & 2 ** bit == 0 else True


# Path: MC6809/tests/test_6809_arithmetic_shift.py
import logging
import sys
import unittest
from MC6809.tests.test_base import BaseCPUTestCase
from MC6809.utils.bits import get_bit, is_bit_set

                excpeted_bits = f"1{src_bit_str[:-1]}"
            else:
                excpeted_bits = f"0{src_bit_str[:-1]}"

            # test ASRB/LSRB result
            self.assertEqual(dst_bit_str, excpeted_bits)

            # test negative
            if 128 <= dst <= 255:
                self.assertEqual(self.cpu.N, 1)
            else:
                self.assertEqual(self.cpu.N, 0)

            # test zero
            if dst == 0:
                self.assertEqual(self.cpu.Z, 1)
            else:
                self.assertEqual(self.cpu.Z, 0)

            # test overflow (is uneffected!)
            self.assertEqual(self.cpu.V, 0)

            # test carry
            source_bit0 = is_bit_set(src, bit=0)
            if source_bit0:
                self.assertEqual(self.cpu.C, 1)
            else:
                self.assertEqual(self.cpu.C, 0)



class Test6809_Rotate(BaseCPUTestCase):