22
22
#include "emulate_game_controller_via_input_plugin.h"
23
23
#include "plugin/plugin.h"
24
24
25
+ #ifdef HAVE_RAPHNET_INPUT
26
+ #include "mupen64plus-input-raphnetraw/plugin_front.h"
27
+ #include "plugin_back.h"
28
+ #endif
29
+
25
30
#include "api/m64p_plugin.h"
26
31
#include "device/controllers/game_controller.h"
27
32
#include <libretro.h>
@@ -40,13 +45,15 @@ extern retro_input_state_t input_cb;
40
45
extern struct retro_rumble_interface rumble ;
41
46
extern int pad_pak_types [4 ];
42
47
extern int pad_present [4 ];
48
+ extern int pad_rawdata [4 ];
43
49
extern int astick_deadzone ;
44
50
extern int astick_sensitivity ;
45
51
extern int r_cbutton ;
46
52
extern int l_cbutton ;
47
53
extern int d_cbutton ;
48
54
extern int u_cbutton ;
49
55
extern bool alternate_mapping ;
56
+ extern int raw_input_adapter ;
50
57
static bool libretro_supports_bitmasks = false;
51
58
52
59
extern m64p_rom_header ROM_HEADER ;
@@ -73,6 +80,14 @@ void inputGetKeys_default( int Control, BUTTONS *Keys );
73
80
typedef void (* get_keys_t )(int , BUTTONS * );
74
81
static get_keys_t getKeys = inputGetKeys_default ;
75
82
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
+
76
91
static void inputGetKeys_default_descriptor (void )
77
92
{
78
93
if (alternate_mapping )
@@ -146,11 +161,31 @@ EXPORT m64p_error CALL inputPluginStartup(m64p_dynlib_handle CoreLibHandle, void
146
161
libretro_supports_bitmasks = true;
147
162
getKeys = inputGetKeys_default ;
148
163
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
+
149
179
return M64ERR_SUCCESS ;
150
180
}
151
181
152
182
EXPORT m64p_error CALL inputPluginShutdown (void )
153
183
{
184
+ #ifdef HAVE_RAPHNET_INPUT
185
+ if (raw_input_adapter == 1 )
186
+ raphnetPluginShutdown ();
187
+ #endif
188
+
154
189
libretro_supports_bitmasks = false;
155
190
abort ();
156
191
return 0 ;
@@ -202,8 +237,14 @@ static unsigned char DataCRC( unsigned char *Data, int iLenght )
202
237
initilize controller: 01 03 00 FF FF FF
203
238
read controller: 01 04 01 FF FF FF FF
204
239
*******************************************************************/
205
- EXPORT void CALL inputControllerCommand (int Control , unsigned char * Command )
240
+ EXPORT void CALL inputControllerCommand_default (int Control , unsigned char * Command )
206
241
{
242
+ if (controllerCommand != inputControllerCommand_default )
243
+ {
244
+ controllerCommand (Control , Command );
245
+ return ;
246
+ }
247
+
207
248
unsigned char * Data = & Command [5 ];
208
249
209
250
if (Control == -1 )
@@ -399,7 +440,7 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
399
440
{
400
441
controller [i ].control = ControlInfo .Controls + i ;
401
442
controller [i ].control -> Present = pad_present [i ];
402
- controller [i ].control -> RawData = 0 ;
443
+ controller [i ].control -> RawData = pad_rawdata [ i ] ;
403
444
404
445
if (pad_pak_types [i ] == PLUGIN_MEMPAK )
405
446
controller [i ].control -> Plugin = PLUGIN_MEMPAK ;
@@ -413,6 +454,20 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
413
454
414
455
getKeys = inputGetKeys_default ;
415
456
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
416
471
}
417
472
418
473
/******************************************************************
@@ -426,9 +481,12 @@ EXPORT void CALL inputInitiateControllers(CONTROL_INFO ControlInfo)
426
481
note: This function is only needed if the DLL is allowing raw
427
482
data.
428
483
*******************************************************************/
429
- EXPORT void CALL inputReadController (int Control , unsigned char * Command )
484
+ EXPORT void CALL inputReadController_default (int Control , unsigned char * Command )
430
485
{
431
- inputControllerCommand (Control , Command );
486
+ if (readController != inputReadController_default )
487
+ readController (Control , Command );
488
+ else
489
+ inputControllerCommand_default (Control , Command );
432
490
}
433
491
434
492
/******************************************************************
@@ -437,7 +495,12 @@ EXPORT void CALL inputReadController(int Control, unsigned char *Command)
437
495
input: none
438
496
output: none
439
497
*******************************************************************/
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
+ }
441
504
442
505
/******************************************************************
443
506
Function: RomOpen
@@ -446,7 +509,29 @@ EXPORT void CALL inputRomClosed(void) { }
446
509
input: none
447
510
output: none
448
511
*******************************************************************/
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
+ }
450
535
451
536
452
537
int egcvip_is_connected (void * opaque , enum pak_type * pak )
0 commit comments