Merge branch 'master' of https://github.com/LIJI32/SameBoy
This commit is contained in:
commit
8f892ab798
17
SDL/gui.c
17
SDL/gui.c
@ -729,6 +729,23 @@ void run_gui(bool is_running)
|
||||
else if (event.jbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) event.key.keysym.scancode = SDL_SCANCODE_LEFT;
|
||||
else if (event.jbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) event.key.keysym.scancode = SDL_SCANCODE_RIGHT;
|
||||
break;
|
||||
|
||||
case SDL_JOYHATMOTION: {
|
||||
uint8_t value = event.jhat.value;
|
||||
if (value != 0) {
|
||||
uint32_t scancode =
|
||||
value == SDL_HAT_UP ? SDL_SCANCODE_UP
|
||||
: value == SDL_HAT_DOWN ? SDL_SCANCODE_DOWN
|
||||
: value == SDL_HAT_LEFT ? SDL_SCANCODE_LEFT
|
||||
: value == SDL_HAT_RIGHT ? SDL_SCANCODE_RIGHT
|
||||
: 0;
|
||||
|
||||
if (scancode != 0) {
|
||||
event.type = SDL_KEYDOWN;
|
||||
event.key.keysym.scancode = scancode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case SDL_JOYAXISMOTION: {
|
||||
static bool axis_active[2] = {false, false};
|
||||
|
15
SDL/main.c
15
SDL/main.c
@ -165,6 +165,21 @@ static void handle_events(GB_gameboy_t *gb)
|
||||
GB_set_key_state(gb, GB_KEY_LEFT, event.jaxis.value < -0x4000);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
uint8_t value = event.jhat.value;
|
||||
int8_t updown =
|
||||
value == SDL_HAT_LEFTUP || value == SDL_HAT_UP || value == SDL_HAT_RIGHTUP ? -1 : (value == SDL_HAT_LEFTDOWN || value == SDL_HAT_DOWN || value == SDL_HAT_RIGHTDOWN ? 1 : 0);
|
||||
int8_t leftright =
|
||||
value == SDL_HAT_LEFTUP || value == SDL_HAT_LEFT || value == SDL_HAT_LEFTDOWN ? -1 : (value == SDL_HAT_RIGHTUP || value == SDL_HAT_RIGHT || value == SDL_HAT_RIGHTDOWN ? 1 : 0);
|
||||
|
||||
GB_set_key_state(gb, GB_KEY_LEFT, leftright == -1);
|
||||
GB_set_key_state(gb, GB_KEY_RIGHT, leftright == 1);
|
||||
GB_set_key_state(gb, GB_KEY_UP, updown == -1);
|
||||
GB_set_key_state(gb, GB_KEY_DOWN, updown == 1);
|
||||
break;
|
||||
};
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.scancode) {
|
||||
|
Loading…
Reference in New Issue
Block a user