Each channel needs its own buffer...

This commit is contained in:
Raphael Assenat 2016-10-23 21:44:42 -04:00
parent d7bdf59860
commit 21ebef2ed3
4 changed files with 34 additions and 34 deletions

View File

@ -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)

View File

@ -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];

View File

@ -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__

30
n64.c
View File

@ -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)