From 16e047c8e9204675c8dfa97a552a9d1a6d24334b Mon Sep 17 00:00:00 2001 From: riccardom Date: Thu, 28 Jan 2010 16:19:20 +0000 Subject: [PATCH] Implement set_get_joy_key(), set_get_joy_axis() as wrapper around a get only version of the same. These will be used in the gtk frontend where we want to have the luxury of discarding changes. --- desmume/src/ctrlssdl.cpp | 24 +++++++++++++++++++----- desmume/src/ctrlssdl.h | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/desmume/src/ctrlssdl.cpp b/desmume/src/ctrlssdl.cpp index 38d711d66..4b5f77df2 100644 --- a/desmume/src/ctrlssdl.cpp +++ b/desmume/src/ctrlssdl.cpp @@ -196,8 +196,8 @@ static void clear_events( void) return; } -/* Get and set a new joystick key */ -u16 get_set_joy_key(int index) { +/* Get pressed joystick key */ +u16 get_joy_key(int index) { BOOL done = FALSE; SDL_Event event; u16 key = joypad_cfg[index]; @@ -220,11 +220,17 @@ u16 get_set_joy_key(int index) { if( SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE ) SDL_JoystickEventState(SDL_IGNORE); - joypad_cfg[index] = key; return key; } +/* Get and set a new joystick key */ +u16 get_set_joy_key(int index) { + joypad_cfg[index] = get_joy_key(index); + + return joypad_cfg[index]; +} + /* Reset corresponding key and its twin axis key */ static u16 get_joy_axis_twin(u16 key) { @@ -239,8 +245,8 @@ static u16 get_joy_axis_twin(u16 key) } } -/* Get and set a new joystick axis */ -void get_set_joy_axis(int index, int index_o) { +/* Get a new joystick axis */ +u16 get_joy_axis(int index, int index_o) { BOOL done = FALSE; SDL_Event event; u16 key = joypad_cfg[index]; @@ -267,6 +273,14 @@ void get_set_joy_axis(int index, int index_o) { } if( SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE ) SDL_JoystickEventState(SDL_IGNORE); + + return key; +} + +/* Get and set a new joystick axis */ +void get_set_joy_axis(int index, int index_o) { + u16 key = get_joy_axis(index, index_o); + /* Update configuration */ joypad_cfg[index] = key; joypad_cfg[index_o] = joypad_cfg[index]; diff --git a/desmume/src/ctrlssdl.h b/desmume/src/ctrlssdl.h index 4b57ab16c..516d64186 100644 --- a/desmume/src/ctrlssdl.h +++ b/desmume/src/ctrlssdl.h @@ -82,7 +82,9 @@ BOOL init_joy( void); void uninit_joy( void); void set_joy_keys(const u16 joyCfg[]); void set_kb_keys(const u16 kbCfg[]); +u16 get_joy_key(int index); u16 get_set_joy_key(int index); +u16 get_joy_axis(int index, int index_opp); void get_set_joy_axis(int index, int index_opp); void update_keypad(u16 keys); u16 get_keypad( void);