mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Add HAVE_LIBNX ifdefs to switch_input.c/switch_joypad.c, and
features_cpu.c
This commit is contained in:
parent
6139f8846a
commit
517b1b9089
@ -9,6 +9,10 @@
|
||||
#include "../../config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBNX
|
||||
#include <switch.h>
|
||||
#endif
|
||||
|
||||
#include "../input_driver.h"
|
||||
|
||||
#define MAX_PADS 10
|
||||
|
@ -2,8 +2,13 @@
|
||||
#include "../../config.h"
|
||||
#endif
|
||||
|
||||
#include<libtransistor/nx.h>
|
||||
#ifdef HAVE_LIBNX
|
||||
#include <switch.h>
|
||||
#else
|
||||
#include <libtransistor/nx.h>
|
||||
#endif
|
||||
|
||||
#include "../configuration.h"
|
||||
#include "../input_driver.h"
|
||||
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
@ -13,10 +18,20 @@
|
||||
#include "string.h"
|
||||
|
||||
|
||||
#ifdef HAVE_LIBNX
|
||||
|
||||
#ifndef MAX_PADS
|
||||
#define MAX_PADS 8
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifndef MAX_PADS
|
||||
#define MAX_PADS 10
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static uint16_t pad_state[MAX_PADS];
|
||||
static int16_t analog_state[MAX_PADS][2][2];
|
||||
extern uint64_t lifecycle_state;
|
||||
@ -40,10 +55,16 @@ static void switch_joypad_autodetect_add(unsigned autoconf_pad)
|
||||
|
||||
static bool switch_joypad_init(void *data)
|
||||
{
|
||||
#ifdef HAVE_LIBNX
|
||||
unsigned i;
|
||||
hidScanInput();
|
||||
for (i = 0; i < MAX_PADS; i++)
|
||||
switch_joypad_autodetect_add(i);
|
||||
#else
|
||||
hid_init();
|
||||
|
||||
switch_joypad_autodetect_add(0);
|
||||
switch_joypad_autodetect_add(1);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -126,27 +147,78 @@ static bool switch_joypad_query_pad(unsigned pad)
|
||||
|
||||
static void switch_joypad_destroy(void)
|
||||
{
|
||||
#ifndef HAVE_LIBNX
|
||||
hid_finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBNX
|
||||
int lastMode = 0; // 0 = handheld, 1 = whatever
|
||||
|
||||
static void switch_joypad_poll(void)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
hidScanInput();
|
||||
|
||||
if (settings->bools.split_joycon && !hidGetHandheldMode())
|
||||
{
|
||||
if (lastMode != 1)
|
||||
{
|
||||
RARCH_LOG("[HID] Enable Split Joycon!\n");
|
||||
hidSetNpadJoyAssignmentModeSingleByDefault(CONTROLLER_PLAYER_1);
|
||||
hidSetNpadJoyAssignmentModeSingleByDefault(CONTROLLER_PLAYER_2);
|
||||
lastMode = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastMode != 0)
|
||||
{
|
||||
RARCH_LOG("[HID] Disable Split Joycon!\n");
|
||||
hidSetNpadJoyAssignmentModeDual(CONTROLLER_PLAYER_1);
|
||||
hidSetNpadJoyAssignmentModeDual(CONTROLLER_PLAYER_2);
|
||||
lastMode = 0;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
HidControllerID target = (i == 0) ? CONTROLLER_P1_AUTO : i;
|
||||
pad_state[i] = hidKeysDown(target) | hidKeysHeld(target);
|
||||
JoystickPosition joyPositionLeft, joyPositionRight;
|
||||
hidJoystickRead(&joyPositionLeft, target, JOYSTICK_LEFT);
|
||||
hidJoystickRead(&joyPositionRight, target, JOYSTICK_RIGHT);
|
||||
analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = joyPositionLeft.dx;
|
||||
analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = -joyPositionLeft.dy;
|
||||
analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = joyPositionRight.dx;
|
||||
analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = -joyPositionRight.dy;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void switch_joypad_poll(void)
|
||||
{
|
||||
int16_t lsx, lsy, rsx, rsy;
|
||||
hid_controller_t *controllers = hid_get_shared_memory()->controllers;
|
||||
hid_controller_t *cont = &controllers[0];
|
||||
hid_controller_state_entry_t ent = cont->main.entries[cont->main.latest_idx];
|
||||
hid_controller_state_entry_t ent8 = (cont+8)->main.entries[(cont+8)->main.latest_idx];
|
||||
pad_state[0] = ent.button_state | ent8.button_state;
|
||||
pad_state[0] = ent.button_state | ent8.button_state;
|
||||
|
||||
int16_t lsx, lsy, rsx, rsy;
|
||||
lsx = ent.left_stick_x;
|
||||
lsy = ent.left_stick_y;
|
||||
rsx = ent.right_stick_x;
|
||||
rsy = ent.right_stick_y;
|
||||
if(ent8.left_stick_x != 0 || ent8.left_stick_y != 0) { // handheld overrides player 1
|
||||
lsx = ent.left_stick_x;
|
||||
lsy = ent.left_stick_y;
|
||||
rsx = ent.right_stick_x;
|
||||
rsy = ent.right_stick_y;
|
||||
|
||||
if (ent8.left_stick_x != 0 || ent8.left_stick_y != 0)
|
||||
{
|
||||
/* handheld overrides player 1 */
|
||||
lsx = ent8.left_stick_x;
|
||||
lsy = ent8.left_stick_y;
|
||||
}
|
||||
if(ent8.right_stick_x != 0 || ent8.right_stick_y != 0) { // handheld overrides player 1
|
||||
|
||||
if (ent8.right_stick_x != 0 || ent8.right_stick_y != 0)
|
||||
{
|
||||
/* handheld overrides player 1 */
|
||||
rsx = ent8.right_stick_x;
|
||||
rsy = ent8.right_stick_y;
|
||||
}
|
||||
@ -156,6 +228,7 @@ static void switch_joypad_poll(void)
|
||||
analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rsx;
|
||||
analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = -rsy;
|
||||
}
|
||||
#endif
|
||||
|
||||
input_device_driver_t switch_joypad = {
|
||||
switch_joypad_init,
|
||||
|
@ -668,7 +668,7 @@ const char* const input_builtin_autoconfs[] =
|
||||
#ifdef __CELLOS_LV2__
|
||||
DECL_AUTOCONF_DEVICE("SixAxis Controller", "ps3", PS3INPUT_DEFAULT_BINDS),
|
||||
#endif
|
||||
#ifdef __SWITCH__
|
||||
#if defined(__SWITCH__) || defined(SWITCH)
|
||||
DECL_AUTOCONF_DEVICE("Switch Controller", "switch", SWITCH_DEFAULT_BINDS),
|
||||
#endif
|
||||
#ifdef EMSCRIPTEN
|
||||
|
@ -79,7 +79,9 @@
|
||||
#include <wiiu/os/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef SWITCH
|
||||
#if defined(HAVE_LIBNX)
|
||||
#include <switch.h>
|
||||
#elif defined(SWITCH)
|
||||
#include <libtransistor/types.h>
|
||||
#include <libtransistor/svc.h>
|
||||
#endif
|
||||
@ -219,7 +221,7 @@ retro_time_t cpu_features_get_time_usec(void)
|
||||
return sys_time_get_system_time();
|
||||
#elif defined(GEKKO)
|
||||
return ticks_to_microsecs(gettime());
|
||||
#elif defined(SWITCH)
|
||||
#elif defined(SWITCH) || defined(HAVE_LIBNX)
|
||||
return (svcGetSystemTick() * 10) / 192;
|
||||
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__)
|
||||
struct timespec tv = {0};
|
||||
@ -481,6 +483,8 @@ unsigned cpu_features_get_core_amount(void)
|
||||
return 1;
|
||||
#elif defined(VITA)
|
||||
return 4;
|
||||
#elif defined(HAVE_LIBNX) || defined(SWITCH)
|
||||
return 4;
|
||||
#elif defined(_3DS)
|
||||
u8 device_model = 0xFF;
|
||||
CFGU_GetSystemModel(&device_model);/*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user