Exemple #1
0
def read_menu_cfg(file_name):

    lines = open(file_name).readlines()

    # Discard the headings.
    lines.pop(0)

    info = []

    i = 0
    while i < len(lines):

        line = lines[i]
        i += 1

        l = line.strip()
        if not l:
            break

        pieces = l.split()
        page = int(pieces[0])
        command = pieces[1]
        files = pieces[2:]
        info.append((page, command, files))

    # Read the spans.
    i += 1
    spans = []

    while i < len(lines):

        line = lines[i]
        i += 1

        l = line.strip()
        if not l:
            break

        pieces = l.split()
        begin = int(pieces[0])
        end = int(pieces[1])

        if pieces[2] == "rainbow":
            spans.append(
                ((begin, end),
                 lambda i: get_entries(4, rainbow(i, rainbow_colours, 3))))

        elif len(pieces) == 6:
            colours = []
            for c in pieces[2:]:
                colours.append(standard_colours[c])

            spans.append(((begin, end), lambda i: get_entries(4, colours)))

        else:
            sys.stderr.write("Invalid palette description '%s' in %s.\n" %
                             (l, file_name))
            sys.exit(1)

    return info, spans
Exemple #2
0
def mgc_palette(full=True):

    # Special MGC title palette processing

    fe08_data = []
    fe09_data = []

    blank = get_entries(4, [black, black, black, black])
    standard = get_entries(4, [black, red, yellow, white])

    if full:
        s1, s2 = 111, 65
    else:
        s1, s2 = 43, 3

    for i in range(256):

        if i >= 128 + s1:
            fe08, fe09 = get_entries(
                4, rainbow(i - 239, [yellow, cyan, white, green, cyan], 3))
        elif i >= 128 + s2:
            fe08, fe09 = get_entries(4, rainbow(i, rainbow_colours, 3))
        elif full and i >= 128 + 46:
            fe08, fe09 = get_entries(
                4, rainbow(i, [white, cyan, green, yellow], 3))
        elif full and i > 128:
            fe08, fe09 = get_entries(4, [black, blue, cyan, white])
        else:
            fe08, fe09 = standard

        fe08_data.append(fe08)
        fe09_data.append(fe09)

    return fe08_data, fe09_data
Exemple #3
0
def title_palette(spans, default, full=True):

    # Special title palette processing

    fe08_data = []
    fe09_data = []

    blank = get_entries(4, [black, black, black, black])

    for i in range(256):

        for (s1, s2), fn in spans:

            if i >= s1 and i < s2:
                fe08, fe09 = fn(i)
                break
        else:
            # The last item in the list should be the fallback.
            fe08, fe09 = default(i)

        fe08_data.append(fe08)
        fe09_data.append(fe09)

    return fe08_data, fe09_data
Exemple #4
0
if __name__ == "__main__":

    if len(sys.argv) != 3:

        sys.stderr.write(
            "Usage: %s <menu configuration file> <title image>\n" %
            sys.argv[0])
        sys.exit(1)

    menu_cfg_file = sys.argv[1]
    title_image_file = sys.argv[2]

    # Special title image and code processing
    menu_info, spans = read_menu_cfg(menu_cfg_file)
    default = lambda i: get_entries(4, [black, red, yellow, white])

    # Convert the PNG to screen data and compress it with the palette data.
    title_sprite = read_sprite(read_png(title_image_file))
    fe08_data, fe09_data = title_palette(spans, default, full=True)
    data_list = "".join(
        map(chr, compress(fe08_data + fe09_data + map(ord, title_sprite))))

    # Prepend the menu data to a generated file.
    code_temp = generate_menu(menu_info)

    # Read the code and append the formatted title data to it.
    title_dest_end = 0x2e00 + len(title_sprite) + len(fe08_data) + len(
        fe09_data)
    code_temp += ".alias title_dest_end $%x\n" % title_dest_end
    code_temp += ".alias title_palette_start %i\n" % spans[0][0][0]
Exemple #5
0
    #if subst:
    #    f.write(open(rl_template_file).read())

    f.write("decode_command:\n\n")

    if check_system:
        f.write(check_system_template)

    f.write(open(dp_template_file).read())

    if make_snapshot and not chain:

        mode = ula[8]
        if mode in (0, 3, 4, 6):
            colours = [rgb(palette[0]), rgb(palette[14])]
            registers = get_entries(2, colours)
        elif mode in (1, 5):
            colours = [
                rgb(palette[0]),
                rgb(palette[2]),
                rgb(palette[8]),
                rgb(palette[10])
            ]
            registers = get_entries(4, colours)
        else:
            colours = [rgb(palette[0]), rgb(palette[14])]
            registers = get_entries(16, colours)

        palette_code = []
        v = 0xfe08
        for r in registers:
Exemple #6
0
     
     palette[row - start_row] = entries
     old_entries = entries[:]
     row += 1
 
 name = os.path.split(file_name)[1]
 output_file = os.path.join("data", os.path.splitext(name)[0] + ".dat")
 print "Writing", output_file
 
 f = open(output_file, "w")
 fe08_values = []
 fe09_values = []
 
 for entries in palette:
 
     fe08, fe09 = get_entries(4, map(lambda x: rgb_values[x], entries))
     fe08_values.append(fe08)
     fe09_values.append(fe09)
 
 while len(fe08_values) < max_rows:
     fe08_values.append(0xff)
     fe09_values.append(0xff)
 
 for fe08 in fe08_values:
     f.write(chr(fe08))
 
 for fe09 in fe09_values:
     f.write(chr(fe09))
 
 by = start_row
 while by < min(start_row + max_rows, len(rows)):
Exemple #7
0
def encode_palette(palette_info):

    return "".join(map(chr, get_entries(16, palette_info)))