diff --git a/.gitignore b/.gitignore index e2b78543..80e6e342 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ objdiff.json /dsd.pdb build.ninja .ninja_log +/wibo diff --git a/libs/c/include/stdlib.h b/libs/c/include/stdlib.h new file mode 100644 index 00000000..0f078d8a --- /dev/null +++ b/libs/c/include/stdlib.h @@ -0,0 +1,6 @@ +#ifndef _C_STRLIB_H +#define _C_STRLIB_H + +int abs(int n); + +#endif diff --git a/libs/c/include/string.h b/libs/c/include/string.h new file mode 100644 index 00000000..6c1c86a7 --- /dev/null +++ b/libs/c/include/string.h @@ -0,0 +1,15 @@ +#ifndef _C_STRING_H +#define _C_STRING_H + +typedef unsigned int size_t; + +size_t strlen(const char *str); +char *strcpy(char *dest, const char *src); +char *strncpy(char *dest, const char *src, size_t num); +char *strcat(char *dest, const char *src); +int strcmp(char *str1, char *str2); +int strncmp(char *str1, char *str2, size_t num); +const char *strchr(const char *str, char ch); +const char *strstr(const char *str1, const char *str2); + +#endif diff --git a/libs/cpp/include/global_destructor_chain.h b/libs/cpp/include/global_destructor_chain.h new file mode 100644 index 00000000..c5043126 --- /dev/null +++ b/libs/cpp/include/global_destructor_chain.h @@ -0,0 +1,10 @@ +#pragma once + +typedef struct DestructorChain { + /* 0 */ struct DestructorChain *next; + /* 4 */ void *destructor; + /* 8 */ void *object; + /* c */ +} DestructorChain; + +void *__register_global_object(void *object, void *destructor, DestructorChain *link); diff --git a/libs/cpp/include/vector b/libs/cpp/include/vector new file mode 100644 index 00000000..7d78e50c --- /dev/null +++ b/libs/cpp/include/vector @@ -0,0 +1,10 @@ +#pragma once + +namespace std { + template class vector { + public: + T *elements; + int size; + int capacity; + }; +} // namespace std diff --git a/libs/cpp/src/__register_global_object.c b/libs/cpp/src/__register_global_object.c new file mode 100644 index 00000000..7d1e188f --- /dev/null +++ b/libs/cpp/src/__register_global_object.c @@ -0,0 +1,14 @@ +#include "global_destructor_chain.h" + +#define CALL_DTOR(dtor, obj) (((void (*)(void *, int))(dtor))((obj), -1)) + +DestructorChain *__global_destructor_chain; + +void *__register_global_object(void *object, void *destructor, DestructorChain *link) { + link->next = __global_destructor_chain; + link->destructor = destructor; + link->object = object; + + __global_destructor_chain = link; + return object; +} diff --git a/tools/configure.py b/tools/configure.py index 065d1102..b391c5cb 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -10,7 +10,7 @@ import ninja_syntax parser = argparse.ArgumentParser(description="Generates build.ninja") -parser.add_argument('-w', type=str, default="wine", dest="wine", required=False, help="Path to Wine (linux only)") +parser.add_argument('-w', type=str, default="./wibo", dest="wine", required=False, help="Path to Wine/Wibo (linux only)") parser.add_argument('version', help='Game version') args = parser.parse_args() @@ -18,7 +18,7 @@ args = parser.parse_args() # Config GAME = "st" MWCC_VERSION = "2.0/sp1p5" -DECOMP_ME_COMPILER = "mwcc_40_1051" +DECOMP_ME_COMPILER = "mwcc_30_131" CC_FLAGS = " ".join([ "-O4,p", # Optimize maximally for performance "-enum int", # Use int-sized enums @@ -27,11 +27,12 @@ CC_FLAGS = " ".join([ "-proc arm946e", # Target processor "-gccext,on", # Enable GCC extensions "-fp soft", # Compute float operations in software - "-inline on,noauto", # Inline only functions marked with 'inline' + "-inline noauto", # Inline only functions marked with 'inline' "-lang=c++", # Set language to C++ "-Cpp_exceptions off", # Disable C++ exceptions "-RTTI off", # Disable runtime type information "-interworking", # Enable ARM/Thumb interworking + "-w off", # Disable warnings "-sym on", # Debug info, including line numbers "-gccinc", # Interpret #include "..." and #include <...> equally "-nolink", # Do not link @@ -179,6 +180,12 @@ def main(): ) n.newline() + n.rule( + name="sha1", + command=f"{PYTHON} tools/sha1.py $in -c $sha1_file" + ) + n.newline() + game_build = build_path / game_version game_extract = extract_path / game_version @@ -249,6 +256,16 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi ) n.newline() + n.build( + inputs=rom_file, + rule="sha1", + variables={ + "sha1_file": str(Path(rom_file).with_suffix(".sha1")) + }, + outputs="sha1", + ) + n.newline() + def add_mwcc_builds(n: ninja_syntax.Writer, game_version: str, game_build: Path, mwcc_implicit: list[Path]): for source_file in get_c_cpp_files([src_path, libs_path]): diff --git a/tools/setup.py b/tools/setup.py index 667bee30..024a8926 100644 --- a/tools/setup.py +++ b/tools/setup.py @@ -3,9 +3,10 @@ import zipfile import io from pathlib import Path import platform +import stat - -DSD_VERSION = 'v0.3.2' +DSD_VERSION = 'v0.4.0' +WIBO_VERSION = '0.6.16' tools_path = Path(__file__).parent @@ -31,11 +32,22 @@ match platform.machine().lower(): print('\nInstalling dsd...') response = requests.get(f'https://github.com/AetiasHax/ds-decomp/releases/download/{DSD_VERSION}/dsd-{system}-{machine}{EXE}') -with open(root_path / f'dsd{EXE}', 'wb') as f: +dsd_path = root_path / f'dsd{EXE}' +with open(dsd_path, 'wb') as f: f.write(response.content) +dsd_path.chmod(dsd_path.stat().st_mode | stat.S_IEXEC) print('\nInstalling toolchain...') response = requests.get('http://decomp.aetias.com/files/mwccarm.zip') zip_file = zipfile.ZipFile(io.BytesIO(response.content)) zip_file.extractall(tools_path) + + +if system == "linux": + print('\nInstalling wibo...') + response = requests.get(f'https://github.com/decompals/wibo/releases/download/{WIBO_VERSION}/wibo') + wibo_path = root_path / 'wibo' + with open(wibo_path, 'wb') as f: + f.write(response.content) + wibo_path.chmod(wibo_path.stat().st_mode | stat.S_IEXEC)