mirror of
https://github.com/izzy2lost/Diddy-Kong-Racing.git
synced 2026-06-19 01:16:26 -07:00
Splat merge (#470)
* First pass * Fix n64crc and add submodules properly * Fix other versions * Match func_8005B818 for v80 code. * Formatting * Fix build for JPN in last commit. Still broken in post v77 roms though. * Fix builds for other versions. * Match load_menu_text for other versions. * Fix progress script * update m2c * Modify asset tools to remove the LD script code. * Fix asm file macro inclue * Get a working splat version for us_1.0 to build from the assets tool. * update asm differ * Update tools again * Fix the makefile to only compile assets when requested. This will build all versions successfully, and compile assets for us_1.0 when requested. * First round of suggestions * Small cleanup * Fix the gcc_generate.py path. * Make entrypointThreadStack * Small addition to the last commit * "Fix" score script. Still need to fix the score values themselves, but at least it runs and is kind of close. * Much closer matching score script * Fix the splat version due to a breaking change in 0.33.0 for this repo for now. * Fix the main function name * Add gitignore entries * Fix the padding problem to be handled by objcopy instead of a binary pad from splat. * Update the README and change dependencies to setup. * Have a hasm header that can be tweaked. * Still calculate the checksum on no_verify builds or they won't work. * Add support for boot_custom.bin * Fix custom boot ld code. * Fix score script * Fix gcc building. * Update m2c * Fix warning, stop ignoring mod assets, and add some handy make rules. * Uggh, serves me right for not testing. * First stab at modifiable entrypoint. * Fix typo, and small README change * Stop n64crd from defaulting to returning 6105, so we can properly fail if the CIC checksum fails. Also, fix the * Extract custom boot script * Update automated scripts. * Woops, fixed the MAXCONTROLLERS thing now. * Add the method for building binutils back. Sorry! * Only use -m32 when the longbit says we're on a 64 bit platform. * Woops.... * Hopefully fix arm detection for raspi ido downloads.
This commit is contained in:
@@ -2,4 +2,3 @@
|
||||
/dkr_assets_tool
|
||||
/dkr_assets_tool_classes/_build
|
||||
/binutils
|
||||
/ido5.3_recomp
|
||||
|
||||
+22
-9
@@ -9,14 +9,23 @@ CXXFLAGS := -I . -I dkr_assets_tool_src/ -std=c++17 $(OPT)
|
||||
LDFLAGS := -lm
|
||||
PROGRAMS := n64crc dkr_assets_tool
|
||||
|
||||
OS := $(shell uname)
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
# MacOS has a slightly different name for grep, so check to see if it needs to be used.
|
||||
ifeq ($(OS), Darwin)
|
||||
ifeq ($(UNAME_S),Windows_NT)
|
||||
$(error Native Windows is currently unsupported for building this repository, use WSL instead c:)
|
||||
else ifeq ($(UNAME_S),Darwin)
|
||||
DETECTED_OS := macos
|
||||
CXXFLAGS += -I/opt/homebrew/include
|
||||
LDFLAGS += -I/opt/homebrew/lib -lpcre2-8
|
||||
else
|
||||
else ifeq ($(UNAME_S),Linux)
|
||||
DETECTED_OS := linux
|
||||
CXXFLAGS += -Werror -Wall $(IGNORE_W_ERRORS) -lpcre2-8
|
||||
UNAME_P := $(shell uname -p)
|
||||
# If we detect arm as a platform for linux, but not mac, we'll make this -arm to download that version (Mostly used for raspi)
|
||||
ifneq ($(filter arm%,$(UNAME_P)),)
|
||||
DETECTED_OS := linux-arm
|
||||
endif
|
||||
endif
|
||||
|
||||
BUILD_DIR := dkr_assets_tool_src/_build
|
||||
@@ -26,6 +35,8 @@ ENUMS_HEADER := ../include/enums.h
|
||||
# From: https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make/18258352#18258352
|
||||
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
||||
|
||||
RECOMP_DIR := ido-recomp/$(DETECTED_OS)
|
||||
|
||||
default: all
|
||||
|
||||
n64crc_SOURCES := n64crc.c
|
||||
@@ -34,9 +45,9 @@ all: $(PROGRAMS) recomp flips
|
||||
|
||||
# make clean for flips doesn't work, so just manually delete it on a clean.
|
||||
clean:
|
||||
rm -Rf $(PROGRAMS) $(BUILD_DIR)
|
||||
@make -C ido-static-recomp clean VERSION=5.3
|
||||
rm -f Flips/flips
|
||||
$(RM) -Rf $(PROGRAMS) $(BUILD_DIR)
|
||||
$(RM) -rf $(RECOMP_DIR)
|
||||
$(RM) -f Flips/flips
|
||||
|
||||
distclean: clean
|
||||
|
||||
@@ -60,10 +71,12 @@ $(BUILD_DIR)/%.o: %.cpp
|
||||
dkr_assets_tool: $(dkr_assets_tool_OBJ_FILES)
|
||||
$(CXX) $^ -o $@ $(CXXFLAGS) $(LDFLAGS) -lpthread
|
||||
|
||||
#recomp likes to echo some strings on all calls to make, the >/dev/null will silence them.
|
||||
recomp:
|
||||
@make -C ido-static-recomp VERSION=5.3 RELEASE=1 setup >/dev/null
|
||||
@make -C ido-static-recomp VERSION=5.3 RELEASE=1 >/dev/null
|
||||
@echo "Fetching Recomp..."
|
||||
wget https://github.com/decompals/ido-static-recomp/releases/download/v1.2/ido-5.3-recomp-${DETECTED_OS}.tar.gz
|
||||
mkdir -p $(RECOMP_DIR)
|
||||
tar xf ido-5.3-recomp-${DETECTED_OS}.tar.gz -C $(RECOMP_DIR)
|
||||
$(RM) ido-5.3-recomp-${DETECTED_OS}.tar.gz
|
||||
|
||||
#Builds the CLI only version of flips. It will complain about it being debug, but this makes it much faster compile.
|
||||
flips:
|
||||
|
||||
Submodule
+1
Submodule tools/asm-differ added at 150720b883
Submodule
+1
Submodule tools/asm-processor added at b296bcca13
Submodule tools/asm_processor deleted from 92b9ec72f4
@@ -5,9 +5,6 @@
|
||||
"configs_subpath" : "extract-ver/",
|
||||
"include_subpath" : "include/",
|
||||
"asm_subpath" : "asm/",
|
||||
"src_subpath" : "src/",
|
||||
"lib_asm_subpath" : "lib/asm/",
|
||||
"lib_src_subpath" : "lib/src/",
|
||||
"build_subpath" : "build/",
|
||||
"data_subpath" : "data/",
|
||||
"model_scale": 0.001,
|
||||
|
||||
@@ -173,7 +173,7 @@ uint8_t *BuildMisc::_build_magic_codes(BuildInfo &info, size_t &outDataSize) {
|
||||
}
|
||||
|
||||
if(_settings.debugBuildKeepUncompressed) {
|
||||
fs::path unencryptedCheatsPath = _settings.pathToBuild / _settings.dkrVersion / "debug/cheats" / info.dstPath.filename();
|
||||
fs::path unencryptedCheatsPath = _settings.pathToBuild / "debug/cheats" / info.dstPath.filename();
|
||||
FileHelper::write_binary_file(out, outDataSize, unencryptedCheatsPath, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ BuildObjectMap::BuildObjectMap(DkrAssetsSettings &settings, BuildInfo &info) : _
|
||||
|
||||
if(_settings.debugBuildKeepUncompressed) {
|
||||
// Have the uncompressed binary in a seperate directory in the build folder.
|
||||
fs::path outUncompressedPath = _settings.pathToBuild / _settings.dkrVersion / "debug/objectMaps" / (_info.dstPath.stem().string() + ".bin");
|
||||
fs::path outUncompressedPath = _settings.pathToBuild / "debug/objectMaps" / (_info.dstPath.stem().string() + ".bin");
|
||||
FileHelper::write_binary_file(out, outUncompressedPath, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ BuildTexture::BuildTexture(DkrAssetsSettings &settings, BuildInfo &info) : _sett
|
||||
|
||||
if(_settings.debugBuildKeepUncompressed) {
|
||||
// Have the uncompressed binary in a seperate directory in the build folder.
|
||||
fs::path outUncompressedPath = _settings.pathToBuild / _settings.dkrVersion / "debug/textures" / (_info.dstPath.stem().string() + ".bin");
|
||||
fs::path outUncompressedPath = _settings.pathToBuild / "debug/textures" / (_info.dstPath.stem().string() + ".bin");
|
||||
FileHelper::write_binary_file(out, outUncompressedPath, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ void WritableAsmInclude::write_include(std::string filepath) {
|
||||
_out << ".include \"" << filepath << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void WritableAsmInclude::write_section(std::string section) {
|
||||
_out << ".section ." << section << std::endl;
|
||||
}
|
||||
|
||||
void WritableAsmInclude::write_binary_include(std::string filepath) {
|
||||
_out << ".incbin \"" << filepath << "\"" << std::endl;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
void write_word_with_comment(const std::string &value, const char *comment);
|
||||
|
||||
void write_include(std::string filepath);
|
||||
void write_section(std::string section);
|
||||
void write_binary_include(std::string filepath);
|
||||
|
||||
void write_global_label(const std::string &label, bool align=false);
|
||||
|
||||
@@ -15,9 +15,6 @@ const std::string DEFAULT_ASSETS_SUBPATH = "assets/";
|
||||
const std::string DEFAULT_CONFIGS_SUBPATH = "extract-ver/";
|
||||
const std::string DEFAULT_INCLUDE_SUBPATH = "include/";
|
||||
const std::string DEFAULT_ASM_SUBPATH = "asm/";
|
||||
const std::string DEFAULT_SRC_SUBPATH = "src/";
|
||||
const std::string DEFAULT_LIB_ASM_SUBPATH = "lib/asm/";
|
||||
const std::string DEFAULT_LIB_SRC_SUBPATH = "lib/src/";
|
||||
const std::string DEFAULT_DATA_SUBPATH = "data/";
|
||||
const std::string DEFAULT_BUILD_SUBPATH = "build/";
|
||||
const std::string DEFAULT_CACHE_SUBPATH = ".cache/";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// Some paths to find if a directory is considered to be the "root" of the decomp.
|
||||
const std::vector<fs::path> REPO_ROOT_FIND_PATHS = {
|
||||
"src",
|
||||
"lib",
|
||||
"libultra",
|
||||
"include",
|
||||
"baseroms",
|
||||
"README.md"
|
||||
@@ -28,9 +28,6 @@ struct DkrAssetsSettings {
|
||||
fs::path pathToConfigs;
|
||||
fs::path pathToInclude;
|
||||
fs::path pathToAsm;
|
||||
fs::path pathToSrc;
|
||||
fs::path pathToLibAsm;
|
||||
fs::path pathToLibSrc;
|
||||
fs::path pathToData;
|
||||
fs::path pathToBuild;
|
||||
fs::path pathToCache;
|
||||
@@ -54,9 +51,6 @@ struct DkrAssetsSettings {
|
||||
"\n Configs Path: ", pathToConfigs,
|
||||
"\n Include Path: ", pathToInclude,
|
||||
"\n ASM Path: ", pathToAsm,
|
||||
"\n Src Path: ", pathToSrc,
|
||||
"\n Lib ASM Path: ", pathToLibAsm,
|
||||
"\n Lib Src Path: ", pathToLibSrc,
|
||||
"\n Data Path: ", pathToData,
|
||||
"\n Build Path: ", pathToBuild,
|
||||
"\n Model Scale: ", modelScale,
|
||||
@@ -126,15 +120,9 @@ struct DkrAssetsSettings {
|
||||
std::string localModAssetsPath;
|
||||
|
||||
_load_string_from_ptr(localAsmPath, "/asm_subpath", DEFAULT_ASM_SUBPATH);
|
||||
_load_string_from_ptr(localSrcPath, "/src_subpath", DEFAULT_SRC_SUBPATH);
|
||||
_load_string_from_ptr(localLibAsmPath, "/lib_asm_subpath", DEFAULT_LIB_ASM_SUBPATH);
|
||||
_load_string_from_ptr(localLibSrcPath, "/lib_src_subpath", DEFAULT_LIB_SRC_SUBPATH);
|
||||
_load_string_from_ptr(localModAssetsPath, "/mod_assets_subpath", DEFAULT_MOD_ASSETS_SUBPATH);
|
||||
|
||||
_format_subpath(pathToAsm, pathToRepo, localAsmPath);
|
||||
_format_subpath(pathToSrc, pathToRepo, localSrcPath);
|
||||
_format_subpath(pathToLibAsm, pathToRepo, localLibAsmPath);
|
||||
_format_subpath(pathToLibSrc, pathToRepo, localLibSrcPath);
|
||||
_format_subpath(pathToModAssets, pathToMods, localModAssetsPath);
|
||||
|
||||
// Build subdirectories
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "ld.h"
|
||||
|
||||
#include "helpers/fileHelper.h"
|
||||
|
||||
const size_t INDENT_AMOUNT = 4; // Indent by 4 spaces
|
||||
|
||||
WritableLD::WritableLD(DkrAssetsSettings &settings) : _settings(settings) {
|
||||
}
|
||||
|
||||
WritableLD::~WritableLD() {
|
||||
}
|
||||
|
||||
void WritableLD::write_comment(const char *text) {
|
||||
_out << _indent << "/* " << text << " */" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_include(const char *text) {
|
||||
_out << _indent << "#include \"" << text << "\"" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_arch(const char *archName) {
|
||||
_out << _indent << "OUTPUT_ARCH (" << archName << ")" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_rom_pos_at(const char *value) {
|
||||
_out << _indent << "romPos = " << value << ";" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_add_to_rom_pos(const char *value) {
|
||||
_out << _indent << "romPos += " << value << ";" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_assignment(const char *var, const char *value) {
|
||||
_out << _indent << var << " = " << value << ";" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_section_header(const char *name, const char *ramPos, const char *romPos, const LD_SUBALIGN subalign) {
|
||||
_out << _indent << "." << name << " " << ramPos << " : AT(" << romPos << ")";
|
||||
if(subalign != LD_SUBALIGN::NONE) {
|
||||
_out << " SUBALIGN(" << subalign << ")";
|
||||
}
|
||||
_out << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_raw(const char *text) {
|
||||
_out << _indent << text;
|
||||
}
|
||||
|
||||
void WritableLD::write_raw_line(const char *text) {
|
||||
_out << _indent << text << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_raw_line(const std::string text) {
|
||||
write_raw_line(text.c_str());
|
||||
}
|
||||
|
||||
void WritableLD::write_open_brace() {
|
||||
_out << _indent << "{" << std::endl;
|
||||
_indent.append(INDENT_AMOUNT, ' '); // Add 4 spaces to the indent
|
||||
}
|
||||
|
||||
void WritableLD::write_close_brace() {
|
||||
if (_indent.size() > INDENT_AMOUNT) {
|
||||
_indent.resize(_indent.size() - INDENT_AMOUNT); // Remove 4 spaces from the indent
|
||||
} else {
|
||||
_indent.clear();
|
||||
}
|
||||
_out << _indent << "}" << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::write_newline() {
|
||||
_out << std::endl;
|
||||
}
|
||||
|
||||
void WritableLD::save(const std::string &filepath) {
|
||||
std::string ldText = _out.str();
|
||||
FileHelper::write_text_file_if_changed(ldText, filepath, true);
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "misc/settings.hpp"
|
||||
|
||||
enum LD_SUBALIGN {
|
||||
NONE = 0,
|
||||
ALIGN4 = 4,
|
||||
ALIGN8 = 8,
|
||||
ALIGN16 = 16
|
||||
};
|
||||
|
||||
// Creates a read-only linker
|
||||
class WritableLD {
|
||||
public:
|
||||
WritableLD(DkrAssetsSettings &settings);
|
||||
~WritableLD();
|
||||
|
||||
void write_comment(const char *text);
|
||||
void write_include(const char *text);
|
||||
void write_arch(const char *archName);
|
||||
void write_raw(const char *text);
|
||||
void write_raw_line(const char *text);
|
||||
void write_raw_line(const std::string text);
|
||||
|
||||
void write_assignment(const char *var, const char *value);
|
||||
|
||||
void write_rom_pos_at(const char *value);
|
||||
void write_add_to_rom_pos(const char *value);
|
||||
|
||||
void write_section_header(const char *name, const char *ramPos, const char *romPos, const LD_SUBALIGN subalign);
|
||||
|
||||
void write_open_brace();
|
||||
void write_close_brace();
|
||||
void write_newline();
|
||||
|
||||
|
||||
void save(const std::string &filepath);
|
||||
private:
|
||||
DkrAssetsSettings &_settings;
|
||||
|
||||
std::string _indent;
|
||||
std::stringstream _out;
|
||||
};
|
||||
@@ -21,7 +21,7 @@ AssetsAsm::AssetsAsm(DkrAssetsSettings &settings) : _settings(settings) {
|
||||
|
||||
_outFilepath = _settings.pathToAsm / "assets/assets.s";
|
||||
|
||||
_outPrefix = _settings.pathToBuild / _settings.dkrVersion / "assets/";
|
||||
_outPrefix = _settings.pathToBuild / "assets/";
|
||||
|
||||
_write();
|
||||
}
|
||||
@@ -35,7 +35,9 @@ void AssetsAsm::_write() {
|
||||
|
||||
// Includes
|
||||
_asm.write_newline();
|
||||
_asm.write_include("macros.inc");
|
||||
_asm.write_include("macro.inc");
|
||||
_asm.write_newline();
|
||||
_asm.write_section("data");
|
||||
_asm.write_newline();
|
||||
|
||||
_write_asset_sections();
|
||||
|
||||
@@ -17,358 +17,18 @@ const std::string SECTION_RODATA = "rodata";
|
||||
const std::string SECTION_BSS = "bss";
|
||||
|
||||
PreBuild::PreBuild(DkrAssetsSettings &settings) : _settings(settings) {
|
||||
_buildFolder = _settings.pathToBuild / _settings.dkrVersion;
|
||||
_buildFolder = _settings.pathToBuild;
|
||||
|
||||
// Gets rid of the starting "./" from the path.
|
||||
_buildFolder = fs::relative(_buildFolder);
|
||||
|
||||
_buildAsm = _buildFolder / "asm";
|
||||
_buildSrc = _buildFolder / "src";
|
||||
_buildLibAsm = _buildFolder / "lib/asm";
|
||||
_buildLibSrc = _buildFolder / "lib/src";
|
||||
|
||||
CompileAssets compileAssets(_settings);
|
||||
|
||||
_settings.pathToAssets /= _settings.dkrVersion;
|
||||
|
||||
AssetsAsm assetsAsm(_settings); // Generate asm/assets/assets.s
|
||||
AssetEnums assetEnums(_settings); // Generate include/asset_enums.h
|
||||
|
||||
_generate_ld();
|
||||
_generate_ucode_files();
|
||||
}
|
||||
|
||||
PreBuild::~PreBuild() {
|
||||
}
|
||||
|
||||
void PreBuild::_append_files(const std::string inPath, const std::string extension, const std::string outPath) {
|
||||
std::vector<fs::path> files = FileHelper::get_files_from_directory_with_extension(fs::path(inPath), extension);
|
||||
for(auto &p : files) {
|
||||
DebugHelper::info(p);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string _RAM_POS_REGEX = R"([\/][*]+[ \t]*RAM_POS:[ \t]*((?:0x)[0-9a-fA-F]+|(?:[Aa][Uu][Tt][Oo]))[ \t]*(?:if[ \t]*([^*]*))?[*][\/])";
|
||||
|
||||
void PreBuild::_check_file_for_ram_pos(fs::path &filepath) {
|
||||
// Only load the first 256 bytes of the file for speed reasons.
|
||||
|
||||
std::string file = FileHelper::read_text_file(filepath, 256);
|
||||
RegexMatch *match = RegexHelper::get_first_match(file, _RAM_POS_REGEX);
|
||||
if(match == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string ramPos = match->get_group(1).get_text();
|
||||
std::string condition = match->get_group(2).get_text();
|
||||
|
||||
StringHelper::make_lowercase(ramPos);
|
||||
|
||||
if(ramPos == "auto") {
|
||||
ramPos = "0x800FFFF0";
|
||||
}
|
||||
|
||||
if(!StringHelper::starts_with(ramPos, "0x")) {
|
||||
ramPos.insert(0, "0x");
|
||||
}
|
||||
|
||||
uint32_t address = static_cast<uint32_t>(std::stoul(ramPos, nullptr, 0));
|
||||
|
||||
fs::path outFilepath = filepath.lexically_relative(_settings.pathToRepo);
|
||||
outFilepath.replace_extension(".o");
|
||||
|
||||
outFilepath = _buildFolder / outFilepath;
|
||||
|
||||
_codeFilesMutex.lock();
|
||||
while(_codeFiles.find(address) != _codeFiles.end()) {
|
||||
address++; // Make sure each address is unique.
|
||||
}
|
||||
_codeFiles[address] = {
|
||||
outFilepath,
|
||||
condition
|
||||
};
|
||||
_codeFilesMutex.unlock();
|
||||
}
|
||||
|
||||
void PreBuild::_get_code_files() {
|
||||
std::vector<fs::path> allFiles;
|
||||
|
||||
FileHelper::append_files_from_directory_with_extension(_settings.pathToAsm, ".s", allFiles);
|
||||
FileHelper::append_files_from_directory_with_extension(_settings.pathToSrc, ".c", allFiles);
|
||||
FileHelper::append_files_from_directory_with_extension(_settings.pathToLibAsm, ".s", allFiles);
|
||||
FileHelper::append_files_from_directory_with_extension(_settings.pathToLibSrc, ".c", allFiles);
|
||||
|
||||
{
|
||||
ThreadPool pool(_settings.threadCount);
|
||||
for(fs::path &filepath : allFiles) {
|
||||
pool.enqueue([this, &filepath = filepath] {
|
||||
_check_file_for_ram_pos(filepath);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PreBuild::_populate_filepaths() {
|
||||
_lateDataFiles = {
|
||||
};
|
||||
_bssLibOrderFiles = {
|
||||
};
|
||||
}
|
||||
|
||||
void PreBuild::_write_files_to_section(WritableLD &ld, const std::string §ionName) {
|
||||
bool isDataSection = (sectionName == "data") || (sectionName == "rodata");
|
||||
bool isBssSection = (sectionName == "bss");
|
||||
|
||||
for (auto &file : _codeFiles) {
|
||||
std::string &path = file.second.path;
|
||||
|
||||
if(isDataSection && DataHelper::vector_has<fs::path>(_lateDataFiles, path)) {
|
||||
continue;
|
||||
} else if(isBssSection && DataHelper::vector_has<fs::path>(_bssLibOrderFiles, path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string &condition = file.second.condition;
|
||||
if(!condition.empty()) {
|
||||
ld.write_raw_line("#if " + condition);
|
||||
}
|
||||
ld.write_raw_line(path + "(." + sectionName + ");");
|
||||
if(!condition.empty()) {
|
||||
ld.write_raw_line("#endif");
|
||||
}
|
||||
}
|
||||
if(isDataSection) {
|
||||
for(fs::path &path : _lateDataFiles) {
|
||||
ld.write_raw_line(std::string(path) + "(." + sectionName + ");");
|
||||
}
|
||||
} else if(isBssSection) {
|
||||
for(fs::path &path : _bssLibOrderFiles) {
|
||||
ld.write_raw_line(std::string(path) + "(." + sectionName + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PreBuild::_write_ld_boot_section(WritableLD &ld) {
|
||||
ld.write_section_header("boot", "0", "romPos", LD_SUBALIGN::NONE);
|
||||
ld.write_open_brace(); // Open .boot
|
||||
|
||||
// TODO: Refactor to remove hardcoding.
|
||||
ld.write_raw_line(_buildFolder / "asm/boot/rom_header.o(.text);");
|
||||
ld.write_raw_line(_buildFolder / "asm/boot/rom_boot.o(.text);");
|
||||
|
||||
ld.write_close_brace(); // Close .boot
|
||||
ld.write_add_to_rom_pos("SIZEOF(.boot)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_main_section(WritableLD &ld) {
|
||||
ld.write_section_header("main", "__FUNC_RAM_START", "romPos", LD_SUBALIGN::ALIGN16);
|
||||
ld.write_open_brace(); // Open .main
|
||||
|
||||
_write_files_to_section(ld, SECTION_TEXT);
|
||||
|
||||
ld.write_close_brace(); // Close .main
|
||||
ld.write_add_to_rom_pos("SIZEOF(.main)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_ucode_text_section(WritableLD &ld) {
|
||||
ld.write_section_header("ucodeText", ".", "romPos", LD_SUBALIGN::NONE);
|
||||
ld.write_open_brace(); // Open .ucodeText
|
||||
|
||||
// TODO: Refactor to remove hardcoding.
|
||||
ld.write_raw_line(_buildFolder / "asm/assets/ucode_text.o(.text);");
|
||||
|
||||
ld.write_close_brace(); // Close .ucodeText
|
||||
ld.write_add_to_rom_pos("SIZEOF(.ucodeText)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_data_section(WritableLD &ld) {
|
||||
ld.write_section_header("data", ".", "romPos", LD_SUBALIGN::ALIGN16);
|
||||
ld.write_open_brace(); // Open .data
|
||||
|
||||
_write_files_to_section(ld, SECTION_DATA);
|
||||
|
||||
ld.write_close_brace(); // Close .data
|
||||
ld.write_add_to_rom_pos("SIZEOF(.data)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_rodata_section(WritableLD &ld) {
|
||||
ld.write_section_header("rodata", ".", "romPos", LD_SUBALIGN::ALIGN16);
|
||||
ld.write_open_brace(); // Open .rodata
|
||||
|
||||
_write_files_to_section(ld, SECTION_RODATA);
|
||||
|
||||
ld.write_close_brace(); // Close .rodata
|
||||
ld.write_add_to_rom_pos("SIZEOF(.rodata)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_ucode_data_section(WritableLD &ld) {
|
||||
ld.write_section_header("ucodeData", ".", "romPos", LD_SUBALIGN::NONE);
|
||||
ld.write_open_brace(); // Open .ucodeData
|
||||
|
||||
// TODO: Refactor to remove hardcoding.
|
||||
ld.write_raw_line(_buildFolder / "asm/assets/ucode_data.o(.text);");
|
||||
|
||||
ld.write_close_brace(); // Close .ucodeData
|
||||
ld.write_add_to_rom_pos("SIZEOF(.ucodeData)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_bss_section(WritableLD &ld) {
|
||||
// TODO: add this to ld file
|
||||
ld.write_raw_line(".bss.noload . (NOLOAD): SUBALIGN(4)");
|
||||
ld.write_open_brace(); // Open .bss
|
||||
|
||||
_write_files_to_section(ld, SECTION_BSS);
|
||||
|
||||
ld.write_close_brace(); // Close .bss
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_assets_section(WritableLD &ld) {
|
||||
ld.write_section_header("assets", "0", "romPos", LD_SUBALIGN::NONE);
|
||||
ld.write_open_brace(); // Open .assets
|
||||
|
||||
// TODO: Refactor to remove hardcoding.
|
||||
ld.write_raw_line(_buildFolder / "asm/assets/assets.o(.text);");
|
||||
|
||||
|
||||
ld.write_close_brace(); // Close .assets
|
||||
ld.write_add_to_rom_pos("SIZEOF(.assets)");
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_write_discard_section(WritableLD &ld) {
|
||||
ld.write_comment("Discard everything not specifically mentioned above.");
|
||||
|
||||
// TODO: add this to ld file
|
||||
ld.write_raw_line("/DISCARD/ :");
|
||||
ld.write_open_brace(); // Open discard
|
||||
ld.write_raw_line("*(*);");
|
||||
ld.write_close_brace(); // Close discard
|
||||
ld.write_newline();
|
||||
}
|
||||
|
||||
void PreBuild::_generate_ld() {
|
||||
_get_code_files();
|
||||
_populate_filepaths();
|
||||
|
||||
fs::path outputPath = _settings.pathToRepo / "dkr.ld";
|
||||
WritableLD ld(_settings);
|
||||
|
||||
ld.write_comment("This file is automatically generated. Any changes you make to this file will get overwritten.");
|
||||
ld.write_newline();
|
||||
|
||||
ld.write_include("config.h");
|
||||
ld.write_newline();
|
||||
|
||||
ld.write_arch("mips");
|
||||
ld.write_newline();
|
||||
|
||||
ld.write_raw_line("SECTIONS");
|
||||
ld.write_open_brace(); // Open SECTIONS
|
||||
|
||||
ld.write_rom_pos_at("0");
|
||||
|
||||
// .boot section
|
||||
_write_ld_boot_section(ld);
|
||||
|
||||
ld.write_assignment("__FUNC_RAM_START", "0x80000400");
|
||||
ld.write_assignment("__FUNC_ROM_START", "0x00001000");
|
||||
ld.write_assignment("__RAM_TO_ROM", "__FUNC_RAM_START - __FUNC_ROM_START");
|
||||
ld.write_newline();
|
||||
|
||||
// .main section
|
||||
_write_main_section(ld);
|
||||
|
||||
// .ucodeText section
|
||||
_write_ucode_text_section(ld);
|
||||
|
||||
// .data section
|
||||
_write_data_section(ld);
|
||||
|
||||
// .rodata section
|
||||
_write_rodata_section(ld);
|
||||
|
||||
// .ucodeData section
|
||||
_write_ucode_data_section(ld);
|
||||
|
||||
ld.write_assignment("__BSS_SECTION_SIZE", "SIZEOF(.bss.noload) - 32");
|
||||
ld.write_newline();
|
||||
|
||||
// .bss.noload section
|
||||
_write_bss_section(ld);
|
||||
|
||||
ld.write_assignment("__ASSETS_LUT_START", "romPos");
|
||||
// TODO: Turn `0xD0` into sizeof main asset table.
|
||||
ld.write_assignment("__ASSETS_LUT_END", "__ASSETS_LUT_START + 0xD0");
|
||||
ld.write_newline();
|
||||
|
||||
// .assets section
|
||||
_write_assets_section(ld);
|
||||
|
||||
ld.write_assignment("__ROM_END", "romPos");
|
||||
ld.write_newline();
|
||||
|
||||
_write_discard_section(ld);
|
||||
|
||||
ld.write_close_brace(); // Close SECTIONS
|
||||
|
||||
ld.save(outputPath);
|
||||
}
|
||||
|
||||
void PreBuild::_write_ucode_file_glabel(WritableAsmInclude &asmInc, std::string label, std::string path) {
|
||||
asmInc.write_global_label(label);
|
||||
asmInc.write_binary_include(_buildFolder / path);
|
||||
}
|
||||
|
||||
void PreBuild::_generate_ucode_text_file() {
|
||||
fs::path ucodeTextPath = _settings.pathToAsm / "assets/ucode_text.s";
|
||||
WritableAsmInclude text;
|
||||
|
||||
text.write_comment("This file is automatically generated. Any changes you make to this file will get overwritten.");
|
||||
text.write_newline();
|
||||
|
||||
text.write_include("macros.inc");
|
||||
text.write_newline();
|
||||
|
||||
// TODO: Refactor this!
|
||||
_write_ucode_file_glabel(text, "aspMainTextStart", "ucode/ucode_audio.bin");
|
||||
_write_ucode_file_glabel(text, "rspF3DDKRBootStart", "ucode/ucode_boot.bin");
|
||||
_write_ucode_file_glabel(text, "rspF3DDKRDramStart", "ucode/ucode_f3ddkr_dram.bin");
|
||||
_write_ucode_file_glabel(text, "rspF3DDKRFifoStart", "ucode/ucode_f3ddkr_fifo.bin");
|
||||
_write_ucode_file_glabel(text, "rspF3DDKRXbusStart", "ucode/ucode_f3ddkr_xbus.bin");
|
||||
_write_ucode_file_glabel(text, "rspUnknown2Start", "ucode/ucode_unknown_2.bin");
|
||||
|
||||
text.save(ucodeTextPath);
|
||||
}
|
||||
|
||||
void PreBuild::_generate_ucode_data_file() {
|
||||
fs::path ucodeDataPath = _settings.pathToAsm / "assets/ucode_data.s";
|
||||
WritableAsmInclude data;
|
||||
|
||||
data.write_comment("This file is automatically generated. Any changes you make to this file will get overwritten.");
|
||||
data.write_newline();
|
||||
|
||||
data.write_include("macros.inc");
|
||||
data.write_newline();
|
||||
|
||||
// TODO: Refactor this!
|
||||
_write_ucode_file_glabel(data, "aspMainDataStart", "ucode/data_audio.bin");
|
||||
_write_ucode_file_glabel(data, "rspF3DDKRDataDramStart", "ucode/data_f3ddkr_dram.bin");
|
||||
_write_ucode_file_glabel(data, "rspF3DDKRDataFifoStart", "ucode/data_f3ddkr_fifo.bin");
|
||||
_write_ucode_file_glabel(data, "rspF3DDKRDataXbusStart", "ucode/data_f3ddkr_xbus.bin");
|
||||
_write_ucode_file_glabel(data, "rspUnknown2DataStart", "ucode/data_unknown_2.bin");
|
||||
|
||||
data.save(ucodeDataPath);
|
||||
}
|
||||
|
||||
void PreBuild::_generate_ucode_files() {
|
||||
_generate_ucode_text_file();
|
||||
_generate_ucode_data_file();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "misc/settings.hpp"
|
||||
#include "prebuild/linker/ld.h"
|
||||
|
||||
#include "helpers/fileHelper.h"
|
||||
#include "helpers/asmHeader.h"
|
||||
@@ -22,33 +21,5 @@ public:
|
||||
private:
|
||||
DkrAssetsSettings &_settings;
|
||||
|
||||
std::vector<fs::path> _lateDataFiles;
|
||||
std::vector<fs::path> _bssLibOrderFiles;
|
||||
std::map<uint32_t, LDCodeFile> _codeFiles; // Sorted by ram address
|
||||
std::mutex _codeFilesMutex;
|
||||
|
||||
fs::path _buildFolder, _buildAsm, _buildSrc, _buildLibAsm, _buildLibSrc;
|
||||
|
||||
void _write_files_to_section(WritableLD &ld, const std::string §ionName);
|
||||
|
||||
void _write_ld_boot_section(WritableLD &ld);
|
||||
void _write_main_section(WritableLD &ld);
|
||||
void _write_ucode_text_section(WritableLD &ld);
|
||||
void _write_data_section(WritableLD &ld);
|
||||
void _write_rodata_section(WritableLD &ld);
|
||||
void _write_ucode_data_section(WritableLD &ld);
|
||||
void _write_bss_section(WritableLD &ld);
|
||||
void _write_assets_section(WritableLD &ld);
|
||||
void _write_discard_section(WritableLD &ld);
|
||||
|
||||
void _append_files(const std::string inPath, const std::string extension, const std::string outPath);
|
||||
void _check_file_for_ram_pos(fs::path &filepath);
|
||||
void _get_code_files();
|
||||
void _populate_filepaths();
|
||||
|
||||
void _generate_ld();
|
||||
void _write_ucode_file_glabel(WritableAsmInclude &asmInc, std::string label, std::string path);
|
||||
void _generate_ucode_text_file();
|
||||
void _generate_ucode_data_file();
|
||||
void _generate_ucode_files();
|
||||
fs::path _buildFolder;
|
||||
};
|
||||
|
||||
@@ -40,10 +40,10 @@ def firstDiffMain():
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
buildFolder = Path("build") / Path("us_1.0")
|
||||
buildFolder = Path("build")
|
||||
|
||||
BUILTROM = buildFolder / f"dkr.z64"
|
||||
BUILTMAP = buildFolder / f"dkr.map"
|
||||
BUILTROM = buildFolder / f"dkr.{args.region}.{args.version}.z64"
|
||||
BUILTMAP = buildFolder / f"dkr.{args.region}.{args.version}.map"
|
||||
|
||||
EXPECTEDROM = "expected" / BUILTROM
|
||||
EXPECTEDMAP = "expected" / BUILTMAP
|
||||
+1
-1
@@ -29,7 +29,7 @@ APPLY_OPTS = ""
|
||||
|
||||
# Compiler options used with Clang-Tidy
|
||||
# Normal warnings are disabled with -Wno-everything to focus only on tidying
|
||||
INCLUDES = "-Iinclude -Isrc -Ibuild -I. -Ilib/src -Iinclude/libc -Iinclude/PR -Iinclude/sys -Ilib/src -Ilib/src/audio -Ilib/src/debug -Ilib/src/gu -Ilib/src/libc -Ilib/src/os"
|
||||
INCLUDES = "-Iinclude -Isrc -Ibuild -I. -Ilib/src"
|
||||
DEFINES = "-D_LANGUAGE_C -DNON_MATCHING -D_MIPS_SZLONG=32 -DNON_EQUIVALENT"
|
||||
COMPILER_OPTS = f"-fno-builtin -std=gnu90 -m32 -Wno-everything {INCLUDES} {DEFINES}"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user