mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-29 15:04:23 +01:00
Implement binding of keys to any wiimote direction or button. If it
works? Who knows :-) Also some comments about what network should do.
This commit is contained in:
parent
331320c6e5
commit
debf526c38
@ -274,7 +274,9 @@ void C64::select_disc(Prefs *np)
|
|||||||
|
|
||||||
char *C64::bind_one_key(Prefs *np, int which)
|
char *C64::bind_one_key(Prefs *np, int which)
|
||||||
{
|
{
|
||||||
static const char *which_to_button_name[] = { "A", "B", "+", "-", "1",
|
static const char *which_to_button_name[] = { "up", "down", "left", "right",
|
||||||
|
"fire","A", "B", "+", "-", "1",
|
||||||
|
"classic up", "classic down", "classic left", "classic right", "classic fire",
|
||||||
"classic X", "classic Y", "classic B", "classic L",
|
"classic X", "classic Y", "classic B", "classic L",
|
||||||
"classic R", "classic ZR", "classic ZL" };
|
"classic R", "classic ZR", "classic ZL" };
|
||||||
static char strs[N_WIIMOTE_BINDINGS][255];
|
static char strs[N_WIIMOTE_BINDINGS][255];
|
||||||
@ -305,7 +307,7 @@ void C64::bind_keys(Prefs *np)
|
|||||||
|
|
||||||
memset(bind_key_messages, 0, sizeof(const char*) * (N_WIIMOTE_BINDINGS + 1));
|
memset(bind_key_messages, 0, sizeof(const char*) * (N_WIIMOTE_BINDINGS + 1));
|
||||||
|
|
||||||
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : 5); i++)
|
for (int i = 0; i < (has_classic_controller ? N_WIIMOTE_BINDINGS : WIIMOTE_2); i++)
|
||||||
bind_key_messages[i] = this->bind_one_key(np, i);
|
bind_key_messages[i] = this->bind_one_key(np, i);
|
||||||
|
|
||||||
int opt = menu_select(real_screen, this->menu_font,
|
int opt = menu_select(real_screen, this->menu_font,
|
||||||
|
@ -611,62 +611,55 @@ uint8 C64::poll_joystick(int port)
|
|||||||
int extra_keys[N_WIIMOTE_BINDINGS];
|
int extra_keys[N_WIIMOTE_BINDINGS];
|
||||||
int controller = port;
|
int controller = port;
|
||||||
Uint32 held = 0;
|
Uint32 held = 0;
|
||||||
Uint32 held_other = 0;
|
|
||||||
Uint32 held_classic = 0;
|
Uint32 held_classic = 0;
|
||||||
Uint32 held_classic_other = 0;
|
WPADData *wpad;
|
||||||
WPADData *wpad, *wpad_other;
|
|
||||||
|
|
||||||
if (ThePrefs.JoystickSwap)
|
if (ThePrefs.JoystickSwap)
|
||||||
controller = !port;
|
controller = !port;
|
||||||
|
|
||||||
wpad = WPAD_Data(controller);
|
wpad = WPAD_Data(controller);
|
||||||
wpad_other = WPAD_Data(!controller);
|
if (!wpad)
|
||||||
if (!wpad && !wpad_other)
|
return j;
|
||||||
return 0xff;
|
|
||||||
|
|
||||||
held = wpad->btns_h;
|
held = wpad->btns_h;
|
||||||
held_other = wpad_other->btns_h;
|
|
||||||
|
|
||||||
// Check classic controller as well
|
// Check classic controller as well
|
||||||
if (wpad->exp.type == WPAD_EXP_CLASSIC)
|
if (wpad->exp.type == WPAD_EXP_CLASSIC)
|
||||||
held_classic = wpad->exp.classic.btns_held;
|
held_classic = wpad->exp.classic.btns_held;
|
||||||
if (wpad_other->exp.type == WPAD_EXP_CLASSIC)
|
|
||||||
held_classic_other = wpad_other->exp.classic.btns_held;
|
|
||||||
|
|
||||||
if ( (held & WPAD_BUTTON_UP) || (held_classic & CLASSIC_CTRL_BUTTON_LEFT) )
|
extra_keys[WIIMOTE_UP] = held & WPAD_BUTTON_UP;
|
||||||
j &= 0xfb; // Left
|
extra_keys[WIIMOTE_DOWN] = held & WPAD_BUTTON_DOWN;
|
||||||
if ( (held & WPAD_BUTTON_DOWN) || (held_classic & CLASSIC_CTRL_BUTTON_RIGHT) )
|
extra_keys[WIIMOTE_LEFT] = held & WPAD_BUTTON_LEFT;
|
||||||
j &= 0xf7; // Right
|
extra_keys[WIIMOTE_RIGHT] = held & WPAD_BUTTON_RIGHT;
|
||||||
if ( (held & WPAD_BUTTON_RIGHT) || (held_classic & CLASSIC_CTRL_BUTTON_UP) )
|
|
||||||
j &= 0xfe; // Up
|
|
||||||
if ( (held & WPAD_BUTTON_LEFT) || (held_classic & CLASSIC_CTRL_BUTTON_DOWN) )
|
|
||||||
j &= 0xfd; // Down
|
|
||||||
if ( (held & WPAD_BUTTON_2) || (held_classic & CLASSIC_CTRL_BUTTON_A) )
|
|
||||||
j &= 0xef; // Button
|
|
||||||
if ( (held & WPAD_BUTTON_HOME) || (held_classic & CLASSIC_CTRL_BUTTON_HOME) )
|
|
||||||
TheC64->enter_menu();
|
|
||||||
|
|
||||||
extra_keys[WIIMOTE_A] = (held | held_other) & WPAD_BUTTON_A;
|
extra_keys[WIIMOTE_A] = held & WPAD_BUTTON_A;
|
||||||
extra_keys[WIIMOTE_B] = (held | held_other) & WPAD_BUTTON_B;
|
extra_keys[WIIMOTE_B] = held & WPAD_BUTTON_B;
|
||||||
extra_keys[WIIMOTE_1] = (held | held_other) & WPAD_BUTTON_1;
|
extra_keys[WIIMOTE_1] = held & WPAD_BUTTON_1;
|
||||||
|
extra_keys[WIIMOTE_2] = held & WPAD_BUTTON_2;
|
||||||
|
|
||||||
/* Classic buttons (might not be connected) */
|
/* Classic buttons (might not be connected) */
|
||||||
extra_keys[CLASSIC_X] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_X;
|
extra_keys[CLASSIC_UP] = held_classic & CLASSIC_CTRL_BUTTON_UP;
|
||||||
extra_keys[CLASSIC_Y] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_Y;
|
extra_keys[CLASSIC_DOWN] = held_classic & CLASSIC_CTRL_BUTTON_DOWN;
|
||||||
extra_keys[CLASSIC_B] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_B;
|
extra_keys[CLASSIC_LEFT] = held_classic & CLASSIC_CTRL_BUTTON_LEFT;
|
||||||
extra_keys[CLASSIC_L] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_FULL_L;
|
extra_keys[CLASSIC_RIGHT] = held_classic & CLASSIC_CTRL_BUTTON_RIGHT;
|
||||||
extra_keys[CLASSIC_R] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_FULL_R;
|
|
||||||
extra_keys[CLASSIC_ZL] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_ZL;
|
|
||||||
extra_keys[CLASSIC_ZR] = (held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_ZR;
|
|
||||||
|
|
||||||
extra_keys[WIIMOTE_PLUS] = ((held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_MINUS) |
|
extra_keys[CLASSIC_X] = held_classic & CLASSIC_CTRL_BUTTON_X;
|
||||||
(held | held_other) & WPAD_BUTTON_PLUS;
|
extra_keys[CLASSIC_Y] = held_classic & CLASSIC_CTRL_BUTTON_Y;
|
||||||
extra_keys[WIIMOTE_MINUS] = ((held_classic | held_classic_other) & CLASSIC_CTRL_BUTTON_PLUS) |
|
extra_keys[CLASSIC_A] = held_classic & CLASSIC_CTRL_BUTTON_A;
|
||||||
(held | held_other) & WPAD_BUTTON_MINUS;
|
extra_keys[CLASSIC_B] = held_classic & CLASSIC_CTRL_BUTTON_B;
|
||||||
|
extra_keys[CLASSIC_L] = held_classic & CLASSIC_CTRL_BUTTON_FULL_L;
|
||||||
|
extra_keys[CLASSIC_R] = held_classic & CLASSIC_CTRL_BUTTON_FULL_R;
|
||||||
|
extra_keys[CLASSIC_ZL] = held_classic & CLASSIC_CTRL_BUTTON_ZL;
|
||||||
|
extra_keys[CLASSIC_ZR] = held_classic & CLASSIC_CTRL_BUTTON_ZR;
|
||||||
|
|
||||||
|
extra_keys[WIIMOTE_PLUS] = (held_classic & CLASSIC_CTRL_BUTTON_MINUS) |
|
||||||
|
held & WPAD_BUTTON_PLUS;
|
||||||
|
extra_keys[WIIMOTE_MINUS] = (held_classic & CLASSIC_CTRL_BUTTON_PLUS) |
|
||||||
|
held & WPAD_BUTTON_MINUS;
|
||||||
|
|
||||||
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
|
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
|
||||||
{
|
{
|
||||||
static bool is_pressed[N_WIIMOTE_BINDINGS];
|
static bool is_pressed[2][N_WIIMOTE_BINDINGS];
|
||||||
int kc = ThePrefs.JoystickKeyBinding[i];
|
int kc = ThePrefs.JoystickKeyBinding[i];
|
||||||
|
|
||||||
if ( kc >= 0)
|
if ( kc >= 0)
|
||||||
@ -676,14 +669,14 @@ uint8 C64::poll_joystick(int port)
|
|||||||
TheDisplay->UpdateKeyMatrix(kc, false,
|
TheDisplay->UpdateKeyMatrix(kc, false,
|
||||||
TheCIA1->KeyMatrix, TheCIA1->RevMatrix,
|
TheCIA1->KeyMatrix, TheCIA1->RevMatrix,
|
||||||
&j);
|
&j);
|
||||||
is_pressed[i] = true;
|
is_pressed[controller][i] = true;
|
||||||
}
|
}
|
||||||
else if (is_pressed[i])
|
else if (is_pressed[i])
|
||||||
{
|
{
|
||||||
TheDisplay->UpdateKeyMatrix(kc, true,
|
TheDisplay->UpdateKeyMatrix(kc, true,
|
||||||
TheCIA1->KeyMatrix, TheCIA1->RevMatrix,
|
TheCIA1->KeyMatrix, TheCIA1->RevMatrix,
|
||||||
&j);
|
&j);
|
||||||
is_pressed[i] = false;
|
is_pressed[controller][i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -753,6 +753,17 @@ bool Network::WaitForConnection()
|
|||||||
|
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
/* See http://www.brynosaurus.com/pub/net/p2pnat/ for how this works.
|
||||||
|
* To do here:
|
||||||
|
*
|
||||||
|
* 1. Send connect to the broker
|
||||||
|
* 2. Wait for broker to return the peer connection info (private
|
||||||
|
* and public address)
|
||||||
|
* 3. Until connected:
|
||||||
|
* 3.1 Send connection message to peer
|
||||||
|
* 3.2 Wait for reply from peer
|
||||||
|
*/
|
||||||
if (this->ReceiveUpdate(&tv) == true)
|
if (this->ReceiveUpdate(&tv) == true)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -761,6 +772,18 @@ bool Network::WaitForConnection()
|
|||||||
|
|
||||||
bool Network::ConnectToPeer()
|
bool Network::ConnectToPeer()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* To do here:
|
||||||
|
*
|
||||||
|
* 1. Send connect to the broker
|
||||||
|
* 2. Wait for the broker to return list of peers
|
||||||
|
* 3. Tell the broker who to connect to
|
||||||
|
* 4. Wait for broker to return the peer connection info (private
|
||||||
|
* and public address)
|
||||||
|
* 5. Until connected:
|
||||||
|
* 5.1 Send connection message to peer
|
||||||
|
* 5.2 Wait for reply from peer
|
||||||
|
*/
|
||||||
return this->SendUpdate();
|
return this->SendUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,17 @@ enum
|
|||||||
ENTER_MENU = 8,
|
ENTER_MENU = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
CONNECT_TO_BROKER,
|
||||||
|
WAIT_FOR_PEER_ADDRESS,
|
||||||
|
CONNECT_TO_PEER,
|
||||||
|
WAIT_FOR_PEER_REPLY,
|
||||||
|
|
||||||
|
/* Client-only */
|
||||||
|
WAIT_FOR_PEER_LIST,
|
||||||
|
};
|
||||||
|
|
||||||
struct NetworkUpdate
|
struct NetworkUpdate
|
||||||
{
|
{
|
||||||
uint16 magic; /* Should be 0x1976 */
|
uint16 magic; /* Should be 0x1976 */
|
||||||
|
@ -87,6 +87,17 @@ Prefs::Prefs()
|
|||||||
#ifdef HAVE_SDL
|
#ifdef HAVE_SDL
|
||||||
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
|
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
|
||||||
this->JoystickKeyBinding[i] = -1;
|
this->JoystickKeyBinding[i] = -1;
|
||||||
|
this->JoystickKeyBinding[WIIMOTE_UP] = 0x40 | 0x1;
|
||||||
|
this->JoystickKeyBinding[WIIMOTE_DOWN] = 0x40 | 0x2;
|
||||||
|
this->JoystickKeyBinding[WIIMOTE_LEFT] = 0x40 | 0x4;
|
||||||
|
this->JoystickKeyBinding[WIIMOTE_RIGHT] = 0x40 | 0x8;
|
||||||
|
this->JoystickKeyBinding[WIIMOTE_2] = 0x40 | 0x10;
|
||||||
|
|
||||||
|
this->JoystickKeyBinding[CLASSIC_UP] = 0x40 | 0x1;
|
||||||
|
this->JoystickKeyBinding[CLASSIC_DOWN] = 0x40 | 0x2;
|
||||||
|
this->JoystickKeyBinding[CLASSIC_LEFT] = 0x40 | 0x4;
|
||||||
|
this->JoystickKeyBinding[CLASSIC_RIGHT] = 0x40 | 0x8;
|
||||||
|
this->JoystickKeyBinding[CLASSIC_B] = 0x40 | 0x10;
|
||||||
|
|
||||||
this->DisplayOption = 0;
|
this->DisplayOption = 0;
|
||||||
this->MsPerFrame = 28;
|
this->MsPerFrame = 28;
|
||||||
@ -155,6 +166,15 @@ bool Prefs::operator==(const Prefs &rhs) const
|
|||||||
&& this->JoystickKeyBinding[10] == rhs.JoystickKeyBinding[10]
|
&& this->JoystickKeyBinding[10] == rhs.JoystickKeyBinding[10]
|
||||||
&& this->JoystickKeyBinding[11] == rhs.JoystickKeyBinding[11]
|
&& this->JoystickKeyBinding[11] == rhs.JoystickKeyBinding[11]
|
||||||
&& this->JoystickKeyBinding[12] == rhs.JoystickKeyBinding[12]
|
&& this->JoystickKeyBinding[12] == rhs.JoystickKeyBinding[12]
|
||||||
|
&& this->JoystickKeyBinding[13] == rhs.JoystickKeyBinding[13]
|
||||||
|
&& this->JoystickKeyBinding[14] == rhs.JoystickKeyBinding[14]
|
||||||
|
&& this->JoystickKeyBinding[15] == rhs.JoystickKeyBinding[15]
|
||||||
|
&& this->JoystickKeyBinding[16] == rhs.JoystickKeyBinding[16]
|
||||||
|
&& this->JoystickKeyBinding[17] == rhs.JoystickKeyBinding[17]
|
||||||
|
&& this->JoystickKeyBinding[18] == rhs.JoystickKeyBinding[18]
|
||||||
|
&& this->JoystickKeyBinding[19] == rhs.JoystickKeyBinding[19]
|
||||||
|
&& this->JoystickKeyBinding[20] == rhs.JoystickKeyBinding[20]
|
||||||
|
&& this->JoystickKeyBinding[21] == rhs.JoystickKeyBinding[21]
|
||||||
&& this->DisplayOption == rhs.DisplayOption
|
&& this->DisplayOption == rhs.DisplayOption
|
||||||
&& this->MsPerFrame == rhs.MsPerFrame
|
&& this->MsPerFrame == rhs.MsPerFrame
|
||||||
#endif
|
#endif
|
||||||
@ -317,6 +337,24 @@ void Prefs::Load(char *filename)
|
|||||||
JoystickKeyBinding[11] = atoi(value);
|
JoystickKeyBinding[11] = atoi(value);
|
||||||
else if (!strcmp(keyword, "JoystickKeyBinding12"))
|
else if (!strcmp(keyword, "JoystickKeyBinding12"))
|
||||||
JoystickKeyBinding[12] = atoi(value);
|
JoystickKeyBinding[12] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding13"))
|
||||||
|
JoystickKeyBinding[13] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding14"))
|
||||||
|
JoystickKeyBinding[14] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding15"))
|
||||||
|
JoystickKeyBinding[15] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding16"))
|
||||||
|
JoystickKeyBinding[16] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding17"))
|
||||||
|
JoystickKeyBinding[17] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding18"))
|
||||||
|
JoystickKeyBinding[18] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding19"))
|
||||||
|
JoystickKeyBinding[19] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding20"))
|
||||||
|
JoystickKeyBinding[20] = atoi(value);
|
||||||
|
else if (!strcmp(keyword, "JoystickKeyBinding21"))
|
||||||
|
JoystickKeyBinding[21] = atoi(value);
|
||||||
else if (!strcmp(keyword, "DisplayOption"))
|
else if (!strcmp(keyword, "DisplayOption"))
|
||||||
DisplayOption = atoi(value);
|
DisplayOption = atoi(value);
|
||||||
else if (!strcmp(keyword, "MsPerFrame"))
|
else if (!strcmp(keyword, "MsPerFrame"))
|
||||||
|
10
Src/Prefs.h
10
Src/Prefs.h
@ -47,13 +47,23 @@ enum {
|
|||||||
|
|
||||||
// Key bindings (WII)
|
// Key bindings (WII)
|
||||||
enum {
|
enum {
|
||||||
|
WIIMOTE_UP,
|
||||||
|
WIIMOTE_DOWN,
|
||||||
|
WIIMOTE_LEFT,
|
||||||
|
WIIMOTE_RIGHT,
|
||||||
WIIMOTE_A,
|
WIIMOTE_A,
|
||||||
WIIMOTE_B,
|
WIIMOTE_B,
|
||||||
WIIMOTE_PLUS,
|
WIIMOTE_PLUS,
|
||||||
WIIMOTE_MINUS,
|
WIIMOTE_MINUS,
|
||||||
WIIMOTE_1,
|
WIIMOTE_1,
|
||||||
|
WIIMOTE_2,
|
||||||
|
CLASSIC_UP,
|
||||||
|
CLASSIC_DOWN,
|
||||||
|
CLASSIC_LEFT,
|
||||||
|
CLASSIC_RIGHT,
|
||||||
CLASSIC_X,
|
CLASSIC_X,
|
||||||
CLASSIC_Y,
|
CLASSIC_Y,
|
||||||
|
CLASSIC_A,
|
||||||
CLASSIC_B,
|
CLASSIC_B,
|
||||||
CLASSIC_L,
|
CLASSIC_L,
|
||||||
CLASSIC_R,
|
CLASSIC_R,
|
||||||
|
Loading…
Reference in New Issue
Block a user