(net retropad core) Cleanups

This commit is contained in:
twinaphex 2016-09-29 04:35:39 +02:00
parent 0ce63a3f94
commit 091aa7d8a6

View File

@ -111,26 +111,23 @@ static struct descriptor *descriptors[] = {
void NETRETROPAD_CORE_PREFIX(retro_init)(void) void NETRETROPAD_CORE_PREFIX(retro_init)(void)
{ {
struct descriptor *desc;
int size;
int i; int i;
frame_buf = (uint16_t*)calloc(320 * 240, sizeof(uint16_t)); frame_buf = (uint16_t*)calloc(320 * 240, sizeof(uint16_t));
if (frame_buf) if (frame_buf)
{ {
unsigned rle, runs, count;
uint16_t *pixel = frame_buf + 49 * 320 + 32; uint16_t *pixel = frame_buf + 49 * 320 + 32;
for (unsigned rle = 0; rle < sizeof(body); ) for (rle = 0; rle < sizeof(body); )
{ {
uint16_t color = 0; uint16_t color = 0;
for (unsigned runs = body[rle++]; runs > 0; runs--) for (runs = body[rle++]; runs > 0; runs--)
{ {
for (unsigned count = body[rle++]; count > 0; count--) for (count = body[rle++]; count > 0; count--)
{
*pixel++ = color; *pixel++ = color;
}
color = 0x4208 - color; color = 0x4208 - color;
} }
@ -140,10 +137,11 @@ void NETRETROPAD_CORE_PREFIX(retro_init)(void)
} }
/* Allocate descriptor values */ /* Allocate descriptor values */
for (i = 0; i < ARRAY_SIZE(descriptors); i++) { for (i = 0; i < ARRAY_SIZE(descriptors); i++)
desc = descriptors[i]; {
size = DESC_NUM_PORTS(desc) * DESC_NUM_INDICES(desc) * DESC_NUM_IDS(desc); struct descriptor *desc = descriptors[i];
descriptors[i]->value = (uint16_t*)calloc(size, sizeof(uint16_t)); int size = DESC_NUM_PORTS(desc) * DESC_NUM_INDICES(desc) * DESC_NUM_IDS(desc);
descriptors[i]->value = (uint16_t*)calloc(size, sizeof(uint16_t));
} }
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO, "Initialising sockets...\n"); NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO, "Initialising sockets...\n");
@ -159,7 +157,8 @@ void NETRETROPAD_CORE_PREFIX(retro_deinit)(void)
frame_buf = NULL; frame_buf = NULL;
/* Free descriptor values */ /* Free descriptor values */
for (i = 0; i < ARRAY_SIZE(descriptors); i++) { for (i = 0; i < ARRAY_SIZE(descriptors); i++)
{
free(descriptors[i]->value); free(descriptors[i]->value);
descriptors[i]->value = NULL; descriptors[i]->value = NULL;
} }
@ -202,40 +201,43 @@ void NETRETROPAD_CORE_PREFIX(retro_get_system_av_info)(
static void retropad_update_input(void) static void retropad_update_input(void)
{ {
struct descriptor *desc;
struct remote_joypad_message msg;
uint16_t state;
uint16_t old;
int offset;
int port;
int index;
int id;
int i; int i;
/* Poll input */ /* Poll input */
NETRETROPAD_CORE_PREFIX(input_poll_cb)(); NETRETROPAD_CORE_PREFIX(input_poll_cb)();
/* Parse descriptors */ /* Parse descriptors */
for (i = 0; i < ARRAY_SIZE(descriptors); i++) { for (i = 0; i < ARRAY_SIZE(descriptors); i++)
{
int port;
/* Get current descriptor */ /* Get current descriptor */
desc = descriptors[i]; struct descriptor *desc = descriptors[i];
/* Go through range of ports/indices/IDs */ /* Go through range of ports/indices/IDs */
for (port = desc->port_min; port <= desc->port_max; port++) for (port = desc->port_min; port <= desc->port_max; port++)
{
int index;
for (index = desc->index_min; index <= desc->index_max; index++) for (index = desc->index_min; index <= desc->index_max; index++)
for (id = desc->id_min; id <= desc->id_max; id++) { {
int id;
for (id = desc->id_min; id <= desc->id_max; id++)
{
struct remote_joypad_message msg;
/* Compute offset into array */ /* Compute offset into array */
offset = DESC_OFFSET(desc, port, index, id); int offset = DESC_OFFSET(desc, port, index, id);
/* Get old state */ /* Get old state */
old = desc->value[offset]; uint16_t old = desc->value[offset];
/* Get new state */ /* Get new state */
state = NETRETROPAD_CORE_PREFIX(input_state_cb)( uint16_t state = NETRETROPAD_CORE_PREFIX(input_state_cb)(
port, port,
desc->device, desc->device,
index, index,
id); id);
/* Continue if state is unchanged */ /* Continue if state is unchanged */
if (state == old) if (state == old)
@ -245,14 +247,17 @@ static void retropad_update_input(void)
desc->value[offset] = state; desc->value[offset] = state;
/* Attempt to send updated state */ /* Attempt to send updated state */
msg.port = port; msg.port = port;
msg.device = desc->device; msg.device = desc->device;
msg.index = index; msg.index = index;
msg.id = id; msg.id = id;
msg.state = state; msg.state = state;
if (sendto(s, (char*)&msg, sizeof(msg), 0, (struct sockaddr *)&si_other, sizeof(si_other)) == -1) if (sendto(s, (char*)&msg, sizeof(msg), 0, (struct sockaddr *)&si_other, sizeof(si_other)) == -1)
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO, "Error sending data!\n"); NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO, "Error sending data!\n");
} }
}
}
} }
} }