# Path: dragonpy/constants.py
# DRAGON32 = "Dragon32"
# DRAGON64 = "Dragon64"
# COCO2B = "CoCo2b"
# SBC09 = "sbc09"
# SIMPLE6809 = "Simple6809"
# MULTICOMP6809 = "Multicomp6809"
# VECTREX = "Vectrex"
# 
# Path: dragonpy/utils/bits.py
# 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
# 
# def set_bit(value, bit):
#     """
#     returns an integer with the bit at offset >bit< set to 1.
# 
#     >>> set_bit(0x00, 2)
#     4
#     >>> set_bit(0x00, 7)
#     128
#     >>> '{0:08b}'.format(set_bit(int('00000000', 2), bit=5))
#     '00100000'
#     >>> '{0:08b}'.format(set_bit(int('10101010', 2), bit=0))
#     '10101011'
#     >>> '{0:08b}'.format(set_bit(int('1111000011110000', 2), bit=10))
#     '1111010011110000'
#     >>> '{0:08b}'.format(set_bit(int('11111111', 2), bit=3))
#     '11111111'
#     """
#     return value | 1 << bit
# 
# Path: dragonpy/utils/humanize.py
# def byte2bit_string(data):
#     """
#     >>> byte2bit_string(0x1b)
#     '00011011'
#     """
#     return f'{data:08b}'


import logging
import queue
from dragonpy import constants
from dragonpy.utils.bits import is_bit_set, set_bit
from dragonpy.utils.humanize import byte2bit_string
                        #     "\tget new key from queue: %s", repr(self.current_input_char)
                        # )
                        self.empty_key_toggle = True

        if self.current_input_char is None:
            #            log.critical("\tno key pressed")
            result = 0xff
            self.empty_key_toggle = False
        else:
            #            log.critical("\tsend %s", repr(self.current_input_char))
            result = self.cfg.pia_keymatrix_result(
                self.current_input_char, pia0b)

#         if not is_bit_set(pia0b, bit=7):
# bit 7 | PA7 | joystick comparison input
#             result = clear_bit(result, bit=7)

#         if self.current_input_char is not None:
#             log.critical(
#                 "%04x| read $%04x ($ff02 is $%02x %s) send $%02x %s back\t|%s",
#                 op_address, address,
#                 pia0b, '{0:08b}'.format(pia0b),
#                 result, '{0:08b}'.format(result),
#                 self.cfg.mem_info.get_shortest(op_address)
#             )
        return result

    def write_PIA0_A_data(self, cpu_cycles, op_address, address, value):
        """ write to 0xff00 -> PIA 0 A side Data reg. """
        log.error("%04x| write $%02x (%s) to $%04x -> PIA 0 A side Data reg.\t|%s",

# Path: dragonpy/constants.py
# DRAGON32 = "Dragon32"
# DRAGON64 = "Dragon64"
# COCO2B = "CoCo2b"
# SBC09 = "sbc09"
# SIMPLE6809 = "Simple6809"
# MULTICOMP6809 = "Multicomp6809"
# VECTREX = "Vectrex"
# 
# Path: dragonpy/utils/bits.py
# 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
# 
# def set_bit(value, bit):
#     """
#     returns an integer with the bit at offset >bit< set to 1.
# 
#     >>> set_bit(0x00, 2)
#     4
#     >>> set_bit(0x00, 7)
#     128
#     >>> '{0:08b}'.format(set_bit(int('00000000', 2), bit=5))
#     '00100000'
#     >>> '{0:08b}'.format(set_bit(int('10101010', 2), bit=0))
#     '10101011'
#     >>> '{0:08b}'.format(set_bit(int('1111000011110000', 2), bit=10))
#     '1111010011110000'
#     >>> '{0:08b}'.format(set_bit(int('11111111', 2), bit=3))
#     '11111111'
#     """
#     return value | 1 << bit
# 
# Path: dragonpy/utils/humanize.py
# def byte2bit_string(data):
#     """
#     >>> byte2bit_string(0x1b)
#     '00011011'
#     """
#     return f'{data:08b}'


# Path: dragonpy/Dragon32/MC6821_PIA.py
import logging
import queue
from dragonpy import constants
from dragonpy.utils.bits import is_bit_set, set_bit
from dragonpy.utils.humanize import byte2bit_string

                        #     "\tget new key from queue: %s", repr(self.current_input_char)
                        # )
                        self.empty_key_toggle = True

        if self.current_input_char is None:
            #            log.critical("\tno key pressed")
            result = 0xff
            self.empty_key_toggle = False
        else:
            #            log.critical("\tsend %s", repr(self.current_input_char))
            result = self.cfg.pia_keymatrix_result(
                self.current_input_char, pia0b)

#         if not is_bit_set(pia0b, bit=7):
# bit 7 | PA7 | joystick comparison input
#             result = clear_bit(result, bit=7)

#         if self.current_input_char is not None:
#             log.critical(
#                 "%04x| read $%04x ($ff02 is $%02x %s) send $%02x %s back\t|%s",
#                 op_address, address,
#                 pia0b, '{0:08b}'.format(pia0b),
#                 result, '{0:08b}'.format(result),
#                 self.cfg.mem_info.get_shortest(op_address)
#             )
        return result

    def write_PIA0_A_data(self, cpu_cycles, op_address, address, value):
        """ write to 0xff00 -> PIA 0 A side Data reg. """
        log.error("%04x| write $%02x (%s) to $%04x -> PIA 0 A side Data reg.\t|%s",

                  op_address, value, byte2bit_string(value), address,