mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-16 21:05:12 +00:00
Match retail BSS ordering (#1927)
* Match retail BSS ordering * Revert moving some global variables to headers * Adjust block numbers after header changes * Fix debug build * Overlay bss ordering * Fix BSS ordering after header changes * gc-eu-mq OK * Implement preprocessor for #pragma increment_block_number * Transfer usage comment from reencode.sh * Use temporary directory instead of temporary file * Move ColChkMassType back
This commit is contained in:
parent
a94661054e
commit
f643499462
25 changed files with 224 additions and 165 deletions
66
tools/preprocess.py
Executable file
66
tools/preprocess.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: © 2024 ZeldaRET
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# Usage: preprocess.py [compile command minus input file...] [single input file]
|
||||
# Preprocess a C file to:
|
||||
# * Re-encode from UTF-8 to EUC-JP (the repo uses UTF-8 for text encoding, but
|
||||
# the strings in the ROM are encoded in EUC-JP)
|
||||
# * Replace `#pragma increment_block_number N` with `N` fake structs for
|
||||
# controlling BSS ordering
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
import tempfile
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def fail(message):
|
||||
print(message, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def process_file(filename, input, output):
|
||||
output.write(f'#line 1 "{filename}"\n')
|
||||
for i, line in enumerate(input, start=1):
|
||||
if line.startswith("#pragma increment_block_number"):
|
||||
parts = line.split()
|
||||
if len(parts) != 3:
|
||||
fail(
|
||||
f"{filename}:{i}: increment_block_number must be followed by an integer"
|
||||
)
|
||||
try:
|
||||
amount = int(parts[2])
|
||||
except ValueError:
|
||||
fail(
|
||||
f"{filename}:{i}: increment_block_number must be followed by an integer"
|
||||
)
|
||||
# Write fake structs for BSS ordering
|
||||
for j in range(amount):
|
||||
output.write(f"struct DummyStruct_{i:05}_{j:03};\n")
|
||||
output.write(f'#line {i + 1} "{filename}"\n')
|
||||
else:
|
||||
output.write(line)
|
||||
|
||||
|
||||
def main():
|
||||
filename = Path(sys.argv[-1])
|
||||
with tempfile.TemporaryDirectory(prefix="oot_") as tmpdir:
|
||||
tmpfile = Path(tmpdir) / filename.name
|
||||
|
||||
with open(filename, mode="r", encoding="utf-8") as input:
|
||||
with open(tmpfile, mode="w", encoding="euc-jp") as output:
|
||||
process_file(filename, input, output)
|
||||
|
||||
compile_command = sys.argv[1:-1] + ["-I", filename.parent, tmpfile]
|
||||
process = subprocess.run(compile_command)
|
||||
return process.returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(1)
|
Loading…
Add table
Add a link
Reference in a new issue