@@ -61,7 +61,8 @@ static int rd(uint64_t a, void *out, size_t n) { vm_size_t got = 0; return a >=
6161// Writing just its 60-fps flag or changing display Hz leaves the engine cap.
6262// Match FPSLocker's exact-build configuration; never apply these addresses to
6363// another build, or without the rewriter's asserted busy-wait repair.
64- static int nfs_init , nfs_target , nfs_logged ; static uint8_t * nfs_base ;
64+ static int nfs_init , nfs_target , nfs_logged , nfs_unlimited ; static uint8_t * nfs_base ;
65+ static uint64_t nfs_last_guest_ns ;
6566void dm_nfs_timing_init (void ) {
6667 int * initialized = & nfs_init ;
6768 if (* initialized ) return ;
@@ -79,10 +80,10 @@ void dm_nfs_timing_init(void) {
7980 LOG ("[RED] DM_NFS_FPS must be 0, 30, 60 or 120; using original 30" ); target = 30 ;
8081 }
8182 if (!target ) target = 30 ;
82- nfs_base = base ; nfs_target = target ;
83+ nfs_base = base ; nfs_target = target ; nfs_unlimited = dm_frame_limit_unlimited ();
8384 // Configure before the game initializes Metal/the display link. A 120-Hz
8485 // screen request alone leaves NVN's independent default 60-Hz pacer active.
85- char hz [16 ]; snprintf (hz ,sizeof hz ,"%d" ,target );
86+ char hz [16 ]; snprintf (hz ,sizeof hz ,"%d" ,nfs_unlimited ? 0 : target );
8687 setenv ("DM_PRESENT_HZ" ,hz ,1 ); setenv ("DM_PRESENT_INTERVAL" ,"display" ,1 ); setenv ("DM_PRESENT_LINK" ,"2" ,1 );
8788}
8889static void nfs_fps_tick (void ) {
@@ -94,15 +95,29 @@ static void nfs_fps_tick(void) {
9495 !rd ((uintptr_t )base + 0xeffc60 , & step , 8 ) || !step ) return ;
9596 const uint64_t addresses [] = {(uintptr_t )base + 0xf0043c , timer + 0x30 , timer + 0x28 , step + 0x30 , step + 0x50 };
9697 uint32_t old [5 ], want [5 ] = {target >= 60 , 19200000u / target , 1920000u / target , 0 , 0 };
97- float seconds = 1.0f / target ; memcpy (& want [3 ], & seconds , 4 ); want [4 ] = want [3 ];
98+ float seconds = 1.0f / target ;
99+ uint64_t now = 0 ;
100+ if (nfs_unlimited ) {
101+ now = guest_ns ();
102+ uint64_t elapsed = nfs_last_guest_ns && now > nfs_last_guest_ns ? now - nfs_last_guest_ns : 1000000000ull /(unsigned )target ;
103+ // The guest clock excludes host freeze/suspend. Both timing consumers
104+ // receive the same real duration, independent of frame/display rate.
105+ // A representable Switch tick interval is required before any write.
106+ __uint128_t ticks = (__uint128_t )elapsed * 19200000u /1000000000u ;
107+ if (!ticks || ticks > UINT32_MAX ) return ;
108+ want [0 ]= 1 ;want [1 ]= (uint32_t )ticks ;want [2 ]= (uint32_t )(ticks /10 );
109+ seconds = (float )((double )elapsed /1e9 );
110+ }
111+ memcpy (& want [3 ], & seconds , 4 ); want [4 ] = want [3 ];
98112 // Validate every destination before changing any field. Null/uninitialized
99113 // managers occur during loading; do not dereference or partially update them.
100114 for (int i = 0 ; i < 5 ; i ++ ) if (!rd (addresses [i ], & old [i ], 4 )) return ;
101115 if (old [0 ] > 1 ) return ;
116+ if (nfs_unlimited ) nfs_last_guest_ns = now ;
102117 for (int i = 0 ; i < 5 ; i ++ ) if (old [i ] != want [i ]) {
103118 uint32_t * p = (uint32_t * )(uintptr_t )addresses [i ]; dm_guest_write_prepare (p , 4 ); __atomic_store_n (p , want [i ], __ATOMIC_RELAXED );
104119 }
105- if (!nfs_logged ) { nfs_logged = 1 ; LOG ("main: NFS timer, tolerance and 2D/3D frame targets = %d fps (DM_NFS_FPS; actual performance unverified)" , target ); }
120+ if (!nfs_logged ) { nfs_logged = 1 ; LOG ("main: NFS timing %s, nominal %d fps; 2D/3D steps agree ( actual performance unverified)" , nfs_unlimited ? "unlimited, real elapsed clock" : "fixed target " , target ); }
106121}
107122
108123// NieR 1.0.3 exposes its preset minimum but ships fixed mode-specific fallbacks.
0 commit comments