From 8981dd6c6b43ebc34a56e084e238c749cabbbeff Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 9 Sep 2012 23:35:23 +0200 Subject: [PATCH] Add RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS. --- dynamic.c | 43 +++++++++++++++++++++++++++++++++++ general.h | 2 ++ libretro-test/libretro-test.c | 10 ++++++++ libretro.h | 25 ++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/dynamic.c b/dynamic.c index 4945ee765c..0410cedebf 100644 --- a/dynamic.c +++ b/dynamic.c @@ -352,6 +352,49 @@ static bool environment_cb(unsigned cmd, void *data) break; } + case RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS: + { + memset(g_extern.system.input_desc_btn, 0, sizeof(g_extern.system.input_desc_btn)); + + const struct retro_input_descriptor *desc = (const struct retro_input_descriptor*)data; + for (; desc->description; desc++) + { + if (desc->port >= MAX_PLAYERS) + continue; + + if (desc->device != RETRO_DEVICE_JOYPAD) // Ignore all others for now. + continue; + + if (desc->id >= RARCH_FIRST_ANALOG_BIND) + continue; + + g_extern.system.input_desc_btn[desc->port][desc->id] = desc->description; + } + + static const char *libretro_btn_desc[] = { + "B (bottom)", "Y (left)", "Select", "Start", + "D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right", + "A (right)", "X (up)", + "L", "R", "L2", "R2", "L3", "R3", + }; + + RARCH_LOG("Environ SET_INPUT_DESCRIPTORS:\n"); + for (unsigned p = 0; p < MAX_PLAYERS; p++) + { + for (unsigned id = 0; id < RARCH_FIRST_ANALOG_BIND; id++) + { + const char *desc = g_extern.system.input_desc_btn[p][id]; + if (desc) + { + RARCH_LOG("\tRetroPad, Player %u, Button \"%s\" => \"%s\"\n", + p + 1, libretro_btn_desc[id], desc); + } + } + } + + break; + } + default: RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd); return false; diff --git a/general.h b/general.h index d10d992456..13874e8861 100644 --- a/general.h +++ b/general.h @@ -344,6 +344,8 @@ struct global bool rgb32; bool force_nonblock; + + const char *input_desc_btn[MAX_PLAYERS][RARCH_FIRST_ANALOG_BIND]; } system; struct diff --git a/libretro-test/libretro-test.c b/libretro-test/libretro-test.c index ff6eef5a54..9ebc08c1ab 100644 --- a/libretro-test/libretro-test.c +++ b/libretro-test/libretro-test.c @@ -170,6 +170,16 @@ void retro_run(void) bool retro_load_game(const struct retro_game_info *info) { + struct retro_input_descriptor desc[] = { + { .port = 0, .device = RETRO_DEVICE_JOYPAD, .index = 0, .id = RETRO_DEVICE_ID_JOYPAD_LEFT, .description = "Left" }, + { .port = 0, .device = RETRO_DEVICE_JOYPAD, .index = 0, .id = RETRO_DEVICE_ID_JOYPAD_UP, .description = "Up" }, + { .port = 0, .device = RETRO_DEVICE_JOYPAD, .index = 0, .id = RETRO_DEVICE_ID_JOYPAD_DOWN, .description = "Down" }, + { .port = 0, .device = RETRO_DEVICE_JOYPAD, .index = 0, .id = RETRO_DEVICE_ID_JOYPAD_RIGHT, .description = "Right" }, + { 0 }, + }; + + environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); + (void)info; return true; } diff --git a/libretro.h b/libretro.h index 02d7c80f34..330fd2181a 100755 --- a/libretro.h +++ b/libretro.h @@ -357,6 +357,14 @@ enum retro_key // The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555. // If the call returns false, the frontend does not support this pixel format. // This function should be called inside retro_load_game() or retro_get_system_av_info(). + // +#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11 + // const struct retro_input_descriptor * -- + // Sets an array of retro_input_descriptors. + // It is up to the frontend to present this in a usable way. + // The array is terminated by retro_input_descriptor::description being set to NULL. + // This function can be called at any time, but it is recommended to call it as early as possible. + enum retro_pixel_format { @@ -370,8 +378,25 @@ struct retro_message unsigned frames; // Duration in frames of message. }; +// Describes how the libretro implementation maps a libretro input bind +// to its internal input system through a human readable string. +// This string can be used to better let a user configure input. +struct retro_input_descriptor +{ + // Associates given parameters with a description. + unsigned port; + unsigned device; + unsigned index; + unsigned id; + + const char *description; // Human readable description for parameters. + // The pointer must remain valid until retro_unload_game() is called. +}; + struct retro_system_info { + // All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called. + const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc. const char *library_version; // Descriptive version of core.