# Path: dragonpy/utils/bits.py
# def clear_bit(value, bit):
#     """
#     returns an integer with the bit at offset >bit< set to 0.
# 
#     >>> clear_bit(128, 7)
#     0
#     >>> clear_bit(0, 2)
#     0
# 
#     >>> '{0:08b}'.format(clear_bit(int('11111111', 2), bit=5))
#     '11011111'
# 
#     >>> '{0:08b}'.format(clear_bit(int('1111000011110000', 2), bit=13))
#     '1101000011110000'
#     """
#     return value & ~(1 << bit)
# 
# def invert_byte(value):
#     """
#     >>> '{0:08b}'.format(invert_byte(int('00001000',2)))
#     '11110111'
# 
#     >>> '{0:08b}'.format(invert_byte(int('10101010',2)))
#     '01010101'
# 
#     >>> '{0:08b}'.format(invert_byte(int('00110011',2)))
#     '11001100'
#     """
#     return 2 ** 8 + ~value
# 
# 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


import logging
    import doctest
    import pprint
    import tkinter
from dragonlib.utils.auto_shift import invert_shift
from dragonpy.utils.bits import clear_bit, invert_byte, is_bit_set
    1: 5,
    2: 0,
    3: 1,
    4: 2,
    5: 3,
    6: 6,
}

# Use the Dragon map and just swap the rows
COCO_KEYMAP = {}
for key, coordinates in list(DRAGON_KEYMAP.items()):
    coco_coordinates = []
    for column, row in coordinates:
        new_row = COCO_ROW_MAP[row]
        coco_coordinates.append((column, new_row))
    COCO_KEYMAP[key] = tuple(coco_coordinates)


def _get_col_row_values(inkey, keymap):
    try:
        col_row_values = keymap[inkey]
    except KeyError:
        col_row_values = ()
        log.critical("Key %r not supported or unknown.", inkey)
    return col_row_values


def _set_bits(pia0b, col_row_values):
    result = 0xff
    for col, row in col_row_values:

# Path: dragonpy/utils/bits.py
# def clear_bit(value, bit):
#     """
#     returns an integer with the bit at offset >bit< set to 0.
# 
#     >>> clear_bit(128, 7)
#     0
#     >>> clear_bit(0, 2)
#     0
# 
#     >>> '{0:08b}'.format(clear_bit(int('11111111', 2), bit=5))
#     '11011111'
# 
#     >>> '{0:08b}'.format(clear_bit(int('1111000011110000', 2), bit=13))
#     '1101000011110000'
#     """
#     return value & ~(1 << bit)
# 
# def invert_byte(value):
#     """
#     >>> '{0:08b}'.format(invert_byte(int('00001000',2)))
#     '11110111'
# 
#     >>> '{0:08b}'.format(invert_byte(int('10101010',2)))
#     '01010101'
# 
#     >>> '{0:08b}'.format(invert_byte(int('00110011',2)))
#     '11001100'
#     """
#     return 2 ** 8 + ~value
# 
# 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


# Path: dragonpy/Dragon32/keyboard_map.py
import logging
    import doctest
    import pprint
    import tkinter
from dragonlib.utils.auto_shift import invert_shift
from dragonpy.utils.bits import clear_bit, invert_byte, is_bit_set

    1: 5,
    2: 0,
    3: 1,
    4: 2,
    5: 3,
    6: 6,
}

# Use the Dragon map and just swap the rows
COCO_KEYMAP = {}
for key, coordinates in list(DRAGON_KEYMAP.items()):
    coco_coordinates = []
    for column, row in coordinates:
        new_row = COCO_ROW_MAP[row]
        coco_coordinates.append((column, new_row))
    COCO_KEYMAP[key] = tuple(coco_coordinates)


def _get_col_row_values(inkey, keymap):
    try:
        col_row_values = keymap[inkey]
    except KeyError:
        col_row_values = ()
        log.critical("Key %r not supported or unknown.", inkey)
    return col_row_values


def _set_bits(pia0b, col_row_values):
    result = 0xff
    for col, row in col_row_values:

        if not is_bit_set(pia0b, bit=col):