This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy path2063_sdl2.c
More file actions
55 lines (50 loc) · 1.43 KB
/
Copy path2063_sdl2.c
File metadata and controls
55 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
#define WITH_SDL
#include "event.h"
#include "system.h"
#include "joystick.h"
static const uint8_t button_map[SDL_CONTROLLER_BUTTON_MAX] = {
1 << 0, // SDL_CONTROLLER_BUTTON_A
1 << 4, // SDL_CONTROLLER_BUTTON_B
0, // SDL_CONTROLLER_BUTTON_X
0, // SDL_CONTROLLER_BUTTON_Y
0, // SDL_CONTROLLER_BUTTON_BACK
0, // SDL_CONTROLLER_BUTTON_GUIDE
0, // SDL_CONTROLLER_BUTTON_START
0, // SDL_CONTROLLER_BUTTON_LEFTSTICK
0, // SDL_CONTROLLER_BUTTON_RIGHTSTICK
0, // SDL_CONTROLLER_BUTTON_LEFTSHOULDER
0, // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
1 << 7, // SDL_CONTROLLER_BUTTON_DPAD_UP
1 << 6, // SDL_CONTROLLER_BUTTON_DPAD_DOWN
1 << 2, // SDL_CONTROLLER_BUTTON_DPAD_LEFT
1 << 5, // SDL_CONTROLLER_BUTTON_DPAD_RIGHT
};
static int js2063_event(void *dev, void *evp)
{
SDL_Event *ev = evp;
while (SDL_PollEvent(ev)) {
switch(ev->type) {
case SDL_JOYDEVICEADDED:
joystick_add(ev->jdevice.which);
break;
case SDL_JOYDEVICEREMOVED:
joystick_remove(ev->jdevice.which);
break;
case SDL_CONTROLLERBUTTONDOWN:
joystick_button_down(ev->cbutton.which, ev->cbutton.button, button_map);
break;
case SDL_CONTROLLERBUTTONUP:
joystick_button_up(ev->cbutton.which, ev->cbutton.button, button_map);
break;
}
}
return 0;
}
void js2063_add_events(void)
{
add_ui_handler(js2063_event, NULL);
}