Update toolchain, add pch

This commit is contained in:
mateusfavarin 2023-02-08 18:00:17 -03:00
parent e06ba2a4d8
commit a0e3058b01
9 changed files with 62 additions and 31 deletions

View File

@ -11,6 +11,7 @@ __pycache__/
*.o
*.dep
*.bin
*.gch
# ISO files
*.cue

View File

@ -6,7 +6,8 @@
"optimization": 4,
"debug": 1,
"psyq": 0,
"8mb": 1
"8mb": 1,
"pch": "common.h"
},
"versions":
[

View File

@ -55,8 +55,9 @@ COMP_SOURCE = DEBUG_FOLDER + "source.txt"
TEXTURES_FOLDER = "newtex/"
TEXTURES_OUTPUT_FOLDER = TEXTURES_FOLDER + "output/"
GCC_MAP_FILE = DEBUG_FOLDER + "mod.map"
GCC_OUT_FILE = "gcc_out.txt"
COMPILATION_RESIDUES = ["overlay.ld", MAKEFILE, "offset.txt", "comport.txt", GCC_OUT_FILE]
GCC_OUT_FILE = DEBUG_FOLDER + "gcc_out.txt"
TRIMBIN_OFFSET = DEBUG_FOLDER + "offset.txt"
COMPILATION_RESIDUES = ["overlay.ld", MAKEFILE, "comport.txt"]
REDUX_MAP_FILE = DEBUG_FOLDER + "redux.map"
CONFIG_PATH = FOLDER_DISTANCE + CONFIG_FILE
SETTINGS_PATH = FOLDER_DISTANCE + "../settings.json"
@ -164,9 +165,9 @@ def request_user_input(first_option: int, last_option: int, intro_msg: str, erro
return i
def get_build_id() -> int:
if not os.path.isfile("Makefile"):
if not os.path.isfile(MAKEFILE):
return None
with open("Makefile", "r") as file:
with open(MAKEFILE, "r") as file:
for line in file:
line = line.split()
if len(line) and line[0] == "CPPFLAGS":

View File

@ -19,6 +19,7 @@ class CompileList:
self.sym = sym
self.ignore = False
self.is_bin = False
self.pch = str()
self.min_addr = 0x80000000
self.max_addr = 0x807FFFFF if self.is_8mb() else 0x801FFFFF
self.parse_line(line)

View File

@ -1,4 +1,4 @@
from makefile import Makefile
from makefile import Makefile, clean_pch
from compile_list import CompileList, free_sections, print_errors
from syms import Syms
from redux import Redux
@ -34,9 +34,10 @@ class Main:
11 : self.redux.start_emulation,
12 : self.nops.hot_reload,
13 : self.nops.restore,
14 : self.disasm,
15 : rename_psyq_sections,
16 : self.clean_all,
14 : self.clean_pch,
15 : self.disasm,
16 : rename_psyq_sections,
17 : self.clean_all,
}
self.num_options = len(self.actions)
self.window_title = GAME_NAME + " - " + MOD_NAME
@ -48,27 +49,28 @@ class Main:
def get_options(self) -> int:
intro_msg = (
"Please select an action:\n\n"
"Mod:\n\n"
"Mod:\n"
"1 - Compile\n"
"2 - Clean\n\n"
"Iso:\n\n"
"Iso:\n"
"3 - Extract Iso\n"
"4 - Build Iso\n"
"5 - Generate xdelta patch\n"
"6 - Clean Build\n\n"
"PCSX-Redux:\n\n"
"PCSX-Redux:\n"
"7 - Hot Reload Mod\n"
"8 - Restore Mod\n"
"9 - Replace Textures\n"
"10 - Restore Textures\n"
"11 - Start Emulation\n\n"
"NotPSXSerial:\n\n"
"NotPSXSerial:\n"
"12 - Hot Reload\n"
"13 - Restore\n\n"
"Misc:\n\n"
"14 - Disassemble Elf\n"
"15 - Rename PSYQ Sections\n"
"16 - Clean All\n"
"General:\n"
"14 - Clean Precompiled Header\n"
"15 - Disassemble Elf\n"
"16 - Rename PSYQ Sections\n"
"17 - Clean All\n"
)
error_msg = "ERROR: Wrong option. Please type a number from 1-" + str(self.num_options) + ".\n"
return request_user_input(first_option=1, last_option=self.num_options, intro_msg=intro_msg, error_msg=error_msg)
@ -103,9 +105,13 @@ class Main:
for file in COMPILATION_RESIDUES:
delete_file(file)
def clean_pch(self) -> None:
clean_pch()
def clean_all(self) -> None:
self.mkpsxiso.clean(all=True)
self.clean()
self.clean_pch()
def replace_textures(self) -> None:
create_directory(TEXTURES_OUTPUT_FOLDER)

View File

@ -1,16 +1,25 @@
from compile_list import CompileList
from common import create_directory, request_user_input, rename_psyq_sections, delete_file, cli_clear, GCC_OUT_FILE, COMP_SOURCE, GAME_INCLUDE_PATH, FOLDER_DISTANCE, SRC_FOLDER, DEBUG_FOLDER, OUTPUT_FOLDER, BACKUP_FOLDER, OBJ_FOLDER, DEP_FOLDER, GCC_MAP_FILE, REDUX_MAP_FILE, CONFIG_PATH, PSYQ_RENAME_CONFIRM_FILE
from common import create_directory, request_user_input, rename_psyq_sections, delete_file, cli_clear, MAKEFILE, TRIMBIN_OFFSET, GCC_OUT_FILE, COMP_SOURCE, GAME_INCLUDE_PATH, FOLDER_DISTANCE, SRC_FOLDER, DEBUG_FOLDER, OUTPUT_FOLDER, BACKUP_FOLDER, OBJ_FOLDER, DEP_FOLDER, GCC_MAP_FILE, REDUX_MAP_FILE, CONFIG_PATH, PSYQ_RENAME_CONFIRM_FILE
import re
import json
import os
import shutil
from time import time
def clean_pch() -> None:
with open(CONFIG_PATH, "r") as file:
data = json.load(file)["compiler"]
if "pch" in data:
pch = data["pch"] + ".gch"
delete_file(GAME_INCLUDE_PATH + pch)
class Makefile:
def __init__(self, build_id: int, sym_file: list[str]) -> None:
self.build_id = build_id
self.sym_file = sym_file
self.cl = list()
self.pch = str()
self.load_config()
def load_config(self) -> None:
@ -27,6 +36,8 @@ class Makefile:
self.compiler_flags += " -g"
self.use_psyq_str = str(data["psyq"] != 0).lower()
self.use_psyq = data["psyq"] != 0
if "pch" in data:
self.pch = data["pch"] + ".gch"
def add_cl(self, cl: CompileList) -> None:
self.cl.append(cl)
@ -100,7 +111,8 @@ class Makefile:
with open(filename, "w") as file:
file.write(buffer)
with open("offset.txt", "w") as file:
create_directory(DEBUG_FOLDER)
with open(TRIMBIN_OFFSET, "w") as file:
file.write(offset_buffer)
return filename
@ -141,10 +153,12 @@ class Makefile:
buffer += "SRCINCLUDEDIR = $(MODDIR)" + SRC_FOLDER + "\n"
buffer += "GAMEINCLUDEDIR = $(MODDIR)" + GAME_INCLUDE_PATH + "\n"
buffer += "EXTRA_CC_FLAGS = " + self.compiler_flags + "\n"
buffer += "PCHS = $(GAMEINCLUDEDIR)" + self.pch + "\n"
buffer += "TRIMBIN_OFFSET = $(MODDIR)" + TRIMBIN_OFFSET + "\n"
buffer += "\n"
buffer += "include " + FOLDER_DISTANCE + "../common.mk\n"
with open("Makefile", "w") as file:
with open(MAKEFILE, "w") as file:
file.write(buffer)
return True
@ -187,28 +201,30 @@ class Makefile:
def make(self) -> None:
create_directory(OUTPUT_FOLDER)
create_directory(BACKUP_FOLDER)
create_directory(DEBUG_FOLDER)
create_directory(OBJ_FOLDER)
create_directory(DEP_FOLDER)
self.restore_temp_files()
cli_clear()
print("\n[Makefile-py] Compilation started...\n")
start_time = time()
os.system("make -s -j8 > " + GCC_OUT_FILE + " 2>&1")
with open(GCC_OUT_FILE) as file:
end_time = time()
total_time = str(round(end_time - start_time, 3))
with open(GCC_OUT_FILE, "r") as file:
for line in file:
print(line)
if (not os.path.isfile("mod.map")) or (not os.path.isfile("mod.elf")):
self.move_temp_files()
self.delete_temp_files()
print("\n[Makefile-py] ERROR: compilation was not successful.\n")
print("\n[Makefile-py] ERROR: compilation was not successful. (" + total_time + "s)\n")
return
shutil.move("mod.map", DEBUG_FOLDER + "mod.map")
shutil.move("mod.elf", DEBUG_FOLDER + "mod.elf")
self.move_temp_files()
print("\n[Makefile-py] Successful compilation.\n")
print("\n[Makefile-py] Successful compilation in " + total_time + "s.\n")
pattern = re.compile(r"0x0000000080[0-7][0-9a-fA-F]{5}\s+([a-zA-Z]|_)\w*")
special_symbols = ["__heap_base", "__ovr_start", "__ovr_end", "OVR_START_ADDR"]
buffer = ""

View File

@ -38,11 +38,11 @@ DEPS += $(patsubst %.cc, %.dep,$(filter %.cc,$(SRCS)))
DEPS += $(patsubst %.c, %.dep,$(filter %.c,$(SRCS)))
DEPS += $(patsubst %.s, %.dep,$(filter %.s,$(SRCS)))
all: dep $(foreach ovl, $(OVERLAYSECTION), $(BINDIR)Overlay$(ovl))
all: pch dep $(foreach ovl, $(OVERLAYSECTION), $(BINDIR)Overlay$(ovl))
$(BINDIR)Overlay%: $(BINDIR)$(TARGET).elf
$(PREFIX)-objcopy -j $(@:$(BINDIR)Overlay%=%) -O binary $< $(BINDIR)$(TARGET)$(@:$(BINDIR)Overlay%=%)
$(PYTHON) $(TOOLSDIR)trimbin/trimbin.py $(BINDIR)$(TARGET)$(@:$(BINDIR)Overlay%=%) $(BUILDDIR)
$(PYTHON) $(TOOLSDIR)trimbin/trimbin.py $(BINDIR)$(TARGET)$(@:$(BINDIR)Overlay%=%) $(BUILDDIR) $(TRIMBIN_OFFSET)
$(BINDIR)$(TARGET).elf: $(OBJS)
ifneq ($(strip $(BINDIR)),)
@ -67,6 +67,11 @@ endif
dep: $(DEPS)
%.h.gch: %.h
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
pch: $(PCHS)
-include $(DEPS)
.PHONY: all
.PHONY: all pch dep

View File

@ -1,13 +1,13 @@
import sys
import os
def trimbin(filename: str, target_path: str) -> None:
def trimbin(filename: str, target_path: str, offset_file: str) -> None:
arr = bytearray()
with open(filename, "rb") as file:
arr = file.read()
extension = filename.split(".")[1]
with open("offset.txt", "r") as file:
with open(offset_file, "r") as file:
for line in file:
line = line.split()
if line[0] == extension:
@ -24,6 +24,6 @@ def trimbin(filename: str, target_path: str) -> None:
os.rename(filename, new_filename)
def main() -> None:
trimbin(sys.argv[1], sys.argv[2])
trimbin(sys.argv[1], sys.argv[2], sys.argv[3])
main()

View File

@ -1 +1 @@
0573eff05e921488c4cbcad921487bb90209cbfe
82dc0b08a6657d657bac458746b203ab6499b3b5