SDL input: Replaced all the interface global vars by accessors

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@670 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-08-30 19:29:38 +00:00
parent 719d63deae
commit e1f05955e9
3 changed files with 124 additions and 74 deletions

View File

@ -546,127 +546,127 @@ void sdlReadPreferences(FILE *f)
} }
if(!strcmp(key,"Joy0_Left")) { if(!strcmp(key,"Joy0_Left")) {
joypad[0][KEY_LEFT] = sdlFromHex(value); inputSetKeymap(0, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Right")) { } else if(!strcmp(key, "Joy0_Right")) {
joypad[0][KEY_RIGHT] = sdlFromHex(value); inputSetKeymap(0, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Up")) { } else if(!strcmp(key, "Joy0_Up")) {
joypad[0][KEY_UP] = sdlFromHex(value); inputSetKeymap(0, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Down")) { } else if(!strcmp(key, "Joy0_Down")) {
joypad[0][KEY_DOWN] = sdlFromHex(value); inputSetKeymap(0, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_A")) { } else if(!strcmp(key, "Joy0_A")) {
joypad[0][KEY_BUTTON_A] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_B")) { } else if(!strcmp(key, "Joy0_B")) {
joypad[0][KEY_BUTTON_B] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_L")) { } else if(!strcmp(key, "Joy0_L")) {
joypad[0][KEY_BUTTON_L] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_R")) { } else if(!strcmp(key, "Joy0_R")) {
joypad[0][KEY_BUTTON_R] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Start")) { } else if(!strcmp(key, "Joy0_Start")) {
joypad[0][KEY_BUTTON_START] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Select")) { } else if(!strcmp(key, "Joy0_Select")) {
joypad[0][KEY_BUTTON_SELECT] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Speed")) { } else if(!strcmp(key, "Joy0_Speed")) {
joypad[0][KEY_BUTTON_SPEED] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_Capture")) { } else if(!strcmp(key, "Joy0_Capture")) {
joypad[0][KEY_BUTTON_CAPTURE] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy1_Left")) { } else if(!strcmp(key,"Joy1_Left")) {
joypad[1][KEY_LEFT] = sdlFromHex(value); inputSetKeymap(1, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Right")) { } else if(!strcmp(key, "Joy1_Right")) {
joypad[1][KEY_RIGHT] = sdlFromHex(value); inputSetKeymap(1, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Up")) { } else if(!strcmp(key, "Joy1_Up")) {
joypad[1][KEY_UP] = sdlFromHex(value); inputSetKeymap(1, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Down")) { } else if(!strcmp(key, "Joy1_Down")) {
joypad[1][KEY_DOWN] = sdlFromHex(value); inputSetKeymap(1, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_A")) { } else if(!strcmp(key, "Joy1_A")) {
joypad[1][KEY_BUTTON_A] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_B")) { } else if(!strcmp(key, "Joy1_B")) {
joypad[1][KEY_BUTTON_B] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_L")) { } else if(!strcmp(key, "Joy1_L")) {
joypad[1][KEY_BUTTON_L] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_R")) { } else if(!strcmp(key, "Joy1_R")) {
joypad[1][KEY_BUTTON_R] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Start")) { } else if(!strcmp(key, "Joy1_Start")) {
joypad[1][KEY_BUTTON_START] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Select")) { } else if(!strcmp(key, "Joy1_Select")) {
joypad[1][KEY_BUTTON_SELECT] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Speed")) { } else if(!strcmp(key, "Joy1_Speed")) {
joypad[1][KEY_BUTTON_SPEED] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_Capture")) { } else if(!strcmp(key, "Joy1_Capture")) {
joypad[1][KEY_BUTTON_CAPTURE] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy2_Left")) { } else if(!strcmp(key,"Joy2_Left")) {
joypad[2][KEY_LEFT] = sdlFromHex(value); inputSetKeymap(2, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Right")) { } else if(!strcmp(key, "Joy2_Right")) {
joypad[2][KEY_RIGHT] = sdlFromHex(value); inputSetKeymap(2, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Up")) { } else if(!strcmp(key, "Joy2_Up")) {
joypad[2][KEY_UP] = sdlFromHex(value); inputSetKeymap(2, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Down")) { } else if(!strcmp(key, "Joy2_Down")) {
joypad[2][KEY_DOWN] = sdlFromHex(value); inputSetKeymap(2, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_A")) { } else if(!strcmp(key, "Joy2_A")) {
joypad[2][KEY_BUTTON_A] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_B")) { } else if(!strcmp(key, "Joy2_B")) {
joypad[2][KEY_BUTTON_B] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_L")) { } else if(!strcmp(key, "Joy2_L")) {
joypad[2][KEY_BUTTON_L] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_R")) { } else if(!strcmp(key, "Joy2_R")) {
joypad[2][KEY_BUTTON_R] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Start")) { } else if(!strcmp(key, "Joy2_Start")) {
joypad[2][KEY_BUTTON_START] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Select")) { } else if(!strcmp(key, "Joy2_Select")) {
joypad[2][KEY_BUTTON_SELECT] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Speed")) { } else if(!strcmp(key, "Joy2_Speed")) {
joypad[2][KEY_BUTTON_SPEED] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_Capture")) { } else if(!strcmp(key, "Joy2_Capture")) {
joypad[2][KEY_BUTTON_CAPTURE] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key,"Joy3_Left")) { } else if(!strcmp(key,"Joy3_Left")) {
joypad[3][KEY_LEFT] = sdlFromHex(value); inputSetKeymap(3, KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Right")) { } else if(!strcmp(key, "Joy3_Right")) {
joypad[3][KEY_RIGHT] = sdlFromHex(value); inputSetKeymap(3, KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Up")) { } else if(!strcmp(key, "Joy3_Up")) {
joypad[3][KEY_UP] = sdlFromHex(value); inputSetKeymap(3, KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Down")) { } else if(!strcmp(key, "Joy3_Down")) {
joypad[3][KEY_DOWN] = sdlFromHex(value); inputSetKeymap(3, KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_A")) { } else if(!strcmp(key, "Joy3_A")) {
joypad[3][KEY_BUTTON_A] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_B")) { } else if(!strcmp(key, "Joy3_B")) {
joypad[3][KEY_BUTTON_B] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_L")) { } else if(!strcmp(key, "Joy3_L")) {
joypad[3][KEY_BUTTON_L] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_L, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_R")) { } else if(!strcmp(key, "Joy3_R")) {
joypad[3][KEY_BUTTON_R] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_R, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Start")) { } else if(!strcmp(key, "Joy3_Start")) {
joypad[3][KEY_BUTTON_START] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_START, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Select")) { } else if(!strcmp(key, "Joy3_Select")) {
joypad[3][KEY_BUTTON_SELECT] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_SELECT, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Speed")) { } else if(!strcmp(key, "Joy3_Speed")) {
joypad[3][KEY_BUTTON_SPEED] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_SPEED, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_Capture")) { } else if(!strcmp(key, "Joy3_Capture")) {
joypad[3][KEY_BUTTON_CAPTURE] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_CAPTURE, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_AutoA")) { } else if(!strcmp(key, "Joy0_AutoA")) {
joypad[0][KEY_BUTTON_AUTO_A] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy0_AutoB")) { } else if(!strcmp(key, "Joy0_AutoB")) {
joypad[0][KEY_BUTTON_AUTO_B] = sdlFromHex(value); inputSetKeymap(0, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_AutoA")) { } else if(!strcmp(key, "Joy1_AutoA")) {
joypad[1][KEY_BUTTON_AUTO_A] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy1_AutoB")) { } else if(!strcmp(key, "Joy1_AutoB")) {
joypad[1][KEY_BUTTON_AUTO_B] = sdlFromHex(value); inputSetKeymap(1, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_AutoA")) { } else if(!strcmp(key, "Joy2_AutoA")) {
joypad[2][KEY_BUTTON_AUTO_A] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy2_AutoB")) { } else if(!strcmp(key, "Joy2_AutoB")) {
joypad[2][KEY_BUTTON_AUTO_B] = sdlFromHex(value); inputSetKeymap(2, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_AutoA")) { } else if(!strcmp(key, "Joy3_AutoA")) {
joypad[3][KEY_BUTTON_AUTO_A] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_AUTO_A, sdlFromHex(value));
} else if(!strcmp(key, "Joy3_AutoB")) { } else if(!strcmp(key, "Joy3_AutoB")) {
joypad[3][KEY_BUTTON_AUTO_B] = sdlFromHex(value); inputSetKeymap(3, KEY_BUTTON_AUTO_B, sdlFromHex(value));
} else if(!strcmp(key, "openGL")) { } else if(!strcmp(key, "openGL")) {
openGL = sdlFromHex(value); openGL = sdlFromHex(value);
} else if(!strcmp(key, "Motion_Left")) { } else if(!strcmp(key, "Motion_Left")) {
motion[KEY_LEFT] = sdlFromHex(value); inputSetMotionKeymap(KEY_LEFT, sdlFromHex(value));
} else if(!strcmp(key, "Motion_Right")) { } else if(!strcmp(key, "Motion_Right")) {
motion[KEY_RIGHT] = sdlFromHex(value); inputSetMotionKeymap(KEY_RIGHT, sdlFromHex(value));
} else if(!strcmp(key, "Motion_Up")) { } else if(!strcmp(key, "Motion_Up")) {
motion[KEY_UP] = sdlFromHex(value); inputSetMotionKeymap(KEY_UP, sdlFromHex(value));
} else if(!strcmp(key, "Motion_Down")) { } else if(!strcmp(key, "Motion_Down")) {
motion[KEY_DOWN] = sdlFromHex(value); inputSetMotionKeymap(KEY_DOWN, sdlFromHex(value));
} else if(!strcmp(key, "frameSkip")) { } else if(!strcmp(key, "frameSkip")) {
frameSkip = sdlFromHex(value); frameSkip = sdlFromHex(value);
if(frameSkip < 0 || frameSkip > 9) if(frameSkip < 0 || frameSkip > 9)
@ -1529,15 +1529,21 @@ void sdlPollEvents()
"autofire B", "autofire B",
"autofire R", "autofire R",
"autofire L"}; "autofire L"};
int mask = 1 << (event.key.keysym.sym - SDLK_1);
if(event.key.keysym.sym > SDLK_2) EKey k = KEY_BUTTON_A;
mask <<= 6; if (event.key.keysym.sym == SDLK_1)
if(autoFire & mask) { k = KEY_BUTTON_A;
autoFire &= ~mask; else if (event.key.keysym.sym == SDLK_2)
systemScreenMessage(disableMessages[event.key.keysym.sym - SDLK_1]); k = KEY_BUTTON_B;
} else { else if (event.key.keysym.sym == SDLK_3)
autoFire |= mask; k = KEY_BUTTON_R;
else if (event.key.keysym.sym == SDLK_4)
k = KEY_BUTTON_L;
if(inputToggleAutoFire(k)) {
systemScreenMessage(enableMessages[event.key.keysym.sym - SDLK_1]); systemScreenMessage(enableMessages[event.key.keysym.sym - SDLK_1]);
} else {
systemScreenMessage(disableMessages[event.key.keysym.sym - SDLK_1]);
} }
} else if(!(event.key.keysym.mod & MOD_NOCTRL) && } else if(!(event.key.keysym.mod & MOD_NOCTRL) &&
(event.key.keysym.mod & KMOD_CTRL)) { (event.key.keysym.mod & KMOD_CTRL)) {

View File

@ -2,6 +2,8 @@
#include <SDL.h> #include <SDL.h>
#define SDLBUTTONS_NUM 14
bool sdlButtons[4][SDLBUTTONS_NUM] = { bool sdlButtons[4][SDLBUTTONS_NUM] = {
{ false, false, false, false, false, false, { false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false, false,
@ -66,6 +68,50 @@ u16 defaultMotion[4] = {
int sensorX = 2047; int sensorX = 2047;
int sensorY = 2047; int sensorY = 2047;
void inputSetKeymap(int joy, EKey key, u16 code)
{
joypad[joy][key] = code;
}
void inputSetMotionKeymap(EKey key, u16 code)
{
motion[key] = code;
}
bool inputToggleAutoFire(EKey key)
{
int mask = 0;
switch (key)
{
case KEY_BUTTON_A:
mask = 1 << 0;
break;
case KEY_BUTTON_B:
mask = 1 << 1;
break;
case KEY_BUTTON_R:
mask = 1 << 8;
break;
case KEY_BUTTON_L:
mask = 1 << 9;
break;
default:
break;
}
if(autoFire & mask)
{
autoFire &= ~mask;
return false;
}
else
{
autoFire |= mask;
return true;
}
}
void sdlUpdateKey(int key, bool down) void sdlUpdateKey(int key, bool down)
{ {
int i; int i;

View File

@ -3,9 +3,7 @@
#include "../System.h" #include "../System.h"
#define SDLBUTTONS_NUM 14 enum EKey {
enum {
KEY_LEFT, KEY_RIGHT, KEY_LEFT, KEY_RIGHT,
KEY_UP, KEY_DOWN, KEY_UP, KEY_DOWN,
KEY_BUTTON_A, KEY_BUTTON_B, KEY_BUTTON_A, KEY_BUTTON_B,
@ -15,9 +13,9 @@ enum {
KEY_BUTTON_AUTO_A, KEY_BUTTON_AUTO_B KEY_BUTTON_AUTO_A, KEY_BUTTON_AUTO_B
}; };
extern u16 joypad[4][SDLBUTTONS_NUM]; void inputSetKeymap(int joy, EKey key, u16 code);
extern u16 motion[4]; void inputSetMotionKeymap(EKey key, u16 code);
extern int autoFire; bool inputToggleAutoFire(EKey key);
void sdlUpdateKey(int key, bool down); void sdlUpdateKey(int key, bool down);
void sdlUpdateJoyButton(int which, int button, bool pressed); void sdlUpdateJoyButton(int which, int button, bool pressed);