7070 "src/text_00310BE8.cpp"
7171]
7272
73+ UNCOMPATIBLE_SN_AS_SPLITS = [
74+ "src/text_002421F8.cpp" ,
75+ "src/text_0031FC50.cpp" ,
76+ "src/text_00330930.cpp" ,
77+ "src/text_00334BD0.cpp"
78+ ]
79+
7380COMPLETED_SPLITS = [
7481]
7582
@@ -96,7 +103,7 @@ def clean():
96103 shutil .rmtree ("target" , ignore_errors = True )
97104 shutil .rmtree (BUILD_DIR , ignore_errors = True )
98105
99- def ninja_build (linker_entries : List [LinkerEntry ], objdiff_mode : bool , skip_checksum : bool ):
106+ def ninja_build (linker_entries : List [LinkerEntry ], objdiff_mode : bool , skip_checksum : bool , use_sn_as : bool = False ):
100107
101108 if objdiff_mode :
102109 ninja_file = ninja_syntax .Writer (open ("matching.ninja" , "w" , encoding = "utf-8" ), width = 9999 )
@@ -168,10 +175,17 @@ def ninja_build(linker_entries: List[LinkerEntry], objdiff_mode: bool, skip_chec
168175
169176 split_state = ""
170177
171- for split in COMPLETED_SPLITS :
172- if split == str (entry .src_paths [0 ]):
173- split_state = "-snas"
174- break
178+ if use_sn_as :
179+ split_state = "-snas"
180+ for split in UNCOMPATIBLE_SN_AS_SPLITS :
181+ if split == str (entry .src_paths [0 ]):
182+ split_state = ""
183+ break
184+ else :
185+ for split in COMPLETED_SPLITS :
186+ if split == str (entry .src_paths [0 ]):
187+ split_state = "-snas"
188+ break
175189
176190 # Matching file
177191 match seg .type :
@@ -279,6 +293,58 @@ def ninja_build(linker_entries: List[LinkerEntry], objdiff_mode: bool, skip_chec
279293 else :
280294 print ("Skipping checksum step" )
281295
296+ COMMENT_PART = r"\/\* (.+) ([0-9A-Z]{2})([0-9A-Z]{2})([0-9A-Z]{2})([0-9A-Z]{2}) \*\/"
297+ INSTRUCTION_PART = r"(\b(vadda\.xyz)\b.*)"
298+ OPCODE_PATTERN = re .compile (f"{ COMMENT_PART } { INSTRUCTION_PART } " )
299+
300+ PROBLEMATIC_FUNCS = {
301+ "func_001F9CD0" ,
302+ "func_00234A28" ,
303+ "func_00147650" ,
304+ "func_00110A08" ,
305+ "func_001134A0" ,
306+ "func_00113B10" ,
307+ "func_00116250" ,
308+ "func_0017A110" ,
309+ "func_00131970" ,
310+ "func_00169B38" ,
311+ "func_001E86F8" ,
312+ "func_00104DA0" ,
313+ "func_0017EBF8" ,
314+ "func_002EAD28" ,
315+ "func_002EA480" ,
316+ "func_002EBFC8" ,
317+ "func_002EB508" ,
318+ "func_002EB958" ,
319+ "func_002E55A8__17TurnFlexAnimation" ,
320+ "func_002E3E60" ,
321+ "func_002E1680" ,
322+ "func_002886B0"
323+ }
324+
325+ def replace_instructions_with_opcodes (asm_folder : Path ) -> None :
326+ nm_folder = ROOT / asm_folder / "nonmatchings"
327+ for p in nm_folder .rglob ("*.s" ):
328+
329+ if p .stem not in PROBLEMATIC_FUNCS :
330+ continue
331+
332+ with p .open ("r" ) as file :
333+ content = file .read ()
334+
335+ if re .search (OPCODE_PATTERN , content ):
336+ # Reference found
337+ # Embed the opcode, we have to swap byte order for correct endianness
338+ content = re .sub (
339+ OPCODE_PATTERN ,
340+ r"/* \1 \2\3\4\5 */ .word 0x\5\4\3\2 /* \6 */" ,
341+ content ,
342+ )
343+
344+ # Write the updated content back to the file
345+ with p .open ("w" ) as file :
346+ file .write (content )
347+
282348def main ():
283349 parser = argparse .ArgumentParser (description = "Configure the project" )
284350 parser .add_argument (
@@ -299,6 +365,12 @@ def main():
299365 help = "Skip the checksum step" ,
300366 action = "store_true" ,
301367 )
368+ parser .add_argument (
369+ "-sn_as" ,
370+ "--sn_assembler" ,
371+ help = "Build the entire game and engine using the alternative SN Assembler" ,
372+ action = "store_true" ,
373+ )
302374 parser .add_argument (
303375 "-diff" ,
304376 "--objdiff" ,
@@ -310,6 +382,7 @@ def main():
310382 do_clean = (args .clean or args .clean_only ) or False
311383 do_skip_checksum = args .skip_checksum or False
312384 do_objects = args .objdiff or False
385+ use_sn_as = args .sn_assembler or False
313386
314387 if do_clean :
315388 clean ()
@@ -319,11 +392,13 @@ def main():
319392
320393 split .main ([YAML_FILE ], modes = "all" , verbose = False , disassemble_all = True , make_full_disasm_for_code = do_objects )
321394
322- ninja_build (split .linker_writer .entries , do_objects , do_skip_checksum )
395+ ninja_build (split .linker_writer .entries , do_objects , do_skip_checksum , use_sn_as )
323396
324397 if do_objects :
325398 subprocess .call (["ninja" , "-f" , "objdiff.ninja" ])
326399
400+ if use_sn_as :
401+ replace_instructions_with_opcodes (split .config ["options" ]["asm_path" ])
327402
328403if __name__ == "__main__" :
329404 main ()
0 commit comments