# Path: dragonpy/core/machine.py
# class MachineGUI:
#     def __init__(self, cfg):
#         self.cfg = cfg
# 
#         # Queue to send keyboard inputs from GUI to CPU Thread:
#         self.user_input_queue = queue.Queue()
# 
#     def run(self, PeripheryClass, GUI_Class):
#         log.log(99, "Startup '%s' machine...", self.cfg.MACHINE_NAME)
# 
#         log.critical("init GUI")
#         # e.g. TkInter GUI
#         gui = GUI_Class(
#             self.cfg,
#             self.user_input_queue
#         )
# 
#         log.critical("init machine")
#         # start CPU+Memory+Periphery in a separate thread
#         machine = Machine(
#             self.cfg,
#             PeripheryClass,
#             gui.display_callback,
#             self.user_input_queue
#         )
# 
#         try:
#             gui.mainloop(machine)
#         except Exception as err:
#             log.critical("GUI exception: %s", err)
#             print_exc_plus()
#         machine.quit()
# 
#         log.log(99, " --- END ---")
# 
# Path: dragonpy/sbc09/config.py
# class SBC09Cfg(BaseConfig):
#     """
#     DragonPy config for Lennart's 6809 single board computer
# 
#         Buggy machine language monitor and rudimentary O.S. version 1.0
# 
#     More info read ./sbc09/README.creole
#     """
# 
#     CONFIG_NAME = constants.SBC09
#     MACHINE_NAME = "Lennart's 6809 single board computer"
# 
#     RAM_START = 0x0000
#     RAM_END = 0x7FFF
#     # RAM size: 0x8000 == 32768 Bytes
# 
#     ROM_START = 0x8000
#     ROM_END = 0xFFFF
#     # ROM size: 0x4000 == 16384 Bytes
# 
#     BUS_ADDR_AREAS = (
#         (0xe000, 0xe001, "RS232 interface"),  # emulated serial port (ACIA)
#         (0xFFF2, 0xFFFE, "Interrupt vectors"),
#     )
# 
#     DEFAULT_ROMS = (
#         SBC09Rom(address=0x8000, max_size=None),
#     )
# 
#     # Used in unittest for init the machine:
#     STARTUP_END_ADDR = 0xe45a  # == O.S. routine to read a character into B register.
# 
#     def __init__(self, cmd_args):
#         super().__init__(cmd_args)
# 
#         self.machine_api = CoCoAPI()  # FIXME!
# 
# #         if self.verbosity <= logging.INFO:
#         self.mem_info = get_sbc09_meminfo()
# 
#         self.periphery_class = SBC09Periphery
# 
# Path: dragonpy/sbc09/gui.py
# class SBC09TkinterGUI(ScrolledTextGUI):
#     pass
# 
# Path: dragonpy/sbc09/periphery.py
# class SBC09Periphery:
#     TITLE = "DragonPy - Buggy machine language monitor and rudimentary O.S. version 1.0"
#     INITAL_INPUT = (
#         #        # Dump registers
#         #        'r\r\n'
#         #
#         #        # SSaddr,len - Dump memory region as Motorola S records.
#         #        'ss\r\n'
#         #
#         #        # Daddr,len - Dump memory region
#         #        'DE5E2\r\n'
#         #
#         #        # Iaddr - Display the contents of the given address.
#         #        'IE001\r\n' # e.g.: Show the ACIA status
#         #
#         #        # Uaddr,len - Diassemble memory region
#         #        'UE400\r\n'
#         #
#         #        # Calculate simple expression in hex with + and -
#         #        'H4444+A5\r\n'
# 
#         #
#         #         "UE400,20\r\n"
#         #         "ubasic\r\n"
#     )
# 
#     def __init__(self, cfg, cpu, memory, display_callback, user_input_queue):
#         self.cfg = cfg
#         self.cpu = cpu
#         self.memory = memory
#         self.display_callback = display_callback
#         self.user_input_queue = user_input_queue
# 
#         self.memory.add_read_byte_callback(self.read_acia_status, 0xe000)  # Control/status port of ACIA
#         self.memory.add_read_byte_callback(self.read_acia_data, 0xe001)  # Data port of ACIA
# 
#         self.memory.add_write_byte_callback(self.write_acia_status, 0xe000)  # Control/status port of ACIA
#         self.memory.add_write_byte_callback(self.write_acia_data, 0xe001)  # Data port of ACIA
# 
#     def write_acia_status(self, cpu_cycles, op_address, address, value):
#         return 0xff
# 
#     def read_acia_status(self, cpu_cycles, op_address, address):
#         return 0x03
# 
#     def read_acia_data(self, cpu_cycles, op_address, address):
#         try:
#             char = self.user_input_queue.get(block=False)
#         except queue.Empty:
#             return 0x0
# 
#         value = ord(char)
#         log.error("%04x| (%i) read from ACIA-data, send back %r $%x",
#                   op_address, cpu_cycles, char, value
#                   )
#         return value
# 
#     def write_acia_data(self, cpu_cycles, op_address, address, value):
#         char = chr(value)
#         log.debug("Write to screen: %s ($%x)", repr(char), value)
# #        log.error("*"*79)
# #        log.error("Write to screen: %s ($%x)" , repr(char), value)
# #        log.error("*"*79)
# 
#         self.display_callback(char)


import logging
from dragonpy.core.machine import MachineGUI
from dragonpy.sbc09.config import SBC09Cfg
from dragonpy.sbc09.gui import SBC09TkinterGUI
from dragonpy.sbc09.periphery import SBC09Periphery
#!/usr/bin/env python

"""
    Multicomp 6809
    ~~~~~~~~~~~~~~

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




log = logging.getLogger(__name__)


def run_sbc09(cfg_dict):
    machine = MachineGUI(
        cfg=SBC09Cfg(cfg_dict)
    )
    machine.run(

# Path: dragonpy/core/machine.py
# class MachineGUI:
#     def __init__(self, cfg):
#         self.cfg = cfg
# 
#         # Queue to send keyboard inputs from GUI to CPU Thread:
#         self.user_input_queue = queue.Queue()
# 
#     def run(self, PeripheryClass, GUI_Class):
#         log.log(99, "Startup '%s' machine...", self.cfg.MACHINE_NAME)
# 
#         log.critical("init GUI")
#         # e.g. TkInter GUI
#         gui = GUI_Class(
#             self.cfg,
#             self.user_input_queue
#         )
# 
#         log.critical("init machine")
#         # start CPU+Memory+Periphery in a separate thread
#         machine = Machine(
#             self.cfg,
#             PeripheryClass,
#             gui.display_callback,
#             self.user_input_queue
#         )
# 
#         try:
#             gui.mainloop(machine)
#         except Exception as err:
#             log.critical("GUI exception: %s", err)
#             print_exc_plus()
#         machine.quit()
# 
#         log.log(99, " --- END ---")
# 
# Path: dragonpy/sbc09/config.py
# class SBC09Cfg(BaseConfig):
#     """
#     DragonPy config for Lennart's 6809 single board computer
# 
#         Buggy machine language monitor and rudimentary O.S. version 1.0
# 
#     More info read ./sbc09/README.creole
#     """
# 
#     CONFIG_NAME = constants.SBC09
#     MACHINE_NAME = "Lennart's 6809 single board computer"
# 
#     RAM_START = 0x0000
#     RAM_END = 0x7FFF
#     # RAM size: 0x8000 == 32768 Bytes
# 
#     ROM_START = 0x8000
#     ROM_END = 0xFFFF
#     # ROM size: 0x4000 == 16384 Bytes
# 
#     BUS_ADDR_AREAS = (
#         (0xe000, 0xe001, "RS232 interface"),  # emulated serial port (ACIA)
#         (0xFFF2, 0xFFFE, "Interrupt vectors"),
#     )
# 
#     DEFAULT_ROMS = (
#         SBC09Rom(address=0x8000, max_size=None),
#     )
# 
#     # Used in unittest for init the machine:
#     STARTUP_END_ADDR = 0xe45a  # == O.S. routine to read a character into B register.
# 
#     def __init__(self, cmd_args):
#         super().__init__(cmd_args)
# 
#         self.machine_api = CoCoAPI()  # FIXME!
# 
# #         if self.verbosity <= logging.INFO:
#         self.mem_info = get_sbc09_meminfo()
# 
#         self.periphery_class = SBC09Periphery
# 
# Path: dragonpy/sbc09/gui.py
# class SBC09TkinterGUI(ScrolledTextGUI):
#     pass
# 
# Path: dragonpy/sbc09/periphery.py
# class SBC09Periphery:
#     TITLE = "DragonPy - Buggy machine language monitor and rudimentary O.S. version 1.0"
#     INITAL_INPUT = (
#         #        # Dump registers
#         #        'r\r\n'
#         #
#         #        # SSaddr,len - Dump memory region as Motorola S records.
#         #        'ss\r\n'
#         #
#         #        # Daddr,len - Dump memory region
#         #        'DE5E2\r\n'
#         #
#         #        # Iaddr - Display the contents of the given address.
#         #        'IE001\r\n' # e.g.: Show the ACIA status
#         #
#         #        # Uaddr,len - Diassemble memory region
#         #        'UE400\r\n'
#         #
#         #        # Calculate simple expression in hex with + and -
#         #        'H4444+A5\r\n'
# 
#         #
#         #         "UE400,20\r\n"
#         #         "ubasic\r\n"
#     )
# 
#     def __init__(self, cfg, cpu, memory, display_callback, user_input_queue):
#         self.cfg = cfg
#         self.cpu = cpu
#         self.memory = memory
#         self.display_callback = display_callback
#         self.user_input_queue = user_input_queue
# 
#         self.memory.add_read_byte_callback(self.read_acia_status, 0xe000)  # Control/status port of ACIA
#         self.memory.add_read_byte_callback(self.read_acia_data, 0xe001)  # Data port of ACIA
# 
#         self.memory.add_write_byte_callback(self.write_acia_status, 0xe000)  # Control/status port of ACIA
#         self.memory.add_write_byte_callback(self.write_acia_data, 0xe001)  # Data port of ACIA
# 
#     def write_acia_status(self, cpu_cycles, op_address, address, value):
#         return 0xff
# 
#     def read_acia_status(self, cpu_cycles, op_address, address):
#         return 0x03
# 
#     def read_acia_data(self, cpu_cycles, op_address, address):
#         try:
#             char = self.user_input_queue.get(block=False)
#         except queue.Empty:
#             return 0x0
# 
#         value = ord(char)
#         log.error("%04x| (%i) read from ACIA-data, send back %r $%x",
#                   op_address, cpu_cycles, char, value
#                   )
#         return value
# 
#     def write_acia_data(self, cpu_cycles, op_address, address, value):
#         char = chr(value)
#         log.debug("Write to screen: %s ($%x)", repr(char), value)
# #        log.error("*"*79)
# #        log.error("Write to screen: %s ($%x)" , repr(char), value)
# #        log.error("*"*79)
# 
#         self.display_callback(char)


# Path: dragonpy/sbc09/machine.py
import logging
from dragonpy.core.machine import MachineGUI
from dragonpy.sbc09.config import SBC09Cfg
from dragonpy.sbc09.gui import SBC09TkinterGUI
from dragonpy.sbc09.periphery import SBC09Periphery

#!/usr/bin/env python

"""
    Multicomp 6809
    ~~~~~~~~~~~~~~

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




log = logging.getLogger(__name__)


def run_sbc09(cfg_dict):
    machine = MachineGUI(
        cfg=SBC09Cfg(cfg_dict)
    )
    machine.run(

        PeripheryClass=SBC09Periphery,