Files
HackerOoT/tools/preprocess.py
Yanis 20a0613120 Merge zeldaret/main (#106)
* 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

* Player: Document "WaitForPutAway"  (#1936)

* document put away delay

* functions.txt

* add a note on delaying indefinitely

* format

* typo

* delay -> wait for put away

* revert unintended formatting change

* add comment to struct member

* format

* fix functions.txt

* Set up gc-eu and match all code (#1938)

* Set up gc-eu and match all code

* Format

* Mark gc-eu-mq as WIP until it builds OK

* Move original/MQ map mark data to separate files

* Add #includes to .inc.c files to help out VS Code

* Use #if in spec instead of .inc.c files

* Delete disassembly data for gc-eu-mq (#1942)

* Player Docs: "sUpperBodyIsBusy" (#1944)

* document upperbodybusy

* change wording for comment and rename upperanimblendweight

* format

* review

* Fix miscategorized scenes (#1946)

* Fix miscategorized scenes

* Sort includes

* Player Docs: Action Interrupt (#1947)

* document action interrupt

* format

* new function comment

* format

* add a note about items

* format

* Add gc-eu-mq to CI (#1943)

* Add gc-eu-mq to CI

* Give up on scripting

* Revert quotes changes

* Player Docs: Name some high level update calls (#1593)

* name some low hanging fruit

* revert burn and shock, doing in seperate pr

* add some function comments

* yaw func

* adjust comment

* some review

* unname UpdateZTarget

* Player_DetectRumbleSecrets

* fix dive do action name

* Player Docs: Control stick buffers (#1945)

* name vars and add enum

* name some spin attack stuff

* fix right and left

* forward/backward

* format

* fix retail bss

* sControlStickWorldYaw

* Force string.o to be in boot for gcc builds (#1948)

In retail builds, memcpy is linked in code, not boot, but GCC likes to call memcpy when copying structs so currently GCC builds immediately crash in __osInitialize_common.

* Rename yDistToWater -> depthInWater (#1950)

* Rename yDistToWater -> yDistUnderWater

* yDistUnderWater -> depthInWater

* Check baserom hash before decompression (#1952)

* Remove Cygwin support (#1951)

* update installation docs

* setup fixes

* tabs

---------

Co-authored-by: cadmic <cadmic24@gmail.com>
Co-authored-by: fig02 <fig02srl@gmail.com>
2024-05-10 18:21:07 +02:00

67 lines
2.0 KiB
Python
Executable File

#!/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)