2021-01-15 02:26:06 +01:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
import sys
|
2021-01-15 02:26:06 +01:00
|
|
|
import argparse
|
2022-05-05 16:08:16 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
2021-06-16 11:52:15 +02:00
|
|
|
from util.n64 import rominfo, find_code_length
|
2021-01-15 02:26:06 +01:00
|
|
|
|
2022-05-05 16:08:16 +02:00
|
|
|
parser = argparse.ArgumentParser(description="Create a splat config from an N64 ROM.")
|
|
|
|
parser.add_argument("rom", help="Path to a .z64/.n64 ROM")
|
2021-01-15 02:26:06 +01:00
|
|
|
|
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
def main(rom_path: Path):
|
|
|
|
if not rom_path.exists():
|
|
|
|
sys.exit(f"ROM file {rom_path} does not exist ({rom_path.absolute()})")
|
|
|
|
if rom_path.is_dir():
|
|
|
|
sys.exit(f"Path {rom_path} is a directory ({rom_path.absolute()})")
|
|
|
|
rom_bytes = rominfo.read_rom(rom_path)
|
|
|
|
|
|
|
|
rom = rominfo.get_info(rom_path, rom_bytes)
|
2021-01-15 02:26:06 +01:00
|
|
|
basename = rom.name.replace(" ", "").lower()
|
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
header = f"""\
|
2021-06-16 11:52:15 +02:00
|
|
|
name: {rom.name.title()} ({rom.get_country_name()})
|
|
|
|
sha1: {rom.sha1}
|
2021-01-15 02:26:06 +01:00
|
|
|
options:
|
2021-06-16 11:52:15 +02:00
|
|
|
basename: {basename}
|
2022-05-05 16:08:16 +02:00
|
|
|
target_path: {rom_path.with_suffix(".z64")}
|
2021-04-23 13:55:30 +02:00
|
|
|
base_path: .
|
2021-06-16 11:52:15 +02:00
|
|
|
compiler: {rom.compiler}
|
|
|
|
find_file_boundaries: True
|
2022-05-05 16:08:16 +02:00
|
|
|
header_encoding: {rom.header_encoding}
|
2021-06-16 11:52:15 +02:00
|
|
|
# platform: n64
|
2022-06-12 17:33:32 +02:00
|
|
|
# undefined_funcs_auto: True
|
2021-06-16 11:52:15 +02:00
|
|
|
# undefined_funcs_auto_path: undefined_funcs_auto.txt
|
2022-06-12 17:33:32 +02:00
|
|
|
# undefined_syms_auto: True
|
2021-06-16 11:52:15 +02:00
|
|
|
# undefined_syms_auto_path: undefined_syms_auto.txt
|
|
|
|
# symbol_addrs_path: symbol_addrs.txt
|
|
|
|
# undefined_syms_path: undefined_syms.txt
|
|
|
|
# asm_path: asm
|
|
|
|
# src_path: src
|
|
|
|
# build_path: build
|
|
|
|
# extensions_path: tools/splat_ext
|
2022-06-12 17:33:32 +02:00
|
|
|
# mips_abi_float_regs: o32
|
|
|
|
# section_order: [".text", ".data", ".rodata", ".bss"]
|
|
|
|
# auto_all_sections: [".data", ".rodata", ".bss"]
|
|
|
|
"""
|
2021-02-06 05:05:39 +01:00
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
first_section_end = find_code_length.run(rom_bytes, 0x1000, rom.entry_point)
|
2021-01-15 02:26:06 +01:00
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
segments = f"""\
|
2021-06-16 11:52:15 +02:00
|
|
|
segments:
|
2021-01-15 02:26:06 +01:00
|
|
|
- name: header
|
|
|
|
type: header
|
|
|
|
start: 0x0
|
|
|
|
- name: boot
|
|
|
|
type: bin
|
|
|
|
start: 0x40
|
|
|
|
- name: main
|
|
|
|
type: code
|
|
|
|
start: 0x1000
|
2021-06-16 11:52:15 +02:00
|
|
|
vram: 0x{rom.entry_point:X}
|
2021-04-13 09:47:52 +02:00
|
|
|
subsegments:
|
2021-01-15 02:26:06 +01:00
|
|
|
- [0x1000, asm]
|
|
|
|
- type: bin
|
2021-06-16 11:52:15 +02:00
|
|
|
start: 0x{first_section_end:X}
|
|
|
|
- [0x{rom.size:X}]
|
2022-06-12 17:33:32 +02:00
|
|
|
"""
|
2021-01-15 02:26:06 +01:00
|
|
|
|
2022-05-05 16:08:16 +02:00
|
|
|
out_file = f"{basename}.yaml"
|
|
|
|
with open(out_file, "w", newline="\n") as f:
|
|
|
|
print(f"Writing config to {out_file}")
|
2022-06-12 17:33:32 +02:00
|
|
|
f.write(header)
|
|
|
|
f.write(segments)
|
2021-01-15 02:26:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = parser.parse_args()
|
2022-05-05 16:08:16 +02:00
|
|
|
main(Path(args.rom))
|