Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
patches: Tears of the Kingdom 1.4.2 frame step and render scale sites
v0lumehie8ed45e6b703
diff --git a/patches/0037-totk-1.4.2-frame-step-sites.patch b/patches/0037-totk-1.4.2-frame-step-sites.patchnew file mode 100644index 00000000..5e7afce7--- /dev/null+++ b/patches/0037-totk-1.4.2-frame-step-sites.patch@@ -0,0 +1,195 @@+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001+From: Fred Chu <[email protected]>+Date: Sat, 31 Oct 2026 20:59:10 +0800+Subject: [PATCH] TOTK: frame step and render scale sites for 1.4.2++Tears of the Kingdom 1.4.2 (main 5cb42b1c...) packs from a derived profile,+so it had no frame step: the game kept its own present interval 2 while the+host presented at the profile's 60 fps, and the game ran at double speed+(LNPANDY/NX2Apple#303).++The frame step, the two readers of the integer fps, the D-pad menu fade and+the swapchain argument come from FPSLocker's config for this build+(5CB42B1CF25469FB.yaml). The two render scale sites were found by 1.4.3's+bytes: one match each, 0xc0 apart as on 1.4.3. By disassembly of 1.4.2's+main, all 9 sites hold the original instructions the stubs assert, and every+branch back lands on the next original instruction. The only difference is+the D-pad fade, which reads the menu entry through x25 and writes s9 on+1.4.2 (x24 and s10 on 1.4.3), so that stub now takes both registers from a+per-build site table. 1.4.3's output is unchanged: the same 140 events on a+recording context before and after.++game.tsv gets a `build v655360 1.4.2` row, the game note an "Update 1.4.2"+section, and docs/agents/game-patches.md is regenerated.++Measured on an M1 Max, macOS 27.0.1, with 1.4.2's main rewritten by this+change: DM_FPS_TARGET=60 holds 60.0 fps at 1.000 of real time from the+title on, DM_FPS_TARGET=30 holds 30.0 fps at 1.000; two gameplay runs past+the title (71 s and 115 s) held 1 vsync for every frame at 1.000 of real+time. test_patches, test_docs and test_nsp_incremental pass.++Upstream-Status: forwarded seedds/nxnative#793+Reason: Tears of the Kingdom 1.4.2 ran at double speed without frame step sites+Issue: LNPANDY/NX2Apple#303++---+ dm/games/0100F2C0115B6000/README.md | 7 +++++ dm/games/0100F2C0115B6000/game.tsv | 2 ++ dm/games/0100F2C0115B6000/patches.py | 61 ++++++++++++++++------------+ 3 files changed, 45 insertions(+), 25 deletions(-)++diff --git a/dm/games/0100F2C0115B6000/README.md b/dm/games/0100F2C0115B6000/README.md+index 67826da..0ccd1b9 100644+--- a/dm/games/0100F2C0115B6000/README.md++++ b/dm/games/0100F2C0115B6000/README.md+@@ -24,6 +24,13 @@ Update 1.4.3 (v720896) over the base game, SDK 20.5.22. Nintendo EPD's engine (s+ - **Resolved:** the yield back-off used to start after 200 µs, which caught the main thread waiting for its workers on the frame's critical path: frames ran past 33 ms and the game dropped itself to 20 fps (9 times in 300 s on the Mac; on the iPhone the threads also stayed on efficiency cores). From 2 ms on it never backs off ([development.md, Power](../../../docs/development.md#power)).+ - The spin-wait rewrite finds 843 loops in `main`; 701 of them are one inlined atomic decrement (a compare-and-swap retried after another thread changed the count), which yields only on a second retry in a row.+++## Update 1.4.2++++- **Current:** 1.4.2 (v655360, main `5cb42b1c…`) has the same frame step and render scale stubs at its own sites (`sites` in `patches.py`). It is packed from a derived profile, as its shaders are not in this profile's tables. Without the stubs it ran at double speed at the default 60 fps: the host presented every vsync while the game still stepped 1/30 s per frame (`the game sets present interval 1 → 2`, 60.0 fps).++- Sites: the frame step, the two fps readers, the D-pad fade and the swapchain argument from FPSLocker's config for this build (`5CB42B1CF25469FB.yaml`); the render scale sites by 1.4.3's bytes, one match each, `0xc0` apart as on 1.4.3. Every site's original instructions are 1.4.3's, except the D-pad fade, which reads the menu entry through x25 and writes s9 (x24 and s10 on 1.4.3). By disassembly, the registers each stub takes are dead there as on 1.4.3, and every branch back lands on the next original instruction. 1.4.3's stubs are unchanged: the same 140 events on a recording context.++- Measured on the Mac (M1 Max, a Mac app from 1.4.2 with the rewritten `main`, the boot to the title, 130 s): at 60, `frame step cap 0 → 60 fps`, 60.0 fps once the title had loaded, game time 32.03 s in 32.03 s (1.000 of real time); while loading it held 2 or 3 vsyncs. At 30, 30.0 fps throughout, 60.00 s in 60.00 s. Not checked: gameplay past the title, the D-pad menu fade, render scales below 1.0, the iPhone.++- The 1.4.2 `sdk` (`5cf080e8…`) is not 1.4.3's; it gets the node area cut of issue #70 ([Memory](#memory)) through the SDK-wide function match (`AddressRegionManager node area 1 GB → 62 MB`, matched at `0x145bfc` and `0x145c68`).+++ ## Memory++ - **Current (issue #147): confirmed transient upload-memory bug on the Mac; iOS validation pending.** With update 1.4.3, the corrected issue #70 SDK module, shader chain `dec5ee141a9f` and 30 fps, walking from the Great Sky Island save produced 10.70 GiB peak footprint after about 474 s; a shorter repeat reached 12.81 GiB after about 150 s. Live staging peaked at 4.48 / 5.82 GiB and the open batch at 4.41 / 5.75 GiB, then memory fell back near 4 GiB. The shorter burst logged 3,084.2 MB of uploads in one frame. A temporary 50 ms sampler and the kernel footprint-peak ledger caught peaks missed by the periodic reports and the 8 GiB sampled watchdog. With [bounded batches and upload-completion retirement](../../../docs/reference/memory.md#upload-staging-grows-within-one-rendering-submission), the 220 s shortened route with deferred encoding enabled peaked at 4.24 GiB footprint and 216 MiB live staging, without GPU errors. A 520 s replay of the original input timings peaked at 4.23 GiB / 200 MiB, but landed differently and reached Game Over earlier, so it is not an equivalent traversal comparison. These local results do not establish the cause of the reporter's full-device reboot or rule out longer-term cache growth; the requested save/route, full logs and Jetsam/panic reports are still needed for that comparison.+diff --git a/dm/games/0100F2C0115B6000/game.tsv b/dm/games/0100F2C0115B6000/game.tsv+index 223a7f7..fb0af7d 100644+--- a/dm/games/0100F2C0115B6000/game.tsv++++ b/dm/games/0100F2C0115B6000/game.tsv+@@ -16,7 +16,9 @@ app_category public.app-category.adventure-games+ pad_layout full++ # ---- Versions ----++# 1.4.2 (v655360) has its own frame step sites in patches.py; it is packed from a profile derived from it (its own shaders: these tables were made from 1.4.3's files)+ build v720896 1.4.3 main=277178b7dba1b6d4949a84778d4abc58 subsdk0=f39f4c431234c72eb520cfdd1001bbcf sdk=574284b40c06cf1821a44857939083be++build v655360 1.4.2 main=5cb42b1cf25469fb0635fd046453d843 subsdk0=3308c1d216f788397d1451c8345a16cd sdk=5cf080e800530a7f25bd528ec875c27b+ package v720896+ shader_versions v720896++diff --git a/dm/games/0100F2C0115B6000/patches.py b/dm/games/0100F2C0115B6000/patches.py+index 42673bc..0b6b7d7 100644+--- a/dm/games/0100F2C0115B6000/patches.py++++ b/dm/games/0100F2C0115B6000/patches.py+@@ -7,11 +7,12 @@ from nso_asm import ADRP, B, NOP, STP_PRE+ # and main+0x3e562c). The stub replaces that logic: int fps = 60 / step, and the float fps (timing +0x24, unused, per masagrator's FPSLocker config for this build, which found the+ # sites) the same, which the consumers read. Until the host has decided a step (the first frames) the step is the measured frame time (timing frame +0xd8, 19.2 MHz+ # ticks), clamped to [1 / cap, 1 / 15 s]; game time that ran ahead after a short frame (the "lead", at most 0.25 s; totk-mobile) is paid back by later frames. Prerendered movies hold 30 (the host's movie flag, state +4, hle_movie.c+-# dm_movie_playing), the D-pad menu fade starts at full rate (FPSLocker's fix at main+0x1fbc80) and the swapchain argument at main+0xbe14a8 becomes 1 as in FPSLocker+-def frame_step(ctx):++# dm_movie_playing), the D-pad menu fade starts at full rate (FPSLocker's fix at main+0x1fbc80) and the swapchain argument at main+0xbe14a8 becomes 1 as in FPSLocker.++# Offsets in the comments are 1.4.3's; each build's sites are in the sites table below++def frame_step(ctx, s):+ here, emit, fs_site, fs_put, FS_STATE_OFF = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state+ # frame step (replaces ldrb w9,[x0,#0x58], the first instruction after the prologue)+- fs_site(0x2db18c, '09604139')++ fs_site(s['step'], '09604139')+ start = here(); emit(ADRP(16, here(), FS_STATE_OFF))+ for w in (0xbd400200, # ldr s0,[x16] target fps+ 0x1e202008, # fcmp s0,#0.0+@@ -30,7 +31,7 @@ def frame_step(ctx):+ 0x8b224084, # add x4,x4,w2,uxtw+ 0xf9001a04): # str x4,[x16,#0x30] vsyncs stepped+ emit(w)+- emit(B(here(), 0x2db284)) # the original epilogue++ emit(B(here(), s['epilogue'])) # the original epilogue+ for w in (0xf9406c22, # elapsed: ldr x2,[x1,#0xd8] last frame time in 19.2 MHz ticks+ 0x9e630041, # ucvtf d1,x2+ 0x529f0003, # mov w3,#0xf800+@@ -66,11 +67,11 @@ def frame_step(ctx):+ 0x1e672a73, # fadd d19,d19,d7+ 0xfd000e13): # str d19,[x16,#0x18] game seconds stepped+ emit(w)+- emit(B(here(), 0x2db284)) # the original epilogue+- emit(0x39416009); emit(B(here(), 0x2db190)) # off: ldrb w9,[x0,#0x58]; back+- fs_put(0x2db18c, [B(0x2db18c, start)], 'frame step from the host in whole vsyncs, by elapsed time until it has decided one (state page target fps; 0 = original interval logic)')++ emit(B(here(), s['epilogue'])) # the original epilogue++ emit(0x39416009); emit(B(here(), s['step'] + 4)) # off: ldrb w9,[x0,#0x58]; back++ fs_put(s['step'], [B(s['step'], start)], 'frame step from the host in whole vsyncs, by elapsed time until it has decided one (state page target fps; 0 = original interval logic)')+ # the two readers of the integer fps: float fps when on; the scvtf a few instructions later moves into the stub (s0 is not touched in between)+- for site, cvt, r in ((0x2daa54, 0x2daa6c, 19), (0x3e562c, 0x3e5638, 22)):++ for site, cvt, r in s['readers']:+ fs_site(site, struct.pack('<I', 0xbd425000 | r << 5).hex()); fs_site(cvt, '00d8215e')+ start = here(); emit(STP_PRE(16, 17, 31, -16)); emit(ADRP(16, here(), FS_STATE_OFF))+ for w in (0xb9400211, # ldr w17,[x16]+@@ -84,30 +85,32 @@ def frame_step(ctx):+ emit(B(here(), site + 4))+ fs_put(site, [B(site, start)], 'game step reads the float fps (original integer fps and scvtf when off)')+ fs_put(cvt, [NOP], 'scvtf moved into the stub at the load')+- # D-pad menu fade (w8 is overwritten right after the site)+- fs_site(0x1fbc80, '0820201e0a04081f')++ # D-pad menu fade (w8 is overwritten right after the site). The menu entry's base register and the fade's destination differ by build: x24 and s10 on 1.4.3, x25 and s9 on 1.4.2++ fade, base, dst = s['fade']++ fmadd = 0x1f080400 | dst # fmadd s<dst>,s0,s8,s1++ fs_site(fade, '0820201e' + struct.pack('<I', fmadd).hex())+ start = here(); emit(ADRP(8, here(), FS_STATE_OFF))+ for w in (0xb9400108, 0x340001a8, # ldr w8,[x8]; cbz w8,off (+52)+ 0x1e202028, 0x54000101, # fcmp s1,#0.0; b.ne go+- 0x785fa308, 0x7100151f, 0x540000a1, # ldurh w8,[x24,#-6]; cmp w8,#5; b.ne go+- 0x785f8308, 0x7100151f, 0x54000041, # ldurh w8,[x24,#-8]; cmp w8,#5; b.ne go++ 0x785fa008 | base << 5, 0x7100151f, 0x540000a1, # ldurh w8,[x<base>,#-6]; cmp w8,#5; b.ne go++ 0x785f8008 | base << 5, 0x7100151f, 0x54000041, # ldurh w8,[x<base>,#-8]; cmp w8,#5; b.ne go+ 0x1e2e1008, # fmov s8,#1.0+- 0x1f08040a, 0x1e202008, 0x14000003, # go: fmadd s10,s0,s8,s1; fcmp s0,#0.0; b end+- 0x1e202008, 0x1f08040a): # off: the original fcmp s0,#0.0; fmadd s10,s0,s8,s1++ fmadd, 0x1e202008, 0x14000003, # go: fmadd s<dst>,s0,s8,s1; fcmp s0,#0.0; b end++ 0x1e202008, fmadd): # off: the original fcmp s0,#0.0; fmadd s<dst>,s0,s8,s1+ emit(w)+- emit(B(here(), 0x1fbc88))+- fs_put(0x1fbc80, [B(0x1fbc80, start), NOP], 'D-pad menu fade starts at full rate under fractional steps (FPSLocker)')++ emit(B(here(), fade + 8))++ fs_put(fade, [B(fade, start), NOP], 'D-pad menu fade starts at full rate under fractional steps (FPSLocker)')+ # swapchain argument (x16 is dead before the bl that follows)+- fs_site(0xbe14a8, '61a24039')++ fs_site(s['swapchain'], '61a24039')+ start = here(); emit(ADRP(16, here(), FS_STATE_OFF))+ for w in (0xb9400210, 0x34000070, 0x52800021, 0x14000002, 0x3940a261): # ldr w16,[x16]; cbz w16,off; mov w1,#1; b end; off: ldrb w1,[x19,#0x28]+ emit(w)+- emit(B(here(), 0xbe14ac))+- fs_put(0xbe14a8, [B(0xbe14a8, start)], 'swapchain argument 1 when on (FPSLocker)')++ emit(B(here(), s['swapchain'] + 4))++ fs_put(s['swapchain'], [B(s['swapchain'], start)], 'swapchain argument 1 when on (FPSLocker)')+ # Render scale (state +0x10, float written by the loader: DM_RENDER_SCALE, 1.0 by default). main+0xd5c24 sizes each view: screen size x the view's scale (5/6 for the scene: 1600x896+ # docked) x the dynamic-resolution multiplier, clamped to 8..16384 and floored to the view's alignment. The stub multiplies both extents by the factor (s6, w8 and the flags are dead+ # at main+0xd5cc0: s6 is set to 8.0 right after); any factor but 1.0 also replaces the dynamic multiplier (main+0xd5d80) with 1, so the size is fixed. 1.0 = bit-exact original+- fs_site(0xd5cc0, '08d0a8524008251e6108241e0401271e'); fs_site(0xd5d80, '062940bd')++ fs_site(s['view'], '08d0a8524008251e6108241e0401271e'); fs_site(s['dynamic'], '062940bd')+ start = here(); emit(ADRP(8, here(), FS_STATE_OFF))+ for w in (0xbd401106, # ldr s6,[x8,#0x10] render scale+ 0x1e250840, # fmul s0,s2,s5 (original)+@@ -119,8 +122,8 @@ def frame_step(ctx):+ 0x52a8d008, # skip: mov w8,#0x46800000 (original)+ 0x1e270104): # fmov s4,w8 (original)+ emit(w)+- emit(B(here(), 0xd5cd0))+- fs_put(0xd5cc0, [B(0xd5cc0, start)], 'view render size x the host render scale (1.0 = original)'); ctx.render_scale = 1++ emit(B(here(), s['view'] + 0x10))++ fs_put(s['view'], [B(s['view'], start)], 'view render size x the host render scale (1.0 = original)'); ctx.render_scale = 1+ start = here(); emit(0xbd402906); emit(ADRP(8, here(), FS_STATE_OFF)) # ldr s6,[x8,#0x28] (original: the dynamic multiplier); x8 is dead after it+ for w in (0xbd401107, # ldr s7,[x8,#0x10]+ 0x1e2e1010, # fmov s16,#1.0+@@ -130,10 +133,18 @@ def frame_step(ctx):+ 0x5400004d, # b.le done (+8) not set+ 0x1e204206): # fmov s6,s16 a fixed scale: no dynamic multiplier+ emit(w)+- emit(B(here(), 0xd5d84))+- fs_put(0xd5d80, [B(0xd5d80, start)], 'dynamic resolution only at render scale 1.0')++ emit(B(here(), s['dynamic'] + 4))++ fs_put(s['dynamic'], [B(s['dynamic'], start)], 'dynamic resolution only at render scale 1.0')++-FRAME_STEP = {'277178b7dba1b6d4949a84778d4abc58': frame_step}++# Each build's sites. 1.4.2's: the frame step, the fps readers, the D-pad fade and the swapchain argument from FPSLocker's config for that build (5CB42B1CF25469FB.yaml), the render++# scale sites by 1.4.3's bytes (one match each, at the same distance apart); every site's original instructions and the registers the stubs rely on checked by disassembly++sites = {++ '277178b7dba1b6d4949a84778d4abc58': {'step': 0x2db18c, 'epilogue': 0x2db284, 'readers': ((0x2daa54, 0x2daa6c, 19), (0x3e562c, 0x3e5638, 22)), # 1.4.3++ 'fade': (0x1fbc80, 24, 10), 'swapchain': 0xbe14a8, 'view': 0xd5cc0, 'dynamic': 0xd5d80},++ '5cb42b1cf25469fb0635fd046453d843': {'step': 0x2d4e68, 'epilogue': 0x2d4f60, 'readers': ((0x2d4730, 0x2d4748, 19), (0x37ea5c, 0x37ea68, 22)), # 1.4.2++ 'fade': (0x387390, 25, 9), 'swapchain': 0xbbf258, 'view': 0x10250c, 'dynamic': 0x1025cc},++}++FRAME_STEP = {bid: lambda ctx, s=s: frame_step(ctx, s) for bid, s in sites.items()}++ # How general each patch is and could be (dm/tools/docs_patches.py "Binding", listed in docs/agents/game-patches.md): what, its binding now, the loosest it could have (goal),+ # purpose, why; blocked or kept: why the gap stays open (cannot close yet, or left open on purpose); checked: what was checked on game files (else a judgement)diff --git a/patches/series b/patches/seriesindex 26bce982..77f6fdbe 100644--- a/patches/series+++ b/patches/series@@ -22,3 +22,4 @@0034-metal-a-newer-compiler-of-the-recorded-generatio.patch0035-the-3d-layout-points-at-its-invisible-right-stic.patch0036-the-layout-editor-long-press-the-layout-button-a.patch+0037-totk-1.4.2-frame-step-sites.patch