From 21ebef2ed34b363181355cb696ea4e2e69903615 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sun, 23 Oct 2016 21:44:42 -0400 Subject: [PATCH] Each channel needs its own buffer... --- gamecube.c | 30 +++++++++++++++--------------- gamepads.c | 4 ++-- gamepads.h | 4 ++-- n64.c | 30 +++++++++++++++--------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/gamecube.c b/gamecube.c index 8a1a09a..a4142ec 100644 --- a/gamecube.c +++ b/gamecube.c @@ -84,30 +84,30 @@ void gc_decodeAnswer(unsigned char chn, unsigned char data[8]) 56-63 Right Btn Val */ - last_built_report.pad_type = PAD_TYPE_GAMECUBE; - last_built_report.gc.buttons = data[0] | data[1] << 8; + last_built_report[chn].pad_type = PAD_TYPE_GAMECUBE; + last_built_report[chn].gc.buttons = data[0] | data[1] << 8; x = data[2]; y = data[3]; cx = data[4]; cy = data[5]; - last_built_report.gc.lt = data[6]; - last_built_report.gc.rt = data[7]; - memcpy(last_built_report.gc.raw_data, data, 8); + last_built_report[chn].gc.lt = data[6]; + last_built_report[chn].gc.rt = data[7]; + memcpy(last_built_report[chn].gc.raw_data, data, 8); if (origins_set[chn]) { - last_built_report.gc.x = ((int)x-(int)orig_x[chn]); - last_built_report.gc.y = ((int)y-(int)orig_y[chn]); - last_built_report.gc.cx = ((int)cx-(int)orig_cx[chn]); - last_built_report.gc.cy = ((int)cy-(int)orig_cy[chn]); + last_built_report[chn].gc.x = ((int)x-(int)orig_x[chn]); + last_built_report[chn].gc.y = ((int)y-(int)orig_y[chn]); + last_built_report[chn].gc.cx = ((int)cx-(int)orig_cx[chn]); + last_built_report[chn].gc.cy = ((int)cy-(int)orig_cy[chn]); } else { orig_x[chn] = x; orig_y[chn] = y; orig_cx[chn] = cx; orig_cy[chn] = cy; - last_built_report.gc.x = 0; - last_built_report.gc.y = 0; - last_built_report.gc.cx = 0; - last_built_report.gc.cy = 0; + last_built_report[chn].gc.x = 0; + last_built_report[chn].gc.y = 0; + last_built_report[chn].gc.cx = 0; + last_built_report[chn].gc.cy = 0; origins_set[chn] = 1; } } @@ -150,13 +150,13 @@ static char gamecubeProbe(unsigned char chn) static char gamecubeChanged(unsigned char chn) { - return memcmp(&last_built_report, &last_sent_report, sizeof(gamepad_data)); + return memcmp(&last_built_report[chn], &last_sent_report[chn], sizeof(gamepad_data)); } static void gamecubeGetReport(unsigned char chn, gamepad_data *dst) { if (dst) - memcpy(dst, &last_built_report, sizeof(gamepad_data)); + memcpy(dst, &last_built_report[chn], sizeof(gamepad_data)); } static void gamecubeVibration(unsigned char chn, char enable) diff --git a/gamepads.c b/gamepads.c index 8144055..e7b1132 100644 --- a/gamepads.c +++ b/gamepads.c @@ -18,6 +18,6 @@ /* Shared between N64 and GC (only one is used at a time). Saves memory. */ -gamepad_data last_sent_report; -gamepad_data last_built_report; +gamepad_data last_sent_report[GAMEPAD_MAX_CHANNELS]; +gamepad_data last_built_report[GAMEPAD_MAX_CHANNELS]; diff --git a/gamepads.h b/gamepads.h index 014fd27..5a2eaaa 100644 --- a/gamepads.h +++ b/gamepads.h @@ -83,10 +83,10 @@ typedef struct { } Gamepad; /* What was most recently read from the controller */ -extern gamepad_data last_built_report; +extern gamepad_data last_built_report[GAMEPAD_MAX_CHANNELS]; /* What was most recently sent to the host */ -extern gamepad_data last_sent_report; +extern gamepad_data last_sent_report[GAMEPAD_MAX_CHANNELS]; #endif // _gamepads_h__ diff --git a/n64.c b/n64.c index fe652aa..1c6a651 100644 --- a/n64.c +++ b/n64.c @@ -213,16 +213,16 @@ static char n64Update(unsigned char chn) } #endif - last_built_report.pad_type = PAD_TYPE_N64; - last_built_report.n64.buttons = (btns1 << 8) | btns2; - last_built_report.n64.x = x; - last_built_report.n64.y = y; + last_built_report[chn].pad_type = PAD_TYPE_N64; + last_built_report[chn].n64.buttons = (btns1 << 8) | btns2; + last_built_report[chn].n64.x = x; + last_built_report[chn].n64.y = y; /* Copy all the data as-is for the raw field */ - last_built_report.n64.raw_data[0] = btns1; - last_built_report.n64.raw_data[1] = btns2; - last_built_report.n64.raw_data[2] = x; - last_built_report.n64.raw_data[3] = y; + last_built_report[chn].n64.raw_data[0] = btns1; + last_built_report[chn].n64.raw_data[1] = btns2; + last_built_report[chn].n64.raw_data[2] = x; + last_built_report[chn].n64.raw_data[3] = y; /* Some cheap non-official controllers * use the full 8 bit range instead of the @@ -243,10 +243,10 @@ static char n64Update(unsigned char chn) * on a N64, or maybe a little better. This should * help people realise they got what the paid for * instead of suspecting the adapter. */ - if (last_built_report.n64.x == -128) - last_built_report.n64.x = -127; - if (last_built_report.n64.y == -128) - last_built_report.n64.y = -127; + if (last_built_report[chn].n64.x == -128) + last_built_report[chn].n64.x = -127; + if (last_built_report[chn].n64.y == -128) + last_built_report[chn].n64.y = -127; return 0; } @@ -286,15 +286,15 @@ static char n64Probe(unsigned char chn) static char n64Changed(unsigned char chn) { - return memcmp(&last_built_report, &last_sent_report, sizeof(gamepad_data)); + return memcmp(&last_built_report[chn], &last_sent_report[chn], sizeof(gamepad_data)); } static void n64GetReport(unsigned char chn, gamepad_data *dst) { if (dst) - memcpy(dst, &last_built_report, sizeof(gamepad_data)); + memcpy(dst, &last_built_report[chn], sizeof(gamepad_data)); - memcpy(&last_sent_report, &last_built_report, sizeof(gamepad_data)); + memcpy(&last_sent_report[chn], &last_built_report[chn], sizeof(gamepad_data)); } static void n64SetVibration(unsigned char chn, char enable)