# 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)


import logging
import sys
import unittest
from MC6809.tests.test_base import BaseCPUTestCase

    :created: 2014 by Jens Diemer - www.jensdiemer.de
    :copyleft: 2014-2015 by the MC6809 team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""





log = logging.getLogger("MC6809")


class Test6809_AddressModes_LowLevel(BaseCPUTestCase):
    def test_base_page_direct01(self):
        self.cpu.memory.load(0x1000, [0x12, 0x34, 0x0f])
        self.cpu.program_counter.set(0x1000)
        self.cpu.direct_page.set(0xab)

        ea = self.cpu.get_ea_direct()
        self.assertEqualHexWord(ea, 0xab12)

        ea = self.cpu.get_ea_direct()
        self.assertEqualHexWord(ea, 0xab34)

        self.cpu.direct_page.set(0x0)
        ea = self.cpu.get_ea_direct()
        self.assertEqualHexByte(ea, 0xf)



# 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/tests/test_6809_address_modes.py
import logging
import sys
import unittest
from MC6809.tests.test_base import BaseCPUTestCase


    :created: 2014 by Jens Diemer - www.jensdiemer.de
    :copyleft: 2014-2015 by the MC6809 team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""





log = logging.getLogger("MC6809")


class Test6809_AddressModes_LowLevel(BaseCPUTestCase):
    def test_base_page_direct01(self):
        self.cpu.memory.load(0x1000, [0x12, 0x34, 0x0f])
        self.cpu.program_counter.set(0x1000)
        self.cpu.direct_page.set(0xab)

        ea = self.cpu.get_ea_direct()
        self.assertEqualHexWord(ea, 0xab12)

        ea = self.cpu.get_ea_direct()
        self.assertEqualHexWord(ea, 0xab34)

        self.cpu.direct_page.set(0x0)
        ea = self.cpu.get_ea_direct()
        self.assertEqualHexByte(ea, 0xf)



class Test6809_AddressModes_Indexed(BaseCPUTestCase):