Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion ASM/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@
parser.add_argument('--pj64sym', help="Output path for Project64 debugging symbols")
parser.add_argument('--compile-c', action='store_true', help="Recompile C modules. This is the default")
parser.add_argument('--no-compile-c', action='store_true', help="Do not recompile C modules")
parser.add_argument('--compile-wii', action='store_true', help="Recompile Wii VC modules. Requires devkitpro toolchain.")
parser.add_argument('--dump-obj', action='store_true', help="Dumps extra object info for debugging purposes. Does nothing with --no-compile-c")
parser.add_argument('--diff-only', action='store_true', help="Creates diff output without running armips")
parser.add_argument('--mips-binutils-prefix', type=str, default="mips64-", help="Use a different prefix for N64 toolchain")
parser.add_argument('--mips-binutils-prefix', type=str, default="mips64-ultra-elf-", help="Use a different prefix for N64 toolchain")

args = parser.parse_args()
pj64_sym_path = args.pj64sym
compile_c = not args.no_compile_c
compile_wii = args.compile_wii
dump_obj = args.dump_obj
diff_only = args.diff_only
mips_binutils_prefix = args.mips_binutils_prefix

root_dir = os.path.dirname(os.path.realpath(__file__))
wii_src_dir = os.path.join(root_dir, 'wiivc')
wii_bin_dir = os.path.join(wii_src_dir, 'bin')
wii_out_dir = os.path.join(root_dir, 'build')
gzinject_dir = os.path.join(root_dir, '..', 'bin', 'gzinject')
tools_dir = os.path.join(root_dir, 'tools')
# Makes it possible to use the "tools" directory as the prefix for the toolchain
tools_bin_dir = os.path.join(tools_dir, 'bin')
Expand All @@ -51,6 +57,45 @@
clist.append('RUN_OBJDUMP=1')
call(clist)

if compile_wii:
os.chdir(wii_src_dir)
clist = ['make','all']
call(clist)
regions = ['usa','jpn']
gzi_branches = {
'usa': '0304 0004E320',
'jpn': '0304 0004E304',
}
def calculate_branch_bytes(region: str) -> str:
gzi_vram = {
'usa': 0x80052d60,
'jpn': 0x80052d44,
}
target_addr = 0
with open(os.path.join(wii_src_dir, 'bin',region,f'mwserial-{region}.map'), 'r') as f:
for line in f.readlines():
if line.endswith(' frameEnd_hook\n'):
target_addr = int(line.replace('frameEnd_hook','').strip(), 16)
instruction_addr = gzi_vram[region]
offset = ((target_addr - instruction_addr) >> 2) & 0x00FFFFFF
instruction = (18 << 26) | (offset << 2) | 0b1
return f'{instruction:08X}'
for region in regions:
bin_file = os.path.join(wii_bin_dir, region, f"mwserial-{region}.bin")
if os.path.exists(bin_file):
os.replace(bin_file, os.path.join(wii_out_dir, f"wiivc_{region}.bin"))
gzi_file = os.path.join(gzinject_dir, f'ootr_{region}.gzi')
# Has to be read in byte mode to handle Windows-style \r\n line endings
with open(gzi_file, 'r+b') as f:
while line_bytes := f.readline():
# update branch to frameEnd_hook() if it shifted
line = line_bytes.decode()
if line.startswith(gzi_branches[region]):
f.seek(f.tell() - len(line_bytes))
new_line = f'{gzi_branches[region]} {calculate_branch_bytes(region)}'
f.write(new_line.encode())
break

if not diff_only:
os.chdir(run_dir + '/src')
call(['armips', '-sym2', '../build/asm_symbols.txt', 'build.asm'])
Expand Down
Loading