# Path: MC6809/tests/test_base.py
# 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
import sys
import unittest
from MC6809.tests.test_base import BaseStackTestCase



log = logging.getLogger("MC6809")


class Test6809_Store(BaseStackTestCase):
    def test_STA_direct(self):
        self.cpu.direct_page.set(0x41)
        self.cpu.accu_a.set(0xad)
        self.cpu_test_run(start=0x4000, end=None, mem=[0x97, 0xfe])  # STA <$fe (Direct)
        self.assertEqualHex(self.cpu.memory.read_byte(0x41fe), 0xad)

    def test_STB_extended(self):
        self.cpu.accu_b.set(0x81)
        self.cpu_test_run(start=0x4000, end=None, mem=[0xF7, 0x50, 0x10])  # STB $5010 (Extended)
        self.assertEqualHex(self.cpu.memory.read_byte(0x5010), 0x81)

    def test_STD_extended(self):
        self.cpu.accu_d.set(0x4321)
        self.cpu_test_run(start=0x4000, end=None, mem=[0xFD, 0x50, 0x01])  # STD $5001 (Extended)
        self.assertEqualHex(self.cpu.memory.read_word(0x5001), 0x4321)

    def test_STS_indexed(self):
        self.cpu.system_stack_pointer.set(0x1234)
        self.cpu.index_x.set(0x0218)
        self.cpu_test_run(start=0x1b5c, end=None, mem=[0x10, 0xef, 0x83])  # STS ,R-- (indexed)
        self.assertEqualHex(self.cpu.memory.read_word(0x0216), 0x1234)  # 0x0218 -2 = 0x0216



# Path: MC6809/tests/test_base.py
# 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_6809_StoreLoad.py
import logging
import sys
import unittest
from MC6809.tests.test_base import BaseStackTestCase




log = logging.getLogger("MC6809")


class Test6809_Store(BaseStackTestCase):
    def test_STA_direct(self):
        self.cpu.direct_page.set(0x41)
        self.cpu.accu_a.set(0xad)
        self.cpu_test_run(start=0x4000, end=None, mem=[0x97, 0xfe])  # STA <$fe (Direct)
        self.assertEqualHex(self.cpu.memory.read_byte(0x41fe), 0xad)

    def test_STB_extended(self):
        self.cpu.accu_b.set(0x81)
        self.cpu_test_run(start=0x4000, end=None, mem=[0xF7, 0x50, 0x10])  # STB $5010 (Extended)
        self.assertEqualHex(self.cpu.memory.read_byte(0x5010), 0x81)

    def test_STD_extended(self):
        self.cpu.accu_d.set(0x4321)
        self.cpu_test_run(start=0x4000, end=None, mem=[0xFD, 0x50, 0x01])  # STD $5001 (Extended)
        self.assertEqualHex(self.cpu.memory.read_word(0x5001), 0x4321)

    def test_STS_indexed(self):
        self.cpu.system_stack_pointer.set(0x1234)
        self.cpu.index_x.set(0x0218)
        self.cpu_test_run(start=0x1b5c, end=None, mem=[0x10, 0xef, 0x83])  # STS ,R-- (indexed)
        self.assertEqualHex(self.cpu.memory.read_word(0x0216), 0x1234)  # 0x0218 -2 = 0x0216



class Test6809_Load(BaseStackTestCase):