@@ -12,6 +12,7 @@ static int hid_usleep(useconds_t usec);
1212#undef usleep
1313#include "../pad_slots.h"
1414
15+ module_t * g_mod ; int g_nmod ; // no guest module in the generic HID regressions
1516static int checks , fails , g_mode = 1 , g_signals ;
1617static void * g_signalled ;
1718static time_t rumble_second = 1 ;
@@ -359,6 +360,43 @@ static void t_motion_hid(void) {
359360 dm_pad_players (1 ); g_phone_mode = -1 ;
360361}
361362
363+ static void t_nfs_race_buttons (void ) {
364+ static module_t m ;
365+ size_t size = 0x1800000 ;
366+ uint8_t * base = calloc (1 ,size ), * wrapper = calloc (1 ,0x20 ), * owner = calloc (1 ,0x14144c );
367+ CHECK (base && wrapper && owner ,"allocate isolated NFS control state" );
368+ if (!base || !wrapper || !owner ) abort ();
369+ strcpy (m .name ,"main" ); strcpy (m .build_id ,"799d1061182c1302e08e706b84ce76e5" );m .base = base ;m .size = size ;g_mod = & m ;g_nmod = 1 ;
370+ * (uint32_t * )(base + 0x1c0ae0 )= 0xd00061b7 ; * (uint32_t * )(base + 0x1c0ae4 )= 0xf9448ef7 ;
371+ * (uint32_t * )(base + 0x1c4ab4 )= 0x52828909 ; * (uint32_t * )(base + 0x1c4ab8 )= 0x72a00289 ; * (uint32_t * )(base + 0x1c4abc )= 0x38696908 ;
372+ * (uintptr_t * )(base + 0xeed0d0 )= (uintptr_t )wrapper ;* (uintptr_t * )(wrapper + 0x10 )= (uintptr_t )owner ;
373+ uint8_t * groups = owner + 0x141448 ;
374+ g_mode = 1 ;ids ((uint32_t []){0 },1 );dm_pad_players (1 );
375+ // Touch/keyboard, controller and script all pass through the real fill().
376+ for (int source = 0 ;source < 3 ;source ++ ) for (int state = 0 ;state < 6 ;state ++ ) {
377+ memset (groups ,0 ,4 );groups [1 ]= state != 0 ;groups [2 ]= state == 2 ;groups [3 ]= state == 3 ;
378+ if (state == 4 )groups [1 ]= 2 ;
379+ if (state == 5 )m .build_id [0 ]= '0' ;
380+ int driving = state == 1 ;
381+ for (unsigned bits = 0 ;bits < 16 ;bits ++ ) {
382+ dm_input_set (source == 0 ?bits :0 ,0 ,0 ,0 ,0 ); dm_pad_set (source == 1 ?bits :0 ,0 ,0 ,0 ,0 );script_set (source == 2 ?bits :0 ,0 ,0 ,0 ,0 );
383+ (void )buttons_of (0 ,STYLE_FULLKEY ); // drain the existing edge latch
384+ uint64_t expected = bits ;
385+ if (driving )expected = (bits & ~12u )|((bits & 4u )<<1 )|((bits & 8u )>>1 );
386+ CHECK (buttons_of (0 ,STYLE_FULLKEY )== expected ,"NFS driving-only X/Y; A/B and menus unchanged across input sources" );
387+ }
388+ m .build_id [0 ]= '7' ;
389+ }
390+ groups [1 ]= 1 ; groups [2 ]= groups [3 ]= 0 ;
391+ * (uintptr_t * )(wrapper + 0x10 )= 1 ;CHECK (race_buttons (DM_BTN_X )== DM_BTN_X ,"unreadable owner fails closed" );
392+ * (uintptr_t * )(wrapper + 0x10 )= (uintptr_t )owner ;
393+ * (uintptr_t * )(base + 0xeed0d0 )= 0 ;CHECK (race_buttons (DM_BTN_X )== DM_BTN_X ,"loading with no wrapper fails closed" );
394+ * (uintptr_t * )(base + 0xeed0d0 )= (uintptr_t )wrapper ;
395+ * (uint32_t * )(base + 0x1c4ab4 )^=1 ;CHECK (race_buttons (DM_BTN_X )== DM_BTN_X ,"different instruction fails closed" );
396+ g_nmod = 0 ;g_mod = NULL ;dm_input_set (0 ,0 ,0 ,0 ,0 );dm_pad_set (0 ,0 ,0 ,0 ,0 );script_set (0 ,0 ,0 ,0 ,0 );
397+ free (base );free (wrapper );free (owner );
398+ }
399+
362400int main (void ) {
363401 CHECK (setenv ("DM_RUMBLE_LOG" , "1" , 1 ) == 0 , "enable rumble diagnostics" );
364402 t_slots ();
@@ -369,6 +407,7 @@ int main(void) {
369407 t_motion_threads ();
370408 t_motion_live ();
371409 t_motion_hid ();
410+ t_nfs_race_buttons ();
372411 printf ("hid players: %d checks, %d failed\n" , checks , fails );
373412 return fails != 0 ;
374413}
0 commit comments