diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-04-28 22:24:09 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-04-28 22:24:09 +0200 |
| commit | 9463faa436e1b981ef72000568445a83682f2658 (patch) | |
| tree | 3aa7f59a2199cbe7df4555dc2b4963d1b5a5b86f /mapper_scan.py | |
| parent | e08b851c79ae9a7fc0a2066e49110dc7fb426bce (diff) | |
add a few python scripts for mapper generation and setup
Diffstat (limited to 'mapper_scan.py')
| -rwxr-xr-x | mapper_scan.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mapper_scan.py b/mapper_scan.py new file mode 100755 index 0000000..5b6e96a --- /dev/null +++ b/mapper_scan.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +import glob +import re + +def scan_mappers(): + mappers = [] + + # Find all mapper_*.c files + for filename in sorted(glob.glob("mapper_*.c")): + # Extract mapper ID from filename + match = re.match(r'mapper_(\d+)_([0-9a-fA-F])\.c', filename) + if match: + mapper_id = int(match.group(1)) + submapper_id = int(match.group(2), 16) + full_id = (mapper_id << 4) | submapper_id + else: + # Legacy format: mapper_xxx.c without submapper + match = re.match(r'mapper_(\d+)\.c', filename) + if match: + mapper_id = int(match.group(1)) + full_id = (mapper_id << 4) | 0 + else: + continue + + init_fn = f"mapper_{mapper_id:03d}_{submapper_id:x}_init" if 'submapper_id' in locals() else f"mapper_{mapper_id:03d}_init" + mappers.append((full_id, init_fn)) + + return mappers + +def generate_table(mappers): + print("static struct mapper_entry mapper_table[] = {") + for full_id, init_fn in mappers: + print(f"\t{{ 0x{full_id:04x}, {init_fn} }},") + print("};") + +if __name__ == "__main__": + mappers = scan_mappers() + generate_table(mappers) |
