mirror of https://github.com/snes9xgit/snes9x.git
Implement RETRO_ENVIRONMENT_SET_CONTROLLER_INFO
This commit is contained in:
parent
7c9db9acf5
commit
4f0d5131f1
|
@ -35,6 +35,11 @@
|
|||
#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102
|
||||
#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103
|
||||
|
||||
#define RETRO_DEVICE_JOYPAD_MULTITAP RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
|
||||
#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0)
|
||||
#define RETRO_DEVICE_LIGHTGUN_JUSTIFIER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 1)
|
||||
#define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 2)
|
||||
|
||||
static retro_log_printf_t log_cb = NULL;
|
||||
static retro_video_refresh_t s9x_video_cb = NULL;
|
||||
static retro_audio_sample_t s9x_audio_cb = NULL;
|
||||
|
@ -128,8 +133,29 @@ void retro_set_environment(retro_environment_t cb)
|
|||
{ NULL },
|
||||
};
|
||||
|
||||
static const struct retro_controller_description port_1[] = {
|
||||
{ "SNES Joypad", RETRO_DEVICE_JOYPAD },
|
||||
{ "SNES Mouse", RETRO_DEVICE_MOUSE },
|
||||
};
|
||||
|
||||
static const struct retro_controller_description port_2[] = {
|
||||
{ "SNES Joypad", RETRO_DEVICE_JOYPAD },
|
||||
{ "SNES Mouse", RETRO_DEVICE_MOUSE },
|
||||
{ "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP },
|
||||
{ "SuperScope", RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE },
|
||||
{ "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER },
|
||||
{ "Justifiers", RETRO_DEVICE_LIGHTGUN_JUSTIFIERS },
|
||||
};
|
||||
|
||||
static const struct retro_controller_info ports[] = {
|
||||
{ port_1, 2 },
|
||||
{ port_2, 6 },
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO, (void*)subsystems);
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
|
||||
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
|
||||
}
|
||||
|
||||
static void update_variables(void)
|
||||
|
@ -483,6 +509,7 @@ void retro_init()
|
|||
#define BTN_POINTER (BTN_LAST + 1)
|
||||
#define BTN_POINTER2 (BTN_POINTER + 1)
|
||||
|
||||
|
||||
static void map_buttons()
|
||||
{
|
||||
MAP_BUTTON(MAKE_BUTTON(PAD_1, BTN_A), "Joypad1 A");
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef LIBRETRO_H__
|
||||
#define LIBRETRO_H__
|
||||
|
||||
#include "port.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -46,8 +46,22 @@ extern "C" {
|
|||
// It is not incremented for compatible changes to the API.
|
||||
#define RETRO_API_VERSION 1
|
||||
|
||||
// Libretro's fundamental device abstractions.
|
||||
#define RETRO_DEVICE_MASK 0xff
|
||||
//
|
||||
// Libretros fundamental device abstractions.
|
||||
/////////
|
||||
//
|
||||
// Libretros input system consists of some standardized device types such as a joypad (with/without analog),
|
||||
// mouse, keyboard, lightgun and a pointer. The functionality of these devices are fixed, and individual cores map
|
||||
// their own concept of a controller to libretros abstractions.
|
||||
// This makes it possible for frontends to map the abstract types to a real input device,
|
||||
// and not having to worry about binding input correctly to arbitrary controller layouts.
|
||||
|
||||
|
||||
#define RETRO_DEVICE_TYPE_SHIFT 8
|
||||
#define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1)
|
||||
#define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base)
|
||||
|
||||
// Input disabled.
|
||||
#define RETRO_DEVICE_NONE 0
|
||||
|
||||
// The JOYPAD is called RetroPad. It is essentially a Super Nintendo controller,
|
||||
|
@ -62,6 +76,7 @@ extern "C" {
|
|||
|
||||
// KEYBOARD device lets one poll for raw key pressed.
|
||||
// It is poll based, so input callback will return with the current pressed state.
|
||||
// For event/text based keyboard input, see RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
|
||||
#define RETRO_DEVICE_KEYBOARD 3
|
||||
|
||||
// Lightgun X/Y coordinates are reported relatively to last poll, similar to mouse.
|
||||
|
@ -87,7 +102,7 @@ extern "C" {
|
|||
//
|
||||
// To check if the pointer coordinates are valid (e.g. a touch display actually being touched),
|
||||
// PRESSED returns 1 or 0.
|
||||
// If using a mouse, PRESSED will usually correspond to the left mouse button.
|
||||
// If using a mouse on a desktop, PRESSED will usually correspond to the left mouse button, but this is a frontend decision.
|
||||
// PRESSED will only return 1 if the pointer is inside the game screen.
|
||||
//
|
||||
// For multi-touch, the index variable can be used to successively query more presses.
|
||||
|
@ -96,16 +111,6 @@ extern "C" {
|
|||
// Eventually _PRESSED will return false for an index. No further presses are registered at this point.
|
||||
#define RETRO_DEVICE_POINTER 6
|
||||
|
||||
// These device types are specializations of the base types above.
|
||||
// They should only be used in retro_set_controller_type() to inform libretro implementations
|
||||
// about use of a very specific device type.
|
||||
//
|
||||
// In input state callback, however, only the base type should be used in the 'device' field.
|
||||
#define RETRO_DEVICE_JOYPAD_MULTITAP ((1 << 8) | RETRO_DEVICE_JOYPAD)
|
||||
#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE ((1 << 8) | RETRO_DEVICE_LIGHTGUN)
|
||||
#define RETRO_DEVICE_LIGHTGUN_JUSTIFIER ((2 << 8) | RETRO_DEVICE_LIGHTGUN)
|
||||
#define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS ((3 << 8) | RETRO_DEVICE_LIGHTGUN)
|
||||
|
||||
// Buttons for the RetroPad (JOYPAD).
|
||||
// The placement of these is equivalent to placements on the Super Nintendo controller.
|
||||
// L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
|
||||
|
@ -548,12 +553,12 @@ enum retro_mod
|
|||
// If this interface is not used, libretro cores should log to stderr as desired.
|
||||
#define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
|
||||
// struct retro_perf_callback * --
|
||||
// Gets an interface for performance counters. This is useful for performance logging in a
|
||||
// Gets an interface for performance counters. This is useful for performance logging in a
|
||||
// cross-platform way and for detecting architecture-specific features, such as SIMD support.
|
||||
#define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29
|
||||
// struct retro_location_callback * --
|
||||
// Gets access to the location interface.
|
||||
// The purpose of this interface is to be able to retrieve location-based information from the host device,
|
||||
// The purpose of this interface is to be able to retrieve location-based information from the host device,
|
||||
// such as current latitude / longitude.
|
||||
//
|
||||
#define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30
|
||||
|
@ -611,7 +616,44 @@ enum retro_mod
|
|||
// and this environment call allows a libretro core to expose which subsystems are supported for use with retro_load_game_special().
|
||||
// A core passes an array of retro_game_special_info which is terminated with a zeroed out retro_game_special_info struct.
|
||||
//
|
||||
// If a core wants to use this functionality, SET_SPECIAL_GAME_TYPES **MUST** be called from within retro_set_environment().
|
||||
// If a core wants to use this functionality, SET_SUBSYSTEM_INFO **MUST** be called from within retro_set_environment().
|
||||
//
|
||||
#define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35
|
||||
// const struct retro_controller_info * --
|
||||
// This environment call lets a libretro core tell the frontend which
|
||||
// controller types are recognized in calls to retro_set_controller_port_device().
|
||||
//
|
||||
// Some emulators such as Super Nintendo
|
||||
// support multiple lightgun types which must be specifically selected from.
|
||||
// It is therefore sometimes necessary for a frontend to be able to tell
|
||||
// the core about a special kind of input device which is not covered by the
|
||||
// libretro input API.
|
||||
//
|
||||
// In order for a frontend to understand the workings of an input device,
|
||||
// it must be a specialized type
|
||||
// of the generic device types already defined in the libretro API.
|
||||
//
|
||||
// Which devices are supported can vary per input port.
|
||||
// The core must pass an array of const struct retro_controller_info which is terminated with
|
||||
// a blanked out struct. Each element of the struct corresponds to an ascending port index to retro_set_controller_port_device().
|
||||
// Even if special device types are set in the libretro core, libretro should only poll input based on the base input device types.
|
||||
|
||||
struct retro_controller_description
|
||||
{
|
||||
// Human-readable description of the controller. Even if using a generic input device type, this can be
|
||||
// set to the particular device type the core uses.
|
||||
const char *desc;
|
||||
|
||||
// Device type passed to retro_set_controller_port_device(). If the device type is a sub-class of a generic input device type,
|
||||
// use the RETRO_DEVICE_SUBCLASS macro to create an ID. E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1).
|
||||
unsigned id;
|
||||
};
|
||||
|
||||
struct retro_controller_info
|
||||
{
|
||||
const struct retro_controller_description *types;
|
||||
unsigned num_types;
|
||||
};
|
||||
|
||||
struct retro_subsystem_memory_info
|
||||
{
|
||||
|
@ -827,7 +869,7 @@ typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, uns
|
|||
//
|
||||
// texture_target is the texture target for the GL texture.
|
||||
// These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly more depending on extensions.
|
||||
//
|
||||
//
|
||||
// affine points to a packed 3x3 column-major matrix used to apply an affine transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
|
||||
// After transform, normalized texture coord (0, 0) should be bottom-left and (1, 1) should be top-right (or (width, height) for RECTANGLE).
|
||||
//
|
||||
|
@ -855,7 +897,7 @@ struct retro_camera_callback
|
|||
};
|
||||
|
||||
// Sets the interval of time and/or distance at which to update/poll location-based data.
|
||||
// To ensure compatibility with all location-based implementations, values for both
|
||||
// To ensure compatibility with all location-based implementations, values for both
|
||||
// interval_ms and interval_distance should be provided.
|
||||
// interval_ms is the interval expressed in milliseconds.
|
||||
// interval_distance is the distance interval expressed in meters.
|
||||
|
@ -883,7 +925,7 @@ struct retro_location_callback
|
|||
retro_location_start_t start;
|
||||
retro_location_stop_t stop;
|
||||
retro_location_get_position_t get_position;
|
||||
retro_location_set_interval_t set_interval;
|
||||
retro_location_set_interval_t set_interval;
|
||||
|
||||
retro_location_lifetime_status_t initialized;
|
||||
retro_location_lifetime_status_t deinitialized;
|
||||
|
@ -975,7 +1017,7 @@ struct retro_hw_render_callback
|
|||
unsigned version_minor; // Minor version number for core GL context.
|
||||
|
||||
bool cache_context; // If this is true, the frontend will go very far to avoid resetting context in scenarios like toggling fullscreen, etc.
|
||||
// The reset callback might still be called in extreme situations such as if the context is lost beyond recovery.
|
||||
// The reset callback might still be called in extreme situations such as if the context is lost beyond recovery.
|
||||
// For optimal stability, set this to false, and allow context to be reset at any time.
|
||||
retro_hw_context_reset_t context_destroy; // A callback to be called before the context is destroyed. Resources can be deinitialized at this step. This can be set to NULL, in which resources will just be destroyed without any notification.
|
||||
bool debug_context; // Creates a debug context.
|
||||
|
@ -1208,6 +1250,8 @@ void retro_get_system_info(struct retro_system_info *info);
|
|||
void retro_get_system_av_info(struct retro_system_av_info *info);
|
||||
|
||||
// Sets device to be used for player 'port'.
|
||||
// By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all available ports.
|
||||
// Setting a particular device type is not a guarantee that libretro cores will only poll input based on that particular device type. It is only a hint to the libretro core when a core cannot automatically detect the appropriate input device type on its own. It is also relevant when a core can change its behavior depending on device type.
|
||||
void retro_set_controller_port_device(unsigned port, unsigned device);
|
||||
|
||||
// Resets the current game.
|
||||
|
|
Loading…
Reference in New Issue