# 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)
# 
# class BaseStackTestCase(BaseCPUTestCase):
#     INITIAL_SYSTEM_STACK_ADDR = 0x1000
#     INITIAL_USER_STACK_ADDR = 0x2000
# 
#     def setUp(self):
#         super().setUp()
#         self.cpu.system_stack_pointer.set(self.INITIAL_SYSTEM_STACK_ADDR)
#         self.cpu.user_stack_pointer.set(self.INITIAL_USER_STACK_ADDR)


import logging
from MC6809.tests.test_base import BaseCPUTestCase, BaseStackTestCase
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0xFF,  # LDA $FF
            0x40,  # NEGA
        ])
        self.assertEqual(self.cpu.Z, 0)

    def test_ANDA(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0xF0,  # LDA $F0
            0x84, 0x0F,  # ANDA $0F
        ])
        self.assertEqual(self.cpu.Z, 1)

    def test_TFR(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0x04,  # LDA $04
            0x1F, 0x8a,  # TFR A,CCR
        ])
        self.assertEqual(self.cpu.Z, 1)

    def test_CLRA(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x4F,  # CLRA
        ])
        self.assertEqual(self.cpu.Z, 1)



# 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)
# 
# class BaseStackTestCase(BaseCPUTestCase):
#     INITIAL_SYSTEM_STACK_ADDR = 0x1000
#     INITIAL_USER_STACK_ADDR = 0x2000
# 
#     def setUp(self):
#         super().setUp()
#         self.cpu.system_stack_pointer.set(self.INITIAL_SYSTEM_STACK_ADDR)
#         self.cpu.user_stack_pointer.set(self.INITIAL_USER_STACK_ADDR)


# Path: MC6809/tests/test_cpu6809.py
import logging
from MC6809.tests.test_base import BaseCPUTestCase, BaseStackTestCase

        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0xFF,  # LDA $FF
            0x40,  # NEGA
        ])
        self.assertEqual(self.cpu.Z, 0)

    def test_ANDA(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0xF0,  # LDA $F0
            0x84, 0x0F,  # ANDA $0F
        ])
        self.assertEqual(self.cpu.Z, 1)

    def test_TFR(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x86, 0x04,  # LDA $04
            0x1F, 0x8a,  # TFR A,CCR
        ])
        self.assertEqual(self.cpu.Z, 1)

    def test_CLRA(self):
        self.assertEqual(self.cpu.Z, 0)
        self.cpu_test_run(start=0x4000, end=None, mem=[
            0x4F,  # CLRA
        ])
        self.assertEqual(self.cpu.Z, 1)



class Test6809_CC(BaseCPUTestCase):