(codedata)
return code_length, code, compressed_size
Decompresses compressed code data.

    Args:
        codedata: The bytes of the code region (0x4300:0x8000).

    Returns:
        The tuple (code_length, code, compressed_size). code is a bytestring.
Decompresses compressed code data.
Decompresses compressed code data .
def decompress_code(codedata):
    """Decompresses compressed code data.

    Args:
        codedata: The bytes of the code region (0x4300:0x8000).

    Returns:
        The tuple (code_length, code, compressed_size). code is a bytestring.
    """
    code_length = (codedata[4] << 8) | codedata[5]
    assert bytes(codedata[6:8]) == b'\x00\x00'

    out = [0] * code_length
    in_i = 8
    out_i = 0
    while out_i < code_length and in_i < len(codedata):
        if codedata[in_i] == 0x00:
            in_i += 1
            out[out_i] = codedata[in_i]
            out_i += 1
        elif codedata[in_i] <= 0x3b:
            out[out_i] = COMPRESSED_LUA_CHAR_TABLE[codedata[in_i]]
            out_i += 1
        else:
            in_i += 1
            offset = (
                (codedata[in_i - 1] - 0x3c) * 16 +
                (codedata[in_i] & 0xf))
            length = (codedata[in_i] >> 4) + 2
            out[out_i:out_i + length] = \
                out[out_i - offset:out_i - offset + length]
            out_i += length
        in_i += 1

    code = bytes(out).strip(b'\x00')
    if code.endswith(PICO8_FUTURE_CODE1):
        code = code[:-len(PICO8_FUTURE_CODE1)]
        if code[-1] == b'\n'[0]:
            code = code[:-1]
    if code.endswith(PICO8_FUTURE_CODE2):
        code = code[:-len(PICO8_FUTURE_CODE2)]
        if code[-1] == b'\n'[0]:
            code = code[:-1]

    compressed_size = in_i

    return code_length, code, compressed_size
def decompress_code ( codedata ) : code_length = ( codedata [ 4 ] << 8 ) | codedata [ 5 ] assert bytes ( codedata [ 6 : 8 ] ) == b'\x00\x00' out = [ 0 ] * code_length in_i = 8 out_i = 0 while out_i < code_length and in_i < len ( codedata ) : if codedata [ in_i ] == 0x00 : in_i += 1 out [ out_i ] = codedata [ in_i ] out_i += 1 elif codedata [ in_i ] <= 0x3b : out [ out_i ] = COMPRESSED_LUA_CHAR_TABLE [ codedata [ in_i ] ] out_i += 1 else : in_i += 1 offset = ( ( codedata [ in_i - 1 ] - 0x3c ) * 16 + ( codedata [ in_i ] & 0xf ) ) length = ( codedata [ in_i ] >> 4 ) + 2 out [ out_i : out_i + length ] = out [ out_i - offset : out_i - offset + length ] out_i += length in_i += 1 code = bytes ( out ) . strip ( b'\x00' ) if code . endswith ( PICO8_FUTURE_CODE1 ) : code = code [ : - len ( PICO8_FUTURE_CODE1 ) ] if code [ - 1 ] == b'\n' [ 0 ] : code = code [ : - 1 ] if code . endswith ( PICO8_FUTURE_CODE2 ) : code = code [ : - len ( PICO8_FUTURE_CODE2 ) ] if code [ - 1 ] == b'\n' [ 0 ] : code = code [ : - 1 ] compressed_size = in_i return code_length , code , compressed_size