# Path: python/loaderlib/constants.py
# DATA_TYPE_BIT0          = DATA_TYPE_CODE - 1
# 
# DATA_TYPE_BITCOUNT      = _count_bits(DATA_TYPE_DATA32)
# 
# DATA_TYPE_BITMASK       = _make_bitmask(DATA_TYPE_BITCOUNT)
# 
# DATA_TYPE_DATA08        = 3
# 
# DATA_TYPE_DATA16        = 4
# 
# DATA_TYPE_DATA32        = 5
# 
# DATA_TYPE_SIZES = [
#     (DATA_TYPE_DATA32, 4),
#     (DATA_TYPE_DATA16, 2),
#     (DATA_TYPE_DATA08, 1),
# ]
# 
# class FileFormat(IntEnum):
#     UNKNOWN = 0
#     AMIGA_HUNK_EXECUTABLE = PLATFORM_AMIGA + 1
#     AMIGA_HUNK_LIBRARY = PLATFORM_AMIGA + 2
#     ATARIST_GEMDOS_EXECUTABLE = PLATFORM_ATARIST + 1
#     SNES_SMC = PLATFORM_SNES + 1
#     X68000_X_EXECUTABLE = PLATFORM_X68000 + 1
#     ZXSPECTRUM_Z80_1 = PLATFORM_ZXSPECTRUM + 1
#     ZXSPECTRUM_Z80_2 = PLATFORM_ZXSPECTRUM + 2
#     ZXSPECTRUM_Z80_3 = PLATFORM_ZXSPECTRUM + 3
# 
# class Processor(IntEnum):
#     UNKNOWN = 0
#     M680x0 = 100
#     M68000 = 101
#     M68010 = 102
#     M68020 = 103
#     M68030 = 104
#     M68040 = 105
#     M68060 = 106
#     MIPS = 200
#     P65c816 = 300       # This gets a P prefix to account for the numeric name.
#     Z80 = 400


import io
from typing import Any, Dict, List, Optional, Tuple
from .loaderlib.constants import DATA_TYPE_BIT0, DATA_TYPE_BITCOUNT, DATA_TYPE_BITMASK, \
    DATA_TYPE_DATA08, DATA_TYPE_DATA16, DATA_TYPE_DATA32, DATA_TYPE_SIZES, FileFormat, Processor
## ProgramData related.

STATE_LOADING = 1
STATE_LOADED = 2

def program_data_set_state(program_data, state):
    program_data.state = state

## SegmentBlock flag field related.

def __init_descending_data_sizes():
    def __get_descending_data_sizes_from(data_size):
        for i, entry in enumerate(DATA_TYPE_SIZES):
            if data_size == entry[0]:
                return DATA_TYPE_SIZES[i:]
        raise Exception("unsupported size", data_size)
    result = {}
    for value in DATA_TYPE_SIZES:
        result[value[0]] = __get_descending_data_sizes_from(value[0])
    return result

DESCENDING_DATA_TYPE_SIZES = __init_descending_data_sizes()

""" Indicates that the block is not backed by file data. """
BLOCK_FLAG_ALLOC        = 1 << (DATA_TYPE_BITCOUNT+0)

""" Indicates that the block has been processed. """
BLOCK_FLAG_PROCESSED    = 1 << (DATA_TYPE_BITCOUNT+1)

""" The mask for the flags to preserve if the block is split. """

# Path: python/loaderlib/constants.py
# DATA_TYPE_BIT0          = DATA_TYPE_CODE - 1
# 
# DATA_TYPE_BITCOUNT      = _count_bits(DATA_TYPE_DATA32)
# 
# DATA_TYPE_BITMASK       = _make_bitmask(DATA_TYPE_BITCOUNT)
# 
# DATA_TYPE_DATA08        = 3
# 
# DATA_TYPE_DATA16        = 4
# 
# DATA_TYPE_DATA32        = 5
# 
# DATA_TYPE_SIZES = [
#     (DATA_TYPE_DATA32, 4),
#     (DATA_TYPE_DATA16, 2),
#     (DATA_TYPE_DATA08, 1),
# ]
# 
# class FileFormat(IntEnum):
#     UNKNOWN = 0
#     AMIGA_HUNK_EXECUTABLE = PLATFORM_AMIGA + 1
#     AMIGA_HUNK_LIBRARY = PLATFORM_AMIGA + 2
#     ATARIST_GEMDOS_EXECUTABLE = PLATFORM_ATARIST + 1
#     SNES_SMC = PLATFORM_SNES + 1
#     X68000_X_EXECUTABLE = PLATFORM_X68000 + 1
#     ZXSPECTRUM_Z80_1 = PLATFORM_ZXSPECTRUM + 1
#     ZXSPECTRUM_Z80_2 = PLATFORM_ZXSPECTRUM + 2
#     ZXSPECTRUM_Z80_3 = PLATFORM_ZXSPECTRUM + 3
# 
# class Processor(IntEnum):
#     UNKNOWN = 0
#     M680x0 = 100
#     M68000 = 101
#     M68010 = 102
#     M68020 = 103
#     M68030 = 104
#     M68040 = 105
#     M68060 = 106
#     MIPS = 200
#     P65c816 = 300       # This gets a P prefix to account for the numeric name.
#     Z80 = 400


# Path: python/disassembly_data.py
import io
from typing import Any, Dict, List, Optional, Tuple
from .loaderlib.constants import DATA_TYPE_BIT0, DATA_TYPE_BITCOUNT, DATA_TYPE_BITMASK, \
    DATA_TYPE_DATA08, DATA_TYPE_DATA16, DATA_TYPE_DATA32, DATA_TYPE_SIZES, FileFormat, Processor

## ProgramData related.

STATE_LOADING = 1
STATE_LOADED = 2

def program_data_set_state(program_data, state):
    program_data.state = state

## SegmentBlock flag field related.

def __init_descending_data_sizes():
    def __get_descending_data_sizes_from(data_size):
        for i, entry in enumerate(DATA_TYPE_SIZES):
            if data_size == entry[0]:
                return DATA_TYPE_SIZES[i:]
        raise Exception("unsupported size", data_size)
    result = {}
    for value in DATA_TYPE_SIZES:
        result[value[0]] = __get_descending_data_sizes_from(value[0])
    return result

DESCENDING_DATA_TYPE_SIZES = __init_descending_data_sizes()

""" Indicates that the block is not backed by file data. """
BLOCK_FLAG_ALLOC        = 1 << (DATA_TYPE_BITCOUNT+0)

""" Indicates that the block has been processed. """
BLOCK_FLAG_PROCESSED    = 1 << (DATA_TYPE_BITCOUNT+1)

""" The mask for the flags to preserve if the block is split. """

BLOCK_SPLIT_BITMASK     = BLOCK_FLAG_ALLOC | DATA_TYPE_BITMASK | BLOCK_FLAG_PROCESSED