[Wii] added missing source files for WiiU GamePad Controller support on vWii

This commit is contained in:
EkeEke 2017-12-13 23:07:42 +01:00
parent 77ef8e8b70
commit 515e2ff0d1
5 changed files with 289 additions and 2 deletions

View File

@ -21,10 +21,10 @@ TARGET := genplus_wii
BUILD := build_wii
SOURCES := core core/m68k core/z80 core/sound core/tremor core/ntsc core/input_hw core/cd_hw core/cart_hw core/cart_hw/svp \
$(CHDLIBDIR)/src $(CHDLIBDIR)/deps/libFLAC $(CHDLIBDIR)/deps/lzma \
gx gx/utils gx/gui gx/fileio gx/images gx/sounds
gx gx/utils gx/utils/wiidrc gx/gui gx/fileio gx/images gx/sounds
INCLUDES := core core/m68k core/z80 core/sound core/tremor core/ntsc core/input_hw core/cd_hw core/cart_hw core/cart_hw/svp \
$(CHDLIBDIR)/src $(CHDLIBDIR)/deps/libFLAC/include $(CHDLIBDIR)/deps/lzma \
gx gx/utils gx/gui gx/fileio gx/images gx/sounds \
gx gx/utils gx/utils/wiidrc gx/gui gx/fileio gx/images gx/sounds \
$(BUILD)
#---------------------------------------------------------------------------------

21
gx/utils/wiidrc/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 FIX94
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

176
gx/utils/wiidrc/wiidrc.c Normal file
View File

@ -0,0 +1,176 @@
/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#include <gccore.h>
#include <stdio.h>
#include <string.h>
#include "wiidrc_structs.h"
#include "wiidrc/wiidrc.h"
static struct WiiDRCStat __WiiDRC_Status;
static struct WiiDRCData __WiiDRC_PadData;
static struct WiiDRCButtons __WiiDRC_PadButtons;
static bool __WiiDRC_ShutdownRequested;
static u32 __WiiDRC_Inited = 0;
static u8 *__WiiDRC_I2CBuf = NULL;
static u8 *__WiiDRC_DRCStateBuf = NULL;
static bool __WiiDRC_SetI2CBuf()
{
DCInvalidateRange((void*)0x938B2964, 4);
if(*(vu32*)0x938B2964 == 0x138BB004) //r569
{
__WiiDRC_I2CBuf = (u8*)0x938BB004;
return true;
}
DCInvalidateRange((void*)0x938B2564, 4);
if(*(vu32*)0x938B2564 == 0x138BB004) //r570
{
__WiiDRC_I2CBuf = (u8*)0x938BB004;
return true;
}
else if(*(vu32*)0x938B2564 == 0x138BA004) //r590
{
__WiiDRC_I2CBuf = (u8*)0x938BA004;
return true;
}
return false;
}
static bool __WiiDRC_SetDRCStateBuf()
{
//TODO r569
DCInvalidateRange((void*)0x938B563C, 4);
if(*(vu32*)0x938B563C == 0x138BE770) //r570
{
__WiiDRC_DRCStateBuf = (u8*)0x938BE770;
return true;
}
DCInvalidateRange((void*)0x938B5724, 4);
if(*(vu32*)0x938B5724 == 0x138BD770) //r590
{
__WiiDRC_DRCStateBuf = (u8*)0x938BD770;
return true;
}
return false;
}
bool WiiDRC_Init()
{
if(__WiiDRC_Inited == 1)
return false;
if(!__WiiDRC_SetI2CBuf())
return false;
//can fail on r569 for now
__WiiDRC_SetDRCStateBuf();
__WiiDRC_Inited = 1;
WiiDRC_Recalibrate(); //sets up __WiiDRC_Status
memset(&__WiiDRC_PadData,0,sizeof(struct WiiDRCData));
memset(&__WiiDRC_PadButtons,0,sizeof(struct WiiDRCButtons));
__WiiDRC_ShutdownRequested = false;
return true;
}
bool WiiDRC_Inited()
{
return !!__WiiDRC_Inited;
}
bool WiiDRC_Recalibrate()
{
if(__WiiDRC_Inited == 0)
return false;
DCInvalidateRange(__WiiDRC_I2CBuf,9);
__WiiDRC_Status.xAxisLmid = (s8)(__WiiDRC_I2CBuf[4]-0x80);
__WiiDRC_Status.yAxisLmid = (s8)(__WiiDRC_I2CBuf[5]-0x80);
__WiiDRC_Status.xAxisRmid = (s8)(__WiiDRC_I2CBuf[6]-0x80);
__WiiDRC_Status.yAxisRmid = (s8)(__WiiDRC_I2CBuf[7]-0x80);
return true;
}
bool WiiDRC_ScanPads()
{
if(__WiiDRC_Inited == 0)
return false;
DCInvalidateRange(__WiiDRC_I2CBuf,9);
__WiiDRC_ShutdownRequested = !!(__WiiDRC_I2CBuf[1]&0x80);
__WiiDRC_PadData.button = (__WiiDRC_I2CBuf[2]<<8) | (__WiiDRC_I2CBuf[3]);
__WiiDRC_PadData.xAxisL = ((s8)(__WiiDRC_I2CBuf[4]-0x80)) - __WiiDRC_Status.xAxisLmid;
__WiiDRC_PadData.yAxisL = ((s8)(__WiiDRC_I2CBuf[5]-0x80)) - __WiiDRC_Status.yAxisLmid;
__WiiDRC_PadData.xAxisR = ((s8)(__WiiDRC_I2CBuf[6]-0x80)) - __WiiDRC_Status.xAxisRmid;
__WiiDRC_PadData.yAxisR = ((s8)(__WiiDRC_I2CBuf[7]-0x80)) - __WiiDRC_Status.yAxisRmid;
__WiiDRC_PadData.extra = __WiiDRC_I2CBuf[8];
__WiiDRC_PadData.battery = (__WiiDRC_PadData.extra>>1)&7;
u16 newstate, oldstate;
newstate = __WiiDRC_PadData.button;
oldstate = __WiiDRC_PadButtons.state;
__WiiDRC_PadButtons.state = newstate;
__WiiDRC_PadButtons.up = oldstate & ~newstate;
__WiiDRC_PadButtons.down = newstate & (newstate ^ oldstate);
return true;
}
bool WiiDRC_Connected()
{
if(__WiiDRC_DRCStateBuf)
{
DCInvalidateRange(__WiiDRC_DRCStateBuf, 4);
return !!(*(vu32*)__WiiDRC_DRCStateBuf);
}
return true; //default connect
}
bool WiiDRC_ShutdownRequested()
{
return __WiiDRC_ShutdownRequested;
}
const u8 *WiiDRC_GetRawI2CAddr()
{
return __WiiDRC_I2CBuf;
}
const struct WiiDRCData *WiiDRC_Data()
{
return &__WiiDRC_PadData;
}
u32 WiiDRC_ButtonsUp()
{
return __WiiDRC_PadButtons.up;
}
u32 WiiDRC_ButtonsDown()
{
return __WiiDRC_PadButtons.down;
}
u32 WiiDRC_ButtonsHeld()
{
return __WiiDRC_PadButtons.state;
}
s16 WiiDRC_lStickX()
{
return __WiiDRC_PadData.xAxisL;
}
s16 WiiDRC_lStickY()
{
return __WiiDRC_PadData.yAxisL;
}
s16 WiiDRC_rStickX()
{
return __WiiDRC_PadData.xAxisR;
}
s16 WiiDRC_rStickY()
{
return __WiiDRC_PadData.yAxisR;
}

67
gx/utils/wiidrc/wiidrc.h Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#ifndef _WIIDRC_H_
#define _WIIDRC_H_
#ifdef __cplusplus
extern "C" {
#endif
struct WiiDRCData {
s16 xAxisL;
s16 xAxisR;
s16 yAxisL;
s16 yAxisR;
u16 button;
u8 battery;
u8 extra;
};
#define WIIDRC_BUTTON_A 0x8000
#define WIIDRC_BUTTON_B 0x4000
#define WIIDRC_BUTTON_X 0x2000
#define WIIDRC_BUTTON_Y 0x1000
#define WIIDRC_BUTTON_LEFT 0x0800
#define WIIDRC_BUTTON_RIGHT 0x0400
#define WIIDRC_BUTTON_UP 0x0200
#define WIIDRC_BUTTON_DOWN 0x0100
#define WIIDRC_BUTTON_ZL 0x0080
#define WIIDRC_BUTTON_ZR 0x0040
#define WIIDRC_BUTTON_L 0x0020
#define WIIDRC_BUTTON_R 0x0010
#define WIIDRC_BUTTON_PLUS 0x0008
#define WIIDRC_BUTTON_MINUS 0x0004
#define WIIDRC_BUTTON_HOME 0x0002
#define WIIDRC_BUTTON_SYNC 0x0001
#define WIIDRC_EXTRA_BUTTON_L3 0x80
#define WIIDRC_EXTRA_BUTTON_R3 0x40
#define WIIDRC_EXTRA_BUTTON_TV 0x20
#define WIIDRC_EXTRA_OVERLAY_TV 0x10
#define WIIDRC_EXTRA_OVERLAY_POWER 0x01
bool WiiDRC_Init();
bool WiiDRC_Inited();
bool WiiDRC_Recalibrate();
bool WiiDRC_ScanPads();
bool WiiDRC_Connected();
bool WiiDRC_ShutdownRequested();
const u8 *WiiDRC_GetRawI2CAddr();
const struct WiiDRCData *WiiDRC_Data();
u32 WiiDRC_ButtonsUp();
u32 WiiDRC_ButtonsDown();
u32 WiiDRC_ButtonsHeld();
s16 WiiDRC_lStickX();
s16 WiiDRC_lStickY();
s16 WiiDRC_rStickX();
s16 WiiDRC_rStickY();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#ifndef _WIIDRC_STRUCTS_H_
#define _WIIDRC_STRUCTS_H_
struct WiiDRCStat {
s16 xAxisLmid;
s16 xAxisRmid;
s16 yAxisLmid;
s16 yAxisRmid;
};
struct WiiDRCButtons {
u32 up;
u32 down;
u32 state;
};
#endif