Add rumble support.

Use dualshock instead of dualanalog. Hopefully won't break. :)
This commit is contained in:
Themaister 2013-09-26 13:42:08 +02:00
parent 8aa91fecdf
commit 7cd015b1ac
3 changed files with 156 additions and 5 deletions

View File

@ -17,6 +17,8 @@ static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_rumble_interface rumble;
static bool overscan;
static double last_sound_rate;
static MDFN_PixelFormat last_pixel_format;
@ -607,12 +609,19 @@ static void hookup_ports(bool force)
switch (retro_devices[j])
{
case RETRO_DEVICE_ANALOG:
currgame->SetInput(j, "dualanalog", &buf.u8[j]);
currgame->SetInput(j, "dualshock", &buf.u8[j]);
break;
default:
currgame->SetInput(j, "gamepad", &buf.u8[j]);
break;
}
if (rumble.set_rumble_state)
{
rumble.set_rumble_state(j, RETRO_RUMBLE_STRONG, 0);
rumble.set_rumble_state(j, RETRO_RUMBLE_WEAK, 0);
buf.u32[j][9] = 0;
}
}
#elif defined(WANT_PCE_FAST_EMU)
// Possible endian bug ...
@ -664,6 +673,8 @@ bool retro_load_game(const struct retro_game_info *info)
#if defined(WANT_PSX_EMU)
check_variables();
if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble))
fprintf(stderr, "Rumble interface supported!\n");
#endif
game = MDFNI_LoadGame(MEDNAFEN_CORE_NAME_MODULE, info->path);
@ -786,6 +797,16 @@ static void update_input(void)
buf.u32[j][7] = l_down;
buf.u32[j][8] = l_up;
}
fprintf(stderr, "Rumble strong: %u, weak: %u.\n", buf.u8[0][9 * 4 + 1], buf.u8[0][9 * 4]);
if (rumble.set_rumble_state)
{
// Appears to be correct.
rumble.set_rumble_state(0, RETRO_RUMBLE_WEAK, buf.u8[0][9 * 4] * 0x101);
rumble.set_rumble_state(0, RETRO_RUMBLE_STRONG, buf.u8[0][9 * 4 + 1] * 0x101);
rumble.set_rumble_state(1, RETRO_RUMBLE_WEAK, buf.u8[1][9 * 4] * 0x101);
rumble.set_rumble_state(1, RETRO_RUMBLE_STRONG, buf.u8[1][9 * 4 + 1] * 0x101);
}
#elif defined(WANT_PCE_FAST_EMU)
static unsigned map[] = {

View File

@ -1,3 +1,25 @@
/* Copyright (C) 2010-2013 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this libretro API header (libretro.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIBRETRO_H__
#define LIBRETRO_H__
@ -335,6 +357,8 @@ enum retro_mod
// If set, this call is not part of the public libretro API yet. It can change or be removed at any time.
#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
// Environment callback to be used internally in frontend.
#define RETRO_ENVIRONMENT_PRIVATE 0x20000
// Environment commands.
#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
@ -412,7 +436,7 @@ enum retro_mod
// Sets an interface which frontend can use to eject and insert disk images.
// This is used for games which consist of multiple images and must be manually
// swapped out by the user (e.g. PSX).
#define RETRO_ENVIRONMENT_SET_HW_RENDER (14 | RETRO_ENVIRONMENT_EXPERIMENTAL)
#define RETRO_ENVIRONMENT_SET_HW_RENDER 14
// struct retro_hw_render_callback * --
// NOTE: This call is currently very experimental, and should not be considered part of the public API.
// The interface could be changed or removed at any time.
@ -423,7 +447,7 @@ enum retro_mod
// If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or NULL to retro_video_refresh_t.
#define RETRO_ENVIRONMENT_GET_VARIABLE 15
// struct retro_variable * --
// Interface to aquire user-defined information from environment
// Interface to acquire user-defined information from environment
// that cannot feasibly be supported in a multi-system way.
// 'key' should be set to a key which has already been set by SET_VARIABLES.
// 'data' will be set to a value or NULL.
@ -452,12 +476,102 @@ enum retro_mod
// Result is set to true if some variables are updated by
// frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.
// Variables should be queried with GET_VARIABLE.
//
#define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
// const bool * --
// If true, the libretro implementation supports calls to retro_load_game() with NULL as argument.
// Used by cores which can run without particular game data.
// This should be called within retro_set_environment() only.
//
#define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
// const char ** --
// Retrieves the absolute path from where this libretro implementation was loaded.
// NULL is returned if the libretro was loaded statically (i.e. linked statically to frontend), or if the path cannot be determined.
// Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can be loaded without ugly hacks.
//
//
// Environment 20 was an obsolete version of SET_AUDIO_CALLBACK. It was not used by any known core at the time,
// and was removed from the API.
#define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
// const struct retro_audio_callback * --
// Sets an interface which is used to notify a libretro core about audio being available for writing.
// The callback can be called from any thread, so a core using this must have a thread safe audio implementation.
// It is intended for games where audio and video are completely asynchronous and audio can be generated on the fly.
// This interface is not recommended for use with emulators which have highly synchronous audio.
//
// The callback only notifies about writability; the libretro core still has to call the normal audio callbacks
// to write audio. The audio callbacks must be called from within the notification callback.
// The amount of audio data to write is up to the implementation.
// Generally, the audio callback will be called continously in a loop.
//
// Due to thread safety guarantees and lack of sync between audio and video, a frontend
// can selectively disallow this interface based on internal configuration. A core using
// this interface must also implement the "normal" audio interface.
//
// A libretro core using SET_AUDIO_CALLBACK should also make use of SET_FRAME_TIME_CALLBACK.
#define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21
// const struct retro_frame_time_callback * --
// Lets the core know how much time has passed since last invocation of retro_run().
// The frontend can tamper with the timing to fake fast-forward, slow-motion, frame stepping, etc.
// In this case the delta time will use the reference value in frame_time_callback..
//
#define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE (23 | RETRO_ENVIRONMENT_EXPERIMENTAL)
// struct retro_rumble_interface * --
// Gets an interface which is used by a libretro core to set state of rumble motors in controllers.
// A strong and weak motor is supported, and they can be controlled indepedently.
enum retro_rumble_effect
{
RETRO_RUMBLE_STRONG = 0,
RETRO_RUMBLE_WEAK = 1,
RETRO_RUMBLE_DUMMY = INT_MAX
};
// Sets rumble state for joypad plugged in port 'port'. Rumble effects are controlled independently,
// and setting e.g. strong rumble does not override weak rumble.
// Strength has a range of [0, 0xffff].
//
// Returns true if rumble state request was honored. Calling this before first retro_run() is likely to return false.
typedef bool (*retro_set_rumble_state_t)(unsigned port, enum retro_rumble_effect effect, uint16_t strength);
struct retro_rumble_interface
{
retro_set_rumble_state_t set_rumble_state;
};
// Notifies libretro that audio data should be written.
typedef void (*retro_audio_callback_t)(void);
// True: Audio driver in frontend is active, and callback is expected to be called regularily.
// False: Audio driver in frontend is paused or inactive. Audio callback will not be called until set_state has been called with true.
// Initial state is false (inactive).
typedef void (*retro_audio_set_state_callback_t)(bool enabled);
struct retro_audio_callback
{
retro_audio_callback_t callback;
retro_audio_set_state_callback_t set_state;
};
// Notifies a libretro core of time spent since last invocation of retro_run() in microseconds.
// It will be called right before retro_run() every frame.
// The frontend can tamper with timing to support cases like fast-forward, slow-motion and framestepping.
// In those scenarios the reference frame time value will be used.
typedef int64_t retro_usec_t;
typedef void (*retro_frame_time_callback_t)(retro_usec_t usec);
struct retro_frame_time_callback
{
retro_frame_time_callback_t callback;
retro_usec_t reference; // Represents the time of one frame. It is computed as 1000000 / fps, but the implementation will resolve the rounding to ensure that framestepping, etc is exact.
};
// Pass this to retro_video_refresh_t if rendering to hardware.
// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
// Invalidates the current HW context.
// Any GL state is lost, and must not be deinitialized explicitly. If explicit deinitialization is desired by the libretro core,
// it should implement context_destroy callback.
// If called, all GPU resources must be reinitialized.
// Usually called when frontend reinits video driver.
// Also called first time video driver is initialized, allowing libretro core to init resources.
@ -474,6 +588,7 @@ enum retro_hw_context_type
RETRO_HW_CONTEXT_NONE = 0,
RETRO_HW_CONTEXT_OPENGL, // OpenGL 2.x. Latest version available before 3.x+.
RETRO_HW_CONTEXT_OPENGLES2, // GLES 2.0
RETRO_HW_CONTEXT_OPENGL_CORE, // Modern desktop core GL context. Use major/minor fields to set GL version.
RETRO_HW_CONTEXT_DUMMY = INT_MAX
};
@ -481,10 +596,21 @@ enum retro_hw_context_type
struct retro_hw_render_callback
{
enum retro_hw_context_type context_type; // Which API to use. Set by libretro core.
retro_hw_context_reset_t context_reset; // Set by libretro core.
retro_hw_context_reset_t context_reset; // Called when a context has been created or when it has been reset.
retro_hw_get_current_framebuffer_t get_current_framebuffer; // Set by frontend.
retro_hw_get_proc_address_t get_proc_address; // Set by frontend.
bool depth; // Set if render buffers should have depth component attached.
bool stencil; // Set if stencil buffers should be attached.
// If depth and stencil are true, a packed 24/8 buffer will be added. Only attaching stencil is invalid and will be ignored.
bool bottom_left_origin; // Use conventional bottom-left origin convention. Is false, standard libretro top-left origin semantics are used.
unsigned version_major; // Major version number for core GL context.
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.
// 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.
};
// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events.
@ -496,7 +622,7 @@ typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t cha
struct retro_keyboard_callback
{
retro_keyboard_event_t callback;
retro_keyboard_event_t callback;
};
// Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.

View File

@ -224,7 +224,11 @@ void InputDevice_DualShock::Power(void)
transmit_pos = 0;
transmit_count = 0;
#ifdef __LIBRETRO__ // This is a hack. Couldn't figure out how to do it otherwise.
analog_mode = true;
#else
analog_mode = false;
#endif
analog_mode_locked = false;
mad_munchkins = false;