Created
January 6, 2017 08:26
-
-
Save taotao54321/e4269a404f64c33380d0ae44e6b259d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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