Add support for the RetroPad and disable keyboard.

How they can coexist is still not clear to me.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-12-19 14:26:48 +00:00
parent e6532deea3
commit 10eeeda581
6 changed files with 79 additions and 15 deletions

View file

@ -95,7 +95,7 @@ See [sa2](source/frontends/sa2/README.md).
There is an initial [libretro](https://docs.libretro.com/development/cores/developing-cores/) core.
Keyboard works, but a lot of keys overlap with RetroArch shortcuts.
Keyboard works, but a lot of keys overlap with RetroArch shortcuts. In the latest version the keyboard has been disabled and only the retro joypad works.
Video works, but the vertical flip is done in software.

View file

@ -12,6 +12,7 @@ if (IS_DIRECTORY ${LIBRETRO_PATH})
rdirectsound.cpp
interface.cpp
game.cpp
joypad.cpp
)
target_include_directories(ra2 PRIVATE

View file

@ -14,6 +14,6 @@ extern retro_audio_sample_batch_t audio_batch_cb;
extern std::string retro_base_directory;
#define RETRO_DEVICES 5
#define RETRO_DEVICES 1
extern unsigned int retro_devices[RETRO_DEVICES];

View file

@ -0,0 +1,39 @@
#include "frontends/retro/joypad.h"
#include "frontends/retro/environment.h"
#include "libretro.h"
Joypad::Joypad()
: myButtonCodes(2), myAxisCodes(2)
{
myButtonCodes[0] = RETRO_DEVICE_ID_JOYPAD_A;
myButtonCodes[1] = RETRO_DEVICE_ID_JOYPAD_B;
myAxisCodes[0][RETRO_DEVICE_ID_JOYPAD_LEFT] = -1.0;
myAxisCodes[0][RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1.0;
myAxisCodes[1][RETRO_DEVICE_ID_JOYPAD_UP] = -1.0;
myAxisCodes[1][RETRO_DEVICE_ID_JOYPAD_DOWN] = 1.0;
}
bool Joypad::getButton(int i) const
{
const int value = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, myButtonCodes[i]);
// if (value)
// log_cb(RETRO_LOG_INFO, "Joypad button: %d.\n", value);
return value != 0;
}
double Joypad::getAxis(int i) const
{
for (const auto & axis : myAxisCodes[i])
{
const int value = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, axis.first);
if (value)
{
// log_cb(RETRO_LOG_INFO, "Joypad axis: %d.\n", value);
return axis.second;
}
}
return 0.0;
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "linux/paddle.h"
#include <vector>
#include <map>
class Joypad : public Paddle
{
public:
Joypad();
virtual bool getButton(int i) const;
virtual double getAxis(int i) const;
private:
std::vector<unsigned> myButtonCodes;
std::vector<std::map<unsigned, double> > myAxisCodes;
};

View file

@ -6,9 +6,11 @@
#include "Frame.h"
#include "linux/version.h"
#include "linux/paddle.h"
#include "frontends/retro/game.h"
#include "frontends/retro/environment.h"
#include "frontends/retro/joypad.h"
namespace
{
@ -81,21 +83,20 @@ void retro_set_environment(retro_environment_t cb)
log_cb = logging.log;
else
log_cb = fallback_log;
/*
static const retro_controller_description controllers[] =
{
{ "Apple Keyboard", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0) },
};
static const retro_controller_info ports[] =
{
{ controllers, 1 },
{ NULL, 0 },
};
static const struct retro_controller_description controllers[] = {
{ "Nintendo DS", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) },
};
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);*/
retro_keyboard_callback callback = {&Game::keyboardCallback};
cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &callback);
static const struct retro_controller_info ports[] = {
{ controllers, 1 },
{ NULL, 0 },
};
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
// retro_keyboard_callback callback = {&Game::keyboardCallback};
// cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &callback);
}
void retro_set_audio_sample(retro_audio_sample_t cb)
@ -153,6 +154,9 @@ bool retro_load_game(const retro_game_info *info)
log_cb(RETRO_LOG_INFO, "Game path: %s:%d\n", info->path, ok);
Paddle::instance().reset(new Joypad);
Paddle::setSquaring(false);
return ok;
}
catch (const std::exception & e)