2020-04-25 00:12:46 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
asm_dir = script_dir + "/asm/"
|
|
|
|
|
2020-04-25 07:13:22 +02:00
|
|
|
|
2020-04-25 22:35:26 +02:00
|
|
|
def replace_move_daddu(match):
|
2020-04-25 07:13:22 +02:00
|
|
|
match = match.group()
|
|
|
|
match = re.sub("\\s+", " ", match)
|
|
|
|
match_split = match.split(" ")
|
|
|
|
ret = "daddu " + match_split[1] + " " + match_split[2] + ", $zero"
|
|
|
|
return ret
|
|
|
|
|
2020-04-25 00:12:46 +02:00
|
|
|
|
2020-04-26 08:34:37 +02:00
|
|
|
def replace_move_addu(match):
|
|
|
|
match = match.group()
|
|
|
|
match = re.sub("\\s+", " ", match)
|
|
|
|
match_split = match.split(" ")
|
|
|
|
ret = "addu " + match_split[1] + " " + match_split[2] + ", $zero"
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2020-04-25 22:35:26 +02:00
|
|
|
def replace_move_or(match):
|
|
|
|
match = match.group()
|
|
|
|
match = re.sub("\\s+", " ", match)
|
|
|
|
match_split = match.split(" ")
|
|
|
|
ret = "or " + match_split[1] + " " + match_split[2] + ", $zero"
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2020-04-26 08:34:37 +02:00
|
|
|
adds = ["4a140", "4a1b0"]
|
|
|
|
ors = ["4a360"]
|
|
|
|
|
|
|
|
range_start = int("3bde0", 16)
|
|
|
|
range_end = int("48be0", 16)
|
|
|
|
|
2020-04-25 00:12:46 +02:00
|
|
|
for root, dirs, files in os.walk(asm_dir):
|
|
|
|
for file in files:
|
|
|
|
if file.endswith(".s"):
|
2020-04-26 08:34:37 +02:00
|
|
|
dumb_split = file.split("_")
|
|
|
|
if len(dumb_split) > 2:
|
|
|
|
file_num = dumb_split[1]
|
2020-05-07 06:23:38 +02:00
|
|
|
try:
|
|
|
|
test = int(file_num, 16)
|
|
|
|
except ValueError:
|
|
|
|
file_num = ""
|
2020-04-26 08:34:37 +02:00
|
|
|
else:
|
|
|
|
file_num = ""
|
2020-04-25 00:12:46 +02:00
|
|
|
with open(os.path.join(root, file)) as f:
|
|
|
|
file_text_orig = f.read()
|
|
|
|
file_text = file_text_orig
|
2020-04-25 07:13:22 +02:00
|
|
|
|
|
|
|
# Fix instructions
|
2020-04-26 08:34:37 +02:00
|
|
|
if file == "boot.s" or file_num in ors:
|
2020-04-25 22:35:26 +02:00
|
|
|
file_text = re.sub("move\\s+\\$.+,\\s\\$.+", replace_move_or, file_text)
|
2020-04-26 08:34:37 +02:00
|
|
|
elif file_num != "" and ((range_start <= int(file_num, 16) <= range_end) or file_num in adds):
|
|
|
|
file_text = re.sub("move\\s+\\$.+,\\s\\$.+", replace_move_addu, file_text)
|
2020-04-25 22:35:26 +02:00
|
|
|
else:
|
|
|
|
file_text = re.sub("move\\s+\\$.+,\\s\\$.+", replace_move_daddu, file_text)
|
2020-04-25 07:13:22 +02:00
|
|
|
|
2020-04-25 00:12:46 +02:00
|
|
|
if file_text != file_text_orig:
|
|
|
|
with open(os.path.join(root, file), "w") as f:
|
2020-04-25 07:13:22 +02:00
|
|
|
f.write(file_text)
|