From 71c828b9b6397f9d9d6c29dda1df12c1e3266aa1 Mon Sep 17 00:00:00 2001 From: Yanis002 <35189056+Yanis002@users.noreply.github.com> Date: Fri, 14 Feb 2025 01:25:49 +0100 Subject: [PATCH] delink __register_global_object, fix eur checksum and update docs (and bump compiler version) --- CONTRIBUTING.md | 35 ++++++++++++++++ INSTALL.md | 57 ++++++++++++++++++++++++++ README.md | 81 +++++-------------------------------- config/eur/arm9/delinks.txt | 4 ++ config/eur/arm9/symbols.txt | 4 +- extract/README.md | 2 +- st_eur.sha1 | 2 +- tools/configure.py | 4 +- 8 files changed, 112 insertions(+), 77 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 INSTALL.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..b30c4da3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,35 @@ +# Contribution guide +- [Project structure](#project-structure) +- [Decompiling](#decompiling) +- [Code style](#code-style) +- [Creating new `.c`/`.cpp` files](#creating-new-ccpp-files) + +## Project structure +- `build/`: Build output + - `eur|jp/`: Target version + - `build/`: Linked ROM objects + - `delinks/`: Objects delinked from the base ROM + - `libs|src/`: Built C/C++ code + - `arm9.o`: Linked ELF object + - `arm9.o.xMAP`: Map file listing memory addresses for all symbols +- `config/`: [`dsd`](https://github.com/AetiasHax/ds-decomp) configuration files +- `docs/`: Documentation about the game +- `extract/`: Game assets, extracted from your own supplied ROM + - `eur|jp/`: [`ds-rom`](https://github.com/AetiasHax/ds-rom) extract directories +- `include/`: Include files +- `src/`: Source C/C++ files +- `tools/`: Tools for this project + - `mwccarm/`: Compiler toolchain + - `configure.py`: Generates `build.ninja` + - `m2ctx.py`: Generates context for [decomp.me](https://decomp.me/) + - `mangle.py`: Shows mangled symbol names in a given C/C++ file + - `requirements.txt`: Python libraries + - `setup.py`: Sets up the project +- `*.sha1`: SHA-1 digests of different versions of the game + +## Decompiling +See [/docs/decompiling.md](/docs/decompiling.md). + +## Code style +This project has a `.clang-format` file and all C/C++ files in this project should follow it. We recommend using an editor +compatible with `clang-format` to format the code as you save. diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 00000000..91c4a96c --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,57 @@ +# Install + +Contents: + +- [Prerequisites](#prerequisites) +- [Build the ROM](#build-the-rom) + - [Matching the base ROM](#matching-the-base-rom) + - [Building with non-matching code](#building-with-non-matching-code) + +## Prerequisites + +1. Use one of these platforms: + - Windows (recommended) + - Linux +2. Install the following: + - Python 3.11+ and pip + - GCC 9+ + - Ninja +3. Install the Python dependencies: +```shell +python -m pip install -r tools/requirements.txt +``` +4. Install pre-commit hooks: +```shell +pre-commit install +``` +5. Run the setup script: +```shell +python tools/setup.py +``` +6. Run the Ninja configure script: +```shell +python tools/configure.py +``` + +> [!IMPORTANT] +> Rerun `configure.py` often to ensure that all C/C++ code gets compiled. + +> [!NOTE] +> For Linux users: Wibo is used by default. If you want to use Wine instead, run `configure.py` with `-w `. +7. Put one or more base ROMs in the [`/extract/`](/extract/README.md) directory of this repository. + +Now you can run `ninja` to build a ROM for the chosen version. + +### Matching the base ROM + +**This is optional!** You only need to follow these steps if you want a matching ROM. + +First, [extract the ARM7 BIOS from your DS device](https://wiki.ds-homebrew.com/ds-index/ds-bios-firmware-dump). Put the +ARM7 BIOS in the root directory of this repository, and verify that your dumped BIOS matches one of the following: + +| File name | SHA1 | +| --------------- | ------------------------------------------ | +| `arm7_bios.bin` | `6ee830c7f552c5bf194c20a2c13d5bb44bdb5c03` | +| `arm7_bios.bin` | `24f67bdea115a2c847c8813a262502ee1607b7df` | + +Now, rerun `configure.py` so it can update `build.ninja` to build a matching ROM. diff --git a/README.md b/README.md index aebbf642..a754a2f6 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,16 @@ # The Legend of Zelda: Spirit Tracks -Note: currently this is mostly a "trying out dsd" repo, it will be cleaned up later once everything works. -Also I want to automate the setup process, i.e running the `dsd rom extract` and `dsd init` commands automatically from running `configure.py`. +**Work in progress!** This project aims to recreate source code for ***The Legend of Zelda: Spirit Tracks*** by decompiling its code by hand. **The repository does not contain assets or assembly code.** To build the ROM, you must own an existing +copy of the game to extract assets from. -My goal is to provide a working template repository for DS decomps. +> [!NOTE] +> The project targets the European and Japanese versions, and other versions might be supported later. ---- +## How to install +See [INSTALL.md](INSTALL.md) for instructions on how to install the project. -A work-in-progress decompilation of The Legend of Zelda: Spirit Tracks. +## Contribution +A work in progress, but [CONTRIBUTING.md](CONTRIBUTING.md) has guidelines for how to contribute to the project. -Supported versions: -- `st-j`: Spirit Tracks - Japan - -Currently the decompilation mainly targets the `st-j` version. - -## Building - -### Requirements - -You will need the following dependencies: -* git -* ninja -* python3 -* wine (for macOS or non-x86 Linux) -* clang-format (optional) - -#### Ubuntu/Debian/Windows (WSL) - -You can install the dependencies with the following commands: - -``` -sudo apt-get update -sudo apt-get install git ninja-build python3 -``` - -#### macOS - -You can install dependencies via Homebrew with the following command: - -``` -brew install git ninja python3 -brew install --cask --no-quarantine gcenx/wine/wine-crossover -``` - -#### Windows (Native) - -You will need the following dependencies: -- [ninja.exe](https://github.com/ninja-build/ninja/releases/latest) -- Python (make sure to add it to your PATH during the installation) -- [Git for Windows](https://www.git-scm.com/downloads) - -You need to add ``C:\Program Files\Git\bin`` to your system's PATH (not the user one) in order to execute bash scripts properly. - -To get objdiff to work properly you also need to add the path to the folder containing ``ninja.exe`` to the system's PATH. - -### Instructions - -1. Clone the repo using `git clone https://github.com/yanis42/st`. - -2. Get the ARM7 bios and place it inside `orig/arm7/arm7.bin` - -3. Run `python tools/setup.py` - -### TODO: automate this - -4. Run `dsd.exe rom extract -r orig/VERSION/game.nds -7 orig/arm7/arm7.bin -o test/` - -## Development Tools - -### objdiff - -For local decompilation testing, start the [objdiff](https://github.com/encounter/objdiff) GUI and open this directory as the project directory. - -## License - -This project is licensed under CC0. Some tools might have their own license. +## Documentation +See [/docs](/docs) for documentation about the game. diff --git a/config/eur/arm9/delinks.txt b/config/eur/arm9/delinks.txt index ec75d310..8a91900f 100644 --- a/config/eur/arm9/delinks.txt +++ b/config/eur/arm9/delinks.txt @@ -5,3 +5,7 @@ .data start:0x02043220 end:0x02044dc0 kind:data align:32 .bss start:0x02044dc0 end:0x02051ae0 kind:bss align:32 +libs/cpp/src/__register_global_object.c: + complete + .text start:0x0203ce74 end:0x0203ce94 + .bss start:0x02051ad4 end:0x02051ad8 diff --git a/config/eur/arm9/symbols.txt b/config/eur/arm9/symbols.txt index 053421dc..84598fa0 100644 --- a/config/eur/arm9/symbols.txt +++ b/config/eur/arm9/symbols.txt @@ -2115,7 +2115,7 @@ func_0203ce2c kind:function(arm,size=0xc) addr:0x0203ce2c func_0203ce38 kind:function(arm,size=0xc) addr:0x0203ce38 func_0203ce44 kind:function(arm,size=0x18) addr:0x0203ce44 func_0203ce5c kind:function(arm,size=0x18) addr:0x0203ce5c -func_0203ce74 kind:function(arm,size=0x20) addr:0x0203ce74 +__register_global_object kind:function(arm,size=0x20) addr:0x0203ce74 func_0203ce94 kind:function(arm,size=0x1b4) addr:0x0203ce94 func_0203d048 kind:function(arm,size=0x48) addr:0x0203d048 func_0203d090 kind:function(arm,size=0x14) addr:0x0203d090 @@ -2845,4 +2845,4 @@ data_02051aa4 kind:bss addr:0x02051aa4 data_02051aa8 kind:bss addr:0x02051aa8 data_02051ac4 kind:bss addr:0x02051ac4 data_02051acc kind:bss addr:0x02051acc -data_02051ad4 kind:bss addr:0x02051ad4 +__global_destructor_chain kind:bss addr:0x02051ad4 diff --git a/extract/README.md b/extract/README.md index 0a681662..0450b2b6 100644 --- a/extract/README.md +++ b/extract/README.md @@ -4,5 +4,5 @@ Put the base ROM(s) in this directory. Please verify that your dumped ROM matche | Version | File name | SHA1 | | ------- | -------------------- | ------------------------------------------ | -| EUR | `baserom_st_eur.nds` | `4c950473fa0694cea04eed517e05631f529b35ed` | +| EUR | `baserom_st_eur.nds` | `9e99cc803a14ce038eb908db585431f8254f09ee` | | JP | `baserom_st_jp.nds` | `eaee3602b8a2235211b2e20cdcd4cb357956a264` | diff --git a/st_eur.sha1 b/st_eur.sha1 index 10822861..1c953ae8 100644 --- a/st_eur.sha1 +++ b/st_eur.sha1 @@ -1 +1 @@ -4c950473fa0694cea04eed517e05631f529b35ed st_eur.nds +9e99cc803a14ce038eb908db585431f8254f09ee st_eur.nds diff --git a/tools/configure.py b/tools/configure.py index b391c5cb..dffbc9f4 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -17,8 +17,8 @@ args = parser.parse_args() # Config GAME = "st" -MWCC_VERSION = "2.0/sp1p5" -DECOMP_ME_COMPILER = "mwcc_30_131" +MWCC_VERSION = "2.0/sp2p4" +DECOMP_ME_COMPILER = "mwcc_30_139" # TODO: verify CC_FLAGS = " ".join([ "-O4,p", # Optimize maximally for performance "-enum int", # Use int-sized enums