From 197a475fab5e083c21b70995ffb3ef1ddd9b6721 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 10 Jun 2022 14:37:28 +0300 Subject: [PATCH] SDL Joypad controls for MBC7 games --- SDL/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SDL/main.c b/SDL/main.c index d73d667..aa95a07 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -272,9 +272,14 @@ static void handle_events(GB_gameboy_t *gb) case SDL_JOYAXISMOTION: { static bool axis_active[2] = {false, false}; + static double accel_values[2] = {0, 0}; joypad_axis_t axis = get_joypad_axis(event.jaxis.axis); if (axis == JOYPAD_AXISES_X) { - if (event.jaxis.value > JOYSTICK_HIGH) { + if (GB_has_accelerometer(gb)) { + accel_values[0] = event.jaxis.value / (double)32768.0; + GB_set_accelerometer_values(gb, -accel_values[0], -accel_values[1]); + } + else if (event.jaxis.value > JOYSTICK_HIGH) { axis_active[0] = true; GB_set_key_state(gb, GB_KEY_RIGHT, true); GB_set_key_state(gb, GB_KEY_LEFT, false); @@ -291,7 +296,11 @@ static void handle_events(GB_gameboy_t *gb) } } else if (axis == JOYPAD_AXISES_Y) { - if (event.jaxis.value > JOYSTICK_HIGH) { + if (GB_has_accelerometer(gb)) { + accel_values[1] = event.jaxis.value / (double)32768.0; + GB_set_accelerometer_values(gb, -accel_values[0], -accel_values[1]); + } + else if (event.jaxis.value > JOYSTICK_HIGH) { axis_active[1] = true; GB_set_key_state(gb, GB_KEY_DOWN, true); GB_set_key_state(gb, GB_KEY_UP, false);