This commit is contained in:
Themaister 2010-10-01 20:38:27 +02:00
parent f3d41c5aaa
commit 79b520a75c
2 changed files with 15 additions and 10 deletions

View File

@ -90,7 +90,7 @@ static const bool audio_enable = true;
static const unsigned out_rate = 48000; static const unsigned out_rate = 48000;
// Input samplerate from libSNES. // Input samplerate from libSNES.
// Lower this (slightly) if you are experiencing frequent audio dropouts and vsync is enabled. // Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled.
static const unsigned in_rate = 31950; static const unsigned in_rate = 31950;
// Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults. // Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults.
@ -114,6 +114,7 @@ static const bool audio_sync = true;
// To figure out which joypad buttons to use, check jstest or similar. // To figure out which joypad buttons to use, check jstest or similar.
// Player 1
static const struct snes_keybind snes_keybinds_1[] = { static const struct snes_keybind snes_keybinds_1[] = {
// SNES button | keyboard key | joypad button | // SNES button | keyboard key | joypad button |
{ SNES_DEVICE_ID_JOYPAD_A, 'X', 1 }, { SNES_DEVICE_ID_JOYPAD_A, 'X', 1 },
@ -132,6 +133,7 @@ static const struct snes_keybind snes_keybinds_1[] = {
{ -1 } { -1 }
}; };
// Player 2
static const struct snes_keybind snes_keybinds_2[] = { static const struct snes_keybind snes_keybinds_2[] = {
// SNES button | keyboard key | joypad button | // SNES button | keyboard key | joypad button |
{ SNES_DEVICE_ID_JOYPAD_A, 'B', 1 }, { SNES_DEVICE_ID_JOYPAD_A, 'B', 1 },
@ -140,14 +142,13 @@ static const struct snes_keybind snes_keybinds_2[] = {
{ SNES_DEVICE_ID_JOYPAD_Y, 'F', 2 }, { SNES_DEVICE_ID_JOYPAD_Y, 'F', 2 },
{ SNES_DEVICE_ID_JOYPAD_L, 'R', 4 }, { SNES_DEVICE_ID_JOYPAD_L, 'R', 4 },
{ SNES_DEVICE_ID_JOYPAD_R, 'T', 5 }, { SNES_DEVICE_ID_JOYPAD_R, 'T', 5 },
{ SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 12 }, { SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 12 },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 13 }, { SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 13 },
{ SNES_DEVICE_ID_JOYPAD_UP, 'I', 10 }, { SNES_DEVICE_ID_JOYPAD_UP, 'I', 10 },
{ SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 11 }, { SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 11 },
{ SNES_DEVICE_ID_JOYPAD_START, 'P', 6 }, { SNES_DEVICE_ID_JOYPAD_START, 'P', 6 },
{ SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 14 }, { SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 14 },
{ -1 } { -1 }
//{ SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 9 },
}; };
///// Save state ///// Save state

8
gl.c
View File

@ -42,6 +42,8 @@ static void glfw_input_poll(void *data)
glfwPollEvents(); glfwPollEvents();
} }
#define BUTTONS_MAX 128
static int joypad_id[2]; static int joypad_id[2];
static int joypad_buttons[2]; static int joypad_buttons[2];
static bool joypad_inited = false; static bool joypad_inited = false;
@ -51,12 +53,14 @@ static int init_joypads(int max_pads)
{ {
// Finds the first (two) joypads that are alive // Finds the first (two) joypads that are alive
int count = 0; int count = 0;
for ( int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST && count < max_pads; i++ ) for ( int i = GLFW_JOYSTICK_1; (i <= GLFW_JOYSTICK_LAST) && (count < max_pads); i++ )
{ {
if ( glfwGetJoystickParam(i, GLFW_PRESENT) == GL_TRUE ) if ( glfwGetJoystickParam(i, GLFW_PRESENT) == GL_TRUE )
{ {
joypad_id[count] = i; joypad_id[count] = i;
joypad_buttons[count] = glfwGetJoystickParam(i, GLFW_BUTTONS); joypad_buttons[count] = glfwGetJoystickParam(i, GLFW_BUTTONS);
if (joypad_buttons[count] > BUTTONS_MAX)
joypad_buttons[count] = BUTTONS_MAX;
count++; count++;
} }
} }
@ -74,7 +78,7 @@ static int16_t glfw_input_state(void *data, const struct snes_keybind **binds, b
joypad_count = init_joypads(2); joypad_count = init_joypads(2);
int port_num = port ? 1 : 0; int port_num = port ? 1 : 0;
unsigned char buttons[joypad_buttons[port_num]]; unsigned char buttons[BUTTONS_MAX];
if ( joypad_count > id ) if ( joypad_count > id )
glfwGetJoystickButtons(joypad_id[port_num], buttons, joypad_buttons[port_num]); glfwGetJoystickButtons(joypad_id[port_num], buttons, joypad_buttons[port_num]);