From 4e5b6e6d6f45882f2b4c8998e94ae0837208d413 Mon Sep 17 00:00:00 2001 From: alvinwong Date: Wed, 26 Feb 2014 11:29:53 +0000 Subject: [PATCH] Linux (gtk, glade, cli): - Add control for Lid (defaults to Backspace). - Disallow Left+Right or Up+Down, acts like Windows port. - Show correct button state on HUD. --- desmume/src/cli/doc/desmume-cli.1 | 3 + desmume/src/cli/main.cpp | 3 +- desmume/src/ctrlssdl.cpp | 83 ++++++++++++++++++----- desmume/src/ctrlssdl.h | 3 +- desmume/src/gtk-glade/doc/desmume-glade.1 | 3 + desmume/src/gtk-glade/glade/DeSmuMe.glade | 38 +++++++++++ desmume/src/gtk-glade/main.cpp | 3 +- desmume/src/gtk/doc/desmume.1 | 3 + desmume/src/gtk/main.cpp | 3 +- 9 files changed, 121 insertions(+), 21 deletions(-) diff --git a/desmume/src/cli/doc/desmume-cli.1 b/desmume/src/cli/doc/desmume-cli.1 index 44a7f686b..41653038f 100644 --- a/desmume/src/cli/doc/desmume-cli.1 +++ b/desmume/src/cli/doc/desmume-cli.1 @@ -156,6 +156,9 @@ Enter = START .RS Left Shift = SELECT .RE +.RS +Backspace = LID +.RE .SH AUTHOR desmume was written by DeSmuME team (http://sourceforge.net/projects/desmume). diff --git a/desmume/src/cli/main.cpp b/desmume/src/cli/main.cpp index 6d3a9d52e..e8a47224a 100644 --- a/desmume/src/cli/main.cpp +++ b/desmume/src/cli/main.cpp @@ -121,7 +121,8 @@ const u16 cli_kb_cfg[NB_KEYS] = SDLK_s, // X SDLK_a, // Y SDLK_p, // DEBUG - SDLK_o // BOOST + SDLK_o, // BOOST + SDLK_BACKSPACE, // Lid }; class configured_features : public CommandLine diff --git a/desmume/src/ctrlssdl.cpp b/desmume/src/ctrlssdl.cpp index 95edffaab..8ae5d5cfb 100644 --- a/desmume/src/ctrlssdl.cpp +++ b/desmume/src/ctrlssdl.cpp @@ -39,7 +39,8 @@ const char *key_names[NB_KEYS] = "A", "B", "Select", "Start", "Right", "Left", "Up", "Down", "R", "L", "X", "Y", - "Debug", "Boost" + "Debug", "Boost", + "Lid", }; /* Joypad Key Codes -- 4-digit Hexadecimal number @@ -70,7 +71,8 @@ const u16 default_joypad_cfg[NB_KEYS] = 0x0204, // X 0x0203, // Y 0xFFFF, // DEBUG - 0xFFFF // BOOST + 0xFFFF, // BOOST + 0x0202, // Lid }; /* Load default joystick and keyboard configurations */ @@ -265,25 +267,72 @@ static void set_mouse_coord(signed long x,signed long y) mouse.y = y; } +// Adapted from Windows port +bool allowUpAndDown = false; +static buttonstruct cardinalHeldTime = {0}; + +static void RunAntipodalRestriction(const buttonstruct& pad) +{ + if(allowUpAndDown) + return; + + pad.U ? (cardinalHeldTime.U++) : (cardinalHeldTime.U=0); + pad.D ? (cardinalHeldTime.D++) : (cardinalHeldTime.D=0); + pad.L ? (cardinalHeldTime.L++) : (cardinalHeldTime.L=0); + pad.R ? (cardinalHeldTime.R++) : (cardinalHeldTime.R=0); +} +static void ApplyAntipodalRestriction(buttonstruct& pad) +{ + if(allowUpAndDown) + return; + + // give preference to whichever direction was most recently pressed + if(pad.U && pad.D) + if(cardinalHeldTime.U < cardinalHeldTime.D) + pad.D = false; + else + pad.U = false; + if(pad.L && pad.R) + if(cardinalHeldTime.L < cardinalHeldTime.R) + pad.R = false; + else + pad.L = false; +} + /* Update NDS keypad */ void update_keypad(u16 keys) { + // Set raw inputs + { + buttonstruct input = {}; + input.G = (keys>>12)&1; + input.E = (keys>>8)&1; + input.W = (keys>>9)&1; + input.X = (keys>>10)&1; + input.Y = (keys>>11)&1; + input.A = (keys>>0)&1; + input.B = (keys>>1)&1; + input.S = (keys>>3)&1; + input.T = (keys>>2)&1; + input.U = (keys>>6)&1; + input.D = (keys>>7)&1; + input.L = (keys>>5)&1; + input.R = (keys>>4)&1; + input.F = (keys>>14)&1; + RunAntipodalRestriction(input); + NDS_setPad( + input.R, input.L, input.D, input.U, + input.T, input.S, input.B, input.A, + input.Y, input.X, input.W, input.E, + input.G, input.F); + } + + // Set real input NDS_beginProcessingInput(); - UserButtons& input = NDS_getProcessingUserInput().buttons; - input.G = (keys>>12)&1; - input.E = (keys>>8)&1; - input.W = (keys>>9)&1; - input.X = (keys>>10)&1; - input.Y = (keys>>11)&1; - input.A = (keys>>0)&1; - input.B = (keys>>1)&1; - input.S = (keys>>3)&1; - input.T = (keys>>2)&1; - input.U = (keys>>6)&1; - input.D = (keys>>7)&1; - input.L = (keys>>5)&1; - input.R = (keys>>4)&1; - input.F = 0; + { + UserButtons& input = NDS_getProcessingUserInput().buttons; + ApplyAntipodalRestriction(input); + } NDS_endProcessingInput(); } diff --git a/desmume/src/ctrlssdl.h b/desmume/src/ctrlssdl.h index a09766ff3..f4da4b1e8 100644 --- a/desmume/src/ctrlssdl.h +++ b/desmume/src/ctrlssdl.h @@ -44,7 +44,7 @@ #define JOY_HAT_UP 2 #define JOY_HAT_DOWN 3 -#define NB_KEYS 14 +#define NB_KEYS 15 #define KEY_NONE 0 #define KEY_A 1 #define KEY_B 2 @@ -60,6 +60,7 @@ #define KEY_Y 12 #define KEY_DEBUG 13 #define KEY_BOOST 14 +#define KEY_LID 15 /* Keypad key names */ extern const char *key_names[NB_KEYS]; diff --git a/desmume/src/gtk-glade/doc/desmume-glade.1 b/desmume/src/gtk-glade/doc/desmume-glade.1 index 0b9d66dae..2376378f8 100644 --- a/desmume/src/gtk-glade/doc/desmume-glade.1 +++ b/desmume/src/gtk-glade/doc/desmume-glade.1 @@ -103,6 +103,9 @@ Enter = START .RS Left Shift = SELECT .RE +.RS +Backspace = LID +.RE .PP Desmume accepts joystick events, which can be configured by user. .SH AUTHOR diff --git a/desmume/src/gtk-glade/glade/DeSmuMe.glade b/desmume/src/gtk-glade/glade/DeSmuMe.glade index 62d4329d8..04c57d995 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe.glade +++ b/desmume/src/gtk-glade/glade/DeSmuMe.glade @@ -1596,6 +1596,25 @@ Contributors: + + + True + True + Lid : + True + GTK_RELIEF_NORMAL + True + + + + 4 + 5 + 2 + 3 + fill + + + @@ -2012,6 +2031,25 @@ Contributors: + + + True + True + Lid : + True + GTK_RELIEF_NORMAL + True + + + + 4 + 5 + 1 + 2 + fill + + + diff --git a/desmume/src/gtk-glade/main.cpp b/desmume/src/gtk-glade/main.cpp index 5bc57a648..30db38ffa 100755 --- a/desmume/src/gtk-glade/main.cpp +++ b/desmume/src/gtk-glade/main.cpp @@ -61,7 +61,8 @@ const u16 gtk_kb_cfg[NB_KEYS] = GDK_s, // X GDK_a, // Y GDK_p, // DEBUG - GDK_o // BOOST + GDK_o, // BOOST + GDK_BackSpace, // Lid }; SoundInterface_struct *SNDCoreList[] = { diff --git a/desmume/src/gtk/doc/desmume.1 b/desmume/src/gtk/doc/desmume.1 index 477b6d6ae..728bd50dd 100644 --- a/desmume/src/gtk/doc/desmume.1 +++ b/desmume/src/gtk/doc/desmume.1 @@ -157,6 +157,9 @@ Enter = START .RS Left Shift = SELECT .RE +.RS +Backspace = LID +.RE .PP Desmume accepts joystick events, which can be configured by user. .SH AUTHOR diff --git a/desmume/src/gtk/main.cpp b/desmume/src/gtk/main.cpp index 10bdb47ee..2e37298f6 100644 --- a/desmume/src/gtk/main.cpp +++ b/desmume/src/gtk/main.cpp @@ -610,7 +610,8 @@ static const u16 gtk_kb_cfg[NB_KEYS] = { GDK_s, // X GDK_a, // Y GDK_p, // DEBUG - GDK_o // BOOST + GDK_o, // BOOST + GDK_BackSpace, // Lid }; GKeyFile *keyfile;