From 733c3f25c78ae3c08525235a8c8ff3ac1685d64a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Tue, 19 Jun 2012 05:10:42 +0200 Subject: [PATCH] (PS3) Add preliminary USB/Bluetooth mouse support --- Makefile.ps3 | 2 +- ps3/main.c | 7 ++++ ps3/ps3_input.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/Makefile.ps3 b/Makefile.ps3 index 78c26d75c7..b8ed88e2ca 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -68,7 +68,7 @@ endif PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread -DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_HEADSET -DHAVE_VID_CONTEXT -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) +DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_HEADSET -DHAVE_VID_CONTEXT -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_OSKUTIL -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) PPU_OPTIMIZE_LV := -O0 -g diff --git a/ps3/main.c b/ps3/main.c index 9fc59bc64d..c2f1b5bf34 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -168,6 +168,7 @@ static void callback_sysutil_exit(uint64_t status, uint64_t param, void *userdat gl->quitting = true; rarch_settings_change(S_QUIT); break; +#ifdef HAVE_OSKUTIL case CELL_SYSUTIL_OSKDIALOG_FINISHED: oskutil_close(&g_console.oskutil_handle); oskutil_finished(&g_console.oskutil_handle); @@ -175,6 +176,7 @@ static void callback_sysutil_exit(uint64_t status, uint64_t param, void *userdat case CELL_SYSUTIL_OSKDIALOG_UNLOADED: oskutil_unload(&g_console.oskutil_handle); break; +#endif } } #endif @@ -364,7 +366,9 @@ int main(int argc, char *argv[]) input_ps3.init(); +#ifdef HAVE_OSKUTIL oskutil_init(&g_console.oskutil_handle, 0); +#endif rarch_input_set_default_keybind_names_for_emulator(); @@ -421,8 +425,11 @@ begin_shutdown: video_gl.stop(); menu_free(); +#ifdef HAVE_OSKUTIL if(g_console.oskutil_handle.is_running) oskutil_unload(&g_console.oskutil_handle); +#endif + #ifdef HAVE_LOGGER logger_shutdown(); #endif diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index f4f4559ee6..5712c5f827 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -18,6 +18,11 @@ #include #include + +#ifdef HAVE_MOUSE +#include +#endif + #include #include #include @@ -30,6 +35,38 @@ #include "../general.h" #include "shared.h" +/*============================================================ + PS3 MOUSE +============================================================ */ + +#ifdef HAVE_MOUSE + +#define MAX_MICE 7 + +static void ps3_mouse_input_deinit(void) +{ + cellMouseEnd(); +} + +static uint32_t ps3_mouse_input_mice_connected(void) +{ + CellMouseInfo mouse_info; + cellMouseGetInfo(&mouse_info); + return mouse_info.now_connect; +} + +CellMouseData ps3_mouse_input_poll_device(uint32_t id) +{ + CellMouseData mouse_data; + + // Get new pad data + cellMouseGetData(id, &mouse_data); + + return mouse_data; +} + +#endif + /*============================================================ PS3 PAD ============================================================ */ @@ -38,6 +75,7 @@ static uint64_t state[MAX_PADS]; static unsigned pads_connected; +static unsigned mice_connected; uint32_t cell_pad_input_pads_connected(void) { @@ -89,11 +127,39 @@ static void ps3_input_poll(void *data) { (void)data; for (unsigned i = 0; i < MAX_PADS; i++) + { state[i] = cell_pad_input_poll_device(i); + } pads_connected = cell_pad_input_pads_connected(); +#ifdef HAVE_MOUSE + mice_connected = ps3_mouse_input_mice_connected(); +#endif } +#ifdef HAVE_MOUSE + +static int16_t ps3_mouse_device_state(void *data, unsigned player, unsigned id) +{ + CellMouseData mouse_state = ps3_mouse_input_poll_device(player); + + switch (id) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + return (!mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_1); + case RETRO_DEVICE_ID_MOUSE_RIGHT: + return (!mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_2); + case RETRO_DEVICE_ID_MOUSE_X: + return (!mice_connected ? 0 : mouse_state.x_axis); + case RETRO_DEVICE_ID_MOUSE_Y: + return (!mice_connected ? 0 : mouse_state.y_axis); + default: + return 0; + } +} + +#endif + static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) @@ -102,10 +168,22 @@ static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, unsigned player = port; uint64_t button = binds[player][id].joykey; - int16_t retval = CTRL_MASK(state[player], button) ? 1 : 0; + int16_t retval = 0; - if(player >= pads_connected || device != RETRO_DEVICE_JOYPAD) - retval = 0; + if(player < pads_connected) + { + switch (device) + { + case RETRO_DEVICE_JOYPAD: + retval = CTRL_MASK(state[player], button) ? 1 : 0; + break; +#ifdef HAVE_MOUSE + case RETRO_DEVICE_MOUSE: + retval = ps3_mouse_device_state(data, player, id); + break; +#endif + } + } return retval; } @@ -114,6 +192,8 @@ static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, ON-SCREEN KEYBOARD UTILITY ============================================================ */ +#ifdef HAVE_OSKUTIL + #define OSK_IN_USE 1 void oskutil_init(oskutil_params *params, unsigned int containersize) @@ -236,6 +316,8 @@ void oskutil_unload(oskutil_params *params) params->is_running = false; } +#endif + /*============================================================ RetroArch PS3 INPUT DRIVER ============================================================ */ @@ -249,6 +331,9 @@ static void ps3_free_input(void *data) static void* ps3_input_initialize(void) { cellPadInit(MAX_PADS); +#ifdef HAVE_MOUSE + cellMouseInit(MAX_MICE); +#endif for(unsigned i = 0; i < MAX_PADS; i++) ps3_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); return (void*)-1;