commit 847b3f2b56afed2b6207b78ec5ce3e43a712255d
parent 344c5c99040206b0f06d0a34a77569956c622315
Author: Lior Stern <liorst4@gmail.com>
Date: Wed, 12 Apr 2023 13:48:52 +0300
uxnemu: Add dpad support
More info about joyhats in SDL2:
https://wiki.libsdl.org/SDL2/SDL_JoyHatEvent
Diffstat:
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git 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);