Skip to content

Commit

Permalink
Update dtk-template
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Dec 15, 2024
1 parent 8259432 commit ffff659
Show file tree
Hide file tree
Showing 18 changed files with 642 additions and 262 deletions.
44 changes: 31 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
# IDE folders
.idea/
.vs/

# Caches
__pycache__
.idea
.vscode/*.log
.ninja_*
.mypy_cache
*.exe
build
build.ninja
objdiff.json
.cache/

# Original files
orig/*/*
!orig/*/.gitkeep
*.dol
*.rel
*.elf
*.o
*.map
*.MAP

# Build files
build/
.ninja_*
build.ninja

# decompctx output
ctx.*
*.ctx

# Generated configs
objdiff.json
compile_commands.json

# Miscellaneous
/*.txt
ctx.c
*.exe
/decomp
tools/mwcc_compiler
tools/dtk
tools/powerpc
*.map
*.dol
*.bat
newlines.py
/decomp
9 changes: 4 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ Building
git clone https://github.com/projectPiki/pikmin.git
```

- Using [Dolphin Emulator](https://dolphin-emu.org/), extract your game's system data to `orig/GPIE01_01`. (Or the appropriate version folder.)
- Right-click the game in Dolphin's game list and select `Properties`.
- Go to the `Filesystem` tab and right-click `Disc` -> `Extract System Data`.
![Dolphin filesystem extract](assets/dolphin-extract.png)
- After extraction, the following file should exist: `orig/GPIE01_01/sys/main.dol`.
- Copy your game's disc image to `orig/GPIE01_01`. (Or the appropriate version folder.)
- Supported formats: ISO (GCM), RVZ, WIA, WBFS, CISO, NFS, GCZ, TGC
- After the initial build, the disc image can be deleted to save space.

- Configure:

```sh
Expand Down
3 changes: 2 additions & 1 deletion config/DPIJ01/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/DPIJ01/sys/main.dol
object_base: orig/DPIJ01
object: files/zz_pikmin_game/PikiDemo.tgc:sys/main.dol
hash: 16aa58df2658f79b1dbb0f8500afd65399253267

# Generated from dataDir/build.map
Expand Down
6 changes: 3 additions & 3 deletions config/DPIJ01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2850,9 +2850,6 @@ gx/GXPerf.c:
.text start:0x8021C054 end:0x8021C8FC
.data start:0x802F2670 end:0x802F2760

Runtime/PPCEABI/H/__mem.c:
.init start:0x80003384 end:0x800034C8

Runtime/PPCEABI/H/__va_arg.c:
.text start:0x8021C8FC end:0x8021C9F0

Expand All @@ -2861,6 +2858,9 @@ Runtime/PPCEABI/H/global_destructor_chain.c:
.dtors start:0x8022A068 end:0x8022A06C
.sbss start:0x803F12B8 end:0x803F12C0

Runtime/PPCEABI/H/__mem.c:
.init start:0x80003384 end:0x800034C8

Runtime/PPCEABI/H/CPlusLibPPC.cp:
.text start:0x8021CA50 end:0x8021CA80

Expand Down
3 changes: 2 additions & 1 deletion config/GPIE01_00/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/GPIE01_00/sys/main.dol
object_base: orig/GPIE01_00
object: sys/main.dol
hash: 30a3850f203a4a910eaccb8fdc697f518d22a687

# Generated from dataDir/build.map
Expand Down
2 changes: 1 addition & 1 deletion config/GPIE01_00/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8618,7 +8618,7 @@ __vt__7Texture = .data:0x80228FC8; // type:object size:0x14 scope:global align:4
@713 = .data:0x80228FE8; // type:object size:0xC scope:local align:4
__vt__9GfxObject = .data:0x80229010; // type:object size:0x10 scope:weak align:4
...data.0 = .data:0x80229020; // type:label scope:local
bigFont_data = .data:0x80229020; // type:object size:0x7C080 noreloc scope:local align:32
bigFont_data = .data:0x80229020; // type:object size:0x7C080 scope:local align:32 noreloc
@577 = .data:0x802A50A0; // type:object size:0xB scope:local align:4 data:string
@907 = .data:0x802A50AC; // type:object size:0xA scope:local align:4 data:string
@951 = .data:0x802A50B8; // type:object size:0x9 scope:local align:4 data:string
Expand Down
3 changes: 2 additions & 1 deletion config/GPIE01_01/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/GPIE01_01/sys/main.dol
object_base: orig/GPIE01_01
object: sys/main.dol
hash: 02204260b7efe8742d34572e58ba3dfecd92e4e9

# Generated from dataDir/build.map
Expand Down
3 changes: 2 additions & 1 deletion config/GPIJ01_01/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/GPIJ01_01/sys/main.dol
object_base: orig/GPIJ01_01
object: sys/main.dol
hash: 92b0ca199a36b78ad978f54541392231ef8c0cea

# Generated from dataDir/build.map
Expand Down
3 changes: 2 additions & 1 deletion config/GPIJ01_02/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/GPIJ01_02/sys/main.dol
object_base: orig/GPIJ01_02
object: sys/main.dol
hash: d87f92a733fc8fa5f65045730fe81a66b0c7d146

# Generated from dataDir/build.map
Expand Down
2 changes: 1 addition & 1 deletion config/GPIJ01_02/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8728,7 +8728,7 @@ __vt__7Texture = .data:0x8022E85C; // type:object size:0x14 scope:global align:4
@714 = .data:0x8022E87C; // type:object size:0xC scope:local align:4
__vt__9GfxObject = .data:0x8022E8A4; // type:object size:0x10 scope:weak align:4
...data.0 = .data:0x8022E8C0; // type:label scope:local
bigFont_data = .data:0x8022E8C0; // type:object size:0x7C080 noreloc scope:local align:32
bigFont_data = .data:0x8022E8C0; // type:object size:0x7C080 scope:local align:32 noreloc
@577 = .data:0x802AA940; // type:object size:0xB scope:local align:4 data:string
@687 = .data:0x802AA94C; // type:object size:0x27 scope:local align:4 data:string
@789 = .data:0x802AA974; // type:object size:0x1F scope:local align:4 data:string
Expand Down
3 changes: 2 additions & 1 deletion config/GPIP01_00/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
object: orig/GPIP01_00/sys/main.dol
object_base: orig/GPIP01_00
object: sys/main.dol
hash: e5794ffe8ac72c3ead3849edbd2f27ea5e0ed440

# Generated from dataDir/build.map
Expand Down
2 changes: 1 addition & 1 deletion config/GPIP01_00/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8654,7 +8654,7 @@ __vt__7Texture = .data:0x8022AEC8; // type:object size:0x14 scope:global align:4
@713 = .data:0x8022AEE8; // type:object size:0xC scope:local align:4
__vt__9GfxObject = .data:0x8022AF10; // type:object size:0x10 scope:weak align:4
...data.0 = .data:0x8022AF20; // type:label scope:local
bigFont_data = .data:0x8022AF20; // type:object size:0x7C080 noreloc scope:local align:32
bigFont_data = .data:0x8022AF20; // type:object size:0x7C080 scope:local align:32 noreloc
@577 = .data:0x802A6FA0; // type:object size:0xB scope:local align:4 data:string
@907 = .data:0x802A6FAC; // type:object size:0xA scope:local align:4 data:string
@951 = .data:0x802A6FB8; // type:object size:0x9 scope:local align:4 data:string
Expand Down
40 changes: 34 additions & 6 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
import sys
from pathlib import Path
from typing import Any, Dict, List
from tools.project import *

from tools.project import (
Object,
ProgressCategory,
ProjectConfig,
calculate_progress,
generate_build,
is_windows,
)

# Game versions
DEFAULT_VERSION = 4
Expand Down Expand Up @@ -110,6 +118,12 @@
action="store_true",
help="builds equivalent (but non-matching) or modded objects",
)
parser.add_argument(
"--no-progress",
dest="progress",
action="store_false",
help="disable progress calculation",
)
args = parser.parse_args()

config = ProjectConfig()
Expand All @@ -125,6 +139,7 @@
config.generate_map = args.map
config.non_matching = args.non_matching
config.sjiswrap_path = args.sjiswrap
config.progress = args.progress
if not is_windows():
config.wrapper = args.wrapper
# Don't build asm unless we're --non-matching
Expand All @@ -134,9 +149,9 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v0.9.6"
config.objdiff_tag = "v2.0.0"
config.sjiswrap_tag = "v1.1.1"
config.dtk_tag = "v1.3.0"
config.objdiff_tag = "v2.4.0"
config.sjiswrap_tag = "v1.2.0"
config.wibo_tag = "0.6.11"

# Project
Expand All @@ -157,9 +172,14 @@
config.ldflags.append("-g")
if args.map:
config.ldflags.append("-mapunused")

# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []

# Optional numeric ID for decomp.me preset
# Can be overridden in libraries or objects
config.scratch_preset_id = 62 # Pikmin

# Progress configuration
config.progress_all = False
config.progress_use_fancy = True
Expand Down Expand Up @@ -191,7 +211,8 @@
"-i include",
"-i include/stl",
f"-i build/{config.version}/include",
f"-DVERSION={version_num}",
f"-DBUILD_VERSION={version_num}",
f"-DVERSION_{config.version}",
]

# Debug flags
Expand Down Expand Up @@ -222,7 +243,8 @@
"-i include",
"-i include/stl",
f"-i build/{config.version}/include",
f"-DVERSION={version_num}",
f"-DBUILD_VERSION={version_num}",
f"-DVERSION_{config.version}",
"-common on",
"-func_align 32",
"-lang c++",
Expand Down Expand Up @@ -274,6 +296,12 @@ def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
NonMatching = False # Object does not match and should not be linked
Equivalent = config.non_matching # Object should be linked when configured with --non-matching


# Object is only matching for specific versions
def MatchingFor(*versions):
return config.version in versions


config.warn_missing_config = True
config.warn_missing_source = False
config.libs = [
Expand Down
2 changes: 1 addition & 1 deletion src/os/__start.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ WEAKFUNC ASM void __start(void)
_end_of_parseargs:
bl DBInit
bl OSInit
#if VERSION == 0
#if BUILD_VERSION == 0
lis r4, 0x8000
addi r4, r4, 0x30e6
lhz r3, 0x0(r4)
Expand Down
46 changes: 30 additions & 16 deletions tools/decompctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,63 @@
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
src_dir = os.path.join(root_dir, "src")
include_dirs = [
os.path.join(root_dir, "include"),
os.path.join(root_dir, "include/stl"),
]
include_dirs: List[str] = [] # Set with -I flag

include_pattern = re.compile(r'^#\s*include\s*[<"](.+?)[>"]$')
include_pattern = re.compile(r'^#\s*include\s*[<"](.+?)[>"]')
guard_pattern = re.compile(r"^#\s*ifndef\s+(.*)$")
once_pattern = re.compile(r"^#\s*pragma\s+once$")

defines = set()
deps = []


def import_h_file(in_file: str, r_path: str, deps: List[str]) -> str:
def import_h_file(in_file: str, r_path: str) -> str:
rel_path = os.path.join(root_dir, r_path, in_file)
if os.path.exists(rel_path):
return import_c_file(rel_path, deps)
return import_c_file(rel_path)
for include_dir in include_dirs:
inc_path = os.path.join(include_dir, in_file)
if os.path.exists(inc_path):
return import_c_file(inc_path, deps)
return import_c_file(inc_path)
else:
print("Failed to locate", in_file)
return ""


def import_c_file(in_file: str, deps: List[str]) -> str:
def import_c_file(in_file: str) -> str:
in_file = os.path.relpath(in_file, root_dir)
deps.append(in_file)
out_text = ""

try:
with open(in_file, encoding="utf-8") as file:
out_text += process_file(in_file, list(file), deps)
out_text += process_file(in_file, list(file))
except Exception:
with open(in_file) as file:
out_text += process_file(in_file, list(file), deps)
out_text += process_file(in_file, list(file))
return out_text


def process_file(in_file: str, lines: List[str], deps: List[str]) -> str:
def process_file(in_file: str, lines: List[str]) -> str:
out_text = ""
for idx, line in enumerate(lines):
guard_match = guard_pattern.match(line.strip())
if idx == 0:
guard_match = guard_pattern.match(line.strip())
if guard_match:
if guard_match[1] in defines:
break
defines.add(guard_match[1])
else:
once_match = once_pattern.match(line.strip())
if once_match:
if in_file in defines:
break
defines.add(in_file)
print("Processing file", in_file)
include_match = include_pattern.match(line.strip())
if include_match and not include_match[1].endswith(".s"):
out_text += f'/* "{in_file}" line {idx} "{include_match[1]}" */\n'
out_text += import_h_file(include_match[1], os.path.dirname(in_file), deps)
out_text += import_h_file(include_match[1], os.path.dirname(in_file))
out_text += f'/* end "{include_match[1]}" */\n'
else:
out_text += line
Expand Down Expand Up @@ -100,10 +105,19 @@ def main():
"--depfile",
help="""Dependency file""",
)
parser.add_argument(
"-I",
"--include",
help="""Include directory""",
action="append",
)
args = parser.parse_args()

deps = []
output = import_c_file(args.c_file, deps)
if args.include is None:
exit("No include directories specified")
global include_dirs
include_dirs = args.include
output = import_c_file(args.c_file)

with open(os.path.join(root_dir, args.output), "w", encoding="utf-8") as f:
f.write(output)
Expand Down
1 change: 1 addition & 0 deletions tools/download_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def dtk_url(tag: str) -> str:
repo = "https://github.com/encounter/decomp-toolkit"
return f"{repo}/releases/download/{tag}/dtk-{system}-{arch}{suffix}"


def objdiff_cli_url(tag: str) -> str:
uname = platform.uname()
suffix = ""
Expand Down
Loading

0 comments on commit ffff659

Please sign in to comment.