Skip to content

Commit

Permalink
Add core setting to enable raw adapter(s)
Browse files Browse the repository at this point in the history
Make raphnet support completely optional (disable for now)
Raphnet controllers should be able to work along side with non-raphnet controllers
  • Loading branch information
CEnnis91 committed Jul 6, 2021
1 parent 69f8ef0 commit fa05347
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 39 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ endif
ifneq (,$(findstring unix,$(platform)))
TARGET := $(TARGET_NAME)_libretro.so
LDFLAGS += -shared -Wl,--version-script=$(LIBRETRO_DIR)/link.T -Wl,--no-undefined
HAVE_RAPHNET_INPUT = 1

ifeq ($(FORCE_GLES),1)
GLES = 1
Expand Down Expand Up @@ -235,7 +234,6 @@ else ifneq (,$(findstring odroid64,$(platform)))
GLES = 0
GLES3= 1
GL_LIB := -lGLESv3
HAVE_RAPHNET_INPUT = 1
endif

COREFLAGS += -DOS_LINUX
Expand Down
5 changes: 4 additions & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ SOURCES_C += $(VIDEODIR_ANGRYLION)/interface.c \
endif

# raphnetraw and hidapi
# FIXME windows build untested and probably incomplete
ifeq ($(HAVE_RAPHNET_INPUT), 1)
CFLAGS += -DHAVE_RAPHNET_INPUT
CXXFLAGS += -DHAVE_RAPHNET_INPUT
INCFLAGS += $(HIDAPI_INCFLAGS)
LDFLAGS += -ludev -ldl
LDFLAGS += -ludev -ldl

SOURCES_C += $(ROOT_DIR)/custom/mupen64plus-input-raphnetraw/plugin_front.c \
$(INPUTDIR_RAPHNET)/src/plugin_back.c \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include "emulate_game_controller_via_input_plugin.h"
#include "plugin/plugin.h"

#ifdef HAVE_RAPHNET_INPUT
#include "mupen64plus-input-raphnetraw/plugin_front.h"
#include "plugin_back.h"
#endif

#include "api/m64p_plugin.h"
#include "device/controllers/game_controller.h"
#include <libretro.h>
Expand All @@ -40,13 +45,15 @@ extern retro_input_state_t input_cb;
extern struct retro_rumble_interface rumble;
extern int pad_pak_types[4];
extern int pad_present[4];
extern int pad_rawdata[4];
extern int astick_deadzone;
extern int astick_sensitivity;
extern int r_cbutton;
extern int l_cbutton;
extern int d_cbutton;
extern int u_cbutton;
extern bool alternate_mapping;
extern int raw_input_adapter;
static bool libretro_supports_bitmasks = false;

extern m64p_rom_header ROM_HEADER;
Expand All @@ -73,6 +80,14 @@ void inputGetKeys_default( int Control, BUTTONS *Keys );
typedef void (*get_keys_t)(int, BUTTONS*);
static get_keys_t getKeys = inputGetKeys_default;

void inputControllerCommand_default( int Control, unsigned char *Command );
typedef void (*controller_command_t)(int, unsigned char*);
static controller_command_t controllerCommand = inputControllerCommand_default;

void inputReadController_default( int Control, unsigned char *Command );
typedef void (*read_controller_t)(int, unsigned char*);
static read_controller_t readController = inputReadController_default;

static void inputGetKeys_default_descriptor(void)
{
if (alternate_mapping)
Expand Down Expand Up @@ -146,11 +161,31 @@ EXPORT m64p_error CALL inputPluginStartup(m64p_dynlib_handle CoreLibHandle, void
libretro_supports_bitmasks = true;
getKeys = inputGetKeys_default;
inputGetKeys_default_descriptor();

#ifdef HAVE_RAPHNET_INPUT
if (raw_input_adapter == 1)
{
controllerCommand = raphnetControllerCommand;
readController = raphnetReadController;
raphnetPluginStartup(CoreLibHandle, Context, DebugCallback);
}
else
{
controllerCommand = inputControllerCommand_default;
readController = inputReadController_default;
}
#endif

return M64ERR_SUCCESS;
}

EXPORT m64p_error CALL inputPluginShutdown(void)
{
#ifdef HAVE_RAPHNET_INPUT
if (raw_input_adapter == 1)
raphnetPluginShutdown();
#endif

libretro_supports_bitmasks = false;
abort();
return 0;
Expand Down Expand Up @@ -202,8 +237,14 @@ static unsigned char DataCRC( unsigned char *Data, int iLenght )
initilize controller: 01 03 00 FF FF FF
read controller: 01 04 01 FF FF FF FF
*******************************************************************/
EXPORT void CALL inputControllerCommand(int Control, unsigned char *Command)
EXPORT void CALL inputControllerCommand_default(int Control, unsigned char *Command)
{
if (controllerCommand != inputControllerCommand_default)
{
controllerCommand(Control, Command);
return;
}

unsigned char *Data = &Command[5];

if (Control == -1)
Expand Down Expand Up @@ -399,7 +440,7 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
{
controller[i].control = ControlInfo.Controls + i;
controller[i].control->Present = pad_present[i];
controller[i].control->RawData = 0;
controller[i].control->RawData = pad_rawdata[i];

if (pad_pak_types[i] == PLUGIN_MEMPAK)
controller[i].control->Plugin = PLUGIN_MEMPAK;
Expand All @@ -413,6 +454,20 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)

getKeys = inputGetKeys_default;
inputGetKeys_default_descriptor();

#ifdef HAVE_RAPHNET_INPUT
if (raw_input_adapter == 1)
{
controllerCommand = raphnetControllerCommand;
readController = raphnetReadController;
pb_scanControllers();
}
else
{
controllerCommand = inputControllerCommand_default;
readController = inputReadController_default;
}
#endif
}

/******************************************************************
Expand All @@ -426,9 +481,12 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
note: This function is only needed if the DLL is allowing raw
data.
*******************************************************************/
EXPORT void CALL inputReadController(int Control, unsigned char *Command)
EXPORT void CALL inputReadController_default(int Control, unsigned char *Command)
{
inputControllerCommand(Control, Command);
if (readController != inputReadController_default)
readController(Control, Command);
else
inputControllerCommand_default(Control, Command);
}

/******************************************************************
Expand All @@ -437,7 +495,12 @@ EXPORT void CALL inputReadController(int Control, unsigned char *Command)
input: none
output: none
*******************************************************************/
EXPORT void CALL inputRomClosed(void) { }
EXPORT void CALL inputRomClosed(void) {
#ifdef HAVE_RAPHNET_INPUT
if (raw_input_adapter == 1)
raphnetRomClosed();
#endif
}

/******************************************************************
Function: RomOpen
Expand All @@ -446,7 +509,29 @@ EXPORT void CALL inputRomClosed(void) { }
input: none
output: none
*******************************************************************/
EXPORT int CALL inputRomOpen(void) { return 1; }
EXPORT int CALL inputRomOpen(void) {
#ifdef HAVE_RAPHNET_INPUT
if (raw_input_adapter == 1)
{
bool all_unset = true;

for (int i = 0; i < 4; i++)
{
if (pad_rawdata[i] == 1)
all_unset = false;
}

// HACK: handle a special case if we enable raphnet support, but
// don't change any of the controllers to actually use raw data
if (all_unset)
raphnetPluginShutdown();
else
raphnetRomOpen();
}
#endif

return 1;
}


int egcvip_is_connected(void* opaque, enum pak_type* pak)
Expand Down
23 changes: 21 additions & 2 deletions custom/mupen64plus-input-raphnetraw/plugin_front.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,33 @@ static int emu2adap_portmap[MAX_CONTROLLERS] = { 0, 2, 3, 1 };
static int emu2adap_portmap[MAX_CONTROLLERS] = { 0, 1, 2, 3 };
#endif

#define EMU_2_ADAP_PORT(a) ((a) == -1 ? -1 : emu2adap_portmap[a])
extern struct
{
CONTROL *control;
BUTTONS buttons;
} controller[4];
static int pad_portmap[MAX_CONTROLLERS] = { -1, -1, -1, -1 };
#define EMU_2_ADAP_PORT(a) ((a) == -1 ? -1 : pad_portmap[a])

/* static data definitions */
static void (*l_DebugCallback)(void *, int, const char *) = NULL;
static void *l_DebugCallContext = NULL;
static int l_PluginInit = 0;

/* Global functions */
void raphnetUpdatePortMap()
{
int map = 0;

for( int i = 0; i < MAX_CONTROLLERS; i++ )
{
if (controller[i].control && controller[i].control->RawData == 1)
pad_portmap[i] = map++;
else
pad_portmap[i] = -1;
}
}

static void DebugMessage(int level, const char *message, ...)
{
char msgbuf[1024];
Expand Down Expand Up @@ -252,7 +271,7 @@ EXPORT int CALL raphnetRomOpen(void)
}

/******************************************************************
Function: SDL_KeyDown
Function: raphnetSDL_KeyDown
Purpose: To pass the SDL_KeyDown message from the emulator to the
plugin.
input: keymod and keysym of the SDL_KEYDOWN message.
Expand Down
14 changes: 14 additions & 0 deletions custom/mupen64plus-input-raphnetraw/plugin_front.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,19 @@

#define PAK_IO_RUMBLE 0xC000 // the address where rumble-commands are sent to

void raphnetUpdatePortMap();

m64p_error raphnetPluginStartup(m64p_dynlib_handle CoreLibHandle, void *Context, void (*DebugCallback)(void *, int, const char *));
m64p_error raphnetPluginShutdown(void);
m64p_error raphnetPluginGetVersion(m64p_plugin_type *PluginType, int *PluginVersion, int *APIVersion, const char **PluginNamePtr, int *Capabilities);
void raphnetInitiateControllers(CONTROL_INFO ControlInfo);
void raphnetReadController(int Control, unsigned char *Command);
void raphnetControllerCommand(int Control, unsigned char *Command);
void raphnetGetKeys( int Control, BUTTONS *Keys );
void raphnetRomClosed(void);
int raphnetRomOpen(void);
void raphnetSDL_KeyDown(int keymod, int keysym);
void raphnetSDL_KeyUp(int keymod, int keysym);

#endif // __PLUGIN_H__

Loading

0 comments on commit fa05347

Please sign in to comment.