mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
Merge pull request #1155: game 1.1.0 gets the climbing speed and gear rotation fixes above 60 fps, and the patch tools write their files as UTF-8 (shenjackyuanjie, #35, #276, #1001, #330, #984)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
8eec0eeedf
7 files changed
+358
-9
No files matched your search
+27
-1
@@ -13,8 +13,10 @@ The built-in table is [recomp/patches-v110.txt](../recomp/patches-v110.txt). The
|
||||
| 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. |
|
||||
| climb | 1 | Climbing speed above 60 fps: the 1.2.1 climb factor in the 1.1.0 climb controller. Follows `TOTK_CLIMB_FIX` and needs the real-time step. |
|
||||
| gears | 2 | The gear rotation check scales its one-frame threshold by the update's frame delta, so shrine gears read as turning above 30 fps. Follows `TOTK_HIGHFPS_FIX`. |
|
||||
|
||||
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 table has 16 sets and 54 instruction sites in total. Its 889 spin back-edges are unchanged. The 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.
|
||||
|
||||
@@ -39,3 +41,27 @@ 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.
|
||||
|
||||
## Climbing and gears
|
||||
|
||||
Both sets port their 1.2.1 counterparts in [recomp/patches-v121.txt](../recomp/patches-v121.txt); the comments there explain the formulas.
|
||||
|
||||
**climb**, one site at main+0x19279f0 (1.2.1: main+0x19182cc) in the climb controller's velocity step at main+0x1927948. The site replaces `fmov s1, #1.5` after the shipping factor 1.272 - 0.362 (r - 1), r in s9, s8 = 0.5. The body between prologue and epilogue is word for word the 1.2.1 one: it reads u = max(page +0, r) and gives s0 = max(s0, h), s1 = max(1.5, h). At r >= 1 h stays at or below the shipping factor, so 30 fps and slower keep it bit for bit; at 60 fps the factor becomes 1.4.3's, about 1.8665 instead of 1.453; above 60 fps g(u) takes over. Unlike 1.2.1, the site does not rely on dead registers: a 96-byte stack frame saves x8 and full q5, q6, q7, q16 and q17 and restores them before the original code continues, so only s0 and s1 change. `TOTK_CLIMB_FIX=0` runs the original `fmov`; [frame_step_init](../runtime/frame_rate.c) switches the set off without the real-time step, where the page is not written.
|
||||
|
||||
**gears**, two sites in the ActorCheckRotateModule update at main+0x213eec4 (vtable 0x347e8e8 slot +0x110; 1.2.1: main+0x21350c0). The first, main+0x213eee4, loads the update context's frame delta (x1 + 8) into s12 before the function overwrites x1; the prologue saved d12 at main+0x213eec8, nothing writes s12 before the second site, and callees preserve the low 64 bits of v12. The second, main+0x213f0d4, turns `fdiv s12, s0, s4` into s12 = (s0 / s4) * delta, the RotateStartDeg / 30 threshold scaled by the delta, which the three `fcmp s8, s12` at main+0x213f10c, +0x213f174 and +0x213f1b0 read. It saves full q4 in a 16-byte stack slot and restores it and SP. The set does not read the patch page and works with or without the real-time step; `TOTK_HIGHFPS_FIX=0` keeps both original sites.
|
||||
|
||||
Each original window below occurs once in the 1.1.0 main (addresses and hashes, not game bytes):
|
||||
|
||||
| Window | Length | SHA-256 |
|
||||
| --- | ---: | --- |
|
||||
| +0x19279b0 | 108 bytes | 8262a11c180c734f2692a74e9563140f26d743f0f1f95d31732f975b46c27331 |
|
||||
| +0x213eee4 | 32 bytes | 17487c0fe195655e9a1bcaf49835208bd1ebca86eeef9a2ca0059752f503e378 |
|
||||
| +0x213f0d0 | 28 bytes | d07279a2abea53cffbd8861e95034cd1a5c85edf90f6094c5261ba55da203577 |
|
||||
|
||||
```sh
|
||||
python tests/patches_v110_highfps_check.py
|
||||
python tests/patches_v110_highfps_check.py --cflags=-march=x86-64-v2
|
||||
python tests/patches_v110_highfps_check.py --exefs <local ExeFS directory>
|
||||
```
|
||||
|
||||
The test lifts both sets and runs them against Unicorn on and off, at 30, 60, 120 and 240 Hz and slower steps, with zero and tiny deltas, adjacent ULPs around 0.5 and at each compare threshold, and all 16 NZCV values (3240 cases). It compares all general and full 128-bit SIMD registers, SP, NZCV and the whole scratch memory: only s0/s1 (climb), x1/s12 (gears) and the exact save slots may change. It also compiles [patches.c](../runtime/patches.c) with frame_step_init for the nine combinations of the three switches. With `--exefs` it checks every original word, the shipping constants, the d12 save, the vtable entry and the three compares with their branch targets. These are instruction and switch contracts; climbing and the shrine gears still need checks in the game.
|
||||
@@ -119,6 +119,23 @@ site cascade main 1158040 52a84408 @page:x8 b9404508
|
||||
site cascade main 11580c8 52a85408 @page:x8 b9404908
|
||||
site cascade main 115814c 52a86408 @page:x8 b9404d08
|
||||
|
||||
# High-frame-rate climbing (#35, #276, #1001): r is in s9 in the local 1.1.0 controller at main+0x1927948.
|
||||
# The shipping formula multiplies by -0.181, doubles with fadd, then adds 1.272; keep its rounding and [0.5, 1.5] clamp.
|
||||
# For r<1 use the 1.2.1 climb h(r,u), u=max(page+0,r); the normal 30 Hz factor stays unchanged.
|
||||
# runtime/frame_rate.c disables climb when realtime=0; TOTK_CLIMB_FIX=0 keeps the original instruction.
|
||||
# A 96-byte, 16-byte-aligned stack frame saves x8 and full q5/q6/q7/q16/q17; only s0/s1 are outputs.
|
||||
set climb TOTK_CLIMB_FIX 1
|
||||
site climb main 19279f0 1e2f1001 d10183ff f90003e8 ad009be5 ad01c3e7 3d8017f1 @page:x8 bd400111 1e296a31 1e2e1005 1e3138a5 52862508 72a7e308 1e270106 1e2608a5 1e2528a5 529a1ca8 72a7f448 1e270106 1e2628a5 1e201006 1e2678a5 52946dc8 72a7e528 1e270106 1e3118c6 52828248 72a7dfe8 1e270107 1e2728c6 529573e8 72a7b5a8 1e270107 1f1118e6 1e283a27 2f00e410 1e3068e7 1e261010 1f1098e6 1e241010 1e3078c6 1e2668a5 1e256800 1e2f1001 1e256821 3dc017f1 ad41c3e7 ad409be5 f94003e8 910183ff
|
||||
|
||||
# Gear rotation check (#330, #984): main+0x213eec4, vtable 0x347e8e8 slot +0x110.
|
||||
# AI dispatchers 0x1205b90 / 0x2ae29ac pass a context with frame delta at +8; keep it in the already-saved s12.
|
||||
# Scale RotateStartDeg/30 by that delta for all three angle compares: 0x213f10c/0x213f174/0x213f1b0.
|
||||
# The second site saves full q4 in a 16-byte stack slot, without relying on a later callee killing it.
|
||||
# This set does not read the patch page and works with realtime=0; TOTK_HIGHFPS_FIX=0 keeps both original sites.
|
||||
set gears TOTK_HIGHFPS_FIX 1
|
||||
site gears main 213eee4 f9402001 bd40082c f9402001
|
||||
site gears main 213f0d4 1e24180c 3c9f0fe4 1e241804 1e2c088c 3cc107e4
|
||||
|
||||
# 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.
|
||||
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ def load(path, mods):
|
||||
"""Table from a patch file; mods is layout() output [(name, base, size)]."""
|
||||
sets, index, sites, spins, hooks, ordered, plugins = [], {}, {}, {}, {}, set(), {}
|
||||
bases = {n: (b, s) for n, b, s in mods}
|
||||
for no, raw in enumerate(Path(path).read_text().splitlines(), 1):
|
||||
for no, raw in enumerate(Path(path).read_text(encoding='utf-8').splitlines(), 1):
|
||||
f = raw.split('#', 1)[0].split()
|
||||
if not f:
|
||||
continue
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
"""Check the 1.1.0 climb/gear numeric, switch, full-width register and local-stack contracts.
|
||||
|
||||
Synthetic checks need no game; --exefs also checks local original words and semantic anchors.
|
||||
Uses the shared differential harness CC selection, Windows/Linux suffixes and mappings, without fixed host paths.
|
||||
"""
|
||||
import argparse
|
||||
import math
|
||||
import os
|
||||
import struct
|
||||
import subprocess
|
||||
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, compiler, diff_state, run_harness
|
||||
import patches
|
||||
from layout import layout
|
||||
from lifter import Lifter
|
||||
from module import Module
|
||||
|
||||
NL = chr(10)
|
||||
CLIMB, GEAR_LOAD, GEAR_SCALE = 0x19279f0, 0x213eee4, 0x213f0d4
|
||||
COMPARES = (0x213f10c, 0x213f174, 0x213f1b0)
|
||||
SITES = (CLIMB, GEAR_LOAD, GEAR_SCALE)
|
||||
|
||||
|
||||
def f32(x):
|
||||
return struct.unpack('<f', struct.pack('<f', x))[0]
|
||||
|
||||
|
||||
def bits(x):
|
||||
return int.from_bytes(struct.pack('<f', x), 'little')
|
||||
|
||||
|
||||
def scalar(x):
|
||||
return struct.unpack('<f', (x & 0xffffffff).to_bytes(4, 'little'))[0]
|
||||
|
||||
|
||||
def shipping(r):
|
||||
# Round in v110 order: multiply, double, then add the intercept; do not fuse the -0.362 multiplication.
|
||||
t = f32(f32(r - 1.0) * f32(-0.181))
|
||||
return f32(f32(t + t) + f32(1.272))
|
||||
|
||||
|
||||
def compensation(r, raw):
|
||||
u = max(raw, r)
|
||||
g = math.inf if u == 0 else 0.66265 / u + 0.4982 + 0.0848 * u
|
||||
h = max(min(1.272 + 1.189 * (1 - u), 2), min(g - 16 * max(u - 0.5, 0), 8))
|
||||
return h
|
||||
|
||||
|
||||
def extract_function(text, name):
|
||||
start = text.index(name + '(')
|
||||
start = text.rfind(NL, 0, start) + 1
|
||||
opening = text.index('{', start)
|
||||
depth = 1
|
||||
end = opening + 1
|
||||
while depth:
|
||||
depth += (text[end] == '{') - (text[end] == '}')
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def gating_check(work, table):
|
||||
# Compile the real patches.c and frame_step_init/step_store; stub only config and platform memory boundaries.
|
||||
cfg = (ROOT / 'runtime' / 'cfg.c').read_text(encoding='utf-8')
|
||||
for key in ('CLIMB_FIX', 'HIGHFPS_FIX', 'REALTIME'):
|
||||
assert '{"' + key + '", "1", "0|1"' in cfg, key
|
||||
source = (ROOT / 'runtime' / 'patches.c').read_text(encoding='utf-8')
|
||||
source = NL.join(x for x in source.splitlines() if not x.startswith('#include'))
|
||||
frame = (ROOT / 'runtime' / 'frame_rate.c').read_text(encoding='utf-8')
|
||||
# Keep the real patch API declarations, including the ordered-site types and forward declarations.
|
||||
host = (ROOT / 'runtime' / 'host.h').read_text(encoding='utf-8')
|
||||
patch_api = host[host.index('void rt_patches_init(void);'):host.index('void frame_step_init(void);')]
|
||||
pre = '''#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
static _Alignas(16) unsigned char test_page[4096];
|
||||
static int real_on, climb_on, high_on;
|
||||
static const char *cfg_get(const char *e) {
|
||||
if (!strcmp(e,"TOTK_REALTIME")) return real_on<0?NULL:real_on?"1":"0";
|
||||
if (!strcmp(e,"TOTK_CLIMB_FIX")) return climb_on<0?NULL:climb_on?"1":"0";
|
||||
if (!strcmp(e,"TOTK_HIGHFPS_FIX")) return high_on<0?NULL:high_on?"1":"0";
|
||||
return NULL;
|
||||
}
|
||||
static const void *cfg_meta(const char *e) {
|
||||
return !strcmp(e,"TOTK_REALTIME") || !strcmp(e,"TOTK_CLIMB_FIX") || !strcmp(e,"TOTK_HIGHFPS_FIX") ? e : NULL;
|
||||
}
|
||||
static int cfg_bool(const char *e) { const char *v=cfg_get(e); return !v || strcmp(v,"0"); }
|
||||
static int plat_mem_commit(uint64_t a, size_t n) { return a==(uintptr_t)test_page && n==4096; }
|
||||
static void rt_fatal(const char *s, ...) { (void)s; abort(); }
|
||||
static void rt_log(const char *s, ...) { (void)s; }
|
||||
'''
|
||||
macro = '#define RT_PATCH_COUNT %d' % len(table.sets) + NL
|
||||
macro += '#define RT_PATCH_PAGE ((uintptr_t)test_page)' + NL
|
||||
macro += '#define RT_PATCH_SETS(X) ' + ' '.join('X(%d,%s,"%s",%d)' % (i, *s) for i, s in enumerate(table.sets)) + NL
|
||||
frame_pre = '''static _Atomic uint64_t *step_word;
|
||||
static _Atomic uint32_t *step_interval;
|
||||
static double step_now;
|
||||
#define STEP_FIRST_S (1.0/60.0)
|
||||
static void frame_limit_live(void) {}
|
||||
'''
|
||||
main = '''int main(void) {
|
||||
for (int i=-1;i<8;i++) {
|
||||
real_on=i<0?-1:!!(i&1); climb_on=i<0?-1:!!(i&2); high_on=i<0?-1:!!(i&4);
|
||||
memset(test_page,0x5a,sizeof test_page); step_word=NULL; step_interval=NULL;
|
||||
rt_patches_init(); frame_step_init();
|
||||
assert(rt_patch_enabled(rt_patch_set("climb"))==((real_on!=0)&&(climb_on!=0)));
|
||||
assert(rt_patch_enabled(rt_patch_set("gears"))==(high_on!=0));
|
||||
assert((step_word!=NULL)==(real_on!=0));
|
||||
if (real_on==0) for (size_t j=0;j<sizeof test_page;j++) assert(test_page[j]==0x5a);
|
||||
else { float v; memcpy(&v,test_page,4); assert(v==0.5f); }
|
||||
}
|
||||
puts("v110: 9 native default/realtime/climb/highfps gating combinations passed");
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
c = work / 'gating.c'
|
||||
c.write_text(pre + patch_api + macro + source + frame_pre + extract_function(frame, 'step_store') + NL +
|
||||
extract_function(frame, 'frame_step_init') + NL + main, encoding='utf-8')
|
||||
exe = work / ('gating.exe' if os.name == 'nt' else 'gating')
|
||||
subprocess.run([compiler(), '-std=gnu11', '-O1', '-UNDEBUG', str(c), '-o', str(exe)], check=True)
|
||||
subprocess.run([str(exe)], check=True)
|
||||
fixture = work / 'unicode-patch.txt'
|
||||
# Chinese fixture data intentionally tests UTF-8 decoding independently of the host encoding.
|
||||
fixture.write_text('# 中文注释,不依赖宿主默认代码页' + NL + 'set test TEST 1' + NL, encoding='utf-8')
|
||||
assert patches.load(fixture, [('main', 0x7000000000, 4096)]).sets == [('test', 'TEST', 1)]
|
||||
|
||||
|
||||
def local_check(exefs, table, mods):
|
||||
for name, base, _ in mods:
|
||||
patches.check(table, Module(name, exefs / name, base), name)
|
||||
main = Module('main', exefs / 'main', mods[0][1])
|
||||
base = mods[0][1]
|
||||
# Local semantic anchors: original coefficients, saved d12, vtable target and three matching compares/branches.
|
||||
assert main.read(base + 0x3816770, 4) == bits(-0.181)
|
||||
assert main.read(base + 0x3816774, 4) == bits(1.272)
|
||||
assert main.word(base + CLIMB - 8) == 0x1e202800 # The shipping factor first doubles with fadd s0,s0,s0.
|
||||
assert main.word(base + 0x213eec8) == 0xfd002bec # str d12,[sp,#0x50]
|
||||
assert main.read(base + 0x347e9f8, 8) == 0x213eec4
|
||||
for off, target in zip(COMPARES, (0x213f148, 0x213f13c, 0x213f13c)):
|
||||
assert main.word(base + off) == 0x1e2c2100
|
||||
branch = main.word(base + off + 4)
|
||||
assert branch & 0xff00001f == 0x5400000d
|
||||
assert patches.branch_target(branch, base + off + 4) == base + target
|
||||
print('v110: all %d opcode guards, %d spin targets and local highfps anchors passed' %
|
||||
(sum(map(len, table.sites.values())), sum(map(len, table.spins.values()))))
|
||||
|
||||
|
||||
def preservation(ex, esp, ev, x, sp, v, allowed_x, allowed_v):
|
||||
assert esp == sp and sp % 16 == 0
|
||||
assert all(ex[i] == x[i] for i in range(31) if i not in allowed_x), 'GPR preservation'
|
||||
assert all(ev[i] == v[i] for i in range(32) if i not in allowed_v), 'Full 128-bit SIMD preservation'
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__)
|
||||
ap.add_argument('--exefs', type=Path)
|
||||
ap.add_argument('--cflags', default='-march=x86-64-v3')
|
||||
ap.add_argument('--work-dir', type=Path, default=ROOT / 'build')
|
||||
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)
|
||||
if args.exefs:
|
||||
local_check(args.exefs, table, mods)
|
||||
sets = {name: (env, default) for name, env, default in table.sets}
|
||||
assert sets['climb'] == ('TOTK_CLIMB_FIX', 1)
|
||||
assert sets['gears'] == ('TOTK_HIGHFPS_FIX', 1)
|
||||
base = mods[0][1]
|
||||
resolved = table.for_module('main', base)
|
||||
original, replacement = {}, {}
|
||||
for off in SITES:
|
||||
alternatives = table.sites['main'][off]
|
||||
assert len(alternatives) == 1
|
||||
original[off] = [alternatives[0][2]]
|
||||
replacement[off] = resolved[base + off][0][1]
|
||||
specs = [(CLIMB,), (GEAR_LOAD,), (GEAR_SCALE,)] + [(GEAR_LOAD, GEAR_SCALE, off) for off in COMPARES]
|
||||
programs, bodies = [], []
|
||||
lift = Lifter(base, 'c')
|
||||
for spec in specs:
|
||||
on, off = [], []
|
||||
for address in spec:
|
||||
if address == GEAR_SCALE and len(spec) == 3:
|
||||
# Model a legal callee clobbering the upper 64 bits of q12; delta must rely only on preserved d12.
|
||||
on += [0x4e181d0c] # mov v12.d[1],x8
|
||||
off += [0x4e181d0c]
|
||||
if address in COMPARES:
|
||||
# A handwritten cset records this b.le condition without copying a game function or skipping its test.
|
||||
pair = [0x1e2c2100, 0x1a9fc7f8]
|
||||
on += pair
|
||||
off += pair
|
||||
else:
|
||||
on += replacement[address]
|
||||
off += original[address]
|
||||
def lower(words):
|
||||
ops = [lift.lift(w, base + spec[0]) for w in words]
|
||||
assert all(i.kind == 'op' for i in ops)
|
||||
return ' '.join(i.code for i in ops)
|
||||
bodies.append('if (c->x[30]) { ' + lower(on) + ' } else { ' + lower(off) + ' }')
|
||||
programs.append((off, on))
|
||||
args.work_dir.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='v110-highfps-', dir=args.work_dir) as temp:
|
||||
work = Path(temp)
|
||||
gating_check(work, table)
|
||||
exe = build_harness(work, bodies, 2, args.cflags)
|
||||
total = 0
|
||||
raw_steps = (0.0, 1e-8, 0.125, 0.25, f32(0.5 - 2**-24), 0.5, f32(0.5 + 2**-23), 1.0, 2.0, 16.0)
|
||||
for raw in raw_steps:
|
||||
raw = f32(raw)
|
||||
mem = bytearray((i * 37 + 19) & 255 for i in range(BUF_SIZE))
|
||||
struct.pack_into('<Q', mem, 0x2040, BUF + 0x4000)
|
||||
struct.pack_into('<f', mem, 0x3008, raw)
|
||||
page = bytearray(4096)
|
||||
struct.pack_into('<f', page, 0, raw)
|
||||
cases, expected = [], []
|
||||
for k, spec in enumerate(specs):
|
||||
for enabled in (0, 1):
|
||||
for r in (0.0, 1e-8, 0.125, 0.25, 0.5, 0.75, 1.0, 2.0, 16.0):
|
||||
r = f32(r)
|
||||
for edge in (-1, 0, 1):
|
||||
# x30 selects the test path; other GPRs and vector upper bits have distinct sentinels.
|
||||
x = [0x1234567800000000 + i * 0x101 for i in range(31)]
|
||||
x[0], x[1], x[30] = BUF + 0x2000, BUF + 0x3000, enabled
|
||||
v = [((0xfedcba987654321001234567 + i) << 32) | bits(3.0 + i) for i in range(32)]
|
||||
for reg, value in ((0, shipping(r)), (4, 30.0), (9, r), (12, raw)):
|
||||
v[reg] = (v[reg] & ~0xffffffff) | bits(value)
|
||||
assert all(v[reg] >> 64 for reg in (4, 8, 9)), 'Upper 64-bit SIMD sentinels must be nonzero'
|
||||
threshold = f32(f32(shipping(r) / 30) * raw) if enabled else f32(shipping(r) / 30)
|
||||
# Adjacent ULPs exercise greater-than, equal and less-than at all three branch thresholds.
|
||||
tb = bits(threshold)
|
||||
v[8] = (v[8] & ~0xffffffff) | (bits(0.5) if k == 0 else max(0, tb + edge))
|
||||
sp, nzcv = BUF + BUF_SIZE - 0x100, ((total + len(cases)) % 16) << 28
|
||||
code = programs[k][enabled]
|
||||
pc = base + spec[0]
|
||||
lo = pc & ~0xffff
|
||||
text = bytearray(pc - lo + 4 * len(code))
|
||||
struct.pack_into('<' + 'I' * len(code), text, pc - lo, *code)
|
||||
emu = Emu([(lo, text), (table.page, page)])
|
||||
emu.mu.mem_write(BUF, bytes(mem))
|
||||
ex, esp, enz, epc, ev = emu.run(pc, 0, x, sp, nzcv, v, count=len(code))
|
||||
allowed_x = {1} if GEAR_LOAD in spec else set()
|
||||
if len(spec) == 3:
|
||||
allowed_x |= {24}
|
||||
allowed_v = {0, 1} if k == 0 else {12}
|
||||
preservation(ex, esp, ev, x, sp, v, allowed_x, allowed_v)
|
||||
if len(spec) != 3:
|
||||
assert enz == nzcv
|
||||
touched = []
|
||||
if enabled and k == 0:
|
||||
touched = [(sp - 96, x[8].to_bytes(8, 'little'))]
|
||||
touched += [(sp - 80 + i * 16, v[reg].to_bytes(16, 'little'))
|
||||
for i, reg in enumerate((5, 6, 7, 16, 17))]
|
||||
h = compensation(r, raw)
|
||||
for reg, want in ((0, max(shipping(r), h)), (1, max(1.5, h))):
|
||||
assert math.isclose(scalar(ev[reg]), want, rel_tol=2e-6, abs_tol=2e-7), (reg, r, raw, scalar(ev[reg]), want)
|
||||
assert ev[reg] >> 32 == 0
|
||||
if r >= 1 and raw <= r:
|
||||
assert ev[0] & 0xffffffff == v[0] & 0xffffffff and ev[1] == bits(1.5), 'Shipping factor bits unchanged at 30 Hz and slower steps'
|
||||
if not enabled and k == 0:
|
||||
assert ev[0] == v[0] and ev[1] == bits(1.5)
|
||||
if enabled and GEAR_SCALE in spec:
|
||||
touched = [(sp - 16, v[4].to_bytes(16, 'little'))]
|
||||
want = f32(f32(scalar(v[0]) / scalar(v[4])) * raw)
|
||||
assert ev[12] == bits(want)
|
||||
if GEAR_LOAD in spec:
|
||||
assert ex[1] == BUF + 0x4000
|
||||
if k == 1 and enabled:
|
||||
assert ev[12] == bits(raw)
|
||||
if len(spec) == 3:
|
||||
angle, limit = scalar(v[8]), scalar(ev[12])
|
||||
# ARM64 b.le also accepts unordered (N != V), unlike Python NaN <= comparisons.
|
||||
want_branch = math.isnan(angle) or math.isnan(limit) or angle <= limit
|
||||
assert ex[24] == want_branch, (spec, enabled, raw, r, edge, ex[24], angle, limit, hex(enz))
|
||||
want_mem = bytearray(mem)
|
||||
for address, data in touched:
|
||||
at = address - BUF
|
||||
want_mem[at:at + len(data)] = data
|
||||
actual_mem = bytes(emu.mu.mem_read(BUF, BUF_SIZE))
|
||||
assert actual_mem == want_mem, 'Only exact save slots may change; all other memory, gaps and canaries must stay intact'
|
||||
assert actual_mem[sp - BUF - 112:sp - BUF - 96] == mem[sp - BUF - 112:sp - BUF - 96]
|
||||
assert actual_mem[sp - BUF:sp - BUF + 16] == mem[sp - BUF:sp - BUF + 16]
|
||||
cases.append((k, 0, x, sp, nzcv, v, True))
|
||||
expected.append((ex, esp, enz, epc, ev, zlib.crc32(actual_mem)))
|
||||
page_path = work / 'page.bin'
|
||||
page_base = table.page & ~0xffff
|
||||
page_path.write_bytes(bytes(table.page - page_base) + page)
|
||||
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, expected, records):
|
||||
delta = diff_state(got, want, False, True)
|
||||
assert not delta, (specs[case[0]], delta)
|
||||
total += len(cases)
|
||||
print(f'v110: {total} native/Unicorn cases passed; 6 contracts, on/off, 16 NZCV, full GPR/SIMD/SP/memory')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
+3
-3
@@ -349,7 +349,7 @@ def main():
|
||||
args = ap.parse_args()
|
||||
sys.stdout.reconfigure(errors='replace') # cheat names in a console without their characters
|
||||
m = Main(args.exefs / 'main')
|
||||
text = args.patches.read_text()
|
||||
text = args.patches.read_text(encoding='utf-8')
|
||||
files = cheat_files(args.mods, build_id(args.exefs / 'main'))
|
||||
cheats = [c for mod, f in files for c in parse(f.read_text(encoding='utf-8-sig', errors='replace'), mod)]
|
||||
sets, sites, status = [], [], []
|
||||
@@ -357,7 +357,7 @@ def main():
|
||||
classify(m, c)
|
||||
if c.sites:
|
||||
name = f'cheat_{c.key.lower()}'
|
||||
label = c.name.encode('ascii', 'replace').decode() # recomp/patches.py reads the file as ASCII
|
||||
label = c.name.encode('ascii', 'replace').decode() # a comment only, kept ASCII like the mod labels
|
||||
sets.append(f'set {name} TOTK_CHEAT_{c.key} {1 if c.kind == "master" else 0} # {label}')
|
||||
for a, repl in sorted(c.sites.items()):
|
||||
sites.append(f'site {name} main {a:x} {m.word(a):08x} {" ".join(f"{w:08x}" for w in repl)}')
|
||||
@@ -367,7 +367,7 @@ def main():
|
||||
print(f'cheats: {c.kind:11} {c.name}' + (f' ({note})' if note else ''))
|
||||
if sets:
|
||||
text += ('\n# Cheats of the mods folder (tools/cheats.py)\n' + '\n'.join(sets) + '\n' + '\n'.join(sites) + '\n')
|
||||
args.out.write_text(text)
|
||||
args.out.write_text(text, encoding='utf-8')
|
||||
args.status.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.status.write_text('\n'.join(status) + ('\n' if status else ''), encoding='utf-8')
|
||||
kinds = {}
|
||||
|
||||
@@ -319,7 +319,7 @@ def build(args):
|
||||
m = Main(args.exefs / 'main')
|
||||
md = MainData(m) if args.data else None
|
||||
bid = m.nso.build_id
|
||||
text = args.patches.read_text()
|
||||
text = args.patches.read_text(encoding='utf-8')
|
||||
builtin = builtin_sites(text)
|
||||
files = patch_files(args.mods)
|
||||
sets, sites, status, data_lines, kinds = [], [], [], [], {}
|
||||
@@ -351,7 +351,7 @@ def build(args):
|
||||
if sets:
|
||||
text += ('\n# ExeFS patches of the mods folder (tools/exefs_patches.py)\n' + '\n'.join(sets) + '\n'
|
||||
+ '\n'.join(sites) + '\n')
|
||||
args.out.write_text(text)
|
||||
args.out.write_text(text, encoding='utf-8')
|
||||
args.status.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.status.write_text('\n'.join(status) + ('\n' if status else ''), encoding='utf-8')
|
||||
if args.data:
|
||||
|
||||
@@ -454,7 +454,7 @@ def plugin_files(mods):
|
||||
def emit(results, args):
|
||||
"""--patches-out and --status from the checked plugins. results: one (module, its NSO file, its record or None,
|
||||
the record's directory, hooks, reasons) per plugin of the layout; no reasons: accepted."""
|
||||
text = args.patches.read_text() if args.patches else ''
|
||||
text = args.patches.read_text(encoding='utf-8') if args.patches else ''
|
||||
builtin = builtin_sites(text)
|
||||
status, sets = [], []
|
||||
files = {str(f.resolve()): (m, rel, f) for m, rel, f in plugin_files(args.mods)}
|
||||
@@ -482,7 +482,7 @@ def emit(results, args):
|
||||
if over else ''))
|
||||
if sets:
|
||||
text += '\n# Mod plugins (tools/exefs_plugins.py)\n' + '\n'.join(line for s in sets for line in s) + '\n'
|
||||
args.patches_out.write_text(text)
|
||||
args.patches_out.write_text(text, encoding='utf-8')
|
||||
args.status.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.status.write_text('\n'.join(status) + ('\n' if status else ''), encoding='utf-8')
|
||||
|
||||
|
||||
Reference in new issue
Block a user