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:
parent
e6532deea3
commit
10eeeda581
6 changed files with 79 additions and 15 deletions
2
linux.md
2
linux.md
|
@ -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.
|
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.
|
Video works, but the vertical flip is done in software.
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ if (IS_DIRECTORY ${LIBRETRO_PATH})
|
||||||
rdirectsound.cpp
|
rdirectsound.cpp
|
||||||
interface.cpp
|
interface.cpp
|
||||||
game.cpp
|
game.cpp
|
||||||
|
joypad.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ra2 PRIVATE
|
target_include_directories(ra2 PRIVATE
|
||||||
|
|
|
@ -14,6 +14,6 @@ extern retro_audio_sample_batch_t audio_batch_cb;
|
||||||
|
|
||||||
extern std::string retro_base_directory;
|
extern std::string retro_base_directory;
|
||||||
|
|
||||||
#define RETRO_DEVICES 5
|
#define RETRO_DEVICES 1
|
||||||
|
|
||||||
extern unsigned int retro_devices[RETRO_DEVICES];
|
extern unsigned int retro_devices[RETRO_DEVICES];
|
||||||
|
|
39
source/frontends/retro/joypad.cpp
Normal file
39
source/frontends/retro/joypad.cpp
Normal 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;
|
||||||
|
}
|
20
source/frontends/retro/joypad.h
Normal file
20
source/frontends/retro/joypad.h
Normal 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;
|
||||||
|
};
|
|
@ -6,9 +6,11 @@
|
||||||
#include "Frame.h"
|
#include "Frame.h"
|
||||||
|
|
||||||
#include "linux/version.h"
|
#include "linux/version.h"
|
||||||
|
#include "linux/paddle.h"
|
||||||
|
|
||||||
#include "frontends/retro/game.h"
|
#include "frontends/retro/game.h"
|
||||||
#include "frontends/retro/environment.h"
|
#include "frontends/retro/environment.h"
|
||||||
|
#include "frontends/retro/joypad.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -81,21 +83,20 @@ void retro_set_environment(retro_environment_t cb)
|
||||||
log_cb = logging.log;
|
log_cb = logging.log;
|
||||||
else
|
else
|
||||||
log_cb = fallback_log;
|
log_cb = fallback_log;
|
||||||
/*
|
|
||||||
static const retro_controller_description controllers[] =
|
static const struct retro_controller_description controllers[] = {
|
||||||
{
|
{ "Nintendo DS", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) },
|
||||||
{ "Apple Keyboard", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0) },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const retro_controller_info ports[] =
|
static const struct retro_controller_info ports[] = {
|
||||||
{
|
|
||||||
{ controllers, 1 },
|
{ controllers, 1 },
|
||||||
{ NULL, 0 },
|
{ NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);*/
|
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
|
||||||
retro_keyboard_callback callback = {&Game::keyboardCallback};
|
|
||||||
cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &callback);
|
// retro_keyboard_callback callback = {&Game::keyboardCallback};
|
||||||
|
// cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void retro_set_audio_sample(retro_audio_sample_t cb)
|
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);
|
log_cb(RETRO_LOG_INFO, "Game path: %s:%d\n", info->path, ok);
|
||||||
|
|
||||||
|
Paddle::instance().reset(new Joypad);
|
||||||
|
Paddle::setSquaring(false);
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
catch (const std::exception & e)
|
catch (const std::exception & e)
|
||||||
|
|
Loading…
Add table
Reference in a new issue