ui, separate sdl keymaps to avoid warnings with -flto
authorkub <derkub@gmail.com>
Thu, 17 Dec 2020 21:27:24 +0000 (22:27 +0100)
committerkub <derkub@gmail.com>
Thu, 17 Dec 2020 22:02:17 +0000 (23:02 +0100)
Makefile
platform/common/inputmap_kbd.c [new file with mode: 0644]
platform/common/plat_sdl.c
platform/common/plat_sdl.h [new file with mode: 0644]
platform/opendingux/inputmap.c

index 1a36870..34f4824 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -97,6 +97,7 @@ ifneq (,$(filter %__GCW0__ %__RG350__, $(CFLAGS)))
 CFLAGS += -DMIPS_USE_SYNCI # clear_cache uses SYNCI instead of a syscall
 endif
 
+use_inputmap ?= 1
 # OpenDingux is a generic platform, really.
 PLATFORM := generic
 endif
@@ -111,7 +112,7 @@ else
 LDFLAGS += -lEGL -lGLESv2
 endif
 OBJS += platform/linux/emu.o platform/linux/blit.o # FIXME
-OBJS += platform/common/plat_sdl.o
+OBJS += platform/common/plat_sdl.o platform/common/input_sdlkbd.o
 OBJS += platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
 OBJS += platform/libpicofe/plat_dummy.o
 OBJS += platform/libpicofe/gl.o
@@ -121,7 +122,11 @@ endif
 ifeq "$(PLATFORM)" "generic"
 CFLAGS += -DSDL_OVERLAY_2X -DSDL_BUFFER_3X
 OBJS += platform/linux/emu.o platform/linux/blit.o # FIXME
-OBJS += platform/common/plat_sdl.o
+ifeq "$(use_inputmap)" "1"
+OBJS += platform/common/plat_sdl.o platform/opendingux/inputmap.o
+else
+OBJS += platform/common/plat_sdl.o platform/common/inputmap_kbd.o
+endif
 OBJS += platform/libpicofe/plat_sdl.o platform/libpicofe/in_sdl.o
 OBJS += platform/libpicofe/plat_dummy.o
 USE_FRONTEND = 1
diff --git a/platform/common/inputmap_kbd.c b/platform/common/inputmap_kbd.c
new file mode 100644 (file)
index 0000000..0900fb1
--- /dev/null
@@ -0,0 +1,66 @@
+#include <stdlib.h>
+#include <SDL_keysym.h>
+
+#include "../libpicofe/input.h"
+#include "../libpicofe/in_sdl.h"
+#include "../common/input_pico.h"
+#include "../common/plat_sdl.h"
+
+const struct in_default_bind in_sdl_defbinds[] = {
+       { SDLK_UP,     IN_BINDTYPE_PLAYER12, GBTN_UP },
+       { SDLK_DOWN,   IN_BINDTYPE_PLAYER12, GBTN_DOWN },
+       { SDLK_LEFT,   IN_BINDTYPE_PLAYER12, GBTN_LEFT },
+       { SDLK_RIGHT,  IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
+       { SDLK_z,      IN_BINDTYPE_PLAYER12, GBTN_A },
+       { SDLK_x,      IN_BINDTYPE_PLAYER12, GBTN_B },
+       { SDLK_c,      IN_BINDTYPE_PLAYER12, GBTN_C },
+       { SDLK_a,      IN_BINDTYPE_PLAYER12, GBTN_X },
+       { SDLK_s,      IN_BINDTYPE_PLAYER12, GBTN_Y },
+       { SDLK_d,      IN_BINDTYPE_PLAYER12, GBTN_Z },
+       { SDLK_RETURN, IN_BINDTYPE_PLAYER12, GBTN_START },
+       { SDLK_f,      IN_BINDTYPE_PLAYER12, GBTN_MODE },
+       { SDLK_ESCAPE, IN_BINDTYPE_EMU, PEVB_MENU },
+       { SDLK_TAB,    IN_BINDTYPE_EMU, PEVB_RESET },
+       { SDLK_F1,     IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
+       { SDLK_F2,     IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
+       { SDLK_F3,     IN_BINDTYPE_EMU, PEVB_SSLOT_PREV },
+       { SDLK_F4,     IN_BINDTYPE_EMU, PEVB_SSLOT_NEXT },
+       { SDLK_F5,     IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
+       { SDLK_F6,     IN_BINDTYPE_EMU, PEVB_PICO_PPREV },
+       { SDLK_F7,     IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },
+       { SDLK_F8,     IN_BINDTYPE_EMU, PEVB_PICO_SWINP },
+       { SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },
+       { 0, 0, 0 }
+};
+
+const struct menu_keymap in_sdl_key_map[] = {
+       { SDLK_UP,      PBTN_UP },
+       { SDLK_DOWN,    PBTN_DOWN },
+       { SDLK_LEFT,    PBTN_LEFT },
+       { SDLK_RIGHT,   PBTN_RIGHT },
+       { SDLK_RETURN,  PBTN_MOK },
+       { SDLK_ESCAPE,  PBTN_MBACK },
+       { SDLK_SEMICOLON,       PBTN_MA2 },
+       { SDLK_QUOTE,   PBTN_MA3 },
+       { SDLK_LEFTBRACKET,  PBTN_L },
+       { SDLK_RIGHTBRACKET, PBTN_R },
+{ SDLK_COMMA,  PBTN_MA2 },
+{ SDLK_o,  PBTN_L },
+{ SDLK_p,  PBTN_R },
+};
+const int in_sdl_key_map_sz = sizeof(in_sdl_key_map) / sizeof(in_sdl_key_map[0]);
+
+const struct menu_keymap in_sdl_joy_map[] = {
+       { SDLK_UP,      PBTN_UP },
+       { SDLK_DOWN,    PBTN_DOWN },
+       { SDLK_LEFT,    PBTN_LEFT },
+       { SDLK_RIGHT,   PBTN_RIGHT },
+       /* joystick */
+       { SDLK_WORLD_0, PBTN_MOK },
+       { SDLK_WORLD_1, PBTN_MBACK },
+       { SDLK_WORLD_2, PBTN_MA2 },
+       { SDLK_WORLD_3, PBTN_MA3 },
+};
+const int in_sdl_joy_map_sz = sizeof(in_sdl_joy_map) / sizeof(in_sdl_joy_map[0]);
+
+const char * const (*in_sdl_key_names)[SDLK_LAST] = NULL;
index e1024f7..ceab084 100644 (file)
 #include "emu.h"
 #include "menu_pico.h"
 #include "input_pico.h"
+#include "plat_sdl.h"
 #include "version.h"
 
 #include <pico/pico.h>
 
 static void *shadow_fb;
 
-const struct in_default_bind in_sdl_defbinds[] __attribute__((weak)) = {
-       { SDLK_UP,     IN_BINDTYPE_PLAYER12, GBTN_UP },
-       { SDLK_DOWN,   IN_BINDTYPE_PLAYER12, GBTN_DOWN },
-       { SDLK_LEFT,   IN_BINDTYPE_PLAYER12, GBTN_LEFT },
-       { SDLK_RIGHT,  IN_BINDTYPE_PLAYER12, GBTN_RIGHT },
-       { SDLK_z,      IN_BINDTYPE_PLAYER12, GBTN_A },
-       { SDLK_x,      IN_BINDTYPE_PLAYER12, GBTN_B },
-       { SDLK_c,      IN_BINDTYPE_PLAYER12, GBTN_C },
-       { SDLK_a,      IN_BINDTYPE_PLAYER12, GBTN_X },
-       { SDLK_s,      IN_BINDTYPE_PLAYER12, GBTN_Y },
-       { SDLK_d,      IN_BINDTYPE_PLAYER12, GBTN_Z },
-       { SDLK_RETURN, IN_BINDTYPE_PLAYER12, GBTN_START },
-       { SDLK_f,      IN_BINDTYPE_PLAYER12, GBTN_MODE },
-       { SDLK_ESCAPE, IN_BINDTYPE_EMU, PEVB_MENU },
-       { SDLK_TAB,    IN_BINDTYPE_EMU, PEVB_RESET },
-       { SDLK_F1,     IN_BINDTYPE_EMU, PEVB_STATE_SAVE },
-       { SDLK_F2,     IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
-       { SDLK_F3,     IN_BINDTYPE_EMU, PEVB_SSLOT_PREV },
-       { SDLK_F4,     IN_BINDTYPE_EMU, PEVB_SSLOT_NEXT },
-       { SDLK_F5,     IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
-       { SDLK_F6,     IN_BINDTYPE_EMU, PEVB_PICO_PPREV },
-       { SDLK_F7,     IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },
-       { SDLK_F8,     IN_BINDTYPE_EMU, PEVB_PICO_SWINP },
-       { SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },
-       { 0, 0, 0 }
-};
-
-const struct menu_keymap in_sdl_key_map[] __attribute__((weak)) =
-{
-       { SDLK_UP,      PBTN_UP },
-       { SDLK_DOWN,    PBTN_DOWN },
-       { SDLK_LEFT,    PBTN_LEFT },
-       { SDLK_RIGHT,   PBTN_RIGHT },
-       { SDLK_RETURN,  PBTN_MOK },
-       { SDLK_ESCAPE,  PBTN_MBACK },
-       { SDLK_SEMICOLON,       PBTN_MA2 },
-       { SDLK_QUOTE,   PBTN_MA3 },
-       { SDLK_LEFTBRACKET,  PBTN_L },
-       { SDLK_RIGHTBRACKET, PBTN_R },
-};
-
-const struct menu_keymap in_sdl_joy_map[] __attribute__((weak)) =
-{
-       { SDLK_UP,      PBTN_UP },
-       { SDLK_DOWN,    PBTN_DOWN },
-       { SDLK_LEFT,    PBTN_LEFT },
-       { SDLK_RIGHT,   PBTN_RIGHT },
-       /* joystick */
-       { SDLK_WORLD_0, PBTN_MOK },
-       { SDLK_WORLD_1, PBTN_MBACK },
-       { SDLK_WORLD_2, PBTN_MA2 },
-       { SDLK_WORLD_3, PBTN_MA3 },
-};
-
-const char *const *in_sdl_key_names_p __attribute__((weak)) = NULL;
-
-
 static struct in_pdata in_sdl_platform_data = {
        .defbinds = in_sdl_defbinds,
        .key_map = in_sdl_key_map,
-       .kmap_size = sizeof(in_sdl_key_map) / sizeof(in_sdl_key_map[0]),
        .joy_map = in_sdl_joy_map,
-       .jmap_size = sizeof(in_sdl_joy_map) / sizeof(in_sdl_joy_map[0]),
 };
 
 /* YUV stuff */
@@ -331,7 +273,9 @@ void plat_init(void)
        g_screen_ppitch = 320;
        g_screen_ptr = shadow_fb;
 
-       in_sdl_platform_data.key_names = in_sdl_key_names_p;
+       in_sdl_platform_data.kmap_size = in_sdl_key_map_sz,
+       in_sdl_platform_data.jmap_size = in_sdl_joy_map_sz,
+       in_sdl_platform_data.key_names = *in_sdl_key_names,
        in_sdl_init(&in_sdl_platform_data, plat_sdl_event_handler);
        in_probe();
 
diff --git a/platform/common/plat_sdl.h b/platform/common/plat_sdl.h
new file mode 100644 (file)
index 0000000..ea8680f
--- /dev/null
@@ -0,0 +1,7 @@
+
+extern const struct in_default_bind in_sdl_defbinds[];
+extern const struct menu_keymap in_sdl_key_map[];
+extern const int in_sdl_key_map_sz;
+extern const struct menu_keymap in_sdl_joy_map[];
+extern const int in_sdl_joy_map_sz;
+extern const char * const (*in_sdl_key_names)[SDLK_LAST];
index 660fd5f..7db293c 100644 (file)
@@ -4,6 +4,7 @@
 #include "../libpicofe/input.h"
 #include "../libpicofe/in_sdl.h"
 #include "../common/input_pico.h"
+#include "../common/plat_sdl.h"
 
 const struct in_default_bind in_sdl_defbinds[] = {
        { SDLK_UP,      IN_BINDTYPE_PLAYER12, GBTN_UP },
@@ -23,8 +24,7 @@ const struct in_default_bind in_sdl_defbinds[] = {
        { 0, 0, 0 }
 };
 
-const struct menu_keymap in_sdl_key_map[] =
-{
+const struct menu_keymap in_sdl_key_map[] = {
        { SDLK_UP,      PBTN_UP },
        { SDLK_DOWN,    PBTN_DOWN },
        { SDLK_LEFT,    PBTN_LEFT },
@@ -36,8 +36,22 @@ const struct menu_keymap in_sdl_key_map[] =
        { SDLK_TAB,     PBTN_L },
        { SDLK_BACKSPACE,       PBTN_R },
 };
+const int in_sdl_key_map_sz = sizeof(in_sdl_key_map) / sizeof(in_sdl_key_map[0]);
 
-const char * const in_sdl_key_names[SDLK_LAST] = {
+const struct menu_keymap in_sdl_joy_map[] = {
+       { SDLK_UP,      PBTN_UP },
+       { SDLK_DOWN,    PBTN_DOWN },
+       { SDLK_LEFT,    PBTN_LEFT },
+       { SDLK_RIGHT,   PBTN_RIGHT },
+       /* joystick */
+       { SDLK_WORLD_0, PBTN_MOK },
+       { SDLK_WORLD_1, PBTN_MBACK },
+       { SDLK_WORLD_2, PBTN_MA2 },
+       { SDLK_WORLD_3, PBTN_MA3 },
+};
+const int in_sdl_joy_map_sz = sizeof(in_sdl_joy_map) / sizeof(in_sdl_joy_map[0]);
+
+const char * const _in_sdl_key_names[SDLK_LAST] = {
        [SDLK_UP] = "UP",
        [SDLK_DOWN] = "DOWN",
        [SDLK_LEFT] = "LEFT",
@@ -70,5 +84,4 @@ const char * const in_sdl_key_names[SDLK_LAST] = {
        [SDLK_PAUSE] = "LOCK",
 #endif
 };
-
-const char *const *in_sdl_key_names_p = in_sdl_key_names;
+const char * const (*in_sdl_key_names)[SDLK_LAST] = &_in_sdl_key_names;