Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""AD&D プールオブレイディアンス (FC) マップデータ切り出し
iNESヘッダなしのROMファイルを食わせると全マップデータを出力する。
"""
import argparse
MAP_COUNT = 33
DATA_SIZE = 0x400
def offset(bank, addr_hi):
return 8192*bank + (addr_hi<<8) - 0xA000 if addr_hi else None
def get_offsets(in_):
in_.seek(60*8192 + 0x10AB)
banks = in_.read(MAP_COUNT)
addrs = in_.read(MAP_COUNT)
return tuple(offset(b,a) for b,a in zip(banks, addrs))
def extract(args):
in_ = args.in_
offs = get_offsets(in_)
for i, off in enumerate(offs):
if off is None: continue
print("{}:0x{:05X}".format(i, off))
in_.seek(off)
data = in_.read(DATA_SIZE)
path = "map-{:02d}.bin".format(i)
with open(path, "wb") as out:
out.write(data)
def parse_args():
ap = argparse.ArgumentParser()
ap.add_argument("in_", type=argparse.FileType("rb"))
return ap.parse_args()
def main():
args = parse_args()
extract(args)
if __name__ == "__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment