-
Notifications
You must be signed in to change notification settings - Fork 42
/
2063_sdlui.c
51 lines (47 loc) · 1.38 KB
/
2063_sdlui.c
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
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
#define WITH_SDL
#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
};
void ui_event(void)
{
SDL_Event ev;
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;
case SDL_QUIT:
emulator_done = 1;
break;
}
}
}