all repos — mgba @ 9085bbb8a4f0c40bbc4965bb2cf89343e940551a

mGBA Game Boy Advance Emulator

SDL: Add rumble PWM support
Jeffrey Pfau jeffrey@endrift.com
Thu, 21 May 2015 22:31:26 -0700
commit

9085bbb8a4f0c40bbc4965bb2cf89343e940551a

parent

c6c57273b56df6aef0e5fda0c64cd85134a642fd

3 files changed, 18 insertions(+), 2 deletions(-)

jump to
M CHANGESCHANGES

@@ -16,6 +16,7 @@ - Status messages for actions taken while a game is running (e.g. save/load state)

- Memory inspector - Screensaver can now be suspended while a game is running - Load/save the most recent savestate slot + - Support varible speed (PWM) rumble Bugfixes: - ARM7: Fix SWI and IRQ timings - GBA Audio: Force audio FIFOs to 32-bit
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -22,8 +22,11 @@ #define GUI_MOD KMOD_CTRL

#endif #define GYRO_STEPS 100 +#define RUMBLE_PWM 35 +#if SDL_VERSION_ATLEAST(2, 0, 0) static void _GBASDLSetRumble(struct GBARumble* rumble, int enable); +#endif static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble); static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble); static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble);

@@ -154,6 +157,8 @@ player->joystickIndex = SIZE_MAX;

#if SDL_VERSION_ATLEAST(2, 0, 0) player->rumble.d.setRumble = _GBASDLSetRumble; + CircleBufferInit(&player->rumble.history, RUMBLE_PWM); + player->rumble.level = 0; player->rumble.p = player; #endif

@@ -531,8 +536,15 @@ struct GBASDLRumble* sdlRumble = (struct GBASDLRumble*) rumble;

if (!sdlRumble->p->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->haptic)) { return; } - if (enable) { - SDL_HapticRumblePlay(sdlRumble->p->haptic, 1.0f, 20); + sdlRumble->level += enable; + if (CircleBufferSize(&sdlRumble->history) == RUMBLE_PWM) { + int8_t oldLevel; + CircleBufferRead8(&sdlRumble->history, &oldLevel); + sdlRumble->level -= oldLevel; + } + CircleBufferWrite8(&sdlRumble->history, enable); + if (sdlRumble->level) { + SDL_HapticRumblePlay(sdlRumble->p->haptic, sdlRumble->level / (float) RUMBLE_PWM, 20); } else { SDL_HapticRumbleStop(sdlRumble->p->haptic); }
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -48,6 +48,9 @@

struct GBASDLRumble { struct GBARumble d; struct GBASDLPlayer* p; + + int level; + struct CircleBuffer history; } rumble; #endif