Joystick handling for the menu and the wii. Untested and unfinished.

This commit is contained in:
simon.kagstrom 2010-02-23 20:45:29 +00:00
parent 341c31bfd1
commit 56f1d9c22d
5 changed files with 67 additions and 33 deletions

View File

@ -869,17 +869,13 @@ uint8 C64::poll_joystick_buttons(int port)
for (i = 0; i < SDL_JoystickNumButtons (js); i++) {
bool cur = SDL_JoystickGetButton (js, i) ? true : false;
int kc = ThePrefs.JoystickButtons[i];
event_t ev = (event_t)ThePrefs.MenuJoystickButtons[i];
this->joy_button_pressed[i] = cur;
Gui::gui->pushEvent(ev);
if (kc == JOY_NONE)
continue;
else if (kc == JOY_FIRE)
Gui::gui->pushEvent(KEY_SELECT);
else if (kc == JOY_ENTER_MENU)
Gui::gui->activate();
else
Gui::gui->pushEvent(KEY_ESCAPE);
TheDisplay->UpdateKeyMatrix(kc, !cur,
TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &out);

View File

@ -25,6 +25,7 @@
#include "Display.h"
#include "C64.h"
#include "main.h"
#include "gui/widget.hh"
// These are the active preferences
@ -112,10 +113,17 @@ void Prefs::SetupJoystickDefaults()
{
for (int i = 0; i < MAX_JOYSTICK_AXES; i++)
this->JoystickAxes[i] = JOY_NONE;
for (int i = 0; i < MAX_JOYSTICK_HATS; i++)
this->JoystickHats[i] = JOY_NONE;
{
this->JoystickHats[i] = HAT_PLAIN;
this->MenuJoystickHats[i] = HAT_PLAIN;
}
for (int i = 0; i < MAX_JOYSTICK_BUTTONS; i++)
{
this->JoystickButtons[i] = JOY_NONE;
this->MenuJoystickButtons[i] = EVENT_NONE;
}
if (SDL_NumJoysticks() > 0)
{
@ -124,10 +132,8 @@ void Prefs::SetupJoystickDefaults()
if (strncmp(name, "Wiimote", 7) == 0)
{
/* Wiimote/Classic hat */
this->JoystickHats[0] = 0x41; /* Up */
this->JoystickHats[1] = 0x42; /* Down */
this->JoystickHats[2] = 0x44; /* Left */
this->JoystickHats[3] = 0x48; /* Right */
this->JoystickHats[0] = HAT_ROTATED_90;
this->MenuJoystickHats[0] = HAT_ROTATED_90;
/* Nunchuk/classic analogue */
this->JoystickAxes[0] = JOY_HORIZ;
@ -140,24 +146,33 @@ void Prefs::SetupJoystickDefaults()
this->JoystickButtons[7] = 0x50;
this->JoystickButtons[9] = 0x50;
this->JoystickButtons[10] = 0x50;
this->MenuJoystickButtons[3] = KEY_SELECT;
this->MenuJoystickButtons[7] = KEY_SELECT;
this->MenuJoystickButtons[9] = KEY_SELECT;
this->MenuJoystickButtons[10] = KEY_SELECT;
/* Wiimote A, Classic Zr, Zl as space */
this->JoystickButtons[0] = (7 << 3) | 4;
this->JoystickButtons[15] = (7 << 3) | 4;
this->JoystickButtons[16] = (7 << 3) | 4;
/* Wiimote B, classic x, y as R/S (escape in the menu) */
/* Wiimote B, classic x, y as R/S and menu escape */
this->JoystickButtons[1] = (7 << 3) | 7;
this->JoystickButtons[11] = (7 << 3) | 7;
this->JoystickButtons[12] = (7 << 3) | 7;
this->MenuJoystickButtons[1] = KEY_ESCAPE;
this->MenuJoystickButtons[11] = KEY_ESCAPE;
this->MenuJoystickButtons[12] = KEY_ESCAPE;
/* Wiimote, classic Home as enter menu */
this->JoystickButtons[6] = JOY_ENTER_MENU;
this->JoystickButtons[19] = JOY_ENTER_MENU;
this->MenuJoystickButtons[6] = ENTER_MENU;
this->MenuJoystickButtons[19] = ENTER_MENU;
}
/* Saitek P380 */
else if (strcmp(name, "Jess Tech Dual Analog Pad") == 0)
{
/* Hat is plain */
/* Pad */
this->JoystickHats[0] = 0x41; /* Up */
this->JoystickHats[1] = 0x42; /* Down */
@ -203,11 +218,15 @@ bool Prefs::operator==(const Prefs &rhs) const
{
if (this->JoystickHats[i] != rhs.JoystickHats[i])
return false;
if (this->MenuJoystickHats[i] != rhs.MenuJoystickHats[i])
return false;
}
for (int i = 0; i < MAX_JOYSTICK_BUTTONS; i++)
{
if (this->JoystickButtons[i] != rhs.JoystickButtons[i])
return false;
if (this->MenuJoystickButtons[i] != rhs.MenuJoystickButtons[i])
return false;
}
return (1
@ -414,6 +433,20 @@ void Prefs::Load(const char *filename)
if (n >= 0 && n < MAX_JOYSTICK_BUTTONS)
this->JoystickButtons[n] = atoi(value);
}
else if (!strncmp(keyword, "MenuJoystickHats", strlen("MenuJoystickHats")))
{
int n = atoi(keyword + strlen("MenuJoystickHats"));
if (n >= 0 && n < MAX_JOYSTICK_HATS)
this->MenuJoystickHats[n] = atoi(value);
}
else if (!strncmp(keyword, "MenuJoystickButtons", strlen("MenuJoystickButtons")))
{
int n = atoi(keyword + strlen("MenuJoystickButtons"));
if (n >= 0 && n < MAX_JOYSTICK_BUTTONS)
this->MenuJoystickButtons[n] = atoi(value);
}
else if (!strcmp(keyword, "DisplayOption"))
DisplayOption = atoi(value);
else if (!strcmp(keyword, "MsPerFrame"))
@ -519,9 +552,15 @@ bool Prefs::Save(const char *filename)
for (int i = 0; i < MAX_JOYSTICK_AXES; i++)
fprintf(file, "JoystickAxes%d = %d\n", i, JoystickAxes[i]);
for (int i = 0; i < MAX_JOYSTICK_HATS; i++)
{
fprintf(file, "JoystickHats%d = %d\n", i, JoystickHats[i]);
fprintf(file, "MenuJoystickHats%d = %d\n", i, MenuJoystickHats[i]);
}
for (int i = 0; i < MAX_JOYSTICK_BUTTONS; i++)
{
fprintf(file, "JoystickButtons%d = %d\n", i, JoystickButtons[i]);
fprintf(file, "MenuJoystickButtons%d = %d\n", i, MenuJoystickButtons[i]);
}
fprintf(file, "DisplayOption = %d\n", DisplayOption);
fprintf(file, "MsPerFrame = %d\n", MsPerFrame);
@ -537,20 +576,3 @@ bool Prefs::Save(const char *filename)
}
return false;
}
#ifdef __BEOS__
#include "Prefs_Be.h"
#endif
#ifdef AMIGA
#include "Prefs_Amiga.h"
#endif
#ifdef WIN32
#include "Prefs_WIN32.h"
#endif
#ifdef HAVE_GLADE
#include "Prefs_glade.h"
#endif

View File

@ -25,7 +25,7 @@
#define SPEED_100 20
#define SPEED_110 18
#define MAX_JOYSTICK_AXES 32
#define MAX_JOYSTICK_AXES 16
#define MAX_JOYSTICK_BUTTONS 32
#define MAX_JOYSTICK_HATS 8
@ -58,7 +58,13 @@ enum {
JOY_HORIZ = 256,
JOY_VERT = 258,
JOY_FIRE = 259,
JOY_ENTER_MENU = 260,
};
enum {
HAT_PLAIN = 0,
HAT_ROTATED_90 = 1,
HAT_ROTATED_180 = 2,
HAT_ROTATED_270 = 2,
};
// Key bindings (WII)
@ -176,6 +182,9 @@ private:
int JoystickHats[MAX_JOYSTICK_HATS];
int JoystickButtons[MAX_JOYSTICK_BUTTONS];
int MenuJoystickHats[MAX_JOYSTICK_HATS];
int MenuJoystickButtons[MAX_JOYSTICK_BUTTONS];
char NetworkName[32];
char NetworkServer[64];
int NetworkRegion;

View File

@ -335,6 +335,12 @@ void Gui::pushEvent(event_t ev)
{
GuiView *cur_view = this->peekView();
if (ev == KEY_ENTER_MENU)
{
this->activate();
return;
}
if (!this->is_active || !cur_view)
{
if (this->kbd)

View File

@ -14,6 +14,7 @@ enum key_event {
KEY_PAGEDOWN = (1 << 15),
KEY_PAGEUP = (1 << 16),
KEY_HELP = (1 << 17),
KEY_ENTER_MENU = (1 << 18),
};
typedef enum key_event event_t;