Skip to content

Commit fa05347

Browse files
committed
Add core setting to enable raw adapter(s)
Make raphnet support completely optional (disable for now) Raphnet controllers should be able to work along side with non-raphnet controllers
1 parent 69f8ef0 commit fa05347

File tree

8 files changed

+216
-39
lines changed

8 files changed

+216
-39
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ endif
9292
ifneq (,$(findstring unix,$(platform)))
9393
TARGET := $(TARGET_NAME)_libretro.so
9494
LDFLAGS += -shared -Wl,--version-script=$(LIBRETRO_DIR)/link.T -Wl,--no-undefined
95-
HAVE_RAPHNET_INPUT = 1
9695

9796
ifeq ($(FORCE_GLES),1)
9897
GLES = 1
@@ -235,7 +234,6 @@ else ifneq (,$(findstring odroid64,$(platform)))
235234
GLES = 0
236235
GLES3= 1
237236
GL_LIB := -lGLESv3
238-
HAVE_RAPHNET_INPUT = 1
239237
endif
240238

241239
COREFLAGS += -DOS_LINUX

Makefile.common

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,12 @@ SOURCES_C += $(VIDEODIR_ANGRYLION)/interface.c \
404404
endif
405405

406406
# raphnetraw and hidapi
407+
# FIXME windows build untested and probably incomplete
407408
ifeq ($(HAVE_RAPHNET_INPUT), 1)
409+
CFLAGS += -DHAVE_RAPHNET_INPUT
410+
CXXFLAGS += -DHAVE_RAPHNET_INPUT
408411
INCFLAGS += $(HIDAPI_INCFLAGS)
409-
LDFLAGS += -ludev -ldl
412+
LDFLAGS += -ludev -ldl
410413

411414
SOURCES_C += $(ROOT_DIR)/custom/mupen64plus-input-raphnetraw/plugin_front.c \
412415
$(INPUTDIR_RAPHNET)/src/plugin_back.c \

custom/mupen64plus-core/plugin/emulate_game_controller_via_libretro.c

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include "emulate_game_controller_via_input_plugin.h"
2323
#include "plugin/plugin.h"
2424

25+
#ifdef HAVE_RAPHNET_INPUT
26+
#include "mupen64plus-input-raphnetraw/plugin_front.h"
27+
#include "plugin_back.h"
28+
#endif
29+
2530
#include "api/m64p_plugin.h"
2631
#include "device/controllers/game_controller.h"
2732
#include <libretro.h>
@@ -40,13 +45,15 @@ extern retro_input_state_t input_cb;
4045
extern struct retro_rumble_interface rumble;
4146
extern int pad_pak_types[4];
4247
extern int pad_present[4];
48+
extern int pad_rawdata[4];
4349
extern int astick_deadzone;
4450
extern int astick_sensitivity;
4551
extern int r_cbutton;
4652
extern int l_cbutton;
4753
extern int d_cbutton;
4854
extern int u_cbutton;
4955
extern bool alternate_mapping;
56+
extern int raw_input_adapter;
5057
static bool libretro_supports_bitmasks = false;
5158

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

83+
void inputControllerCommand_default( int Control, unsigned char *Command );
84+
typedef void (*controller_command_t)(int, unsigned char*);
85+
static controller_command_t controllerCommand = inputControllerCommand_default;
86+
87+
void inputReadController_default( int Control, unsigned char *Command );
88+
typedef void (*read_controller_t)(int, unsigned char*);
89+
static read_controller_t readController = inputReadController_default;
90+
7691
static void inputGetKeys_default_descriptor(void)
7792
{
7893
if (alternate_mapping)
@@ -146,11 +161,31 @@ EXPORT m64p_error CALL inputPluginStartup(m64p_dynlib_handle CoreLibHandle, void
146161
libretro_supports_bitmasks = true;
147162
getKeys = inputGetKeys_default;
148163
inputGetKeys_default_descriptor();
164+
165+
#ifdef HAVE_RAPHNET_INPUT
166+
if (raw_input_adapter == 1)
167+
{
168+
controllerCommand = raphnetControllerCommand;
169+
readController = raphnetReadController;
170+
raphnetPluginStartup(CoreLibHandle, Context, DebugCallback);
171+
}
172+
else
173+
{
174+
controllerCommand = inputControllerCommand_default;
175+
readController = inputReadController_default;
176+
}
177+
#endif
178+
149179
return M64ERR_SUCCESS;
150180
}
151181

152182
EXPORT m64p_error CALL inputPluginShutdown(void)
153183
{
184+
#ifdef HAVE_RAPHNET_INPUT
185+
if (raw_input_adapter == 1)
186+
raphnetPluginShutdown();
187+
#endif
188+
154189
libretro_supports_bitmasks = false;
155190
abort();
156191
return 0;
@@ -202,8 +237,14 @@ static unsigned char DataCRC( unsigned char *Data, int iLenght )
202237
initilize controller: 01 03 00 FF FF FF
203238
read controller: 01 04 01 FF FF FF FF
204239
*******************************************************************/
205-
EXPORT void CALL inputControllerCommand(int Control, unsigned char *Command)
240+
EXPORT void CALL inputControllerCommand_default(int Control, unsigned char *Command)
206241
{
242+
if (controllerCommand != inputControllerCommand_default)
243+
{
244+
controllerCommand(Control, Command);
245+
return;
246+
}
247+
207248
unsigned char *Data = &Command[5];
208249

209250
if (Control == -1)
@@ -399,7 +440,7 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
399440
{
400441
controller[i].control = ControlInfo.Controls + i;
401442
controller[i].control->Present = pad_present[i];
402-
controller[i].control->RawData = 0;
443+
controller[i].control->RawData = pad_rawdata[i];
403444

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

414455
getKeys = inputGetKeys_default;
415456
inputGetKeys_default_descriptor();
457+
458+
#ifdef HAVE_RAPHNET_INPUT
459+
if (raw_input_adapter == 1)
460+
{
461+
controllerCommand = raphnetControllerCommand;
462+
readController = raphnetReadController;
463+
pb_scanControllers();
464+
}
465+
else
466+
{
467+
controllerCommand = inputControllerCommand_default;
468+
readController = inputReadController_default;
469+
}
470+
#endif
416471
}
417472

418473
/******************************************************************
@@ -426,9 +481,12 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
426481
note: This function is only needed if the DLL is allowing raw
427482
data.
428483
*******************************************************************/
429-
EXPORT void CALL inputReadController(int Control, unsigned char *Command)
484+
EXPORT void CALL inputReadController_default(int Control, unsigned char *Command)
430485
{
431-
inputControllerCommand(Control, Command);
486+
if (readController != inputReadController_default)
487+
readController(Control, Command);
488+
else
489+
inputControllerCommand_default(Control, Command);
432490
}
433491

434492
/******************************************************************
@@ -437,7 +495,12 @@ EXPORT void CALL inputReadController(int Control, unsigned char *Command)
437495
input: none
438496
output: none
439497
*******************************************************************/
440-
EXPORT void CALL inputRomClosed(void) { }
498+
EXPORT void CALL inputRomClosed(void) {
499+
#ifdef HAVE_RAPHNET_INPUT
500+
if (raw_input_adapter == 1)
501+
raphnetRomClosed();
502+
#endif
503+
}
441504

442505
/******************************************************************
443506
Function: RomOpen
@@ -446,7 +509,29 @@ EXPORT void CALL inputRomClosed(void) { }
446509
input: none
447510
output: none
448511
*******************************************************************/
449-
EXPORT int CALL inputRomOpen(void) { return 1; }
512+
EXPORT int CALL inputRomOpen(void) {
513+
#ifdef HAVE_RAPHNET_INPUT
514+
if (raw_input_adapter == 1)
515+
{
516+
bool all_unset = true;
517+
518+
for (int i = 0; i < 4; i++)
519+
{
520+
if (pad_rawdata[i] == 1)
521+
all_unset = false;
522+
}
523+
524+
// HACK: handle a special case if we enable raphnet support, but
525+
// don't change any of the controllers to actually use raw data
526+
if (all_unset)
527+
raphnetPluginShutdown();
528+
else
529+
raphnetRomOpen();
530+
}
531+
#endif
532+
533+
return 1;
534+
}
450535

451536

452537
int egcvip_is_connected(void* opaque, enum pak_type* pak)

custom/mupen64plus-input-raphnetraw/plugin_front.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,33 @@ static int emu2adap_portmap[MAX_CONTROLLERS] = { 0, 2, 3, 1 };
6666
static int emu2adap_portmap[MAX_CONTROLLERS] = { 0, 1, 2, 3 };
6767
#endif
6868

69-
#define EMU_2_ADAP_PORT(a) ((a) == -1 ? -1 : emu2adap_portmap[a])
69+
extern struct
70+
{
71+
CONTROL *control;
72+
BUTTONS buttons;
73+
} controller[4];
74+
static int pad_portmap[MAX_CONTROLLERS] = { -1, -1, -1, -1 };
75+
#define EMU_2_ADAP_PORT(a) ((a) == -1 ? -1 : pad_portmap[a])
7076

7177
/* static data definitions */
7278
static void (*l_DebugCallback)(void *, int, const char *) = NULL;
7379
static void *l_DebugCallContext = NULL;
7480
static int l_PluginInit = 0;
7581

7682
/* Global functions */
83+
void raphnetUpdatePortMap()
84+
{
85+
int map = 0;
86+
87+
for( int i = 0; i < MAX_CONTROLLERS; i++ )
88+
{
89+
if (controller[i].control && controller[i].control->RawData == 1)
90+
pad_portmap[i] = map++;
91+
else
92+
pad_portmap[i] = -1;
93+
}
94+
}
95+
7796
static void DebugMessage(int level, const char *message, ...)
7897
{
7998
char msgbuf[1024];
@@ -252,7 +271,7 @@ EXPORT int CALL raphnetRomOpen(void)
252271
}
253272

254273
/******************************************************************
255-
Function: SDL_KeyDown
274+
Function: raphnetSDL_KeyDown
256275
Purpose: To pass the SDL_KeyDown message from the emulator to the
257276
plugin.
258277
input: keymod and keysym of the SDL_KEYDOWN message.

custom/mupen64plus-input-raphnetraw/plugin_front.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,19 @@
4343

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

46+
void raphnetUpdatePortMap();
47+
48+
m64p_error raphnetPluginStartup(m64p_dynlib_handle CoreLibHandle, void *Context, void (*DebugCallback)(void *, int, const char *));
49+
m64p_error raphnetPluginShutdown(void);
50+
m64p_error raphnetPluginGetVersion(m64p_plugin_type *PluginType, int *PluginVersion, int *APIVersion, const char **PluginNamePtr, int *Capabilities);
51+
void raphnetInitiateControllers(CONTROL_INFO ControlInfo);
52+
void raphnetReadController(int Control, unsigned char *Command);
53+
void raphnetControllerCommand(int Control, unsigned char *Command);
54+
void raphnetGetKeys( int Control, BUTTONS *Keys );
55+
void raphnetRomClosed(void);
56+
int raphnetRomOpen(void);
57+
void raphnetSDL_KeyDown(int keymod, int keysym);
58+
void raphnetSDL_KeyUp(int keymod, int keysym);
59+
4660
#endif // __PLUGIN_H__
4761

0 commit comments

Comments
 (0)