mirror of https://github.com/encounter/SDL.git
SDL_hidapi_wii.c: fix build in c89 mode and builds using watcom compiler
This commit is contained in:
parent
397672edfe
commit
0ffaf5b871
|
@ -204,14 +204,14 @@ static SDL_bool IsWriteMemoryResponse(const Uint8 *data)
|
||||||
|
|
||||||
static SDL_bool WriteRegister(SDL_DriverWii_Context *ctx, Uint32 address, const Uint8 *data, int size, SDL_bool sync)
|
static SDL_bool WriteRegister(SDL_DriverWii_Context *ctx, Uint32 address, const Uint8 *data, int size, SDL_bool sync)
|
||||||
{
|
{
|
||||||
Uint8 writeRequest[k_unWiiPacketDataLength] = {
|
Uint8 writeRequest[k_unWiiPacketDataLength];
|
||||||
k_eWiiOutputReportIDs_WriteMemory,
|
|
||||||
0x04 | ctx->m_bRumbleActive,
|
writeRequest[0] = k_eWiiOutputReportIDs_WriteMemory;
|
||||||
(address >> 16) & 0xff,
|
writeRequest[1] = 0x04 | ctx->m_bRumbleActive;
|
||||||
(address >> 8) & 0xff,
|
writeRequest[2] = (address >> 16) & 0xff;
|
||||||
address & 0xff,
|
writeRequest[3] = (address >> 8) & 0xff;
|
||||||
size
|
writeRequest[4] = address & 0xff;
|
||||||
};
|
writeRequest[5] = size;
|
||||||
SDL_assert(size > 0 && size <= 16);
|
SDL_assert(size > 0 && size <= 16);
|
||||||
SDL_memcpy(writeRequest + 6, data, size);
|
SDL_memcpy(writeRequest + 6, data, size);
|
||||||
|
|
||||||
|
@ -233,15 +233,16 @@ static SDL_bool WriteRegister(SDL_DriverWii_Context *ctx, Uint32 address, const
|
||||||
|
|
||||||
static SDL_bool ReadRegister(SDL_DriverWii_Context *ctx, Uint32 address, int size, SDL_bool sync)
|
static SDL_bool ReadRegister(SDL_DriverWii_Context *ctx, Uint32 address, int size, SDL_bool sync)
|
||||||
{
|
{
|
||||||
Uint8 readRequest[7] = {
|
Uint8 readRequest[7];
|
||||||
k_eWiiOutputReportIDs_ReadMemory,
|
|
||||||
0x04 | ctx->m_bRumbleActive,
|
readRequest[0] = k_eWiiOutputReportIDs_ReadMemory;
|
||||||
(address >> 16) & 0xff,
|
readRequest[1] = 0x04 | ctx->m_bRumbleActive;
|
||||||
(address >> 8) & 0xff,
|
readRequest[2] = (address >> 16) & 0xff;
|
||||||
address & 0xff,
|
readRequest[3] = (address >> 8) & 0xff;
|
||||||
(size >> 8) & 0xff,
|
readRequest[4] = address & 0xff;
|
||||||
size & 0xff
|
readRequest[5] = (size >> 8) & 0xff;
|
||||||
};
|
readRequest[6] = size & 0xff;
|
||||||
|
|
||||||
SDL_assert(size > 0 && size <= 0xffff);
|
SDL_assert(size > 0 && size <= 0xffff);
|
||||||
|
|
||||||
if (!WriteOutput(ctx, readRequest, sizeof(readRequest), sync)) {
|
if (!WriteOutput(ctx, readRequest, sizeof(readRequest), sync)) {
|
||||||
|
@ -260,6 +261,8 @@ static SDL_bool ReadRegister(SDL_DriverWii_Context *ctx, Uint32 address, int siz
|
||||||
static SDL_bool ParseExtensionResponse(SDL_DriverWii_Context *ctx)
|
static SDL_bool ParseExtensionResponse(SDL_DriverWii_Context *ctx)
|
||||||
{
|
{
|
||||||
Uint64 type = 0;
|
Uint64 type = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
SDL_assert(ctx->m_rgucReadBuffer[0] == k_eWiiInputReportIDs_ReadMemory);
|
SDL_assert(ctx->m_rgucReadBuffer[0] == k_eWiiInputReportIDs_ReadMemory);
|
||||||
if (ctx->m_rgucReadBuffer[4] != 0x00 || ctx->m_rgucReadBuffer[5] != 0xFA) {
|
if (ctx->m_rgucReadBuffer[4] != 0x00 || ctx->m_rgucReadBuffer[5] != 0xFA) {
|
||||||
SDL_SetError("Unexpected extension response address");
|
SDL_SetError("Unexpected extension response address");
|
||||||
|
@ -274,20 +277,30 @@ static SDL_bool ParseExtensionResponse(SDL_DriverWii_Context *ctx)
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 6; i < 12; i++) {
|
for (i = 6; i < 12; i++) {
|
||||||
type = type << 8 | ctx->m_rgucReadBuffer[i];
|
type = type << 8 | ctx->m_rgucReadBuffer[i];
|
||||||
}
|
}
|
||||||
switch (type) {
|
|
||||||
case 0x0000A4200000: ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_Nunchuck; break;
|
if (type == 0x0000A4200000) {
|
||||||
case 0x0000A4200101: ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_ClassicController; break;
|
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_Nunchuck;
|
||||||
case 0x0100A4200101: ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_ClassicControllerPro; break;
|
return SDL_TRUE;
|
||||||
case 0x0000A4200120: ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_WiiUPro; break;
|
|
||||||
default:
|
|
||||||
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_Unknown;
|
|
||||||
SDL_SetError("Unrecognized controller type: %012" SDL_PRIx64, type);
|
|
||||||
return SDL_FALSE;
|
|
||||||
}
|
}
|
||||||
return SDL_TRUE;
|
if (type == 0x0000A4200101) {
|
||||||
|
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_ClassicController;
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
if (type == 0x0100A4200101) {
|
||||||
|
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_ClassicControllerPro;
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
if (type == 0x0000A4200120) {
|
||||||
|
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_WiiUPro;
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->m_eExtensionControllerType = k_eWiiExtensionControllerType_Unknown;
|
||||||
|
SDL_SetError("Unrecognized controller type: %012" SDL_PRIx64, type);
|
||||||
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,8 +354,9 @@ static SDL_bool IdentifyController(SDL_DriverWii_Context *ctx, SDL_Joystick *joy
|
||||||
hasExtension = ctx->m_rgucReadBuffer[3] & 2 ? SDL_TRUE : SDL_FALSE;
|
hasExtension = ctx->m_rgucReadBuffer[3] & 2 ? SDL_TRUE : SDL_FALSE;
|
||||||
if (hasExtension) {
|
if (hasExtension) {
|
||||||
/* http://wiibrew.org/wiki/Wiimote/Extension_Controllers#The_New_Way */
|
/* http://wiibrew.org/wiki/Wiimote/Extension_Controllers#The_New_Way */
|
||||||
SDL_bool ok = WriteRegister(ctx, 0xA400F0, (Uint8[1]){0x55}, 1, SDL_TRUE)
|
Uint8 data[2] = {0x55, 0x00};
|
||||||
&& WriteRegister(ctx, 0xA400FB, (Uint8[1]){0x00}, 1, SDL_TRUE)
|
SDL_bool ok = WriteRegister(ctx, 0xA400F0, &data[0], 1, SDL_TRUE)
|
||||||
|
&& WriteRegister(ctx, 0xA400FB, &data[1], 1, SDL_TRUE)
|
||||||
&& ReadRegister(ctx, 0xA400FA, 6, SDL_TRUE)
|
&& ReadRegister(ctx, 0xA400FA, 6, SDL_TRUE)
|
||||||
&& ParseExtensionResponse(ctx);
|
&& ParseExtensionResponse(ctx);
|
||||||
if (!ok) { return SDL_FALSE; }
|
if (!ok) { return SDL_FALSE; }
|
||||||
|
@ -369,15 +383,20 @@ static EWiiInputReportIDs GetButtonPacketType(SDL_DriverWii_Context *ctx)
|
||||||
static SDL_bool RequestButtonPacketType(SDL_DriverWii_Context *ctx, EWiiInputReportIDs type)
|
static SDL_bool RequestButtonPacketType(SDL_DriverWii_Context *ctx, EWiiInputReportIDs type)
|
||||||
{
|
{
|
||||||
Uint8 tt = ctx->m_bRumbleActive;
|
Uint8 tt = ctx->m_bRumbleActive;
|
||||||
|
Uint8 data[3];
|
||||||
/* Continuous reporting off, tt & 4 == 0 */
|
/* Continuous reporting off, tt & 4 == 0 */
|
||||||
return WriteOutput(ctx, (Uint8[3]){ k_eWiiOutputReportIDs_DataReportingMode, tt, type }, 3, SDL_FALSE);
|
data[0] = k_eWiiOutputReportIDs_DataReportingMode;
|
||||||
|
data[1] = tt;
|
||||||
|
data[2] = type;
|
||||||
|
return WriteOutput(ctx, data, 3, SDL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitStickCalibrationData(SDL_DriverWii_Context *ctx)
|
static void InitStickCalibrationData(SDL_DriverWii_Context *ctx)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
switch (ctx->m_eExtensionControllerType) {
|
switch (ctx->m_eExtensionControllerType) {
|
||||||
case k_eWiiExtensionControllerType_WiiUPro:
|
case k_eWiiExtensionControllerType_WiiUPro:
|
||||||
for (int i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ctx->m_StickCalibrationData[i].min = 1000;
|
ctx->m_StickCalibrationData[i].min = 1000;
|
||||||
ctx->m_StickCalibrationData[i].max = 3000;
|
ctx->m_StickCalibrationData[i].max = 3000;
|
||||||
ctx->m_StickCalibrationData[i].center = 0;
|
ctx->m_StickCalibrationData[i].center = 0;
|
||||||
|
@ -386,7 +405,7 @@ static void InitStickCalibrationData(SDL_DriverWii_Context *ctx)
|
||||||
break;
|
break;
|
||||||
case k_eWiiExtensionControllerType_ClassicController:
|
case k_eWiiExtensionControllerType_ClassicController:
|
||||||
case k_eWiiExtensionControllerType_ClassicControllerPro:
|
case k_eWiiExtensionControllerType_ClassicControllerPro:
|
||||||
for (int i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ctx->m_StickCalibrationData[i].min = 0;
|
ctx->m_StickCalibrationData[i].min = 0;
|
||||||
ctx->m_StickCalibrationData[i].max = i < 2 ? 63 : 31;
|
ctx->m_StickCalibrationData[i].max = i < 2 ? 63 : 31;
|
||||||
ctx->m_StickCalibrationData[i].center = 0;
|
ctx->m_StickCalibrationData[i].center = 0;
|
||||||
|
@ -394,7 +413,7 @@ static void InitStickCalibrationData(SDL_DriverWii_Context *ctx)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case k_eWiiExtensionControllerType_Nunchuck:
|
case k_eWiiExtensionControllerType_Nunchuck:
|
||||||
for (int i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
ctx->m_StickCalibrationData[i].min = 0;
|
ctx->m_StickCalibrationData[i].min = 0;
|
||||||
ctx->m_StickCalibrationData[i].max = 255;
|
ctx->m_StickCalibrationData[i].max = 255;
|
||||||
ctx->m_StickCalibrationData[i].center = 0;
|
ctx->m_StickCalibrationData[i].center = 0;
|
||||||
|
@ -653,19 +672,21 @@ static void HandleWiiUProButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *jo
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Uint8 zl, zr;
|
Uint8 zl, zr;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
if (data.ucNExtensionBytes < 11) {
|
if (data.ucNExtensionBytes < 11) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sticks */
|
/* Sticks */
|
||||||
for (int i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
Uint16 value = data.rgucExtension[i * 2] | (data.rgucExtension[i * 2 + 1] << 8);
|
Uint16 value = data.rgucExtension[i * 2] | (data.rgucExtension[i * 2 + 1] << 8);
|
||||||
PostStickCalibrated(joystick, &ctx->m_StickCalibrationData[i], axes[i], value);
|
PostStickCalibrated(joystick, &ctx->m_StickCalibrationData[i], axes[i], value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
for (int i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
for (int j = 0; j < 8; j++) {
|
for (j = 0; j < 8; j++) {
|
||||||
Uint8 button = buttons[i][j];
|
Uint8 button = buttons[i][j];
|
||||||
if (button != 0xFF) {
|
if (button != 0xFF) {
|
||||||
SDL_bool state = (data.rgucExtension[8 + i] >> j) & 1 ? SDL_RELEASED : SDL_PRESSED;
|
SDL_bool state = (data.rgucExtension[8 + i] >> j) & 1 ? SDL_RELEASED : SDL_PRESSED;
|
||||||
|
@ -813,8 +834,11 @@ HIDAPI_DriverWii_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||||
|
|
||||||
/* Request a status update periodically to make sure our battery value is up to date */
|
/* Request a status update periodically to make sure our battery value is up to date */
|
||||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->m_iLastStatus + FIFTEEN_MINUTES_IN_MS)) {
|
if (SDL_TICKS_PASSED(SDL_GetTicks(), ctx->m_iLastStatus + FIFTEEN_MINUTES_IN_MS)) {
|
||||||
|
Uint8 data[2];
|
||||||
ctx->m_iLastStatus = SDL_GetTicks();
|
ctx->m_iLastStatus = SDL_GetTicks();
|
||||||
WriteOutput(ctx, (Uint8[2]){ k_eWiiOutputReportIDs_StatusRequest, ctx->m_bRumbleActive }, 2, SDL_FALSE);
|
data[0] = k_eWiiOutputReportIDs_StatusRequest;
|
||||||
|
data[1] = ctx->m_bRumbleActive;
|
||||||
|
WriteOutput(ctx, data, 2, SDL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
|
|
Loading…
Reference in New Issue