Exemple #1
0
def main():
    mapfile = sys.argv[1] if len(sys.argv) >= 2 else 'pokegold-spaceworld.map'
    filename = sys.argv[2] if len(sys.argv) >= 3 else 'mask.w1024.2bpp'

    num_banks = 0x40
    bank_mask = 0x3FFF
    bank_size = 0x4000  # bytes

    r = MapReader()
    with open(mapfile, 'r', encoding='utf-8') as f:
        l = f.readlines()
    r.read_map_data(l)

    default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
    with open(filename, 'wb') as f:
        for bank in range(num_banks):
            hits = bytearray([0x00] * bank_size)
            data = r.bank_data['rom bank'].get(bank, default_bank_data)
            for s in data['sections']:
                if s['beg'] > s['end']:
                    continue
                if s['beg'] == 0x0000 and s['end'] > 0xFFFF:
                    # https://github.com/gbdev/rgbds/issues/515
                    continue
                beg = s['beg'] & bank_mask
                end = s['end'] & bank_mask
                for i in range(beg, end + 1):
                    hits[i] = 0xFF
            f.write(hits)
def main():
    print_bank = 'none'
    mapfile = 'pokecrystal11.map'

    if len(sys.argv) >= 2 and sys.argv[1].startswith('BANK='):
        print_bank = sys.argv[1].split('=', 1)[-1]
        if len(sys.argv) >= 3:
            mapfile = sys.argv[2]
    elif len(sys.argv) >= 3 and sys.argv[2].startswith('BANK='):
        print_bank = sys.argv[2].split('=', 1)[-1]
        mapfile = sys.argv[1]

    if print_bank not in {'all', 'none'}:
        try:
            if print_bank.startswith('0x') or print_bank.startswith('0X'):
                print_bank = int(print_bank[2:], 16)
            else:
                print_bank = int(print_bank)
        except ValueError:
            error = 'Error: invalid BANK: %s' % print_bank
            if print_bank.isalnum():
                error += ' (did you mean: 0x%s?)' % print_bank
            print(error, file=sys.stderr)
            sys.exit(1)

    num_banks = 0x80
    bank_size = 0x4000  # bytes
    total_size = num_banks * bank_size

    r = MapReader()
    with open(mapfile, 'r', encoding='utf-8') as f:
        l = f.readlines()
    r.read_map_data(l)

    free_space = 0
    per_bank = []
    default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
    for bank in range(num_banks):
        bank_data = r.bank_data['ROM0 bank'] if bank == 0 else r.bank_data[
            'ROMX bank']
        data = bank_data.get(bank, default_bank_data)
        used = data['used']
        slack = data['slack']
        per_bank.append((used, slack))
        free_space += slack

    print('Free space: %d/%d (%.2f%%)' %
          (free_space, total_size, free_space * 100.0 / total_size))
    if print_bank != 'none':
        print()
        print('bank, used, free')
    for bank in range(num_banks):
        used, slack = per_bank[bank]
        if print_bank in {'all', bank}:
            print('$%02X, %d, %d' % (bank, used, slack))
def main():
    mapfile = sys.argv[1] if len(sys.argv) >= 2 else 'pokegold-spaceworld.map'
    filename = sys.argv[2] if len(sys.argv) >= 3 else 'coverage.png'

    num_banks = 0x40
    bank_mask = 0x3FFF
    bank_size = 0x4000  # bytes

    bpp = 8  # bytes per pixel
    height = 256  # pixels
    assert bank_size % bpp == 0 and (bank_size // bpp) % height == 0

    pixels_per_bank = bank_size // bpp  # 2048 pixels
    bank_width = pixels_per_bank // height  # 8 pixels
    width = bank_width * num_banks  # 1024 pixels

    r = MapReader()
    with open(mapfile, 'r', encoding='utf-8') as f:
        l = f.readlines()
    r.read_map_data(l)

    hit_data = []
    default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
    for bank in range(num_banks):
        hits = [0] * pixels_per_bank
        data = r.bank_data['rom bank'].get(bank, default_bank_data)
        for s in data['sections']:
            if s['beg'] > s['end']:
                continue
            if s['beg'] == 0x0000 and s['end'] > 0xFFFF:
                # https://github.com/gbdev/rgbds/issues/515
                continue
            beg = s['beg'] & bank_mask
            end = s['end'] & bank_mask
            for i in range(beg, end + 1):
                hits[i // bpp] += 1
        hit_data.append(hits)

    pixels = [[(0xFF, 0xFF, 0xFF)] * width for _ in range(height)]
    for bank, hits in enumerate(hit_data):
        hue = 0 if not bank else 210 if bank % 2 else 270
        for i, h in enumerate(hits):
            y = i // bank_width
            x = i % bank_width + bank * bank_width
            hls = (hue / 360.0, 1.0 - (h / bpp * (100 - 15)) / 100.0, 1.0)
            rgb = tuple(int(c * 255) for c in hls_to_rgb(*hls))
            pixels[y][x] = rgb

    png_data = [tuple(c for pixel in row for c in pixel) for row in pixels]
    with open(filename, 'wb') as f:
        w = png.Writer(width, height)
        w.write(f, png_data)
Exemple #4
0
    args = ap.parse_args()

    bank_mask = 0x3FFF
    bank_size = 0x4000  # bytes
    width = 256  # pixels per row
    bpp = 8  # bytes per pixel

    rom_size = args.num_banks * bank_size  # bytes
    height = (args.num_banks * bank_size +
              (width * bpp - 1)) // (width * bpp)  # pixels
    rows_per_bank = bank_size // (width * bpp)

    r = MapReader()
    with open(args.mapfile, 'r', encoding="utf-8") as f:
        l = f.readlines()
    r.read_map_data(l)

    hit_data = [[0] * width for _ in range(height)]
    default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
    for bank in range(args.num_banks):
        data = r.bank_data['ROM Bank'].get(bank, default_bank_data)
        for s in data['sections']:
            beg = (s['beg'] & bank_mask) + bank * bank_size
            end = (s['end'] & bank_mask) + bank * bank_size
            y_beg = beg // (width * bpp)
            x_beg = (beg % (width * bpp)) // bpp
            y_end = end // (width * bpp)
            x_end = (end % (width * bpp)) // bpp
            #print('beg {0} end {1}: {2}/{3} -- {4}/{5}'.format(beg, end, y_beg, x_beg, y_end, x_end))
            # special case y_beg/x_beg and y_end/x_end
            if (y_beg == y_end and x_beg == x_end):
 args = ap.parse_args()
 
 bank_mask = 0x3FFF
 bank_size = 0x4000 # bytes
 width = 256 # pixels per row
 bpp = 8 # bytes per pixel
 
 romname = args.romname
 rom_size = args.num_banks * bank_size # bytes
 height = (args.num_banks * bank_size + (width * bpp - 1)) // (width * bpp) # pixels
 rows_per_bank = bank_size // (width * bpp)
 
 r = MapReader()
 with open(args.mapfile, 'r', encoding= 'utf-8') as f:
     l = f.readlines()
 r.read_map_data(l)
 
 default_bank_data = {'sections': [], 'used': 0, 'slack': bank_size}
 filler = [0x00, 0xFF]
 
 if (romname is not None):
     with open(romname, 'rb') as f:
         for rb in range(0, args.num_banks):
             data = r.bank_data['ROM Bank'].get(rb, default_bank_data)
             bank = f.read(bank_size)
             if (bank[bank_size - 1] in filler):
                 fill = bank[bank_size - 1]
                 for i in reversed(range(-1, bank_size - 1)):
                     if (i < 0 or bank[i] != fill):
                         break
                 # i is now pointing to first different byte