mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-18 20:15:56 +00:00
Merge pull request #1002: game 1.1.0 gets the core frame and camera patch sets of 1.2.1 and 1.4.3, so the frame rate, cursor, field of view and aspect ratio options work on it (shenjackyuanjie)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
a9de583d79
6 files changed
+264
-7
No files matched your search
@@ -10,8 +10,8 @@ Code copied or adapted from another project is listed here with its source, the
|
||||
| MacNativeGames TotK host runtime: dynamic linking, identity check, module permissions, guest memory and SVCs, threads, IPC, audio renderer, system services, RomFS and save storage, boot sequence, the NVN proc name list | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/runtime/`, `games/totk/scripts/prepare_runtime.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/loader.c`, `runtime/memory.c`; `runtime/kernel.c`, `runtime/svc.c`, `runtime/ipc.c`, `runtime/ipc.h`, `runtime/audren.c`, `runtime/audren.h`, `runtime/audio_mixer.c`, `runtime/audio_effects.c`, `runtime/audio_effects.h`, `runtime/audio_reverb.c`, `runtime/audio_reverb.h` (SDL3 output replaces CoreAudio), `runtime/ov_system.c` (also `shared_font.c`: the BFTTF layout behind nn::pl), `runtime/ov_input.c` (also `hid_feedback.c`: vibration and six-axis handles and calls), `runtime/motion_fusion.c` (six-axis fusion of `motion_fusion.c`), `runtime/ov_media.c` (hardware Opus decoder over libopus), `runtime/swkbd_win.c` (`swkbd_host.c`: ShowKeyboardArg offsets, UTF-8/UTF-16 conversion, disabled-key filter, result codes; Win32 window replaces the macOS text bar), `runtime/ov_gfx.c`, `runtime/romfs.c`, `runtime/romfs_path.h`, `runtime/fs_host.c`, `runtime/fs.h`, `runtime/boot.c`; `runtime/gfx_window.c`; `tools/gen_nvn_procs.py`, `runtime/nvn_procs.inc` (`NVN/names.txt` and the `NVN_EXTRA` names of `totk_nvn_ext.c`) |
|
||||
| MacNativeGames TotK frame-rate patches: 60 fps present-interval controller, real-time frame step and its present sampling, hair and cloth clock, trampoline slow-motion check (instruction words and 1.2.1 sites), player position chain; quick-menu capture background RomFS overlay | https://github.com/ly05010419/MacNativeGames @ `ebe621de99bfc48f3c42f2d2aa73e04fbcc6eae2` (`games/totk/runtime/game_patches.c`, `game_version.h`, `world_survey.c`, `games/totk/scripts/make_romfs_patches.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/frame_rate.c`, `recomp/patches-v121.txt`, `tools/make_romfs_patches.py` |
|
||||
| MacNativeGames TotK 1.4.3 fade fix: the four distance / LOD and pre-actor fade sites, their instruction words and the floor of the fade step at 1 | https://github.com/ly05010419/MacNativeGames @ `3e9e7f67fdfdd3404134dcfa0f24969a9425a33f` (`games/totk/runtime/game_patches_v143.c` patch_fade_increment), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set fade; the floor without flags, clz >> 5, as in pull request #78) |
|
||||
| MacNativeGames TotK 1.2.1 cursor and aim steps: the map cursor, vertical Ultrahand aim and vertical gyro aim sites, their instruction words and the step scaled by the frame ratio | https://github.com/ly05010419/MacNativeGames @ `363a6eb50434387f7d623349934bcf1e910be48f` (`games/totk/runtime/game_patches.c` patch_cursor_speed), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v121.txt` (set cursor) |
|
||||
| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) |
|
||||
| MacNativeGames TotK 1.2.1 cursor and aim steps: the map cursor, vertical Ultrahand aim and vertical gyro aim sites, their instruction words and the step scaled by the frame ratio | https://github.com/ly05010419/MacNativeGames @ `363a6eb50434387f7d623349934bcf1e910be48f` (`games/totk/runtime/game_patches.c` patch_cursor_speed), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v121.txt`, `recomp/patches-v110.txt` (set cursor) |
|
||||
| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt`, `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) |
|
||||
| MacNativeGames TotK button icons: the Xbox controller's shoulder buttons, triggers, Menu, View and d-pad drawn with letters from the game's own text fonts, the .bfotf key, the button guide's images and their block-linear layout, the resource size table raised for the archives that grew | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/scripts/make_button_icons.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/button_icons.py`, `tools/make_romfs_patches.py` (--prompts) |
|
||||
| RenoDX TotK mod (game mod by souperman9, tonemapper by Musa, RenoDX framework by ShortFuse, RenoVK fork by Ritsu): the approach of the HDR tonemap (the game's 1 - e^-x curve kept below a pivot and continued along its tangent above it, the saturation grade applied to the colour scaled into 0..1) and the observation that the passes after the tonemap keep values above 1. No code copied; the shader is our own | https://github.com/clshortfuse/renodx @ `b6f87272ad1bfdc0e6444910a93606815944a085` (`src/games/totk/tonemap.slang`, `addon.cpp`), Copyright (c) 2025 Carlos Lopez Jr. | MIT | `runtime/shaders/hdr_tonemap.frag`, `runtime/vk_hdr.c` |
|
||||
| TOTK-Ultrawide, the community mod for emulators: the list of UI panes the ultrawide layout edits and the distances they move (data only, no code copied; the edit code is our own, and MacNativeGames' `ultrawide_layout.py` in the row above already carries the same values). The mod's repository URL and licence version are not recorded in this repository | TOTK-Ultrawide (community mod; URL not recorded here) | GPL (version not recorded here) | `tools/ultrawide_layout.py` (`KEEP_ROOT`, `edits`, `anim_edits`) |
|
||||
@@ -41,6 +41,7 @@ Code copied or adapted from another project is listed here with its source, the
|
||||
| AMD Display Library (ADL) declarations: `AdapterInfo`, `ADLSingleSensorData`, `ADLPMLogDataOutput`, the `ADL_PMLOG_*` sensor numbers and the `ADL2_*` function signatures | https://github.com/GPUOpen-LibrariesAndSDKs/display-library @ `84c881cb2136f04287eb3af12de00a9e2867aa9e` (`include/adl_structures.h`, `include/adl_defines.h`, `include/adl_sdk.h`), Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc. | MIT | `runtime/perfmon.c` |
|
||||
| Zstandard 1.5.7 (MSYS2 `mingw-w64-ucrt-x86_64-zstd`), static link | https://github.com/facebook/zstd, Copyright (c) Meta Platforms, Inc. and affiliates | BSD-3-Clause | `runtime/resolution.c` (the HeapDef table), `runtime/ov_zstd.c` (the game's zstd frames decoded on the host) |
|
||||
| musl `fma.c`, `fmaf.c` and `scalbn.c`, adapted into one file for the x86-64-v2 build | https://github.com/kraj/musl @ `5a56ad13e1e0790c06122978aad2a14d6b9efc1a` (mirror of https://git.musl-libc.org/cgit/musl), Copyright (c) 2005-2020 Rich Felker and contributors | MIT | `runtime/fma.c` (the correctly rounded fma/fmaf the FP lowering needs on CPUs without FMA3) |
|
||||
| MacNativeGames texture pool offset fix: widen the 32-bit texture storage and packaged-data offsets unsigned | https://github.com/ly05010419/MacNativeGames @ `ca311e2d` (`games/totk/runtime/game_patches.c` patch_pool_offset), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt` (set pooloff; sites located again in 1.1.0) |
|
||||
|
||||
## Compiler runtime in a source build
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Game 1.1.0 patch coverage
|
||||
|
||||
The built-in table is [recomp/patches-v110.txt](../recomp/patches-v110.txt). These sites were located in the local 1.1.0 main and checked against its original instruction words, rather than applying a version-wide address shift. The generator rejects a different word or an invalid spin back-edge.
|
||||
|
||||
## Added coverage
|
||||
|
||||
| Set | Sites added | Runtime control |
|
||||
| --- | ---: | --- |
|
||||
| realtime | 1 | Equipment-switch cooldown: step every positive remainder, including values below FLT_EPSILON. Follows the existing real-time clock switch. |
|
||||
| cursor | 3 | Scale map panning, vertical ability aim and vertical gyro aim by the 30 Hz ratio; follows `TOTK_HIGHFPS_FIX`. |
|
||||
| aspect | 4 | The two camera and two viewport projections read page +56. The resolution code enables it for non-16:9 output. |
|
||||
| fov | 2 | The two camera projections multiply their vertical angle by page +60. The field-of-view setting is live; 100 leaves the original path. |
|
||||
| pooloff | 2 | Widen texture-pool offsets unsigned, covering 2..4 GiB without changing offsets below 2 GiB. Enabled by default; `TOTK_POOL_OFFSET_PATCH=0` retains the original path. |
|
||||
| shadow | 1 | The sun shadow map takes its fixed size from page +92 before rounding. The shadow-resolution setting enables it; `shadow_res=game` leaves the game's sizing. |
|
||||
| cascade | 4 | Read the four sun shadow cascade defaults from page +64..76. Shadow range 100 leaves the original constructor. |
|
||||
|
||||
The table has 12 sets and 50 instruction sites in total. Its existing 889 spin back-edges are unchanged. The new sets use the existing runtime page and settings; no new setting, allocator or renderer path is introduced.
|
||||
|
||||
The camera sites were cross-checked by normalized instruction-window matching from the local 1.0.0 main. The viewport routine has two matching copies: both are patched. Other sites were checked through their data flow: the equipment timer and its gate, the map clock, the ability clock, the NVN texture storage/package calls, the shadow size publication and the cascade parameter constructor. FOV's s8 is overwritten by the next original instruction; x10 is saved. The cursor sites use the same scratch registers as their 1.2.1 counterparts.
|
||||
|
||||
## Deliberately separate
|
||||
|
||||
- Direct mouse: 1.1.0 continues to use stick emulation. Porting the complete camera hook set also needs the runtime layout and load-site table; matching an individual store or one camera mode is not sufficient. No partial set is enabled here.
|
||||
- Fade: the four 1.4.3 sites are not presumed to exist in 1.1.0. An equivalent zero-increment path has not been established.
|
||||
- Native Zstandard: the existing host bridge calls back to hard-coded 1.4.3 decoder entry points on fallback. Adding only the BL patches to 1.1.0 would be incorrect.
|
||||
- Live DLSS scene sizing and game-menu mouse input retain their existing version restrictions. They are not patch-table parity work.
|
||||
|
||||
## Validation
|
||||
|
||||
Run with Python's numpy, lz4, capstone and unicorn dependencies and a runtime-supported Clang:
|
||||
|
||||
```sh
|
||||
# CC selects the Clang used by the differential harness.
|
||||
python tests/patches_v110_check.py
|
||||
python tests/patches_v110_check.py --cflags=-march=x86-64-v2
|
||||
python tests/patches_v110_check.py --exefs <local ExeFS directory>
|
||||
```
|
||||
|
||||
Without ExeFS, the test uses synthetic memory and the patch table only. It compares the complete integer/SIMD register state, SP and NZCV of the lifted C and Unicorn for all 17 additions, on and off, at 30/60/120 Hz, including pool offsets immediately below and above 2 GiB and at the end of the 32-bit range. Windows test mappings respect its 64 KiB allocation granularity. With ExeFS it additionally validates every original word and spin target. Extracted images and generated C are local build artifacts, never repository content.
|
||||
|
||||
These checks establish instruction and code-generation contracts. World-scene visual acceptance, texture packs allocating a pool above 2 GiB, physical gyro and comparisons of shadow quality still require gameplay checks.
|
||||
@@ -10,6 +10,8 @@ set cloth TOTK_CLOTH_REALTIME 1
|
||||
set bounce TOTK_HIGHFPS_FIX 1
|
||||
set output TOTK_PATCH_OUTPUT 0
|
||||
set scene TOTK_PATCH_SCENE 0
|
||||
set shadow TOTK_PATCH_SHADOW 0
|
||||
set cascade TOTK_PATCH_CASCADE 0
|
||||
|
||||
# 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1.
|
||||
site fps60 main 90e978 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum)
|
||||
@@ -66,6 +68,50 @@ site scene main cea5e0 5e21d900 @page:x9 # scvtf s0, s8 -> adrp x9, page
|
||||
site scene main cea5e8 bd0cc660 2d420520 # str s0, [x19, #0xcc4] -> ldp s0, s1, [x9, #16]
|
||||
site scene main cea5ec 5e21d921 bd0cc660 # scvtf s1, s9 -> str s0, [x19, #0xcc4]
|
||||
|
||||
# Equipment-switch cooldown (issue #18): the player update tests state +0x109c against FLT_EPSILON,
|
||||
# while the equipment gate (main+0x7f0134) blocks changes above zero. Step every positive remainder through
|
||||
# main+0xa26bb0, including (0, FLT_EPSILON], so a measured frame ratio cannot leave equipment locked.
|
||||
site realtime main a20518 1e270101 1e2703e1 # fmov s1, w8 (FLT_EPSILON) -> fmov s1, wzr
|
||||
|
||||
# Cursor and aim steps (MacNativeGames game_patches.c patch_cursor_speed, 363a6eb): use the same 30 Hz ratio
|
||||
# already read by these updates for smoothing. x9 / s16 are scratch at the map site; x20 holds the aim clock.
|
||||
set cursor TOTK_HIGHFPS_FIX 1
|
||||
site cursor main f31e80 bd400361 f94002e9 bd400930 1e300800 bd400361 # map pan s0 *= [[x23] + 8]
|
||||
site cursor main 1d55f24 1e2a198c 1e2a198c bd400a90 1e30098c # vertical ability aim s12 *= [x20 + 8]
|
||||
site cursor main 1d556a4 1e200923 1e200923 bd400a90 1e300863 # vertical gyro aim s3 *= [x20 + 8]
|
||||
|
||||
# Camera aspect (Hor+): two camera projection updates and the two copies of the viewport projection routine.
|
||||
# The camera sites were matched against 1.0.0 by instruction windows; both viewport copies match the same
|
||||
# 193-word normalized window. Page +56 is set by runtime/resolution.c. Save x10 instead of assuming it dead.
|
||||
set aspect TOTK_ASPECT_PATCH 0
|
||||
site aspect main cdbf30 bd414260 f81f0fea @page:x10 bd403940 f84107ea
|
||||
site aspect main 1261a64 bd414260 f81f0fea @page:x10 bd403940 f84107ea
|
||||
site aspect main 19c2260 1e211800 f81f0fea @page:x10 bd403940 f84107ea
|
||||
site aspect main 1ed8fa4 1e211800 f81f0fea @page:x10 bd403940 f84107ea
|
||||
|
||||
# Field of view: load the camera's vertical angle as before and multiply by page +60. The following projection
|
||||
# setup overwrites s8 before reading it; s1 (the half-angle multiplier) stays intact. x10 is saved on the stack.
|
||||
set fov TOTK_FOV_PATCH 0
|
||||
site fov main cdbef8 bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea
|
||||
site fov main 1261a2c bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea
|
||||
|
||||
# Texture pool offsets above 2 GiB (MacNativeGames game_patches.c patch_pool_offset, ca311e2d): the loader
|
||||
# passes w25 to SetStorage and SetPackagedTextureData. Widen unsigned to cover the complete 32-bit pool offset.
|
||||
set pooloff TOTK_POOL_OFFSET_PATCH 1
|
||||
site pooloff main 9b93a8 93407f22 2a1903e2
|
||||
site pooloff main 9b93c4 8b39c101 8b394101
|
||||
|
||||
# Sun shadow map: the size rounded here is used for width (+0x3d8), height (+0x3f8) and viewport together.
|
||||
# runtime/resolution.c shadow_init supplies the fixed size at page +92; the default remains the game's size.
|
||||
site shadow main d0760c 11001d6b @page:x11 b9405d6b 11001d6b
|
||||
|
||||
# Sun shadow cascade parameter defaults: depth_shadow_near_0_1..3 and depth_shadow_far_0. The constructor
|
||||
# stores 20, 40, 80 and 160 metres; runtime/resolution.c res_shadow_range supplies page +64..+76.
|
||||
site cascade main 1157fb8 52a83408 @page:x8 b9404108
|
||||
site cascade main 1158040 52a84408 @page:x8 b9404508
|
||||
site cascade main 11580c8 52a85408 @page:x8 b9404908
|
||||
site cascade main 115814c 52a86408 @page:x8 b9404d08
|
||||
|
||||
# Spin waits, from tools/spin_waits.py --exefs build/extracted/v110/exefs --patches recomp/patches-v110.txt: loops that only
|
||||
# another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), TOTK_SPIN=0 keeps the core.
|
||||
|
||||
|
||||
+4
-4
@@ -86,7 +86,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
|
||||
"bars, or stretch them over the whole picture. Applies from the next movie.",
|
||||
[UI_MENU_MOVIE_ASPECT_KEEP] = "Black bars", [UI_MENU_MOVIE_ASPECT_STRETCH] = "Stretch",
|
||||
[UI_MENU_FOV] = "Field of view",
|
||||
[UI_MENU_FOV_DESC] = "How much of the world the camera shows, in percent of the game's own. Game version 1.4.3 only.",
|
||||
[UI_MENU_FOV_DESC] = "How much of the world the camera shows, in percent of the game's own. Game versions 1.1.0 and 1.4.3.",
|
||||
[UI_MENU_SHADOW_RES] = "Shadow map size",
|
||||
[UI_MENU_SHADOW_RES_DESC] = "Size of the sun's shadow map. The game's own size changes with the view, down to about 400 "
|
||||
"near the ground, so leaf shadows look blocky and jump; a fixed size keeps them still and "
|
||||
@@ -584,7 +584,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
|
||||
"растянуть их на всю картинку. Действует со следующего ролика.",
|
||||
[UI_MENU_MOVIE_ASPECT_KEEP] = "Чёрные полосы", [UI_MENU_MOVIE_ASPECT_STRETCH] = "Растянуть",
|
||||
[UI_MENU_FOV] = "Поле зрения",
|
||||
[UI_MENU_FOV_DESC] = "Сколько мира показывает камера, в процентах от игрового. Только для версии игры 1.4.3.",
|
||||
[UI_MENU_FOV_DESC] = "Сколько мира показывает камера, в процентах от игрового. Для версий игры 1.1.0 и 1.4.3.",
|
||||
[UI_MENU_SHADOW_RES] = "Размер карты теней",
|
||||
[UI_MENU_SHADOW_RES_DESC] = "Размер карты теней от солнца. Собственный размер игры меняется вместе с видом, у земли до "
|
||||
"примерно 400, поэтому тени листвы выглядят квадратными и дёргаются; постоянный размер делает "
|
||||
@@ -1385,7 +1385,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, nitidez %d%%", [UI_MENU_OV_SCALE_NONE] = "nenhuma (1:1)",
|
||||
[UI_MENU_OV_SCALE_BILINEAR] = "bilinear",
|
||||
[UI_MENU_FOV] = "Campo de visão",
|
||||
[UI_MENU_FOV_DESC] = "Quanto do mundo a câmera mostra, em porcentagem do original do jogo. Só na versão 1.4.3 do "
|
||||
[UI_MENU_FOV_DESC] = "Quanto do mundo a câmera mostra, em porcentagem do original do jogo. Nas versões 1.1.0 e 1.4.3 do "
|
||||
"jogo.",
|
||||
[UI_MENU_SHADOW_RES] = "Tamanho do mapa de sombras",
|
||||
[UI_MENU_SHADOW_RES_DESC] = "Tamanho do mapa de sombras do sol. O tamanho do jogo muda com a vista, até cerca de "
|
||||
@@ -1673,7 +1673,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_MOVIE_ASPECT_STRETCH] = "拉伸",
|
||||
[UI_MENU_FOV] = "视野",
|
||||
[UI_MENU_FOV_DESC] = "镜头能看到多大范围,以游戏自身视野的百分比表示。"
|
||||
"仅限游戏版本 1.4.3。",
|
||||
"支持游戏版本 1.1.0 和 1.4.3。",
|
||||
[UI_MENU_SHARPNESS] = "FSR 锐度",
|
||||
[UI_MENU_SHARPNESS_DESC] = "FSR 缩放后的锐化强度;0 为关闭。",
|
||||
[UI_MENU_COLOR] = "色彩",
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
"""Check the v110 patch contracts without game data; optionally check every site and spin against local ExeFS.
|
||||
|
||||
python tests/patches_v110_check.py --exefs <local ExeFS> [--cflags=-march=x86-64-v2]
|
||||
Uses the differential harness, Clang (CC) and Unicorn. Extracted bytes and generated C stay in build/.
|
||||
"""
|
||||
import argparse
|
||||
import math
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tests' / 'diff'))
|
||||
from common import BUF, BUF_SIZE, Emu, build_harness, diff_state, run_harness
|
||||
import patches
|
||||
from lifter import Lifter
|
||||
from layout import layout
|
||||
from module import Module
|
||||
|
||||
# Set, offset, target register, result kind. The patch file owns the instruction words.
|
||||
SITES = [
|
||||
('realtime', 0xa20518, 1, 'zero'),
|
||||
('cursor', 0xf31e80, 0, 'map'),
|
||||
('cursor', 0x1d55f24, 12, 'aim'),
|
||||
('cursor', 0x1d556a4, 3, 'gyro'),
|
||||
*[('aspect', a, 0, 'aspect') for a in (0xcdbf30, 0x1261a64, 0x19c2260, 0x1ed8fa4)],
|
||||
*[('fov', a, 0, 'fov') for a in (0xcdbef8, 0x1261a2c)],
|
||||
('pooloff', 0x9b93a8, 2, 'offset'), ('pooloff', 0x9b93c4, 1, 'source'),
|
||||
('shadow', 0xd0760c, 11, 'shadow'),
|
||||
*[('cascade', a, 8, 'cascade') for a in (0x1157fb8, 0x1158040, 0x11580c8, 0x115814c)],
|
||||
]
|
||||
|
||||
|
||||
def f32(v):
|
||||
return struct.unpack('<f', struct.pack('<f', v))[0]
|
||||
|
||||
|
||||
def scalar(v):
|
||||
return struct.unpack('<f', (v & 0xffffffff).to_bytes(4, 'little'))[0]
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__)
|
||||
ap.add_argument('--exefs', type=Path)
|
||||
ap.add_argument('--cflags', default='-march=x86-64-v3')
|
||||
args = ap.parse_args()
|
||||
mods = layout(args.exefs) if args.exefs else [
|
||||
('main', 0x7000000000, 0x472d000), ('subsdk0', 0x7004800000, 0x400000),
|
||||
('sdk', 0x7004c00000, 0x800000)]
|
||||
table = patches.load(ROOT / 'recomp' / 'patches-v110.txt', mods)
|
||||
base = mods[0][1]
|
||||
if args.exefs:
|
||||
for name, at, _ in mods:
|
||||
mod = Module(name, args.exefs / name, at)
|
||||
patches.check(table, mod, name)
|
||||
print(f'v110: all {sum(len(s) for s in table.sites.values())} sites and '
|
||||
f'{sum(len(s) for s in table.spins.values())} spin back-edges match local ExeFS')
|
||||
by_name = {name: i for i, (name, _, _) in enumerate(table.sets)}
|
||||
resolved = table.for_module('main', base)
|
||||
bodies, words = [], []
|
||||
lift = Lifter(base, 'c')
|
||||
for name, off, _, _ in SITES:
|
||||
alternatives = table.sites['main'][off]
|
||||
assert len(alternatives) == 1 and alternatives[0][0] == by_name[name]
|
||||
orig = alternatives[0][2]
|
||||
repl = resolved[base + off][0][1]
|
||||
original = lift.lift(orig, base + off)
|
||||
replacement = [lift.lift(w, base + off) for w in repl]
|
||||
assert original.kind == 'op' and all(i.kind == 'op' for i in replacement)
|
||||
bodies.append('if (c->x[30]) { ' + ' '.join(i.code for i in replacement) +
|
||||
' } else { ' + original.code + ' }')
|
||||
words.append((orig, repl))
|
||||
build = ROOT / 'build'
|
||||
build.mkdir(exist_ok=True)
|
||||
groups = {ratio: ([], []) for ratio in (1.0, 0.5, 0.25)}
|
||||
page = bytearray(0x1000)
|
||||
# Distinct fields reveal an accidental load from the neighboring page slot.
|
||||
for off, value in ((0, 0.5), (4, 1 / 60), (56, 21 / 9), (60, 1.2),
|
||||
(64, 25), (68, 50), (72, 100), (76, 200)):
|
||||
struct.pack_into('<f', page, off, value)
|
||||
struct.pack_into('<I', page, 92, 2048)
|
||||
initial = bytearray(BUF_SIZE)
|
||||
for off, value in ((0, 3), (4, 5), (8, 0.5), (0x13c, 0.9), (0x140, 16 / 9)):
|
||||
struct.pack_into('<f', initial, 0x2000 + off, value)
|
||||
struct.pack_into('<Q', initial, 0x2000, BUF + 0x3000)
|
||||
struct.pack_into('<f', initial, 0x3008, 0.5)
|
||||
with tempfile.TemporaryDirectory(prefix='patch-v110-', dir=build) as temp:
|
||||
work = Path(temp)
|
||||
exe = build_harness(work, bodies, 2, args.cflags)
|
||||
for k, (name, off, target, kind) in enumerate(SITES):
|
||||
pc = base + off
|
||||
for enabled in (0, 1):
|
||||
for ratio in (1.0, 0.5, 0.25):
|
||||
for offset in (0, 0x7fffffff, 0x80000000, 0xffffffff):
|
||||
mem = bytearray(initial)
|
||||
struct.pack_into('<f', mem, 0x2008, ratio)
|
||||
struct.pack_into('<f', mem, 0x3008, ratio)
|
||||
code = words[k][1] if enabled else [words[k][0]]
|
||||
lo = pc & ~0xffff
|
||||
text = bytearray((pc - lo) + len(code) * 4)
|
||||
struct.pack_into('<' + 'I' * len(code), text, pc - lo, *code)
|
||||
emu = Emu([(lo, text), (table.page, page)])
|
||||
emu.mu.mem_write(BUF, bytes(mem))
|
||||
x = [0x1234567800000000 + i for i in range(31)]
|
||||
for i in (8, 19, 20, 23, 27):
|
||||
x[i] = BUF + 0x2000
|
||||
x[25], x[30] = offset, enabled
|
||||
v = [(0x123456789abcdef << 32) | int.from_bytes(struct.pack('<f', 2.0), 'little')] * 32
|
||||
v[1] = int.from_bytes(struct.pack('<f', 4.0), 'little')
|
||||
v[9] = int.from_bytes(struct.pack('<f', 3.0), 'little')
|
||||
v[10] = int.from_bytes(struct.pack('<f', 4.0), 'little')
|
||||
v[12] = int.from_bytes(struct.pack('<f', 8.0), 'little')
|
||||
sp, nzcv = BUF + BUF_SIZE - 0x100, 0xa0000000
|
||||
ex, esp, enz, epc, ev = emu.run(pc, 0, x, sp, nzcv, v, count=len(code))
|
||||
assert esp == sp and enz == nzcv
|
||||
if enabled:
|
||||
want = {'zero': 0, 'map': 2 * ratio, 'aim': 2 * ratio, 'gyro': 6 * ratio,
|
||||
'aspect': f32(21 / 9), 'fov': f32(f32(0.9) * f32(1.2))}
|
||||
if kind in want:
|
||||
assert math.isclose(scalar(ev[target]), want[kind], rel_tol=1e-6, abs_tol=1e-7), (kind, off)
|
||||
elif kind == 'offset':
|
||||
assert ex[target] == offset
|
||||
elif kind == 'source':
|
||||
assert ex[target] == x[8] + offset
|
||||
elif kind == 'shadow':
|
||||
assert ex[target] == 2055
|
||||
elif kind == 'cascade':
|
||||
slot = (64, 68, 72, 76)[(0x1157fb8, 0x1158040, 0x11580c8, 0x115814c).index(off)]
|
||||
assert ex[target] == struct.unpack_from('<I', page, slot)[0]
|
||||
# The stack save must preserve the complete x10, not just its lower word.
|
||||
if name in ('aspect', 'fov'):
|
||||
assert ex[10] == x[10]
|
||||
allowed_x = {target} if kind in ('offset', 'source', 'shadow', 'cascade') else {9} if kind == 'map' else set()
|
||||
# Integer destinations do not authorize writes to the same-numbered SIMD register.
|
||||
allowed_v = set() if kind in ('offset', 'source', 'shadow', 'cascade') else {0, 1} if kind == 'map' else {target}
|
||||
if enabled and kind in ('map', 'aim', 'gyro'):
|
||||
allowed_v |= {16}
|
||||
if kind == 'map':
|
||||
allowed_v |= {1}
|
||||
if enabled and kind == 'fov':
|
||||
allowed_v |= {8}
|
||||
assert all(ex[i] == x[i] for i in range(31) if i not in allowed_x)
|
||||
assert all(ev[i] == v[i] for i in range(32) if i not in allowed_v)
|
||||
cases, expect = groups[ratio]
|
||||
cases.append((k, 0, x, sp, nzcv, v, True))
|
||||
memory = zlib.crc32(emu.mu.mem_read(BUF, BUF_SIZE))
|
||||
expect.append((ex, esp, enz, epc, ev, memory))
|
||||
page_path = work / 'page.bin'
|
||||
page_base = table.page & ~0xffff # Windows reserves at 64 KiB allocation granularity
|
||||
page_path.write_bytes(bytes(table.page - page_base) + page)
|
||||
total = 0
|
||||
for ratio, (cases, expect) in groups.items():
|
||||
mem = bytearray(initial)
|
||||
struct.pack_into('<f', mem, 0x2008, ratio)
|
||||
struct.pack_into('<f', mem, 0x3008, ratio)
|
||||
records, err = run_harness(exe, work, mem, cases, [(page_base, page_path)])
|
||||
assert not err and len(records) == len(cases), err
|
||||
for case, want, got in zip(cases, expect, records):
|
||||
differences = diff_state(got, want, False, True)
|
||||
assert not differences, (SITES[case[0]], differences)
|
||||
total += len(cases)
|
||||
print(f'v110: {len(SITES)} patch contracts, {total} native/Unicorn cases passed (on and off)')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
+1
-1
@@ -200,7 +200,7 @@
|
||||
# does. Read when a movie starts, so a change takes effect at the next movie.
|
||||
# movie_aspect = keep
|
||||
# Field of view, in percent of the game's own: 70 to 140, 100 (the default) leaves the camera as it is. Higher shows
|
||||
# more of the world around Link. Game version 1.4.3 only. Changes while the game runs take effect at once.
|
||||
# more of the world around Link. Game versions 1.1.0 and 1.4.3. Changes while the game runs take effect at once.
|
||||
# fov = 100
|
||||
# Anisotropic filtering of surface textures: game (the level the game asks for, as on the Switch) or 2, 4, 8, 16. Keeps
|
||||
# ground, roads and walls seen at a shallow angle sharp into the distance. Only filtered, mipmapped textures that tile
|
||||
|
||||
Reference in new issue
Block a user