Move common code to joypad_connection.c - will still need

iOS/OSX build fixes
This commit is contained in:
twinaphex 2014-10-04 19:07:59 +02:00
parent b7a0098c80
commit 640fa534cd
6 changed files with 173 additions and 286 deletions

View File

@ -333,6 +333,7 @@ INPUT
#endif
#if defined(__APPLE__)
#include "../input/joypad_connection.c"
#include "../input/wiimote.c"
#include "../input/apple_joypad_ps3.c"
#include "../input/apple_joypad_ps4.c"

View File

@ -18,6 +18,7 @@
#define __APPLE_RARCH_INPUT_H__
#include "../general.h"
#include "joypad_connection.h"
/* Input responder */
#define MAX_TOUCHES 16
@ -51,33 +52,6 @@ typedef struct
const rarch_joypad_driver_t *joypad;
} apple_input_data_t;
struct pad_connection;
struct pad_connection_interface
{
void* (*connect)(void *data, uint32_t slot);
void (*disconnect)(void* device);
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
uint16_t strength);
};
/* Joypad data */
int32_t pad_connection_connect(const char* name, void *data);
int32_t apple_joypad_connect_gcapi(void);
void pad_connection_disconnect(uint32_t slot);
void pad_connection_packet(uint32_t slot, uint8_t* data, uint32_t length);
/* Determine if connected joypad is a hidpad backed device.
* If false, pad_connection_packet cannot be used */
bool pad_connection_has_interface(uint32_t slot);
void apple_input_enable_icade(bool on);
void apple_input_enable_small_keyboard(bool on);

View File

@ -20,17 +20,6 @@
#include "input_common.h"
#include "../general.h"
typedef struct
{
bool used;
struct pad_connection_interface *iface;
void* data;
bool is_gcapi;
} joypad_slot_t;
static joypad_slot_t slots[MAX_PLAYERS];
struct pad_connection
{
int v_id;
@ -235,103 +224,6 @@ static void append_matching_dictionary(CFMutableArrayRef array,
CFRelease(matcher);
}
static int find_vacant_pad(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (slots[i].used)
continue;
memset(&slots[i], 0, sizeof(slots[0]));
return i;
}
return -1;
}
int32_t pad_connection_connect(const char* name, void *data)
{
struct pad_connection* connection = (struct pad_connection*)data;
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
unsigned i;
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
s->used = true;
static const struct
{
const char* name;
struct pad_connection_interface *iface;
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", &apple_pad_wii },
/* { "Nintendo RVL-CNT-01-UC", &apple_pad_wii }, */ /* WiiU */
/* { "Wireless Controller", &apple_pad_ps4 }, */ /* DualShock4 */
{ "PLAYSTATION(R)3 Controller", &apple_pad_ps3 },
{ 0, 0}
};
for (i = 0; name && pad_map[i].name; i++)
if (strstr(name, pad_map[i].name))
{
s->iface = pad_map[i].iface;
s->data = s->iface->connect(connection, pad);
}
}
return pad;
}
int32_t apple_joypad_connect_gcapi(void)
{
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
s->used = true;
s->is_gcapi = true;
}
return pad;
}
void pad_connection_disconnect(uint32_t slot)
{
if (slot < MAX_PLAYERS && slots[slot].used)
{
joypad_slot_t* s = (joypad_slot_t*)&slots[slot];
if (s->iface && s->data && s->iface->disconnect)
s->iface->disconnect(s->data);
memset(s, 0, sizeof(joypad_slot_t));
}
}
void pad_connection_packet(uint32_t slot,
uint8_t* data, uint32_t length)
{
if (slot < MAX_PLAYERS && slots[slot].used)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[slot];
if (s->iface && s->data && s->iface->packet_handler)
s->iface->packet_handler(s->data, data, length);
}
}
bool pad_connection_has_interface(uint32_t slot)
{
if (slot < MAX_PLAYERS && slots[slot].used)
return slots[slot].iface ? true : false;
return false;
}
static bool apple_joypad_init(void)
{
CFMutableArrayRef matcher;
@ -382,18 +274,7 @@ static void apple_joypad_hid_destroy(void)
static void apple_joypad_destroy(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i ++)
{
if (slots[i].used && slots[i].iface
&& slots[i].iface->set_rumble)
{
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
}
}
pad_connection_destroy();
apple_joypad_hid_destroy();
}
@ -440,14 +321,7 @@ static void apple_joypad_poll(void)
static bool apple_joypad_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
if (pad < MAX_PLAYERS && slots[pad].used && slots[pad].iface
&& slots[pad].iface->set_rumble)
{
slots[pad].iface->set_rumble(slots[pad].data, effect, strength);
return true;
}
return false;
return pad_connection_rumble(pad, effect, strength);
}
static const char *apple_joypad_name(unsigned pad)

View File

@ -23,119 +23,6 @@
#include "../apple/iOS/bluetooth/btpad.c"
#include "../apple/iOS/bluetooth/btpad_queue.c"
typedef struct
{
bool used;
struct pad_connection_interface *iface;
void* data;
bool is_gcapi;
} joypad_slot_t;
static joypad_slot_t slots[MAX_PLAYERS];
static int find_vacant_pad(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (slots[i].used)
continue;
memset(&slots[i], 0, sizeof(slots[0]));
return i;
}
return -1;
}
int32_t pad_connection_connect(const char* name, void *data)
{
struct pad_connection* connection = (struct pad_connection*)data;
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
unsigned i;
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
s->used = true;
static const struct
{
const char* name;
struct pad_connection_interface *iface;
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", &apple_pad_wii },
/* { "Nintendo RVL-CNT-01-UC", &apple_pad_wii }, */ /* WiiU */
/* { "Wireless Controller", &apple_pad_ps4 }, */ /* DualShock4 */
{ "PLAYSTATION(R)3 Controller", &apple_pad_ps3 },
{ 0, 0}
};
for (i = 0; name && pad_map[i].name; i++)
if (strstr(name, pad_map[i].name))
{
s->iface = pad_map[i].iface;
s->data = s->iface->connect(connection, pad);
}
}
return pad;
}
int32_t apple_joypad_connect_gcapi(void)
{
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
if (s)
{
s->used = true;
s->is_gcapi = true;
}
}
return pad;
}
void pad_connection_disconnect(uint32_t pad)
{
if (pad < MAX_PLAYERS && slots[pad].used)
{
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
if (s->iface && s->data && s->iface->disconnect)
s->iface->disconnect(s->data);
memset(s, 0, sizeof(joypad_slot_t));
}
}
void pad_connection_packet(uint32_t pad,
uint8_t* data, uint32_t length)
{
if (pad < MAX_PLAYERS && slots[pad].used)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
if (s->iface && s->data && s->iface->packet_handler)
s->iface->packet_handler(s->data, data, length);
}
}
bool pad_connection_has_interface(uint32_t pad)
{
if (pad < MAX_PLAYERS && slots[pad].used)
return slots[pad].iface ? true : false;
return false;
}
static bool apple_joypad_init(void)
{
return true;
@ -148,16 +35,7 @@ static bool apple_joypad_query_pad(unsigned pad)
static void apple_joypad_destroy(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i ++)
{
if (slots[i].used && slots[i].iface && slots[i].iface->set_rumble)
{
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
}
}
pad_connection_destroy();
}
static bool apple_joypad_button(unsigned port, uint16_t joykey)
@ -204,14 +82,7 @@ static void apple_joypad_poll(void)
static bool apple_joypad_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
if (pad < MAX_PLAYERS && slots[pad].used && slots[pad].iface
&& slots[pad].iface->set_rumble)
{
slots[pad].iface->set_rumble(slots[pad].data, effect, strength);
return true;
}
return false;
return pad_connection_rumble(pad, effect, strength);
}
static const char *apple_joypad_name(unsigned joypad)

View File

@ -15,3 +15,143 @@
*/
#include "joypad_connection.h"
typedef struct
{
bool used;
struct pad_connection_interface *iface;
void* data;
bool is_gcapi;
} joypad_slot_t;
static joypad_slot_t slots[MAX_PLAYERS];
static int find_vacant_pad(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (slots[i].used)
continue;
memset(&slots[i], 0, sizeof(slots[0]));
return i;
}
return -1;
}
int32_t pad_connection_connect(const char* name, void *data)
{
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
unsigned i;
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
s->used = true;
static const struct
{
const char* name;
struct pad_connection_interface *iface;
} pad_map[] =
{
{ "Nintendo RVL-CNT-01", &apple_pad_wii },
/* { "Nintendo RVL-CNT-01-UC", &apple_pad_wii }, */ /* WiiU */
/* { "Wireless Controller", &apple_pad_ps4 }, */ /* DualShock4 */
{ "PLAYSTATION(R)3 Controller", &apple_pad_ps3 },
{ 0, 0}
};
for (i = 0; name && pad_map[i].name; i++)
if (strstr(name, pad_map[i].name))
{
s->iface = pad_map[i].iface;
s->data = s->iface->connect(data, pad);
}
}
return pad;
}
int32_t apple_joypad_connect_gcapi(void)
{
int pad = find_vacant_pad();
if (pad >= 0 && pad < MAX_PLAYERS)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
if (s)
{
s->used = true;
s->is_gcapi = true;
}
}
return pad;
}
void pad_connection_disconnect(uint32_t pad)
{
if (pad < MAX_PLAYERS && slots[pad].used)
{
joypad_slot_t* s = (joypad_slot_t*)&slots[pad];
if (s->iface && s->data && s->iface->disconnect)
s->iface->disconnect(s->data);
memset(s, 0, sizeof(joypad_slot_t));
}
}
void pad_connection_packet(uint32_t pad,
uint8_t* data, uint32_t length)
{
if (pad < MAX_PLAYERS && slots[pad].used)
{
joypad_slot_t *s = (joypad_slot_t*)&slots[pad];
if (s->iface && s->data && s->iface->packet_handler)
s->iface->packet_handler(s->data, data, length);
}
}
bool pad_connection_has_interface(uint32_t pad)
{
if (pad < MAX_PLAYERS && slots[pad].used)
return slots[pad].iface ? true : false;
return false;
}
void pad_connection_destroy(void)
{
unsigned i;
for (i = 0; i < MAX_PLAYERS; i ++)
{
if (slots[i].used && slots[i].iface
&& slots[i].iface->set_rumble)
{
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_STRONG, 0);
slots[i].iface->set_rumble(slots[i].data, RETRO_RUMBLE_WEAK, 0);
}
}
}
bool pad_connection_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
if (pad < MAX_PLAYERS && slots[pad].used && slots[pad].iface
&& slots[pad].iface->set_rumble)
{
slots[pad].iface->set_rumble(slots[pad].data, effect, strength);
return true;
}
return false;
}

View File

@ -17,4 +17,31 @@
#ifndef _JOYPAD_CONNECTION_H
#define _JOYPAD_CONNECTION_H
#include <stddef.h>
struct pad_connection_interface
{
void* (*connect)(void *data, uint32_t slot);
void (*disconnect)(void* device);
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
uint16_t strength);
};
int32_t pad_connection_connect(const char* name, void *data);
int32_t apple_joypad_connect_gcapi(void);
void pad_connection_disconnect(uint32_t slot);
void pad_connection_packet(uint32_t slot, uint8_t* data, uint32_t length);
/* Determine if connected joypad is a hidpad backed device.
* If false, pad_connection_packet cannot be used */
bool pad_connection_has_interface(uint32_t slot);
#endif