# 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
    PB6 - $ff02 in $bf (10111111) -> $ff00 out $ff (11111111) stored in $0158
    PB7 - $ff02 in $7f (01111111) -> $ff00 out $ff (11111111) stored in $0159
      ^                 ^^^^^^^^                     ^^^^^^^
      |                 ||||||||                     |||||||
    col            col: 76543210              row -> 6543210

    >>> test("P", "coco")
    char/keycode: 'P' -> cols/rows: ((0, 2),)
    PB0 - $ff02 in $fe (11111110) -> $ff00 out $fb (11111011) stored in $0152
    PB1 - $ff02 in $fd (11111101) -> $ff00 out $ff (11111111) stored in $0153
    PB2 - $ff02 in $fb (11111011) -> $ff00 out $ff (11111111) stored in $0154
    PB3 - $ff02 in $f7 (11110111) -> $ff00 out $ff (11111111) stored in $0155
    PB4 - $ff02 in $ef (11101111) -> $ff00 out $ff (11111111) stored in $0156
    PB5 - $ff02 in $df (11011111) -> $ff00 out $ff (11111111) stored in $0157
    PB6 - $ff02 in $bf (10111111) -> $ff00 out $ff (11111111) stored in $0158
    PB7 - $ff02 in $7f (01111111) -> $ff00 out $ff (11111111) stored in $0159
      ^                 ^^^^^^^^                     ^^^^^^^
      |                 ||||||||                     |||||||
    col            col: 76543210              row -> 6543210
    """
    if matrix_name == "dragon":
        col_row_values = _get_col_row_values(inkey, DRAGON_KEYMAP)
    elif matrix_name == "coco":
        col_row_values = _get_col_row_values(inkey, COCO_KEYMAP)
    else:
        raise RuntimeError

    print(f"char/keycode: {inkey!r} -> cols/rows: {col_row_values!r}")

    for i in range(8):

# 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

    PB6 - $ff02 in $bf (10111111) -> $ff00 out $ff (11111111) stored in $0158
    PB7 - $ff02 in $7f (01111111) -> $ff00 out $ff (11111111) stored in $0159
      ^                 ^^^^^^^^                     ^^^^^^^
      |                 ||||||||                     |||||||
    col            col: 76543210              row -> 6543210

    >>> test("P", "coco")
    char/keycode: 'P' -> cols/rows: ((0, 2),)
    PB0 - $ff02 in $fe (11111110) -> $ff00 out $fb (11111011) stored in $0152
    PB1 - $ff02 in $fd (11111101) -> $ff00 out $ff (11111111) stored in $0153
    PB2 - $ff02 in $fb (11111011) -> $ff00 out $ff (11111111) stored in $0154
    PB3 - $ff02 in $f7 (11110111) -> $ff00 out $ff (11111111) stored in $0155
    PB4 - $ff02 in $ef (11101111) -> $ff00 out $ff (11111111) stored in $0156
    PB5 - $ff02 in $df (11011111) -> $ff00 out $ff (11111111) stored in $0157
    PB6 - $ff02 in $bf (10111111) -> $ff00 out $ff (11111111) stored in $0158
    PB7 - $ff02 in $7f (01111111) -> $ff00 out $ff (11111111) stored in $0159
      ^                 ^^^^^^^^                     ^^^^^^^
      |                 ||||||||                     |||||||
    col            col: 76543210              row -> 6543210
    """
    if matrix_name == "dragon":
        col_row_values = _get_col_row_values(inkey, DRAGON_KEYMAP)
    elif matrix_name == "coco":
        col_row_values = _get_col_row_values(inkey, COCO_KEYMAP)
    else:
        raise RuntimeError

    print(f"char/keycode: {inkey!r} -> cols/rows: {col_row_values!r}")

    for i in range(8):

        pia0b = invert_byte(2 ** i)  # written into $ff02