diff options
author | Rangi <remy.oukaour+rangi@gmail.com> | 2020-09-23 09:40:56 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi@gmail.com> | 2020-09-23 09:40:56 -0400 |
commit | ab60521b62ae52a125a30ea06d3f749f4031b95e (patch) | |
tree | af066fce7da4a0ea70037e8c376c8cc078ae9126 /utils/mask.py | |
parent | c544daf8cd0cdcee418d6e8b88c1506a50eda0a0 (diff) |
Add utils/mask.py
This creates a 2bpp file the same size as the ROM. The ROM can be renamed 2bpp and the mask image can be overlaid on the ROM image to show what's disassembled.
Diffstat (limited to 'utils/mask.py')
-rw-r--r-- | utils/mask.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/utils/mask.py b/utils/mask.py new file mode 100644 index 0000000..934a64a --- /dev/null +++ b/utils/mask.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Usage: python3 mask.py [pokegold-spaceworld.map] [mask.png] + +Generate a 2BPP visualizing the space used by each bank in the ROM. +""" + +import sys + +from mapreader import MapReader + +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) + +if __name__ == '__main__': + main() |