summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun Inman2021-03-13 00:18:13 -0500
committerneonloop2021-03-13 16:45:40 +0000
commite7746f9d5668e275bc838d71c2445c7490deb9df (patch)
treeff96b4131af1758c5cb214e7cf002f78957909aa
parent6c76f136e5c0793dbb3d716b51cfccd4b1e21cdf (diff)
downloadsnes9x2002-e7746f9d5668e275bc838d71c2445c7490deb9df.tar.gz
snes9x2002-e7746f9d5668e275bc838d71c2445c7490deb9df.tar.bz2
snes9x2002-e7746f9d5668e275bc838d71c2445c7490deb9df.zip
changed input from polling to event-based
to prevent menu input from reaching the game
-rw-r--r--shell/input/sdl/input.c110
1 files changed, 66 insertions, 44 deletions
diff --git a/shell/input/sdl/input.c b/shell/input/sdl/input.c
index efc44ac..bf6cff5 100644
--- a/shell/input/sdl/input.c
+++ b/shell/input/sdl/input.c
@@ -22,11 +22,7 @@ uint8_t *keystate;
uint8_t exit_snes = 0;
extern uint32_t emulator_state;
-#define CASE(realkey, key) \
- if (keystate[realkey]) \
- joypad |= key; \
- else \
- joypad &= ~key; \
+static uint32_t joypad = 0;
uint32_t S9xReadJoypad(int32_t port)
{
@@ -47,54 +43,80 @@ uint32_t S9xReadJoypad(int32_t port)
SNES_TR_MASK
};
- int32_t i;
- uint32_t joypad = 0;
-
// Only 1P is supported
if (port > 0) return joypad;
- keystate = SDL_GetKeyState(NULL);
-
while (SDL_PollEvent(&event))
{
switch (event.type)
{
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case BTN_MENU:
- case BTN_L2:
- emulator_state = 1;
- break;
- default:
- break;
- }
- break;
- case SDL_KEYUP:
- switch(event.key.keysym.sym)
- {
- case BTN_HOME:
- emulator_state = 1;
- break;
- default:
- break;
- }
- break;
+ case SDL_KEYDOWN: {
+ SDLKey key = event.key.keysym.sym;
+
+ if (key==BTN_MENU)
+ emulator_state = 1;
+
+ if (key==option.config_buttons[0][0])
+ joypad |= SNES_UP_MASK;
+ if (key==option.config_buttons[0][1])
+ joypad |= SNES_RIGHT_MASK;
+ if (key==option.config_buttons[0][2])
+ joypad |= SNES_DOWN_MASK;
+ if (key==option.config_buttons[0][3])
+ joypad |= SNES_LEFT_MASK;
+
+ if (key==option.config_buttons[0][4])
+ joypad |= SNES_A_MASK;
+ if (key==option.config_buttons[0][5])
+ joypad |= SNES_B_MASK;
+ if (key==option.config_buttons[0][6])
+ joypad |= SNES_X_MASK;
+ if (key==option.config_buttons[0][7])
+ joypad |= SNES_Y_MASK;
+ if (key==option.config_buttons[0][8])
+ joypad |= SNES_TL_MASK;
+ if (key==option.config_buttons[0][9])
+ joypad |= SNES_TR_MASK;
+
+ if (key==option.config_buttons[0][10])
+ joypad |= SNES_START_MASK;
+ if (key==option.config_buttons[0][11])
+ joypad |= SNES_SELECT_MASK;
+ } break;
+
+
+ case SDL_KEYUP: {
+ SDLKey key = event.key.keysym.sym;
+
+ if (key==option.config_buttons[0][0])
+ joypad &= ~SNES_UP_MASK;
+ if (key==option.config_buttons[0][1])
+ joypad &= ~SNES_RIGHT_MASK;
+ if (key==option.config_buttons[0][2])
+ joypad &= ~SNES_DOWN_MASK;
+ if (key==option.config_buttons[0][3])
+ joypad &= ~SNES_LEFT_MASK;
+
+ if (key==option.config_buttons[0][4])
+ joypad &= ~SNES_A_MASK;
+ if (key==option.config_buttons[0][5])
+ joypad &= ~SNES_B_MASK;
+ if (key==option.config_buttons[0][6])
+ joypad &= ~SNES_X_MASK;
+ if (key==option.config_buttons[0][7])
+ joypad &= ~SNES_Y_MASK;
+ if (key==option.config_buttons[0][8])
+ joypad &= ~SNES_TL_MASK;
+ if (key==option.config_buttons[0][9])
+ joypad &= ~SNES_TR_MASK;
+
+ if (key==option.config_buttons[0][10])
+ joypad &= ~SNES_START_MASK;
+ if (key==option.config_buttons[0][11])
+ joypad &= ~SNES_SELECT_MASK;
+ } break;
}
}
- CASE(option.config_buttons[0][10], SNES_START_MASK);
- CASE(option.config_buttons[0][11], SNES_SELECT_MASK);
- CASE(option.config_buttons[0][4], SNES_A_MASK);
- CASE(option.config_buttons[0][5], SNES_B_MASK);
- CASE(option.config_buttons[0][6], SNES_X_MASK);
- CASE(option.config_buttons[0][7], SNES_Y_MASK);
- CASE(option.config_buttons[0][8], SNES_TL_MASK);
- CASE(option.config_buttons[0][9], SNES_TR_MASK);
- CASE(option.config_buttons[0][0], SNES_UP_MASK);
- CASE(option.config_buttons[0][1], SNES_RIGHT_MASK);
- CASE(option.config_buttons[0][2], SNES_DOWN_MASK);
- CASE(option.config_buttons[0][3], SNES_LEFT_MASK);
-
return joypad;
}