def generate_block_data(data, index, blocktype):
    """Generates the largest block possible starting at index in data.
    returns (output, new_index) where output is the generated block and
    new_index points to where the next block in data would be extracted"""
    output = bytearray()
    output += b'\x3c'
    output.append(blocktype)
    sz = len(data) - index
    if (sz > 0xff):
        sz = 0xff
    output.append(sz)
    output += data[index:index + sz]
    checksum = sum(output[1:]) & 0xff
    output.append(checksum)
    return (output, index + sz)