From d865c5e4a660fc434ed259be1769f5022371236c Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 16 Jun 2019 13:32:27 -0500 Subject: [PATCH] add some copyright on files I contributed considerably just in case --- cheevos-new/badges.c | 15 ++ command.c | 2 +- configuration.c | 2 +- discord/discord.c | 2 +- discord/discord.h | 2 +- frontend/drivers/platform_unix.c | 2 +- frontend/drivers/platform_win32.c | 1 + input/input_mapper.c | 2 +- input/input_mapper.h | 2 +- input/input_remapping.c | 2 +- input/input_remapping.h | 2 +- input/input_remote.c | 265 ++++++++++++++++++++++++++++++ input/input_remote.h | 51 ++++++ menu/cbs/menu_cbs_ok.c | 2 +- menu/menu_displaylist.c | 2 +- menu/menu_networking.c | 2 +- menu/widgets/menu_filebrowser.c | 1 + paths.c | 1 + record/drivers/record_ffmpeg.c | 1 + retroarch.c | 1 - tasks/task_autodetect.c | 1 + tasks/task_content.c | 1 + tasks/task_netplay_find_content.c | 2 +- tasks/task_netplay_lan_scan.c | 2 +- 24 files changed, 351 insertions(+), 15 deletions(-) create mode 100644 input/input_remote.c create mode 100644 input/input_remote.h diff --git a/cheevos-new/badges.c b/cheevos-new/badges.c index 87e3b4335d..2c3bdaeb53 100644 --- a/cheevos-new/badges.c +++ b/cheevos-new/badges.c @@ -1,3 +1,18 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2015-2016 - Andre Leiradella + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + #include #include diff --git a/command.c b/command.c index 10568c26f5..37278c4eac 100755 --- a/command.c +++ b/command.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2015-2017 - Andres Suarez + * Copyright (C) 2015-2017 - Andrés Suarez * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms diff --git a/configuration.c b/configuration.c index 770dd62b59..612d65d41e 100644 --- a/configuration.c +++ b/configuration.c @@ -2,7 +2,7 @@ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2015-2017 - Andrés Suárez + * Copyright (C) 2015-2019 - Andrés Suárez * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms diff --git a/discord/discord.c b/discord/discord.c index f176ac38ef..64d07cb965 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -1,5 +1,5 @@ /* RetroArch - A frontend for libretro. - * Copyright (C) 2018 - Andrés Suárez + * Copyright (C) 2018-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/discord/discord.h b/discord/discord.h index f0eefb2db0..27de339835 100644 --- a/discord/discord.h +++ b/discord/discord.h @@ -1,5 +1,5 @@ /* RetroArch - A frontend for libretro. - * Copyright (C) 2018 - Andrés Suárez + * Copyright (C) 2018-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index d8fea7a599..01e1d42e9a 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -3,7 +3,7 @@ * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2012-2015 - Jason Fetters * Copyright (C) 2012-2015 - Michael Lelli - * Copyright (C) 2015-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index b1069f076e..a6a271ab21 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -1,6 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2018-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/input_mapper.c b/input/input_mapper.c index b6c7440e54..52105d5205 100644 --- a/input/input_mapper.c +++ b/input/input_mapper.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/input_mapper.h b/input/input_mapper.h index 21741d008e..189d3c78e5 100644 --- a/input/input_mapper.h +++ b/input/input_mapper.h @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/input_remapping.c b/input/input_remapping.c index ba231c2a11..2f0859260d 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/input_remapping.h b/input/input_remapping.h index 12316e1115..65b546f2ff 100644 --- a/input/input_remapping.h +++ b/input/input_remapping.h @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2016-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/input/input_remote.c b/input/input_remote.c new file mode 100644 index 0000000000..fd0d746613 --- /dev/null +++ b/input/input_remote.c @@ -0,0 +1,265 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2017-2019 - Andrés Suárez + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +#include "input_remote.h" + +#include "../configuration.h" +#include "../msg_hash.h" +#include "../verbosity.h" + +#define DEFAULT_NETWORK_GAMEPAD_PORT 55400 +#define UDP_FRAME_PACKETS 16 + +struct remote_message +{ + uint16_t state; + int port; + int device; + int index; + int id; +}; + +struct input_remote +{ + bool state[RARCH_BIND_LIST_END]; +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) + int net_fd[MAX_USERS]; +#endif +}; + +typedef struct input_remote_state +{ + /* Left X, Left Y, Right X, Right Y */ + int16_t analog[4][MAX_USERS]; + /* This is a bitmask of (1 << key_bind_id). */ + uint64_t buttons[MAX_USERS]; +} input_remote_state_t; + +static input_remote_state_t remote_st_ptr; +static input_remote_state_t *input_remote_get_state_ptr(void) +{ + return &remote_st_ptr; +} + +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) +static bool input_remote_init_network(input_remote_t *handle, + uint16_t port, unsigned user) +{ + int fd; + struct addrinfo *res = NULL; + + port = port + user; + + if (!network_init()) + return false; + + RARCH_LOG("Bringing up remote interface on port %hu.\n", + (unsigned short)port); + + fd = socket_init((void**)&res, port, NULL, SOCKET_TYPE_DATAGRAM); + + if (fd < 0) + goto error; + + handle->net_fd[user] = fd; + + if (!socket_nonblock(handle->net_fd[user])) + goto error; + + if (!socket_bind(handle->net_fd[user], res)) + { + RARCH_ERR("%s\n", msg_hash_to_str(MSG_FAILED_TO_BIND_SOCKET)); + goto error; + } + + freeaddrinfo_retro(res); + return true; + +error: + if (res) + freeaddrinfo_retro(res); + return false; +} +#endif + +input_remote_t *input_remote_new(uint16_t port, unsigned max_users) +{ + unsigned user; +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) + settings_t *settings = config_get_ptr(); +#endif + input_remote_t *handle = (input_remote_t*) + calloc(1, sizeof(*handle)); + + if (!handle) + return NULL; + + (void)port; + +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) + for(user = 0; user < max_users; user ++) + { + handle->net_fd[user] = -1; + if(settings->bools.network_remote_enable_user[user]) + if (!input_remote_init_network(handle, port, user)) + goto error; + } +#endif + + return handle; + +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) +error: + input_remote_free(handle, max_users); + return NULL; +#endif +} + +void input_remote_free(input_remote_t *handle, unsigned max_users) +{ + unsigned user; +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) + + for(user = 0; user < max_users; user ++) + socket_close(handle->net_fd[user]); +#endif + + free(handle); +} + +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) +static void input_remote_parse_packet(struct remote_message *msg, unsigned user) +{ + input_remote_state_t *input_state = input_remote_get_state_ptr(); + + /* Parse message */ + switch (msg->device) + { + case RETRO_DEVICE_JOYPAD: + input_state->buttons[user] &= ~(1 << msg->id); + if (msg->state) + input_state->buttons[user] |= 1 << msg->id; + break; + case RETRO_DEVICE_ANALOG: + input_state->analog[msg->index * 2 + msg->id][user] = msg->state; + break; + } +} +#endif + +void input_remote_state( + int16_t *ret, + unsigned port, + unsigned device, + unsigned idx, + unsigned id) +{ + switch (device) + { + case RETRO_DEVICE_JOYPAD: + if (input_remote_key_pressed(id, port)) + *ret |= 1; + break; + case RETRO_DEVICE_ANALOG: + { + unsigned base = 0; + input_remote_state_t *input_state = input_remote_get_state_ptr(); + + if (!input_state) + return; + + if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT) + base = 2; + if (id == RETRO_DEVICE_ID_ANALOG_Y) + base += 1; + if (input_state && input_state->analog[base][port]) + *ret = input_state->analog[base][port]; + } + break; + } +} + +bool input_remote_key_pressed(int key, unsigned port) +{ + input_remote_state_t *input_state = input_remote_get_state_ptr(); + + if (!input_state) + return false; + + return (input_state->buttons[port] & (UINT64_C(1) << key)); +} + +void input_remote_poll(input_remote_t *handle, unsigned max_users) +{ + unsigned user; + settings_t *settings = config_get_ptr(); + input_remote_state_t *input_state = input_remote_get_state_ptr(); + + for(user = 0; user < max_users; user++) + { + if (settings->bools.network_remote_enable_user[user]) + { +#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD) + struct remote_message msg; + ssize_t ret; + fd_set fds; + + if (handle->net_fd[user] < 0) + return; + + FD_ZERO(&fds); + FD_SET(handle->net_fd[user], &fds); + + ret = recvfrom(handle->net_fd[user], (char*)&msg, + sizeof(msg), 0, NULL, NULL); + + if (ret == sizeof(msg)) + input_remote_parse_packet(&msg, user); + else if ((ret != -1) || ((errno != EAGAIN) && (errno != ENOENT))) +#endif + { + input_state->buttons[user] = 0; + input_state->analog[0][user] = 0; + input_state->analog[1][user] = 0; + input_state->analog[2][user] = 0; + input_state->analog[3][user] = 0; + } + } + } +} diff --git a/input/input_remote.h b/input/input_remote.h new file mode 100644 index 0000000000..5f784a94c2 --- /dev/null +++ b/input/input_remote.h @@ -0,0 +1,51 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2017-2019 - Andrés Suárez + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef INPUT_REMOTE_H__ +#define INPUT_REMOTE_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +RETRO_BEGIN_DECLS + +typedef struct input_remote input_remote_t; + +input_remote_t *input_remote_new(uint16_t port, unsigned max_users); + +void input_remote_free(input_remote_t *handle, unsigned max_users); + +void input_remote_poll(input_remote_t *handle, unsigned max_users); + +bool input_remote_key_pressed(int key, unsigned port); + +void input_remote_state( + int16_t *ret, + unsigned port, + unsigned device, + unsigned idx, + unsigned id); + +RETRO_END_DECLS + +#endif diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index eaa6cf39b8..9553eda134 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2016-2019 - Brad Parker - * Copyright (C) 2015-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index f76287368e..d216f3fbe1 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2015-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms diff --git a/menu/menu_networking.c b/menu/menu_networking.c index 6c47bdf505..a039cf8500 100644 --- a/menu/menu_networking.c +++ b/menu/menu_networking.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2014-2017 - Jean-André Santoni - * Copyright (C) 2015-2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms diff --git a/menu/widgets/menu_filebrowser.c b/menu/widgets/menu_filebrowser.c index 3475f316fe..0692414ae2 100644 --- a/menu/widgets/menu_filebrowser.c +++ b/menu/widgets/menu_filebrowser.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2017-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/paths.c b/paths.c index 7dabdd0d49..06317987c0 100644 --- a/paths.c +++ b/paths.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2017-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/record/drivers/record_ffmpeg.c b/record/drivers/record_ffmpeg.c index 630dadf34d..d4048a9095 100644 --- a/record/drivers/record_ffmpeg.c +++ b/record/drivers/record_ffmpeg.c @@ -1,6 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2017-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/retroarch.c b/retroarch.c index 6ffc12fd2b..1a036e55fa 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2,7 +2,6 @@ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2012-2015 - Michael Lelli - * Copyright (C) 2015-2017 - Andrés Suárez * Copyright (C) 2014-2017 - Jean-André Santoni * Copyright (C) 2016-2019 - Brad Parker * diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index e02dec918c..b1e51de8a7 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -2,6 +2,7 @@ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/tasks/task_content.c b/tasks/task_content.c index 0ac55d7918..2c236ed112 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1,6 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2011-2017 - Daniel De Matteis * Copyright (C) 2016-2019 - Brad Parker + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/tasks/task_netplay_find_content.c b/tasks/task_netplay_find_content.c index bd026a5552..df762f1ba6 100644 --- a/tasks/task_netplay_find_content.c +++ b/tasks/task_netplay_find_content.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2017 - Jean-André Santoni - * Copyright (C) 2017 - Andrés Suárez + * Copyright (C) 2017-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- diff --git a/tasks/task_netplay_lan_scan.c b/tasks/task_netplay_lan_scan.c index 4e0a3955a0..c16c8cf8b0 100644 --- a/tasks/task_netplay_lan_scan.c +++ b/tasks/task_netplay_lan_scan.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2016-2017 - Jean-André Santoni - * Copyright (C) 2017 - Andrés Suárez + * Copyright (C) 2016-2019 - Andrés Suárez * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found-