Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding DRC (Wii U GamePad) support to Not64 (basing in FIX94's work) (experimental, needs testing) #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
480e15a
Add DRC (Wii U GamePad) support for Wii U
saulfabregwiivc Nov 10, 2021
8a5410b
Add DRC (Wii U GamePad) support (FIX94, emukidid)
saulfabregwiivc Dec 17, 2021
bffc69b
Merge pull request #1 from saulfabregwiivc/patch-2
saulfabregwiivc Dec 17, 2021
61395eb
Add DRC (Wii U GamePad) support
saulfabregwiivc Dec 17, 2021
9428dcf
Add DRC (Wii U GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
61e863a
Add DRC (Wii U GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
37e0567
Add DRC (Wii U GamePad) support (FIX94, emukidid)
saulfabregwiivc Dec 17, 2021
6dddec7
Add DRC (WiiU GamePad) support from Wii64 (FIX94, emukidid)
saulfabregwiivc Dec 17, 2021
0432362
Merge pull request #2 from saulfabregwiivc/patch-2
saulfabregwiivc Dec 17, 2021
0fefb94
Add DRC (Wii U GamePad) support (emukidid, FIX94)
saulfabregwiivc Dec 17, 2021
38a1823
Add DRC (Wii U GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
a1cf704
Add DRC (WiiU GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
aa7f8e2
Add DRC (WiiU GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
a801f11
Add DRC (Wii U GamePad) support from Wii64 (FIX94)
saulfabregwiivc Dec 17, 2021
fdefec2
Add DRC (Wii U GamePad) support (FIX94)
saulfabregwiivc Dec 17, 2021
57d4dbe
Add DRC (Wii U GamePad) support using libwiidrc (FIX94)
saulfabregwiivc Dec 17, 2021
395e2c4
Added a thing for "fix" the build based in mupen64gc-fix94
saulfabregwiivc Dec 17, 2021
74facba
Missed added the -DRVL_LIBWIIDRC fir finish adding DRC support (i thi…
saulfabregwiivc Dec 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile.menu2_wii
Expand Up @@ -5,7 +5,7 @@ CXX =powerpc-eabi-g++
AS =powerpc-eabi-as

CFLAGS = -pipe -Ofast -Wall -Wno-multichar -mrvl -fgnu89-inline -flto=jobserver \
-DWII -DRELEASE -DMENU_V2 -DGLN64_GX -DUSE_EXPANSION \
-DWII -DRELEASE -DMENU_V2 -D__wii__ -DRVL_LIBWIIDRC -DGLN64_GX -DUSE_EXPANSION \
-DPPC_DYNAREC -DUSE_RECOMP_CACHE -DFASTMEM -DNDEBUG

LDFLAGS =$(CFLAGS) -Wl,-Map,$(notdir $@).map -Wl,--cref
Expand Down Expand Up @@ -96,6 +96,7 @@ OBJ_INPUT =gc_input/main.o \
gc_input/controller-GC.o \
gc_input/controller-Extenmote.o \
gc_input/controller-Classic.o \
gc_input/controller-DRC.o \
gc_input/controller-WiimoteNunchuk.o

OBJ_RSPHLE =rsp_hle/alist.o \
Expand Down Expand Up @@ -163,7 +164,7 @@ HEADER =main/rom.h \
r4300/recomp.h \
gc_memory/pif.h

LIB = -laesnd -lwiiuse -lbte -ltinysmb -lfat -lz -static
LIB = -laesnd -lwiiuse -lbte -ltinysmb -lfat -lwiidrc -lz -static

ifeq ($(strip mupen64_GX_gfx/main.cpp),)
export LD := $(CC)
Expand Down
233 changes: 233 additions & 0 deletions gc_input/controller-DRC.c
@@ -0,0 +1,233 @@
/*
* Not64 - controller-DRC.c (based in controller-Classic.c)
* Original from emu_kidid (imported by saulfabreg)
* Copyright (c) 2013 Extrems <metaradil@gmail.com>
*
* This file is part of Not64.
*
* Not64 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Not64 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Not64; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <string.h>
#include <math.h>
#include "controller.h"
#include <wiidrc/wiidrc.h>

#define DRC_DEADZONE 6
#define _DRC_BUILD_TMPSTICK(inval) \
tmp_stick16 = (inval*1.08f); \
if(tmp_stick16 > DRC_DEADZONE) tmp_stick16 = (tmp_stick16-DRC_DEADZONE)*1.08f; \
else if(tmp_stick16 < -DRC_DEADZONE) tmp_stick16 = (tmp_stick16+DRC_DEADZONE)*1.08f; \
else tmp_stick16 = 0; \
if(tmp_stick16 > 80) tmp_stick8 = 80; \
else if(tmp_stick16 < -80) tmp_stick8 = -80; \
else tmp_stick8 = (s8)tmp_stick16;

static int getDRCValue(int in)
{
//do scale, deadzone and clamp
s8 tmp_stick8; s16 tmp_stick16;
_DRC_BUILD_TMPSTICK(in);
return tmp_stick8;
}

enum {
L_STICK_AS_ANALOG = 1, R_STICK_AS_ANALOG = 2,
};

enum {
L_STICK_L = 0x01 << 16,
L_STICK_R = 0x02 << 16,
L_STICK_U = 0x04 << 16,
L_STICK_D = 0x08 << 16,
R_STICK_L = 0x10 << 16,
R_STICK_R = 0x20 << 16,
R_STICK_U = 0x40 << 16,
R_STICK_D = 0x80 << 16,
};

static button_t buttons[] = {
{ 0, ~0, "None" },
{ 1, WIIDRC_BUTTON_UP, "D-Up" },
{ 2, WIIDRC_BUTTON_LEFT, "D-Left" },
{ 3, WIIDRC_BUTTON_RIGHT, "D-Right" },
{ 4, WIIDRC_BUTTON_DOWN, "D-Down" },
{ 5, WIIDRC_BUTTON_L, "L" },
{ 6, WIIDRC_BUTTON_R, "R" },
{ 7, WIIDRC_BUTTON_ZL, "Left Z" },
{ 8, WIIDRC_BUTTON_ZR, "Right Z" },
{ 9, WIIDRC_BUTTON_A, "A" },
{ 10, WIIDRC_BUTTON_B, "B" },
{ 11, WIIDRC_BUTTON_X, "X" },
{ 12, WIIDRC_BUTTON_Y, "Y" },
{ 13, WIIDRC_BUTTON_PLUS, "+" },
{ 14, WIIDRC_BUTTON_MINUS, "-" },
{ 15, WIIDRC_BUTTON_HOME, "Home" },
{ 16, R_STICK_U, "RS-Up" },
{ 17, R_STICK_L, "RS-Left" },
{ 18, R_STICK_R, "RS-Right" },
{ 19, R_STICK_D, "RS-Down" },
{ 20, L_STICK_U, "LS-Up" },
{ 21, L_STICK_L, "LS-Left" },
{ 22, L_STICK_R, "LS-Right" },
{ 23, L_STICK_D, "LS-Down" },
};

static button_t analog_sources[] = {
{ 0, L_STICK_AS_ANALOG, "Left Stick" },
{ 1, R_STICK_AS_ANALOG, "Right Stick" },
};

static button_t menu_combos[] = {
{ 0, WIIDRC_BUTTON_X|WIIDRC_BUTTON_Y, "X+Y" },
{ 1, WIIDRC_BUTTON_ZL|WIIDRC_BUTTON_ZR, "ZL+ZR" },
};

static unsigned int getButtons()
{
const struct WiiDRCData *data = WiiDRC_Data();

unsigned int b = data->button;

if(data->xAxisL < -20) b |= L_STICK_L;
if(data->xAxisL > 20) b |= L_STICK_R;
if(data->yAxisL > 20) b |= L_STICK_U;
if(data->yAxisL < -20) b |= L_STICK_D;

if(data->xAxisR < -20) b |= R_STICK_L;
if(data->xAxisR > 20) b |= R_STICK_R;
if(data->yAxisR > 20) b |= R_STICK_U;
if(data->yAxisR < -20) b |= R_STICK_D;

return b;
}

static int available(int Control) {
if(Control == 0 && WiiDRC_Inited() && WiiDRC_Connected())
{
controller_DRC.available[Control] = 1;
return 1;
}
else
{
controller_DRC.available[Control] = 0;
return 0;
}
}

static int _GetKeys(int Control, BUTTONS * Keys, controller_config_t* config)
{
if(drcNeedScan){ WiiDRC_ScanPads(); drcNeedScan = 0; }
BUTTONS* c = Keys;
memset(c, 0, sizeof(BUTTONS));

// Only use a connected classic controller
if(!available(Control))
return 0;

unsigned int b = getButtons();
inline int isHeld(button_tp button){
return (b & button->mask) == button->mask;
}

c->R_DPAD = isHeld(config->DR);
c->L_DPAD = isHeld(config->DL);
c->D_DPAD = isHeld(config->DD);
c->U_DPAD = isHeld(config->DU);

c->START_BUTTON = isHeld(config->START);
c->B_BUTTON = isHeld(config->B);
c->A_BUTTON = isHeld(config->A);

c->Z_TRIG = isHeld(config->Z);
c->R_TRIG = isHeld(config->R);
c->L_TRIG = isHeld(config->L);

c->R_CBUTTON = isHeld(config->CR);
c->L_CBUTTON = isHeld(config->CL);
c->D_CBUTTON = isHeld(config->CD);
c->U_CBUTTON = isHeld(config->CU);

if(config->analog->mask == L_STICK_AS_ANALOG){
c->X_AXIS = getDRCValue(WiiDRC_lStickX());
c->Y_AXIS = getDRCValue(WiiDRC_lStickY());
} else if(config->analog->mask == R_STICK_AS_ANALOG){
c->X_AXIS = getDRCValue(WiiDRC_rStickX());
c->Y_AXIS = getDRCValue(WiiDRC_rStickY());
}
if(config->invertedY) c->Y_AXIS = -c->Y_AXIS;

// Return whether the exit button(s) are pressed
return isHeld(config->exit);
}

static void pause(int Control){ }

static void resume(int Control){ }

static void rumble(int Control, int rumble){ }

static void configure(int Control, controller_config_t* config){
// Don't know how this should be integrated
}

static void assign(int p, int v){
// TODO: Light up the LEDs appropriately
}

static void refreshAvailable(void);

controller_t controller_DRC =
{ 'D',
_GetKeys,
configure,
assign,
pause,
resume,
rumble,
refreshAvailable,
{0, 0, 0, 0},
sizeof(buttons)/sizeof(buttons[0]),
buttons,
sizeof(analog_sources)/sizeof(analog_sources[0]),
analog_sources,
sizeof(menu_combos)/sizeof(menu_combos[0]),
menu_combos,
{ .DU = &buttons[1], // D-Pad Up
.DL = &buttons[2], // D-Pad Left
.DR = &buttons[3], // D-Pad Right
.DD = &buttons[4], // D-Pad Down
.Z = &buttons[7], // Left Z
.L = &buttons[5], // Left Trigger
.R = &buttons[6], // Right Trigger
.A = &buttons[9], // A
.B = &buttons[10], // B
.START = &buttons[13], // +
.CU = &buttons[16], // Right Stick Up
.CL = &buttons[17], // Right Stick Left
.CR = &buttons[18], // Right Stick Right
.CD = &buttons[19], // Right Stick Down
.analog = &analog_sources[0],
.exit = &menu_combos[0],
.invertedY = 0,
}
};

static void refreshAvailable(void){
int i;
for(i=0; i<4; ++i){
available(i);
}
}
6 changes: 4 additions & 2 deletions gc_input/input.c
Expand Up @@ -38,7 +38,7 @@
static CONTROL_INFO control_info;
static BOOL lastData[4];

virtualControllers_t virtualControllers[4];
virtualControllers_t virtualControllers[5];

controller_t* controller_ts[num_controller_t] =
#if defined(WII) && !defined(NO_BT)
Expand All @@ -49,6 +49,7 @@ controller_t* controller_ts[num_controller_t] =
&controller_ExtenmoteNES,
&controller_WiiUPro,
&controller_Classic,
&controller_DRC,
&controller_WiimoteNunchuk,
&controller_Wiimote,
};
Expand Down Expand Up @@ -335,7 +336,8 @@ EXPORT void CALL WM_KeyDown( WPARAM wParam, LPARAM lParam )
EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam )
{
}
void pauseInput(void){

void pauseInput(void){
int i;
for(i=0; i<4; ++i){
if(virtualControllers[i].inUse){
Expand Down
34 changes: 34 additions & 0 deletions libgui/FocusManager.cpp
Expand Up @@ -38,6 +38,7 @@ Focus::Focus()
{
for (int i=0; i<4; i++) {
previousButtonsWii[i] = 0;
previousButtonsDRC[i] = 0;
previousButtonsGC[i] = 0;
}
}
Expand Down Expand Up @@ -71,6 +72,7 @@ void Focus::updateFocus()
previousButtonsGC[i] = PAD_ButtonsHeld(i);
#ifdef HW_RVL
previousButtonsWii[i] = WPAD_ButtonsHeld(i);
previousButtonsDRC[i] = (i == 0 ? WiiDRC_ButtonsHeld() : 0);
#endif
}
clearInput = false;
Expand Down Expand Up @@ -213,6 +215,38 @@ void Focus::updateFocus()
else primaryFocusOwner = currentFrame->updateFocus(focusDirection,buttonsDown);
break;
}

else if (i == 0 && WiiDRC_Inited() && WiiDRC_Connected() && (WiiDRC_ButtonsHeld() ^ previousButtonsDRC[i]))
{
u32 currentButtonsDownDRC = (WiiDRC_ButtonsHeld() ^ previousButtonsDRC[i]) & WiiDRC_ButtonsHeld();
previousButtonsDRC[i] = WiiDRC_ButtonsHeld();
switch (currentButtonsDownDRC) {
case WIIDRC_BUTTON_LEFT:
focusDirection = DIRECTION_LEFT;
break;
case WIIDRC_BUTTON_RIGHT:
focusDirection = DIRECTION_RIGHT;
break;
case WIIDRC_BUTTON_DOWN:
focusDirection = DIRECTION_DOWN;
break;
case WIIDRC_BUTTON_UP:
focusDirection = DIRECTION_UP;
break;
default:
focusDirection = DIRECTION_NONE;
}
if (currentButtonsDownDRC & (WIIDRC_BUTTON_A)) buttonsDown |= ACTION_SELECT;
if (currentButtonsDownDRC & (WIIDRC_BUTTON_B)) buttonsDown |= ACTION_BACK;
if (freezeAction)
{
focusDirection = DIRECTION_NONE;
buttonsDown = 0;
}
if (primaryFocusOwner) primaryFocusOwner = primaryFocusOwner->updateFocus(focusDirection,buttonsDown);
else primaryFocusOwner = currentFrame->updateFocus(focusDirection,buttonsDown);
break;
}
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions libgui/FocusManager.h
Expand Up @@ -64,6 +64,7 @@ class Focus
int buttonsPressed, previousButtonsPressed;
u32 previousButtonsWii[4];
u16 previousButtonsGC[4];
u32 previousButtonsDRC[4];
ComponentList focusList;
Component *primaryFocusOwner, *secondaryFocusOwner;
Frame *currentFrame;
Expand Down
11 changes: 7 additions & 4 deletions libgui/InputManager.cpp
Expand Up @@ -22,6 +22,7 @@
#include "FocusManager.h"
#include "CursorManager.h"
#include "../main/wii64config.h"
#include <wiidrc/wiidrc.h>

extern char shutdown;
extern int stop;
Expand All @@ -35,13 +36,14 @@ Input::Input()
{
PAD_SetSamplingRate(pollRate);
PAD_Init();
#ifdef HW_RVL
WPAD_Init();
#ifdef HW_RVL
WPAD_Init();
WPAD_SetVRes(WPAD_CHAN_ALL, 640, 480);
WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
SYS_SetPowerCallback(PowerCallback);
WiiDRC_Init();
#endif
SYS_SetResetCallback(ResetCallback);
SYS_SetResetCallback(ResetCallback);
}

Input::~Input()
Expand All @@ -53,6 +55,7 @@ void Input::refreshInput()
PAD_ScanPads();
#ifdef HW_RVL
WPAD_ScanPads();
if(drcNeedScan){ WiiDRC_ScanPads(); drcNeedScan = 0; }
#endif
}

Expand Down
1 change: 1 addition & 0 deletions libgui/InputManager.h
Expand Up @@ -22,6 +22,7 @@
#define INPUTMANAGER_H

#include "GuiTypes.h"
#include <wiidrc/wiidrc.h>

namespace menu {

Expand Down