From 4e454fcb866d2f837c2ef1e112b2ab0fac68ae1f Mon Sep 17 00:00:00 2001 From: bgk Date: Sat, 30 Aug 2008 17:50:51 +0000 Subject: [PATCH] SDL: Started factoring out the input code to a new file. Only moved code at this point. The ultimate goal is to reuse this code for the GTK port. --- CMakeLists.txt | 1 + src/sdl/SDL.cpp | 428 +------------------------------------------ src/sdl/inputSDL.cpp | 421 ++++++++++++++++++++++++++++++++++++++++++ src/sdl/inputSDL.h | 28 +++ 4 files changed, 451 insertions(+), 427 deletions(-) create mode 100644 src/sdl/inputSDL.cpp create mode 100644 src/sdl/inputSDL.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d0276959..89ef1c7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,7 @@ SET(SRC_SDL src/sdl/dummy.cpp src/sdl/filters.cpp src/sdl/text.cpp + src/sdl/inputSDL.cpp src/sdl/sndSDL.cpp src/sdl/expr.cpp src/sdl/exprNode.cpp diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index dbe5c2ac..456507fa 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -51,6 +51,7 @@ #include "debugger.h" #include "filters.h" #include "text.h" +#include "inputSDL.h" #ifndef _WIN32 # include @@ -122,9 +123,6 @@ int destHeight = 0; int desktopWidth = 0; int desktopHeight = 0; -int sensorX = 2047; -int sensorY = 2047; - Filter filter = kStretch2x; u8 *delta = NULL; @@ -197,31 +195,6 @@ char * (sdl_ips_names[IPS_MAX_NUM]) = { NULL }; // and so on #define _stricmp strcasecmp -#define SDLBUTTONS_NUM 14 - -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, false, false, - false, false - }, - { false, false, false, false, false, false, - false, false, false, false, false, false, - false, false - }, - { false, false, false, false, false, false, - false, false, false, false, false, false, - false, false - } -}; - -bool sdlMotionButtons[4] = { false, false, false, false }; - -int sdlNumDevices = 0; -SDL_Joystick **sdlDevices = NULL; bool wasPaused = false; int autoFrameSkip = 0; int frameskipadjust = 0; @@ -245,8 +218,6 @@ int sdlRtcEnable = 0; int sdlAgbPrint = 0; int sdlMirroringEnable = 0; -int sdlDefaultJoypad = 0; - static int ignore_first_resize_event = 0; /* forward */ @@ -257,8 +228,6 @@ void (*dbgSignal)(int,int) = debuggerSignal; void (*dbgOutput)(const char *, u32) = debuggerOutput; int mouseCounter = 0; -int autoFire = 0; -bool autoFireToggle = false; bool screenMessage = false; char screenMessageBuffer[21]; @@ -266,48 +235,6 @@ u32 screenMessageTime = 0; char *arg0; -enum { - KEY_LEFT, KEY_RIGHT, - KEY_UP, KEY_DOWN, - KEY_BUTTON_A, KEY_BUTTON_B, - KEY_BUTTON_START, KEY_BUTTON_SELECT, - KEY_BUTTON_L, KEY_BUTTON_R, - KEY_BUTTON_SPEED, KEY_BUTTON_CAPTURE, - KEY_BUTTON_AUTO_A, KEY_BUTTON_AUTO_B -}; - -u16 joypad[4][SDLBUTTONS_NUM] = { - { SDLK_LEFT, SDLK_RIGHT, - SDLK_UP, SDLK_DOWN, - SDLK_z, SDLK_x, - SDLK_RETURN,SDLK_BACKSPACE, - SDLK_a, SDLK_s, - SDLK_SPACE, SDLK_F12, - SDLK_q, SDLK_w, - }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } -}; - -u16 defaultJoypad[SDLBUTTONS_NUM] = { - SDLK_LEFT, SDLK_RIGHT, - SDLK_UP, SDLK_DOWN, - SDLK_z, SDLK_x, - SDLK_RETURN,SDLK_BACKSPACE, - SDLK_a, SDLK_s, - SDLK_SPACE, SDLK_F12, - SDLK_q, SDLK_w -}; - -u16 motion[4] = { - SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2 -}; - -u16 defaultMotion[4] = { - SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2 -}; - int sdlPreparedCheats = 0; #define MAX_CHEATS 100 const char * sdlPreparedCheatCodes[MAX_CHEATS]; @@ -1251,242 +1178,6 @@ void sdlInitVideo() { #define MOD_NOALT (KMOD_CTRL|KMOD_SHIFT|KMOD_META) #define MOD_NOSHIFT (KMOD_CTRL|KMOD_ALT|KMOD_META) -void sdlUpdateKey(int key, bool down) -{ - int i; - for(int j = 0; j < 4; j++) { - for(i = 0 ; i < SDLBUTTONS_NUM; i++) { - if((joypad[j][i] & 0xf000) == 0) { - if(key == joypad[j][i]) - sdlButtons[j][i] = down; - } - } - } - for(i = 0 ; i < 4; i++) { - if((motion[i] & 0xf000) == 0) { - if(key == motion[i]) - sdlMotionButtons[i] = down; - } - } -} - -void sdlUpdateJoyButton(int which, - int button, - bool pressed) -{ - int i; - for(int j = 0; j < 4; j++) { - for(i = 0; i < SDLBUTTONS_NUM; i++) { - int dev = (joypad[j][i] >> 12); - int b = joypad[j][i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (b >= 128) && (b == (button+128))) { - sdlButtons[j][i] = pressed; - } - } - } - } - for(i = 0; i < 4; i++) { - int dev = (motion[i] >> 12); - int b = motion[i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (b >= 128) && (b == (button+128))) { - sdlMotionButtons[i] = pressed; - } - } - } -} - -void sdlUpdateJoyHat(int which, - int hat, - int value) -{ - int i; - for(int j = 0; j < 4; j++) { - for(i = 0; i < SDLBUTTONS_NUM; i++) { - int dev = (joypad[j][i] >> 12); - int a = joypad[j][i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) { - int dir = a & 3; - int v = 0; - switch(dir) { - case 0: - v = value & SDL_HAT_UP; - break; - case 1: - v = value & SDL_HAT_DOWN; - break; - case 2: - v = value & SDL_HAT_RIGHT; - break; - case 3: - v = value & SDL_HAT_LEFT; - break; - } - sdlButtons[j][i] = (v ? true : false); - } - } - } - } - for(i = 0; i < 4; i++) { - int dev = (motion[i] >> 12); - int a = motion[i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) { - int dir = a & 3; - int v = 0; - switch(dir) { - case 0: - v = value & SDL_HAT_UP; - break; - case 1: - v = value & SDL_HAT_DOWN; - break; - case 2: - v = value & SDL_HAT_RIGHT; - break; - case 3: - v = value & SDL_HAT_LEFT; - break; - } - sdlMotionButtons[i] = (v ? true : false); - } - } - } -} - -void sdlUpdateJoyAxis(int which, - int axis, - int value) -{ - int i; - for(int j = 0; j < 4; j++) { - for(i = 0; i < SDLBUTTONS_NUM; i++) { - int dev = (joypad[j][i] >> 12); - int a = joypad[j][i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (a < 32) && ((a>>1) == axis)) { - sdlButtons[j][i] = (a & 1) ? (value > 16384) : (value < -16384); - } - } - } - } - for(i = 0; i < 4; i++) { - int dev = (motion[i] >> 12); - int a = motion[i] & 0xfff; - if(dev) { - dev--; - - if((dev == which) && (a < 32) && ((a>>1) == axis)) { - sdlMotionButtons[i] = (a & 1) ? (value > 16384) : (value < -16384); - } - } - } -} - -bool sdlCheckJoyKey(int key) -{ - int dev = (key >> 12) - 1; - int what = key & 0xfff; - - if(what >= 128) { - // joystick button - int button = what - 128; - - if(button >= SDL_JoystickNumButtons(sdlDevices[dev])) - return false; - } else if (what < 0x20) { - // joystick axis - what >>= 1; - if(what >= SDL_JoystickNumAxes(sdlDevices[dev])) - return false; - } else if (what < 0x30) { - // joystick hat - what = (what & 15); - what >>= 2; - if(what >= SDL_JoystickNumHats(sdlDevices[dev])) - return false; - } - - // no problem found - return true; -} - -void sdlCheckKeys() -{ - sdlNumDevices = SDL_NumJoysticks(); - - if(sdlNumDevices) - sdlDevices = (SDL_Joystick **)calloc(1,sdlNumDevices * - sizeof(SDL_Joystick **)); - int i; - - bool usesJoy = false; - - for(int j = 0; j < 4; j++) { - for(i = 0; i < SDLBUTTONS_NUM; i++) { - int dev = joypad[j][i] >> 12; - if(dev) { - dev--; - bool ok = false; - - if(sdlDevices) { - if(dev < sdlNumDevices) { - if(sdlDevices[dev] == NULL) { - sdlDevices[dev] = SDL_JoystickOpen(dev); - } - - ok = sdlCheckJoyKey(joypad[j][i]); - } else - ok = false; - } - - if(!ok) - joypad[j][i] = defaultJoypad[i]; - else - usesJoy = true; - } - } - } - - for(i = 0; i < 4; i++) { - int dev = motion[i] >> 12; - if(dev) { - dev--; - bool ok = false; - - if(sdlDevices) { - if(dev < sdlNumDevices) { - if(sdlDevices[dev] == NULL) { - sdlDevices[dev] = SDL_JoystickOpen(dev); - } - - ok = sdlCheckJoyKey(motion[i]); - } else - ok = false; - } - - if(!ok) - motion[i] = defaultMotion[i]; - else - usesJoy = true; - } - } - - if(usesJoy) - SDL_JoystickEventState(SDL_ENABLE); -} /* * 04.02.2008 (xKiv): factored out from sdlPollEvents @@ -2726,66 +2417,6 @@ void systemDrawScreen() } -bool systemReadJoypads() -{ - return true; -} - -u32 systemReadJoypad(int which) -{ - int realAutoFire = autoFire; - - if(which < 0 || which > 3) - which = sdlDefaultJoypad; - - u32 res = 0; - - if(sdlButtons[which][KEY_BUTTON_A]) - res |= 1; - if(sdlButtons[which][KEY_BUTTON_B]) - res |= 2; - if(sdlButtons[which][KEY_BUTTON_SELECT]) - res |= 4; - if(sdlButtons[which][KEY_BUTTON_START]) - res |= 8; - if(sdlButtons[which][KEY_RIGHT]) - res |= 16; - if(sdlButtons[which][KEY_LEFT]) - res |= 32; - if(sdlButtons[which][KEY_UP]) - res |= 64; - if(sdlButtons[which][KEY_DOWN]) - res |= 128; - if(sdlButtons[which][KEY_BUTTON_R]) - res |= 256; - if(sdlButtons[which][KEY_BUTTON_L]) - res |= 512; - if(sdlButtons[which][KEY_BUTTON_AUTO_A]) - realAutoFire ^= 1; - if(sdlButtons[which][KEY_BUTTON_AUTO_B]) - realAutoFire ^= 2; - - // disallow L+R or U+D of being pressed at the same time - if((res & 48) == 48) - res &= ~16; - if((res & 192) == 192) - res &= ~128; - - if(sdlButtons[which][KEY_BUTTON_SPEED]) - res |= 1024; - if(sdlButtons[which][KEY_BUTTON_CAPTURE]) - res |= 2048; - - if(realAutoFire) { - res &= (~realAutoFire); - if(autoFireToggle) - res |= realAutoFire; - autoFireToggle = !autoFireToggle; - } - - return res; -} - void systemSetTitle(const char *title) { SDL_WM_SetCaption(title, NULL); @@ -2908,63 +2539,6 @@ u32 systemGetClock() return SDL_GetTicks(); } -void systemUpdateMotionSensor() -{ - if(sdlMotionButtons[KEY_LEFT]) { - sensorX += 3; - if(sensorX > 2197) - sensorX = 2197; - if(sensorX < 2047) - sensorX = 2057; - } else if(sdlMotionButtons[KEY_RIGHT]) { - sensorX -= 3; - if(sensorX < 1897) - sensorX = 1897; - if(sensorX > 2047) - sensorX = 2037; - } else if(sensorX > 2047) { - sensorX -= 2; - if(sensorX < 2047) - sensorX = 2047; - } else { - sensorX += 2; - if(sensorX > 2047) - sensorX = 2047; - } - - if(sdlMotionButtons[KEY_UP]) { - sensorY += 3; - if(sensorY > 2197) - sensorY = 2197; - if(sensorY < 2047) - sensorY = 2057; - } else if(sdlMotionButtons[KEY_DOWN]) { - sensorY -= 3; - if(sensorY < 1897) - sensorY = 1897; - if(sensorY > 2047) - sensorY = 2037; - } else if(sensorY > 2047) { - sensorY -= 2; - if(sensorY < 2047) - sensorY = 2047; - } else { - sensorY += 2; - if(sensorY > 2047) - sensorY = 2047; - } -} - -int systemGetSensorX() -{ - return sensorX; -} - -int systemGetSensorY() -{ - return sensorY; -} - void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast) { } diff --git a/src/sdl/inputSDL.cpp b/src/sdl/inputSDL.cpp new file mode 100644 index 00000000..564b6ee1 --- /dev/null +++ b/src/sdl/inputSDL.cpp @@ -0,0 +1,421 @@ +#include "inputSDL.h" + +#include + +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, false, false, + false, false + }, + { false, false, false, false, false, false, + false, false, false, false, false, false, + false, false + }, + { false, false, false, false, false, false, + false, false, false, false, false, false, + false, false + } +}; + +bool sdlMotionButtons[4] = { false, false, false, false }; + +int sdlNumDevices = 0; +SDL_Joystick **sdlDevices = NULL; + +int sdlDefaultJoypad = 0; + +int autoFire = 0; +bool autoFireToggle = false; + +u16 joypad[4][SDLBUTTONS_NUM] = { + { SDLK_LEFT, SDLK_RIGHT, + SDLK_UP, SDLK_DOWN, + SDLK_z, SDLK_x, + SDLK_RETURN,SDLK_BACKSPACE, + SDLK_a, SDLK_s, + SDLK_SPACE, SDLK_F12, + SDLK_q, SDLK_w, + }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +}; + +u16 defaultJoypad[SDLBUTTONS_NUM] = { + SDLK_LEFT, SDLK_RIGHT, + SDLK_UP, SDLK_DOWN, + SDLK_z, SDLK_x, + SDLK_RETURN,SDLK_BACKSPACE, + SDLK_a, SDLK_s, + SDLK_SPACE, SDLK_F12, + SDLK_q, SDLK_w +}; + +u16 motion[4] = { + SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2 +}; + +u16 defaultMotion[4] = { + SDLK_KP4, SDLK_KP6, SDLK_KP8, SDLK_KP2 +}; + +int sensorX = 2047; +int sensorY = 2047; + +void sdlUpdateKey(int key, bool down) +{ + int i; + for(int j = 0; j < 4; j++) { + for(i = 0 ; i < SDLBUTTONS_NUM; i++) { + if((joypad[j][i] & 0xf000) == 0) { + if(key == joypad[j][i]) + sdlButtons[j][i] = down; + } + } + } + for(i = 0 ; i < 4; i++) { + if((motion[i] & 0xf000) == 0) { + if(key == motion[i]) + sdlMotionButtons[i] = down; + } + } +} + +void sdlUpdateJoyButton(int which, + int button, + bool pressed) +{ + int i; + for(int j = 0; j < 4; j++) { + for(i = 0; i < SDLBUTTONS_NUM; i++) { + int dev = (joypad[j][i] >> 12); + int b = joypad[j][i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (b >= 128) && (b == (button+128))) { + sdlButtons[j][i] = pressed; + } + } + } + } + for(i = 0; i < 4; i++) { + int dev = (motion[i] >> 12); + int b = motion[i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (b >= 128) && (b == (button+128))) { + sdlMotionButtons[i] = pressed; + } + } + } +} + +void sdlUpdateJoyHat(int which, + int hat, + int value) +{ + int i; + for(int j = 0; j < 4; j++) { + for(i = 0; i < SDLBUTTONS_NUM; i++) { + int dev = (joypad[j][i] >> 12); + int a = joypad[j][i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) { + int dir = a & 3; + int v = 0; + switch(dir) { + case 0: + v = value & SDL_HAT_UP; + break; + case 1: + v = value & SDL_HAT_DOWN; + break; + case 2: + v = value & SDL_HAT_RIGHT; + break; + case 3: + v = value & SDL_HAT_LEFT; + break; + } + sdlButtons[j][i] = (v ? true : false); + } + } + } + } + for(i = 0; i < 4; i++) { + int dev = (motion[i] >> 12); + int a = motion[i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (a>=32) && (a < 48) && (((a&15)>>2) == hat)) { + int dir = a & 3; + int v = 0; + switch(dir) { + case 0: + v = value & SDL_HAT_UP; + break; + case 1: + v = value & SDL_HAT_DOWN; + break; + case 2: + v = value & SDL_HAT_RIGHT; + break; + case 3: + v = value & SDL_HAT_LEFT; + break; + } + sdlMotionButtons[i] = (v ? true : false); + } + } + } +} + +void sdlUpdateJoyAxis(int which, + int axis, + int value) +{ + int i; + for(int j = 0; j < 4; j++) { + for(i = 0; i < SDLBUTTONS_NUM; i++) { + int dev = (joypad[j][i] >> 12); + int a = joypad[j][i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (a < 32) && ((a>>1) == axis)) { + sdlButtons[j][i] = (a & 1) ? (value > 16384) : (value < -16384); + } + } + } + } + for(i = 0; i < 4; i++) { + int dev = (motion[i] >> 12); + int a = motion[i] & 0xfff; + if(dev) { + dev--; + + if((dev == which) && (a < 32) && ((a>>1) == axis)) { + sdlMotionButtons[i] = (a & 1) ? (value > 16384) : (value < -16384); + } + } + } +} + +bool sdlCheckJoyKey(int key) +{ + int dev = (key >> 12) - 1; + int what = key & 0xfff; + + if(what >= 128) { + // joystick button + int button = what - 128; + + if(button >= SDL_JoystickNumButtons(sdlDevices[dev])) + return false; + } else if (what < 0x20) { + // joystick axis + what >>= 1; + if(what >= SDL_JoystickNumAxes(sdlDevices[dev])) + return false; + } else if (what < 0x30) { + // joystick hat + what = (what & 15); + what >>= 2; + if(what >= SDL_JoystickNumHats(sdlDevices[dev])) + return false; + } + + // no problem found + return true; +} + +void sdlCheckKeys() +{ + sdlNumDevices = SDL_NumJoysticks(); + + if(sdlNumDevices) + sdlDevices = (SDL_Joystick **)calloc(1,sdlNumDevices * + sizeof(SDL_Joystick **)); + int i; + + bool usesJoy = false; + + for(int j = 0; j < 4; j++) { + for(i = 0; i < SDLBUTTONS_NUM; i++) { + int dev = joypad[j][i] >> 12; + if(dev) { + dev--; + bool ok = false; + + if(sdlDevices) { + if(dev < sdlNumDevices) { + if(sdlDevices[dev] == NULL) { + sdlDevices[dev] = SDL_JoystickOpen(dev); + } + + ok = sdlCheckJoyKey(joypad[j][i]); + } else + ok = false; + } + + if(!ok) + joypad[j][i] = defaultJoypad[i]; + else + usesJoy = true; + } + } + } + + for(i = 0; i < 4; i++) { + int dev = motion[i] >> 12; + if(dev) { + dev--; + bool ok = false; + + if(sdlDevices) { + if(dev < sdlNumDevices) { + if(sdlDevices[dev] == NULL) { + sdlDevices[dev] = SDL_JoystickOpen(dev); + } + + ok = sdlCheckJoyKey(motion[i]); + } else + ok = false; + } + + if(!ok) + motion[i] = defaultMotion[i]; + else + usesJoy = true; + } + } + + if(usesJoy) + SDL_JoystickEventState(SDL_ENABLE); +} + +bool systemReadJoypads() +{ + return true; +} + +u32 systemReadJoypad(int which) +{ + int realAutoFire = autoFire; + + if(which < 0 || which > 3) + which = sdlDefaultJoypad; + + u32 res = 0; + + if(sdlButtons[which][KEY_BUTTON_A]) + res |= 1; + if(sdlButtons[which][KEY_BUTTON_B]) + res |= 2; + if(sdlButtons[which][KEY_BUTTON_SELECT]) + res |= 4; + if(sdlButtons[which][KEY_BUTTON_START]) + res |= 8; + if(sdlButtons[which][KEY_RIGHT]) + res |= 16; + if(sdlButtons[which][KEY_LEFT]) + res |= 32; + if(sdlButtons[which][KEY_UP]) + res |= 64; + if(sdlButtons[which][KEY_DOWN]) + res |= 128; + if(sdlButtons[which][KEY_BUTTON_R]) + res |= 256; + if(sdlButtons[which][KEY_BUTTON_L]) + res |= 512; + if(sdlButtons[which][KEY_BUTTON_AUTO_A]) + realAutoFire ^= 1; + if(sdlButtons[which][KEY_BUTTON_AUTO_B]) + realAutoFire ^= 2; + + // disallow L+R or U+D of being pressed at the same time + if((res & 48) == 48) + res &= ~16; + if((res & 192) == 192) + res &= ~128; + + if(sdlButtons[which][KEY_BUTTON_SPEED]) + res |= 1024; + if(sdlButtons[which][KEY_BUTTON_CAPTURE]) + res |= 2048; + + if(realAutoFire) { + res &= (~realAutoFire); + if(autoFireToggle) + res |= realAutoFire; + autoFireToggle = !autoFireToggle; + } + + return res; +} + +void systemUpdateMotionSensor() +{ + if(sdlMotionButtons[KEY_LEFT]) { + sensorX += 3; + if(sensorX > 2197) + sensorX = 2197; + if(sensorX < 2047) + sensorX = 2057; + } else if(sdlMotionButtons[KEY_RIGHT]) { + sensorX -= 3; + if(sensorX < 1897) + sensorX = 1897; + if(sensorX > 2047) + sensorX = 2037; + } else if(sensorX > 2047) { + sensorX -= 2; + if(sensorX < 2047) + sensorX = 2047; + } else { + sensorX += 2; + if(sensorX > 2047) + sensorX = 2047; + } + + if(sdlMotionButtons[KEY_UP]) { + sensorY += 3; + if(sensorY > 2197) + sensorY = 2197; + if(sensorY < 2047) + sensorY = 2057; + } else if(sdlMotionButtons[KEY_DOWN]) { + sensorY -= 3; + if(sensorY < 1897) + sensorY = 1897; + if(sensorY > 2047) + sensorY = 2037; + } else if(sensorY > 2047) { + sensorY -= 2; + if(sensorY < 2047) + sensorY = 2047; + } else { + sensorY += 2; + if(sensorY > 2047) + sensorY = 2047; + } +} + +int systemGetSensorX() +{ + return sensorX; +} + +int systemGetSensorY() +{ + return sensorY; +} \ No newline at end of file diff --git a/src/sdl/inputSDL.h b/src/sdl/inputSDL.h new file mode 100644 index 00000000..cb64a826 --- /dev/null +++ b/src/sdl/inputSDL.h @@ -0,0 +1,28 @@ +#ifndef VBAM_INPUTSDL_FILTERS_H +#define VBAM_INPUTSDL_FILTERS_H + +#include "../System.h" + +#define SDLBUTTONS_NUM 14 + +enum { + KEY_LEFT, KEY_RIGHT, + KEY_UP, KEY_DOWN, + KEY_BUTTON_A, KEY_BUTTON_B, + KEY_BUTTON_START, KEY_BUTTON_SELECT, + KEY_BUTTON_L, KEY_BUTTON_R, + KEY_BUTTON_SPEED, KEY_BUTTON_CAPTURE, + KEY_BUTTON_AUTO_A, KEY_BUTTON_AUTO_B +}; + +extern u16 joypad[4][SDLBUTTONS_NUM]; +extern u16 motion[4]; +extern int autoFire; + +void sdlUpdateKey(int key, bool down); +void sdlUpdateJoyButton(int which, int button, bool pressed); +void sdlUpdateJoyHat(int which, int hat, int value); +void sdlUpdateJoyAxis(int which, int axis, int value); +void sdlCheckKeys(); + +#endif // VBAM_INPUTSDL_FILTERS_H \ No newline at end of file