Merge remote-tracking branch 'libretro/master'
authoralexis-puska <a.puska@ile-noire.com>
Sun, 31 Jul 2016 13:05:09 +0000 (15:05 +0200)
committeralexis-puska <a.puska@ile-noire.com>
Sun, 31 Jul 2016 13:05:09 +0000 (15:05 +0200)
Makefile.libretro
frontend/libretro.c
include/psemu_plugin_defs.h
jni/Android.mk

index 2abe711..1cb1df9 100644 (file)
@@ -20,7 +20,6 @@ CC_AS ?= $(CC)
 CFLAGS ?=
 
 TARGET_NAME := pcsx_rearmed
-LIBM := -lm
 LIBZ := -lz
 LIBPTHREAD := -lpthread
 LIBDL := -ldl
@@ -31,24 +30,20 @@ EXTRA_LDFLAGS =
 ifeq ($(platform), unix)
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC
-       SHARED := -shared -Wl,--version-script=libretro/link.T
 
 else ifeq ($(platform), linux-portable)
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC -nostdlib
        EXTRA_LDFLAGS += -fPIC -nostdlib
-       LIBM :=
        LIBZ :=
        LIBPTHREAD :=
        LIBDL :=
-       SHARED := -shared -Wl,--version-script=libretro/link.T
+       NO_UNDEF_CHECK = 1
+
 # OS X
 else ifeq ($(platform), osx)
        TARGET := $(TARGET_NAME)_libretro.dylib
        fpic := -fPIC
-       SHARED := -dynamiclib
-       OSXVER = `sw_vers -productVersion | cut -d. -f 2`
-       OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
        fpic += -mmacosx-version-min=10.1
 
 # iOS
@@ -61,7 +56,6 @@ ifeq ($(USE_DYNAREC),0)
        TARGET := $(TARGET_NAME)_interpreter_libretro_ios.dylib
 endif
        fpic := -fPIC
-       SHARED := -dynamiclib
 
        ifeq ($(IOSSDK),)
                IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
@@ -126,15 +120,15 @@ else ifeq ($(platform), vita)
        CFLAGS += -DNO_SOCKET -DNO_OS -DNO_DYLIB
        ASFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon
 
-#   CFLAGS += -U__ARM_NEON__
+#      CFLAGS += -U__ARM_NEON__
        HAVE_NEON = 1
        BUILTIN_GPU = neon
 
-#   USE_DYNAREC = 1
+#      USE_DYNAREC = 1
 #      DRC_CACHE_BASE = 0
 
        ARCH = arm
-   STATIC_LINKING = 1
+       STATIC_LINKING = 1
 
 # CTR(3DS)
 else ifeq ($(platform), ctr)
@@ -191,12 +185,14 @@ else ifeq ($(platform), qnx)
        ARCH = arm
        CFLAGS += -DBASE_ADDR_FIXED=0 -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
        ASFLAGS +=  -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
+       MAIN_LDLIBS += -lsocket
+       LIBPTHREAD :=
+       LIBDL :=
 
 #Raspberry Pi 2
 else ifeq ($(platform), rpi2)
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC
-       SHARED := -shared -Wl,--no-undefined
        CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
        ASFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
        HAVE_NEON = 1
@@ -208,7 +204,6 @@ else ifeq ($(platform), rpi2)
 else ifeq ($(platform), rpi3)
        TARGET := $(TARGET_NAME)_libretro.so
        fpic := -fPIC
-       SHARED := -shared -Wl,--no-undefined
        CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        ASFLAGS += -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
        HAVE_NEON = 1
@@ -219,7 +214,6 @@ else ifeq ($(platform), rpi3)
 # ARM
 else ifneq (,$(findstring armv,$(platform)))
        TARGET := $(TARGET_NAME)_libretro.so
-       SHARED := -shared -Wl,--no-undefined
        fpic := -fPIC
        DRC_CACHE_BASE = 0
        ifneq (,$(findstring cortexa8,$(platform)))
@@ -249,23 +243,28 @@ else ifneq (,$(findstring armv,$(platform)))
 # Windows
 else
        TARGET := $(TARGET_NAME)_libretro.dll
-       CC = gcc
-       fpic := -fPIC
-       LD_FLAGS := -fPIC
-       SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=libretro/link.T
-       CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__
+       MAIN_LDFLAGS += -static-libgcc -static-libstdc++ -s
+       CFLAGS += -D__WIN32__
        MMAP_WIN32=1
+       MAIN_LDLIBS += -lws2_32
+       LIBPTHREAD :=
+       LIBDL :=
 endif
 
 CFLAGS += $(fpic)
-ifeq ($(platform),win)
-       MAIN_LDLIBS += -lws2_32
-else ifneq ($(platform),qnx)
-       LDLIBS += $(LIBPHTREAD)
-       MAIN_LDLIBS += $(LIBDL)
-endif
 MAIN_LDFLAGS += -shared
-MAIN_LDLIBS += $(LIBM) $(LIBZ)
+MAIN_LDLIBS += $(LIBPTHREAD) $(LIBDL) $(LIBZ)
+
+# try to autodetect stuff for the lazy
+ifndef ARCH
+ARCH = $(shell $(CC) -dumpmachine | awk -F- '{print $$1}')
+endif
+ifndef HAVE_NEON
+HAVE_NEON = $(shell $(CC) -E -dD - < /dev/null 2> /dev/null | grep -q __ARM_NEON__ && echo 1 || echo 0)
+endif
+ifeq ($(NO_UNDEF_CHECK)$(shell ld -v 2> /dev/null | awk '{print $$1}'),GNU)
+MAIN_LDFLAGS += -Wl,--no-undefined
+endif
 
 TARGET ?= libretro.so
 PLATFORM = libretro
index bdce90e..b13f9c7 100644 (file)
@@ -33,6 +33,8 @@
 #include "3ds/3ds_utils.h"
 #endif
 
+#define PORTS_NUMBER 8
+
 static retro_video_refresh_t video_cb;
 static retro_input_poll_t input_poll_cb;
 static retro_input_state_t input_state_cb;
@@ -54,13 +56,13 @@ extern char Mcd1Data[MCD_SIZE];
 extern char McdDisable[2];
 
 /* PCSX ReARMed core calls and stuff */
-int in_type[8] =  { PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
-                  PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
-                  PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
-                  PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD };
+int in_type[8] =  { PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
+                  PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
+                  PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
+                  PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE };
 int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
 int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
-unsigned short in_keystate[8];
+unsigned short in_keystate[PORTS_NUMBER];
 int multitap1 = 0;
 int multitap2 = 0;
 int in_enable_vibration = 1;
@@ -333,16 +335,16 @@ void retro_set_environment(retro_environment_t cb)
    static const struct retro_variable vars[] = {
       { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
       { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
-      { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad3type", "Pad 3 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad4type", "Pad 4 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad5type", "Pad 5 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad6type", "Pad 6 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad7type", "Pad 7 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_pad8type", "Pad 8 Type; standard|analog|negcon" },
-      { "pcsx_rearmed_multitap1", "Multitap 1; disabled|enabled" },
-      { "pcsx_rearmed_multitap2", "Multitap 2; disabled|enabled" },
+      { "pcsx_rearmed_pad1type", "Pad 1 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|negcon" },
+      { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" },
+      { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" },
 #ifndef DRC_DISABLE
       { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
 #endif
@@ -375,9 +377,160 @@ unsigned retro_api_version(void)
        return RETRO_API_VERSION;
 }
 
+static int controller_port_variable(unsigned port, struct retro_variable *var)
+{
+       if (port >= PORTS_NUMBER)
+               return 0;
+
+       if (!environ_cb)
+               return 0;
+
+       var->value = NULL;
+       switch (port) {
+       case 0:
+               var->key = "pcsx_rearmed_pad1type";
+               break;
+       case 1:
+               var->key = "pcsx_rearmed_pad2type";
+               break;
+       case 2:
+               var->key = "pcsx_rearmed_pad3type";
+               break;
+       case 3:
+               var->key = "pcsx_rearmed_pad4type";
+               break;
+       case 4:
+               var->key = "pcsx_rearmed_pad5type";
+               break;
+       case 5:
+               var->key = "pcsx_rearmed_pad6type";
+               break;
+       case 6:
+               var->key = "pcsx_rearmed_pad7type";
+               break;
+       case 7:
+               var->key = "pcsx_rearmed_pad8type";
+               break;
+       }
+
+       return environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, var) || var->value;
+}
+
+static void update_controller_port_variable(unsigned port)
+{
+       if (port >= PORTS_NUMBER)
+               return;
+
+       struct retro_variable var;
+
+       if (controller_port_variable(port, &var))
+       {
+               if (strcmp(var.value, "standard") == 0)
+                       in_type[0] = PSE_PAD_TYPE_STANDARD;
+               else if (strcmp(var.value, "analog") == 0)
+                       in_type[0] = PSE_PAD_TYPE_ANALOGPAD;
+               else if (strcmp(var.value, "negcon") == 0)
+                       in_type[0] = PSE_PAD_TYPE_NEGCON;
+               else if (strcmp(var.value, "none") == 0)
+                       in_type[0] = PSE_PAD_TYPE_NONE;
+               // else 'default' case, do nothing
+       }
+}
+
+static void update_controller_port_device(unsigned port, unsigned device)
+{
+       if (port >= PORTS_NUMBER)
+               return;
+
+       struct retro_variable var;
+
+       if (!controller_port_variable(port, &var))
+               return;
+
+       if (strcmp(var.value, "default") != 0)
+               return;
+
+       switch (device)
+       {
+       case RETRO_DEVICE_JOYPAD:
+               in_type[port] = PSE_PAD_TYPE_STANDARD;
+               break;
+       case RETRO_DEVICE_ANALOG:
+               in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
+               break;
+       case RETRO_DEVICE_MOUSE:
+               in_type[port] = PSE_PAD_TYPE_MOUSE;
+               break;
+       case RETRO_DEVICE_LIGHTGUN:
+               in_type[port] = PSE_PAD_TYPE_GUN;
+               break;
+       case RETRO_DEVICE_NONE:
+       default:
+               in_type[port] = PSE_PAD_TYPE_NONE;
+       }
+}
+
+static void update_multitap()
+{
+       struct retro_variable var;
+       int auto_case;
+
+       var.value = NULL;
+       var.key = "pcsx_rearmed_multitap1";
+       auto_case = 0;
+       if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
+       {
+               if (strcmp(var.value, "enabled") == 0)
+                       multitap1 = 1;
+               else if (strcmp(var.value, "disabled") == 0)
+                       multitap1 = 0;
+               else // 'auto' case
+                       auto_case = 1;
+       }
+       else
+               auto_case = 1;
+
+       if (auto_case)
+       {
+               // If a gamepad is plugged after port 2, we need a first multitap.
+               multitap1 = 0;
+               for (int port = 2; port < PORTS_NUMBER; port++)
+                       multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE;
+       }
+
+       var.value = NULL;
+       var.key = "pcsx_rearmed_multitap2";
+       auto_case = 0;
+       if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
+       {
+               if (strcmp(var.value, "enabled") == 0)
+                       multitap2 = 1;
+               else if (strcmp(var.value, "disabled") == 0)
+                       multitap2 = 0;
+               else // 'auto' case
+                       auto_case = 1;
+       }
+       else
+               auto_case = 1;
+
+       if (auto_case)
+       {
+               // If a gamepad is plugged after port 4, we need a second multitap.
+               multitap2 = 0;
+               for (int port = 4; port < PORTS_NUMBER; port++)
+                       multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE;
+       }
+}
+
 void retro_set_controller_port_device(unsigned port, unsigned device)
 {
        SysPrintf("port %u  device %u",port,device);
+
+       if (port >= PORTS_NUMBER)
+               return;
+
+       update_controller_port_device(port, device);
+       update_multitap();
 }
 
 void retro_get_system_info(struct retro_system_info *info)
@@ -1070,111 +1223,10 @@ static void update_variables(bool in_flight)
          Config.PsxType = 1;
    }
 
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad1type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[0] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[0] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[0] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad2type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[1] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[1] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[1] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad3type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[2] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[2] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[2] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad4type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[3] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[3] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[3] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad5type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[4] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[4] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[4] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad6type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[5] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[5] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[5] = PSE_PAD_TYPE_NEGCON;
-   }
+   for (int i = 0; i < PORTS_NUMBER; i++)
+      update_controller_port_variable(i);
 
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad7type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[6] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[6] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[6] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_pad8type";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      in_type[7] = PSE_PAD_TYPE_STANDARD;
-      if (strcmp(var.value, "analog") == 0)
-         in_type[7] = PSE_PAD_TYPE_ANALOGPAD;
-      else if (strcmp(var.value, "negcon") == 0)
-         in_type[7] = PSE_PAD_TYPE_NEGCON;
-   }
-
-   var.value = NULL;
-   var.key = "pcsx_rearmed_multitap1";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      if (strcmp(var.value, "enabled") == 0)
-         multitap1 = 1;
-      else multitap1 = 0;
-   }
-    
-   var.value = NULL;
-   var.key = "pcsx_rearmed_multitap2";
-   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
-   {
-      if (strcmp(var.value, "enabled") == 0)
-         multitap2 = 1;
-      else multitap2 = 0;
-   }
+   update_multitap();
 
 #ifdef __ARM_NEON__
    var.value = "NULL";
@@ -1322,8 +1374,12 @@ void retro_run(void)
 
        // reset all keystate, query libretro for keystate
        int j;
-       for(i = 0; i < 8; i++) {
+       for(i = 0; i < PORTS_NUMBER; i++) {
                in_keystate[i] = 0;
+
+               if (in_type[i] == PSE_PAD_TYPE_NONE)
+                       continue;
+
                // query libretro for keystate
                for (j = 0; j < RETRO_PSX_MAP_LEN; j++)
                        if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j))
index fafd8c4..6fc59b7 100644 (file)
@@ -153,6 +153,8 @@ typedef struct
 
 
 
+// No controller
+#define PSE_PAD_TYPE_NONE                      0
 // MOUSE SCPH-1030
 #define PSE_PAD_TYPE_MOUSE                     1
 // NEGCON - 16 button analog controller SLPH-00001
index 72c6738..36b0c93 100644 (file)
@@ -4,6 +4,9 @@ include $(CLEAR_VARS)
 
 APP_DIR := ../../src
 
+#fix stupid change in ndk r11 that breaks compiling even when the exe would run fine
+LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
+
 ifneq ($(TARGET_ARCH_ABI),armeabi-v7a)
    NO_NEON_BUILD := 1
 else