@@ -1403,18 +1403,157 @@ static void core_performance_counter_stop(struct retro_perf_counter *perf)
14031403
14041404static void rarch_get_extra_input_actions (rarch_system_info_t * system_info ,
14051405 struct retro_get_extra_input_actions * request ) {
1406-
1407- /* We only know about the joypad. */
1406+ /* We only know/care about the joypad. */
14081407 if (request -> query .device != RETRO_DEVICE_JOYPAD ) {
14091408 request -> response .known = false;
14101409 }
14111410
1412- /* TODO: Implement this. */
1411+ /* Reserve all the buttons after the current maximum. */
1412+ /* When cores send the input descriptors they will have to start at the given base. */
14131413 request -> response .known = true;
1414- request -> response .num_extra = 1 ;
1415- request -> response .extra_start_id = 128 ;
1414+ request -> response .extra_start_id = RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS ;
1415+ request -> response .num_extra = RARCH_MAX_EXTRA_BUTTON ;
1416+ }
1417+
1418+ static void rarch_set_input_descriptors (const void * data , unsigned int p ,
1419+ runloop_state_t * runloop_st , const settings_t * settings ,
1420+ rarch_system_info_t * sys_info ) {
1421+ unsigned retro_id ;
1422+ const struct retro_input_descriptor * desc = NULL ;
1423+ memset ((void * )& sys_info -> input_desc_btn , 0 ,
1424+ sizeof (sys_info -> input_desc_btn ));
1425+
1426+ desc = (const struct retro_input_descriptor * )data ;
1427+
1428+ for (; desc -> description ; desc ++ )
1429+ {
1430+ unsigned retro_port = desc -> port ;
1431+
1432+ retro_id = desc -> id ;
1433+
1434+ if (desc -> port >= MAX_USERS )
1435+ continue ;
1436+
1437+ /* Ignore extended custom binds. */
1438+ if (desc -> id >= RARCH_FIRST_CUSTOM_BIND )
1439+ {
1440+ /* However if we are using extra keys, remap them accordingly. */
1441+ if (!(desc -> id >= RARCH_EXTRA_BUTTON_ID (0 ) &&
1442+ desc -> id < RARCH_EXTRA_BUTTON_ID (RARCH_MAX_EXTRA_BUTTON )))
1443+ continue ;
1444+ }
1445+
1446+ switch (desc -> device )
1447+ {
1448+ case RETRO_DEVICE_JOYPAD :
1449+ sys_info -> input_desc_btn [retro_port ]
1450+ [retro_id ] = desc -> description ;
1451+ break ;
1452+ case RETRO_DEVICE_ANALOG :
1453+ switch (retro_id )
1454+ {
1455+ case RETRO_DEVICE_ID_ANALOG_X :
1456+ switch (desc -> index )
1457+ {
1458+ case RETRO_DEVICE_INDEX_ANALOG_LEFT :
1459+ sys_info -> input_desc_btn [retro_port ]
1460+ [RARCH_ANALOG_LEFT_X_PLUS ] = desc -> description ;
1461+ sys_info -> input_desc_btn [retro_port ]
1462+ [RARCH_ANALOG_LEFT_X_MINUS ] = desc -> description ;
1463+ break ;
1464+ case RETRO_DEVICE_INDEX_ANALOG_RIGHT :
1465+ sys_info -> input_desc_btn [retro_port ]
1466+ [RARCH_ANALOG_RIGHT_X_PLUS ] = desc -> description ;
1467+ sys_info -> input_desc_btn [retro_port ]
1468+ [RARCH_ANALOG_RIGHT_X_MINUS ] = desc -> description ;
1469+ break ;
1470+ }
1471+ break ;
1472+ case RETRO_DEVICE_ID_ANALOG_Y :
1473+ switch (desc -> index )
1474+ {
1475+ case RETRO_DEVICE_INDEX_ANALOG_LEFT :
1476+ sys_info -> input_desc_btn [retro_port ]
1477+ [RARCH_ANALOG_LEFT_Y_PLUS ] = desc -> description ;
1478+ sys_info -> input_desc_btn [retro_port ]
1479+ [RARCH_ANALOG_LEFT_Y_MINUS ] = desc -> description ;
1480+ break ;
1481+ case RETRO_DEVICE_INDEX_ANALOG_RIGHT :
1482+ sys_info -> input_desc_btn [retro_port ]
1483+ [RARCH_ANALOG_RIGHT_Y_PLUS ] = desc -> description ;
1484+ sys_info -> input_desc_btn [retro_port ]
1485+ [RARCH_ANALOG_RIGHT_Y_MINUS ] = desc -> description ;
1486+ break ;
1487+ }
1488+ break ;
1489+ case RETRO_DEVICE_ID_JOYPAD_R2 :
1490+ switch (desc -> index )
1491+ {
1492+ case RETRO_DEVICE_INDEX_ANALOG_BUTTON :
1493+ sys_info -> input_desc_btn [retro_port ]
1494+ [retro_id ] = desc -> description ;
1495+ break ;
1496+ }
1497+ break ;
1498+ case RETRO_DEVICE_ID_JOYPAD_L2 :
1499+ switch (desc -> index )
1500+ {
1501+ case RETRO_DEVICE_INDEX_ANALOG_BUTTON :
1502+ sys_info -> input_desc_btn [retro_port ]
1503+ [retro_id ] = desc -> description ;
1504+ break ;
1505+ }
1506+ break ;
1507+ }
1508+ break ;
1509+ }
1510+ }
1511+
1512+ RARCH_LOG ("[Environ]: SET_INPUT_DESCRIPTORS:\n" );
1513+
1514+ {
1515+ unsigned log_level = settings -> uints .libretro_log_level ;
1516+
1517+ if (log_level == RETRO_LOG_DEBUG )
1518+ {
1519+ unsigned input_driver_max_users = settings -> uints .input_max_users ;
1520+
1521+ for (p = 0 ; p < input_driver_max_users ; p ++ )
1522+ {
1523+ unsigned mapped_port = settings -> uints .input_remap_ports [p ];
1524+
1525+ RARCH_DBG (" %s %u:\n" , msg_hash_to_str (MENU_ENUM_LABEL_VALUE_PORT ), p + 1 );
1526+
1527+ for (retro_id = 0 ; retro_id < RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS ; retro_id ++ )
1528+ {
1529+ unsigned bind_index = input_config_bind_order [retro_id ];
1530+ const char * description = sys_info -> input_desc_btn [mapped_port ][bind_index ];
1531+
1532+ if (!description )
1533+ continue ;
1534+
1535+ RARCH_DBG (" \"%s\" => \"%s\"\n" ,
1536+ msg_hash_to_str (MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B + bind_index ),
1537+ description );
1538+ }
14161539
1417- RARCH_LOG ("rarch_get_extra_input_actions(%p, %p)" , system_info , request );
1540+ for (retro_id = RARCH_EXTRA_BUTTON_ID (0 ); retro_id < RARCH_EXTRA_BUTTON_ID_END ; retro_id ++ )
1541+ {
1542+ const char * description = sys_info -> input_desc_btn [mapped_port ][retro_id ];
1543+
1544+ if (!description )
1545+ continue ;
1546+
1547+ RARCH_DBG (" Extra %d => \"%s\"\n" ,
1548+ retro_id ,
1549+ description );
1550+ }
1551+ }
1552+ }
1553+ }
1554+
1555+ runloop_st -> current_core .flags |=
1556+ RETRO_CORE_FLAG_HAS_SET_INPUT_DESCRIPTORS ;
14181557}
14191558
14201559bool runloop_environment_cb (unsigned cmd , void * data )
@@ -2064,124 +2203,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
20642203 {
20652204 if (sys_info )
20662205 {
2067- unsigned retro_id ;
2068- const struct retro_input_descriptor * desc = NULL ;
2069- memset ((void * )& sys_info -> input_desc_btn , 0 ,
2070- sizeof (sys_info -> input_desc_btn ));
2071-
2072- desc = (const struct retro_input_descriptor * )data ;
2073-
2074- for (; desc -> description ; desc ++ )
2075- {
2076- unsigned retro_port = desc -> port ;
2077-
2078- retro_id = desc -> id ;
2079-
2080- if (desc -> port >= MAX_USERS )
2081- continue ;
2082-
2083- if (desc -> id >= RARCH_FIRST_CUSTOM_BIND )
2084- continue ;
2085-
2086- switch (desc -> device )
2087- {
2088- case RETRO_DEVICE_JOYPAD :
2089- sys_info -> input_desc_btn [retro_port ]
2090- [retro_id ] = desc -> description ;
2091- break ;
2092- case RETRO_DEVICE_ANALOG :
2093- switch (retro_id )
2094- {
2095- case RETRO_DEVICE_ID_ANALOG_X :
2096- switch (desc -> index )
2097- {
2098- case RETRO_DEVICE_INDEX_ANALOG_LEFT :
2099- sys_info -> input_desc_btn [retro_port ]
2100- [RARCH_ANALOG_LEFT_X_PLUS ] = desc -> description ;
2101- sys_info -> input_desc_btn [retro_port ]
2102- [RARCH_ANALOG_LEFT_X_MINUS ] = desc -> description ;
2103- break ;
2104- case RETRO_DEVICE_INDEX_ANALOG_RIGHT :
2105- sys_info -> input_desc_btn [retro_port ]
2106- [RARCH_ANALOG_RIGHT_X_PLUS ] = desc -> description ;
2107- sys_info -> input_desc_btn [retro_port ]
2108- [RARCH_ANALOG_RIGHT_X_MINUS ] = desc -> description ;
2109- break ;
2110- }
2111- break ;
2112- case RETRO_DEVICE_ID_ANALOG_Y :
2113- switch (desc -> index )
2114- {
2115- case RETRO_DEVICE_INDEX_ANALOG_LEFT :
2116- sys_info -> input_desc_btn [retro_port ]
2117- [RARCH_ANALOG_LEFT_Y_PLUS ] = desc -> description ;
2118- sys_info -> input_desc_btn [retro_port ]
2119- [RARCH_ANALOG_LEFT_Y_MINUS ] = desc -> description ;
2120- break ;
2121- case RETRO_DEVICE_INDEX_ANALOG_RIGHT :
2122- sys_info -> input_desc_btn [retro_port ]
2123- [RARCH_ANALOG_RIGHT_Y_PLUS ] = desc -> description ;
2124- sys_info -> input_desc_btn [retro_port ]
2125- [RARCH_ANALOG_RIGHT_Y_MINUS ] = desc -> description ;
2126- break ;
2127- }
2128- break ;
2129- case RETRO_DEVICE_ID_JOYPAD_R2 :
2130- switch (desc -> index )
2131- {
2132- case RETRO_DEVICE_INDEX_ANALOG_BUTTON :
2133- sys_info -> input_desc_btn [retro_port ]
2134- [retro_id ] = desc -> description ;
2135- break ;
2136- }
2137- break ;
2138- case RETRO_DEVICE_ID_JOYPAD_L2 :
2139- switch (desc -> index )
2140- {
2141- case RETRO_DEVICE_INDEX_ANALOG_BUTTON :
2142- sys_info -> input_desc_btn [retro_port ]
2143- [retro_id ] = desc -> description ;
2144- break ;
2145- }
2146- break ;
2147- }
2148- break ;
2149- }
2150- }
2151-
2152- RARCH_LOG ("[Environ]: SET_INPUT_DESCRIPTORS:\n" );
2153-
2154- {
2155- unsigned log_level = settings -> uints .libretro_log_level ;
2156-
2157- if (log_level == RETRO_LOG_DEBUG )
2158- {
2159- unsigned input_driver_max_users = settings -> uints .input_max_users ;
2160-
2161- for (p = 0 ; p < input_driver_max_users ; p ++ )
2162- {
2163- unsigned mapped_port = settings -> uints .input_remap_ports [p ];
2164-
2165- RARCH_DBG (" %s %u:\n" , msg_hash_to_str (MENU_ENUM_LABEL_VALUE_PORT ), p + 1 );
2166-
2167- for (retro_id = 0 ; retro_id < RARCH_FIRST_CUSTOM_BIND ; retro_id ++ )
2168- {
2169- unsigned bind_index = input_config_bind_order [retro_id ];
2170- const char * description = sys_info -> input_desc_btn [mapped_port ][bind_index ];
2171-
2172- if (!description )
2173- continue ;
2174-
2175- RARCH_DBG (" \"%s\" => \"%s\"\n" ,
2176- msg_hash_to_str (MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B + bind_index ),
2177- description );
2178- }
2179- }
2180- }
2181- }
2182-
2183- runloop_st -> current_core .flags |=
2184- RETRO_CORE_FLAG_HAS_SET_INPUT_DESCRIPTORS ;
2206+ rarch_set_input_descriptors (data , p , runloop_st , settings , sys_info );
21852207 }
21862208 break ;
21872209 }
0 commit comments