mirror of https://github.com/stella-emu/stella.git
libretro: add more controllers
joysticks: paddles (4), driving (2), booster (2)
This commit is contained in:
parent
2d4b2a314e
commit
1d29fb1282
|
@ -23,9 +23,11 @@
|
|||
|
||||
#include "Console.hxx"
|
||||
#include "ConsoleTiming.hxx"
|
||||
#include "Control.hxx"
|
||||
#include "EmulationTiming.hxx"
|
||||
#include "EventHandler.hxx"
|
||||
#include "M6532.hxx"
|
||||
#include "Paddles.hxx"
|
||||
#include "System.hxx"
|
||||
#include "TIA.hxx"
|
||||
#include "TIASurface.hxx"
|
||||
|
@ -108,6 +110,17 @@ class StellaLIBRETRO
|
|||
|
||||
void setInputEvent(Event::Type type, Int32 state) { myOSystem->eventHandler().handleEvent(type, state); }
|
||||
|
||||
Controller::Type getLeftControllerType() { return myOSystem->console().leftController().type(); }
|
||||
Controller::Type getRightControllerType() { return myOSystem->console().rightController().type(); }
|
||||
|
||||
void setPaddleJoypadSensitivity(int sensitivity)
|
||||
{
|
||||
if(getLeftControllerType() == Controller::Type::Paddles)
|
||||
static_cast<Paddles&>(myOSystem->console().leftController()).setDigitalSensitivity(sensitivity);
|
||||
if(getRightControllerType() == Controller::Type::Paddles)
|
||||
static_cast<Paddles&>(myOSystem->console().rightController()).setDigitalSensitivity(sensitivity);
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateInput();
|
||||
void updateVideo();
|
||||
|
|
|
@ -32,10 +32,13 @@ static struct retro_system_av_info g_av_info;
|
|||
static int setting_ntsc, setting_pal;
|
||||
static int setting_stereo, setting_filter, setting_palette;
|
||||
static int setting_phosphor, setting_console, setting_phosphor_blend;
|
||||
static int stella_paddle_joypad_sensitivity;
|
||||
|
||||
static bool system_reset;
|
||||
|
||||
static unsigned input_devices[2];
|
||||
static unsigned input_devices[4];
|
||||
static Controller::Type input_type[2];
|
||||
|
||||
|
||||
// TODO input:
|
||||
// https://github.com/libretro/blueMSX-libretro/blob/master/libretro.c
|
||||
|
@ -58,17 +61,68 @@ static void update_input()
|
|||
|
||||
#define EVENT stella.setInputEvent
|
||||
|
||||
EVENT(Event::JoystickZeroUp, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP));
|
||||
EVENT(Event::JoystickZeroDown, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
EVENT(Event::JoystickZeroLeft, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::JoystickZeroRight, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::JoystickZeroFire, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
switch(input_type[0])
|
||||
{
|
||||
case Controller::Type::BoosterGrip:
|
||||
EVENT(Event::JoystickZeroFire5, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A));
|
||||
EVENT(Event::JoystickZeroFire9, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y));
|
||||
// Fallthrough
|
||||
|
||||
case Controller::Type::Joystick:
|
||||
default:
|
||||
EVENT(Event::JoystickZeroUp, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP));
|
||||
EVENT(Event::JoystickZeroDown, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
// Fallthrough
|
||||
|
||||
case Controller::Type::Driving:
|
||||
EVENT(Event::JoystickZeroLeft, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::JoystickZeroRight, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::JoystickZeroFire, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
break;
|
||||
|
||||
case Controller::Type::Paddles:
|
||||
EVENT(Event::PaddleZeroIncrease, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::PaddleZeroDecrease, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::PaddleZeroFire, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
//WIP = Event::PaddleZeroAnalog
|
||||
|
||||
EVENT(Event::PaddleOneIncrease, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::PaddleOneDecrease, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::PaddleOneFire, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
switch(input_type[1])
|
||||
{
|
||||
case Controller::Type::BoosterGrip:
|
||||
EVENT(Event::JoystickOneFire5, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A));
|
||||
EVENT(Event::JoystickOneFire9, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y));
|
||||
// Fallthrough
|
||||
|
||||
case Controller::Type::Joystick:
|
||||
default:
|
||||
EVENT(Event::JoystickOneUp, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP));
|
||||
EVENT(Event::JoystickOneDown, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
// Fallthrough
|
||||
|
||||
case Controller::Type::Driving:
|
||||
EVENT(Event::JoystickOneLeft, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::JoystickOneRight, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::JoystickOneFire, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
break;
|
||||
|
||||
case Controller::Type::Paddles:
|
||||
EVENT(Event::PaddleTwoIncrease, input_state_cb(2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::PaddleTwoDecrease, input_state_cb(2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::PaddleTwoFire, input_state_cb(2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
|
||||
EVENT(Event::PaddleThreeIncrease, input_state_cb(3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::PaddleThreeDecrease, input_state_cb(3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::PaddleThreeFire, input_state_cb(3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
break;
|
||||
}
|
||||
|
||||
EVENT(Event::JoystickOneUp, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP));
|
||||
EVENT(Event::JoystickOneDown, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN));
|
||||
EVENT(Event::JoystickOneLeft, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
||||
EVENT(Event::JoystickOneRight, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
||||
EVENT(Event::JoystickOneFire, input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));
|
||||
|
||||
EVENT(Event::ConsoleLeftDiffA, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L));
|
||||
EVENT(Event::ConsoleLeftDiffB, input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2));
|
||||
|
@ -246,6 +300,20 @@ static void update_variables(bool init = false)
|
|||
setting_phosphor_blend = value;
|
||||
}
|
||||
}
|
||||
|
||||
RETRO_GET("stella_paddle_joypad_sensitivity")
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
value = atoi(var.value);
|
||||
|
||||
if(stella_paddle_joypad_sensitivity != value)
|
||||
{
|
||||
if(!init) stella.setPaddleJoypadSensitivity(value);
|
||||
|
||||
stella_paddle_joypad_sensitivity = value;
|
||||
}
|
||||
}
|
||||
|
||||
if(!init && !system_reset)
|
||||
{
|
||||
|
@ -269,6 +337,11 @@ static bool reset_system()
|
|||
|
||||
// reset libretro window
|
||||
update_geometry();
|
||||
|
||||
// get auto-detect controllers
|
||||
input_type[0] = stella.getLeftControllerType();
|
||||
input_type[1] = stella.getRightControllerType();
|
||||
stella.setPaddleJoypadSensitivity(stella_paddle_joypad_sensitivity);
|
||||
|
||||
system_reset = false;
|
||||
return true;
|
||||
|
@ -328,7 +401,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void retro_set_controller_port_device(unsigned port, unsigned device)
|
||||
{
|
||||
if(port < 2)
|
||||
if(port < 4)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
|
@ -362,14 +435,15 @@ void retro_set_environment(retro_environment_t cb)
|
|||
|
||||
struct retro_variable variables[] = {
|
||||
// Adding more variables and rearranging them is safe.
|
||||
{ "stella_console", "Console display; auto|ntsc|pal|secam|ntsc50|pal60|secam60"},
|
||||
{ "stella_filter", "TV effects; disabled|composite|s-video|rgb|badly adjusted"},
|
||||
{ "stella_ntsc_aspect", "NTSC aspect %; par|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85"},
|
||||
{ "stella_pal_aspect", "PAL aspect %; par|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103"},
|
||||
{ "stella_stereo", "Stereo sound; auto|off|on"},
|
||||
{ "stella_palette", "Palette colors; standard|z26"},
|
||||
{ "stella_phosphor", "Phosphor mode; auto|off|on"},
|
||||
{ "stella_phosphor_blend", "Phosphor blend %; 60|65|70|75|80|85|90|95|100|0|5|10|15|20|25|30|35|40|45|50|55"},
|
||||
{ "stella_console", "Console display; auto|ntsc|pal|secam|ntsc50|pal60|secam60" },
|
||||
{ "stella_filter", "TV effects; disabled|composite|s-video|rgb|badly adjusted" },
|
||||
{ "stella_ntsc_aspect", "NTSC aspect %; par|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85" },
|
||||
{ "stella_pal_aspect", "PAL aspect %; par|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103" },
|
||||
{ "stella_stereo", "Stereo sound; auto|off|on" },
|
||||
{ "stella_palette", "Palette colors; standard|z26" },
|
||||
{ "stella_phosphor", "Phosphor mode; auto|off|on" },
|
||||
{ "stella_phosphor_blend", "Phosphor blend %; 60|65|70|75|80|85|90|95|100|0|5|10|15|20|25|30|35|40|45|50|55" },
|
||||
{ "stella_paddle_joypad_sensitivity", "Paddle joypad sensitivity; 3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|1|2" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
@ -399,6 +473,8 @@ bool retro_load_game(const struct retro_game_info *info)
|
|||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Trigger" },
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Booster" },
|
||||
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty A" },
|
||||
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "Left Difficulty B" },
|
||||
|
@ -414,6 +490,16 @@ bool retro_load_game(const struct retro_game_info *info)
|
|||
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
|
||||
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
|
||||
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
|
||||
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Trigger" },
|
||||
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Booster" },
|
||||
|
||||
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
|
||||
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
|
||||
{ 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
|
||||
|
||||
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
|
||||
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
|
||||
{ 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Fire" },
|
||||
|
||||
{ 0 },
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue