From 847b3f2b56afed2b6207b78ec5ce3e43a712255d Mon Sep 17 00:00:00 2001 From: Lior Stern Date: Wed, 12 Apr 2023 13:48:52 +0300 Subject: [PATCH] uxnemu: Add dpad support More info about joyhats in SDL2: https://wiki.libsdl.org/SDL2/SDL_JoyHatEvent --- src/uxnemu.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/uxnemu.c b/src/uxnemu.c index 958a336..2631d61 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -436,6 +436,42 @@ handle_events(Uxn *u) controller_down(u, &u->dev[0x80], get_button_joystick(&event)); else if(event.type == SDL_JOYBUTTONUP) controller_up(u, &u->dev[0x80], get_button_joystick(&event)); + else if(event.type == SDL_JOYHATMOTION) { + /* NOTE: Assuming there is only one joyhat in the controller */ + switch(event.jhat.value) { + case SDL_HAT_UP: + controller_down(u, &u->dev[0x80], 0x10); + break; + case SDL_HAT_DOWN: + controller_down(u, &u->dev[0x80], 0x20); + break; + case SDL_HAT_LEFT: + controller_down(u, &u->dev[0x80], 0x40); + break; + case SDL_HAT_RIGHT: + controller_down(u, &u->dev[0x80], 0x80); + break; + case SDL_HAT_LEFTDOWN: + controller_down(u, &u->dev[0x80], 0x40 | 0x20); + break; + case SDL_HAT_LEFTUP: + controller_down(u, &u->dev[0x80], 0x40 | 0x10); + break; + case SDL_HAT_RIGHTDOWN: + controller_down(u, &u->dev[0x80], 0x80 | 0x20); + break; + case SDL_HAT_RIGHTUP: + controller_down(u, &u->dev[0x80], 0x80 | 0x10); + break; + case SDL_HAT_CENTERED: + /* Set all directions to down */ + controller_up(u, &u->dev[0x80], 0x10 | 0x20 | 0x40 | 0x80); + break; + default: + /* Ignore */ + break; + } + } /* Console */ else if(event.type == stdin_event) console_input(u, event.cbutton.button);